<?php
$path="../../";
include("../../map.php");
include("../../../deppo/tools/script/SimpleImage.php");
header('Content-Type: application/json');

if($_GET["islem"]=="ulogo"){
	$kaydedilecekyer = "../../../deppo/image";
	$kaynak = $_FILES['dosya']['tmp_name'];
	$uzanti = explode('.',$_FILES['dosya']['name']);
	$isim   = $_FILES['dosya']['name'];
	$rand   = substr(md5(uniqid(rand())),0,5);
	$yeni   = "".$_GET["ne"]."-".$rand.".".$uzanti[count($uzanti)-1]."";
	move_uploaded_file ($_FILES['dosya']['tmp_name'], $kaydedilecekyer . "/".$yeni);
	$rboyut = getimagesize("../../../deppo/image/".$yeni."");

	if ($module["webp"] == 1){
		$yeni = towebp($yeni, "../../../deppo/image/");
	}

	
	if($_GET["id"]=="stamp" or $_GET["id"]=="logo_app" or $_GET["id"]=="logo_oim" or $_GET["id"]=="logo_pay"){
		$sql=mysqli_query($conn, "select * from ".$_SESSION["lang"]." where ne='ayarlar' "); $rs=mysqli_fetch_assoc($sql); $jsi = json_decode($rs["n18"], true);
		$iarr = uparr($jsi, $_GET["id"], $yeni);
		$rjsi = json_encode($iarr, JSON_UNESCAPED_UNICODE | JSON_UNESCAPED_SLASHES | JSON_NUMERIC_CHECK);
		$update = mysqli_query($conn, "update ".$_SESSION["lang"]." set n18='".addslashes(stripslashes($rjsi))."' where ne='ayarlar'");
	}else{
		$Rs = mysqli_query($conn, "update ".$_SESSION['lang']." set ".$_GET["id"]."='".$yeni."' where ne='ayarlar'");
	}
	$data=array("function"=>"success","image"=>"../../../deppo/image/".$yeni."");
	echo json_encode($data);

}elseif($_GET["islem"]=="chat"){
	$kaydedilecekyer = "../../../deppo/chat";
	$kaynak = $_FILES['dosya']['tmp_name'];
	$uzanti = explode('.',$_FILES['dosya']['name']);
	$isim   = $_FILES['dosya']['name'];
	$rand   = substr(md5(uniqid(rand())),0,5);
	$yeni   = "".$_GET["id"]."-".$rand.".".$uzanti[count($uzanti)-1]."";
	move_uploaded_file ($_FILES['dosya']['tmp_name'], $kaydedilecekyer . "/".$yeni);
	$rboyut = getimagesize("../../../deppo/chat/".$yeni."");
	$data=array("function"=>"success","image"=>"../deppo/chat/".$yeni."");
	echo json_encode($data);

}elseif($_GET["islem"]=="dlogo"){
	$sql=mysqli_query($conn, "select * from ".$_SESSION['lang']." where ne='ayarlar'"); $rs=mysqli_fetch_assoc($sql); $jsi = json_decode($rs["n18"], true);
	if($_GET["id"]=="stamp" or $_GET["id"]=="logo_app" or $_GET["id"]=="logo_oim" or $_GET["id"]=="logo_pay"){
		$dosya="../../../deppo/image/".$jsi[$_GET["id"]]."";
		$iarr = uparr($jsi, $_GET["id"], "");
		$rjsi = json_encode($iarr, JSON_UNESCAPED_UNICODE | JSON_UNESCAPED_SLASHES | JSON_NUMERIC_CHECK);
		$update = mysqli_query($conn, "update ".$_SESSION["lang"]." set n18='".addslashes(stripslashes($rjsi))."' where ne='ayarlar'");
	}else{
		$dosya="../../../deppo/image/".$rs[$_GET["id"]]."";
	}
	unlink($dosya);
	if($_GET["ne"]=="favicon"){
		for ($l = 1; $l <= $lx; $l++){$Rsq = mysqli_query($conn, "update lang".$l." set ".$_GET["id"]."='' where ne='ayarlar'");}
	}else{
		$Rsq = mysqli_query($conn, "update ".$_SESSION['lang']." set ".$_GET["id"]."='' where ne='ayarlar'");
	}

}elseif($_GET["islem"]=="dragdrop"){
	$sqlk=mysqli_query($conn, "select * from medya where ne='resim' and t3='".$_GET['ne']."' and s1='".$_GET['id']."'"); $rski=mysqli_fetch_assoc($sqlk);
	if(mysqli_num_rows($sqlk)>0){$ks2="0";}else{$ks2="1";}
	if($_POST["i1"]<>"") { $i1isim=substr(cevir($_POST["i1"]),0,30); }
	if($_POST["i2"]<>"") { $i2isim=substr(cevir($_POST["i2"]),0,30); }
	if($_POST["i3"]<>"") { $i3isim=substr(cevir($_POST["i3"]),0,30); }
	if($_POST["i4"]<>"") { $i4isim=substr(cevir($_POST["i4"]),0,30); }
	if($_POST["i5"]<>"") { $i5isim=substr(cevir($_POST["i5"]),0,30); }
	if($_POST["i6"]<>"") { $i6isim=substr(cevir($_POST["i6"]),0,30); }
	if($_POST["i7"]<>"") { $i7isim=substr(cevir($_POST["i7"]),0,30); }
	if($_POST["i8"]<>"") { $i8isim=substr(cevir($_POST["i8"]),0,30); }
	if($_POST["i9"]<>"") { $i9isim=substr(cevir($_POST["i9"]),0,30); }
	if($_POST["i10"]<>""){$i10isim=substr(cevir($_POST["i10"]),0,30);}
	$kaynak1= $_FILES['resim1']['tmp_name'];	//Burası resminiz kök klasörünün yerini verir
	$tipi1	= $_FILES['resim1']['type']; // Dosyanın Tipi
	$adi1	= $_FILES["resim1"]["name"]; // Dosyanın PCdeki Adı
	$uzanti1 = explode('.',$_FILES['resim1']['name']);
	$rand1  = substr(md5(uniqid(rand())),0,10); 
	$yeni1  = "".$i1isim."-".$rand1.".".$uzanti1[count($uzanti1)-1]."";
	move_uploaded_file ($_FILES['resim1']['tmp_name'], $kaydedilecekyer . "/".$yeni1);

	//-------------------------------------------------------------
	if ($_POST["boyut1"]<>""){
		$image = new SimpleImage();
		$image->load("../../../deppo/image/".$yeni1."");
		$image->resizeToWidth("".$a9."");
		$image->save("../../../deppo/image/".$yeni1."");
		$image->resizeToWidth("".$a10."");
		$image->save("../../../deppo/image/k_".$yeni1."");
	}else{
		$image = new SimpleImage();
		$image->load("../../../deppo/image/".$yeni1."");
		//$image->save("../../../deppo/image/".$yeni1."");
		$image->resizeToWidth("".$a10."");
		$image->save("../../../deppo/image/k_".$yeni1."");
	}
	if ($_POST["boyut1"]<>"" and $e1==1){
		$damga = imagecreatefrompng("../../../deppo/image/".$t47."");
		$oyeni = imagecreatefromjpeg("../../../deppo/image/".$yeni1."");
		
		$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/".$yeni1."";
		imagepng($oyeni, $wyeni);
		imagedestroy($oyeni);
	}

	if ($module["webp"] == 1) {
		$yeni1 = towebp($yeni1, "../../../deppo/image/");
	}
	$conn->query("insert INTO medya (ne,s1,s2,s3,s4,s13,t1,t3,t6,t2,n3) VALUES ('resim', '".$ID."', '".$ks2."', '0', '".$s4."','1', '".addslashes($yeni1)."', '".$_GET['ne']."', '".$_SESSION["lang"]."', '".$_POST['i1']."', '".$_POST['ia1']."')");
	//-------------------------------------------------------------
}
//include("../public/log.php");
?>