<?php
define('ADMIN_ROOT',dirname(__FILE__));
require dirname(ADMIN_ROOT).'/sys.php';//初始化系统环境

if(!isset($get_act)) $get_act="";
$str_url=$web_url."/".ADMIN_DIR;
if(isset($get_go_url)){
	$str_url=$get_go_url;
}else{
	if(isset($_SERVER["HTTP_REFERER"])) $str_url=$_SERVER["HTTP_REFERER"];
}
//检查是否登录前台了
if(!$obj_ctl_user->is_login()){
	if($get_act=="login")
	{
		if(!isset($get_go_url)) $get_go_url="login.php";
		$arr_fields=array();
		$arr_fields["uname"]=$get_uname;
		$arr_fields["pwd"]=$get_pwd;
		$arr_return=$obj_ctl_user->on_login($arr_fields);
		if($arr_return["err"]!="")
		{
			$obj_msg->alert($arr_return["err"]);
			$obj_msg->on_history_back();
		}else{
			go_url($str_url);
		}
	}
	include './tpl/login.user.tpl.php';
}else if( !$obj_ctl_user->is_admin_login()) {
	if($get_act=="exit")
	{
		$obj_ctl_user->on_exit();
		$get_act="";
		go_url($str_url);
	}
	if($get_act=="login")
	{
		if(!isset($get_go_url)) $get_go_url="login.php";
		$arr_fields=array();
		$arr_fields["uname"]=$obj_ctl_user->uname;
		$arr_fields["pwd"]=$get_pwd;
		$arr_return=$obj_ctl_user->on_admin_login($arr_fields);
		if($arr_return["err"]!="")
		{
			$obj_msg->alert($arr_return["err"]);
			$obj_msg->on_history_back();
		}else{
			go_url($str_url);
		}
	}
	include 'tpl/login.tpl.php';
}else{
	if($get_act=="exit")
	{
		$obj_ctl_user->on_admin_exit();
		$get_act="";
		go_url($str_url);
	}else{
		if(stripos($str_url,"login.php")||$str_url==""){
			go_url($str_url);
		}else{
			go_url(WEB_URL."/".DATA_DIR);
		}
		exit;
	}
}
?>