<!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">
<?php

//重置密码界面
//fetchpassword.php,getadminpassword.php,resetpass.php
	require_once('inc/conn.php');
	require_once('inc/constant.php');
	require_once('inc/ls_syscode.php');
	$opendb=new mydb();
	require_once('inc/char_set.php');
	
	$urltag=trim($_GET['urltag']);
	if($_POST['urltag']!=''){$urltag=$_POST['urltag'];}  //如果有 表单的urltag，则使用
	echo "<meta http-equiv='Content-Type' content='text/html; charset=utf-8'>";

	$newpassword1=$_POST['newpassword1'];
	$newpassword2=$_POST['newpassword2'];
	//echo $_SESSION['username'];
	$sqlstr="select * from ls_fetchpass where urlTagStr='".$urltag."'";
	//echo $sqlstr;
	$query1=$opendb->query($sqlstr);
	$select_rows2=mysql_num_rows($query1); //总数
	
	if($select_rows2>=1) //
	{

		if(isset($_POST['submit']))
		{

			$rows=mysql_fetch_assoc($query1);
			$sqlstr="select * from ls_admin where adminName='".$rows['adminName']."'";
		
			$query1=$opendb->query($sqlstr);
			$rows=mysql_fetch_assoc($query1);
		
			if ($newpassword1 ==$newpassword2)
			{	
			
				if (!preg_match("/^(?![0-9]+$)(?![a-zA-Z]+$)[0-9a-zA-Z]{6,}$/", $newpassword1))
				{	
					$mess="密码需6位以上，至少包含一个数字一个字母！";
				}
				else
				{
					$sql_update="update ls_admin  set adminPwd='".md5($newpassword2)."' where adminName='". $rows['adminName']."'";
					//echo $sql_update;
					$query_update=$opendb->query($sql_update);
					
					// 删除重置密码url标记
					$select_sql2="delete from ls_fetchpass  where urlTagStr='".$urltag."'";
					$select_query2=$opendb->query($select_sql2);
					writelog($_SERVER['PHP_SELF'],"modify password", $_SESSION['username']);
	
					$mess=$query_update?"密码已重置 <a href='http://".$_SERVER ['HTTP_HOST']."/ls_admin'>点击这里重新登陆</a>":"密码修改失败！";
				}
			}
			else
			{
				$mess="两次输入的新密码不一致！";
			}
		}//if(isset($_POST['submit']))
	}
	else
	{
		die("取回密码链接已失效，请重新取回");
	}
?>

<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<link href="css/admin.css" rel="stylesheet" type="text/css">
<title>重置密码</title>
</head>
<body>
<table width="96%" border="0" align="center" cellpadding="0" cellspacing="1" bgcolor="#6396D6">
  <tr>
    <td height="25" background="images/admin_bg.gif"><div align="center"><font color="#FFFFFF"><strong>重置密码 </strong></font></div></td>
  </tr>
  <tr>
    <td height="251" align="center" valign="top" bgcolor="#E8F1FF"><br>
      <form name="form1" method="post" action="?ls=eidt">
        <p>&nbsp;</p>
        <p>&nbsp;</p>
        <table border="0">
          <tr>
            <td width="106" align="right">新密码：</td>
            <td width="157" align="center"><input name="newpassword1" type="password" id="newpassword1" size="16" maxlength="16"></td>
          </tr>
          <tr>
            <td align="right">新密码验证：</td>
            <td align="center"><input name="newpassword2" type="password" id="newpassword2" size="16" maxlength="16"></td>
          </tr>
          <tr>
            <td colspan="2" align="center"><input name="submit" type="submit" id="submit" value="确认">
              <input type="submit" name="Submit2" value="重填">
              <input type="hidden" name="urltag" id="hiddenField"  value="<?=$urltag?>"/>
              <br>
              <br>
              <font color="#FF0000"><?php echo $mess; ?></font></td>
          </tr>
        </table>
      </form>
      <br></td>
  </tr>
</table>
</body>
</html>
