<?php 
session_start();
require_once 'core/init.php'; 
require_once 'fungsi.php';
require_once 'header.php';


if(!isset($_SESSION['user'])){
		header("location: login.php");
	}
if($_POST) {
	$currentpassword = $_POST['currentpassword'];
	$newpassword = $_POST['password'];
	$conformpassword = $_POST['conformpassword'];

	if($currentpassword == "") {
		echo "Current Password field is required <br />";
	}

	if($newpassword == "") {
		echo "New Password field is required <br />";
	}

	if($conformpassword == "") {
		echo "Conform Password field is required <br />";
	}
echo'<br>';
	if($currentpassword && $newpassword && $conformpassword) {
		if(passwordMatch($_SESSION['username'], $currentpassword) === TRUE) {

			if($newpassword != $conformpassword) {
				echo "New password does not match conform password <br />";
			} else {
				if(changePassword($_SESSION['username'], $newpassword) === TRUE) {
					echo "Successfully updated";
				} else {
					echo "Error while updating the information <br />";
				}
			}
			
		} else {
			echo "Current Password is incorrect <br />";
		}
	}
}

?>

<!DOCTYPE html>
<html>
<head>
	<title>Change Password</title>
        <meta charset="UTF-8" />
        <link rel="shortcut icon" href="../favicon.ico"> 

        <link rel="stylesheet" type="text/css" href="css/stylee.css" />
		<link rel="stylesheet" type="text/css" href="css/animate-custom.css" />
			<meta charset="utf-8">
	<meta name="viewport" content="width=device-width, initial-scale=1">
	<title>BUKIT GIBEON</title>
	<link rel="shortcut icon" href="images/inst.png">
	<link href="css/bootstrap.min.css" rel="stylesheet">
	<link href="css/animate.css" rel="stylesheet">
	<link href="css/myStyle.css" rel="stylesheet">
	<link rel="stylesheet" type="text/css" href="css/font-awesome.min.css">
	<script src="js/jquery-3.1.1.min.js"></script>
	<script src="js/bootstrap.min.js"></script>



</head>
<body background="images/jay.jpg">      
            <section>              	 

				
            <div id="container_demo" >        
                    <a class="hiddenanchor" id="toregister"></a>
                    <br><br><br><a class="hiddenanchor" id="tologin"></a>
                    <div id="wrapper">
					 
<div id="login" class="animate form">
                           <form action="<?php echo $_SERVER['PHP_SELF'] ?>" method="POST">
			<div class="containers"> 
                                <h1>Change Password</h1> 
                                <p> 
                                    <label for="username" class="uname"  > Current Passowrd</label>
                                    <input id="username" name="currentpassword"  type="password" placeholder="enter username" required>
                                </p>
                                <p> 
                                    <label for="password" class="youpasswd" > New Password </label>
                                    <input id="password" name="password"  type="password" placeholder="enter passoword" required > 
                                </p>
                                <p> 
                                    <label for="password" class="youpasswd" > Confirm Passord </label>
                                    <input id="password" name="conformpassword"  type="password" placeholder="enter passoword" required > 
                                </p>


                                <p class="login button"> 
                                    <input type="submit"  value="Change" > 
								</p>
                               
                            </form>
                        </div>

</form>

</body>
</html>