<?php
	require 'init.php';
	$_POST = html_encode($_POST);
	if (is_post()) {
		$admin_user = trim($_POST['admin_user']);
		$admin_pwd  = trim($_POST['admin_pwd']);
		$rnd_code   = trim($_POST['rn_code']);
		if (!check_code($rnd_code)) {
			$sp->bgmsg('验证码错误');
			exit;
		}
		$sql = "SELECT * FROM ##__admin WHERE admin_user = '".$admin_user."' AND admin_pwd = '".md5($admin_pwd)."'";
		$arr = $db->fetch($sql,TRUE);
		if (!empty($arr)) {
			$_SESSION['admin_id']		= $arr['id'];
			$_SESSION['admin_user']		= trim($arr['admin_user']);
			$_SESSION['pri_config']     = trim($arr['pri_config']); //用户权限
			$_SESSION['last_login']		= date('Y-m-d H:i:s');
			$_SESSION['last_login_ip']  = $sp -> getRealIp();
			unset($arr[0]['admin_pwd']);
			$_SESSION['manager_data'] = $arr;
			print('<script>window.location.href="admincp.php";</script>');
			exit;
		} else {
			$sp -> bgmsg('用户名或密码不正确！');
			exit;
		}
	} elseif ($_GET['action'] == 'out') {
		@session_unset();
		@session_destroy();
		header("location:login.php");
	}else{
		$tpl->assign('rand',md5(mt_rand()));
		$pn = '后台入口';
		$sp -> outPut('login.tpl',$pn);
	}
?>