<?php 
    session_start();
    if(!$_SESSION['id']){
        header('location:index.php');
    }
?>
<?php
  require_once '../system/conn.php';
 if(isset($_POST['submit'])) {
     
    $curr_pwd=$_POST['curr_pwd'];
    //$curr_pwd = password_hash($curr_pwd1, PASSWORD_DEFAULT);
    
    $new_pwd=$_POST['new_pwd'];
    $con_new_pwd=$_POST['con_new_pwd'];
    $id= 1;

    $sth = $conn->prepare("SELECT * FROM `admin_login` where id='".$id."' ");
    $sth->execute();
    $row = $sth->fetch(PDO::FETCH_ASSOC); 
    $exit_pwd = $row['password']; 

    //print_r($curr_pwd."---------".$exit_pwd);exit;
    
    
    if(password_verify($curr_pwd, $exit_pwd)){
    
    if($new_pwd==$con_new_pwd){
        
        $new_password = password_hash($new_pwd, PASSWORD_DEFAULT);
        $data = [
        'new_pwd' => $new_password,
        'id' => $id,
        ];
        
        $sql = "UPDATE `admin_login` SET password=:new_pwd WHERE id=:id ";
        $stmt= $conn->prepare($sql);
        $sql1=$stmt->execute($data);
        
        if($sql1){
            $text="Password Update Successfully";
            echo '<script type="text/javascript">alert("'.$text.'")</script>';  
        }
    }  else {
        $text1="New Password and Confirm New Password are not Same ";
        echo '<script type="text/javascript">alert("'.$text1.'")</script>'; 
    } } else {
        
        $text2="Current Password is not Correct. ";
        echo '<script type="text/javascript">alert("'.$text2.'")</script>'; 
    }
 }
?>
<!doctype html>
<html lang="en" class="semi-dark">
  <head>
    <!-- Required meta tags -->
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1">
    
    <!-- loader-->
	  <link href="assets/css/pace.min.css" rel="stylesheet" />
	  <script src="assets/js/pace.min.js"></script>

    <!--plugins-->
    <link href="assets/plugins/perfect-scrollbar/css/perfect-scrollbar.css" rel="stylesheet" />
    <link href="assets/plugins/simplebar/css/simplebar.css" rel="stylesheet" />
    <link href="assets/plugins/metismenu/css/metisMenu.min.css" rel="stylesheet" />

    <!-- CSS Files -->
    <link href="assets/css/bootstrap.min.css" rel="stylesheet">
    <link href="assets/css/bootstrap-extended.css" rel="stylesheet">
    <link href="assets/css/style.css" rel="stylesheet">
    <link href="assets/css/icons.css" rel="stylesheet">
    <link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/bootstrap-icons@1.7.2/font/bootstrap-icons.css">
    <link href="https://fonts.googleapis.com/css2?family=Roboto:wght@400;500&display=swap" rel="stylesheet">

    <!--Theme Styles-->
    <link href="assets/css/dark-theme.css" rel="stylesheet" />
    <link href="assets/css/semi-dark.css" rel="stylesheet" />
    <link href="assets/css/header-colors.css" rel="stylesheet" />

    <title>Change Password</title>
  </head>
  <body>
    

 <!--start wrapper-->
    <div class="wrapper">
    <?php include'system/header.php'?>
    <!--end top header-->


        <!-- start page content wrapper-->
        <div class="page-content-wrapper">
          <!-- start page content-->
         <div class="page-content">


            <div class="row">
              <div class="col-xl-12 mx-auto">
                <h6 class="mb-0 text-uppercase">Update Your Password</h6>
                <hr/>
                <div class="card">
                  <div class="card-body">
                    <div class="p-4 border rounded">
                      <form class="row g-3 needs-validation" novalidate method="post" enctype="multipart/form-data" action="">
                        <div class="col-md-4">
                          <label for="validationCustom01" class="form-label">Current Password <span class="text-danger">*</span></label>
                          <input type="text" class="form-control" id="validationCustom01" placeholder="Current Password " name="curr_pwd" required>
                          <div class="valid-feedback">Enter Site Name!</div>
                        </div>
                        <div class="col-md-4">
                          <label for="validationCustom01" class="form-label">New Password <span class="text-danger">*</span></label>
                          <input type="text" class="form-control" id="validationCustom01" placeholder="Enter Site Name" name="new_pwd" required>
                          <div class="valid-feedback">Enter Site Name!</div>
                        </div>
                        <div class="col-md-4">
                          <label for="validationCustom01" class="form-label">Confirm New Password <span class="text-danger">*</span></label>
                          <input type="password" class="form-control" id="validationCustom01" placeholder="Enter Confirm New Password" name="con_new_pwd" required>
                          <div class="valid-feedback">Enter Site Name!</div>
                        </div>
                        <div class="col-12">
                          <button class="btn btn-primary" type="submit" name="submit" value="submit" >Submit form</button>
                        </div>
                      </form>
                    </div>
                  </div>
                </div>
                
                
              </div>
            </div>
            <!--end row-->


          </div>
          <!-- end page content-->
         </div>
<?php include'system/footer.php'?>