<?php
session_start();
include "../datasource.inc.php";
require_once "../MessageBox.php";
$Message = new MessageBox;
if ( empty($_SESSION["adminuser"]) and $_SESSION["userjs"] != "1") {
	$Message->setMessage("对不起，您没有权限进入后台管理!","logout.php");
	$Message->showMessage();
}
$oldpasswd  = $_REQUEST['oldpasswd'];
$newpasswd  = $_REQUEST['newpasswd'];
if ($_REQUEST['action'] == "submitupdate") {
	$sql     = "select * from zht_user where userid='$_SESSION[adminuser]' and userpwd=PASSWORD('$oldpasswd')";
	$result  = mysql_query($sql);
	$num     = mysql_num_rows($result);
	echo $num;
	if ( $num > 0 ) {
		$query   = "update zht_user set userpwd=PASSWORD('$newpasswd') where userid='$_SESSION[adminuser]'";
		mysql_query($query);
		$Message->setMessage("密码修改成功！","user.php");
		$Message->showMessage();
	} else {
		$Message->setMessage("对不起，您输入的旧密码有误，请重输！","javascript:history.go(-1)");
		$Message->showMessage();
	}
}
?>
<HTML>
<HEAD>
<TITLE>后台管理系统</TITLE>
<META http-equiv=Content-Type content="text/html; charset=gb2312">
<link rel="stylesheet" href="../css/admin_style.css" type="text/css">
</head>
<BODY leftmargin="0" topmargin="0" marginwidth="0" marginheight="0" bgColor=#ffffff >
<br>

<script language="JavaScript">
function chk1()
{
  if(document.form1.oldpasswd.value=="")
    {
	  alert("提示：\n\n请输入密码！！");
	  document.form1.oldpasswd.focus();
	  return false;
	  }
  if(document.form1.oldpasswd.value.length<5)
     {
	   alert("提示:\n\n您输入的旧密码不能小于5位！！")
	   document.form1.oldpasswd.focus();
	   return false;
	   }
  if(document.form1.newpasswd.value=="")
    {
	  alert("提示：\n\n请输入新密码！！");
	  document.form1.newpasswd.focus();
	  return false;
	  }
  if(document.form1.newpasswd.value.length<5)
     {
	   alert("提示:\n\n您输入的新密码不能小于5位！！")
	   document.form1.newpasswd.focus();
	   return false;
	   }
  if(document.form1.newpasswd.value!=document.form1.newpasswd2.value)
    {
	  alert("提示：\n\n您输入的两次新密码不一致，\n请重输！！");
	  document.form1.newpasswd.focus();
	  return false;
	 }
	 	document.form1.submit()
}
</script>
<table width="700" border="0" cellspacing="0" cellpadding="0">
  <tr>
    <TD vAlign=top><FONT color=#565656><IMG height=14
      src="../images/closedfold.gif" width=14>&nbsp;&nbsp;您当前的位置<BR><IMG
      height=15 src="../images/bar.gif" width=15><IMG height=14
      src="../images/openfold.gif" width=14>&nbsp;&nbsp;会员密码修改</FONT>
	</TD>
  </tr>
</table>
<table width="680" height="295" border="0">
  <tr>
    <td width="660" valign="top">
    <form action="user.php?action=submitupdate" method="post" name="form1" onsubmit="return chk1()">
	<table width="260" border="0" align="center">
      <tr>
        <td width="80" height="20">会员帐号</td>
        <td width="170"><?php echo "$_SESSION[adminuser]"; ?></td>
      </tr>
      <tr>
        <td>旧 密 码</td>
        <td><input name="oldpasswd" type=password size="16"></td>
      </tr>
      <tr>
        <td>新 密 码</td>
        <td><input name="newpasswd" type=password size="16"></td>
      </tr>
      <tr>
        <td>确认新密码</td>
        <td><input name="newpasswd2" type=password size="16"></td>
      </tr>
    </table>
	  <table width="200" border="0" align="center">
        <tr>
          <td width="200">
		  <input type="submit" value="确定" name="Submit">&nbsp;&nbsp;
		  <input type="reset" name="Submit1" value="重置">
          </td>
        </tr>
      </table>
	  </form>
    </td>
  </tr>
</table>