<?php

$webPath = $_SERVER['WEB_PATH'];
$modulePath = "$webPath/php/modules";

# load main module to handle pages, ladder, templates, global vars
require_once("$modulePath/mod_main.php");

// xss fixes
// try to loop request
foreach ($_GET as $key=>$value) {
    ${$key} = xssClean($value);
    $_GET[$key] = xssClean($value);
}

foreach ($_POST as $key=>$value) {    
    if (!is_array($_POST[$key])) {
        ${$key} = xssClean($value);
        $_POST[$key] = xssClean($value);
    } else {
        foreach ($_POST[$key] as $postkey=>$postvalue) {
            ${$key}[$postkey] = xssClean($postvalue);
            $_POST[$key][$postkey] = xssClean($postvalue);
        }
    }
}

#  Page engine
if ($_COOKIE['premium_path'] != $ladder || !isset($_COOKIE['premium_path'])) {
    setcookie("premium_path", "$ladder", 0, "/", ".igl.net", 0);
}

if ($ladder) {
    $ladderPath = "$webPath/$ladder";

    # check to see if file exists if not do not require file and display error page
    # this only happens if the ladder was created but missing require file
    if (file_exists("$ladderPath/require.php")) {
        # add local requirements for this template
        require_once("$ladderPath/require.php");
    }
}

$templateDir = "$webPath/php/templates/$template/$language";

# display header
if ($no_header["$page"] != -1) {
    include_once("$templateDir/header.php");
}

# display number of users logged in
#include_once("$modulePath/mod_num_logins.php");

# display content
if (file_exists("$templateDir/$page.php")) {
    include_once("$templateDir/$page.php");
} else {
    header("HTTP/1.0 404 Not Found");
    include_once($_SERVER['WEB_PATH'] . '/404.html');
}

# display footer
if ($no_footer["$page"] != -1 && $page != 'fr_index') {
    include("$templateDir/footer.php");
}

?>
