<?php
session_start ();
$vremya=microtime();
if (file_exists("config/settings.php")) {
require('config/settings.php');
require('config/forum.php');
/////////////////////////////////////////  выбор game сервера
$i = 0;
$randomgame = '';
if ($handle = opendir('config/game')) 
{
    while (false !== ($file = readdir($handle))){
if ($file != "." && $server != ".." && $file != ".htaccess")
{	
        if ($file == "." || $file == "..") 
            continue;
        if (mt_rand(1, ++$i) == 1) 
        {
            $randomgame = $file;
        }
    }}
    closedir($handle);
}
include("config/game/$randomgame");
if (empty($_COOKIE['name']))
{
setcookie('name',$name_server);
header("Location: home.html");
}
$servid=$_COOKIE['name'];
//////////////////////////////////////  выбор login сервера
$i = 0;
$randomlogin = '';
if ($handle2 = opendir('config/login')) 
{
    while (false !== ($file2 = readdir($handle2))){
if ($file2 != "." && $login != ".." && $file2 != ".htaccess")
{	
        if ($file2 == "." || $file2 == "..") 
            continue;
        if (mt_rand(1, ++$i) == 1) 
        {
            $randomlogin = $file2;
        }
    }}
    closedir($handle2);
}
include("config/login/$randomlogin");
if (empty($_COOKIE['login']))
{
setcookie('login',$name_server_login);
header("Location: home.html");
}
$loginid=$_COOKIE['login'];
///////////////////////////////////////////   выбор языка
if (empty($_COOKIE['lang']))
{
setcookie('lang',$admin_langue);
header("Location: home.html");
}
$lang=@$_COOKIE['lang'];
include('engine/langue/'.$lang.'.php');
/////////////////////////////////////////////////////////////////
if (($sytestatus)==open) { 
include('config/game/'.$servid. '.php');
include('config/login/'.$loginid. '.php');
 
$cfile=$curr_tmpl;
$cfileurl='skins/'.$cfile.'/index.php';
if (!file_exists ("data/content/" . $index . ".php"))
die (".$lang_001.");
if (isset($_GET ['alias']))
{
	$alias = trim($_GET ['alias']);
///////////////////////////////////////////////////////////////////////////
if ( $alias == "feedback"){include("module/feedback.php");}
if ( $alias == "status"){include("module/status.php");}
if ( $alias == "pravila"){include("module/pravila.php");}
///////////////////////////////////////////////////////////////////////////
if ( $alias == "stat"){include("module/$type/stat.php");}
if ( $alias == "online"){include("module/$type/online.php");}
if ( $alias == "castle"){include("module/$type/castle.php");}
if ( $alias == "ss"){include("module/$type/ss.php");}
if ( $alias == "clan"){include("module/$type/clan.php");}
if ( $alias == "toppvp"){include("module/$type/toppvp.php");}
if ( $alias == "toppk"){include("module/$type/toppk.php");}
if ( $alias == "top50"){include("module/$type/top50.php");}
if ( $alias == "reyd"){include("module/$type/reyd.php");}
if ( $alias == "reg"){include("module/$typel/reg.php");}
if ( $alias == "reg2"){include("module/$typel/reg2.php");}
if ( $alias == "changepass"){include("module/$typel/changepass.php");}
if ( $alias == "changepass2"){include("module/$typel/changepass2.php");}
if ( $alias == "repass"){include("module/$typel/repass.php");}
if ( $alias == "repass2"){include("module/$typel/repass2.php");}
if ( $alias == "l2top"){include("module/l2top/index.php");}
if ( $alias == "add"){include("engine/votes/add.php");}
if ( $alias == "lk"){include("module/$typel/lk/index.php");} 
if ( $alias == "exit"){include("module/$typel/lk/exit.php");} 
if ( $alias == "teleport"){include("module/$typel/lk/teleport.php");}
if ( $alias == "2auth"){include("module/$typel/lk/2auth.php");}
	else
	{
		$file_menu = file("data/menu.csv");
		foreach( $file_menu as $line )
		{
			$elem = explode(";",$line);
			if ( trim($elem[1]) == trim($alias) ) 
			{
				if (file_exists ("data/content/" . $elem[0] . ".php"))
				{
					include ("data/content/" . $elem[0] . ".php");
				}
				else
				{
					include ('engine/404.html'); exit;
				}	
			}
		}	
	}
}
else
{
if (isset($_REQUEST['id']))  
{
$id =$_REQUEST['id'];
if (preg_match("/[^a-zA-Z0-9_]/", $id))  
{
Header("Location: index.php?id=start");
exit;
}
}
	else
	{
		$id = $index;
	}	
	
	if (file_exists ("data/content/" . $id . ".php")) {include ("data/content/" . $id . ".php");}
	else
	{
		include ('engine/404.html'); exit;
	}	
	}
	if (file_exists ("data/reklama.php")) {include ("data/reklama.php");}
	if (file_exists ("galereya/gal.php")) {include ("galereya/gal.php");}
	if (file_exists ("engine/votes/form_votes.php")) {include ("engine/votes/form_votes.php");}
	if (file_exists ("engine/kalendar.php")) {include ("engine/kalendar.php");}
	if (file_exists ("engine/time.php")) {include ("engine/time.php");}
   	if (file_exists ("module/lang_form.php")){include ("module/lang_form.php");}
   	if (file_exists ("module/status.php")) {include ("module/status.php");}
	if (file_exists ("module/EMU/lk/auth.php"))	{include ("module/EMU/lk/auth.php");}
	if (file_exists ("module/forum/index.php"))	{include ("module/forum/index.php");}
	else
	{
		include ('engine/error.html'); exit;
	}

if (file_exists ("skins/" . $curr_tmpl . "/index.php"))
{
	$template_page = file_get_contents("skins/" . $curr_tmpl . "/index.php");
}
else
{
	include ("engine/error.html");
	die ("");
}
$vremya2=microtime();
$generation1 = $vremya2 - $vremya;
$generation = round($generation1,5);
$timegen ="$lang_002 $generation сек.";
include ("menu.php");
$overall_output = str_replace ("{TITLE}", $page_title, $template_page);
$overall_output = str_replace ("{LK}", $page_lk, $overall_output);
$overall_output = str_replace ("{FORUM}", $page_forum, $overall_output);
$overall_output = str_replace ("{H1}", $page_h1, $overall_output);
$overall_output = str_replace ("{DESC}", $page_descr, $overall_output);
$overall_output = str_replace ("{KEYWORDS}", $page_keyws, $overall_output);
$overall_output = str_replace ("{TEMPLATE}", $curr_tmpl, $overall_output);
$overall_output = str_replace ("{MENU}", $menu_output, $overall_output);
$overall_output = str_replace ("{STATUS}", $status, $overall_output);
$overall_output = str_replace ("{KALENDAR}", $kalendar, $overall_output);
$overall_output = str_replace ("{TIME}", $time, $overall_output);
$overall_output = str_replace ("{PATH}", $path, $overall_output);
$overall_output = str_replace ("{REKLAMA}", $reklama, $overall_output);
$overall_output = str_replace ("{GAL}", $gal, $overall_output);
$overall_output = str_replace ("{VOTES}", $form_votes, $overall_output);
$overall_output = str_replace ("{LANGUE}", $lang_form, $overall_output);
$overall_output = str_replace ("{CONTENT}", $content, $overall_output);
$overall_output = str_replace ("{COPY}", $copy, $overall_output);
$overall_output = str_replace ("{TIMEGEN}", $timegen, $overall_output);
echo $overall_output;
} else {echo $msgsyte;}
} else
{
echo "Сайт не установлен, воспользуйтесь <a href=\"install/install.php\"><b>Инсталятором</b></a>.</div></body>";
}
?>