<?php
$path="../../";
include("../../map.php");
include("../../secure.php");
if($_GET["cmd"]==""){
	include("../../scripts.php");
	?>
	<meta http-equiv="Content-Type" content="text/HTML; charset=utf-8" />
	<script type="text/javascript" src="//cdn.<?php echo $cdnurl?>/js/wpanel.js" lang="<?php echo $sdil[150];?>" id="wjs" url="<?php echo $_SERVER['SERVER_NAME'];?>" pow="<?php echo $pow1?>" ver="<?php echo $pow2?>"></script>
	<div class="panel panel-primary">
		<div class="panel-heading">Sql Operations</div>
		<div class="">
			<form action="?cmd=transfer" method="post" class="panel-body" style="padding: 5px 15px;">
				<div class="col-xs-2">
					<input name="stn1" type="text" placeholder="stn1" value="" class="form-control">
				</div>
				<div class="col-xs-2">
					<input name="stn2" type="text" placeholder="stn2" value="" class="form-control">
				</div>
				<div class="col-xs-2">
					<select name="tbl" class="form-control">
						<?php $sql = "SHOW TABLES FROM $V3Db"; $result = mysql_query($sql); while ($row = mysql_fetch_row($result)) {?>
							<option value="<?php echo $row[0];?>"><?php echo $row[0];?></option>
						<?php }?>
					</select>
				</div>
				<div class="col-xs-4">
					<input name="sql" type="text" placeholder="sql" value="" placeholder="where ?" class="form-control">
				</div>
				<div class="col-xs-2">
					<button class="btn btn-success" type="submit" style="float:right">Data Aktar</button>
				</div>
				<div style="clear:both;padding: 5px; margin-bottom:0px;" class="alert alert-warning"><i class="fa fa-info-circle" aria-hidden="true"></i> Sütunlar girilir, tablo seçilir, varsa sql koşulu yazılır</div>
			</form>
			<form action="?cmd=iupdate" method="post" class="panel-body" style="padding: 5px 15px;">
				<div class="col-xs-2">
					<input name="key" type="text" placeholder="key" value="" class="form-control">
				</div>
				<div class="col-xs-2">
					<input name="val" type="text" placeholder="val" value="" placeholder="where ?" class="form-control">
				</div>
				<div class="col-xs-2">
					<select name="tbl" class="form-control">
						<?php $sql = "SHOW TABLES FROM $V3Db"; $result = mysql_query($sql); while ($row = mysql_fetch_row($result)) {?>
							<option value="<?php echo $row[0];?>"><?php echo $row[0];?></option>
						<?php }?>
					</select>
				</div>
				<div class="col-xs-4">
					<input name="sql" type="text" placeholder="sql" value="" placeholder="where ?" class="form-control">
				</div>
				<div class="col-xs-2">
					<button class="btn btn-success" type="submit" style="float:right">Json Güncelle</button>
				</div>
				<div style="clear:both;padding: 5px; margin-bottom:0px;" class="alert alert-warning"><i class="fa fa-info-circle" aria-hidden="true"></i> jSon Key ve Value girilir, tablo seçilir, varsa sql koşulu yazılır</div>
			</form>
			<form action="?cmd=update" method="post" class="panel-body" style="padding: 5px 15px;">
				<div class="col-xs-2">
					<input name="stn1" type="text" placeholder="stn1" value="" class="form-control">
				</div>
				<div class="col-xs-2">
					<input name="val1" type="text" placeholder="val1" value="" placeholder="where ?" class="form-control">
				</div>
				<div class="col-xs-2">
					<select name="tbl" class="form-control">
						<option value="sale">İndirim %</option>
						<?php $sql = "SHOW TABLES FROM $V3Db"; $result = mysql_query($sql); while ($row = mysql_fetch_row($result)) {?>
							<option value="<?php echo $row[0];?>"><?php echo $row[0];?></option>
						<?php }?>
					</select>
				</div>
				<div class="col-xs-4">
					<input name="sql" type="text" placeholder="sql" value="" placeholder="where ?" class="form-control">
				</div>
				<div class="col-xs-2">
					<button class="btn btn-success" type="submit" style="float:right">Data Güncelle</button>
				</div>
				<div style="clear:both;padding: 5px; margin-bottom:0px;" class="alert alert-warning"><i class="fa fa-info-circle" aria-hidden="true"></i> Sütun ve değer girilir, tablo seçilir, varsa sql koşulu yazılır</div>
				<div style="clear:both;padding: 5px; margin-bottom:0px;" class="alert alert-warning"><i class="fa fa-info-circle" aria-hidden="true"></i> Yüzde indirim seçilirse val1 alanına %oranlar girilir, stn1 alanına işlenecek stn girilir.</div>
			</form>
			<form action="?cmd=delete" method="post" class="panel-body" style="padding: 5px 15px;">
				<div class="col-xs-6">
					<select name="tbl" class="form-control">
						<?php $sql = "SHOW TABLES FROM $V3Db"; $result = mysql_query($sql); while ($row = mysql_fetch_row($result)) {?>
							<option value="<?php echo $row[0];?>"><?php echo $row[0];?></option>
						<?php }?>
					</select>
				</div>
				<div class="col-xs-4">
					<input name="sql" type="text" placeholder="sql" value="" class="form-control">
				</div>
				<div class="col-xs-2">
					<button class="btn btn-success" type="submit" style="float:right">Data Sil</button>
				</div>
				<div style="clear:both;padding: 5px; margin-bottom:0px;" class="alert alert-warning"><i class="fa fa-info-circle" aria-hidden="true"></i> Tablo seçilir, varsa sql koşulu yazılır</div>
			</form>
		</div>
	</div>
	<?php
}elseif($_GET["cmd"]=="iupdate"){
	echo "<u>".$_POST["tbl"]."</u> tablosunda [<b>".$_POST["key"]."</b>] sütununa [<b>".$_POST["val"]."</b>] datası <u>".$_POST["sql"]."</u> koşul(u)(suz) ile Güncellendi <span onclick=\"history.back()\" style=\"float:right;cursor:pointer;\"><< Geri</span><hr>";
	$sqlc=mysqli_query($conn, "select * from ".$_POST["tbl"]." ".$_POST["sql"]." "); while($rsc=mysqli_fetch_assoc($sqlc)){
		$jsi = json_decode($rsc["n17"],true);
		$iarr = array();
		foreach($jsi as $key=>$value){
			if($_POST["key"]<>"" and $key==$_POST["key"]){
				$iarr = $iarr + array($_POST["key"] => $_POST["val"]);
			}else{
				$iarr = $iarr + array( $key => $value);
			}
		}
	//echo "".$rsc["id"]." => ".json_encode($iarr)."<hr>";
		$rjsi = json_encode($iarr, JSON_UNESCAPED_UNICODE | JSON_UNESCAPED_SLASHES | JSON_NUMERIC_CHECK);
		$Sqlu = mysqli_query($conn, "update ".$_POST["tbl"]." set n17='".addslashes(stripslashes($rjsi))."' where id=".$rsc["id"]."");
	}
}elseif($_GET["cmd"]=="transfer"){
	echo "<u>".$_POST["tbl"]."</u> tablosunda [<b>".$_POST["stn2"]."</b>] sütununa [<b>".$_POST["stn1"]."</b>] datası <u>".$_POST["sql"]."</u> koşul(u)(suz) ile aktarıldı <span onclick=\"history.back()\" style=\"float:right;cursor:pointer;\"><< Geri</span><hr>";
	$sqlc=mysqli_query($conn, "select * from ".$_POST["tbl"]." ".$_POST["sql"]." "); while($rsc=mysqli_fetch_assoc($sqlc)){
		$Sqlu = mysqli_query($conn, "update ".$_POST["tbl"]." set ".$_POST["stn2"]."='".$rsc[$_POST["stn1"]]."' where id=".$rsc["id"]."");
	}
}elseif($_GET["cmd"]=="update"){
	if($_POST["tbl"]=="sale"){
		$arr = explode(",",$_POST["val1"]);
		echo "<u>Ürünlere</u> [<b>".$_POST["val1"]."</b>] % oranları uygulandı <span onclick=\"history.back()\" style=\"float:right;cursor:pointer;\"><< Geri</span><hr>";
		$sqlc=mysqli_query($conn, "select * from ".$_SESSION["lang"]." ".$_POST["sql"]." "); while($rsc=mysqli_fetch_assoc($sqlc)){
			$rand_keys = array_rand($arr, 2);
			echo "".$rsc["t1"]." => ".$rsc["pb1"]." > ".round($rsc["pb1"]*(($arr[$rand_keys[0]]+100)/100))." - %".$arr[$rand_keys[0]]."<br>";		
			$pbx=round($rsc["pb1"]*(($arr[$rand_keys[0]]+100)/100));
			$Sqlu = mysqli_query($conn, "update ".$_SESSION["lang"]." set ".$_POST["stn1"]."='".$pbx."' where id=".$rsc["id"]."");
		}
		
	}else{
		$sqlc=mysqli_query($conn, "select * from ".$_POST["tbl"]." ".$_POST["sql"]." "); while($rsc=mysqli_fetch_assoc($sqlc)){
			$Sqlu = mysqli_query($conn, "update ".$_POST["tbl"]." set ".$_POST["stn1"]."='".$_POST["val1"]."' where id=".$rsc["id"]."");
		}
		echo "<u>".$_POST["tbl"]."</u> tablosunda [<b>".$_POST["stn1"]."</b>] datası [<b>".$_POST["val1"]."</b>] olarak <u>".$_POST["sql"]."</u> koşul(u)(suz) ile güncellendi <span onclick=\"history.back()\" style=\"float:right;cursor:pointer;\"><< Geri</span><hr>";
	}
}elseif($_GET["cmd"]=="delete"){
	echo "<u>".$_POST["tbl"]."</u> tablosundaki data(lar) <u>".$_POST["sql"]."</u> koşulu/koşulsuz ile silindi <span onclick=\"history.back()\" style=\"float:right;cursor:pointer;\"><< Geri</span><hr>";
	if($_POST["tbl"]<>"medya"){
		$sqlc=mysqli_query($conn, "select * from ".$_POST["tbl"]." ".$_POST["sql"]." "); while($rsc=mysqli_fetch_assoc($sqlc)){
			if($_POST["tbl"]=="kategoriler"){
				$sql = mysqli_query($conn, "delete from ".$_POST["tbl"]." where Cat_ID=".$rsc["Cat_ID"]."");
			}else{
				for ($l = 1; $l <= $lx; $l++) {$sql = mysqli_query($conn, "delete from ".$_POST["tbl"]." where id=".$rsc["id"]."");}
					$sql=mysqli_query($conn, "select * from medya where ne='resim' and s1=".$rsc["id"].""); while($rsi=mysqli_fetch_assoc($sql)){
						$dosya1="../../../deppo/image/".$rsi["t1"]."";
						unlink($dosya1);
						$dosya2="../../../deppo/image/k_".$rsi["t1"]."";
						unlink($dosya2);
						$sqld = mysqli_query($conn, "delete from medya where s1=".$rsc["id"]."");
					}
				}
			}
		}else{
			$sqlm=mysqli_query($conn, "select * from ".$_POST["tbl"]." ".$_POST["sql"]." "); while($rsm=mysqli_fetch_assoc($sqlm)){
				$dosya1="../../../deppo/image/".$rsm["t1"]."";
				unlink($dosya1);
				$dosya2="../../../deppo/image/k_".$rsm["t1"]."";
				unlink($dosya2);
				$dosya3="../../../deppo/video/".$rsm["n2"]."";
				unlink($dosya3);
				$sqld = mysqli_query($conn, "delete from medya where id=".$rsm["id"]."");
			}
		}
	}
	?>