<?php
$path="../../";
include("../../map.php");
include("../../scripts.php");
include("../../secure.php");
if(empty($_GET["durum"])){
	?>
	<html>
	<title>File Upload</title>
	<body>
		<form class="block-content form" enctype="multipart/form-data" name="frm" method="post" action="?ne=<?php echo $_GET["ne"];?>&islem=<?php echo $_GET["islem"];?>&id=<?php echo $_GET["id"]; ?>&durum=yukle&file=<?php echo $_GET["file"]; ?>&input=<?php echo $_GET["input"]; ?>&folder=<?php echo $_GET["folder"]; ?>" onSubmit="return check(this)">
			<div class="panel panel-default">
				<div class="panel-heading">File Upload
					<div id="rsmbtny" style="display:none"><img src="../../assets/img/loading.gif"></div>
				</div>
				<div class="panel-body">
					<input class="form-control" type="text" name="dadi" placeholder="Dosya Adi Giriniz">
					<br />
					<input class="form-control" type="file" name="dosya" size="20" accept="*" onChange="document.frm.submit();show('rsmbtny');">
				</div>
			</div>
		</form>
	</body>
	</html>
	<img border="0" id="loading" src="../../assets/img/loading.gif" width="16" height="11" style="display:none; position:absolute; top:30px; right:40px;">
	<?php
}else{
	if ($_GET["ne"]=="reklam"){
		$sql=mysqli_query($conn, "select * from genel where ne='reklam' and id=".$_GET["id"].""); $rs=mysqli_fetch_assoc($sql);
		if ($_GET["input"]=="t6"){
			$dosya1="../../../deppo/rek-lam/".$rs["t6"].""; unlink($dosya1);
		}elseif ($_GET["input"]=="t16"){
			$dosya1="../../../deppo/rek-lam/".$rs["t16"].""; unlink($dosya1);
		}
	}else{
		$rne="".$_GET["ne"]."-";
		if ($_GET["input"]=="crm_background"){
			$dosya1="../../../deppo/image/".$module["crm_background"].""; unlink($dosya1);
		}
	}
	$kaydedilecekyer = "../../../deppo/".$_GET["file"]."";
	$kaynak = $_FILES['dosya']['tmp_name'];
	$uzanti = explode('.',$_FILES['dosya']['name']);
	$isim   = $_FILES['dosya']['name'];
	$rand   = substr(md5(uniqid(rand())),0,5);
	$yeni   = "".$rne."".cevir($_POST["dadi"])."".$rand.".".$uzanti[count($uzanti)-1]."";
	move_uploaded_file ($_FILES['dosya']['tmp_name'], $kaydedilecekyer . "/".$yeni);

	// WEBP dönüşümü
	if ($module["webp"] == 1) {
		$yeni = towebp($yeni, "../../../deppo/".$_GET["file"]."");
	}
	?>
	<body onLoad="don();" topmargin="0" leftmargin="0" rightmargin="0" bottommargin="0">
<?php }?>
	<script language="JavaScript">
<?php if($_GET["id"]=="" and $_GET["input"]==""){?>
		function don() {
			if (opener.document.getElementById("t4") != undefined || opener.document.getElementById("t5") != undefined) {
				opener.document.rall.t6.value = "<?php echo $yeni;?>";
			} else if (opener.document.getElementById("t6") != undefined) {
				opener.document.rall.t6.value = "<?php echo $yeni;?>";
			}
			else {
				window.opener.location.reload();
			}
			window.close();
		}
<?php }elseif($_GET["id"]<>"" and $_GET["input"]<>""){?>
		function don() {
			if (opener.document.getElementById("<?php echo $_GET["input"]?>") != undefined) {
				opener.document.rall.<?php echo $_GET["input"]?>.value = "<?php echo $yeni;?>";
			}
			else {
				window.opener.location.reload();
			}
			window.close();
		}
<?php }elseif($_GET["id"]=="" and $_GET["input"]<>""){?>
		function don() {
			opener.document.rall.<?php echo $_GET["input"]?>.value = "<?php echo $_GET["folder"];?><?php echo $yeni;?>";
			window.close();
		}
<?php }else{?>
		function don() {
			opener.document.f<?php echo $_GET["id"];?>.i<?php echo $_GET["id"];?>.value = "<?php echo $yeni;?>";
			window.close();
		}
<?php }?>
	</script>