<?php
// Define a smaller Directory seperater and ROOT path
define('DS', DIRECTORY_SEPARATOR); // "/"
define('ROOT', dirname(__FILE__)); // Directory ROOT
define('CONFIG_PATH', ROOT . DS . 'config' . DS); // Directory config
define('INCLUDE_PATH', ROOT . DS . 'include' . DS); // Directory include
define('LANGUAGE_PATH', ROOT . DS . 'language' . DS); // Directory language
define('MODULE_PATH', ROOT . DS . 'module' . DS); // Directory module (Addons)
define('TEMPLATE_PATH', ROOT . DS . 'template' . DS); // Directory template
define('CACHE_PATH', ROOT . DS . 'cache' . DS); // Directory cache
// Include our config file
include( CONFIG_PATH . 'config.inc.php'); // Config
// Addons
include( MODULE_PATH . 'debug.php'); // PHP Debug
// Languages
include( LANGUAGE_PATH . 'common.php'); // New version
//include( LANGUAGE_PATH . 'commonold.php'); // Old version
/* CONNECTION MANAGEMENT SOON SOMEWHERE ELSE! */
$link = mysql_connect($DBIP, $DBLOGIN, $DBPASSWORD)
   or die('Could not connect: ' . mysql_error());
#echo 'Connected successfully';
mysql_select_db($DBNAME) or die('Could not select database');
/* CONNECTION MANAGEMENT SOON SOMEWHERE ELSE! */
// check if compatibility is required (php < 5)
if (substr(phpversion(),0,1)!=5)
	include( INCLUDE_PATH . 'compatibility.inc.php');
// process page start:
$time_start = microtime(true);
// IFF PID -> go show stats!
//$id = $_REQUEST["id"];
$PID = isset($_GET["pid"]) ? $_GET["pid"] : "0";
$PID = preg_replace("/[^0-9]/", '', $PID);
$RID = isset($_GET["rid"]) ? $_GET["rid"] : "0";
$RID = preg_replace("/[^0-9]/", '', $RID);
$RCUR = isset($_GET["rc"]) ? $_GET["rc"] : "0";
$RNEXT = isset($_GET["rn"]) ? $_GET["rn"] : "0";
$GO = isset($_GET["go"]) ? $_GET["go"] : "0";
$LEADERBOARD = isset($_POST["leaderboard"]) ? $_POST["leaderboard"] : "0";
$GET = isset($_POST["get"]) ? $_POST["get"] : 0;
$SET = isset($_POST["set"]) ? $_POST["set"] : 0;
$ADD = isset($_GET["add"]) ? $_GET["add"] : 0;
$REMOVE = isset($_GET["remove"]) ? $_GET["remove"] : 0;
if ($SET)
{
	setcookie("leaderboard", $LEADERBOARD, time()+315360000, '/', $DOMAIN); // delete after 10 years ;)
	#NOTE: after setting a cookie, you must redirect!
	header("Location: ".$ROOT."?go=my-leaderboard"); // refresh for cookie
	exit();
}
if ($GET)
{
	// output the nice save-url
	header("Location: ".$ROOT.'?go=my-leaderboard&pid='.urlencode($LEADERBOARD));
	exit();
}
include( INCLUDE_PATH . 'datamanagement.inc.php');
/***************************************************************
 * PLAYERSTATS
 ***************************************************************/
if ($GO=="0" && $PID)
{
	$player = getPlayerDataFromPID($PID); // receive player data
	$victims = getFavouriteVictims($PID); // receive victim data
	$enemies = getFavouriteEnemies($PID); // receive enemie data
	$armies = getArmyData($PID); // receive army data
	$armySummary = getArmySummaries($armies); // retrieve Army summary
	$unlocks = getUnlocksByPID($PID); // retrieve unlock data
	$vehicles = getVehicleData($PID); // retrieve vehivle data
	$vehicleSummary = getVehicleSummaries($vehicles); // retrieve Vehicle summary
	$weapons = getWeaponData($PID, $player); // retrieve Weapon data
	$weaponSummary = getWeaponSummary($weapons, $player); // retrieve weapon summary
	$equipmentSummary = getEquipmentSummary($weapons, $player); // retrieve equipment summary
	$kits = getKitData($PID); // retrieve kit data
	$kitSummary = getKitSummary($kits, $player); // retrieve kits summary
	$maps = getMapData($PID);
	$mapSummary = getMapSummary($maps);
	$playerSummary = getPlayerSummary($player, $weapons, $vehicles, $kits, $armies, $maps); // get player summary
	$PlayerAwards  = getAwardsByPID($PID);
	$TheaterData = getTheaterData($PID); // retrueve Theater Data
    $player['name'] = preg_replace("/>/","&gt;",$player['name']);
    $player['name'] = preg_replace("/</","&lt;",$player['name']);
    $rankkeys = array(
 	 "0" => array("rank" => "Private",						"req" => 0),
	 "1" => array("rank" => "Private First Class",			"req" => 150),
	 "2" => array("rank" => "Lance Corporal",				"req" => 500),
	 "3" => array("rank" => "Corporal",						"req" => 800),
	 "4" => array("rank" => "Sergeant",						"req" => 2500),
	 "5" => array("rank" => "Staff Sergeant",				"req" => 5000),
	 "6" => array("rank" => "Gunnery Sergeant",				"req" => 8000),
	 "7" => array("rank" => "Master Sergeant",				"req" => 20000),
	 "8" => array("rank" => "First Sergeant",				"req" => 20000),
	 "9" => array("rank" => "Master Gunnery Sergeant",		"req" => 50000),
	"10" => array("rank" => "Sergeant Major",				"req" => 50000),
	"11" => array("rank" => "Sergeant Major of the Corps",	"req" => 50000),
	"12" => array("rank" => "2nd Lieutenant",				"req" => 60000),
	"13" => array("rank" => "1st Lieutenant",				"req" => 75000),
	"14" => array("rank" => "Captain",						"req" => 90000),
	"15" => array("rank" => "Major",						"req" => 115000),
	"16" => array("rank" => "Lieutenant Colonel",			"req" => 125000),
	"17" => array("rank" => "Colonel",						"req" => 150000),
	"18" => array("rank" => "Brigadier General",			"req" => 180000),
	"19" => array("rank" => "Major General",				"req" => 180000),
	"20" => array("rank" => "Lieutenant General",			"req" => 200000),
	"21" => array("rank" => "General",						"req" => 200000)
    );
//pass value you wish to delete and the array to delete from
function array_delete( $value, $array)
{
    $array = array_diff( $array, array($value) );
    return $array;
}
	$kitbadges = array(
		"1031406",		// Knife Badge *1-FS *2-MG
   		"1031619",		// Pistols Badge *1-FS *2-MG
		"1032415",		// Explosives Badge
   		"1190304",		// Command Badge
		"1190507",		// Engineer Badge
   		"1190601",		// First Aid Badge
		"1191819",		// Resupply Badge
   		"1031923",		// Ground Defense *1-SM *2-BG
		"1220104",		// Air Defense *1-SM *2-BG
   		"1220118",		// Armor Badge *1-SM *2-BG
		"1220122",		// Aviator Badge *1-SM *2-BG
   		"1220803",		// Helicopter Badge *1-SM *2-BG
   		"1222016",		// Transport Badge *1-SM *2-BG
		"1031119",		// Assult *1-FS *2-MG
		"1031120",		// Anti-tank *1-FS *2-MG
		"1031109",		// Sniper *1-FS *2-MG
		"1031115",		// Spec-Ops *1-FS *2-MG
		"1031121",		// Support *1-FS *2-MG
		"1031105",		// Engineer *1-FS *2-MG
		"1031113"		// Medic *1-FS *2-MG
		);
        $levelreq = 0; $allok = 0; $bagesneed = '';
if ($player['rank'] == 6) {$levelreq = 1; $ltext = "Basic ";
$kitbadgesreq = array("1031406", "1031619", "1031119", "1031120", "1031109", "1031115", "1031121", "1031105", "1031113");}
if ($player['rank'] == 7 || $player['rank'] == 8) {$levelreq = 1; $ltext = "Basic ";
$kitbadgesreq = array("1031923", "1220104", "1220118", "1220122", "1220803", "1222016", "1031406", "1031619", "1031119",
"1031120", "1031109", "1031115", "1031121", "1031105", "1031113");}
if ($player['rank'] == 17) {$levelreq = 2; $ltext = "Veteran ";
$kitbadgesreq = array("1031923", "1220104", "1220118", "1220122", "1220803", "1222016", "1031406", "1031619", "1031119",
"1031120", "1031109", "1031115", "1031121", "1031105", "1031113");}
if(($player['rank'] == 6) || ($player['rank'] == 7) || ($player['rank'] == 8) || ($player['rank'] == 17)) {
	$checkawds = "'" . implode("','", $kitbadgesreq) . "'";
	$query = "SELECT awd FROM awards WHERE id = {$PID} AND (awd IN ({$checkawds}) AND level = '".$levelreq."')";
	$result = mysql_query($query) or die(mysql_error());
if (mysql_num_rows($result))
{
    while ($row = mysql_fetch_assoc($result)) {
            $kitbadgesavail[] = $row['awd'];
            $kitbadgesreq = array_delete ($row['awd'],$kitbadgesreq);
	}
    if (count($kitbadgesreq) == 0) {$allok = 1;}
    else {
    foreach ($kitbadgesreq as $value) {
        $bagesneed .= $ltext.getBadgeNameByID($value).", ";
    }
    $bagesneed = ereg_replace("\r\n", "", $bagesneed);
    $bagesneed = ereg_replace(", $", "", $bagesneed);
    }
}
}
                    if ( ($player['rank'] >= 21) ) {
                            $pcntDiff = number_format( 100, 2);
                            $newrank = "Выше вас по званию только Бог... :)";
                            $noranks = 1;
                    } else {
                        $nextrank = $player['rank'] + 1;
                        if($player['rank'] == 7  AND $allok){$nextrank = $player['rank'] + 3;}
                        if($player['rank'] == 7  AND !$allok){
                            $nextrank = $player['rank'] + 2;
                            $noteligible = 1;
                            $gipotrank = $player['rank'] + 3;
                            $gipotrankname = $rankkeys[$gipotrank]['rank'];}
                        if(($player['rank'] == 9)){$nextrank = $player['rank'] + 3;}
                        if(($player['rank'] == 10)){$nextrank = $player['rank'] + 2;}
                        if((($player['rank'] == 6) || ($player['rank'] == 8)) AND $allok){
                            $nextrank = $player['rank'] + 2;}
                        if((($player['rank'] == 6) || ($player['rank'] == 8)) AND !$allok){
                            $nextrank = $player['rank'] + 1;
                            $noteligible = 1;
                            $gipotrank = $player['rank'] + 2;
                            $gipotrankname = $rankkeys[$gipotrank]['rank'];}
                        if($player['rank'] == 17  AND $allok){$nextrank = $player['rank'] + 2;}
                        if($player['rank'] == 17 AND !$allok){
                            $nextrank = $player['rank'] + 1;
                            $noteligible = 1;
                            $gipotrank = $player['rank'] + 2;
                            $gipotrankname = $rankkeys[$gipotrank]['rank'];}
                        $newrank = $rankkeys[$nextrank]['rank'];
                        $requiredPoints = $rankkeys[$nextrank]['req'];	//Required Points for next rank
                        $pointDiff = ($requiredPoints - $player['score']);	//Point differential for next rank
                        $rtime = $player['lastonline'] - $player['joined'];
                        $realtime = round($pointDiff * $rtime / $player['score']/86400);
                        if($pointDiff <= 0) {	//past the required points
                            if($nextrank > 17) {
                                //Beyond Colonel, there's a lot of Expert badges required
                                //we have no way to determine what those badges are..
                                //so list the next rank by score only
                                $pcntDiff = number_format( 100, 2);
                                $newrank = $rankkeys[$nextrank]['rank'];
                            } else {
                                $pcntDiff = number_format( 100, 2);
                                //gotta find their proper/next rank..
/*                                foreach( $rankkeys as $k => $v ) {
                                    if($rankkeys[$k]['req'] >= $player['score']) {
                                        $newrank = $rankkeys[($k - 1)]['rank']; //This is where they're supposed to be
                                        break;
                                    }
                                }*/
                            }
                        } else {
                            $pcntDiff = number_format( (($player['score'] / $requiredPoints) * 100), 2);
                            $newrank = $rankkeys[$nextrank]['rank'];
                            $approx = sec2log( floor(($player['time'] / $player['score']) * $pointDiff) );
                            //$newrank .= "<br />Приблизительное время присвоения: " . $approx;
                        }
                    }
	#$awards = getAwardsByPID($PID); // get earned awards
	if (isCached($PID))// already cached!
	{
		$template = getCache($PID);
		$LASTUPDATE = intToTime(getLastUpdate(getcwd().''.CACHE_PATH.''.$L10N.'-'.$PID.'.cache'));
		$NEXTUPDATE = intToTime(getNextUpdate(getcwd().''.CACHE_PATH.''.$L10N.'-'.$PID.'.cache'));
		$template = str_replace('{:LASTUPDATE:}', $LASTUPDATE, $template);
		$template = str_replace('{:NEXTUPDATE:}', $NEXTUPDATE, $template);
		#echo $template;
	}
	else //if
	{
		include( TEMPLATE_PATH . 'playerstats.php');
		// write cache file
		writeCache($L10N.'-'.$PID, $template);
		$LASTUPDATE = intToTime(0);
		$NEXTUPDATE = intToTime(3600);
		$template = str_replace('{:LASTUPDATE:}', $LASTUPDATE, $template);
		$template = str_replace('{:NEXTUPDATE:}', $NEXTUPDATE, $template);
		#echo $template;
	}
}
/***************************************************************
 * ROUND STATS
 ***************************************************************/
else if ($GO=="0" && $RID)
{
	//$round = getPlayerDataFromPID($PID); // receive player data
    $roundinfo = getRoundInfo($RID);
    $RCUR = $roundinfo[0]['timestamp'] + 120;
    $RNEXT = $roundinfo[0]['timestamp'] + $roundinfo[0]['time'] + 120;
    $RPORT =  $roundinfo[0]['gameport'];
    if ($RPORT == '16567')
    {
        $sservername = "<font color=#83FF61>Ranked Public #1</font>";
    }
    else if ($RPORT == '16568')
    {
        $sservername = "<font color=#FF5757>Special Forces #2</font>";
    }
    else if ($RPORT == '16569')
    {
        $sservername = "<font color=#FF5757>IDF #3</font>";
    }
    else if ($RPORT == '17567')
    {
        $sservername = "<font color=#FF5757>COOP #4</font>";
    }
    else if ($RPORT == '17568')
    {
        $sservername = "<font color=#FF5757>REAL WAR #5</font>";
    }
    else if ($RPORT == '20569')
    {
        $sservername = "<font color=#FF5757>BattleChallenge!</font>";
    }
    else
    {
        $sservername = "<font color=#FF5757>Custom</font>";
    }
	$proundinfo = getPRoundInfo($RID,$RCUR,$RNEXT,$RPORT);
	$LASTUPDATE = 0;
	$NEXTUPDATE = 0;
	if (isCached('round-'.$RID))// already cached!
	{
		$template = getCache('round-'.$RID);
		$LASTUPDATE = intToTime(getLastUpdate(getcwd().''.CACHE_PATH.''.$L10N.'-round-'.$RID.'.cache'));
		$NEXTUPDATE = intToTime(getNextUpdate(getcwd().''.CACHE_PATH.''.$L10N.'-round-'.$RID.'.cache', RANKING_REFRESH_TIME));
	}
	else
	{
		include( TEMPLATE_PATH . 'roundinfo.php');
		// write cache file
		writeCache($L10N.'-round-'.$RID, $template);
		$LASTUPDATE = intToTime(0);
		$NEXTUPDATE = intToTime(60000);
	}
	$template = str_replace('{:LASTUPDATE:}', $LASTUPDATE, $template);
	$template = str_replace('{:NEXTUPDATE:}', $NEXTUPDATE, $template);
	#echo $template;
}
/***************************************************************
 * CURRENT RANKINGS
 ***************************************************************/
else if (strcasecmp($GO, 'currentranking')==0)
{
    $SEARCHVALUE = isset($_POST["searchvalue"]) ? $_POST["searchvalue"] : "0";
    if ($id != '') {$crid = $id; $compare = 1; $SEARCHVALUE = $id;}
	$rankings = getRankingCollection();
	$LASTUPDATE = 0;
	$NEXTUPDATE = 0;
	if (isCached('current-ranking') and !$compare)// already cached!
	{
		$template = getCache('current-ranking');
		$LASTUPDATE = intToTime(getLastUpdate(getcwd().''.CACHE_PATH.''.$L10N.'-current-ranking.cache'));
		$NEXTUPDATE = intToTime(getNextUpdate(getcwd().''.CACHE_PATH.''.$L10N.'-current-ranking.cache', RANKING_REFRESH_TIME));
	}
	else
	{
		include( TEMPLATE_PATH . 'current-ranking.php');
		//write cache file
		if (!$compare) {writeCache($L10N.'-current-ranking', $template);}
		$LASTUPDATE = intToTime(0);
		$NEXTUPDATE = intToTime(3600);
	}
	$template = str_replace('{:LASTUPDATE:}', $LASTUPDATE, $template);
	$template = str_replace('{:NEXTUPDATE:}', $NEXTUPDATE, $template);
	#echo $template;
}
/***************************************************************
 * LAST ROUNDS
 ***************************************************************/
else if (strcasecmp($GO, 'lastrounds')==0)
{
	$lastrounds = getLastRounds();
	$LASTUPDATE = 0;
	$NEXTUPDATE = 0;
	if (isCached('last-rounds'))// already cached!
	{
		$template = getCache('last-rounds');
		$LASTUPDATE = intToTime(getLastUpdate(getcwd().''.CACHE_PATH.''.$L10N.'-last-rounds.cache'));
		$NEXTUPDATE = intToTime(getNextUpdate(getcwd().''.CACHE_PATH.''.$L10N.'-last-rounds.cache', 300));
	}
	else
	{
		include( TEMPLATE_PATH . 'last-rounds.php');
		// write cache file
		writeCache($L10N.'-last-rounds', $template);
		$LASTUPDATE = intToTime(0);
		$NEXTUPDATE = intToTime(300);
	}
	$template = str_replace('{:LASTUPDATE:}', $LASTUPDATE, $template);
	$template = str_replace('{:NEXTUPDATE:}', $NEXTUPDATE, $template);
	#echo $template;
}
/***************************************************************
 * LAST PLAYER ROUNDS
 ***************************************************************/
else if (strcasecmp($GO, 'playerhistory')==0 && $PID)
{
	$ph = getPlayerHistory($PID);
    $ph['pname'] = preg_replace("/>/","&gt;",$ph['pname']);
    $ph['pname'] = preg_replace("/</","&lt;",$ph['pname']);
	$LASTUPDATE = 0;
	$NEXTUPDATE = 0;
	if (isCached('ph-'.$PID))// already cached!
	{
		$template = getCache('ph-'.$PID);
		$LASTUPDATE = intToTime(getLastUpdate(getcwd().''.CACHE_PATH.''.$L10N.'-ph-'.$PID.'.cache'));
		$NEXTUPDATE = intToTime(getNextUpdate(getcwd().''.CACHE_PATH.''.$L10N.'-ph-'.$PID.'.cache', 300));
	}
	else
	{
		include( TEMPLATE_PATH . 'playerhistory.php');
		// write cache file
		writeCache($L10N.'-ph-'.$PID, $template);
		$LASTUPDATE = intToTime(0);
		$NEXTUPDATE = intToTime(300);
	}
	$template = str_replace('{:LASTUPDATE:}', $LASTUPDATE, $template);
	$template = str_replace('{:NEXTUPDATE:}', $NEXTUPDATE, $template);
	#echo $template;
}
/***************************************************************
 * MY LEADER BOARD
 ***************************************************************/
else if  ((strcasecmp($GO, 'my-leaderboard')==0))
{
	#print_r($_COOKIE);
	#echo $_COOKIE["leaderboard"];
	if ($ADD>0)
	{
		if ($_COOKIE['leaderboard']!='')
			$LEADERBOARD = $_COOKIE['leaderboard'].','.$ADD;
		else
			$LEADERBOARD = $ADD;
		setcookie("leaderboard", $LEADERBOARD, time()+315360000, '/', $DOMAIN); // delete after 10 years ;)
		#NOTE: after setting a cookie, you must redirect!
		header("Location: ".$ROOT."?go=my-leaderboard"); // refresh for cookie
		exit();
	}
	else if ($REMOVE>0)
	{
		$LEADERBOARD = explode(',', $_COOKIE['leaderboard']); // get array
		foreach ($LEADERBOARD as $i => $value) { // delete "remove"
   		if ($value==$REMOVE)
   			unset($LEADERBOARD[$i]);
		}
		$LEADERBOARD = implode(',', $LEADERBOARD); // back to string ;)
		setcookie("leaderboard", $LEADERBOARD, time()+315360000, '/', $DOMAIN); // delete after 10 years ;)
		#NOTE: after setting a cookie, you must redirect!
		header("Location: ".$ROOT."?go=my-leaderboard"); // refresh for cookie
		exit();
	}
	# nothing todo -> load from cookie
	$LEADERBOARD = isset($_COOKIE['leaderboard']) ? $_COOKIE['leaderboard'] : '';
	if ($PID!=0) // a saved leaderboard
	{
		$LEADER = getLeaderBoardEntries(urldecode($PID)); # query from database
	}
	else
		$LEADER = getLeaderBoardEntries($LEADERBOARD); # query from database
	#if ($LEADERBOARD==0) $LEADERBOARD = '';
	include( TEMPLATE_PATH . 'my-leaderboard.php');
	#echo $template;
}
/***************************************************************
 * SEARCH FOR PLAYERS
 ***************************************************************/
else if (strcasecmp($GO, 'search')==0)
{
	$LASTUPDATE = 0;
	$NEXTUPDATE = 0;
	if (isCached('search'))// already cached!
	{
		$template = getCache('search');
		$LASTUPDATE = intToTime(getLastUpdate(getcwd().''.CACHE_PATH.''.$L10N.'-search.cache'));
		$NEXTUPDATE = intToTime(getNextUpdate(getcwd().''.CACHE_PATH.''.$L10N.'-search.cache', RANKING_REFRESH_TIME));
	}
	else
	/* fix by Dickie Gales */
	{
		$SEARCHVALUE = isset($_POST["searchvalue"]) ? $_POST["searchvalue"] : "0";
		$SEARCHVALUE = preg_replace("/[^A-Za-z0-9 %_-]/", '', $SEARCHVALUE);
		$SEARCHVALUE = "%" . $SEARCHVALUE . "%";
		if($SEARCHVALUE) $searchresults = getSearchResults($SEARCHVALUE);
		include( TEMPLATE_PATH .'search.php');
	/* Old
	{
		$SEARCHVALUE = isset($_POST["searchvalue"]) ? $_POST["searchvalue"] : "0";
		if ($SEARCHVALUE) $searchresults = getSearchResults($SEARCHVALUE);
		include( TEMPLATE_PATH . 'search.php');
	*/
	#echo $template;
	    writeCache($L10N.'-search', $template);
		$LASTUPDATE = intToTime(0);
		$NEXTUPDATE = intToTime(RANKING_REFRESH_TIME);
	}
	$template = str_replace('{:LASTUPDATE:}', $LASTUPDATE, $template);
	$template = str_replace('{:NEXTUPDATE:}', $NEXTUPDATE, $template);
}
/***************************************************************
 * UBAR PAGES
 ***************************************************************/
elseif(strcasecmp($GO, 'ubar') == 0)
{
	$LASTUPDATE = 0;
	$NEXTUPDATE = 0;
	if (isCached('ubar-'.$page))// already cached!
	{
		$template = getCache('ubar-'.$page);
		$LASTUPDATE = intToTime(getLastUpdate(getcwd().''.CACHE_PATH.''.$L10N.'-'.$page.'.cache'));
		$NEXTUPDATE = intToTime(getNextUpdate(getcwd().''.CACHE_PATH.''.$L10N.'-'.$page.'.cache', RANKING_REFRESH_TIME));
	}
	else
    {
    // Make sure we have a sub page
	$page = (isset($_GET['p'])) ? $_GET['p'] : 'index';
	switch($page)
	{
		default:
		case "index":
			$page = 'ubar-index';
			break;
		case "ribbons":
		case "ribbons-sf":
		case "medals":
		case "medals-sf":
		case "badges":
		case "badges-sf":
		case "ranks":
        case "unlocks":
        case "kits":
			$page = 'ubar-'. $page;
			break;
	}
	// Include our template file
	include( TEMPLATE_PATH . 'ubar/'. $page .'.php');
	#echo $template;
	    writeCache($L10N.'-'.$page, $template);
		$LASTUPDATE = intToTime(0);
		$NEXTUPDATE = intToTime(RANKING_REFRESH_TIME);
	}
	$template = str_replace('{:LASTUPDATE:}', $LASTUPDATE, $template);
	$template = str_replace('{:NEXTUPDATE:}', $NEXTUPDATE, $template);
}
/***************************************************************
 * Monitoring
 ***************************************************************/
else if(strcasecmp($GO, 'monitor') == 0)
{
    include( TEMPLATE_PATH .'monitor.php');
}
/*
elseif(strcasecmp($GO, 'monitor') == 0)
{
    header('Location: monitor.php', true, 302);
}
*/
/***************************************************************
 * FORUM
 ***************************************************************/
#if(strcasecmp($GO, 'forum') == 0)
#else{include("forum.php");}
elseif(strcasecmp($GO, 'forum') == 0)
{
    header('Location: forum.php', true, 302);
}
/***************************************************************
 * FAQ
 ***************************************************************/
elseif(strcasecmp($GO, 'faq') == 0)
{
	$LASTUPDATE = 0;
	$NEXTUPDATE = 0;
	if (isCached('faq-'.$page))// already cached!
	{
		$template = getCache('faq-'.$page);
		$LASTUPDATE = intToTime(getLastUpdate(getcwd().''.CACHE_PATH.''.$L10N.'-'.$page.'.cache'));
		$NEXTUPDATE = intToTime(getNextUpdate(getcwd().''.CACHE_PATH.''.$L10N.'-'.$page.'.cache', RANKING_REFRESH_TIME));
	}
	else
    {
	// Make sure we have a sub page
	$page = (isset($_GET['p'])) ? $_GET['p'] : 'index';
	switch($page)
	{
		default:
		case "index":
			$page = 'faq-index';
			break;
		case "bf":
		case "pb":
			$page = 'faq-'. $page;
			break;
	}
	// Include our template file
	include( TEMPLATE_PATH .'faq/'. $page .'.php');
	#echo $template;
	    writeCache($L10N.'-'.$page, $template);
		$LASTUPDATE = intToTime(0);
		$NEXTUPDATE = intToTime(RANKING_REFRESH_TIME);
	}
	$template = str_replace('{:LASTUPDATE:}', $LASTUPDATE, $template);
	$template = str_replace('{:NEXTUPDATE:}', $NEXTUPDATE, $template);
}
/***************************************************************
 * Banlist
 ***************************************************************/
elseif(strcasecmp($GO, 'banlist') == 0)
{
	$LASTUPDATE = 0;
	$NEXTUPDATE = 0;
	if (isCached('banlist'))// already cached!
	{
		$template = getCache('banlist');
		$LASTUPDATE = intToTime(getLastUpdate(getcwd().''.CACHE_PATH.''.$L10N.'-'.$page.'.cache'));
		$NEXTUPDATE = intToTime(getNextUpdate(getcwd().''.CACHE_PATH.''.$L10N.'-'.$page.'.cache', RANKING_REFRESH_TIME));
	}
	else
    {
	// Make sure we have a sub page
	$page = (isset($_GET['p'])) ? $_GET['p'] : 'index';
	switch($page)
	{
		default:
		case "index":
			$page = 'banlist-index';
			break;
		case "srv1":
		case "srv2":
		case "srv3":
		case "srv4":
		case "srv5":
		case "srv6":
		case "srv7":
		case "srv8":
		case "srv9":
			$page = 'banlist-'. $page;
			break;
	}
	// Include our template file
	include( TEMPLATE_PATH .'ban/'. $page .'.php');
	#echo $template;
	    writeCache($L10N.'-'.$page, $template);
		$LASTUPDATE = intToTime(0);
		$NEXTUPDATE = intToTime(RANKING_REFRESH_TIME);
	}
	$template = str_replace('{:LASTUPDATE:}', $LASTUPDATE, $template);
	$template = str_replace('{:NEXTUPDATE:}', $NEXTUPDATE, $template);
}
/***************************************************************
 * Statistics - modifecation
 ***************************************************************/
else if (strcasecmp($GO, 'stats')==0)
{  // show the top ten
	$LASTUPDATE = 0;
	$NEXTUPDATE = 0;
	if (isCached('home'))// already cached!
	{
		$template = getCache('home');
		$LASTUPDATE = intToTime(getLastUpdate(getcwd().''.CACHE_PATH.''.$L10N.'-home.cache'));
		$NEXTUPDATE = intToTime(getNextUpdate(getcwd().''.CACHE_PATH.''.$L10N.'-home.cache', RANKING_REFRESH_TIME));
	}
	else
	{
		$topten = getTopNP();
		include( TEMPLATE_PATH . 'home.php');
		// write cache file
		//writeCache($L10N.'-home', $template);
		$LASTUPDATE = intToTime(0);
		$NEXTUPDATE = intToTime(RANKING_REFRESH_TIME);
	}
	$template = str_replace('{:LASTUPDATE:}', $LASTUPDATE, $template);
	$template = str_replace('{:NEXTUPDATE:}', $NEXTUPDATE, $template);
}
/***************************************************************
 * SHOW TOP TEN - default
 ***************************************************************/
else
{  // show the top ten
	$LASTUPDATE = 0;
	$NEXTUPDATE = 0;
	if (isCached('main'))// already cached!
	{
		$template = getCache('main');
		$LASTUPDATE = intToTime(getLastUpdate(getcwd().''.CACHE_PATH.''.$L10N.'-main.cache'));
		$NEXTUPDATE = intToTime(getNextUpdate(getcwd().''.CACHE_PATH.''.$L10N.'-main.cache', RANKING_REFRESH_TIME));
	}
	else
	{
		$top = getTop();
		include( TEMPLATE_PATH . 'main.php');
		// write cache file
		//writeCache($L10N.'-main', $template);
		$LASTUPDATE = intToTime(0);
		$NEXTUPDATE = intToTime(RANKING_REFRESH_TIME);
	}
	$template = str_replace('{:LASTUPDATE:}', $LASTUPDATE, $template);
	$template = str_replace('{:NEXTUPDATE:}', $NEXTUPDATE, $template);
}
/* CONNECTION MANAGEMENT SOON SOMEWHERE ELSE! */
// Closing connection
mysql_close($link);
/* CONNECTION MANAGEMENT SOON SOMEWHERE ELSE! */

//processing page END
$time_end = microtime(true);
$time = round($time_end - $time_start,4);

$template = str_replace('{:PROCESSED:}', $time, $template);
#deleteCache(69595617);
echo $template;
?>