<?php
include('inc/conn.php');
$str=$_GET['str'];
 ?>
<!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>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<meta name="robots" content="noindex,nofllow">
<title>无标题文档</title>
<link rel="stylesheet" type="text/css" href="css/css.css" />
</head>

<body>
<div id="main">
<div id="top">
       <?php include('header2.php');  ?>
       <div id="logo">
       <div id="menu">
          <ul><li class="current"><a href="manage.php">系统首页</a></li>
         <li><a href="news.php">新闻</a></li>
          <li><a href="commontools.php">工具箱</a></li>
       </ul><iframe style=" float:right" width='350' height='30' marginwidth='0' marginheight='0' hspace='0' vspace='0' frameborder='0' scrolling='No' src='http://m.weather.com.cn/m/p3/weather1.htm' name="I6"></iframe></div>
       </div>
    </div>
    
    <div id="findp">
       <div class="pcon">
         <h3> 找回密码</h3>
<?php $action=$_GET['action'];  
      if($action==''){
 ?>         
         <form method="post" action="findpwd.php?action=fuser">
         <span>第一步: 请输入要用户名</span>
         <p> 用户名：<input type="text" name="findusername" value="<?php echo $str;  ?>" /> </p>
          <p><input type="submit" name="submit" value="提 交" /></p>
</form>
<?php }elseif($action=='fuser'){  
          $fusername=$_POST['findusername'];
		   if($fusername==''){
		  echo "<font color='#ff0000'>用户名不正确！</font>";
		  echo "<script type='text/javascript'>history.back();</script>";
		  }
		  $userid=sql_select("select userid from etw_user where username='".$fusername."'");
		  if($userid[0][0]==''){
		  echo "<font color='#ff0000'>用户名不正确！</font>";
		  echo "<script type='text/javascript'>history.back();</script>";
		  }
		  $sql="select * from etw_baohu where userid=".$userid[0][0];
		  $result=mysql_query($sql); 
		  $rs=mysql_fetch_array($result);
		  $sql2="select * from etw_question where id=".$rs[questionid]; 
		  $result2=mysql_query($sql2); 
		  $question=mysql_fetch_array($result2);
		   		  		 
 ?>
       <form name="form1" method="post" action="findpwd.php?action=check">
      <span>第二步:  请回答以下2个问题：<br /><input type="hidden" name="userid" value="<?php echo $userid[0][0] ?>" /></span>
        <p> 1. <?php echo $question['question'] ?> 答案是 <input type="text" name="answer"  /></p>
       <p>  2. <?php echo $rs['definequestion'] ?> 答案是 <input type="text" name="defineanswer" /></p>
         <p>  <input type="submit" name="submit2" value="确 定" /></p>
       </form>     
<?php }elseif($action=='check'){
          $userid=$_POST['userid']; 
		  $answer=$_POST['answer']; 
		  $defineanswer=$_POST['defineanswer']; 
		  $sql="select * from etw_baohu where userid=".$userid;
		  $result=mysql_query($sql); 
		  $rs=mysql_fetch_array($result);

         if($rs['answer']==$answer && $rs['defineanswer']==$defineanswer ){
		       $new=rand(10000000,99999999);
			   $up="update etw_user set password='".$new."' where userid=".$userid;
			   mysql_query($up);
			   echo "<span>第三步: 找回密码</span>";
			   echo "<p>新的初始密码为:".$new.",</p><p>请<a href='index.php'>登陆系统</a>,马上重新设置新密码!</p>";
			 
		 }else{  echo "<p>答案不正确,请确认</p>"; 
		     echo "<script type=\"text/javascript\">window.location.href=\"findpwd.php\";</script>";
		 }
 ?>
       
<?php }  ?>
       </div>
    </div>
</div>
<?php mysql_close();?>
</body>
</html>
