<?php
header("Content-type:text/html;charset=utf-8"); 
?>
<!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>找回密码</title>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<meta http-equiv="X-UA-Compatible" content="IE=7; IE=9" />
<link type="text/css" rel="stylesheet" href="css/base.css" />
<script src="js/md5.js" type="text/javascript"></script>
<style type="text/css">
.td1 { padding:5px 0 0 0;width:70px;height:20px;vertical-align:top; }
.td2 { width:230px;vertical-align:top; }
.td3 { padding:5px 0 0 0;width:180px;vertical-align:top; }
.errstr { font-size:13px;color:#33cc00; }
</style>
<script type="text/javascript">
String.prototype.trim=function() {
     return this.replace(/(^\s*)(\s*$)/g, '');
}
function chkform() {
	var form = document.getElementById('form');
    if(form.userid.value.trim() == "") { 
      document.getElementById('errstr_userid').innerText = "用户ID不能为空！";
	  document.getElementById('errstr_userid').style.color = '#ff0000';
      return false; 
    } 
	document.getElementById('errstr_userid').innerText = "";
	document.getElementById('errstr_userid').style.color = '#33cc00';

    return true; 
}//chkform

function chkform2() {
	var form2 = document.getElementById('form2');

	if(form2.answer1.value.trim() == "") { 
      document.getElementById('errstr_answer1').innerText = "答案不能为空！";   
	  document.getElementById('errstr_answer1').style.color = '#ff0000';
      return false; 
    } 
	document.getElementById('errstr_answer1').innerText = "请输入密保答案"; 
	document.getElementById('errstr_answer1').style.color = '#33cc00';

	if(form2.pwd1.value.trim() == "") { 
      document.getElementById('errstr_pwd1').innerText = "登录密码不能为空！";   
	  document.getElementById('errstr_pwd1').style.color = '#ff0000';
      return false; 
    }
	document.getElementById('errstr_pwd1').innerText = "请使用高强度的密码";
	document.getElementById('errstr_pwd1').style.color = '#33cc00';

	if(form2.pwd2.value.trim() == "") { 
      document.getElementById('errstr_pwd2').innerText = "密码确认不能为空！";   
	  document.getElementById('errstr_pwd2').style.color = '#ff0000';
      return false; 
    } 
	document.getElementById('errstr_pwd2').innerText = ""; 
	document.getElementById('errstr_pwd2').style.color = '#33cc00';

	if(form2.pwd1.value.trim() != form2.pwd2.value.trim()) { 
      document.getElementById('errstr_pwd2').innerText = "两次输入的密码不一样！";   
	  document.getElementById('errstr_pwd2').style.color = '#ff0000';
      return false; 
    } 
	document.getElementById('errstr_pwd2').innerText = "";   
	document.getElementById('errstr_pwd2').style.color = '#33cc00';

	var md5Value = hex_md5(form2.pwd1.value.trim());
	md5Value = md5Value.toUpperCase();
	if(md5Value == "") { 
      alert('登录密码MD5加密出错！'); 
      return false; 
    }
	form2.pwd.value = md5Value;

	return true; 
}chkform2
</script>
</head>
<body style="overflow:hidden;border:none;" scroll="no" oncontextmenu="return false;">

<?php
$step = isset($_GET['step']) ? $_GET['step'] : '1'; 

function step1() {
echo<<<EOT
<div style="clear:both;margin:0 auto;padding:8px 0 0 8px;width:492px;height:22px;text-align:left;font-size:15px;font-weight:bold;color:#009ee8;">找回密码:</div>
<form style="margin:0;padding:0;" action="forgetpwd.php?step=2" method="post" id="form" onSubmit="return chkform();">
<div style="clear:both;margin:0 auto;padding:100px 0 0 20px;width:380px;height:180px;text-align:left;font-size:14px;color:#330000;">
	<table border="0">
	<tr>
		<td style="padding:5px 0 0 0;width:60px;height:20px;vertical-align:top;">用户ID:</td>
		<td style="width:140px;vertical-align:top;"><input style="width:120px;" type="text" name="userid" value=""></td>
		<td style="padding:5px 0 0 0;width:180px;vertical-align:top;"><span id="errstr_userid" class="errstr"></span></td>
	</tr>
	<tr>
		<td style="padding:5px 0 0 0;width:60px;height:20px;vertical-align:top;"></td>
		<td colspan="2" style="height:20px;vertical-align:middle;font-size:13px;color:#28a9ff;">请输入需要找回密码的用户ID，并点击下一步。</td>
	</tr>
	</table>
</div>
<div style="clear:both;margin:0 auto;padding:8px 10px 0 0;width:490px;height:32px;text-align:right;">
	<input class="btn80" type="submit" value="下一步">
</div>
</form>
EOT;
}//step1

function step2() {
	require("common.php");

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

	$methodname = 'UserCenter.GetPwdProtection';
	$requestinfo = '<?xml version="1.0" encoding="utf-8"?><request>' . 
		'<userid>' . $userid . '</userid>' . 
		'</request> ';
	$responseinfo = '';
	$responsexml = null;
	$errorcode = ERRORCODE_UNKNOWN;


	$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: 
echo<<<EOT
<div style="clear:both;margin:0 auto;padding:8px 0 0 8px;width:492px;height:22px;text-align:left;font-size:15px;font-weight:bold;color:#009ee8;">验证密保答案，并设置新的密码:</div>
<form style="margin:0;padding:0;" action="forgetpwd.php?step=3" method="post" id="form2" onSubmit="return chkform2();">
<input type="hidden" name="userid" value="{$userid}"/>
<input type="hidden" name="pwd" value=""/>
<div style="clear:both;margin:0 auto;padding:40px 0 0 20px;width:480px;height:240px;text-align:left;font-size:14px;color:#330000;">
	<table border="0">
	<tr>
		<td class="td1">密保问题:</td>
		<td class="td2"><input style="width:200px;background-color:#e2e2e2;" type="text" name="question1" value="{$responsexml->question1}" readOnly /></td>
	</tr>
	<tr>
		<td class="td1">密保答案:</td>
		<td class="td2" style="height:40px;"><input style="width:200px;" type="text" name="answer1" value=""><span style="color:#ff0000;">&nbsp;*</span></td>
		<td class="td3"><span id="errstr_answer1" class="errstr">请输入密保答案</span></td>
	</tr>
	<tr>
		<td class="td1">新的密码:</td>
		<td class="td2"><input style="width:200px;" type="password" name="pwd1" value=""><span style="color:#ff0000;">&nbsp;*</span></td>
		<td class="td3"><span id="errstr_pwd1" class="errstr">请使用高强度的密码</span></td>
	</tr>
	<tr>
		<td class="td1">密码确认:</td>
		<td class="td2" style="height:40px;"><input style="width:200px;" type="password" name="pwd2" value=""><span style="color:#ff0000;">&nbsp;*</span></td>
		<td class="td3"><span id="errstr_pwd2" class="errstr"></span></td>
	</tr>
	</table>
</div>
<div style="clear:both;margin:0 auto;padding:8px 10px 0 0;width:490px;height:32px;text-align:right;">
	<input class="btn80" type="submit" value="提交">
</div>
</form>
EOT;
		break;
		case ERRORCODE_NOTEXISTS: 
echo<<<EOT
	<div style="clear:both;margin:0 auto;padding:8px 0 0 8px;width:492px;height:22px;text-align:left;font-size:15px;font-weight:bold;color:#009ee8;">找回密码:</div>
	<div style="clear:both;margin:0 auto;padding:0;width:500px;height:280px;">
		<div style="float:left;margin:0;padding:120px 0 0 0;width:500px;text-align:center;font-size:16px;">
			<img border="0" width="40px" height="40px" align="absmiddle" src="images/warning.gif" />&nbsp;未设置密保信息！
		</div>
	</div>
	<div style="clear:both;margin:0 auto;padding:8px 10px 0 0;width:490px;height:32px;text-align:right;">
		<input class="btn80" type="button" value="完成" onclick="window.location='about:failure'">
	</div>
EOT;
		break;
		default: 
echo<<<EOT
	<div style="clear:both;margin:0 auto;padding:8px 0 0 8px;width:492px;height:22px;text-align:left;font-size:15px;font-weight:bold;color:#009ee8;">找回密码:</div>
	<div style="clear:both;margin:0 auto;padding:0;width:500px;height:280px;">
		<div style="float:left;margin:0;padding:120px 0 0 0;width:500px;text-align:center;font-size:16px;">
			<img border="0" width="40px" height="40px" align="absmiddle" src="images/warning.gif" />&nbsp;密保信息获取失败！
		</div>
	</div>
	<div style="clear:both;margin:0 auto;padding:8px 10px 0 0;width:490px;height:32px;text-align:right;">
		<input class="btn80" type="button" value="完成" onclick="window.location='about:failure'">
	</div>
EOT;
	}//switch
}//step2

function step3() {
	require("common.php");

	$userid = isset($_POST['userid']) ? $_POST['userid'] : ''; 
	$answer1 = isset($_POST['answer1']) ? $_POST['answer1'] : ''; 
	$answer2 = isset($_POST['answer2']) ? $_POST['answer2'] : ''; 
	$answer3 = isset($_POST['answer3']) ? $_POST['answer3'] : ''; 
	$newpwd = isset($_POST['pwd']) ? $_POST['pwd'] : ''; 

	$methodname = 'UserCenter.ResetUserPWD';
	$requestinfo = '<?xml version="1.0" encoding="utf-8"?><request>' . 
		'<userid>' . $userid . '</userid>' .  
		'<answer1>' . $answer1 . '</answer1>' . 
		'<answer2>' . $answer2 . '</answer2>' . 
		'<answer3>' . $answer3 . '</answer3>' . 
		'<newpwd>' . $newpwd . '</newpwd>' .
		'</request> ';
	$responseinfo = '';
	$responsexml = null;
	$errorcode = ERRORCODE_UNKNOWN;


	$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: 
echo<<<EOT
	<div style="clear:both;margin:0 auto;padding:8px 0 0 8px;width:492px;height:22px;text-align:left;font-size:15px;font-weight:bold;color:#009ee8;">找回密码:</div>
	<div style="clear:both;margin:0 auto;padding:0;width:500px;height:280px;">
		<div style="float:left;margin:0;padding:120px 0 0 0;width:500px;text-align:center;font-size:16px;">
			<img border="0" width="40px" height="40px" align="absmiddle" src="images/ok.gif" />&nbsp;新密码设置成功。
		</div>
	</div>
	<div style="clear:both;margin:0 auto;padding:8px 10px 0 0;width:490px;height:32px;text-align:right;">
		<input class="btn80" type="button" value="完成" onclick="window.location='about:failure'">
	</div>
EOT;
		break;
		case ERRORCODE_NOTEXISTS: 
echo<<<EOT
	<div style="clear:both;margin:0 auto;padding:8px 0 0 8px;width:492px;height:22px;text-align:left;font-size:15px;font-weight:bold;color:#009ee8;">找回密码:</div>
	<div style="clear:both;margin:0 auto;padding:0;width:500px;height:280px;">
		<div style="float:left;margin:0;padding:120px 0 0 0;width:500px;text-align:center;font-size:16px;">
			<img border="0" width="40px" height="40px" align="absmiddle" src="images/warning.gif" />&nbsp;密保答案不正确！
		</div>
	</div>
	<div style="clear:both;margin:0 auto;padding:8px 10px 0 0;width:490px;height:32px;text-align:right;">
		<input class="btn80" type="button" value="完成" onclick="window.location='about:failure'">
	</div>
EOT;
		break;
		default: 
echo<<<EOT
	<div style="clear:both;margin:0 auto;padding:8px 0 0 8px;width:492px;height:22px;text-align:left;font-size:15px;font-weight:bold;color:#009ee8;">找回密码:</div>
	<div style="clear:both;margin:0 auto;padding:0;width:500px;height:280px;">
		<div style="float:left;margin:0;padding:120px 0 0 0;width:500px;text-align:center;font-size:16px;">
			<img border="0" width="40px" height="40px" align="absmiddle" src="images/warning.gif" />&nbsp;未知错误！
		</div>
	</div>
	<div style="clear:both;margin:0 auto;padding:8px 10px 0 0;width:490px;height:32px;text-align:right;">
		<input class="btn80" type="button" value="完成" onclick="window.location='about:failure'">
	</div>
EOT;
	}//switch
}//step3

if ($step == 1) {
	step1();
}
else if ($step == 2) {
	step2();
}
else if ($step == 3) {
	step3();
}
?>

</body>
</html>
