<?php
/*
ob_start();
echo '{"REC_FILEDIR_ID":{"1":"1"},"REC_FILEDIR_CODE":{"1":"SYSDIR1"},"REC_FILEDIR_PARENT_ID":{"1":"0"},"REC_FILEDIR_CAT_DIRTYPE_ID":{"1":"1"},"REC_FILEDIR_DESCRIPTION":{"1":"root"},"REC_FILEDIR_URL":{"1":""},"REC_FILEDIR_FULL_PATH":{"1":"\/root"},"REC_FILEDIR_FULL_ID":{"1":"[0]"},"REC_FILEDIR_CAT_PRIVACY_ID":{"1":"2"},"REC_FILEDIR_SIZE":{"1":"4"},"REC_FILEDIR_REMARKS":{"1":""},"REC_FILEDIR_DATE_CREATED":{"1":"2021-02-09 00:00:00.000000"},"REC_FILEDIR_DATE_MODIFIED":{"1":"2021-02-09 00:00:00.000000"},"REC_FILEDIR_ACC_ACCOUNT_ID":{"1":"2"},"REC_FILEDIR_STATUS":{"1":"2"},"REC_FILEDIR_SYSTEM_GENERATED":{"1":"2"},"CAT_DIRTYPE_ID":{"1":"1"},"REC_FILEDIR_CAT_DIRTYPE_ID_DESCRIPTION":{"1":"Directory"},"CAT_DIRTYPE_DESCRIPTION":{"1":"Directory"},"CAT_DIRTYPE_CAN_CONTAIN_CHILD":{"1":"2"},"CAT_DIRTYPE_STATUS":{"1":"2"},"CAT_PRIVACY_ID":{"1":"2"},"REC_FILEDIR_CAT_PRIVACY_ID_DESCRIPTION":{"1":"Public"},"CAT_PRIVACY_DESCRIPTION":{"1":"Public"},"CAT_PRIVACY_STATUS":{"1":"2"},"ACC_ACCOUNT_ID":{"1":"2"},"ACC_ACCOUNT_SERVER_ID":{"1":"0"},"ACC_ACCOUNT_ACC_LEVEL_ID":{"1":"2"},"ACC_ACCOUNT_ACC_GROUP_ID":{"1":"2"},"ACC_ACCOUNT_ADD_RESOURCE_ID":{"1":"0"},"REC_FILEDIR_ACC_ACCOUNT_ID_DESCRIPTION":{"1":"admin"},"ACC_ACCOUNT_USERNAME":{"1":"admin"},"ACC_ACCOUNT_PASSWORD":{"1":"NePiE7V4WI85P8qe4GFq4MdUVk7SCIxg6331336639653633326366653437373362386136316562313065393230613730643033376330303334333136373834313333663732633235346262623532643331313162333162313438383632653136336262663165633965373831616561363233313638646532306266316364303038376665323437376334653039333037"},"ACC_ACCOUNT_AUTH_CODE":{"1":""},"ACC_ACCOUNT_NAME":{"1":"SYSTEM ,  SUPER ADMIN "},"ACC_ACCOUNT_FIRST_NAME":{"1":"SUPER ADMIN"},"ACC_ACCOUNT_MIDDLE_NAME":{"1":""},"ACC_ACCOUNT_LAST_NAME":{"1":"SYSTEM"},"ACC_ACCOUNT_POSITION":{"1":"Administrator"},"ACC_ACCOUNT_SYS_GENDER_ID":{"1":"1"},"ACC_ACCOUNT_STATUS":{"1":"2"},"ACC_ACCOUNT_SYSTEM_GENERATED":{"1":"2"},"SERVER_TIME":{"1":"2021-02-16 17:03:42.697478"},"RECORD_COUNT":{"1":"1"},"PROCESS_TIME":"0","IS_SUCCESS":"TRUE","JSON_COUNT":"1"}';
header("Connection: close");
ob_end_flush();
exit;
*/

	// Loads Modules
	// -----------------------------------------------------	
	$ROOT = Str_Replace('\\', '/', __DIR__);
	Include_Once $ROOT . '/Modules/INI.php';


	
	// Declare URI
	// -----------------------------------------------------	
	$URI 		= "";
	if(isset($_GET['url']))
	{
		$URI = $_GET['url'];
	}
	
	
	// For Response time test
	if($URI == 'test')
	{
	    
	}
	
	
	// RESTRICT TO HTTPS PROTOCOL
	// -----------------------------------------------------
	PHPRC_APP::REF_CHANGE_PROTOCOL("HTTPS");

	
	// DO NOT USE LOCALHOST
	// -----------------------------------------------------
	PHPRC_APP::REF_BLOCK_LOCALHOST();
	
	
	// Directory Loader [Server]
	// -----------------------------------------------------
	Class PHPDIR
	{   	
	    
	    // [ Server / Directory.php ] 
	    //=========================================================
	    Public Static function LOAD_SERVER($PHPDIR_URI)
	    {
	        // Display home
	        // ............................................
	        if(StrLen($PHPDIR_URI) <= 0)
	        {
	            header("HTTP/1.1 301 Moved Permanently");
	            header("Location: " . PHPSET::$SITE_URL . "/p/index.html");
	            Exit;
	        }
	        
	        // Redirect to proper pages
	        // ............................................
	        else if(PHPRC_FSO_FILE::REF_EXISTS('index.php', PHPSET::$ROOT . '/Server/' . $PHPDIR_URI) === True)
	        {
	            if
	            (
	                PHPVC_STR::VAR_RIGHT($PHPDIR_URI, 1) <> "/" &&
	                PHPVC_STR::VAR_RIGHT($PHPDIR_URI, 1) <> "\\"
	                )
	            {
	                $PHPDIR_URI = $PHPDIR_URI . "/";
	            }
	            
	            include PHPSET::$ROOT . '/Server/' . $PHPDIR_URI . 'index.php';
	        }
	        
	        // Show 404 not dound response
	        // ............................................
	        else
	        {
	            PHPRC_HEADERS::REF_404_NOT_FOUND(PHPSET::$SITE_URL . "/p/status/404.html");
	        }
	    }
	    
	    
	    // [ Pages / Directory.php ]
	    //=========================================================
	    Public Static function LOAD_PAGES($PHPDIR_URI)
	    {
	        // Display home
	        // ............................................
	        $FILE_NAME = Basename($PHPDIR_URI);
	        $FILE_PATH = '/Pages/' . PHPVC_STR::VAR_REPLACE($PHPDIR_URI, $FILE_NAME, '');
	        $FILE_EXTENTION = PathInfo($FILE_NAME, PATHINFO_EXTENSION);
	        
	        // Custom: Load from any image extension
	        // ............................................
	        if(StrToUpper($FILE_EXTENTION) == "IMG")
	        {
	            if(PHPVC_STR::VAR_CONTAINS_RIGHT($FILE_PATH , '/'))
	            {
	                PHPRC_HEADERS::REF_IMAGE(PHPSET::$ROOT . $FILE_PATH . $FILE_NAME);
	            }
	            else
	            {
	                PHPRC_HEADERS::REF_IMAGE(PHPSET::$ROOT . $FILE_PATH . '/' . $FILE_NAME);
	            }
	        }
	        
	        // Redirect to proper pages
	        // ............................................
	        if(PHPRC_FSO_FILE::REF_EXISTS($FILE_NAME, PHPSET::$ROOT . $FILE_PATH) === True)
	        {
	            // Do not allow access to Page/import folder
	            if(PHPVC_STR::VAR_CONTAINS_LEFT($FILE_PATH, '/Pages/import'))
	            {
	                PHPRC_HEADERS::REF_404_NOT_FOUND(PHPSET::$SITE_URL . "/p/status/404.html");
	                Exit();
	            }
	            
	            // Load Image
	            PHPRC_HEADERS::REF_IMAGE(PHPSET::$ROOT . $FILE_PATH . '/' . $FILE_NAME, true);

	            // Load Font
	            PHPRC_HEADERS::REF_FONT(PHPSET::$ROOT . $FILE_PATH . '/' . $FILE_NAME, true);
	            
	            // Load Media
	            PHPRC_HEADERS::REF_MEDIA(PHPSET::$ROOT . $FILE_PATH . $FILE_NAME, $FILE_NAME, true);
	            
	            // Load Document
	            PHPRC_HEADERS::REF_DOCUMENT(PHPSET::$ROOT . $FILE_PATH . '/' . $FILE_NAME, true);
	            
	            // Load Scripts
	            $FILE_CONTENTS = PHPRC_FSO_FILE::REF_READALL($FILE_NAME, PHPSET::$ROOT . $FILE_PATH);
	            $FILE_CONTENTS = PHPVC_COMPILER::REF_PROCESS_SCRIPT($FILE_CONTENTS, False);
	            
	            // HTML
	            if
	            (
	                StrToUpper($FILE_EXTENTION) == "HTML" ||
	                StrToUpper($FILE_EXTENTION) == "HTM"
	            )
	            {
	                echo $FILE_CONTENTS;
	                Exit();
	            }
	            
	            // CSS
	            elseif(StrToUpper($FILE_EXTENTION) == "CSS")
	            {
	                Header("Content-type: text/css");
	                echo $FILE_CONTENTS;
	                Exit();
	            }
	            
	            // JS
	            elseif(StrToUpper($FILE_EXTENTION) == "JS")
	            {
	                Header("Content-Type: application/javascript");
	                echo $FILE_CONTENTS;
	                Exit();
	            }      
	        }
	        
	        // Show 404 not dound response
	        // ............................................
	        else
	        {
	            PHPRC_HEADERS::REF_404_NOT_FOUND(PHPSET::$SITE_URL . "/p/status/404.html");
	        }        
	    }
	    

	    // [ index.php ]
	    //=========================================================
	    Public Static function LOAD_INDEX($PHPDIR_URI)
	    {
	        // Load Pages
	        // ............................................
	        if(StrLen($PHPDIR_URI) >= 2 && PHPVC_STR::VAR_LEFT($PHPDIR_URI, 2) == "p/")
	        {
	            if(StrLen($PHPDIR_URI) == 2)
	            {
	                PHPRC_HEADERS::REF_301_MOVED_PERMANENTLY(PHPSET::$SITE_URL . '/p/index.html');
	            }
	            $PHPDIR_URI = PHPVC_STR::VAR_RIGHT($PHPDIR_URI, StrLen($PHPDIR_URI) - 2);
	            self::LOAD_PAGES($PHPDIR_URI);
	        }
	        
	        // Load Server php files
	        // ............................................
	        else
	        {
	            self::LOAD_SERVER($PHPDIR_URI);
	        }
	        
	        // Terminate Request
	        // ............................................
	        exit(); 
	    }
	    
	}
	
	
	// Run directory control
	// -----------------------------------------------------
	PHPDIR::LOAD_INDEX($URI);
	
?>