<?php
    session_start ( );
    $GLOBALS [ 'request_uri' ] = explode ( "/", $_GET [ 'URI' ] );
    if ( ! file_exists ( 'config.json' ) ) {
        if ( $GLOBALS[ 'request_uri' ] [ 0 ] !== "install" ) {
            header ( "Location: " . substr ( $_SERVER [ 'SCRIPT_NAME' ], 0, -10 ) . "/install" );
        }
    }
    if ( $GLOBALS [ 'request_uri' ] [ 0 ] == "install" ) {
        include ( 'lib/php/install.php' );
        exit;
    }
    require_once ( 'functions.php' );
    $GLOBALS [ 'config' ] = load_config ( );
    if ( isset ( $GLOBALS [ 'request_uri' ] [ 0 ] ) && $GLOBALS [ 'request_uri' ] [ 0 ] != "" ) {
        switch ( $GLOBALS [ 'request_uri' ] [ 0 ] ) {
            case "go":
                include ( 'lib/php/go.php' );
                break;
            case "login":
                include ( 'lib/php/login.php' );
                break;
            case "logout":
                include ( 'lib/php/management/logout.php' );
                break;
            case "dashboard":
                include ( 'lib/php/dashboard.php' );
                break;
            default:
                http_response_code ( 404 );
                include ( 'lib/errors/404.html' );
                die ( );
        }
    }
    else {
        header ( "Location: " . $GLOBALS [ 'config' ] [ 'installation_path' ] . "/login" );
    }