<?
header ("Content-Type: text/html;charset=utf-8"); 
@setlocale(LC_ALL, 'ru_RU.utf8', 'rus_RUS.utf8', 'Russian_Russia.utf8');
@setlocale (LC_NUMERIC, "en_US");

ini_set ("magic_quotes_gpc", "Off");
ini_set ("register_globals", "Off");

session_start();

if( file_exists("install.php") ){
	header("location: install.php");
	die();
}

include("init.php");

Serval::call('tpl')->path        = $config['root'].'/templates/';
Serval::call('tpl')->plugins     = $config['root'].'/lib/tpl/plugins/';
Serval::call('tpl')->all_header  = "header";
Serval::call('tpl')->all_footer  = "footer";
Serval::call('tpl')->header  = "main/header";
Serval::call('tpl')->footer  = "main/footer";
Serval::call('tpl')->config	 = $config;

  
$uri = explode("?",$_SERVER['REQUEST_URI']);
$uri = str_replace($config['http_dir'],"/",$uri);

$path = explode("/",$uri[0]);
if( Serval::call('Auth')->check() ){
  if(Serval::call('Auth')->ID>0){
		switch($path[1]){
			case '':
				include("module/mod_index.php");
			break;
			case 'ajax':
				include("module/mod_ajax.php");
			break;
			case 'exit':
				Serval::call('Auth')->Logout();
				header("location: ".(isset($config['http_dir']) ? $config['http_dir'] : '/'));
				die();
			break;
			default:
				if(file_exists("module/mod_{$path[1]}.php")){
					include("module/mod_{$path[1]}.php");
				}else{
					Serval::call('tpl')->error404();
				}
		}
	}else{
		include("module/mod_auth.php");
	}
}else{
	include("module/mod_auth.php");
}

?>