<?
/*
	[Sueam CMS] (C)2009-2010 ZMRNet Studio
	check.php by 2009-10-10 zmrnet
*/
require_once($adm_dir.'/include/conn.php');
require_once($adm_dir.'/include/function.php');

$adm_name = trim($_POST['userName']);
$adm_pwd = trim($_POST['userPass']);
$adm_code = trim($_POST['chkCode']);

$adm_name = strtolower($adm_name);
$adm_pwd = substr(md5($adm_pwd),8,16);

if($_SERVER['HTTP_CLIENT_IP'])
	$userip = $_SERVER['HTTP_CLIENT_IP'];
elseif($_SERVER['HTTP_X_FORWARDED_FOR'])
	$userip = $_SERVER['HTTP_X_FORWARDED_FOR'];
elseif($_SERVER['REMOTE_ADDR'])
	$userip = $_SERVER['REMOTE_ADDR'];
else
	$userip = $HTTP_SERVER_VARS['REMOTE_ADDR'];

if(check_code && ($adm_code!=$_SESSION['rand_code']))
	die(refresh('?login').'<script>alert(\'验证码错误！\');</script>');

if(checkuser($adm_name)){
	$rs = $_VDB['adm'];
	if($row = $rs[$adm_name]){
		if($adm_pwd==$row['pwd']){
			if($row['lock']){
				die(refresh('../').'<script>alert(\'该管理员已经被锁定！\');</script>');
			}else{
				$row['ip'] = $userip;
				$row['num'] += 1;
				$row['time'] = date('Y-m-d H:i:s', time()+(time_zone*3600));
				$_VDB['adm'][$adm_name] = $row;
				$vdb->update($_VDB);
				$vdb->save();
				$_SESSION['sueam_admin'] = $adm_name;
				die(refresh('?main').'<script>//alert(\'登录成功！\');</script>');
			}
		}else{
			die(refresh('?login').'<script>alert(\'用户名或密码错误！\');</script>');
		}
	}else{
		die(refresh('?login').'<script>alert(\'用户名或密码错误！\');</script>');
	}
	unset($rs);
}else{
	die('用户名应该是数字、字母、点、下划线、连字符号，不允许出现汉字、空格等其他字符，请重新输入用户名！');
}

unset($_VDB);
unset($vdb);
?>