<?php
include ('config.php');
if(!isset($_SESSION['emp_name']))
	 {
	  echo("<script language='javascript'>window.location.href='index.php'</script>");
	  exit;
	 }
if(isset($_REQUEST['type']))
{
	//echo "select * from tbl_admin where emp_uname='".$_SESSION['emp_uname']."' and emp_password='".$_REQUEST['emp_password']."'";
$que=mysqli_query($conn,"select * from tbl_admin where emp_uname='".$_SESSION['emp_uname']."' and emp_password='".$_REQUEST['emp_password']."'")or die(mysql_error());
$re=mysqli_fetch_array($que);
$nu=mysqli_num_rows($que);
if($nu==1)
{
$update=mysqli_query($conn,"update tbl_admin set emp_uname='".$_REQUEST['emp_uname']."',emp_password='".$_REQUEST['emp_npassword']."' where sno='".$_SESSION['sno']."'")or die(mysql_error());
echo '<script language="javascript">alert("Username and Password changed successfully");</script>';
echo '<script language="javascript">alert("Please Relogin !");</script>';
echo '<script language="javascript">window.location.href="logout.php"</script>';
}
else
{
echo '<script language="javascript">alert("Old password is wrong !");</script>';
}
}
?>
<!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 href="css/css.css" rel="stylesheet" type="text/css" />
		<link rel="stylesheet" type="text/css" href="css/grid.css" tppabs="" media="screen" />
        <!-- Main stylesheet -->
        <link rel="stylesheet" type="text/css" href="css/styles.css" tppabs="" media="screen" />

<script language="javascript">
	function validate(){
		d=document.change;
		if(d.emp_uname.value==""){
			alert("We need your username");
			d.emp_uname.focus();
			return false;		
		}
		if(d.emp_password.value==""){
			alert("We need your old password");
			d.emp_password.focus();
			return false;		
		}
		if(d.emp_npassword.value==""){
			alert("We need your new password");
			d.emp_npassword.focus();
			return false;		
		}
		if(d.emp_cpassword.value==""){
			alert("We need your confirm password");
			d.emp_cpassword.focus();
			return false;		
		}
		if(d.emp_npassword.value!=d.emp_cpassword.value){
			alert("Passwords do not match please type in your password");
			d.emp_cpassword.focus();
			return false;		
		}
			}
</script>
</head>
<body>
  <?php include('header1.php');?>
<table width="1002" border="0" align="center" cellpadding="0" cellspacing="0">
  <tr>
    <td></td>
  </tr>
  <tr>
    <td><table width="100%" border="0" cellspacing="0" cellpadding="0">
      <tr>
        <td class="innertop_tablepad">&nbsp;</td>
      </tr>
      <tr>
        <td class="innertop_bg"><table width="96%" border="0" align="center" cellpadding="0" cellspacing="0">

          <tr>
            <td>
			
			<table width="100%" border="0" cellspacing="0" cellpadding="0">
              <tr>
                <td height="55"><table width="99%" border="0" align="center" cellpadding="0" cellspacing="0">
                  <tr>
                    <td width="88%" align="center" class="heading2">Change Password</td>
                    </tr>
                </table></td>
              </tr>
              <tr>
                <td>
				<form method="post" name="change" action="" onsubmit="return validate();" style="margin: 0 0 0 178px;">
				<table width="100%" border="0" cellspacing="0" cellpadding="0">
                  <tr class="head_bg">
                    <td width="100%" height="28" colspan="3" class="form_head" >Enter the New  Password</td>
                    </tr>
                  <tr>
                    <td colspan="3">
					  <?php
					  $seluname=mysqli_query($conn,"select * from tbl_admin where emp_uname='".$_SESSION['emp_uname']."' and emp_password='".$_SESSION['emp_password']."' ") ;
					  $runame=mysqli_fetch_array($seluname);
					  ?>
					<table width="100%" border="0" cellspacing="0" cellpadding="0">
                      <tr>
                        <td width="25%" class="form_text">Username</td>
                        <td width="4%" align="center" class="form_text">:</td>
                        <td width="71%" class="form_text"><input name="emp_uname" type="text" size="35" value="<?php echo $runame['emp_uname']; ?>" /></td>
                      </tr>
                      
                      <tr class="row_color">
                        <td class="form_text">Enter Old Password</td>
                        <td align="center" class="form_text">:</td>
                        <td class="form_text"><input name="emp_password" type="password" size="35" value="" /></td>
                      </tr>
                      <tr>
                        <td class="form_text">Enter New Password</td>
                        <td align="center" class="form_text">:</td>
                        <td class="form_text"><input name="emp_npassword" type="password" size="35" value="" /></td>
                      </tr>
                      <tr class="row_color">
                        <td valign="top" class="form_text"> Enter Confirm Password</td>
                        <td align="center" valign="top" class="form_text">:</td>
                        <td class="form_text"><input name="emp_cpassword" type="password" size="35" value="" /></td>
                      </tr>
                    </table></td>
                  </tr>
                  <tr>
                    <td colspan="3">&nbsp;</td>
                  </tr>
                  <tr>
                    <td colspan="3">&nbsp;</td>
                  </tr>
                  <tr>
                    <td colspan="3"><table width="100%" border="0" cellspacing="0" cellpadding="0">
                      <tr>
                        <td width="69%" align="center"><input name="type" id="type" type="submit"  value="Update" /></td>
                      </tr>
                    </table></td>
                  </tr>
                  <tr>
                    <td colspan="3">&nbsp;</td>
                  </tr>
                </table>
				</form>
				</td>
              </tr>
            </table>
			
			</td>
          </tr>
          <tr>
            <td height="30" class="dotline">&nbsp;</td>
          </tr>
        </table></td>
      </tr>
      
    </table></td>
  </tr>
  <tr>
    <td></td>
  </tr>
</table>
</body>
</html>
