<?

#Avatar Fix 664

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']='Set 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)>50 || imagesy($imgc)>50){
$img_x=imagesx($imgc);
$img_y=imagesy($imgc);

if ($img_x==$img_y){
$dstW=50;
$dstH=50;}

elseif ($img_x>$img_y){
$prop=$img_x/$img_y;
$dstW=50;
$dstH=ceil($dstW/$prop);}

else{
$prop=$img_y/$img_x;
$dstH=50;
$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",50);
@chmod(H."sys/avatar/$user[id].jpg",0777);
imagedestroy($screen);}

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


##########REMODIF BY ANTOQ###########HTTP://INDWAP.TK##################
msg("Avatar Berhasil di Tambahkan");
$msg='Changed [url=/primary.php?id='.$user[id].']foto[/url] profil [img]http://indwap.tk/sys/avatar/'.$user[id].'.jpg[/img]';
mysql_query("INSERT INTO `statuse_list` (`id_user`, `msg`, `time`, `kategori`) values('$user[id]', '$msg', '$time', '1')");
mysql_query("UPDATE `user` SET `balls` = '".($user['balls']+1)."' WHERE `id` = '$user[id]' LIMIT 1");
mysql_query("INSERT INTO `aktivitas_ku` (`id_user`, `id_kont`, `msg`, `time`) values('0', '$user[id]', '$msg', '$time')");
}

if (eregi('\.jpe?g$',$_FILES['file']['name']) && $imgc=@imagecreatefromjpeg($_FILES['file']['tmp_name'])){
if (imagesx($imgc)>150 || imagesy($imgc)>150){
$img_x=imagesx($imgc);
$img_y=imagesy($imgc);

if ($img_x==$img_y){
$dstW=150;
$dstH=150;}

elseif ($img_x>$img_y){
$prop=$img_x/$img_y;
$dstW=150;
$dstH=ceil($dstW/$prop);}

else{
$prop=$img_y/$img_x;
$dstH=150;
$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/avatars/$user[id].jpg",0777);
@chmod(H."sys/avatars/$user[id].gif",0777);
@chmod(H."sys/avatars/$user[id].png",0777);
@unlink(H."sys/avatars/$user[id].jpg");
@unlink(H."sys/avatars/$user[id].gif");
@unlink(H."sys/avatars/$user[id].png");
imagejpeg($screen,H."sys/avatars/$user[id].jpg",150);
@chmod(H."sys/avatars/$user[id].jpg",0777);
imagedestroy($screen);}

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

elseif (eregi('\.gif$',$_FILES['file']['name']) && $imgc=@imagecreatefromgif($_FILES['file']['tmp_name'])){
$screen=gif_resize(fread ( fopen ($_FILES['file']['tmp_name'], "rb" ), filesize ($_FILES['file']['tmp_name']) ),50,50);
@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);
msg("Avatar Berhasil Di Tambahkan");
}
##########REMODIF BY ANTOQ###########HTTP://INDWAP.TK##################
elseif (eregi('\.gif$',$_FILES['file']['name']) && $imgc=@imagecreatefromgif($_FILES['file']['tmp_name'])){
$screen=gif_resize(fread ( fopen ($_FILES['file']['tmp_name'], "rb" ), filesize ($_FILES['file']['tmp_name']) ),150,150);
@chmod(H."sys/avatars/$user[id].jpg",0777);
@chmod(H."sys/avatars/$user[id].gif",0777);
@chmod(H."sys/avatars/$user[id].png",0777);
@unlink(H."sys/avatars/$user[id].jpg");
@unlink(H."sys/avatars/$user[id].gif");
@unlink(H."sys/avatars/$user[id].png");
file_put_contents(H."sys/avatars/$user[id].gif", $screen);
@chmod(H."sys/avatars/$user[id].gif",0777);
}

elseif (eregi('\.png$',$_FILES['file']['name']) && $imgc=@imagecreatefrompng($_FILES['file']['tmp_name'])){
if (imagesx($imgc)>50 || imagesy($imgc)>50){
$img_x=imagesx($imgc);
$img_y=imagesy($imgc);
if ($img_x==$img_y){
$dstW=50;
$dstH=50;}

elseif ($img_x>$img_y){
$prop=$img_x/$img_y;
$dstW=50;
$dstH=ceil($dstW/$prop);}

else{
$prop=$img_y/$img_x;
$dstH=50;
$dstW=ceil($dstH/$prop);}
##########REMODIF BY ANTOQ###########HTTP://INDWAP.TK##################
$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 Berhasil di Tambahkan");
$msg='Changed [url=/primary.php?id='.$user[id].']foto[/url] profil [img]http://indwap.tk/sys/avatar/'.$user[id].'.jpg[/img]';
mysql_query("INSERT INTO `statuse_list` (`id_user`, `msg`, `time`, `kategori`) values('$user[id]', '$msg', '$time', '1')");
mysql_query("UPDATE `user` SET `balls` = '".($user['balls']+1)."' WHERE `id` = '$user[id]' LIMIT 1");
mysql_query("INSERT INTO `aktivitas_ku` (`id_user`, `id_kont`, `msg`, `time`) values('0', '$user[id]', '$msg', '$time')");
}

elseif (eregi('\.png$',$_FILES['file']['name']) && $imgc=@imagecreatefrompng($_FILES['file']['tmp_name'])){
if (imagesx($imgc)>150 || imagesy($imgc)>150){
$img_x=imagesx($imgc);
$img_y=imagesy($imgc);
if ($img_x==$img_y){
$dstW=150;
$dstH=150;}

elseif ($img_x>$img_y){
$prop=$img_x/$img_y;
$dstW=150;
$dstH=ceil($dstW/$prop);}

else{
$prop=$img_y/$img_x;
$dstH=150;
$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/avatars/$user[id].jpg",0777);
@chmod(H."sys/avatars/$user[id].gif",0777);
@chmod(H."sys/avatars/$user[id].png",0777);
@unlink(H."sys/avatars/$user[id].jpg");
@unlink(H."sys/avatars/$user[id].gif");
@unlink(H."sys/avatars/$user[id].png");
imagepng($screen,H."sys/avatars/$user[id].png");
@chmod(H."sys/avatars/$user[id].png",0777);
imagedestroy($screen);}
}


else
{$err='Format file tidak di izinkan';}

}

err();
aut();
title();
echo "<div class='menu'><center>\n";
avatars($user['id']);

echo "<font color='#FF8101'>Avatar Kamu Sekarang</font><center></div>\n";
echo "<div class='p_m'>\n";
echo "<font color='red'>Format file yg di izinkan: GIF, JPG, PNG. \n";
echo "Usahakan jenis gambar bukan animasi</font>\n";
echo "</div>";
echo "<form class='foot' method='post' enctype=\"multipart/form-data\" action='?$passgen'>\n";
echo "<input type=\"file\" name=\"file\" style='width: 98%;' accept='image/*,image/gif,image/png,image/jpeg' />\n";
echo "<input value=\"Upload\" type=\"submit\" />\n";
echo "</form>\n";


echo "<div class='foot' style='text-align: left;'>\n";
echo "&bull; <a href='/'>Home</a> | <a href='umenu.php'>My Menu</a>";
echo "</div>\n";


include_once 'sys/inc/tfoot.php';
?>
