<?php
	!defined('IN_MANAGE') && exit('Access Denied!');
	$action=empty($action)?'login':trim($action);

	switch($action)
	{
		case 'login':
			if(isset($do_submit))
			{
				

				if(!preg_match('/^[\x80-\xff_a-zA-Z0-9]{1,64}$/i',$username))
				{
					$adminobj->setlog($username,$password,'管理账号不存在！',0);
					showjsmsg('管理账号不存在！');
				}

				if(preg_match('/[\x80-\xff]/i',$password))
				{
					$adminobj->setlog($username,$password,'登陆密码不正确！',0);
					showjsmsg('登陆密码不正确！');
				}

				$r=$adminobj->getbyusername($username);
				if(!$r)
				{
					$adminobj->setlog($username,$password,'管理账号不存在！',0);
					showjsmsg('管理账号不存在！');
				}

				if($r['password']!=md5(trim($password)))
				{
					$adminobj->setlog($username,$password,'登陆密码不正确！',0);
					showjsmsg('登陆密码不正确！');
				}

				if($r['status']==0)
				{
					$adminobj->setlog($username,$password,'管理账号已被锁定！',0);
					showjsmsg('管理账号已被锁定！');
				}
				
				$_SESSION['isadmin']=$r['userid'];
				$_SESSION['w']=intval($w);
				$adminobj->setlog($username,'******','登陆成功！',1);
				exit('<script language="javascript">top.location.href="'.LA_PATH.ADMIN_FILE.'"</script>');
			}
			include admin_tlp('login');
			break;
		case 'logout':
			$_SESSION['isadmin']=0;
			$_SESSION['w']=0;
			unset($_SESSION['isadmin'],$_SESSION['w']);

			showjsmsg('登出成功！',LA_PATH.ADMIN_FILE.'?file=login&action=login');
			break;
	}
?>