<?php 
date_default_timezone_set('Europe/Istanbul');
if((date("H") >= "8" and date("H") <= "19") or $_GET["time"]=="no"){
$path="../../../";
include("../../../map.php");
include("../../../scripts.php");
$trendyol_sellerID=tanim("trendyol","n1",0);
$trendyol_username=tanim("trendyol","n2",0);
$trendyol_password=tanim("trendyol","n3",0);
$n11_sellerID=tanim("n11","n1",0);
$n11_username=tanim("n11","n2",0);
$n11_password=tanim("n11","n3",0);
$hepsiburada_sellerID=tanim("hepsiburada","n1",0);
$hepsiburada_username=tanim("hepsiburada","n2",0);
$hepsiburada_password=tanim("hepsiburada","n3",0);
$hepsiburada_merchantID=tanim("hepsiburada","n4",0);
include "../n11/n11.class.php";
function cevirr($metin){
	$metin = str_replace("Ý", "I", $metin);
	$metin = str_replace("Ü", "U", $metin);
	$metin = str_replace("Ö", "O", $metin);
	$metin = str_replace("Ç", "C", $metin);
	$metin = str_replace("Ð", "G", $metin);
	$metin = str_replace("ý", "i", $metin);
	$metin = str_replace("þ", "s", $metin);
	$metin = str_replace("Þ", "S", $metin);
	$metin = str_replace("ð", "g", $metin);
	return $metin;
}
if($_GET["sayfa"] == "") {
	$eta_stocks = file_get_contents('https://siparis.idakozmetik.com/eta_api.asp');
	$i=0;$stocks = explode('+',cevirr($eta_stocks)); $total=count($stocks); 
	$results = array();
	foreach($stocks as $stock){$i++;
		$stock2=explode(',',$stock);
		$results[] = array('code' => $stock2[0], 'barcode' => $stock2[1], 'title' => $stock2[2], 'stock' => $stock2[3], 'fiyat' => $stock2[4]);
	}
	foreach($stocks as $stock){$i++;
		$stock2 = explode(',',$stock);
		if(is_numeric($stock2[1]) and $stock2[3]>=0){
			if($stock2[3]>=1){ $s5=$stock2[3]; }else{ $s5=0; }
			$sql = mysql_query("SELECT * FROM ".$_SESSION['lang']." where ne='kayit' and t5<>'' and  t5='".$stock2[1]."'"); $rsl=mysql_fetch_array($sql);
			$jsi = json_decode($rsl["n17"],true);
			$pb2=round($rsl["pb1"]*1.20);
			$pb1=str_replace(",","",number_format(($stock2[4]*1.18),2));
			$n4="".$stock2[0].",".$stock2[2]."";
			$Rs = mysql_query("update ".$_SESSION['lang']." set pb1='".$pb1."', s5='".$stock2[3]."' where id=".$rsl["id"]."");
		}
	}
	//sNotification("Eta Stock Update", "".$_GET["py"]." Update Started", "Crm");
}
?>
<table class="table">
		<?php
if($_GET["py"]=="N11"){
		$klimit="10";
}elseif($_GET["py"]=="Trendyol"){
		$klimit="10";
}elseif($_GET["py"]=="HepsiBurada"){
		$klimit="5";
}else{
		$pb1=$rsu["pb1"];
		$pb2=round($rsu["pb1"]*1.20);
}
		if($_GET["sayfa"] == "") {$sno = 0;}else{$sno = $_GET["sayfa"];}
		if($_GET["sayfa"] == "") {$ssayfa = 0;}else{$ssayfa = ($_GET["sayfa"]-1) * $klimit;}
		$say = mysql_query("SELECT count(*) FROM ".$_SESSION['lang']." where ne='kayit' and (s9<>'4' and s9<>'5') and s13=1"); $rsay=mysql_fetch_array($say);
		$tss=$rsay[0]/$klimit;
		echo "<title>".round($tss)." > ".$sno.".Sayfa ".$_GET["py"]." Update</title>";
		$p=0;$sql = mysql_query("SELECT * FROM ".$_SESSION['lang']." where ne='kayit' and (s9<>'4' and s9<>'5') and s13=1 limit $ssayfa,$klimit"); while($rsu=mysql_fetch_array($sql)){$p++;
		$jsi = json_decode($rsu["n17"],true);
if($_GET["py"]=="N11" and $jsi["i9"]<>""){
		$pb1=$jsi["i9"];
		$pb2=round($jsi["i9"]*1.20);
}elseif($_GET["py"]=="Trendyol" and $jsi["i10"]<>""){
		$pb1=$jsi["i9"];
		$pb2=round($jsi["i9"]*1.20);
}elseif($_GET["py"]=="HepsiBurada" and $jsi["i11"]<>""){
		$pb1=$jsi["i9"];
		$pb2=round($jsi["i9"]*1.20);
}else{
		$pb1=$rsu["pb1"];
		$pb2=round($rsu["pb1"]*1.20);
}
		?>
			<tr style="">
				<td><?php echo $rsu["id"]?></td>
				<td><?php echo $rsu["t5"]?></td>
				<td><?php echo $rsu["t1"]?></td>
				<td><?php echo $rsu["s5"]?></td>
				<td><del><?php echo $pb2?> <i class="fa fa-try"></i></del></td>
				<td><?php echo $pb1?> <i class="fa fa-try"></i></td>
				<td>
					<?php if($_GET["py"]=="Trendyol"){include("../trendyol/inc_update.php");}?>
				</td>
				<td>
					<?php if($_GET["py"]=="N11"){include("../n11/inc_update.php");}?>
				</td>
				<td>
					<?php if($_GET["py"]=="HepsiBurada"){include("../hepsiburada/inc_update.php");}?>
				</td>
			</tr>
		<?php }?>
</table>
		<?php for ($i = 0; $i <= $tss; $i++) {$x=$i+1; ?>
		<a href="?time=<?php echo $_GET["time"]?>&py=<?php echo $_GET["py"]?>&sayfa=<?php echo $x;?>" style="<?php if($_GET["sayfa"]==$x){echo "font-weight:bold;";}?>"><?php echo $x;?></a>
		<?php }?>
		<?php if($_GET["sayfa"]<=$tss){ ?>
		<meta http-equiv="refresh" content="<?php echo $klimit?>; URL=?time=<?php echo $_GET["time"]?>&py=<?php echo $_GET["py"]?>&sayfa=<?php echo $_GET["sayfa"]+1?>">
		<?php }else{sNotification("Eta Update", "".$_GET["py"]." Update Successfull", "Crm");}?>
		<progress value="0" max="<?php echo $klimit?>" id="progressBar" style="width:100%;"></progress>
		<script type="text/javascript">
			var timeleft = <?php echo $klimit?>;
			var downloadTimer = setInterval(function(){
			  if(timeleft <= 0){
				clearInterval(downloadTimer);
			  }
			  document.getElementById("progressBar").value = <?php echo $klimit?> - timeleft;
			  timeleft -= 1;
			}, 1000);
		</script>
<?php }?>