<?php session_start(); ?>
<?php
include("stop.php");
?>
<?php
$mobile = "xhtml/panel.php";
$text = $_SERVER['HTTP_USER_AGENT'];
$var[2] = "AvantGo";
$var[3] = "ProxiNet";
$var[4] = "Danger hiptop 1.0";
$var[5] = "DoCoMo/";
$var[6] = "Google CHTML Proxy/";
$var[7] = "UP.Browser/";
$var[8] = "SEMC-Browser/";
$var[9] = "J-PHONE/";
$var[10] = "PDXGW/";
$var[11] = "ASTEL/";
$var[13] = "Handspring";
$var[14] = "Windows CE";
$var[15] = "PPC";
$var[17] = "Blazer/";
$var[18] = "Palm";
$var[19] = "WebPro/";
$var[20] = "EPOC32-WTL/";
$var[21] = "Tungsten";
$var[22] = "Netfront/";
$var[23] = "Mobile Content Viewer/";
$var[24] = "PDA";
$var[25] = "MMP/2.0";
$var[26] = "Embedix/";
$var[27] = "Qtopia/";
$var[28] = "Xiino/";
$var[29] = "BlackBerry";
$var[30] = "Gecko/20031007";
$var[31] = "MOT-";
$var[32] = "UP.Link/";
$var[33] = "Smartphone";
$var[34] = "portalmmm/";
$var[35] = "Nokia";
$var[36] = "Symbian";
$var[37] = "AppleWebKit/413";
$var[38] = "UPG1 UP/";
$var[39] = "RegKing";
$var[40] = "STNC-WTL/";
$var[41] = "J2ME";
$var[42] = "Opera Mini/";
$var[43] = "SEC-";
$var[44] = "ReqwirelessWeb/";
$var[45] = "AU-MIC/";
$var[46] = "Sharp";
$var[47] = "SIE-";
$var[48] = "SonyEricsson";
$var[49] = "Elaine/";
$var[50] = "SAMSUNG-";
$var[51] = "Panasonic";
$var[52] = "Siemens";
$var[53] = "Sony";
$var[54] = "Verizon";
$var[55] = "Cingular";
$var[56] = "Sprint";
$var[57] = "AT&T";
$var[58] = "Nextel";
$var[59] = "Pocket PC";
$var[60] = "T-Mobile";
$var[61] = "Orange";
$var[62] = "Casio";
$var[63] = "HTC";
$var[64] = "Motorola";
$var[65] = "Samsung";
$var[66] = "NEC";

$result = count($var);

for ($i=0;$i<$result;$i++)
{
$ausg = stristr($text, $var[$i]);
if(strlen($ausg)>0)
{
header("location: $mobile");
break;
}
}
include ("config.php");

if(isset($_SESSION['nume'])) {
      	$username = ''.$_SESSION['nume'].'';
$stare = "Control Panel";
if(!$act){mysql_query("UPDATE utilizatori SET stare='$stare' WHERE nume='$username'");}
}
?>
<?
include ("header.html");
?>
<table width='950' cellspacing='0' cellpadding='0' align='center'>

<?
include ("right.html");
?>

<td width='760' valign='top' class='continut'>

<table cellspacing='0' cellpadding='10'  width='100%'>
<tr>
<td>
<!-- CONTINUTUL !!!! -->
 <div class='hl'>My Panel</div>

 <div class='txt'>
</div>
<?
if(isset($_SESSION['nume'])) {
$user1=$_SESSION['nume'];
$query="SELECT * from utilizatori where nume='$user1'";
$res=mysql_query($query) or die(mysql_error());
while($row=mysql_fetch_array($res))
{
$avatar = $row['avatar'];
$uid = $row["id"];
$curl = $row["link"];
}
if(!$act){mysql_query("UPDATE utilizatori SET ip='$adresa' WHERE id='$uid'");}
echo "<img src='avatar/$avatar' align='top' class='imagine'  alt='avatar' />Welcome  to your panel <b> $user1 </b>.";

$user1=$_SESSION['nume'];
$result = mysql_query("SELECT * FROM fisiere WHERE user='$user1'");
$num_rows = mysql_num_rows($result);
echo "
<br/>
<div class='hl'>Public files</div>
<div class='txt'>
    You have uploaded <b> $num_rows </b> to public area. These files cannot be managed by uploaders.
<br/><br/>
<a href='userup.php?rid=$user1'>Show my public uploads</a>.  
</div>
 <br/>";
?>
<?
if(isset($_SESSION['nume']))
{
  $user1=$_SESSION['nume'];
  $getuser="SELECT * from utilizatori where nume='$user1'";
  $getuser2=mysql_query($getuser) or die("Could not get user info");
  $getuser3=mysql_fetch_array($getuser2);
  $thedate=date("U");
  $checktime=$thedate-200;
  $uprecords="Update utilizatori set lasttime='$thedate' where id='$getuser3[id]'";
  mysql_query($uprecords) or die("Could not update records");
  if($getuser3[tsgone]<$checktime)
  {
    $updatetime="Update utilizatori set tsgone='$thedate', oldtime='$getuser3[tsgone]' where id='$getuser3[id]'";
    mysql_query($updatetime) or die("Could not update time");
  }
}
?>
<div class='hl'>File Favorite</div>
<br/>
<?
$i=1;
$userid=$_SESSION['nume'];

$idlista=mysql_query("SELECT * FROM utilizatori WHERE nume='$userid'"); 
while($idlista3=mysql_fetch_array($idlista))
{
$sql = mysql_query("SELECT * FROM favorite WHERE uid='$idlista3[id]' ORDER BY id DESC"); 
if(!$sql)
{ 
echo "No file favorite.";
}
while($row = mysql_fetch_array($sql)){ 
// Build your formatted results here.
$id = $row['id'];
$fid = $row['fid'];
$uid = $row['uid'];

$files="SELECT * FROM fisiere WHERE id='$fid'"; 
$files2=mysql_query($files) or die("Could not get file");
while($files3=mysql_fetch_array($files2))
{
$favfile = $files3["file"];    

echo "$i.<a href=\"file.php?id=$fid\">$favfile</a><br/>";
$i++;
}
}}

echo "<div class='hl'>Set your website</div>";

echo "<b>Current site:</b>  $curl <br />";

echo "<form action='panel.php?act=seturl' method='POST'>";
echo "<b>Site:</b><input name='link' type='text' value='http://' size='50'><br>";
echo "<input type='submit' name='submit' value='Submit'>";
echo "</form>";

$act = $_GET["act"];
if($act=="seturl"){
    $linksite = $_POST["link"];
// The Regular Expression filter
$link = htmlspecialchars($linksite, ENT_QUOTES);

mysql_query("UPDATE utilizatori SET link='$link' WHERE id='$uid' "); echo "Your site was add!";}

echo "<div class='hl'>Avatar</div>";

// Aici puteti modifica numele directorului de upload (daca ati pus alt nume)
$uploadpath = "bin/";

// Aici este setata marimea maxima, in KiloBytes, care este permisa (dar marime maxima depinde si de setarile serverului)
$max_size = 20000;

// Aici puteti schimba tipul, extensia fisierelor permise pt. upload
$allowtype = array('bmp', 'gif', 'jpg', 'jpeg', 'png',);

$filename = $_FILES['fisiere']['name'];
$ext = strrchr($filename,'.');
$filename=str_replace(".php"," ",$filename);

$filename=str_replace("$ext", "$userid$ext",$filename);
if(isset($_POST['submit'])) {
  if (isset ($_FILES['fisiere'])) {
    $uploadpath = $uploadpath . basename($filename);
	$type = end(explode(".", strtolower($filename)));

    // Daca fisierul are extensia permisa
    if (in_array($type, $allowtype)) {
	  // Verifica daca fisierul are marimea permisa

	  if ($_FILES['fisiere']['size']<=$max_size*1000) {
        if(move_uploaded_file($_FILES['fisiere']['tmp_name'], $uploadpath)) { 
          echo "Fisierul:<b> ". basename($filename). "</b> a fost incarcat cu succes:"; 
          
          

$idir = "bin/";   // Path To Images Directory
$tdir = "avatar/";   // Path To Thumbnails Directory
$twidth = "40";   // Maximum Width For Thumbnail Images
$theight = "40";   // Maximum Height For Thumbnail Images
 
   
  $urls = $filename;   // Set $url To Equal The Filename For Later Use
 
if(in_array($type,array("jpg"))){
    $simg = imagecreatefromjpeg("$idir" . $urls);   // Make A New Temporary Image To Create The Thumbanil From
      }
      
 if(in_array($type,array("gif"))){
    $simg = imagecreatefromgif("$idir" . $urls);   // Make A New Temporary Image To Create The Thumbanil From
      }
      
if(in_array($type,array("png"))){
    $simg = imagecreatefrompng("$idir" . $urls);   // Make A New Temporary Image To Create The Thumbanil From
      }
      
      $currwidth = imagesx($simg);   // Current Image Width
      $currheight = imagesy($simg);   // Current Image Height
      if ($currheight > $currwidth) {   // If Height Is Greater Than Width
         $zoom = $twidth / $currheight;   // Length Ratio For Width
         $newheight = $theight;   // Height Is Equal To Max Height
         $newwidth = $currwidth * $zoom;   // Creates The New Width
      } else {    // Otherwise, Assume Width Is Greater Than Height (Will Produce Same Result If Width Is Equal To Height)
        $zoom = $twidth / $currwidth;   // Length Ratio For Height
        $newwidth = $twidth;   // Width Is Equal To Max Width
        $newheight = $currheight * $zoom;   // Creates The New Height
      }
      $dimg = imagecreate($newwidth, $newheight);   // Make New Image For Thumbnail
      imagetruecolortopalette($simg, false, 256);   // Create New Color Pallete
      $palsize = ImageColorsTotal($simg);
      for ($i = 0; $i < $palsize; $i++) {   // Counting Colors In The Image
       $colors = ImageColorsForIndex($simg, $i);   // Number Of Colors Used
       ImageColorAllocate($dimg, $colors['red'], $colors['green'], $colors['blue']);   // Tell The Server What Colors This Image Will Use
      }
      imagecopyresized($dimg, $simg, 0, 0, 0, 0, $newwidth, $newheight, $currwidth, $currheight);   // Copy Resized Image To The New Image (So We Can Save It)
      imagejpeg($dimg, "$tdir" . $urls);   // Saving The Image
      imagedestroy($simg);   // Destroying The Temporary Image
      imagedestroy($dimg);   // Destroying The Other Temporary Image
      print 'Image thumbnail created successfully.</br>';   // Resize successful
          
$fisier = $filename;
$user=$_SESSION['nume'];
$getuser=mysql_query("SELECT * from utilizatori where nume='$user'");
$getuser3=mysql_fetch_array($getuser);

$uprecords="Update utilizatori set avatar='$fisier' where id='$getuser3[id]'";
$uprecords1="Update utilizatori set setavatar='1' where id='$getuser3[id]'";
  
  mysql_query($uprecords1) or die("Could not update records"); 
  mysql_query($uprecords) or die("Could not update records"); 
		}
        else { 
          echo "<b>A aparut o eroare la urcarea fisierului pe server, <br /> posibil ca marimea fisierului sa depaseasca permisiunile setate de server.</b>"; 
        }
	  }
	  else { echo 'Fisierul <b>'. $_FILES['fisiere']['name']. '</b> depaseste marimea permisa de maxim <i><b>'. $max_size. 'KB</b></i>'; }
    }
	else { echo 'Fisierul <b>'. $_FILES['fisiere']['name']. '</b> nu are tipul de extensie permis'; }
  }
}

?>
</form>
<small>Maximum size: 61440 bytes and 150 x 150 px</small><br/><br/>
 <br/><br/>
</div>
<div style="width:333px; text-align:center;">
<form action="panel.php" method="POST" enctype="multipart/form-data"> 
Upload Fisier: 
<input type="file" name="fisiere" /> <br />
<input type="submit" name='submit' value="Save Profile" /> 
</form>
</div>
<br />

<div class='hl'>Change Password</div>
<?php
include("change.php");

}else{
echo "Acces refuzed!";
}
?>

<!-- SFARSIT CONTINUT!!! --> 


<br/>
	</center>


</td></tr></table>
</tr>

<tr>
<td width='180'>&nbsp;
</td>

<?php
include ("flooter.html");
?>