<?
		global $begin;
		global $end;
		$begin = microtime(TRUE);
		
		date_default_timezone_set('PRC');
		
		@include_once("config.php");
		require_once "include/include.php";
		
		if(@$m == ""){
				$m = "book/index";
		}
		
		$indexerror = 0;
		$db = new hon6mysql;
		$db -> mysql_link();
		
		Session::start($db);
		
		/*页面风格判断*/
		if(isset($pagestyle)){
				if(file_exists(HON6_ROOT.'./templates/'.$pagestyle)){
						$_SESSION["set"]["pagestyle"] = $pagestyle;
				}else{
						exit("doesn`t exists /templates/$pagestyle");
				}
		}else{
				$pagestyle = (isset($_SESSION["set"]["pagestyle"]) ? $_SESSION["set"]["pagestyle"] : "html");
		}
		
		/*根据SID获取身份*/
		if(count(explode("admin",$m))>1){
			
				if(isset($_SESSION["member"]->sid)){
						$sql = "SELECT * FROM ".JIEQI_DB_PREFIX."_system_users a LEFT JOIN hon6_sid b ON a.uid=b.uid WHERE a.groupid = 2 AND b.sid = '".$_SESSION["member"]->sid."'";
						$admin = $db->query_object($sql);
				}
				if(@!$admin && $m != urldecode("admin/login")){
						$url = array("act"=>"",);
						$tourl = URL_admin_login($url);
						$smartydate = array("pagetitle" => "登录超时",
																"pagecontent" => "登录超时，请您重新登录！<br/>",
																"tourl" => $tourl,
																"redirecturl" => $tourl,
																);
																
						$tplpath = "public.tpl";
						$indexerror = 1;
				}
				
		}else{
				if(isset($sid) && $sid != ""){
						$sql = "SELECT * FROM ".JIEQI_DB_PREFIX."_system_users a LEFT JOIN hon6_sid b ON a.uid=b.uid WHERE b.sid = '".$sid."'";
						if($userdate = $db->query_object($sql)){
								$_SESSION["member"] = $userdate;
								$_SESSION["member"]->sid = $sid;
						}else{
								if(isset($_SESSION["member"]->sid) && $sid!=$_SESSION["member"]->sid){
										$urlarray = parse_url("?".$_SERVER['QUERY_STRING']);
										@$gotourl = $urlarray["path"]."?".urldecode(url_set_value($urlarray["query"],"sid",$_SESSION["member"]->sid));
										header("location:".$gotourl);
										exit();	
								}else{
										unset($_SESSION["member"]);
								}
						}
				}else{
						if(isset($_SESSION["member"]->sid)){
								$urlarray = parse_url("?".$_SERVER['QUERY_STRING']);
								@$gotourl = $urlarray["path"]."?".urldecode(url_set_value($urlarray["query"],"sid",$_SESSION["member"]->sid));
								header("location:".$gotourl);
								exit();	
						}else{
								unset($_SESSION["member"]);
						}
				}
				
				if(@!isset($_SESSION["set"]) && isset($_SESSION["member"]->uid)){
						$sql = "SELECT setdata FROM hon6_sid WHERE uid = ".$_SESSION["member"]->uid;
						$set = $db->query_field($sql);
						$_SESSION["set"] = unserialize($set);
				}
		}
		
		if(count(explode("admin",$m))>1){
				$smartyObj = new mySmarty("admin");
		}else{
				$smartyObj = new mySmarty($pagestyle);
		}
		
		if($pagestyle=="wml"){
				header("Content-type:text/vnd.wap.wml;charset=utf-8");
		}
		
		$listuser = new getuser;
		
		if($indexerror == 0){
				if(@!include_once(HON6_ROOT."./models/".$m.".php")){
						if(count(explode("admin",$m))>1){
								$url = array();
								$tourl = URL_admin_index($url);
						}else{
								$url = array();
								$tourl = URL_book_index($url);
						}
						$smartydate = array("pagetitle" => "不存在的模块",
																"pagecontent" => "$m 模块不存在，请联系管理员！<br/>",
																"tourl" => $tourl,
																"redirecturl" => $tourl,
																);
																
						$tplpath = "public.tpl";
				}
		}
		
		$_getst = new _GSITER();
		$_siter = $_getst->trackPageView();
		
		$Counter = new Application();
		$Counter -> set(session_id());
		$online = $Counter -> Online();
		
		$end = microtime(TRUE);
		$middletimes = $end-$begin;
		
		$smartyObj -> assign('wapset',@$wapset);
		$smartyObj -> assign('version',$version);
		$smartyObj -> assign('online',$online);
		$smartyObj -> assign('sortlist',$jieqiSort['article']);
		$smartyObj -> assign('middletimes',sprintf("%01.2f",$middletimes));
		
		if(@$_SESSION["member"]->uid && @!$smartydate["redirecturl"] && @$smartydate["pagetitle"] && count(explode("history",$m)) == 1){
				
				if(count(@$_SESSION["history"]) > 20){
						array_shift($_SESSION["history"]);
				}
				
				$_SESSION["history"][] = array("pagetitle" => $smartydate["pagetitle"],
																			"url" => "http://".$_SERVER['HTTP_HOST'].$_SERVER['REQUEST_URI'],
																			"date" => time(),
																			);
																			
		}
				
		$smartyObj -> formatpage($tplpath,$smartydate,$_siter);
?>