<?php

	// Check nonce
	PHPCUS_PARAM::CUS_REQUIRES_NONCE();
	
	// Dismiss Session
	PHPVC_SESSION::VAR_STOP();

	// 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, 'account_access_rights');
	
	if
	(
			PHPRC_HTTP_PARAM::REF_ISSET_IN_ARRAY
			(
					[
							'PARAM_ACC_ACCESS_ID',
							'PARAM_ACC_ACCESS_SERVER_ID',
							
							'PARAM_ACC_ACCESS_ACC_LEVEL_ID',
							'PARAM_ACC_ACCESS_SYS_MODULE_ID',
							'PARAM_ACC_ACCESS_SYS_MODULE_KEYWORD',
							'PARAM_ACC_ACCESS_SYS_AUTHORITY_ID',
							'PARAM_ACC_ACCESS_AUTHORITY_POINT_FROM',
							'PARAM_ACC_ACCESS_AUTHORITY_POINT_TO',
							
							'PARAM_ORDER_FIELD',
							'PARAM_ORDER_TYPE',
							'PARAM_SKIP'
					], True
			)
	)
	{
		Try
		{	
			// Read params
			// ------------------------------------------------------------------
			$PARAM_ACC_ACCESS_ID = PHPCUS_PARAM::CUS_READ_BIGINT('PARAM_ACC_ACCESS_ID');
			$PARAM_ACC_ACCESS_SERVER_ID = PHPCUS_PARAM::CUS_READ_BIGINT('PARAM_ACC_ACCESS_SERVER_ID');
			
			$PARAM_ACC_ACCESS_LEVEL_ID = PHPCUS_PARAM::CUS_READ_BIGINT('PARAM_ACC_ACCESS_ACC_LEVEL_ID');
			$PARAM_ACC_ACCESS_MODULE_ID = PHPCUS_PARAM::CUS_READ_BIGINT('PARAM_ACC_ACCESS_SYS_MODULE_ID');
			$PARAM_ACC_ACCESS_MODULE_KEYWORD = PHPCUS_PARAM::CUS_READ_NVARCHAR('PARAM_ACC_ACCESS_SYS_MODULE_KEYWORD');
			
			$PARAM_ACC_ACCESS_AUTHORITY_ID = PHPCUS_PARAM::CUS_READ_INT('PARAM_ACC_ACCESS_SYS_AUTHORITY_ID');
			$PARAM_ACC_ACCESS_AUTHORITY_POINT_FROM = PHPCUS_PARAM::CUS_READ_INT('PARAM_ACC_ACCESS_AUTHORITY_POINT_FROM');
			$PARAM_ACC_ACCESS_AUTHORITY_POINT_TO = PHPCUS_PARAM::CUS_READ_INT('PARAM_ACC_ACCESS_AUTHORITY_POINT_TO');
			
			$PARAM_ORDER_FIELD = PHPCUS_PARAM::CUS_READ_SORT_FIELD
			(
					'PARAM_ORDER_FIELD', 
					[
						'ACC_ACCESS_ID',
						'ACC_ACCESS_SERVER_ID',
						'ACC_ACCESS_ACC_LEVEL_ID',
						'ACC_ACCESS_SYS_MODULE_ID',
						'ACC_ACCESS_SYS_AUTHORITY_ID',
						'ACC_ACCESS_AUTHORITY_POINT',
							
						'LEVEL_TAG_ID',
						'LEVEL_DESCRIPTION',
						'LEVEL_STATUS',
							
						'MODULE_CATEGORY',
						'MODULE_KEYWORD',
						'MODULE_NAME',
						'MODULE_DESCRIPTION',
						'MODULE_STATUS',
							
						'AUTHORITY_ID',
						'AUTHORITY_DESCRIPTION',
						'AUTHORITY_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_Account_Access_Rights::CUS_GET
						(
								$PARAM_ACC_ACCESS_ID,
								$PARAM_ACC_ACCESS_SERVER_ID,
								
								$PARAM_ACC_ACCESS_LEVEL_ID,
								$PARAM_ACC_ACCESS_MODULE_ID,
								$PARAM_ACC_ACCESS_MODULE_KEYWORD,
								
								$PARAM_ACC_ACCESS_AUTHORITY_ID,
								$PARAM_ACC_ACCESS_AUTHORITY_POINT_FROM,
								$PARAM_ACC_ACCESS_AUTHORITY_POINT_TO,
								
								$PARAM_ORDER_FIELD, 
								$PARAM_ORDER_TYPE, 
								$PARAM_SKIP
						);

			// Return JSON response
			PHPCUS_PARAM::CUS_JSON_SUCCESS($DATA_SET);
			
		}
		Catch(Exception $ERR)
		{
			PHPCUS_PARAM::CUS_JSON_ERROR($ERR);
		}
	}
	else
	{
		PHPCUS_PARAM::CUS_JSON_ERROR('Missing parameters');
	}

?>