<?php 
include_once "../includes/connectConfig.php";
if($_POST){
	$semail = test_input($_POST['lgzemail']);	
	$spass = test_input($_POST['lgzpassword']);
	$nwdtt = date('Y');
	try
	{
		$stmt = $db_con->prepare("SELECT tus_id, firstname, lastname, email, phone, user_type, password FROM tks_users WHERE email=:email AND delete_status = 0");
		$stmt->execute(array(":email"=>$semail));
		$count = $stmt->rowCount();
		
		if($count > 0 )
		{
			$countexit = $stmt->rowCount();
		
				if($countexit > 0)
				{
					$fx= $stmt->fetch();
			
					$user = $fx['tus_id'];
					$password = $fx['password'];
					$user_type = $fx['user_type'];
					
					$ses_tkn = gntRdmStgs()."".uniqid();
					
					if($st_hasher->CheckPassword($spass , $password)){
						
						
						    //chksess($user,$ses_tkn);
						    
								
							$_SESSION['acn_sst_userlogz'] = $user;
							$_SESSION['acn_sst_logz'] = $ses_tkn;
							
							
							$_SESSION['acn_sst_typelogz'] = ($user_type == 3 || $user_type == 4) ? "Vendor_sstyp" : gt_typ_nm($user_type)."_sstyp";
							$_SESSION['acn_sst_vndlogz'] = gt_typ_nm($user_type)."_typacc";
							
							$urlnk = "account/";
							
							$output["gerr"] = "";
							$output["loadpage"] = $urlnk."index";
							echo json_encode($output);
							exit;
					}
					else
					{
						$output["gerr"] = "invalid";
						echo json_encode($output);
						exit;
					}
				}
				else
				{
					$output["gerr"] = "invalid";
					echo json_encode($output);
					exit;
				}
			
		}
		else
		{
			
			 //  not available
			
			$output["gerr"] = "invalid";
			echo json_encode($output);
			exit;
		}
			
	}
	catch(PDOException $e){
		echo $e->getMessage();
	}
}

?>