<?php session_start();?>
<?php include 'open_connection.php';?>
<!--link href='blue/style.css' rel='stylesheet' type='text/css' /-->
<link href='css/imagetable.css' rel='stylesheet' type='text/css' />
<?php 
		//$message = '<font color=red>Please insert username and password</font>';
		if (isset($_POST['login'])) {
			$user_name = trim(addslashes($_POST['user_name']));
			$oldpw = trim(addslashes($_POST['oldpw']));
			$newpw = trim(addslashes($_POST['newpw']));
			$confpw = trim(addslashes($_POST['confpw']));
			
			if ( $newpw != $confpw ) {
						$message = '<script type="text/javascript">
						window.alert("New Password not match")
						</script>';
			} else {
			
				$sql = "SELECT * FROM tbl_dir_user 	WHERE user_name = '$user_name' AND user_password = '$oldpw'";
																		
				$result = mysql_query($sql) or die('Query failed. ' . mysql_error());
				$row = mysql_fetch_array($result, MYSQL_ASSOC);
				
				if (mysql_num_rows($result) == 1) {
									
							// insert record into database
							$sql2="update tbl_dir_user set user_password='$newpw' where user_name='$user_name'";

								$result2=mysql_query($sql2);
								
								if($result2)
									echo "<script language='javascript'>window.location='index.php'</script>";
								else
   									echo 'Unsuccessfull update';
   				}	else   { 
					    
						$message = '<script type="text/javascript">
						window.alert("Invalid username or password")
						</script>';
				    }
					}
					 									    
	   } // post login
		
		?>
<!DOCTYPE html>
<html>

<head>
    <title>PICCSB e-Directory System</title>

  </head>
<body bgcolor="#333333"> 
<table width="100%" border="0" align="center">
<tr>
<td width="15%" bgcolor="#333333">&nbsp;</td>
<td width="70%" align="center" bgcolor="#FFFFFF" > 

<table width="100%" border="0" align="center">

<!-- row for header picc 1 -->
<tr>  
     <th width="100%" colspan="4"><img src="images/bgeoffice (1).png" width="100%" height="100%"></th>
</tr>


<!-- row for header picc 2 -->
					<tr>
     					<th width="100%" colspan="4"><img src="images/header picc5.png" width="100%" height="40%"></th>
					</tr>

<!-- calling frame -->	
					<tr>
   						 <td colspan="1" width="10%" align="center"><?php include("header.php");?></td>
					</tr>
					<tr>
						<td>
						<table align="center">
						<tr><td>&nbsp;</td></tr>
					<tr><td>&nbsp;</td></tr>
					<tr><td>&nbsp;</td></tr>
					<tr><td>&nbsp;</td></tr>
					
						<tr>
						<td colspan="3" align="center"><h2 align="center">CHANGE PASSWORD</h2><!--img src="images/login.jpg" width="150" height="90"-->
						</td>
						</tr>
						<form method='post' action="<?php echo $_SERVER['PHP_SELF'];?>">
				<tr>     <td>Username :</td>                  
                    <td><input name='user_name' type='text' size="20" maxlength="12" required='required'/></td></tr>
                <tr>
               <tr>     <td>Old Password :</td>                  
                    <td><input name='oldpw' type='password' size="20" maxlength="8" required='required'/></td></tr>
                <tr>
                    <td>New Password :</td>
                    <td><input name='newpw' type='password' size="20" maxlength="8" required = 'required' /></td></tr>
                <tr>                    
                    <td>Confirm Password :</td>                  
                    <td><input name='confpw' type='password' size="20" maxlength="8" required = 'required' /></td></tr>
                 <tr>   
					<td colspan="2" align="center"> <br /><br />
					<input type='submit' value='CHANGE PASSWORD' class="myButton" name="login" id="login" />
					<input type="reset" value="RESET" name="reset" id="reset" class="myButton">
					<!--input type='button' value='LOGIN PAGE' class="myButton" onClick="window.location.href='staff_login.php'"/-->
				</td>
                </tr>           
     	</form>
		 <?php  echo $message ?>
						 </table>
      					</td>
    				</tr>
					<tr><td>&nbsp;</td></tr>
					<tr><td>&nbsp;</td></tr>
					<tr><td>&nbsp;</td></tr>
					<tr><td>&nbsp;</td></tr>
					<tr><td>&nbsp;</td></tr>
					<tr><td>&nbsp;</td></tr>
					<tr>
						<th align="center" colspan="4">
						<?php include 'footer.php'; ?>
						</th>
					</tr>
 				 </table>
  
		<td width="20%" bgcolor="#333333">&nbsp;</td>

</tr>

<!--- end for ruang kerja 100% -->
</table>
</table>
</body>
</html>
