<?php


include "start.php";
include "../includes/function.php";

$CurrentUserID=0;


$main_array = array();
$qr_verify_array = array();


$query_get="select * from t_".$key_table_prefix."_user_device
	    where dusr_id='".$_REQUEST["u"]."'
	    and dusr_session_id ='".$_REQUEST["s"]."'
		";


$result_get = mysqli_query($dbconn, $query_get) or die("Error".mysqli_error($dbconn));
if($line_get = mysqli_fetch_array($result_get,MYSQLI_ASSOC))
{
	$this_data = array(
		"status" => "YES",
		"message" => "Active"
	     );

	   array_push($main_array, $this_data);
	    
	    
	    
	    
	    $this_qr_code = $_REQUEST["qr_code"];
	    
	    $qr_array = explode("*P*",$this_qr_code);
	    
	    
	    $this_app = $qr_array[0];
	    $this_device = $qr_array[1];
	    $this_user_name = $qr_array[2];
	    $this_timestamp = $qr_array[3];
	    
	    
	    	//get device:
	    	$query_device="select * from t_".$key_table_prefix."_device 
	    				where dev_android_id = '".$this_device."' 
					and dev_default_warehouse_code = '".$_REQUEST["to_warehouse"]."'
					
					";
		$result_device = mysqli_query($dbconn, $query_device) or die("Error".mysqli_error($dbconn));
		if($line_device = mysqli_fetch_array($result_device,MYSQLI_ASSOC))
		{
			
				 
			 $this_data = array(
				 "status" => "YES",
				 "message" => "QR Verified"
				 );

			 array_push($qr_verify_array, $this_data);
						 
			
			
		}
		else {
			
			
				
				 
			 $this_data = array(
				 "status" => "NO",
				 "message" => "Invalid Device(".$_REQUEST["d"].") and Warehouse(".$_REQUEST["to_warehouse"].") Setting"
				 );

			 array_push($qr_verify_array, $this_data);
						 
			
			
		}
	    
	    
	    
	    
	    
	    
	    
	
				
		    
	    
	    
	    
	    
}
else {

    	$this_data = array(
		  "status" => "NO",
		  "message" => "Invalid Login Information"
   	);

   array_push($main_array, $this_data);
}
 


$content_array["login"] = $main_array;
$content_array["qr_verify"] = $qr_verify_array;



$json = json_encode($content_array);

echo $json;






?>
