<?php

	// Initialize
	$DATA_SET = null;
	$JS_Libraries = '';
	
	// Execute Stored Procedure
	if (PHPCUS_SP::$SESSION_AUTHENTICATED_ACCOUNT_ID > 0)
	{
		$DATA_SET = PHPCUS_Account_Member::CUS_GET(PHPCUS_SP::$SESSION_AUTHENTICATED_ACCOUNT_ID);
	}
	
	// Return JSON response
	$JS_Libraries = $JS_Libraries . "function JSCUS_CACHE(){};\n";
	if(empty($DATA_SET) === False)
	{
		$JS_Libraries = $JS_Libraries .
			"JSCUS_CACHE['SITE_SHOW_RESULT_PER_PAGE_PLAIN_TEXT'] = " . PHPSET::SITE_SHOW_RESULT_PER_PAGE_PLAIN_TEXT . "; \n" .
			"JSCUS_CACHE['SITE_ARRAY_REQUEST_LIMIT'] = " . PHPSET::SITE_ARRAY_REQUEST_LIMIT . "; \n" .
			"JSCUS_CACHE['AUTH_ACC_ACCOUNT_ID'] = " . $DATA_SET[0]['ACC_ACCOUNT_ID'] . "; \n" .
			"JSCUS_CACHE['AUTH_ACC_ACCOUNT_SERVER_ID'] = " . $DATA_SET[0]['ACC_ACCOUNT_SERVER_ID'] . "; \n" .
			
			"JSCUS_CACHE['AUTH_ACC_ACCOUNT_ACC_LEVEL_ID'] = " . $DATA_SET[0]['ACC_ACCOUNT_ACC_LEVEL_ID']. "; \n" .
			"JSCUS_CACHE['AUTH_ACC_LEVEL_TAG_ID'] = " . $DATA_SET[0]['ACC_LEVEL_TAG_ID'] . "; \n" .
			"JSCUS_CACHE['AUTH_ACC_LEVEL_DESCRIPTION'] = '" . $DATA_SET[0]['ACC_LEVEL_DESCRIPTION'] . "'; \n" .
			
			"JSCUS_CACHE['AUTH_ACC_ACCOUNT_ACC_GROUP_ID'] = " . $DATA_SET[0]['ACC_ACCOUNT_ACC_GROUP_ID'] . "; \n" .
			"JSCUS_CACHE['AUTH_ACC_GROUP_DESCRIPTION'] = '" . $DATA_SET[0]['ACC_GROUP_DESCRIPTION'] . "'; \n" .
			
			"JSCUS_CACHE['AUTH_ACC_ACCOUNT_USERNAME'] = '" . $DATA_SET[0]['ACC_ACCOUNT_USERNAME'] . "'; \n" .
			"JSCUS_CACHE['AUTH_ACC_ACCOUNT_FIRST_NAME'] = '" . $DATA_SET[0]['ACC_ACCOUNT_FIRST_NAME'] . "'; \n" .
			"JSCUS_CACHE['AUTH_ACC_ACCOUNT_MIDDLE_NAME'] = '" . $DATA_SET[0]['ACC_ACCOUNT_MIDDLE_NAME'] . "'; \n" .
			"JSCUS_CACHE['AUTH_ACC_ACCOUNT_LAST_NAME'] = '" . $DATA_SET[0]['ACC_ACCOUNT_LAST_NAME'] . "'; \n" .
			
			"JSCUS_CACHE['AUTH_ACC_ACCOUNT_SYS_GENDER_ID'] = " . $DATA_SET[0]['ACC_ACCOUNT_SYS_GENDER_ID'] . "; \n" .
			"JSCUS_CACHE['AUTH_SYS_GENDER_DESCRIPTION'] = '" . $DATA_SET[0]['SYS_GENDER_DESCRIPTION'] . "'; \n";
	}
	else
	{
		$JS_Libraries = $JS_Libraries .
			"JSCUS_CACHE['SITE_SHOW_RESULT_PER_PAGE_PLAIN_TEXT'] = " . PHPSET::SITE_SHOW_RESULT_PER_PAGE_PLAIN_TEXT . "; \n" .
			"JSCUS_CACHE['SITE_ARRAY_REQUEST_LIMIT'] = " . PHPSET::SITE_ARRAY_REQUEST_LIMIT . "; \n" .
			"JSCUS_CACHE['AUTH_ACC_ACCOUNT_ID'] = 0; \n" .
			"JSCUS_CACHE['AUTH_ACC_ACCOUNT_SERVER_ID'] = 0; \n" .
			
			"JSCUS_CACHE['AUTH_ACC_ACCOUNT_ACC_LEVEL_ID'] = 0; \n" .
			"JSCUS_CACHE['AUTH_ACC_LEVEL_TAG_ID'] = 0; \n" .
			"JSCUS_CACHE['AUTH_ACC_LEVEL_DESCRIPTION'] = 'Guest User'; \n" .
			
			"JSCUS_CACHE['AUTH_ACC_ACCOUNT_ACC_GROUP_ID'] = 0; \n" .
			"JSCUS_CACHE['AUTH_ACC_GROUP_DESCRIPTION'] = 'Independent'; \n" .
			
			"JSCUS_CACHE['AUTH_ACC_ACCOUNT_USERNAME'] = 'guest'; \n" .
			"JSCUS_CACHE['AUTH_ACC_ACCOUNT_FIRST_NAME'] = 'Guest'; \n" .
			"JSCUS_CACHE['AUTH_ACC_ACCOUNT_MIDDLE_NAME'] = ''; \n" .
			"JSCUS_CACHE['AUTH_ACC_ACCOUNT_LAST_NAME'] = ''; \n" .
			
			"JSCUS_CACHE['AUTH_ACC_ACCOUNT_SYS_GENDER_ID'] = '1'; \n" .
			"JSCUS_CACHE['AUTH_SYS_GENDER_DESCRIPTION'] = 'Male'; \n";
	}
	$JS_Libraries = $JS_Libraries . "function JSCUS_SQL(){};\n";
	
	// Load add javascript data in this folder
	Foreach (array_map('basename', glob(PHPSET::$ROOT . '/Server/JavascriptCustom/*.js')) AS $IMPORT_LIBRARIES)
	{
		//echo $IMPORT_LIBRARIES . '<br />';
		$JS_Libraries = $JS_Libraries . "\n" . PHPRC_FSO_FILE::REF_READALL($IMPORT_LIBRARIES, PHPSET::$ROOT . '/Server/JavascriptCustom/');
	}

	Foreach (array_map('basename', glob(PHPSET::$ROOT . '/Server/JavascriptCustom/Account/*.js')) AS $IMPORT_LIBRARIES)
	{
		//echo $IMPORT_LIBRARIES . '<br />';
		$JS_Libraries = $JS_Libraries . "\n" . PHPRC_FSO_FILE::REF_READALL($IMPORT_LIBRARIES, PHPSET::$ROOT . '/Server/JavascriptCustom/Account/');
	}
	
	Foreach (array_map('basename', glob(PHPSET::$ROOT . '/Server/JavascriptCustom/Category/*.js')) AS $IMPORT_LIBRARIES)
	{
		//echo $IMPORT_LIBRARIES . '<br />';
		$JS_Libraries = $JS_Libraries . "\n" . PHPRC_FSO_FILE::REF_READALL($IMPORT_LIBRARIES, PHPSET::$ROOT . '/Server/JavascriptCustom/Category/');
	}

	header('Content-Type: application/javascript');
	echo PHPVC_COMPILER::REF_PROCESS_SCRIPT($JS_Libraries, False);
	Exit();

?>