<? 
require_once "include/application.php"; 
require_once "include/function.php"; 

if($btnResetPwd){
	$sql = "SELECT * from user where email='$email'";
	$result =mysql_query($sql)or die(mysql_error());
	if(mysql_num_rows($result)==0)  
	{
	     $action_msg = "No correct email.";
	}else{
		while($myrow=MySQL_fetch_array($result)){
			$newpwd=$myrow["oldpwd"];
			$username =$myrow["id"];
		}	
		$sql = "update user set pwd='".md5($newpwd)."' WHERE id='$username'";		
		@mysql_query($sql)or die(mysql_error());
					
		$ret_email=email_notification("FORGOTPWD");																	
														
		$message=str_replace("{ID}",$username,$ret_email[message]);
		$message=str_replace("{newpwd}",$newpwd,$message);
		
		mail($email,$ret_email[subject],$message,'From:'.EMAIL);	

		$action_msg="Your password is already sent, please check your email !";	

	}

}
?>

<!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=iso-8859-1" />
<link rel="stylesheet" type="text/css" href="sddm.css" >
<script src="include/validation.js" type="text/javascript"></script>
<title><? echo TITLE?></title>
</head>
<body>

<table width="1024" border="0" align="center" cellpadding="0" cellspacing="0" bgcolor="#f1efd8">
  <tr>
    <td height="100" colspan="2" align="center"><? require_once "include/header.php"; ?></td>
  </tr>
  <tr>
    <td width="185" valign="top" bgcolor="e6f3f9">
	
<? require_once "include/columnLeft.php"; ?>
	</td>
    <td width="850" valign="top">
	<form name="mainform" method="post" action="<?=$PHP_SELF ?>" ONSUBMIT="return ValidateResetPwd(this)">
	  <table width="98%" border="0" align="center" cellpadding="0" cellspacing="0">
      <tr>
        <td height="30" colspan="2" class="TitleH3">Forgot Password </td>
      </tr>
	        <tr>
            <td colspan="3" ><? echo "<div class='Msg'>$action_msg</div>" ?>&nbsp;</td>
          </tr>
      <tr>
        <td height="1" colspan="2" bgcolor="#B8ED83"></td>
      </tr>
      <tr>
        <td colspan="2">&nbsp;</td>
      </tr>
      <tr>
        <td colspan="2" class="TextH1">Just enter  your email to retrieve your  username and   password.</td>
      </tr>
      <tr>
        <td colspan="2">&nbsp;</td>
      </tr>
      <tr>
        <td width="24%" height="30" class="TextH1">Email :          <span class="require">*</span></td>
        <td width="76%" class="TextH1"><input name="email" type="text" id="email" value="<? echo $email ?>" size="40" /></td>
      </tr>
      <tr>
        <td height="30" colspan="2" class="TextH1"><span class="require">* Denotes a required field</span></td>
      </tr>
      <tr>
        <td height="40" colspan="2" class="TextH1"><input name="btnResetPwd" type="submit" class="btn150" id="btnResetPwd" value="Reset Password" /></td>
      </tr>
    </table>
	</form>
	</td>
  </tr>
  <tr>
    <td colspan="2" bgcolor="#333333"><div align="center"><span class="Footer">
      <br />
      <? require_once  "footer.php"; ?>
    </span></div></td>
  </tr>
</table>
</body>
</html>
