<?php

/*
*	Copyright VeryIDE,2007-2010
*	http://www.veryide.com/
*
*	$Id: page.global.php,v3 19:47 2008-2-18 Leilei $
*/
	
/*

	全局配置、函数及缓存载入

*/

///////////////////////////////////

//载入配置
require_once dirname(__FILE__)."/../config/config.php";
require_once dirname(__FILE__)."/../config/version.php";
require_once dirname(__FILE__)."/../config/setting.php";
require_once dirname(__FILE__)."/../config/ftp.php";
require_once dirname(__FILE__)."/../config/mail.php";

//设置时区
if( PHP_VERSION > '5.1' ) {
	@date_default_timezone_set('Etc/GMT'.($Setting["setting"]["timezone"] > 0 ? '-' : '+').(abs($Setting["setting"]["timezone"])));
}	

//载入扩展
require_once dirname(__FILE__)."/../config/licence.php";
require_once dirname(__FILE__)."/../config/adsense.php";

//载入函数
require_once dirname(__FILE__)."/../function/compat.php";
require_once dirname(__FILE__)."/../function/library.php";
require_once dirname(__FILE__)."/../function/cache.php";
require_once dirname(__FILE__)."/../function/hocker.php";
require_once dirname(__FILE__)."/../function/system.php";
require_once dirname(__FILE__)."/../function/ubb.php";
require_once dirname(__FILE__)."/../function/filter.php";
require_once dirname(__FILE__)."/../function/upload.php";
require_once dirname(__FILE__)."/../function/verify.php";

//载入缓存	

//////////// admins /////////////

//VeryIDE 已安装
if( VI_DBMANPRE && VI_DBMODPRE ){

	//载入用户缓存
	$cache = VI_ROOT."/cache/system/table.admin.php";

	//若不存在则主动创建缓存
	if( !file_exists($cache) ){

		//mysql open
		reader_mysql();

		//缓存系统用户
		cache_table('system',$mysql,VI_DBMANPRE."admin",'<option value=\'{table:id}\'>{table:account}</option>');

		//mysql close
		reader_mysql(true);

	}	

	//载入缓存
	require($cache);

}


//未登录设置全局会话
if( !isset($_SESSION["Manager"]) ){
	$_SESSION["Manager"] = array("id"=>0,"account"=>"","avatar"=>"","gid"=>0);	
}

//////////// modules /////////////

//载入模块缓存
$cache = VI_ROOT."/cache/system/files.module.php";

//若不存在则主动创建缓存
if( !file_exists($cache) ){

	//扫描模块
	cache_module();

}

//载入缓存
require($cache);

//////////// groups /////////////

//VeryIDE 已安装
if( VI_DBMANPRE && VI_DBMODPRE ){

	//载入分组缓存
	$cache = VI_ROOT."/cache/system/table.group.php";

	//若不存在则主动创建缓存
	if( !file_exists($cache) ){

		//mysql open
		reader_mysql();

		//缓存系统用户组
		cache_table('system',$mysql,VI_DBMANPRE."group",'<option value=\'{table:id}\'>{table:name}</option>');

		//mysql close
		reader_mysql(true);

	}

	//载入缓存
	require($cache);

	//缓存时间
	$time  = filemtime($cache);

	//写入到SESSION
	if( ( empty($_SESSION["Group"]) || $_SESSION["GroupLife"] != $time ) && $_SESSION["Manager"]["gid"] ){
		
		$_SESSION["Group"] = fix_json($VICACHE["sys.group"][$_SESSION["Manager"]["gid"]]["config"]);

		$_SESSION["GroupLife"] = $time;

		//var_dump($VICACHE["sys.group"]);

	}

}

$Group = isset($_SESSION["Group"])? $_SESSION["Group"] : array();


//////////// setting /////////////

$Global = $Setting["setting"];

//开启页面压缩
if( $Global["compress"] == "on" ){
	ob_start("compress");
}

//////////// menus /////////////


//VeryIDE 已安装
if( VI_DBMANPRE && VI_DBMODPRE ){

	//载入菜单缓存
	$cache = VI_ROOT."/cache/system/table.menu.php";

	//若不存在则主动创建缓存
	if( !file_exists($cache) ){

		//mysql open
		reader_mysql();

		//缓存系统菜单
		cache_table('system',$mysql,VI_DBMANPRE."menu",'<option value=\'{table:id}\'>{table:name}</option>'," sort asc ");

		//mysql close
		reader_mysql(true);

	}

	//载入缓存
	require($cache);

}
		
?>