<?php
$path="../../";
include("../../map.php");
include("../../scripts.php");
include("../../secure.php");
include("../../../deppo/tools/script/SimpleImage.php");
?>
<!DOCTYPE html>
<html>
<head>
	<meta charset="utf-8"/>
	<link href="//fonts.googleapis.com/css?family=PT+Sans+Narrow:400,700" rel='stylesheet' />
	<link href="../../assets/ajax-upload/assets/css/style.css" rel="stylesheet" />
</head>
<body>
	<form id="upload" method="post" action="?ne=<?php echo $_GET["ne"];?>&islem=<?php echo $_GET["islem"];?>&id=<?php echo $_GET["id"]; ?>&durum=yukle" enctype="multipart/form-data">
		<div id="drop"> <?php echo ctranslate("Sürükle Bırak")?> <a><?php echo ctranslate("Gözat")?></a>
			<input type="file" name="dosya" multiple />
			<input type="hidden" class="form-control" name="risim" value="<?php echo $risim;?>">
			<input type="checkbox" name="durum1" value="ON" style="display:none;" title="Resim Var/Yok" checked>
			<input type="checkbox" name="boyut1" value="ON" style="display:none;" title="Boyutlandır" checked>
		</div>
		<ul></ul>
	</form>
	<!-- JavaScript Includes --> 
	<script src="//ajax.googleapis.com/ajax/libs/jquery/1.9.1/jquery.min.js"></script> 
	<script src="../../assets/ajax-upload/assets/js/jquery.knob.js"></script> 
	<!-- jQuery File Upload Dependencies --> 
	<script src="../../assets/ajax-upload/assets/js/jquery.ui.widget.js"></script> 
	<script src="../../assets/ajax-upload/assets/js/jquery.iframe-transport.js"></script> 
	<script src="../../assets/ajax-upload/assets/js/jquery.fileupload.js"></script> 
	<!-- Our main JS file --> 
	<script src="../../assets/ajax-upload/assets/js/script.js"></script>
</body>
</html>
<?php
if($_GET["durum"]=="yukle"){
	function irep($metin){
		$metin = str_replace("'", "", $metin);
		$metin = str_replace("×", "x", $metin);
		return $metin;
	}
	
	if($_GET["ne"]=="sayfa" or $_GET["ne"]=="haber" or $_GET["ne"]=="msayfa" or $_GET["ne"]=="kayit"){
		$sql=mysqli_query($conn, "select * from ".$_SESSION['lang']." where id=".$_GET["id"].""); $rs=mysqli_fetch_assoc($sql);
		$risim=strtolower(cevir1(irep($rs["t1"])));
	}else{
		$risim=strtolower(cevir1(irep($_GET["ne"])));
	}
	
	$allowed= array('png', 'jpg', 'gif','zip');
	$uzanti = explode('.',$_FILES['dosya']['name']);
	$isim   = $_FILES['dosya']['name'];
	$rand   = substr(md5(uniqid(rand())),0,5);
	$yeni   = "".$risim."-".$rand.".".$uzanti[1]."";
	
	if(isset($_FILES['dosya']) && $_FILES['dosya']['error'] == 0){
		$extension = pathinfo($_FILES['dosya']['name'], PATHINFO_EXTENSION);
		if(!in_array(strtolower($extension), $allowed)){
			echo '{"status":"error"}';
			exit;
		}
		if(move_uploaded_file($_FILES['dosya']['tmp_name'], "../deppo/image/".$yeni."")){
			echo '{"status":"success"}';
			exit;
		}
		
		$conn->query("insert INTO medya (ne,s1,s2,s3,s4,t1,t3,t6,t2,n3) VALUES ('resim', '".$ID."', '".$ks2."', '0', '".$_POST['s4']."', '".addslashes($yeni)."', '".$_GET['ne']."', '".$_SESSION["lang"]."', '".$_POST['i1']."', '".$_POST['ia1']."')");
		//-------------------------------------------------------------
		if ($_POST["boyut1"]<>""){
			$image = new SimpleImage();
			$image->load("../../../deppo/image/".$yeni."");
			$image->resizeToWidth("".$a9."");
			$image->save("../../../deppo/image/".$yeni."");
			$image->resizeToWidth("".$a10."");
			$image->save("../../../deppo/image/k_".$yeni."");
		}else{
			$image = new SimpleImage();
			$image->load("../../../deppo/image/".$yeni."");
			$image->save("../../../deppo/image/".$yeni."");
			$image->resizeToWidth("".$a10."");
			$image->save("../../../deppo/image/k_".$yeni."");
		}
		
		if ($e1==1){
			$damga = imagecreatefrompng("../../../deppo/image/".$t50."");
			$oyeni = imagecreatefromjpeg("../../../deppo/image/".$yeni."");
			$msag = 10;
			$malt = 10;
			$sx = imagesx($damga);
			$sy = imagesy($damga);
			imagecopy($oyeni, $damga, imagesx($oyeni) - $sx - $msag, imagesy($oyeni) - $sy - $malt, 0, 0, imagesx($damga), imagesy($damga));
			$wyeni = "../../../deppo/image/".$yeni."";
			imagepng($oyeni, $wyeni);
			imagedestroy($oyeni);
		}
		//-------------------------------------------------------------
		
		
	}
	echo '{"status":"error"}';
	exit;	
}
?>