<?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"]."");
		}
	}
}
?>
<table class="table">
		<?php
		$klimit="10";
		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 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 s13=1 limit $ssayfa,$klimit"); while($rsu=mysql_fetch_array($sql)){$p++;
		$jsi = json_decode($rsu["n17"],true);
		$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>
					<div id="trendyol_<?php echo $stock2[1]?>"><img src="https://patient.rocks/Content/lg.comet-spinner.gif" style="height:16px;"></div>
					<script> setInterval(function() { $('#trendyol_<?php echo $stock2[1]?>').load('../trendyol/update.php?id=<?php echo $rsl["id"]?>'); }, <?php echo $p*10000?>); </script>
				</td>
				<td>
					<div id="n11_<?php echo $stock2[1]?>"><img src="https://patient.rocks/Content/lg.comet-spinner.gif" style="height:16px;"></div>
					<script> setInterval(function() { $('#n11_<?php echo $stock2[1]?>').load('../n11/update.php?id=<?php echo $rsl["id"]?>'); }, <?php echo $p*11000?>); </script>
				</td>
				<td>
					<div id="hepsiburada_<?php echo $stock2[1]?>"><img src="https://patient.rocks/Content/lg.comet-spinner.gif" style="height:16px;"></div>
					<script> setInterval(function() { $('#hepsiburada_<?php echo $stock2[1]?>').load('../hepsiburada/update.php?id=<?php echo $rsl["id"]?>'); }, <?php echo $p*13000?>); </script>
				</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*3?>; 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*3?>" id="progressBar" style="width:100%;"></progress>
		<script type="text/javascript">
			var timeleft = <?php echo $klimit*3?>;
			var downloadTimer = setInterval(function(){
			  if(timeleft <= 0){
				clearInterval(downloadTimer);
			  }
			  document.getElementById("progressBar").value = <?php echo $klimit*3?> - timeleft;
			  timeleft -= 1;
			}, 1000);
		</script>
<?php }?>