<?


### mymind2u.net - akushah###
include_once 'sys/inc/start.php';
include_once 'sys/inc/compress.php';
include_once 'sys/inc/sess.php';
include_once 'sys/inc/home.php';
include_once 'sys/inc/settings.php';
include_once 'sys/inc/db_connect.php';
include_once 'sys/inc/ipua.php';
include_once 'sys/inc/fnc.php';
include_once 'sys/inc/user.php';

only_reg();

$set['title']='My Avatar';
include_once 'sys/inc/thead.php';

title();

if (isset($_FILES['file']))

{

if (eregi('\.jpe?g$',$_FILES['file']['name']) && $imgc=@imagecreatefromjpeg($_FILES['file']['tmp_name']))

{

if (imagesx($imgc)>60 || imagesy($imgc)>60)

{

$img_x=imagesx($imgc);
$img_y=imagesy($imgc);
if ($img_x==$img_y)

{

$dstW=60; // ?p?a
$dstH=60; // ?co?

}

elseif ($img_x>$img_y)

{

$prop=$img_x/$img_y;
$dstW=60;
$dstH=ceil($dstW/$prop);

}
else
{

$prop=$img_y/$img_x;
$dstH=60;
$dstW=ceil($dstH/$prop);

}

$screen=imagecreatetruecolor($dstW, $dstH);
imagecopyresampled($screen, $imgc, 0, 0, 0, 0, $dstW, $dstH, $img_x, $img_y);
imagedestroy($imgc);
@chmod(H."sys/avatar/$user[id].jpg",0777);
@chmod(H."sys/avatar/$user[id].gif",0777);
@chmod(H."sys/avatar/$user[id].png",0777);
@unlink(H."sys/avatar/$user[id].jpg");
@unlink(H."sys/avatar/$user[id].gif");
@unlink(H."sys/avatar/$user[id].png");
imagejpeg($screen,H."sys/avatar/$user[id].jpg",60);
@chmod(H."sys/avatar/$user[id].jpg",0777);
imagedestroy($screen);

}
else
{

copy($_FILES['file']['tmp_name'], H."sys/avatar/$user[id].jpg");

}

msg("Avatar successfully updated");

###status###
$msgft=' change new avatar 

[img]http://mymind2u.net/sys/avatar/'.$user['id'].'.jpg[/img]';
mysql_query("INSERT INTO `statuse_list` (`id_user`, `msg`, `time`, `anu`) values('$user[id]', '$msgft', '$time', '1')");
###end status###

mysql_query("UPDATE `user` SET `balls` = '".($user['balls']+1)."' WHERE `id` = '$user[id]' LIMIT 1");

###wall photo###
$msgftpr="[url=/info.php?id=$user[id]]$user[nick][/url] [url=/primary.php?id=$user[id]]foto[/url] profil yang baru"; mysql_query("INSERT INTO `aktivitas_ku` (`id_user`, `id_kont`, `msg`, `time`) values('0', '$user[id]', '$msgftpr', '$time')");
###end wall photo###

}

elseif (eregi('\.gif$',$_FILES['file']['name']) && $imgc=@imagecreatefromgif($_FILES['file']['tmp_name']))

{

include_once 'sys/inc/gif_resize.php';
$screen=gif_resize(fread ( fopen ($_FILES['file']['tmp_name'], "rb" ), filesize ($_FILES['file']['tmp_name']) ),60,60);

@chmod(H."sys/avatar/$user[id].jpg",0777);
@chmod(H."sys/avatar/$user[id].gif",0777);
@chmod(H."sys/avatar/$user[id].png",0777);
@unlink(H."sys/avatar/$user[id].jpg");
@unlink(H."sys/avatar/$user[id].gif");
@unlink(H."sys/avatar/$user[id].png");
file_put_contents(H."sys/avatar/$user[id].gif", $screen);
@chmod(H."sys/avatar/$user[id].gif",0777);

}

elseif (eregi('\.png$',$_FILES['file']['name']) && $imgc=@imagecreatefrompng($_FILES['file']['tmp_name']))

{

if (imagesx($imgc)>60 || imagesy($imgc)>60)

{

$img_x=imagesx($imgc);
$img_y=imagesy($imgc);
if ($img_x==$img_y)

{

$dstW=60; // ?p?a
$dstH=60; // ?co?

}

elseif ($img_x>$img_y)

{

$prop=$img_x/$img_y;
$dstW=60;
$dstH=ceil($dstW/$prop);

}
else
{

$prop=$img_y/$img_x;
$dstH=60;
$dstW=ceil($dstH/$prop);

}

$screen=ImageCreate($dstW, $dstH);
imagecopyresampled($screen, $imgc, 0, 0, 0, 0, $dstW, $dstH, $img_x, $img_y);
imagedestroy($imgc);

@chmod(H."sys/avatar/$user[id].jpg",0777);
@chmod(H."sys/avatar/$user[id].gif",0777);
@chmod(H."sys/avatar/$user[id].png",0777);
@unlink(H."sys/avatar/$user[id].jpg");
@unlink(H."sys/avatar/$user[id].gif");
@unlink(H."sys/avatar/$user[id].png");
imagepng($screen,H."sys/avatar/$user[id].png");
@chmod(H."sys/avatar/$user[id].png",0777);
imagedestroy($screen);

}
else
{

copy($_FILES['file']['tmp_name'], H."sys/avatar/$user[id].png");

}

msg("Avatar successfully updated");

}
else
{

$err='Invalid file format!!';

}
}

err();
//aut();

echo "<form method='post' enctype='multipart/form-data' action='?$passgen'>\n";
echo "<table class='post'>\n";

echo "   <tr>\n";
echo "  <td class='icon' rowspan='2'>\n";
avatar($user['id']);
echo "  </td>\n";

echo "  <td class='p_t'>\n";
echo "Your current avatar\n";
echo "  </td>\n";
echo "   </tr>\n";

echo "   <tr>\n";
echo "  <td class='p_m'>\n";
echo "File format allowed : GIF, JPG, PNG<br />\n";
echo "Qualitative transformation GIF-animation is not guaranteed<br />\n";
echo "  </td>\n";
echo "   </tr>\n";

echo "   <tr>\n";
echo "  <td colspan='2'>\n";
echo "<input type='file' name='file' accept='image/*,image/gif,image/png,image/jpeg' /><br />\n";

echo "<div class='foot'><input value='Upload' type='submit' class='button' /><br /></div>\n";
echo "  </td>\n";
echo "   </tr>\n";
echo "</table>\n";
echo "</form>\n";

echo "<div class='foot'>\n";
if(isset($_SESSION['refer']) && $_SESSION['refer']!=NULL && otkuda($_SESSION['refer']))
echo "&laquo;<a href='$_SESSION[refer]'>".otkuda($_SESSION['refer'])."</a><br />\n";
echo "&laquo;<a href='umenu.php'>CPanel</a><br />\n";
echo "</div>\n";

include_once 'sys/inc/tfoot.php';

?>
