<?php
	header('Content-Type: text/html; charset=utf-8');
	error_reporting(0);
	$path="../../";
	include("../../map.php");
	include("../../scripts.php");
	include("../../secure.php");
?>
<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title><?php echo $sdil[8]; //iKod?></title>
</head>
<body>
    <div class="qmodal">
        <div class="qmodal-content">
            <!-- Header with Action Buttons -->
            <div class="qmodal-header">
                <button type="button" class="btn btn-warning mfrm" data-toggle="modal" data-target="#myModal2" data-url="modules/public/uniqs.php?type=discount"><i class="fas fa-tags"></i> Uniq Codes</button>
                <button type="button" class="btn btn-danger" onclick="location.href='?ne=<?php echo $_GET["ne"];?>&islem=<?php echo $_GET["islem"];?>&type=autocreate'" title="Kullanıcı Taraflı Kodlar"><i class="fas fa-tags"></i></button>
            </div>
            <!-- Left Tab Menu -->
            <div class="v8-columns">
                <!-- Content Area -->
                <div class="" ts1="<?php echo dtarih($rs["ts1"],"gg ka yy time");?>" ts2="<?php echo dtarih($rs["ts2"],"gg ka yy time");?>" ts3="<?php echo dtarih($rs["ts3"],"gg ka yy time");?>">
<table class="table table-no-more table-bordered table-striped mb-0">
								<form method="POST" action="?ne=<?php echo $_GET["ne"];?>&islem=<?php echo $_GET["islem"];?>&durum=ekle" autocomplete="off" id="tform" name="tform">
									<tr class="addtr"  onclick="vtr('addtr')">
										<td class=""><input type="text" name="t1" id="" title="" class="form-control" placeholder="<?php echo translate("İndirim Kodu")?>"></td>
										<td class="w15">
										<select name="out[]" data-placeholder="<?php echo translate("İndirim Dışı Gruplar")?>" class="form-control populate" data-plugin-selecttwo="" tabindex="8">
										<?php $discout = explode(',',$rs["n11"]); $sqlx=mysqli_query($conn, "select Cat_ID,Cat_".$_SESSION["lang"]." from kategoriler where ne='ukategori' order by sira asc");  while($rsx=mysqli_fetch_assoc($sqlx)){?>
											<option value="<?php echo $rsx["Cat_ID"];?>" title="<?php echo $rsx["Cat_".$_SESSION["lang"].""];?>" alt="<?php echo $rsx["Cat_".$_SESSION["lang"].""];?>" <?php foreach($discout as $out) {?><?php if($rsx["Cat_ID"]==$out){?>Selected<?php }}?> style="color:#6699FF !important">+ <?php echo $rsx["Cat_".$_SESSION["lang"].""];?></option>
											<?php $sqly=mysqli_query($conn, "select Cat_ID,Cat_".$_SESSION["lang"]." from kategoriler where ne='ualt_kategori' and c1=".$rsx["Cat_ID"]." order by sira asc");  while($rsy=mysqli_fetch_assoc($sqly)){?>
												<option value="<?php echo $rsy["Cat_ID"];?>" title="<?php echo $rsy["Cat_".$_SESSION["lang"].""];?>" alt="<?php echo $rsy["Cat_".$_SESSION["lang"].""];?>" <?php foreach($discout as $out) {?><?php if($rsy["Cat_ID"]==$out){?>Selected<?php }}?> style="color:#6699FF !important">- <?php echo $rsy["Cat_".$_SESSION["lang"].""];?></option>
											<?php }?>													
										<?php }?>
										</select>
										</td>
										<td class="w15"><input type="text" name="t2" id="" title="" class="form-control" placeholder="<?php echo translate("Açıklama")?>"></td>
										<td class="w15">
										<select name="s19" data-placeholder="<?php echo translate("Üye")?>" class="form-control populate" data-plugin-selecttwo="" tabindex="8">
											<option value="0" style="color:#6699FF !important"><?php echo translate("Lütfen Seçiniz")?></option>
										<?php $sqlx=mysqli_query($conn, "select id,t1 from t5 order by t1 asc");  while($rsx=mysqli_fetch_assoc($sqlx)){?>
											<option value="<?php echo $rsx["id"];?>" title="<?php echo $rsx["t1"];?>" alt="<?php echo $rsx["t1"];?>" style="color:#6699FF !important"><?php echo $rsx["t1"];?></option>
										<?php }?>
										</select>
										</td>
										<td class="w8">
											<select name="s2" class="v3-form-control">
												<option value="0" <?php if($rs["s2"]==0){echo "Selected";}?> title="Çok Seferlik Kod"><?php echo translate("Çoklu İndirim")?></option>
												<option value="1" <?php if($rs["s2"]==1){echo "Selected";}?> title="Tek Seferlik Kod"><?php echo translate("Tekil İndirim")?></option>
												<option value="2" <?php if($rs["s2"]==2){echo "Selected";}?> title="Yeni Üyelikte Verilen Puan"><?php echo translate("Yeni Üye")?></option>
												<option value="3" <?php if($rs["s2"]==3){echo "Selected";}?> title="Tavsiyede Verilen Puan"><?php echo translate("Tavsiye")?></option>
											<?php if($m16==1){?>
												<option value="4" <?php if($rs["s2"]==4){echo "Selected";}?> title="Siparişde İndirim Çeki"><?php echo translate("Sipariş")?></option>
											<?php }?>
											</select>
										</td>
										<td class="w6">
											<div class="input-group-btn">
												<button tabindex="-1" class="btn btn-warning mbtn demo editor" type="submit"><i class="fa fa-plus"></i><span class="ddn tdn"> <?php echo $sdil[201]; //ekle?></span></button>
											</div>
										</td>
										</tr>
										<tr class="bg-info" id="addtr" style="display:none;">
											<td class="" colspan="7">
												<table style="width:100%;">
													<tr>
														<td class="w15">
															<input type="text" name="pb2" id="" title="x <?php echo $kpb?> İndirim" value="" class="add_price form-control w45 fl mw45 mfl cw" placeholder="<?php echo translate("İndirim")?> <?php echo $kpb?>">
															<input type="text" name="pb3" id="" title="x <?php echo $kpb?> İndirim Sonrası Devamında y <?php echo $kpb?> İndirim" value="" class="add_price form-control w45 fr mw45 mfr cw" placeholder="<?php echo translate("Devam")?> <?php echo $kpb?>">
														</td>
														<td class="w8"><input type="text" name="pb4" value="" id="" title="Toplam <?php echo $kpb?> İndirim" class="add_price form-control cw" placeholder="<?php echo translate("Toplam")?> <?php echo $kpb?>" disabled></td>
														<td class="w15">
															<input type="text" name="s1" value="" id="" title="x% İndirim" class="add_percent form-control w45 fl mw45 mfl cw" placeholder="<?php echo translate("İndirim")?> %">
															<input type="text" name="s3" value="" id="" title="x% İndirim devamında y% İndirim" class="add_percent form-control w45 fr mw45 mfr cw" placeholder="<?php echo translate("Devam")?> %">
														</td>
														<td class="w8"><input type="text" name="s4" value="" id="" title="Toplam % İndirim" class="add_percent form-control cw" placeholder="<?php echo translate("Toplam")?> %" disabled></td>
														<td class="w8"><input type="text" name="pb1" value="" id="" title="İndirim Alt Limiti" class="form-control cw" placeholder="<?php echo translate("Min-Tutar")?>"></td>
														<td class="w8"><input type="date" name="ts2" id="" title="Geçerlilik Tarihi" class="form-control" value="" placeholder="<?php echo translate("Geçerlilik Tarihi")?>"></td>
													</tr>
												</table>
											</td>										
										</tr>
										</form>
										<?php
											if($_GET["type"]==""){$qry=" and t3='' ";}else{$qry=" and t3='".$_GET["type"]."' ";}
											$sql=mysqli_query($conn, "select * from genel where ne='i-kod' order by id asc"); while($rs=mysqli_fetch_assoc($sql)){
											$sqlco = mysqli_query($conn, "select * from eticaret where ne='siparis' and t6='".$rs["t1"]."' and s1='".$rs["s19"]."'"); $corder = mysqli_fetch_assoc($sqlco);
											if($rs["s2"]==0 and $rs["s3"]==0){	//Multi, ilk
												$code_clr="success";
											}elseif($rs["s2"]==0 and $rs["s3"]<>0 and mysqli_num_rows($sqlco)==0){	//Multi, ilk devam
												$code_clr="success";
											}elseif($rs["s2"]==0 and $rs["s3"]<>0 and mysqli_num_rows($sqlco)>0){	//Multi, devam
												$code_clr="warning";
												
											}elseif($rs["s2"]==1 and $rs["s3"]==0 and mysqli_num_rows($sqlco)==0){ //Single ve ilk 
												$code_clr="success";
											}elseif($rs["s2"]==1 and $rs["s3"]<>0 and mysqli_num_rows($sqlco)==1){	//Single ve devam
												$code_clr="warning";
											}elseif($rs["s2"]==2 and mysqli_num_rows($sqlco)==0){	//Yeni Üye
												$code_clr="success";
											}elseif($rs["s2"]==3 and mysqli_num_rows($sqlco)==0){	//Tavsiye
												$code_clr="success";
											}elseif($rs["s2"]==4 and mysqli_num_rows($sqlco)==0){	//Spariş
												$code_clr="success";
											}else{
												$code_clr="danger";
											}
										?>
											<form method="POST" action="?ne=<?php echo $_GET["ne"];?>&islem=<?php echo $_GET["islem"];?>&durum=duzenle&id=<?php echo $rs["id"];?>" autocomplete="off">
												<tr class="alert alert-<?php echo $code_clr;?>" onclick="vtr('tr<?php echo $rs["id"];?>')">
													<td><input type="text" name="t1" class="form-control" value="<?php echo $rs["t1"];?>"></td>
													<td>
														<select name="out[]" data-placeholder="<?php echo translate("İndirim Dışı Gruplar")?>" class="form-control populate" tabindex="8">
														<?php $discout = explode(',',$rs["n11"]); $sqlx=mysqli_query($conn, "select Cat_ID,Cat_".$_SESSION["lang"]." from kategoriler where ne='ukategori' order by sira asc");  while($rsx=mysqli_fetch_assoc($sqlx)){?>
															<option value="<?php echo $rsx["Cat_ID"];?>" title="<?php echo $rsx["Cat_".$_SESSION["lang"].""];?>" alt="<?php echo $rsx["Cat_".$_SESSION["lang"].""];?>" <?php foreach($discout as $out) {?><?php if($rsx["Cat_ID"]==$out){?>Selected<?php }}?> style="color:#6699FF !important">+ <?php echo $rsx["Cat_".$_SESSION["lang"].""];?></option>
															<?php $sqly=mysqli_query($conn, "select Cat_ID,Cat_".$_SESSION["lang"]." from kategoriler where ne='ualt_kategori' and c1=".$rsx["Cat_ID"]." order by sira asc");  while($rsy=mysqli_fetch_assoc($sqly)){?>
																<option value="<?php echo $rsy["Cat_ID"];?>" title="<?php echo $rsy["Cat_".$_SESSION["lang"].""];?>" alt="<?php echo $rsy["Cat_".$_SESSION["lang"].""];?>" <?php foreach($discout as $out) {?><?php if($rsy["Cat_ID"]==$out){?>Selected<?php }}?> style="color:#6699FF !important">- <?php echo $rsy["Cat_".$_SESSION["lang"].""];?></option>
															<?php }?>
														<?php }?>
														</select>
													</td>
													<td><input type="text" name="t2" class="form-control" value="<?php echo $rs["t2"];?>"></td>
													<td class="w15">
													<select name="s19" data-placeholder="<?php echo translate("Üye")?>" class="form-control" tabindex="8">
														<option value="0" style="color:#6699FF !important"><?php echo translate("Lütfen Seçiniz")?></option>
													<?php $sqlx=mysqli_query($conn, "select id,t1 from t5 order by t1 asc");  while($rsx=mysqli_fetch_assoc($sqlx)){?>
														<option value="<?php echo $rsx["id"];?>" title="<?php echo $rsx["t1"];?>" alt="<?php echo $rsx["t1"];?>"<?php if($rsx["id"]==$rs["s19"]){?>Selected<?php }?> style="color:#6699FF !important"><?php echo $rsx["t1"];?></option>
													<?php }?>
													</select>
													</td>
													<td>
													<select name="s2" class="v3-form-control">
														<option value="0" <?php if($rs["s2"]==0){echo "Selected";}?>><?php echo translate("Çoklu İndirim")?></option>
														<option value="1" <?php if($rs["s2"]==1){echo "Selected";}?>><?php echo translate("Tekil İndirim")?></option>
														<option value="2" <?php if($rs["s2"]==2){echo "Selected";}?>><?php echo translate("Yeni Üye")?></option>
														<option value="3" <?php if($rs["s2"]==3){echo "Selected";}?>><?php echo translate("Tavsiye")?></option>
<?php if($m16==1){?>
														<option value="4" <?php if($rs["s2"]==4){echo "Selected";}?>><?php echo translate("Sipariş")?></option>
<?php }?>
													</select>
													</td>
													<td>
														<div class="input-group-btn">
															<button tabindex="-1" class="btn btn-warning mbtn demo editor" type="submit"><i class="fa fa-refresh"></i><span class="ddn tdn"> <?php echo $sdil[203]; //Güncelle?></span></button>
															<button type="button" style="margin-left: 1px" tabindex="-1" class="btn btn-danger mbtn demo editor" href="?ne=<?php echo $_GET["ne"];?>&islem=<?php echo $_GET["islem"];?>&durum=sil&id=<?php echo $rs["id"];?>" OnClick="return confirm(' Bu Kayıt Silinecektir ! Onaylıyor musunuz ?');"><i class="fa fa-times"></i><span class="ddn tdn"> <?php echo $sdil[204]; //Kaldır?></span></button>
														</div>
													</td>
												</tr>
												<tr class="bg-info cw" id="tr<?php echo $rs["id"];?>" style="display:none;">
													<td class="" colspan="7">
														<table style="width:100%;">
															<tr>
																<td class="w15">
																	<input type="text" name="pb2" id="" title="0" value="<?php echo $rs["pb2"]?>" class="form-control w45 fl mw45 mfl cw" placeholder="<?php echo translate("İndirim")?> <?php echo $kpb?>">
																	<input type="text" name="pb3" id="" title="0" value="<?php echo $rs["pb3"]?>" class="form-control w45 fr mw45 mfr cw" placeholder="<?php echo translate("Devam")?> <?php echo $kpb?>">
																</td>
																<td class="w8"><input type="text" name="pb4" value="<?php echo $rs["pb4"]?>" id="" title="0" class="form-control cw" placeholder="<?php echo translate("Toplam")?> <?php echo $kpb?>" disabled></td>
																<td class="w15">
																	<input type="text" name="s1" value="<?php echo $rs["s1"]?>" id="" title="0" class="form-control w45 fl mw45 mfl cw" placeholder="<?php echo translate("İndirim")?> %">
																	<input type="text" name="s3" value="<?php echo $rs["s3"]?>" id="" title="0" class="form-control w45 fr mw45 mfr cw" placeholder="<?php echo translate("Devam")?> %">
																</td>
																<td class="w8"><input type="text" name="s4" value="<?php echo $rs["s4"]?>" id="" title="0" class="form-control cw" placeholder="<?php echo translate("Toplam")?> %" disabled></td>
																<td class="w8"><input type="text" name="pb1" value="<?php echo $rs["pb1"]?>" id="" title="0" class="form-control cw" placeholder="<?php echo translate("Min-Tutar")?>"></td>
																<td class="w8"><input type="date" name="ts2" id="" title="0" class="form-control" value="<?php echo dtarih($rs["ts2"],"yyyy-aa-gg")?>" placeholder="<?php echo translate("Geçerlilik Tarihi")?>"></td>
															</tr>
														</table>
													</td>
												</tr>
											</form>
										<?php }?>
									</table>
                 </div>
            </div>
</body>
<?php echo $footer?>
</html>
<script>
/*
	jQuery('.add_price, .add_percent').keydown(function(e){
		jQuery('.add_percent').removeAttr('readonly');
		jQuery('.add_price').removeAttr('readonly');
		if(jQuery('.add_price').val()<>""){
			jQuery('.add_percent').prop('readonly','true');
			jQuery('.add_price').removeAttr('readonly');
		}else if(jQuery('.add_percent').val()<>""){
			jQuery('.add_percent').prop('readonly','true');
			jQuery('.add_price').removeAttr('readonly');
		}
	});
*/
</script>
<?php
if($_GET["durum"]=="ekle"){
	$sn11 = implode(',',$_POST["out"]);
	if($_POST["s1"]==""){$ss1=0;}else{$ss1=$_POST["s1"];}
	if($_POST["s2"]==""){$ss2=0;}else{$ss2=$_POST["s2"];}
	if($_POST["s3"]==""){$ss3=0;}else{$ss3=$_POST["s3"];}
	if($_POST["s19"]==""){$ss19=0;}else{$ss19=$_POST["s19"];}
	if($_POST["pb1"]==""){$spb1=0;}else{$spb1=$_POST["pb1"];}
	if($_POST["pb2"]==""){$spb2=0;}else{$spb2=$_POST["pb2"];}
	$sql = $conn->query("insert into genel(t1,t2,ne,pb1,pb2,s1,s2,s3,s19,n11,ts1,ts2) VALUES ('".$_POST["t1"]."', '".$_POST["t2"]."', 'i-kod', '".$spb1."', '".$spb2."', '".$ss1."', '".$ss2."', '".$ss3."', '".$ss19."', '".$sn11."', now(), '".$_POST["ts2"]."')");
	$sqlc=mysqli_query($conn, "select * from t5 where id='".$_POST["s19"]."'"); $rsc=mysqli_fetch_assoc($sqlc);
	$konu=translate("Yeni İndirim Kodu");
	$mesaj	= "
		<h3>".translate("Yeni İndirim Kodu")."</h3>
		<b>".translate("Sayın")." ".$rsc["t1"].";</b><br><b>".$_POST["pb1"]."</b> ".$kpb." Üzerine  <b>%".$_POST["s1"]."</b> <b>%".$_POST["t1"]."</b> ".translate("yeni_indirim_kodu")."
	";
	$malici		= base64_decode($rsc["t2"]);
	$path="../";
	$mesaj	= $design_top.$mesaj.$design_bottom;
	emailgonder($malici, $konu, '', $mesaj);
	echo location("?ne=".$_GET["ne"]."&islem=".$_GET["islem"]."&durum=ok",self,500,1);
	
}elseif($_GET["durum"]=="duzenle"){
	$sn11 = implode(',',$_POST["out"]);
	if($_POST["s1"]==""){$ss1=0;}else{$ss1=$_POST["s1"];}
	if($_POST["s2"]==""){$ss2=0;}else{$ss2=$_POST["s2"];}
	if($_POST["s3"]==""){$ss3=0;}else{$ss3=$_POST["s3"];}
	if($_POST["s19"]==""){$ss19=0;}else{$ss19=$_POST["s19"];}
	if($_POST["pb1"]==""){$spb1=0;}else{$spb1=$_POST["pb1"];}
	if($_POST["pb2"]==""){$spb2=0;}else{$spb2=$_POST["pb2"];}
	$Rs = mysqli_query($conn, "update genel set t1='".$_POST["t1"]."', t2='".$_POST["t2"]."', pb1='".$spb1."', pb2='".$spb2."', s1='".$ss1."', s2='".$ss2."', s3='".$ss3."', s19='".$ss19."', n11='".$sn11."', ts2='".$_POST["ts2"]."' Where id=".$_GET["id"]."");
	echo location("?ne=".$_GET["ne"]."&islem=".$_GET["islem"]."&durum=ok",self,500,1);
	
}elseif($_GET["durum"]=="sil"){
	$Rs = mysqli_query($conn, "delete from genel where id=".$_GET["id"]);
	echo location("?ne=".$_GET["ne"]."&islem=".$_GET["islem"]."&durum=ok",self,500,1);	
}
?>