<?php 
session_start();
include '_inc/dbconn.php';
        
if(!isset($_SESSION['admin_login'])) 
    header('location:adminlogin.php');   
?>
<?php include 'admin_header.php' ?>
<?php include 'admin_navbar.php'?>


<div class="content-wrapper">
  <div class="content">
<div class="row justify-content-center mt-5">
<div class="card-body p-5">
                  <h4 class="text-dark mb-5">Change Password</h4>
                  <form action="" method="POST">
                    <div class="row">
                   <div class="form-group col-md-12 ">
                        <input type="password" class="form-control input-lg" id="password"name="old_password" placeholder="Enter old password">
                      </div>
                      <div class="form-group col-md-12 ">
                        <input type="password" class="form-control input-lg" id="password" name="new_password"placeholder="Enter new password">
                      </div>
                      <div class="form-group col-md-12 ">
                        <input type="password" class="form-control input-lg" id="cpassword"name="again_password" placeholder="Confirm Password">
                      </div>
                      <div class="col-md-12">
                        <div class="d-inline-block mr-3">
                          
                        </div>
                        <button type="submit" name="change_password"class="btn btn-lg btn-primary btn-block mb-4">Change Password</button>
                
                      </div>
                    </div>
                  </form>
</div>
            </div>        </div>
                </div>

<!--             <form action="" method="POST">
                <table align="center">
                    <tr>
                        <td>Enter old password</td>
                        <td><input type="password" name="old_password" required=""/></td>
                    </tr>
                    <tr>
                        <td>Enter new password</td>
                        <td><input type="password" name="new_password" required=""/></td>
                    </tr>
                    <tr>
                        <td>Enter password again</td>
                        <td><input type="password" name="again_password" required=""/></td>
                    </tr>
                    <tr>
                        
                        <td colspan="2" align='center' style='padding-top:20px'><input type="submit" name="change_password" value="Change Password" class="addstaff_button"/></td>
                    </tr>
                </table>
            </form>
                </div>
            </div> -->
            <?php
            if(isset($_REQUEST['change_password'])){
            $sql="SELECT * FROM admin WHERE id='1'";
            $result=mysqli_query($con, $sql);
            $rws=  mysqli_fetch_array($result);
            $old=  mysqli_real_escape_string($con,$_REQUEST['old_password']);
            $new=  mysqli_real_escape_string($con,$_REQUEST['new_password']);
            $again=  mysqli_real_escape_string($con,$_REQUEST['again_password']);
            if($rws[9]==$old && $new==$again){
                $sql1="UPDATE admin SET pwd='$new' WHERE id='1'";
                mysqli_query($sql1) or die(mysqli_error($con));
                header('location:admin_hompage.php');
            }
            else{
                
                header('location:change_password.php');
            }
            }
            ?>
            

        <?php include 'footer.php';?>