<?php

	Try
	{
		// Populate Map Array
		// ...........................................
		$GET_MAP_ARRAY = PHPCUS_RECORD_POSDEVICE::CUS_PREPARE_MAPPED_ARRAY_FOR_GET();	
		$GET_MAP_ARRAY['PARAM_REC_POSDEVICE_ID'] = PHPCUS_Account_Login_Session::$SESSION_AUTHENTICATED_REC_POSDEVICE_ID;
		$GET_MAP_ARRAY['PARAM_REC_POSDEVICE_STATUS'] = 2;
		$GET_MAP_ARRAY["PARAM_LIMIT"] = 1;
		
		
		// Execute Stored Procedure
		// ...........................................
		$DATA_SET = PHPCUS_RECORD_POSDEVICE::CUS_GET_MA($GET_MAP_ARRAY);
		
					
		// Return JSON response
		// ...........................................
		if(empty($DATA_SET) === False)
		{
		    PHPCUS_Account_Login_Session::$SESSION_AUTHENTICATED_REC_POSDEVICE_ID = $DATA_SET[0]["REC_POSDEVICE_ID"];
		    PHPCUS_Account_Login_Session::$SESSION_AUTHENTICATED_REC_POSDEVICE_ACC_GROUP_ID = $DATA_SET[0]["REC_POSDEVICE_ACC_GROUP_ID"];
		    PHPCUS_Account_Login_Session::$SESSION_AUTHENTICATED_REC_POSDEVICE_DESCRIPTION = $DATA_SET[0]["REC_POSDEVICE_DESCRIPTION"];
		    PHPCUS_Account_Login_Session::$SESSION_AUTHENTICATED_REC_POSDEVICE_MODEL = $DATA_SET[0]["REC_POSDEVICE_MODEL"];
		    PHPCUS_Account_Login_Session::$SESSION_AUTHENTICATED_REC_POSDEVICE_CODE = $DATA_SET[0]["REC_POSDEVICE_CODE"];
		    PHPCUS_Account_Login_Session::$SESSION_AUTHENTICATED_REC_POSDEVICE_OS = $DATA_SET[0]["REC_POSDEVICE_OS"];
		    
		    PHPCUS_Account_Login_Session::$SESSION_AUTHENTICATED_REC_POSDEVICE_MACHINE_ID = $DATA_SET[0]["REC_POSDEVICE_MACHINE_ID"];
		    PHPCUS_Account_Login_Session::$SESSION_AUTHENTICATED_REC_POSDEVICE_PERMIT_NUMBER = $DATA_SET[0]["REC_POSDEVICE_PERMIT_NUMBER"];
		    PHPCUS_Account_Login_Session::$SESSION_AUTHENTICATED_REC_POSDEVICE_DATE_ACCREDITED = $DATA_SET[0]["REC_POSDEVICE_DATE_ACCREDITED"];
		    PHPCUS_Account_Login_Session::$SESSION_AUTHENTICATED_REC_POSDEVICE_ADDRESS = $DATA_SET[0]["REC_POSDEVICE_ADDRESS"];
		    PHPCUS_Account_Login_Session::$SESSION_AUTHENTICATED_REC_POSDEVICE_CONTACT = $DATA_SET[0]["REC_POSDEVICE_CONTACT"];
		    PHPCUS_Account_Login_Session::$SESSION_AUTHENTICATED_REC_POSDEVICE_TIN = $DATA_SET[0]["REC_POSDEVICE_TIN"];
		    PHPCUS_Account_Login_Session::$SESSION_AUTHENTICATED_REC_POSDEVICE_RESET_COUNT = $DATA_SET[0]["REC_POSDEVICE_RESET_COUNT"];
		    PHPCUS_Account_Login_Session::CUS_SESSION_SAVE();
		    
			PHPCUS_PARAM::CUS_JSON_SUCCESS($DATA_SET);
		}
		else
		{
			PHPCUS_PARAM::CUS_JSON_SUCCESS('');
		}
		
	}
	Catch(Exception $ERR)
	{		
		PHPVC_LOG::VAR_REPORT_ERROR($ERR, 0);
		if(isset($_SERVER['HTTP_ORIGIN']))
		{
		    PHPVC_LOG::VAR_ERROR('HTTP_ORIGIN', $_SERVER['HTTP_ORIGIN']);
		}
		if(isset($_SERVER['HTTP_HOST']))
		{
		    PHPVC_LOG::VAR_ERROR('HTTP_HOST', $_SERVER['HTTP_HOST']);
		}		
		if(isset($_SERVER['HTTP_REFERER']))
		{
		    PHPVC_LOG::VAR_ERROR('HTTP_REFERER', $_SERVER['HTTP_REFERER']);
		}
		if(isset($_SERVER['REMOTE_ADDR']))
		{
		    PHPVC_LOG::VAR_ERROR('REMOTE_ADDR', $_SERVER['REMOTE_ADDR']);
		}
		
		PHPCUS_PARAM::CUS_JSON_ERROR($ERR->getMessage());
	}

?>