<?php 
session_start();

$alert_msg = '';
if($_SESSION['goodlogin'] != true){
  header('location:../index');}else{
  require('connect.php');
  $unique_admin_id = $_SESSION['unique_admin_id'];
  }
	$updatealert = '';
$alert_msg_pass = '';

$getdata = "SELECT admin_hash_password FROM admin_access WHERE admin_email = '$unique_admin_id'";
$querytogetData = mysqli_query($cxn, $getdata);
if($querytogetData){
	$getmydata = mysqli_fetch_assoc($querytogetData);
	$d_customer_password = $getmydata['admin_hash_password'];
}
if(isset($_POST['update_profile_password'])){

  $customer_old_password = trim($_POST['old_password']);
  $customer_new_password = trim($_POST['new_password']);

  function test_input($cxn, $data){
    $data = stripslashes($data);
    $data = htmlspecialchars($data);
    $data = mysqli_real_escape_string($cxn, $data);
    return $data;
      }
      
  $customer_old_password = test_input($cxn, $customer_old_password);
      $customer_new_password = test_input($cxn, $customer_new_password);
      $customer_new_unhash_password = $customer_new_password;
  if(password_verify($customer_old_password, $d_customer_password)){
          $option = ['cost'=>12,];
          $customer_new_password = password_hash($customer_new_password, PASSWORD_BCRYPT, $option);

          $chk_data = "UPDATE admin_access SET admin_hash_password = '$customer_new_password', admin_password = '$customer_new_unhash_password' WHERE admin_email = '$unique_admin_id'";
          $querytoData = mysqli_query($cxn, $chk_data);
          if($querytoData){
              $errMSG = 'PASSWORD CHANGED SUCCESSFULLY';
              $alert_msg_pass = '<div class="alert alert-success">'.$errMSG.'</div>';
          }else{
              $errMSG = 'UNABLE TO CHANGE PASSWORD AT THIS TIME';
              $alert_msg_pass = '<div class="alert alert-danger">'.$errMSG.'</div>';
          }
      
  }else{
              $errMSG = 'OLD PASSWORD IS INCORRECT';
              $alert_msg_pass = '<div class="alert alert-warning">'.$errMSG.'</div>';
          }
      
      }
 
  ?>
<!DOCTYPE html>
<html lang="en">

<head>
<title>DASHBOARD - CONTROL PANEL</title>
	<link rel="shortcut icon" href="images/bicon.png">
	<!-- for-mobile-apps -->
	<meta name="viewport" content="width=device-width, initial-scale=1">
	<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
	<script>
		addEventListener("load", function () {
			setTimeout(hideURLbar, 0);
		}, false);

		function hideURLbar() {
			window.scrollTo(0, 1);
		}
	</script>
	<!-- css files -->
	<link href="css/bootstrap.css" rel='stylesheet' type='text/css' /><!-- bootstrap css -->
	<link href="css/istyle.css" rel='stylesheet' type='text/css' /><!-- custom css -->
	<link href="css/style.css" rel='stylesheet' type='text/css' /><!-- custom css -->
	<link href="css/font-awesome.min.css" rel="stylesheet"><!-- fontawesome css -->
	<!-- //css files -->

	<!-- google fonts -->
	<link
		href="//fonts.googleapis.com/css?family=Poppins:100,100i,200,200i,300,300i,400,400i,500,500i,600,600i,700,700i,800,800i,900,900i&amp;subset=devanagari,latin-ext"
		rel="stylesheet">

	<!-- //google fonts -->

</head>

<body>
	<!-- //header -->
	<header>
		<div class="container">
			<!-- nav -->
			<nav class="pt-3">
				<div id="logo">
					<h1> <a href="index.php" class="text-white">CONTROL PANEL</a></h1>
				</div>
				<label for="drop" class="toggle">Menu</label>
				<input type="checkbox" id="drop" />
				<ul class="menu mt-md-2 ml-auto">
					<li class="mr-lg-4 mr-2"><a href="index.php" class="text-white">Dashboard</a></li>
					<li class="mr-lg-4 mr-2"><a href="view_account.php" class="text-white"><div class="badge badge-dark p-2">View accounts</div></a></li>
					<li class="mr-lg-4 mr-2"><a href="view_messages.php" class="text-white">View Messages</a></li>
					<li class="mr-lg-4 mr-2"><a href="logout.php" class="text-white">Logout</a></li>
				</ul>
			</nav>
			<!-- //nav -->
		</div>
	</header>
	<!-- //header -->
	<!-- inner banner -->
	<div class="inner-banner2" id="home">
		<div class="container">

		</div>
	</div>
	<!-- inner banner -->
	<!-- TRACKING ORDER -->
	<section class="py-5" id="">
		<div class="container py-md-3">
			<h4 class="heading text-center mb-sm-2 my-4 text-white"> <span class="fa fa-lock"></span> CHANGE PASSWORD </h4>
			<div class="w-100">
                                                        <div class="card-header">
                                                        </div><?php echo $alert_msg_pass; ?>
                                                        <div class="card-body">
                                                            <form method="post"
                                                                action="<?php echo htmlspecialchars($_SERVER['PHP_SELF']);?>"
                                                                enctype="multipart/form-data">
                                                                    <div class="form-group">
                                                                        <label class="mr-sm-2">Old Password</label>
                                                                        <input type="password" name="old_password"
                                                                            class="form-control"
                                                                            placeholder="**********" required>
                                                                    </div>
                                                                    <div class="form-group">
                                                                        <label class="mr-sm-2">New Password</label>
                                                                        <input type="password" class="form-control"
                                                                            placeholder="**********"
                                                                            name="new_password" required>
                                                                    </div>
                                                                        <button type="submit"
                                                                            name="update_profile_password"
                                                                            class="btn btn-outline-dark text-white" style="">Change
                                                                            Password</button>
                                                            </form>
                                                        </div>
                                                    </div>
                                           
			</div>
		</div>
		</div>
	</section>

<script src="js/jquery-3.3.1.min.js"></script>
<script src="js/bootstrap.min.js"></script>
<script src="js/popper.min.js"></script>
</body>

</html>
                                                