<?php include("map.php");?>
<script src="//cdn.<?php echo $cdnurl?>/tools/js/b1f22d74f8.js" crossorigin="anonymous"></script>
<meta charset="UTF-8">
<?php
$file="app_login.txt";
if(file_exists($file)){
	$app_login = fopen($file, "r");
	//$ftime=date ("Y-m-d H:i:s", filemtime($file));
	if ((time()-filectime($file)) > 600) {
		unlink($file); exit();
	}
	$DeviceID=fread($app_login, filesize($file));
	fclose($app_login);
	unlink($file);
	//#Auto Login
	$sqlcl=mysqli_query($conn, "select * from genel where ne='asifre' and n8<>'' "); while($rs=mysqli_fetch_assoc($sqlcl)){$jsa = json_decode($rs["n8"], true);
		if($DeviceID<>"" and $DeviceID==$jsa["DeviceID"]){
			$user = v3d($rs["t1"]);
			$pass = v3d($rs["t2"]);
			$gcode = v3d($rs["t3"]);
			echo " <script> setTimeout(function(){ AjaxPResult('login_ajx.php?cmd=giris&ne=".$_GET["ne"]."&islem=".$_GET["islem"]."&id=".$_GET["id"]."','#flogin','#result','505');return false; }, 1000); </script>";
		}
	}
	//#Auto Login
}
if($_GET["login"]=="check"){
echo "<i class=\"fas fa-qrcode\"></i>";
	if($DeviceID<>""){
		echo "
			<script>
			jQuery(document).ready(function() { jQuery('#luser').val('".$user."'); jQuery('#lpass').val('".$pass."'); jQuery('#lsk').val('".$gcode."');
				//AjaxPResult('login_ajx.php?cmd=giris&ne=".$_GET["ne"]."&islem=".$_GET["islem"]."&id=".$_GET["id"]."','#flogin','#result','505'); return false;
			});
			</script>
		";
	}
}
if($_GET["islem"]=="" and $_GET["login"]==""){
	echo " <center> <i class=\"fa fa-times cp\" onclick=\"hide('#login_qr')\" style=\"position:absolute; right:15px; top:15px; background:white; padding:3px 5px; border-radius:5px;\"></i> <img src=\"".qrCode("".$weburl."/login/".date("Ymd")."",175)."\" style=\"margin-bottom: 0px; width: 48%;\"><br> CrmPlus uygulaması üzerinde login olun, sonra CrmPlus QR okuyucuyu ile kodu okutun ve bekleyin.</center>";
}elseif($_GET["islem"]=="set" or $_GET["islem"]=="relogin"){
	if($_SESSION["app_login_time"]<>"" and $_GET["islem"]<>"relogin"){
		echo " <center style=\"margin-top:10%;\"> #".$_SESSION["DeviceID"]." İşlem Başarılı!<br> <img src=\"//cdn.".$cdnurl."/images/crm-plus-icon.png\" style=\"height: 80px;\"> <script src=\"//code.jquery.com/jquery-latest.js\" type=\"text/javascript\"></script> <script>jQuery(document).ready(function() {location.href='".$weburl."/relogin/".$_SESSION["DeviceID"]."';});</script> <i class=\"fas fa-unlock-alt\" style=\"font-size: 150px; margin-top: 30px; text-align: center; color: limegreen;\"></i> </center> ";
		exit();
	}
	echo " <center style=\"margin-top:10%;\"> #".$_SESSION["DeviceID"]." İşlem Başarılı!<br> <img src=\"//cdn.".$cdnurl."/images/crm-plus-icon.png\" style=\"height: 80px;\"> <i class=\"fas fa-unlock-alt\" style=\"font-size: 150px; margin-top: 30px; text-align: center; color: limegreen;\"></i> </center> ";
	$app_login = fopen($file, "w");
	$txt = $_SESSION["DeviceID"];
	fwrite($app_login, $txt);
	fclose($app_login);
	$_SESSION["app_login_time"]=date("Ymdhis");
}
?>