<?php
    session_start ( );
    $request_uri = explode ( "/", $_GET [ 'URI' ] );
    if ( ! file_exists ( 'config.json' ) ) {
        if ( $request_uri [ 0 ] !== "install" ) {
            header ( "Location: " . substr ( $_SERVER [ 'SCRIPT_NAME' ], 0, -10 ) . "/install" );
        }
    }
    if ( $request_uri [ 0 ] == "install" ) {
        include ( 'lib/php/install.php' );
        exit;
    }
    require_once ( 'functions.php' );
    $config = load_config ( );
    session_set_cookie_params ( 43200, $config [ 'installation_path' ], $config [ 'domain' ], true );
    if ( isset ( $request_uri [ 0 ] ) && $request_uri [ 0 ] != "" ) {
        switch ( $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: " . $config [ 'installation_path' ] . "/login" );
    }