<?php
	include("inside/config.php");
	session_start();
	$user=$_SESSION['username'];
	if(empty($user))
	{
		echo "<script>window.location='login.php'</script>";
	}
	$id=$_REQUEST['id'];
	$currentpage = "profile";
	$sql=mysql_query("select * from `tbl_login` where `username`='$user'");
	$row=mysql_fetch_array($sql);

	if($_REQUEST['action']=="pass")
	{
		$old = $_REQUEST["old"];
		$new = $_REQUEST["new"];
		$confirm = $_REQUEST["confirm"];
		if($old == $row['password'] && $new == $confirm) {
		$update = mysql_query("update `tbl_login` SET `password`='$new' where `username`='$user'");
			if(!$update){
				$type = "error";
				$msg = "Error Updating Password";
				}
				else {
					$type = "ok";
					$msg = "Password Changed Successfully";
					}
			}
		if($old != $row['password']){
			$type = "error";
			$msg = "Your Current Password is Wrong!";
			}
		if($new != $confirm){
			$type = "error";
			$msg = "Password Does Not Match!";
			}
	}
?>
<!DOCTYPE html>
<head>
	<meta http-equiv="Content-type" content="text/html; charset=utf-8" />
	<title>Admin Panel : Frontier Public High School</title>
	<link rel="stylesheet" href="css/style.css" type="text/css" media="all" />
<?php include('inside/jsfunctions.php'); ?>
</head>
<body>
<?php include('inside/header.php'); ?>
<!-- Container -->
<div id="container">
	<div class="shell">
		
		<!-- Small Nav -->
		<div class="small-nav">
			<a href="#">Dashboard</a>
			<span>&gt;</span>
			Profile Setting
		</div>
		<!-- End Small Nav -->
		
		<!-- Message OK -->		
		<?php if($type=="ok"){ ?>
        <div class="msg msg-ok" id="msgok">
			<p><strong><?php echo $msg; ?></strong></p>
			<a href="#" class="close" onclick="removeOk()">close</a>
		</div>
		<!-- End Message OK -->		
		<?php } ?>
		<!-- Message Error -->
		<?php if($type=="error"){ ?>
		<div class="msg msg-error" id="error">
			<p><strong><?php echo $msg; ?></strong></p>
			<a href="#" class="close" onclick="removeError()">close</a>
		</div>
        <?php } ?>
		<!-- End Message Error -->
		<br />
		<!-- Main -->
		<div id="main">
			<div class="cl">&nbsp;</div>
			
			<!-- Content -->
			<div id="content">
				
				<!-- Box -->
				<div class="box">
					<!-- Box Head -->
					<div class="box-head">
						<h2 class="left">Change Password</h2>
					</div>
					<!-- End Box Head -->	

					<!-- Table -->
					<div class="table"><div class="form">
                    <form id="password" name="password" method="post" action="?action=pass&username=<?php echo $user; ?>"> 
					  <table width="100%" border="0" cellspacing="0" cellpadding="0">
                      <tr>
  <td width="29%" class="odd">Current Password</td>
					      <td width="71%"><label for="old"></label>
				          <input type="password" name="old" required="required" id="old" /></td>
					      </tr>
<tr>
  <td class="odd">New Password</td>
  <td><input type="password" name="new" id="new" required="required" /></td>
  </tr>
<tr>
  <td class="odd">Confirm New Password</td>
  <td><input type="password" name="confirm" required="required" id="confirm" /></td>
  </tr>
<tr>
  <td align="center" class="odd">&nbsp;</td>
  <td class="odd"><input name="button" type="submit" class="button" id="button" value="Save" /></td>
  </tr>
                      </table>
					      </form>
                          </div>
					  <!-- Pagging --><!-- End Pagging -->
						
					</div>
					<!-- Table -->
					
				</div>
				<!-- End Box -->
				
				<!-- Box --><!-- End Box -->

			</div>
			<!-- End Content -->
			
			<!-- Sidebar -->
			<div id="sidebar">
				
				<!-- Box -->
				<div class="box">
					
					<!-- Box Head -->
					<div class="box-head">
						<h2>Management</h2>
					</div>
					<!-- End Box Head-->
					
					<div class="box-content">
						<a href="new-article.php" class="add-button"><span>Add new Article</span></a>
						<div class="cl">&nbsp;</div>

						<!-- Sort --><!-- End Sort -->
						
					</div>
				</div>
				<!-- End Box -->
			</div>
			<!-- End Sidebar -->
			
			<div class="cl">&nbsp;</div>			
		</div>
		<!-- Main -->
	</div>
</div>
<!-- End Container -->
<?php  include("inside/footer.php"); ?></body>
</html>