<?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_service_code');


if
(
		PHPRC_HTTP_PARAM::REF_ISSET_IN_ARRAY
		(
				[
						'PARAM_SCODE_ID',
						'PARAM_SCODE_SHORTCODE',
						'PARAM_SCODE_COMPANY_CODE',
						'PARAM_SCODE_CODE',
						'PARAM_SCODE_RESPONSE',
						'PARAM_SCODE_CHARGE',
						'PARAM_SCODE_FILTER_STATUS',
						'PARAM_SCODE_FILTER_LIMIT_FROM',
						'PARAM_SCODE_FILTER_LIMIT_TO',
						'PARAM_SCODE_STATUS',
						
						'PARAM_ORDER_FIELD',
						'PARAM_ORDER_TYPE',
						'PARAM_SKIP'
				], True
				)
		)
{
	Try
	{
		// Read params
		// ------------------------------------------------------------------
		
		$PARAM_SCODE_ID = PHPCUS_PARAM::CUS_READ_BIGINT('PARAM_SCODE_ID');
		$PARAM_SCODE_SHORTCODE = PHPCUS_PARAM::CUS_READ_NVARCHAR('PARAM_SCODE_SHORTCODE');
		$PARAM_SCODE_COMPANY_CODE = PHPCUS_PARAM::CUS_READ_NVARCHAR('PARAM_SCODE_COMPANY_CODE');
		$PARAM_SCODE_CODE = PHPCUS_PARAM::CUS_READ_NVARCHAR('PARAM_SCODE_CODE');
		$PARAM_SCODE_RESPONSE = PHPCUS_PARAM::CUS_READ_NVARCHAR('PARAM_SCODE_RESPONSE');
		$PARAM_SCODE_CHARGE = PHPCUS_PARAM::CUS_READ_NVARCHAR('PARAM_SCODE_CHARGE');
		$PARAM_SCODE_FILTER_STATUS = PHPCUS_PARAM::CUS_READ_INT('PARAM_SCODE_FILTER_STATUS');
		$PARAM_SCODE_FILTER_LIMIT_FROM = PHPCUS_PARAM::CUS_READ_INT('PARAM_SCODE_FILTER_LIMIT_FROM');
		$PARAM_SCODE_FILTER_LIMIT_TO = PHPCUS_PARAM::CUS_READ_INT('PARAM_SCODE_FILTER_LIMIT_TO');
		$PARAM_SCODE_STATUS = PHPCUS_PARAM::CUS_READ_INT('PARAM_SCODE_STATUS');
		
		$PARAM_ORDER_FIELD = PHPCUS_PARAM::CUS_READ_SORT_FIELD
		(
				'PARAM_ORDER_FIELD',
				[
						'SCODE_ID',
						'SCODE_SHORTCODE',
						'SCODE_COMPANY_CODE',
						'SCODE_CODE',
						'SCODE_RESPONSE',
						'SCODE_CHARGE',
						'SCODE_FILTER_STATUS',
						'SCODE_FILTER_LIMIT',
						'SCODE_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_SERVICE_CODE::CUS_GET
		(
				$PARAM_SCODE_ID,
				$PARAM_SCODE_SHORTCODE,
				$PARAM_SCODE_COMPANY_CODE,
				
				$PARAM_SCODE_CODE,
				$PARAM_SCODE_RESPONSE,
				$PARAM_SCODE_CHARGE,
				$PARAM_SCODE_FILTER_STATUS,
				$PARAM_SCODE_FILTER_LIMIT_FROM,
				$PARAM_SCODE_FILTER_LIMIT_TO,
				$PARAM_SCODE_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');
}

?>