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

function checklogin($act){
		
		$iserror = 0;
		
		switch($GLOBALS['fastloginfield']){
				case "username":
						$fastloginname = "用户名";
						$sql = "select * from ".JIEQI_DB_PREFIX."_system_users where uname = '".$GLOBALS['username']."'";
						break;
				case "mobileno":
						$fastloginname = "手机号";
						$sql = "select * from ".JIEQI_DB_PREFIX."_system_users where mobile = ".$GLOBALS['username'];
						if(preg_match("/[^\d-., ]/",$GLOBALS['username'])){
								$GLOBALS['notice'] = "手机号只能为11位数字！<br/>";
								$GLOBALS['iserror'] = 1;
						}
						break;
				case "email":
						$fastloginname = "Email";
						$sql = "select * from ".JIEQI_DB_PREFIX."_system_users where email = '".$GLOBALS['username']."'";
						if(!ereg("^([a-zA-Z0-9_-])+@([a-zA-Z0-9_-])+(\.[a-zA-Z0-9_-])+",$GLOBALS['username'])){
								$GLOBALS['notice'] = "请填写正确的邮箱地址！<br/>";
								$GLOBALS['iserror'] = 1;
						}
						break;
		}
		
		if($GLOBALS['username'] == "" and $iserror == 0){
				$GLOBALS['notice'] = $fastloginname."不能为空！<br/>";
				$GLOBALS['iserror'] = 1;
		}
		
		/*登录密码是否为空*/
		if($GLOBALS['password'] == "" and $iserror == 0){
				$GLOBALS['notice'] = "密码不能为空！<br/>";
				$GLOBALS['iserror'] = 1;
		}
		
		/*密码正确验证*/
		if($iserror == 0){
				$userdate = $GLOBALS['db']->query_object($sql);
				if(!$userdate){
						$GLOBALS['notice'] = $fastloginname."不存在！<br/>";
						$GLOBALS['iserror'] = 1;
				}else{
						if(md5($GLOBALS['password']) != $userdate->pass){
								$GLOBALS['notice'] = "帐号或密码错误！<br/>";
								$GLOBALS['iserror'] = 1;
						}else{
								$_SESSION["member"] = $userdate;
								$_SESSION["member"]->sid = generate_password(12);
								$sql = "SELECT uid,sid,setdata FROM hon6_sid WHERE uid = ".$_SESSION["member"]->uid;
								$set = $GLOBALS['db']->query_object($sql);
								if($set){
										$sql = "UPDATE hon6_sid SET sid = '".$_SESSION["member"]->sid."' WHERE uid = ".$_SESSION["member"]->uid;
										$GLOBALS['db']->query($sql);
										$_SESSION["set"] = unserialize($set->setdata);
								}else{
										$sql = "INSERT INTO hon6_sid(uid,sid) VALUES(".$_SESSION["member"]->uid.",'".$_SESSION["member"]->sid."')";
										$GLOBALS['db']->query($sql);
								}
								$GLOBALS['notice'] = "登录成功！<br/>".$_SESSION["member"]->name.",欢迎您回来，正在返回之前页！<br/>";
								$GLOBALS['iserror'] = 2;
						}
				}
		}
		
		if($GLOBALS['iserror'] == 2){
				$tourl = $GLOBALS['backurl'];
				$urlarray = parse_url($tourl);
				@$GLOBALS['tourl'] = "?".url_set_value($urlarray["query"],"sid",$_SESSION["member"]->sid);
		}
}

function logout($act){
		
				if(@$_SESSION["member"]->uid){
						$sql = "DELETE FROM hon6_sid WHERE uid = ".$_SESSION["member"]->uid;
						$GLOBALS['db']->query($sql);
				}
				unset($_SESSION);
				session_destroy();
				$GLOBALS['notice'] = "您已经成功注销！<br/>";
				$GLOBALS['iserror'] = 2;
				$tourl = $GLOBALS['backurl'];
				$urlarray = parse_url($tourl);
				@$GLOBALS['tourl'] = "?".url_set_value($urlarray["query"],"sid","");
				
}

		$smartydate = array("pagetitle" => "用户登录",
												"tourl" => $GLOBALS['tourl'],
												"redirecturl" => $GLOBALS['tourl'],
												"notice" => $GLOBALS['notice'],
												"pagecontent" => $GLOBALS['notice'],
												);
		if($GLOBALS['iserror'] == 2){
				$tplpath = "public.tpl";
		}else{
				$tplpath = "user/login.tpl";
		}
?>