<?php
// 检查系统是否安装
if (!file_exists("./data/config.php")) {
	header('Location:install/install.php');
	exit();
}
require('inc.php');

// 检查网站是否关闭
if ($web_config['web_close']=='1') exit($web_config['web_close_description']);

base::router(); // 路由设置

$a = base::g('a'); // action
$app_file = 'home'; // 项目名称，根目录下必须有此目录

$view = base::g('mod','index');

if ($a == 'action') {
	if (!file_exists(__ROOT__.'/action.php')) exit('action include no exists!');
	require(__ROOT__.'/action.php');
	$db->close(); // 关闭数据库
	exit();
}

if ($a=='ajax') { // 调用Ajax
	if (!file_exists(__ROOT__.'/ajax/'.$app_file.'/'.$view.'.php')) exit('ajax include no exists!');
	require(__ROOT__.'/ajax/'.$app_file.'/'.$view.'.php');
	$db->close(); // 关闭数据库
	exit();
}


/* 载入语言文件 */

// 模板目录
$template_dir = $web_config["web_template_url"]!=""?$web_config["web_template_url"]:"default";
$tpl_ext = '.html'; // 模板文件的扩展名
$ismobile=base::isMobile();

if($ismobile){
	$template_dir = "mobile";
}
// 实例化模板类
$tpl = new template();
$tpl->direct_output=true;
$tpl->template_dir = "templates/".$template_dir;
// 缓存设置
$expire_time = (int)$web_config['web_cache_time'];
$tpl->cache_lifetime = $expire_time;
$tpl->compile_dir  = "data/compiled";
$tpl->cache_dir = 'data/caches';
if (($web_config['web_debug'] & 1) != 1 && $expire_time > 0) {$tpl->caching = true;} else {$tpl->caching = false;}
// 获取跳转地址
if (trim(base::g("return_url") != '')) {$return_url = base::code(trim(base::g("return_url")),"DE");} else {$return_url = '';}
// 返回地址，经过加密后解密的
$tpl->assign('return_url',$return_url);

//加载语言
$acn=$_GET['en'];
$array=array('ZH','EN');
if(!empty($acn) && in_array($acn,$array)){
	$cfg_lang=$_SESSION['cn']=$acn;
}

$cfg_lang=base::s('cn');
if(empty($cfg_lang)){
	$_SESSION['cn']=$cfg_lang='ZH';
}
require(__ROOT__ . '/languages/' . $cfg_lang . '/common.php');


// 标签调用
$tag_url = __ROOT__.'/home/libs/tag.php';
if (file_exists($tag_url)) {require($tag_url);}
// 程序通用包含文件
$g_page = __ROOT__.'/home/libs/global.php';
if (file_exists($g_page)) require($g_page);
// 程序页
$code_page = __ROOT__.'/'.$app_file.'/'.$view.'.php';
if (file_exists($code_page)) require($code_page);


if($cfg_lang=='ZH'){
	$clg='EN';
}else{
	$clg='ZH';
}
// 网站配置
$tpl->assign('web_config',$web_config);
// 设置网页路径
$tpl->assign('web_dir',WEB_DIR);
// 设置网页mod值
$tpl->assign('web_view',$view);

$act=empty($act)?'index':$act;
$tpl->assign('act',$act);
$tpl->assign('lang',$_LANG);
$tpl->assign('clg',$clg);
$tpl->assign('cfg_lang',$cfg_lang);
// 模板页面设定
if (!isset($template_page)) $template_page = $view.$tpl_ext;
$main_page = __ROOT__.'/'.$tpl->template_dir.'/'.$template_page;
// 以模板页为主，没有控制页，只要有模板页，也能正常显示
if (!file_exists($main_page)) exit('template "<strong>'.$template_page.'</strong>" no exists!');

// 输出模板内容
if (!isset($cache_id)) $cache_id = '';
$tpl->display($template_page,$cache_id);
$db->close(); // 关闭数据库
?>