<?
		global $pagecontent;
		global $tourl;
		global $notice;
		global $iserror;
		
		switch($act){
				case "login":
						checklogin($act);
						break;
				case "logout":
						logout($act);
						break;	
		}

function checklogin($act){
		
		$iserror = 0;					
		
		if($GLOBALS['username'] == "" and $iserror == 0){
				$GLOBALS['notice'] = "用户名不能为空！<br/>";
				$GLOBALS['iserror'] = 1;
		}
		
		/*登录密码是否为空*/
		if($GLOBALS['password'] == "" and $iserror == 0){
				$GLOBALS['notice'] = "密码不能为空！<br/>";
				$GLOBALS['iserror'] = 1;
		}
		
		$sql = "select * from ".JIEQI_DB_PREFIX."_system_users where groupid = 2 and uname = '".$GLOBALS['username']."'";
		
		/*密码正确验证*/
		if($iserror == 0){
				$userdate = $GLOBALS['db']->query_object($sql);
				if(!$userdate){
						$GLOBALS['notice'] = "管理员不存在！<br/>";
						$GLOBALS['iserror'] = 1;
				}else{
						if(md5($GLOBALS['password']) != $userdate->pass){
								$GLOBALS['notice'] = "帐号或密码错误！<br/>";
								$GLOBALS['iserror'] = 1;
						}else{
								$_SESSION["member"]->sid = generate_password(12);
								
								$sql = "SELECT uid,sid,setdata FROM hon6_sid WHERE uid = ".$userdate->uid;
								$set = $GLOBALS['db']->query_object($sql);
								
								if($set){
									
										$sql = "UPDATE hon6_sid SET sid = '".$_SESSION["member"]->sid."' WHERE uid = ".$userdate->uid;
										$GLOBALS['db']->query($sql);
										$_SESSION["set"] = unserialize($set->setdata);
										
								}else{
									
										$sql = "INSERT INTO hon6_sid(uid,sid) VALUES(".$userdate->uid.",'".$_SESSION["member"]->sid."')";
										$GLOBALS['db']->query($sql);
										
								}
								$_SESSION["admin"] = $userdate;
								$GLOBALS['notice'] = "登录成功！<br/>".$userdate->name.",欢迎您回来，正在进入后台！<br/>";
								$GLOBALS['iserror'] = 2;
						}
				}
		}
		
		if($GLOBALS['iserror'] == 2){
				$url = array();
				$tourl = URL_admin_index($url);
				@$GLOBALS['tourl'] = $tourl;
		}elseif($GLOBALS['iserror'] == 1){
				$url = array();
				$tourl = URL_admin_login($url);
				@$GLOBALS['tourl'] = $tourl;
		}
}

function logout($act){
		
				unset($_SESSION["admin"]);
				session_destroy();
				$GLOBALS['notice'] = "您已经成功注销！<br/>";
				$GLOBALS['iserror'] = 2;
				$url = array();
				$tourl = URL_admin_login($url);
				@$GLOBALS['tourl'] = $tourl;
				
}

		$smartydate = array("pagetitle" => "管理员登录",
												"tourl" => $GLOBALS['tourl'],
												"redirecturl" => $GLOBALS['tourl'],
												"notice" => $GLOBALS['notice'],
												"pagecontent" => $GLOBALS['notice'],
												);
		if($GLOBALS['iserror'] == 2){
				$tplpath = "public.tpl";
		}elseif($GLOBALS['iserror'] == 1){
				$tplpath = "public.tpl";
		}else{
				$tplpath = "login.tpl";
		}
?>