<?php
$path="../../";
include("../../map.php");
include("../../scripts.php");
include("../../secure.php");
include("../../../deppo/tools/script/SimpleImage.php");
if($_GET["durum"]==""){
	$sql=mysqli_query($conn, "select * from medya where id=".$_GET["mid"].""); $rs=mysqli_fetch_assoc($sql);
	if ($rs["ne"]=="resim"){
		$q="g";
		$ok="2";
		$medya="Resim";
	}elseif ($rs["ne"]=="video"){
		$q="v";
		$ok="3";
		$medya="Video";
	}elseif ($rs["ne"]=="dosya"){
		$q="d";
		$ok="4";
		$medya="Dosya";
	}
//------------------------------------------------------#Youtube izle----->
	$vcevir0 = array('/v/','?version=3&amp;autohide=1');
	$vcevir1 = array('/embed/','');
//------------------------------------------------------#Youtube izle---->
	?>
	<html>
	<head>
		<meta http-equiv="Content-Language" content="tr">
	</head>
	<body>
		
		<form method="POST" id="reform" enctype="multipart/form-data" name="frm" action="?ne=<?php echo $_GET["ne"];?>&islem=<?php echo $_GET["islem"];?>&nedir=<?php echo $_GET["nedir"];?>&durum=<?php if ($_GET["nedir"] == "dosya") { echo "fedit"; } elseif ($_GET["nedir"] == "video") { echo "vedit"; } else { echo "medit"; } ?>&id=<?php echo $_GET["id"];?>&mid=<?php echo $_GET["mid"];?>">
			<input type="hidden" name="t1" value="<?php echo $rs["t1"];?>">
			<div class="panel panel-default">
				<div class="panel-heading"><?php echo $medya;?> <?php echo $sdil[199]; //Düzenle?> <span style="float:right;"><?php echo dtarih($rs["ts1"],"gg ua yyyy")?></span><?php if ($rs["ne"]=="video"){?><a title="Videoyu Kaynağından Güncelle" href="?ne=<?php echo $_GET["ne"];?>&islem=<?php echo $_GET["islem"];?>&nedir=<?php echo $_GET["nedir"];?>&durum=vup&id=<?php echo $_GET["id"];?>&mid=<?php echo $_GET["mid"];?>&v=<?php echo $rs["t7"]?>" style="float: right; margin-right: 10px; font-size: 18px;" class="fa-solid fa-arrows-rotate"></a><?php }?></div>
				<div class="panel-body">
					<div id="i1" style="min-height:18px; padding:5px; margin-top:-15px; position:relative;">
						<?php if($rs["ne"]=="resim"){ ?>
							<div style="width:100%; height:250px; overflow:hidden; margin-bottom:10px;"><img src="../../../deppo/image/<?php echo $rs['t1']; ?>" style="width:100%; height:100%; object-fit:cover;"></div>
						<?php }elseif($rs["ne"]=="video"){ ?>
							<div style="width:100%; height:250px; overflow:hidden; margin-bottom:10px;"><img src="../../../deppo/video/<?php echo $rs["n2"];?>" style="width:100%; height:100%; object-fit:cover;"></div>
						<?php }?>
<!--
						<?php if($rs["ne"]=="dosya"){ ?>
							<label><?php echo ctranslate("Dosya")?></label>
							<input type="file" name="dosya1" accept="*" class="form-control" style="width:93%; float:left; margin-right:5px;"/>
						<?php }?>
						<label style="display:block;clear:both;"><?php echo ctranslate("Resim")?></label>
						<input id="r1" type="file" name="resim1" accept="*" class="form-control" onchange="document.frm.durum1.checked=true;"  style="width:93%; float:left; margin-right:5px;"/>
						<div style="float:right;">
							<?php if($a5<>0){?>
								<input type="checkbox" name="boyut1" value="ON" style="float:left; margin-left:5px;" title="Boyutlandır" checked id="boyut1" class="mini-switch">
								<label for="boyut1"></label>
							<?php }?>
						</div>
-->
						<div style="clear:both; margin-top:5px;"></div>
						<input type="text" name="t2" class="form-control" style="width:87%; float:left; margin-right:5px;" placeholder="Isim" title="İsim (t2)" value="<?php echo $rs["t2"];?>">
						<input type="text" name="s3" class="form-control" style="width:35px; float:left; margin-top:0px; margin-right:5px;" placeholder="0" value="<?php echo $rs["s3"];?>"  title="Sıra (s3)">
						<div style="float:right;">
							<input type="checkbox" class="mini-switch" id="bs2" name="s2" value="1" style="float:left; margin-top:0px;" <?php if($rs["s2"]<>"0"){?>Checked<?php }?> title="Seçili (s2)">
							<label for="bs2"></label>
						</div>
						
						<div style="clear:both;"></div>
						<textarea name="n3" id="n3" class="form-control" placeholder="<?php echo $sdil[40]; //Kısa?>" title="<?php echo $sdil[40]; //Kısa?> (n3)" style="margin-top:5px;"><?php echo $rs["n3"];?></textarea>
						<textarea name="n4" id="n4" class="form-control" placeholder="Keywords" title="Keywords (n4)" style="margin-top:5px;"><?php echo $rs["n4"];?></textarea>
						<div style="clear:both;"></div>
						<input type="text" name="t5" class="form-control" style="margin-right:5px; margin-top:5px;" placeholder="#ext" title="#ext (t5)" value="<?php echo $rs["t5"];?>">
						<div class="row" style="margin-top:5px;">
							<div class="col-xs-8">
								<input type="text" name="t4" id="n5" list="ln5" style="margin-right:10px;" class="form-control" value="<?php echo $rs["t4"];?>" placeholder="http://www.">
								<datalist id="ln5" style="display: none;"></datalist>
							</div>
							<div class="col-xs-4">
								<select size="1" name="n6" style="" class="form-control">
									<option value="<?php echo $rs["n6"];?>"> <?php if($rs["n6"]==""){echo "Target";}else{echo $rs["n6"];}?> </option>
									<option value="_self" >_self</option>
									<option value="_blank" >_blank</option>
									<option value="_top" >_top</option>
								</select>
							</div>
						</div>
						<div style="clear:both; height:5px;"></div>
					</div>
				</div>
				<div class="panel-heading">Grup</div>
				<div class="panel-body">
					<div class="col-xs-4">
						<select size="1" name="s1" style="width:100%;" title="(s1)" class="v3-form-control">
							<option value="0">[0]<?php echo $sdil[221]; //Lütfen Seçiniz?></option>
							<?php $sqll = mysqli_query($conn, "select * from ".$_SESSION['lang']." where ne='".$_GET["ne"]."'" ); while($rsl=mysqli_fetch_assoc($sqll)){?>
								<option value="<?php echo $rsl["id"];?>" <?php if($rsl["id"]==$rs["s1"]){?>Selected<?php }?>>[<?php echo $rsl["id"];?>] <?php echo $rsl["t1"];?></option>
							<?php }?>
						</select>
					</div>
					<div class="col-xs-4">
						<select size="1" name="s4" style="width:100%;" title="Grup (s4)" class="v3-form-control">
							<option value="0" <?php if($rs["s4"]=="0"){?>Selected<?php }?>>[0]<?php echo $sdil[221]; //Lütfen Seçiniz?></option>
							<?php if($m4<>""){$rgrups = explode(',',$m4); foreach($rgrups as $rgrup) {$g++;?>
								<option value="<?php echo $g;?>" <?php if($rs["s4"]==$g){?>Selected<?php }?>>[<?php echo $g;?>] <?php echo $rgrup;?></option>
							<?php }}?>
							<?php if ($rs["ne"]=="dosya"){?>
								<option value="1" <?php if($rs["s4"]==1){?>Selected<?php }?>>[1] Grup-1</option>
								<option value="2" <?php if($rs["s4"]==2){?>Selected<?php }?>>[2] Grup-2</option>
								<option value="3" <?php if($rs["s4"]==3){?>Selected<?php }?>>[3] Grup-3</option>
								<option value="4" <?php if($rs["s4"]==4){?>Selected<?php }?>>[4] Grup-4</option>
								<option value="5" <?php if($rs["s4"]==5){?>Selected<?php }?>>[5] Grup-5</option>
							<?php }?>
							<?php if($module["g1_".$_GET["ne"].""]=="1"){?>
								<?php $sql=mysqli_query($conn, "select * from t1 where ne='isayfa' and (t2='".$_SESSION['lang']."' or t2='All') and s1=".$_GET["id"]." order by s2 asc"); while($xn=mysqli_fetch_assoc($sql)){?>
									<option value="<?php echo $xn["id"];?>" <?php if($rs["s4"]==$xn["id"]){?>Selected<?php }?>>[<?php echo $xn["id"];?>] <?php echo $xn["t1"];?></option>
								<?php }}?>
							</select>
						</div>
						<div class="col-xs-2">
							<select size="1" name="t6" style="width:100%;" title="Konum (t6)" class="v3-form-control">
								<option value="All" <?php if($rs["t6"]==""){?>Selected<?php }?>>All</option>
								<?php $d=0; $diller = explode(',',$m1); foreach($diller as $dil) {$d++;?>
									<option value="<?php echo "lang".$d."";?>" <?php if($rs["t6"]=="lang".$d.""){?>Selected<?php }?>>[<?php echo "lang".$d."";?>] <?php echo $dil;?></option>
								<?php }?>
							</select>
						</div>
						<div class="col-xs-2">
							<?php if($rs["ne"]<>"dosya"){ ?>
								<select size="1" name="t7" style="width:100%;" title="Responsive (t7)" class="v3-form-control">
									<option value="All" <?php if($rs["t7"]==""){?>Selected<?php }?>>All</option>
									<option value="Desktop" <?php if($rs["t7"]=="Desktop"){?>Selected<?php }?>>Desktop</option>
									<option value="Tablet" <?php if($rs["t7"]=="Tablet"){?>Selected<?php }?>>Tablet</option>
									<option value="Mobile" <?php if($rs["t7"]=="Mobile"){?>Selected<?php }?>>Mobile</option>
								</select>
							<?php }?>
						</div>
					</div>
					
					<div class="panel-heading"><?php echo $sdil[213]; //İşlemler?></div>
					<div class="panel-body">
						<button type="submit" style="float:right; margin-right:10px;" id="btn" onClick="show('loading');hide('btn');" class="btn btn-primary"><?php echo $sdil[203]; //Güncelle?></button>
						<button type="submit" style="float:right; margin-right:10px; display:none;" id="loading" disabled class="btn btn-primary"><img src="../../assets/img/loading.gif"> Yükleniyor</button>
					</div> 
					
				</div>
			</form>
		</body>
		</html>
		<?php
	}elseif($_GET["durum"] == "medit"){
		if($_POST["s1"]<>0){ $s1=$_POST["s1"]; }else{ $s1=$rs["s1"]; }
		if($_POST["s2"]<>0){ $s2=$_POST["s2"]; }else{ $s2=0; }
		if($_POST["s3"]<>0){ $s3=$_POST["s3"]; }else{ $s3=0; }
		if($_POST["s4"]<>0){ $s4=$_POST["s4"]; }else{ $s4=0; }
		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"])));
		}
		$kaydedilecekyer = "../../../deppo/image";
		if (!empty($_FILES['resim1']['name'])){
		$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  = "--".$risim."-".$rand1.".".$uzanti1[count($uzanti1)-1]."";
		unlink("../../../deppo/image/".$_POST["t1"]."");
		move_uploaded_file ($_FILES['resim1']['tmp_name'], $kaydedilecekyer . "/".$yeni1);
		$Rs = mysqli_query($conn, "update medya set t1='".$yeni1."' Where id=".$_GET["mid"]." ");
		//-------------------------------------------------------------
		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/".$t50."");
			$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);
		}
	}
	$Rs = mysqli_query($conn, "update medya set t2='".addslashes($_POST["t2"])."', t4='".addslashes($_POST["t4"])."', t5='".addslashes($_POST["t5"])."', t6='".$_POST["t6"]."', t7='".$_POST["t7"]."', n3='".addslashes($_POST["n3"])."', n4='".addslashes($_POST["n4"])."', n6='".addslashes($_POST["n6"])."', s1='".$s1."', s2='".$s2."', s3='".$s3."', s4='".$s4."' Where id=".$_GET["mid"]." ");
	echo location("?ne=".$_GET["ne"]."&islem=".$_GET["islem"]."&id=".$_GET["id"]."&nedir=".$_GET["nedir"]."&mid=".$_GET["mid"]."&durum=".$ok."",self,1,1);

}elseif ($_GET["durum"]=="fedit"){
	if($_POST["s1"]<>0){ $s1=$_POST["s1"]; }else{ $s1=$rs["s1"]; }
	if($_POST["s2"]<>0){ $s2=$_POST["s2"]; }else{ $s2=0; }
	if($_POST["s3"]<>0){ $s3=$_POST["s3"]; }else{ $s3=0; }
	if($_POST["s4"]<>0){ $s4=$_POST["s4"]; }else{ $s4=0; }
	$kaydedilecekyer = "../../../deppo/dosya";
	$dkaynak = $_FILES['dosya']['tmp_name'];	//Burasi resminiz kök klasörünün yerini verir  
	$dtipi	 = $_FILES['dosya']['type']; // Dosyanin Tipi
	$dadi	 = $_FILES["dosya"]["name"]; // Dosyanin PCdeki Adi
	$duzanti = explode('.',$_FILES['dosya']['name']);
	$drand   = substr(md5(uniqid(rand())),0,10); 
	$dyeni   = "".$isim."-".$drand.".".$duzanti[count($duzanti)-1]."";
	move_uploaded_file ($_FILES['dosya']['tmp_name'], $kaydedilecekyer . "/".$dyeni);
	if (!empty($_FILES['resim1']['name'])) {
		$rkaynak = $_FILES['resim1']['tmp_name'];	//Burasi resminiz kök klasörünün yerini verir
		$rtipi	 = $_FILES['resim1']['type']; // Dosyanin Tipi
		$radi	 = $_FILES["resim1"]["name"]; // Dosyanin PCdeki Adi
		$ruzanti = explode('.',$_FILES['resim1']['name']);
		$rrand   = substr(md5(uniqid(rand())),0,10); 
		$ryeni   = "".$isim."-".$rrand.".".$ruzanti[count($ruzanti)-1]."";
		move_uploaded_file ($_FILES['resim1']['tmp_name'], $kaydedilecekyer . "/".$ryeni);
		$Rs = mysqli_query($conn, "update medya set t5='".$ryeni."' Where id=".$_GET["mid"]." ");
	}
	if (!empty($_FILES['dosya1']['name'])) {
		$kaydedilecekyer = "../../../deppo/dosya";
		$dkaynak = $_FILES['dosya1']['tmp_name'];	//Burasi resminiz kök klasörünün yerini verir  
		$dtipi	 = $_FILES['dosya1']['type']; // Dosyanin Tipi
		$dadi	 = $_FILES["dosya1"]["name"]; // Dosyanin PCdeki Adi
		$duzanti = explode('.',$_FILES['dosya1']['name']);
		$drand   = substr(md5(uniqid(rand())),0,10); 
		$dyeni   = "".$isim."-".$drand.".".$duzanti[count($duzanti)-1]."";
		move_uploaded_file ($_FILES['dosya1']['tmp_name'], $kaydedilecekyer . "/".$dyeni);
		$Rs = mysqli_query($conn, "update medya set t1='".$dyeni."' Where id=".$_GET["mid"]." ");
	}
	$Rs = mysqli_query($conn, "update medya set t2='".addslashes($_POST["t2"])."', t6='".$_POST["t6"]."', t7='".$_POST["t7"]."', n3='".addslashes($_POST["n3"])."', n4='".addslashes($_POST["n4"])."', n6='".addslashes($_POST["n6"])."', s1='".$s1."', s2='".$s2."', s3='".$s3."', s4='".$s4."' Where id=".$_GET["mid"]." ");
	echo location("?ne=".$_GET["ne"]."&islem=".$_GET["islem"]."&id=".$_GET["id"]."&nedir=".$_GET["nedir"]."&mid=".$_GET["mid"]."&durum=".$ok."",self,1,1);

}elseif ($_GET["durum"]=="vedit"){
	if($_POST["s1"]<>0){ $s1=$_POST["s1"]; }else{ $s1=$rs["s1"]; }
	if($_POST["s2"]<>0){ $s2=$_POST["s2"]; }else{ $s2=0; }
	if($_POST["s3"]<>0){ $s3=$_POST["s3"]; }else{ $s3=0; }
	if($_POST["s4"]<>0){ $s4=$_POST["s4"]; }else{ $s4=0; }
	preg_match('~v=([^&]+)~', $_POST["t4"], $m);
	$videoId = $m[1] ?? '';

	$Rs = mysqli_query($conn, "update medya set t2='".addslashes($_POST["t2"])."', t4='".addslashes($_POST["t4"])."', t6='".$_POST["t6"]."', t7='".$videoId."', n3='".addslashes($_POST["n3"])."', n4='".addslashes($_POST["n4"])."', n6='".addslashes($_POST["n6"])."', s1='".$s1."', s2='".$s2."', s3='".$s3."', s4='".$s4."' Where id=".$_GET["mid"]." ");
	echo location("?ne=".$_GET["ne"]."&islem=".$_GET["islem"]."&id=".$_GET["id"]."&nedir=".$_GET["nedir"]."&mid=".$_GET["mid"]."&durum=".$ok."",self,1,1);

}elseif ($_GET["durum"]=="vup"){

    // 3️⃣ Yeni video verilerini çek
    include("../video/video_bot.php");

    // 1️⃣ Mevcut kaydı al (eski görsel için)
   $old = mysqli_fetch_assoc( mysqli_query($conn,"SELECT n2 FROM medya WHERE id=".$_GET["mid"]." LIMIT 1") );

    // 2️⃣ Eski görseli sil
    if(!empty($old["n2"])){
        $oldFile = "../../../deppo/video/".$old["n2"];
        if(file_exists($oldFile)){ unlink($oldFile); }
        // eski webp varsa
        $oldWebp = preg_replace('/\.(jpg|jpeg|png)$/i','.webp',$oldFile);
        if(file_exists($oldWebp)){ unlink($oldWebp); }
    }

    // 4️⃣ Yeni görseli indir
    file_put_contents("../../../deppo/video/".$vis, file_get_contents($vres));

    // 5️⃣ WEBP dönüşümü
    if ($module["webp"] == 1) { $vis = towebp($vis, "../../../deppo/video/");}

    // 6️⃣ UPDATE
    mysqli_query($conn," UPDATE medya SET t2='".val($vtit)."', n3='".addslashes(val($vdes))."', n2='".$vis."' WHERE id=".$_GET["mid"]." ");
    echo location("?ne=".$_GET["ne"]."&islem=".$_GET["islem"]."&id=".$_GET["id"]."&nedir=".$_GET["nedir"]."&mid=".$_GET["mid"]."&durum=".$ok."",self,1,1);

}
echo $footer;
?>
<?php include("../public/log.php");?>