<?php
header("Content-type:text/html;charset=utf-8"); 
session_start(); 

require("common.php");

$admin = isset($_POST['admin']) ? $_POST['admin'] : ''; 
$pwd = isset($_POST['pwd']) ? $_POST['pwd'] : ''; 

$methodname = 'Admin.Login';
$requestinfo = '<?xml version="1.0" encoding="utf-8"?><request>' . 
    '<ip>' . getip() . '</ip>' . 
	'<admin>' . $admin . '</admin>' . 
	'<pwd>' . $pwd . '</pwd>' . 
	'</request> ';
$responseinfo = '';
$responsexml = null;
$errorcode = ERRORCODE_UNKNOWN;

$errorstr = '';

$cmd = new COM("OpenCom.Command");
$methodname = iconv('UTF-8', 'GBK//IGNORE', $methodname);
$requestinfo = iconv('UTF-8', 'GBK//IGNORE', $requestinfo);
if ($cmd->Execute($methodname, $requestinfo, $responseinfo, 5000)) {
	$responseinfo = iconv('GBK', 'UTF-8//IGNORE', $responseinfo);
	$responsexml = simplexml_load_string($responseinfo);
	$errorcode = $responsexml->errorcode;
}
$cmd = null;

switch($errorcode) {
	case ERRORCODE_OK: 
		$_SESSION['admin'] = $admin;
		$_SESSION['logined'] = 1;
		$_SESSION['logintime'] = date('Y-m-d H:i:s');
	    header('Location: main.php');
		break;
	case ERRORCODE_PWDERROR:
        $errorstr = '管理员帐号或密码不正确！';
	    break;
	case ERRORCODE_USERLOCK:
        $errorstr = '管理员帐号已停用！';
	    break;
	case ERRORCODE_NOPERMISSION:
        $errorstr = '无权访问该页面！';
	    break;
	default:
        $errorstr = '未知错误！';	    
}//switch
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title><?php require("info/title.php"); ?></title>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<meta http-equiv="X-UA-Compatible" content="IE=EmulateIE7" />
<link rel="icon" href="favicon.ico" type="image/x-icon" />
<link rel="shortcut icon" href="favicon.ico" type="image/x-icon" />
<link type="text/css" rel="stylesheet" href="css/base.css" />
</head>
<body>

<div style="clear:both;margin:120px auto;padding:0;width:400px;height:300px;background:transparent url(images/login_frame.jpg) no-repeat;">
	<div style="margin:16px 10px 0 10px;padding:8px 6px 0 6px;width:368px;height:22px;font-size:13px;color:#ffffff;background-color:#068cbf;">
		<div style="float:left;margin:0;padding:0;font-weight:bold;"><?php require("info/title.php"); ?></div>
		<div style="float:right;margin:0;padding:0;"><?php require("info/version.php"); ?></div>		
	</div>
	<form action="login.php" method="post" id="form" onSubmit="return chkform();">
	<input type="hidden" name="pwd" value=""/>
	<ul style="margin:0;padding:20px 0 0 0;width:400px;list-style:none;font-size:13px;">
		<li style="padding:60px 0 0 0;height:80px;text-align:center;">&nbsp;<?php echo $errorstr ?></li>
		<li style="padding:15px 0 0 0;text-align:center;"><input class="cssbtn" type="button" value="返回"onclick="window.location='index.php'" /></li>
	</ul>
	</form>
</div>

</body>
</html>