<?php

// Check nonce
PHPCUS_PARAM::CUS_REQUIRES_NONCE();

// Check Array Input
PHPCUS_PARAM::CUS_DOES_NOT_SUPPORT_ARRAY();

// Check already authenticated
PHPCUS_PARAM::CUS_REQUIRES_AUTHENTICATION();

// Check access rights
PHPCUS_PARAM::CUS_HAS_PERMISSION(PHPCUS_SYSTEM::AUTHORITY_VIEW_ONLY, 'mobile_inbox');


if
(
		PHPRC_HTTP_PARAM::REF_ISSET_IN_ARRAY
		(
				[
						'PARAM_INBOX_ID',
						'PARAM_INBOX_TRANSACTION_ID',
						'PARAM_INBOX_SHORTCODE',
						'PARAM_INBOX_COMPANY_CODE',
						
						'PARAM_INBOX_MOBILE_NUMBER',
						'PARAM_INBOX_SERVICE_CODE',
						'PARAM_INBOX_MESSAGE',
						'PARAM_INBOX_RESPONSE',
						'PARAM_INBOX_CHARGE',
						'PARAM_INBOX_TIMESTAMP_FROM',
						'PARAM_INBOX_TIMESTAMP_TO',
						'PARAM_INBOX_RESULT',
						'PARAM_INBOX_STATUS',
						
						'PARAM_ORDER_FIELD',
						'PARAM_ORDER_TYPE',
						'PARAM_SKIP'
				], True
				)
		)
{
	Try
	{
		// Read params
		// ------------------------------------------------------------------
		
		$PARAM_INBOX_ID = PHPCUS_PARAM::CUS_READ_BIGINT('PARAM_INBOX_ID');
		$PARAM_INBOX_TRANSACTION_ID = PHPCUS_PARAM::CUS_READ_NVARCHAR('PARAM_INBOX_TRANSACTION_ID');
		$PARAM_INBOX_SHORTCODE = PHPCUS_PARAM::CUS_READ_NVARCHAR('PARAM_INBOX_SHORTCODE');
		$PARAM_INBOX_COMPANY_CODE = PHPCUS_PARAM::CUS_READ_NVARCHAR('PARAM_INBOX_COMPANY_CODE');
		
		$PARAM_INBOX_MOBILE_NUMBER = PHPCUS_PARAM::CUS_READ_NVARCHAR('PARAM_INBOX_MOBILE_NUMBER');
		$PARAM_INBOX_SERVICE_CODE = PHPCUS_PARAM::CUS_READ_NVARCHAR('PARAM_INBOX_SERVICE_CODE');
		$PARAM_INBOX_MESSAGE = PHPCUS_PARAM::CUS_READ_NVARCHAR('PARAM_INBOX_MESSAGE');
		$PARAM_INBOX_RESPONSE = PHPCUS_PARAM::CUS_READ_NVARCHAR('PARAM_INBOX_RESPONSE');
		$PARAM_INBOX_CHARGE = PHPCUS_PARAM::CUS_READ_NVARCHAR('PARAM_INBOX_CHARGE');
		$PARAM_INBOX_TIMESTAMP_FROM = PHPCUS_PARAM::CUS_READ_DATETIME('PARAM_INBOX_TIMESTAMP_FROM');
		$PARAM_INBOX_TIMESTAMP_TO = PHPCUS_PARAM::CUS_READ_DATETIME('PARAM_INBOX_TIMESTAMP_TO');
		$PARAM_INBOX_RESULT = PHPCUS_PARAM::CUS_READ_NVARCHAR('PARAM_INBOX_RESULT');
		$PARAM_INBOX_STATUS = PHPCUS_PARAM::CUS_READ_INT('PARAM_INBOX_STATUS');
		
		$PARAM_ORDER_FIELD = PHPCUS_PARAM::CUS_READ_SORT_FIELD
		(
				'PARAM_ORDER_FIELD',
				[
						'INBOX_ID',
						'INBOX_TRANSACTION_ID',
						'INBOX_SHORTCODE',
						'INBOX_COMPANY_CODE',
						
						'INBOX_MOBILE_NUMBER',
						'INBOX_SERVICE_CODE',
						'INBOX_MESSAGE',
						'INBOX_RESPONSE',
						'INBOX_CHARGE',
						'INBOX_TIMESTAMP',
						'INBOX_RESULT',
						'INBOX_STATUS'
				]
				);
		
		$PARAM_ORDER_TYPE = PHPCUS_PARAM::CUS_READ_SORT_TYPE('PARAM_ORDER_TYPE');
		$PARAM_SKIP	= PHPCUS_PARAM::CUS_READ_BIGINT('PARAM_SKIP');
		
		// ------------------------------------------------------------------
		
		
		// Execute Stored Procedure
		$DATA_SET = PHPCUS_MOBILE_INBOX::CUS_GET
		(
			$PARAM_INBOX_ID,
			$PARAM_INBOX_TRANSACTION_ID,
			$PARAM_INBOX_SHORTCODE,
			$PARAM_INBOX_COMPANY_CODE,
			
			$PARAM_INBOX_MOBILE_NUMBER,
			$PARAM_INBOX_SERVICE_CODE,
			$PARAM_INBOX_MESSAGE,
			$PARAM_INBOX_RESPONSE,
			$PARAM_INBOX_CHARGE,
			$PARAM_INBOX_TIMESTAMP_FROM,
			$PARAM_INBOX_TIMESTAMP_TO,
			$PARAM_INBOX_RESULT,
			$PARAM_INBOX_STATUS,
			
			$PARAM_ORDER_FIELD,
			$PARAM_ORDER_TYPE,
			$PARAM_SKIP
		);
		
		// Return JSON response
		if(empty($DATA_SET) === False)
		{
			PHPCUS_PARAM::CUS_JSON_SUCCESS($DATA_SET);
		}
		else
		{
			PHPCUS_PARAM::CUS_JSON_SUCCESS('');
		}
		
	}
	Catch(Exception $ERR)
	{
		PHPVC_LOG::VAR_REPORT_ERROR($ERR, 0);
		PHPCUS_PARAM::CUS_JSON_ERROR($ERR->getMessage());
	}
}
else
{
	PHPCUS_PARAM::CUS_JSON_ERROR('Missing parameters');
}

?>