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

	if
	(
			PHPRC_HTTP_PARAM::REF_ISSET_IN_ARRAY
			(
					[
							'PARAM_ACC_ACCOUNT_ID',
							'PARAM_ACC_ACCOUNT_SERVER_ID',
							'PARAM_ACC_ACCOUNT_ACC_LEVEL_ID',
							'PARAM_ACC_ACCOUNT_ACC_GROUP_ID',
							
							'PARAM_ACC_ACCOUNT_USERNAME',
							'PARAM_ACC_ACCOUNT_NAME',
							'PARAM_ACC_ACCOUNT_FIRST_NAME',
							'PARAM_ACC_ACCOUNT_MIDDLE_NAME',
							'PARAM_ACC_ACCOUNT_LAST_NAME',
							
							'PARAM_ACC_ACCOUNT_POSITION',
							'PARAM_ACC_ACCOUNT_SYS_GENDER_ID',
												
							'PARAM_ACC_ACCOUNT_STATUS',
							'PARAM_ACC_ACCOUNT_SYSTEM_GENERATED',
							
							'PARAM_ORDER_FIELD',
							'PARAM_ORDER_TYPE',
							'PARAM_SKIP'
					], True
			)
	)
	{
		Try
		{
			// Read params
			// ------------------------------------------------------------------
			$PARAM_ACCOUNT_ID = PHPCUS_PARAM::CUS_READ_BIGINT('PARAM_ACC_ACCOUNT_ID');
			$PARAM_ACCOUNT_SERVER_ID = PHPCUS_PARAM::CUS_READ_BIGINT('PARAM_ACC_ACCOUNT_SERVER_ID');
			$PARAM_ACCOUNT_LEVEL_ID = PHPCUS_PARAM::CUS_READ_BIGINT('PARAM_ACC_ACCOUNT_ACC_LEVEL_ID');
			$PARAM_ACCOUNT_GROUP_ID = PHPCUS_PARAM::CUS_READ_BIGINT('PARAM_ACC_ACCOUNT_ACC_GROUP_ID');

			$PARAM_ACCOUNT_USERNAME = PHPCUS_PARAM::CUS_READ_NVARCHAR('PARAM_ACC_ACCOUNT_USERNAME');
			$PARAM_ACCOUNT_NAME = PHPCUS_PARAM::CUS_READ_NVARCHAR('PARAM_ACC_ACCOUNT_NAME');
			$PARAM_ACCOUNT_FIRST_NAME = PHPCUS_PARAM::CUS_READ_NVARCHAR('PARAM_ACC_ACCOUNT_FIRST_NAME');
			$PARAM_ACCOUNT_MIDDLE_NAME = PHPCUS_PARAM::CUS_READ_NVARCHAR('PARAM_ACC_ACCOUNT_MIDDLE_NAME');
			$PARAM_ACCOUNT_LAST_NAME = PHPCUS_PARAM::CUS_READ_NVARCHAR('PARAM_ACC_ACCOUNT_LAST_NAME');
				
			$PARAM_ACCOUNT_GENDER_ID = PHPCUS_PARAM::CUS_READ_TINYINT('PARAM_ACC_ACCOUNT_SYS_GENDER_ID');
			$PARAM_ACCOUNT_POSITION = PHPCUS_PARAM::CUS_READ_NVARCHAR('PARAM_ACC_ACCOUNT_POSITION');
			
			$PARAM_ACCOUNT_STATUS = PHPCUS_PARAM::CUS_READ_TINYINT('PARAM_ACC_ACCOUNT_STATUS');
			$PARAM_SYSTEM_GENERATED = PHPCUS_PARAM::CUS_READ_TINYINT('PARAM_ACC_ACCOUNT_SYSTEM_GENERATED');
			
			$PARAM_ORDER_FIELD = PHPCUS_PARAM::CUS_READ_SORT_FIELD
			(
					'PARAM_ORDER_FIELD', 
					[
						'ACC_ACCOUNT_ID',
						'ACC_ACCOUNT_SERVER_ID',
						'ACC_ACCOUNT_ACC_LEVEL_ID',
						'ACC_ACCOUNT_ACC_GROUP_ID',
							
						'ACC_ACCOUNT_USERNAME',
						'ACC_ACCOUNT_FIRST_NAME',
						'ACC_ACCOUNT_MIDDLE_NAME',
						'ACC_ACCOUNT_LAST_NAME',
							
						'ACC_ACCOUNT_SYS_GENDER_ID',
						'ACC_ACCOUNT_POSITION',
							
						'ACC_ACCOUNT_STATUS',
						'ACC_SYSTEM_GENERATED',
							
						'ACC_LEVEL_TAG_ID',
						'ACC_LEVEL_DESCRIPTION',
							
						'SYS_GENDER_DESCRIPTION',
						'SYS_STATUS_DESCRIPTION'
					]
			);

			$PARAM_ORDER_TYPE = PHPCUS_PARAM::CUS_READ_SORT_TYPE('PARAM_ORDER_TYPE');
			$PARAM_SKIP	= PHPCUS_PARAM::CUS_READ_BIGINT('PARAM_SKIP');
			// ------------------------------------------------------------------
			
			
			// Execute Stored Procedure
			$GET_MAP_ARRAY = PHPCUS_ACCOUNT_MEMBER::CUS_PREPARE_MAPPED_ARRAY_FOR_GET();
			
			$GET_MAP_ARRAY['PARAM_ACC_ACCOUNT_ID'] = $PARAM_ACCOUNT_ID;
			$GET_MAP_ARRAY['PARAM_ACC_ACCOUNT_SERVER_ID'] = $PARAM_ACCOUNT_SERVER_ID;
			$GET_MAP_ARRAY['PARAM_ACC_ACCOUNT_ACC_LEVEL_ID'] = $PARAM_ACCOUNT_LEVEL_ID;
			$GET_MAP_ARRAY['PARAM_ACC_ACCOUNT_ACC_GROUP_ID'] = $PARAM_ACCOUNT_GROUP_ID;
			
			$GET_MAP_ARRAY['PARAM_ACC_ACCOUNT_USERNAME'] = $PARAM_ACCOUNT_USERNAME;
			$GET_MAP_ARRAY['PARAM_ACC_ACCOUNT_NAME'] = $PARAM_ACCOUNT_NAME;
			$GET_MAP_ARRAY['PARAM_ACC_ACCOUNT_FIRST_NAME'] = $PARAM_ACCOUNT_FIRST_NAME;
			$GET_MAP_ARRAY['PARAM_ACC_ACCOUNT_MIDDLE_NAME'] = $PARAM_ACCOUNT_MIDDLE_NAME;
			$GET_MAP_ARRAY['PARAM_ACC_ACCOUNT_LAST_NAME'] = $PARAM_ACCOUNT_LAST_NAME;
			$GET_MAP_ARRAY['PARAM_ACC_ACCOUNT_POSITION'] = $PARAM_ACCOUNT_POSITION;
			$GET_MAP_ARRAY['PARAM_ACC_ACCOUNT_SYS_GENDER_ID'] = $PARAM_ACCOUNT_GENDER_ID;
			$GET_MAP_ARRAY['PARAM_ACC_ACCOUNT_STATUS'] = $PARAM_ACCOUNT_STATUS;
			$GET_MAP_ARRAY['PARAM_ACC_ACCOUNT_SYSTEM_GENERATED'] = $PARAM_SYSTEM_GENERATED;
			
			$GET_MAP_ARRAY["PARAM_ORDER_FIELD"] = $PARAM_ORDER_FIELD;
			$GET_MAP_ARRAY["PARAM_ORDER_TYPE"] = $PARAM_ORDER_TYPE;
			$GET_MAP_ARRAY["PARAM_SKIP"] = $PARAM_SKIP;
			
			/*
			$DATA_SET = PHPCUS_Account_Member::CUS_GET
						(
								$PARAM_ACCOUNT_ID,
								$PARAM_ACCOUNT_SERVER_ID,
								$PARAM_ACCOUNT_LEVEL_ID,
								$PARAM_ACCOUNT_GROUP_ID,
								$PARAM_ACCOUNT_USERNAME,
								
								$PARAM_ACCOUNT_NAME,
								$PARAM_ACCOUNT_FIRST_NAME,
								$PARAM_ACCOUNT_MIDDLE_NAME,
								$PARAM_ACCOUNT_LAST_NAME,
								
								$PARAM_ACCOUNT_GENDER_ID,
								$PARAM_ACCOUNT_POSITION,
								
								$PARAM_ACCOUNT_STATUS,
								$PARAM_SYSTEM_GENERATED,
								
								$PARAM_ORDER_FIELD, 
								$PARAM_ORDER_TYPE, 
								$PARAM_SKIP
						);
			*/
			
			// Execute Stored Procedure
			// ...........................................
			$DATA_SET = PHPCUS_ACCOUNT_MEMBER::CUS_GET_MA($GET_MAP_ARRAY);
						
			// Return JSON response
			if(isset($DATA_SET[0]['ACCOUNT_PASSWORD']) === true)
			{
				Unset($DATA_SET[0]['ACCOUNT_PASSWORD']);
			}
			PHPCUS_PARAM::CUS_JSON_SUCCESS($DATA_SET);
			
		}
		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');
	}

?>