<?php
/**
 * Created by PhpStorm.
 * User: sunusi
 * Date: 11/23/2018
 * Time: 7:56 AM
 */

/*
 * Initializing setting and include necessary files
 */
require_once "initialize.php";

/*
 * This line of code must be at the top
 */
$URL = explode("/", $_SERVER["QUERY_STRING"]);

$fPage = $URL[0];

//	echo "<pre>";
//	echo print_r($URL);
//	echo print_r($_SERVER);
//	echo "</pre>";

//conditions
if (isset($_SESSION['YUZA_ID'])) {

    firstPOINT:

    include_once "static/head-script.php";
    // Pre Loader -->
    include_once "static/preloader.php";
    //-- Top Navigation -->
    include_once "static/top-navigation.php";
    //-- Top Menu
    include_once "static/top-menu.php";

    //check if the url is not empty
    if (!empty($fPage)) {
        if ($fPage != "index") {
            if (file_exists($_SESSION['YUZA_ROLE_LOCATION'] . $fPage . ".php")) {
                require $_SESSION['YUZA_ROLE_LOCATION'] . $fPage . ".php";
                goto processCONTINUE;
            } else {
                goto fileNotFound;
            }
        } else {
            $fPage = "home";
            goto firstPOINT;
        }
    } else {
        require $_SESSION['YUZA_ROLE_LOCATION'] . $fPage . "home.php";
        goto processCONTINUE;
    }
    /*
     * File not found
     */
    fileNotFound:
    require "404.php";
    /*
     * Continue
     */
    processCONTINUE:
    //-- Back to Top -->
    include_once "static/back-to-top.php";
    //-- footer -->
    include_once "static/footer.php";

    // -- end scripts -->
    include_once "static/foot-script.php";
    /*
     * skip below and goto end of this document
     */
    goto fEXIT;

} else {
    if (!empty($fPage)) {
        if ($fPage != "index") {
            if (file_exists($fPage . ".php")) {
                require $fPage . ".php";
                goto fEXIT;
            } else {
                goto LOGIN;
            }
        } else {
            if (isset($_SESSION['YUZA_ID'])) {
                require $_SESSION['YUZA_ROLE_LOCATION'] . $fPage . "home.php";
                goto processCONTINUE;
            } else {
                goto LOGIN;
            }
        }

    } else {
        goto LOGIN;
    }
}
/*
 * login form
 */
LOGIN:
require "login.php";
/*
 * termination
 */
fEXIT:
