<?php ob_start();?>
<?php
$path="../../";
include("../../map.php");
include("../../scripts.php");
//https://api.trendyol.com/sapigw-product/product-categories
/*
include "../integration/n11/n11.class.php";
$n11_user=tanim("sp+N11","n1",0);
$n11_pass=tanim("sp+N11","n2",0);
$n11_merchantID=tanim("sp+N11","n4",0);
$n11Params = ['appKey' => n11_user, 'appSecret' => $n11_pass];
$n11 = new N11($n11Params);
$categories = $n11->GetTopLevelCategories();
foreach($categories->categoryList->category as $x=>$kat){
	$options = "<option value=\"".$kat->id."\">".$kat->name."</option>;
	$sayi++;
}
$Hb_user=tanim("sp+Hepsiburada","n1",0);
$Hb_pass=tanim("sp+Hepsiburada","n2",0);
$Hb_merchantID=tanim("sp+Hepsiburada","n4",0);
$service_url = 'https://oms-external.hepsiburada.com/product/api/categories/get-all-categories/merchantID/'.$Hb_merchantID.'';
$curl = curl_init($service_url);
curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
curl_setopt($curl, CURLOPT_HTTPHEADER, array( 'Authorization: Basic ' . base64_encode($Hb_user.':'.$Hb_pass), 'Content-Type: application/json') );
$curl_categories = curl_exec($curl);
$categories = json_decode($curl_categories);
$info = curl_getinfo($curl);
curl_close($curl);
*/
?>
<?php $sql=mysqli_query($conn, "select * from kategoriler where Cat_ID=".$_GET["cID"].""); $rs=mysqli_fetch_assoc($sql);
$ne=$_GET["ne"];
$islem=$_GET["islem"];
$Cat_ID=$_GET["Cat_ID"];
if(isset($rs['n1_lang1'])){
	$clang="_".$_SESSION["lang"]."";
	//echo "var";
}
if(($_SESSION["kim"]=="Admin") or ($_SESSION["kim"]=="yonetici" and $_SESSION["y10"]==3)){
	if (($e10==1 and $_SESSION["user"]<>V3d('TWFzdGVy'))) {
		$yetki=0;
	}else{
		$yetki=1;
	}
}else{
	$yetki=0;
}
$jsi = json_decode($rs["n6"], true);
$jsm = json_decode($rs["n7"], true);
?>
<?php if($_GET["durum"]=="ok"){?>
	<div class="alert alert-success" role="alert" style="padding:5px;">
		<?php echo $sdil[212]; //islem Basariyla Gerçeklestirilmistir !?>
	</div>
<?php }elseif($_GET["durum"]=="hata"){?>
	<div class="alert alert-danger" role="alert">
		...
	</div>
<?php }?>
<form name="frm" class="col-md-12" enctype="multipart/form-data" action="?ne=<?php echo $_GET["ne"];?>&islem=<?php echo $_GET["islem"];?>&Cat_ID=<?php echo $_GET["Cat_ID"];?>&durum=kaydet" method="post">
	<ul class="nav nav-tabs" role="tablist">
		<li role="presentation" class="active"><a href="#tb1" aria-controls="tb1" role="tab" data-toggle="tab">#<?php echo $rs["Cat_ID"];?> <?php echo $rs["Cat_".$_SESSION['lang'].""];?></a></li>
<?php $sqld=mysqli_query($conn, "select * from genel where ne='tanim' and t2='sp' order by t2,n4 asc"); while($rsd=mysqli_fetch_assoc($sqld)){?>
		<li role="presentation" class=""><a href="#tb<?php echo $rsd["id"];?>" aria-controls="tb<?php echo $rsd["id"];?>" role="tab" data-toggle="tab"><?php echo $rsd["n4"];?></a></li>
<?php }?>
	</ul>
	<div class="tab-content">
		<div role="tabpanel" class="tab-pane active" id="tb1">
<div class="col-xs-7"><input type="text" name="cat" class="form-control" value="<?php echo $rs["Cat_".$_SESSION['lang'].""];?>" placeholder="<?php echo $rs["Cat_lang1"];?>" style=""/></div>
<div class="col-xs-2"><input type="text" name="sira" value="<?php echo $rs["sira"];?>" style="" class="form-control"/></div>
<div class="col-xs-1"><input type="checkbox" name="s2" value="1" style="width:33px;" title="s2 Vitrin" class="form-control with-tip" <?php if($rs["s2"]==1){?>Checked<?php }?>></div>
<div class="col-xs-1"><input type="checkbox" name="s1" value="1" class="form-control with-tip" style="<?php if($_SESSION["user"]<>V3d('TWFzdGVy')){?>display:none;<?php }?>width:33px" <?php if($rs["s1"]<>0){?>Checked<?php }?> title="Silinemez!"></div>	
<div class="col-xs-12" style="margin-top:10px;">
	<input type="text" style="" name="n1" class="form-control" title="n1_langx" value="<?php echo $rs["n1".$clang.""];?>" placeholder="<?php echo $sdil[39]; //Title?>" />
</div>
<div class="col-xs-12" style="margin-top:10px;">
	<textarea style="height:60px;" class="form-control" name="n2" title="n2_langx" placeholder="<?php echo $sdil[207]; //Açıklama?>"><?php echo $rs["n2".$clang.""];?></textarea>
</div>
<div class="col-xs-12" style="margin-top:10px;">
	<textarea style="height:60px;" class="form-control" name="n4" title="n4_langx" placeholder="<?php echo $sdil[41]; //Etiket?>"><?php echo $rs["n4".$clang.""];?></textarea>
</div>
<div class="col-xs-12" style="margin-top:10px;">
	<input type="text" style="" name="n3" class="form-control" title="n3" value="<?php echo $rs["n3"];?>" placeholder="Extra / Renk" />
</div>
<div class="col-xs-8" style="margin-top:10px;">
	<input type="text" name="n5" style="" class="form-control" value="<?php echo $rs["n5"];?>" placeholder="http://www.">
</div>
<div class="col-xs-4">
	<select size="1" name="t6" style="margin-top:10px;" class="form-control">
		<option value="<?php echo $rs["t6"];?>"> <?php if($rs["t6"]==""){echo "Target";}else{echo $rs["t6"];}?> </option>
		<option value="_self" >_self</option>
		<option value="_blank" >_blank</option>
		<option value="_top" >_top</option>
	</select>
</div>
<div class="col-xs-12" style="margin-top:10px;">
<?php
$i=0;$sqli=mysqli_query($conn, "select * from genel where ne='inputs' and (t2='All' or t2='".$_SESSION["lang"]."') and n3='kategori' and n4<>'switch' and (n2='0' or n2='".$rs["Cat_ID"]."') and s1=0 order by s10 asc");
if(mysqli_num_rows($sqli)>0){
?>
	<div class="">
	<div class="row">
	<?php while($rsi=mysqli_fetch_assoc($sqli)){$i++;?>
		<div class="col-xs-4 col-md-4" style="">
								<label><i class="<?php echo $rsi["n14"]?>"></i> <?php echo $rsi["n1"];?> <span style="font-size:8px; color:#ccc;"> (i<?php echo $i;?>)</span></label>
								<?php if($rsi["n4"]=="input"){?>
									<input class="form-control <?php echo $rsi["n13"]?>" type="<?php echo $rsi["n5"]?>" name="i<?php echo $i;?>" value="<?php echo $jsi["i".$i.""];?>" placeholder="<?php echo $rsi["n11"]?>" style="" <?php echo $rsi["n8"]?> <?php echo $rsi["n6"]?>>
								<?php }elseif($rsi["n4"]=="textarea"){?>
									<textarea class="form-control <?php echo $rsi["n13"]?>" name="i<?php echo $i;?>" placeholder="<?php echo $rsi["n11"]?>" <?php echo $rsi["n8"]?> <?php echo $rsi["n6"]?>><?php echo $jsi["i".$i.""];?></textarea>
								<?php }elseif($rsi["n4"]=="select"){?>
									<select class="form-control <?php echo $rsi["n13"]?> chosen-select" name="i<?php echo $i;?>[]" style="" <?php echo $rsi["n8"]?> <?php echo $rsi["n6"]?>>
										<option value=""><?php echo $sdil[221]; //Lütfen Seçiniz?></option>
										<?php $o=0;$sqlo=mysqli_query($conn, "select * from genel where ne='inputs' and s1=".$rsi["id"]." order by s10 asc"); while($rso=mysqli_fetch_assoc($sqlo)){$o++;?>
											<option value="<?php echo $rso["n2"]?>" <?php $q="";foreach($jsi["i".$i.""] as $q){?><?php if($q==$rso["n2"] or $rso["n3"]==1){echo "selected";}}?>><?php echo $rso["n1"]?></option>
										<?php }?>
									</select>
								<?php }elseif($rsi["n4"]=="radio"){?>
									<?php $o=0;$sqlo=mysqli_query($conn, "select * from genel where ne='inputs' and t2='".$_SESSION["lang"]."' and s1=".$rsi["id"]." order by s10 asc"); while($rso=mysqli_fetch_assoc($sqlo)){$o++;?>
										<div style="float:left; margin-right: 5px;">
											<label style="float:left; margin-right:5px;"><?php echo $rso["n1"];?>
											<input type="radio" name="i<?php echo $i;?>" value="<?php echo $rso["n2"];?>" <?php echo $rsi["n8"]?> <?php if($jsi["i".$i.""]==$rso["n2"] or $rso["n3"]==1){echo "checked";}?>></label>
										</div>
									<?php }?>
								<?php }elseif($rsi["n4"]=="checkbox"){?>
									<?php $o=0;$sqlo=mysqli_query($conn, "select * from genel where ne='inputs' and t2='".$_SESSION["lang"]."' and s1=".$rsi["id"]." order by s10 asc"); while($rso=mysqli_fetch_assoc($sqlo)){$o++;?>
										<div style="float:left; margin-right: 5px;">
											<label style="float:left; margin-right:5px;"><?php echo $rso["n1"];?>
											<input type="checkbox" name="i<?php echo $i;?>[]" value="<?php echo $rso["n2"];?>" <?php echo $rsi["n8"]?> <?php foreach($jsi["i".$i.""] as $q){?><?php if($q==$rso["n2"] or $rso["n3"]==1){echo "checked";}?><?php }?>></label>
										</div>
									<?php }?>
								<?php }?>
								<p style="font-size:10px;"><?php echo $rsi["n9"];?></p>
							</div>
						<?php }?>
					</div>
					<div class="col-md-12 row">
						<?php $w=0;$sqlw=mysqli_query($conn, "select * from genel where ne='inputs' and t2='".$_SESSION["lang"]."' and n3='kategori' and n4='switch' and (n2='0' or n2='".$rs["Cat_ID"]."') and s1=0 order by s10 asc"); while($rsw=mysqli_fetch_assoc($sqlw)){$w++;?>
							<fieldset class="grey-bg col-xs-3" style="">
								<legend><?php echo $rsw["n1"];?><span style="font-size:8px; color:#ccc;">(m<?php echo $w;?>)</span></legend>
								<div class="switch switch-sm switch-success">
									<input type="checkbox" name="m<?php echo $w;?>" data-plugin-ios-switch="" value="1" class="switch" <?php if($jsm["m".$w.""]=="1"){?>Checked<?php }?>>
								</div>
							</fieldset>
						<?php }?>
					</div>
		</div>
<?php }?>
	<input type="checkbox" class="" name="r1" value="ON" style="display:none; float:left; border:#fff; margin-right:5px; margin-top:3px; margin-left:2px;" alt="Resim Var/Yok" title="Resim Var/Yok">
	<input class="form-control" type="file" name="resim" style="" onchange="document.frm.r1.checked=true;" accept="*" style="margin-top:10px;">
	<button type=submit style="margin-top:5px; float:right; margin-right:5%;" class="btn btn-primary" <?php if ($yetki==0){?>disabled<?php }?>><?php echo $sdil[203]; //Güncelle?></button>
	<?php if(!empty($rs["image"])){?>
		<div style="clear:both;"></div>
		<a href="?ne=<?php echo $_GET["ne"];?>&islem=<?php echo $_GET["islem"];?>&Cat_ID=<?php echo $_GET["Cat_ID"];?>&durum=rsil"><i class="fa fa-times" style="position:absolute; margin-top:-8px; margin-left:5px;"></i></a>
		<img src="../../../deppo/kategori/<?php echo $rs["image"];?>" style="margin-left:5px; height:65px;">
	<?php }?>
</div>
</div>
<?php $sqld=mysqli_query($conn, "select * from genel where ne='tanim' and t2='sp' order by t2,n4 asc"); while($rsd=mysqli_fetch_assoc($sqld)){?>
<div role="tabpanel" class="tab-pane" id="tb<?php echo $rsd["id"];?>">
<?php echo $options;?>
</div>
<?php }?>
</form>
<?php
//-------------------------------------------------------------------------/İşlem Ekle/
if($_GET["durum"] == "kaydet"){
	if($_POST["r1"]<>""){
		$kaydedilecekyer = "../../../deppo/kategori";
		$kaynak	= $_FILES['resim']['tmp_name'];	//Burası resminiz kök klasörünün yerini verir  
		$tipi	= $_FILES['resim']['type']; // Dosyanın Tipi
		$adi	= $_FILES["resim"]["name"]; // Dosyanın PCdeki Adı
		$uzanti = explode('.',$_FILES['resim']['name']);
		$rand 	= substr(md5(uniqid(rand())),0,10); 
		$yeni 	= "".$rand.".".$uzanti[count($uzanti)-1]."";
		move_uploaded_file ($_FILES['resim']['tmp_name'], $kaydedilecekyer . "/".$yeni);
		$Rs = mysqli_query($conn, "update kategoriler set image='".$yeni."' where Cat_ID=".$_GET["Cat_ID"]."");
	}
if(!empty($_POST["pb2"])){$spb2=$_POST["pb2"];}else{$spb2="0";}
if(!empty($_POST["s1"])){$ss1=$_POST["s1"];}else{$ss1=0;}
if(!empty($_POST["s2"])){$ss2=$_POST["s2"];}else{$ss2=0;}
if(!empty($_POST["s6"])){$ss6=$_POST["s6"];}else{$ss6=0;}
$iarr = array();
foreach ($_POST as $key => $value){
	if(substr($key,0,1)=="i"){
		$iarr = $iarr + array( $key => $value);
	}
}
$marr = array();
foreach ($_POST as $key => $value){
	if(substr($key,0,1)=="m"){
		$marr = $marr + array( $key => $value);
	}
}
$rjsi = json_encode($iarr, JSON_UNESCAPED_UNICODE | JSON_UNESCAPED_SLASHES | JSON_NUMERIC_CHECK);
$rjsm = json_encode($marr, JSON_UNESCAPED_UNICODE | JSON_UNESCAPED_SLASHES | JSON_NUMERIC_CHECK);
$Rs = mysqli_query($conn, "update kategoriler set Cat_".$_SESSION['lang']."='".addslashes(stripslashes($_POST["cat"]))."', n1".$clang."='".addslashes(stripslashes($_POST["n1"]))."', n2".$clang."='".addslashes(stripslashes($_POST["n2"]))."', n3='".addslashes(stripslashes($_POST["n3"]))."', n4".$clang."='".addslashes(stripslashes($_POST["n4"]))."', n5='".$_POST["n5"]."', n6='".addslashes(stripslashes($rjsi))."', n7='".addslashes(stripslashes($rjsm))."', t4='".$_POST["t4"]."', sira='".$_POST["sira"]."', s1='".$ss1."', s2='".$ss2."' where Cat_ID=".$_GET["Cat_ID"]."");
go("?ne=".$_GET["ne"]."&islem=".$_GET["islem"]."&Cat_ID=".$_GET["Cat_ID"]."&c1=".$_GET["c1"]."&c2=".$_GET["c2"]."&s3=".$_GET["s3"]."&s4=".$_GET["s4"]."&s5=".$_GET["s5"]."&durum=ok");
}elseif($_GET["durum"] == "rsil"){
	$dosya="../../../deppo/kategori/".$rs["image"]."";
	unlink($dosya);
	$Rs = mysqli_query($conn, "update kategoriler set image='' where Cat_ID=".$_GET["Cat_ID"]."");
	go("?ne=".$_GET["ne"]."&islem=".$_GET["islem"]."&Cat_ID=".$_GET["Cat_ID"]."&durum=ok");
};?>
<?php ob_end_flush();?>
<script src="//ajax.googleapis.com/ajax/libs/jquery/1.11.2/jquery.min.js"></script>
<script src="//maxcdn.bootstrapcdn.com/bootstrap/3.3.2/js/bootstrap.min.js"></script>