<?php require_once("config.php");
$staff_id = $_GET["staff_id"];
if($staff_id == "")
	$staff_id = $_POST["staff_id"];
 ?> 
 <!DOCTYPE html>
<html>
<head>
    <title>Change Password</title>
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/bootstrap@4.5.3/dist/css/bootstrap.min.css"> 
    <link rel="stylesheet" href="style.css">
</head>
<body>
<div class="container">
    <div class="row">
        <div class="col-sm-3">
        </div>
        <div class="col-sm-6">
           
     <form action="" method="POST">
  <div class="login_form">

 <img src="https://technosmarter.com/assets/images/logo.png" alt="Techno Smarter" class="logo img-fluid"> <br> <?php 
	if(isset($_POST['change_password'])){
		//$currentPassword=$_POST['currentPassword']; 
		$staff_id=$_POST['staff_id'];  
		$password=$_POST['password'];  
		$passwordConfirm=$_POST['passwordConfirm']; 
		echo $sql="SELECT password from users where id=$staff_id";
		$res = mysqli_query($link,$sql);
		$res=mysqli_query($link,$sql);
		$row = mysqli_fetch_assoc($res);
		if($password != $passwordConfirm){
			$error[] = 'Passwords do not match.';
		}
		if(!isset($error))
		{
			$password = password_hash($password,PASSWORD_BCRYPT);

			$result = mysqli_query($link,"UPDATE users SET password='$password' WHERE id='$staff_id'");
			if($result)
			{
				header("location:entry.php?password_updated=1");
			}
			else 
			{
				$error[]='Something went wrong';
			}
		}																		  
	}
if(isset($error)){ 
	foreach($error as $error){ 
		echo '<p class="errmsg">'.$error.'</p>'; 
	}
}
        ?> 
     <form method="post" enctype='multipart/form-data' action="">
	 <input type="hidden" name="staff_id" value="<?php echo $staff_id?>">
          <div class="row">
				<div class="col"></div>
			  
				<div class="col"><p><a href="logout.php"><span style="color:red;">Logout <?php echo $staff_id?></span> </a></p>
			 </div>
          </div>
      <div class="form-group">
 <div class="row"> 
             <div class="col">
                 <label>New Password:- </label>
                <input type="password" name="password"  class="form-control">
            </div>
          </div>
      </div>
      <div class="form-group">
 <div class="row">  
             <div class="col">
                 <label>Confirm New Password:-</label>
                <input type="password" name="passwordConfirm"  class="form-control">
            </div>
          </div>
      </div>
           <div class="row">
            <div class="col-sm-6">
            </div>
            <div class="col-sm-6">
<button  class="btn btn-success" name="change_password">Change Password</button>
            </div>
           </div>
       </form>
        </div>
        <div class="col-sm-3">
        </div>
    </div>
</div> 
</body>
<script src="https://code.jquery.com/jquery-3.5.1.slim.min.js"></script>
<script src="https://cdn.jsdelivr.net/npm/bootstrap@4.5.3/dist/js/bootstrap.bundle.min.js"></script>
</html>