<?php
$path="../../";
include("../../map.php");
include("../../secure.php");
$ucats = json_decode(GetArr("u","categories"), true);
if($_GET["cmd"]==""){
	include("../../scripts.php");
?>
<style>
.btn-success{width:50%}
</style>
	<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"><?php echo ctranslate("Toplu Güncelle");?></div>
		<div class="">
			<form action="?cmd=kampanya" method="post" class="panel-body" style="padding: 5px 15px; margin-top:15px;">
				<div class="col-xs-4">
					<input name="val1" type="text" placeholder="% / Tutar" value="" class="form-control">
				</div>
				<div class="col-xs-4">
					<select name="sts" class="form-control">
						<option value="mu">Tutar Artış</option>
						<option value="md">Tutar İndirim</option>
						<option value="pu">Yüzde Artış</option>
						<option value="pd">Yüzde İndirim</option>
					</select>
				</div>
				<div class="col-xs-4">
					<select name="cat" class="form-control">
							<option value="0">Tüm</option>
							<?php
							if($a4<>0){
								foreach($ucats as $xkey=>$xvalue){
									if($xvalue["ne"]=="ukategori" or ($xvalue["t1"]=="kayit" and $xvalue["s1"]==0)){
										?>
										<option class="c0" value="<?php echo $xvalue["id"];?>" title="<?php echo $xvalue["item"];?>" style="color:#6699FF" <?php foreach($s2S as $s2){if($s2==$xvalue["id"]){echo "selected";}}?>>+ <?php echo ctranslate($xvalue["item"]);?> [<?php echo $xvalue["id"];?>]</option>
										<?php foreach($ucats as $ykey=>$yvalue){?>
											<?php if((($yvalue["ne"]=="ualt_kategori") and $yvalue["c1"]=="".$xvalue["id"]."") or (($yvalue["t1"]=="kayit" and $yvalue["s1"]=="".$xvalue["id"]."") and $yvalue["s2"]==0)){?>
												<option class="c1" value="<?php echo $yvalue["item"];?>" title="<?php echo $yvalue["item"];?>" style="color:#6699FF" <?php foreach($s2S as $s2){if($s2==$yvalue["id"]){echo "selected";}}?>>- <?php echo ctranslate($yvalue["item"]);?> [<?php echo $yvalue["id"];?>]</option>
												<?php }}?>
											<?php }?>
										</optgroup>
									<?php }?>
							<?php }?>
					</select>
				</div>
				<div class="col-xs-8" style="<?php if($MSA<>1){echo "display:none;";}?>margin-top:15px;">
					<input name="sql" type="text" placeholder="Sql" value="<?php if($_GET["ne"]=="kayit"){echo "where ne='kayit'";}?>" class="form-control">
				</div>
				<div class="col-xs-4" style="margin-top:15px;">
					<button class="btn btn-success" type="submit" style="float:right">Uygula</button>
				</div>
				<div style="padding: 5px; margin-bottom:0px;margin-top:100px;" 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>
			</form>
		</div>
	</div>
<?php
}elseif($_GET["cmd"]=="kampanya"){
	if($_POST["cat"]<>0){ $usql = " and s10='".$_POST["cat"]."' or s9='".$_POST["cat"]."'"; }
	$i=0;$sqlc=mysqli_query($conn, "select * from ".$_SESSION["lang"]." ".$_POST["sql"]." ".$usql.""); while($rsc=mysqli_fetch_assoc($sqlc)){$i++;
		if(substr($_POST["sts"],0,1)=="p"){
			$doran = ((100 - $_POST["val1"]) / 100);
			$uoran = ((100 + $_POST["val1"]) /100);
			if($_POST["sts"]=="pd"){
				//echo "pd";
				$pb1 = $rsc["pb1"] * $doran;
				$pb2 = $rsc["pb2"] * $doran;
			}else{
				//echo "pu";
				$pb1 = $rsc["pb1"] * $uoran;
				$pb2 = $rsc["pb2"] * $uoran;
			}
		}else{
			$oran = $_POST["val1"];
			if($_POST["sts"]=="md"){
				//echo "md";
				$pb1 = $rsc["pb1"] - $oran;
				$pb2 = $rsc["pb2"] - $oran;
			}else{
				//echo "mu";
				$pb1 = $rsc["pb1"] + $oran;
				$pb2 = $rsc["pb2"] + $oran;
			}
		}
		//echo "".$rsc["id"]." => ".$rsc["pb1"]." => ".$pb1."<br>";
		$Sqlu = mysqli_query($conn, "update ".$_SESSION["lang"]." set pb1='".$pb1."', pb2='".$pb2."' where id=".$rsc["id"]."");
	}
	echo "<u>".$_SESSION["lang"]."</u> tablosunda [<b>".$_POST["sts"]."</b>] methodu ile [<b>".$_POST["val1"]."</b>] işlem <u>".$_POST["sql"]."</u> koşulu/koşulsuz ile <b>".$i."</b> data güncellendi <span onclick=\"history.back()\" style=\"float:right;cursor:pointer;\"><< Geri</span><hr>";
}
?>