<?
require_once "configure.php";

if(!isset($_SESSION["egoUserName"])){
	print("<script type='text/javascript'>location.href='signin.php'</script>");
}

if($_POST["btnSubmit"]){
	$sql = "SELECT * from user WHERE id='".$_SESSION["egoUserID"]."' and pwd='".md5($pwd)."'";
	$result =mysql_query($sql)or die(mysql_error());
	if(mysql_num_rows($result)==0)print("<script type='text/javascript'>alert('Old password is incorrect!')</script>");
	else{
	 	$sql="update `user` set pwd='".md5($npwd)."' where id='".$_SESSION["egoUserID"]."' ";
		@mysql_query($sql) or die(mysql_error());
	
		print("<script type='text/javascript'>location.href='index.php'</script>");

	}
}

$sql = "SELECT * from user WHERE id='".$_SESSION["egoUserID"]."'";
$result =mysql_query($sql)or die(mysql_error());
while($myrow=MySQL_fetch_array($result))
{
	$email=$myrow["email"];
	$name=$myrow["name"];
	$ic=$myrow["ic"];
	$mobile=$myrow["mobile"];

}
?>

<!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" />
<title><?=TITLE;?></title>
<link rel="stylesheet" type="text/css" href="style.css" >
<script>
function ValidateForm(theform)
{
	var msg="";

	if(!theform.pwd.value)msg+="Old password is required. \n";
	if(!theform.npwd.value)msg+="New password is required. \n";			
	if(!theform.cpwd.value)msg+="Confirm password is required. \n";			

	if(theform.npwd.value != theform.cpwd.value)msg+="New password and confirm password is no match. \n";			
		
	if(msg){
		alert(msg)
		return false;
	}else return true;	
	
}
</script>
</head>

<body class="TextBox">
<table width="100%" border="0" cellspacing="0" cellpadding="0">
  <tr>
    <td height="46" bgcolor="#38abe3">
  <? require_once "header.php"; ?></td>
  </tr>
  <tr>
    <td>&nbsp;</td>
  </tr>
  <tr>
    <td><table width="1000" border="0" align="center" cellpadding="0" cellspacing="0">
      <tr>
        <td><form name="form" method="post" action="<?=$PHP_SELF;?>" ONSUBMIT="return ValidateForm(this)"><table width="60%" border="0" cellpadding="0" cellspacing="0">
          <tr>
            <td height="35" class="signin"><a href="account.php">Update Account</a>  &nbsp; &nbsp; &nbsp; Change Password</td>
          </tr>
          <tr>
            <td height="30" bgcolor="#cfecff" class="text">Old Password</td>
          </tr>
          <tr>
            <td height="35" bgcolor="#cfecff" class="text"><input name="pwd" type="password" class="inputBox" id="pwd" size="50" /></td>
          </tr>
          <tr>
            <td height="35" bgcolor="#cfecff" class="text">New Password</td>
          </tr>
          <tr>
            <td height="35" bgcolor="#cfecff" class="text"><input name="npwd" type="password" class="inputBox" id="npwd" size="50" /></td>
          </tr>
          <tr>
            <td height="35" bgcolor="#cfecff" class="text">Confirm Password</td>
          </tr>
          <tr>
            <td height="35" bgcolor="#cfecff" class="text"><input name="cpwd" type="password" class="inputBox" id="cpwd" size="50" /></td>
          </tr>
          <tr>
            <td height="35" bgcolor="#cfecff" class="text"><input type="submit" name="btnSubmit" id="btnSubmit" value="Update" /></td>
          </tr>
        </table>
        </form></td>
      </tr>
      <tr>
        <td>&nbsp;</td>
      </tr>
      <tr>
        <td><a href="http://egenos.com" target="_blank">Powered by eGen online solution</a></td>
      </tr>
    </table></td>
  </tr>
</table>
</body>
</html>