<?php
$path="../../../";
if(file_exists("".$path."config/map.php" )){$path2="config/"; include("".$path."config/map.php");}else{include("".$path."map.php");}
include("fonksiyon".$ver.".php");
include("SimpleImage.php");
echo $_GET["cmd"];
?>
<style>
.form-control {border:0px !important; border-left:2px solid #ccc !important; box-shadow: unset !important; border-radius:0px !important;}
</style>
<?php if($_GET["cmd"]==""){?>
	<div class="v3-panel-body">
		<div class="v3-row" style="clear:both; margin-top:15px;">
			<?php $sqlm=mysqli_query($conn, "select * from medya where (ne='resim' or ne='video' or ne='dosya') and s1=".$_GET["s1"].""); while($rsm=mysqli_fetch_assoc($sqlm)){?>
				<div class="v3-col-xs-6 v3-col-md-3" style="" id="b<?php echo $rsm["id"];?>">
					<div class="v3-thumbnail" style="overflow:hidden;height:200px;position:relative; <?php if($rsm["ne"]=="dosya"){echo "background: lightgrey";}?>">
							<a href="<?php echo $weburl;?>/deppo/tools/script/medya.php?ne=<?php echo $_GET["ne"];?>&id=<?php echo $_GET["s1"];?>&cmd=msec&mid=<?php echo $rsm["id"];?>&onay=<?php if($rsm["s2"]!=1){echo "1";}else{echo "0";}?>" onclick="toggle('.off<?php echo $rsm["id"]?>');toggle('.on<?php echo $rsm["id"]?>')" target="islem" style="position: absolute; right: 10px; font-size:20px; float:right;margin: 0px;" title="Vitrin"><i class="text-warning fa fa-square off<?php echo $rsm["id"]?>" style="<?php if($rsm["s2"]==1){echo "display:none;";}?>"></i><i class="text-success  fa fa-check-square on<?php echo $rsm["id"]?>" style="<?php if($rsm["s2"]!=1){echo "display:none;";}?>"></i></a>
							<?php if($rsm["ne"]=="resim"){?>
								<div style="background-image:url(<?php echo $weburl;?>/deppo/image/<?php echo $rsm["t1"];?>); width: 100%; height: -webkit-fill-available; background-size: contain; background-position: center; background-repeat: no-repeat;" alt="<?php echo $rsm["t2"];?>"></div>
							<?php }elseif($rsm["ne"]=="video"){?>
								<embed src="<?php echo $rsm["n1"];?>" style="width:100%; height:185px;">
							<?php }elseif($rsm["ne"]=="dosya"){?>
								<a href="<?php echo $weburl;?>/deppo/dosya/<?php echo $rsm["t1"]?>" target="_blank">
									<center><i class="far fa-file-<?php echo $rsm["t4"];?>" style="font-size: 120px; color:grey; position: absolute; top: 30px; margin-left: -50px;"></i></center>
								</a>
							<?php }?>
							<div class="v3-caption" style="padding: 5px; position: absolute; left: 0px; bottom: 0px; width: 100%; background: #fff3cdc9;">
								<a href="<?php echo $weburl;?>/deppo/tools/script/medya.php?ne=<?php echo $_GET["ne"];?>&id=<?php echo $_GET["s1"];?>&cmd=<?php echo $rsm["ne"][0]?>sil&<?php echo $rsm["ne"][0]?>id=<?php echo $rsm["id"];?>" onClick="toggle('#b<?php echo $rsm["id"];?>')" target="islem" class="fa fa-trash-o" style="color:red; font-size:15px; margin-top:2px; float: right;"  title="Medya Sil" ></a>
								<form id="of<?php echo $rsm["id"]?>" action="<?php echo $weburl;?>/deppo/tools/script/medya.php?ne=<?php echo $_GET["ne"];?>&id=<?php echo $_GET["s1"];?>&cmd=order&mid=<?php echo $rsm["id"];?>" target="islem" method="post" style="display: inline-block; margin-right: 5px; float: right;">
									<input type="text" name="s3" value="<?php echo $rsm["s3"]?>" style="width: 34px; border:solid 1px grey; border-radius: 5px; text-align: center; height: 18px; font-size: 11px; padding: 0px;" onchange="jQuery('#of<?php echo $rsm["id"]?>').submit();">
								</form>
								<div style="position:absolute; bottom:-10px; height:35px; z-index:9999999999; font-size:12px;"><?php echo kisalt($rsm["t2"],3);?></div>
							</div>
						</div>
					</div>
				<?php }?>
			</div>
		</div>
	<?php }elseif($_GET["cmd"]=="resim"){?>
		<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.2/css/bootstrap.min.css">
		<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/font-awesome/4.3.0/css/font-awesome.min.css">
		<form method="POST" name="frm" enctype="multipart/form-data" action="?cmd=ryukle&ne=<?php echo $_GET["ne"];?>&islem=<?php echo $_GET["islem"];?>&id=<?php echo $_GET["id"];?>">
			<div class="panel panel-<?php if($_GET["durum"]==ok){?>success<?php }else{?>default<?php }?>">
				<div class="panel-heading"><?php echo $sdil[127]; //medya?>
				<?php if($_GET["durum"]==ok){?>
					#<?php echo $sdil[103]; //islem Basariyla Gerçeklestirilmistir !?>
				<?php }?>
			</div>
			<div class="panel-body">
				<label>Medya <span style="font-size:8px; color:#ccc;">(t1)</span></label>
				<input type="file" class="form-control" name="medya" accept="*"/>
				<input type="text" name="t2" class="form-control with-tip" title="Adı (t2)" placeholder="Adı" style="margin-top:5px;">
				<textarea name="n3" rows="2" class="form-control with-tip" title="Açıklama (n3)" style="margin-top:5px;"  placeholder="Açıklama"></textarea>
				<?php if($m4<>""){?>
					<select size="1" class="form-control" name="s4" style="margin-top:5px;">
						<option value="0">[0] Grup Seçiniz</option>
						<?php if($m4<>""){ $rgrups = explode(',',$m4); foreach($rgrups as $rgrup) {$g++;?>
							<option value="<?php echo $g;?>">[<?php echo $g;?>] <?php echo $rgrup;?></option>
						<?php }}?>
					</select>
				<?php }?>
				<button type="submit" style="float:right; margin-right:10px; margin-top:5px;" id="btn" class="btn btn-primary" onclick="show('dbtn'); hide('btn');">Kaydet</button>
				<button type="submit" style="float:right; margin-right:10px; margin-top:5px; display: none;" id="dbtn" class="btn btn-primary" disabled="">Yükleniyor...</button>
			</div>
		</div>
	</form>
<?php }elseif($_GET["cmd"]=="video"){?>
	<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.2/css/bootstrap.min.css">
	<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/font-awesome/4.3.0/css/font-awesome.min.css">
	<form method="POST" name="frm" action="?cmd=vyukle&ne=<?php echo $_GET["ne"];?>&islem=<?php echo $_GET["islem"];?>&id=<?php echo $_GET["id"];?>">
		<div class="panel panel-<?php if($_GET["durum"]==ok){?>success<?php }else{?>default<?php }?>">
			<div class="panel-heading"><?php echo $sdil[128]; //medya?>
			<?php if($_GET["durum"]==ok){?>
				#<?php echo $sdil[103]; //islem Basariyla Gerçeklestirilmistir !?>
			<?php }?>
		</div>
		<div class="panel-body">
			<label>Medya <span style="font-size:8px; color:#ccc;">(t1)</span></label>
			<input type="text" class="form-control" name="video" placeholder="Video Url"/>
			<input type="text" name="t2" class="form-control with-tip" title="Adı (t2)" placeholder="Adı" style="margin-top:5px;">
			<textarea name="n3" rows="2" class="form-control with-tip" title="Açıklama (n3)" style="margin-top:5px;"  placeholder="Açıklama"></textarea>
			<button type="submit" style="float:right; margin-right:10px; margin-top:5px;" id="btn" class="btn btn-primary">Kaydet</button>
		</div>
	</div>
</form>
<?php
}elseif($_GET["cmd"]=="dosya"){
}elseif($_GET["cmd"]=="ryukle"){
	if(!empty($_GET["id"])){$_GET["id"]=$_GET["id"];}else{$_GET["id"]="0";}
	$kaydedilecekyer = "../../image";
	$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";}
	$kaynak= $_FILES['medya']['tmp_name'];	//Burası resminiz kök klasörünün yerini verir  
	$tipi	= $_FILES['medya']['type']; // Dosyanın Tipi
	$adi	= $_FILES["medya"]["name"]; // Dosyanın PCdeki Adı
	$uzanti = explode('.',$_FILES['medya']['name']);
	$rand  = substr(md5(uniqid(rand())),0,10); 
	$yeni  = "".$rand.".".$uzanti[count($uzanti)-1]."";
	if($_POST["s4"]==""){$ks4="0";}else{$ks4="1";}
	move_uploaded_file ($_FILES['medya']['tmp_name'], $kaydedilecekyer . "/".$yeni);
	$conn->query("insert INTO medya (ne,s1,s2,s3,s4,t1,t3,t2,n3) VALUES ('resim','".$_GET["id"]."', '".$ks2."', '0', '".$ks4."', '".addslashes($yeni)."', '".$_GET['ne']."', '".$_POST['t2']."', '".$_POST['n3']."')");
	$image = new SimpleImage();
	$image->load("".$kaydedilecekyer."/".$yeni."");
	$image->resizeToWidth("".$a9."");
	$image->save("".$kaydedilecekyer."/".$yeni."");
	$image->resizeToWidth("".$a10."");
	$image->save("".$kaydedilecekyer."/k_".$yeni."");
	if ($e1==1){
		$damga = imagecreatefrompng("".$kaydedilecekyer."/".$t47."");
		$oyeni = imagecreatefromjpeg("".$kaydedilecekyer."/".$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 = "".$kaydedilecekyer."/".$yeni."";
		imagepng($oyeni, $wyeni);
		imagedestroy($oyeni);
	}
	echo location("?ne=".$_GET["ne"]."&islem=".$_GET["islem"]."&id=".$_GET["id"]."&cmd=resim&durum=ok",self,1,1);
}elseif($_GET["cmd"]=="vyukle"){
	include("../../../crmplus/video_bot.php");
	$s1=$_GET["id"];
	if(!empty($_POST["s3"])){$s3=$_POST["s3"];}else{$s3="0";}
	if(!empty($_POST["s5"])){$s5=$_POST["s5"];}else{$s5="0";}
	if ($_POST["t1"]==""){$vadi=str_replace($degis2, $degis3, $vtitle);}else{$vadi=$_POST["t1"];}
	$_GET["ne"]=$_GET["ne"];
	$sqlk=mysqli_query($conn, "select * from medya where ne='video' and t3='".$_GET['ne']."' and s1='".$_GET['id']."'"); $rski=mysqli_fetch_assoc($sqlk);
	if(mysqli_num_rows($sqlk)>0){$ks2="0";}else{$ks2="1";}
	$sql = $conn->query("insert into medya (ne,s1,s2,s3,s4,s5,n1,n2,n3,n4,t1,t3,t4) values ('video','".$s1."', '".$ks2."', '".$s3."', '0', '".$s5."', '".$vvid."', '".$vres."', '".$_POST["n3"]."', '".$vurl."', '".$vadi."', '".$_GET["ne"]."', '".$vurl."')");
	echo location("?ne=".$_GET["ne"]."&islem=".$_GET["islem"]."&id=".$_GET["id"]."&cmd=video&durum=ok",self,1,1);
}elseif($_GET["cmd"]=="order"){
	echo $_GET["mid"];
	$Sql = mysqli_query($conn, "update medya set s3='".$_POST["s3"]."' where id=".$_GET["mid"]."");
}elseif($_GET["cmd"]=="msec"){
	$Sql = mysqli_query($conn, "update medya set s2='".$_GET["onay"]."' where id=".$_GET["mid"]."");
}elseif($_GET["cmd"]=="rsil"){
	$sql=mysqli_query($conn, "select * from medya where ne='resim' and id=".$_GET["rid"].""); $rs=mysqli_fetch_assoc($sql);
	$dosya1="../deppo/image/".$rs["t1"]."";unlink($dosya1);
	$dosya2="../deppo/image/k_".$rs["t1"]."";unlink($dosya2);
	$Rs = mysqli_query($conn, "delete from medya where id=".$_GET["rid"]);
}elseif($_GET["cmd"]=="vsil"){
	$Rs = mysqli_query($conn, "delete from medya where id=".$_GET["vid"]);
}
?>