<?php

session_start();
include ('connect.php');

if(empty($_SESSION['user_login'])){

	header("Location: login.php");
}else{

  if(isset($_POST['username']) && isset($_POST['email'])){
    
    $sql = "Update adminlogin set username='".$_POST['username']."',email='".$_POST['email']."' WHERE id = '".$_SESSION['admin_id']."'";     
    mysqli_query($conn,$sql);
    $messageForprofile="Profile Updated Successfully!";
    $_SESSION['username'] = $_POST['username'];
  }


  $sql = "SELECT * FROM  adminlogin WHERE id = '".$_SESSION['admin_id']."'";     
  $userdetails = mysqli_query($conn,$sql);
  $userdetails = mysqli_fetch_assoc($userdetails);


  if(isset($_POST['password']) && isset($_POST['new_password']) && isset($_POST['confirm_password'])){

    if($_POST['new_password'] == $_POST['confirm_password']){

      if($userdetails['password'] == md5($_POST['password'])){

        $sql = "Update adminlogin set password='".md5($_POST['confirm_password'])."' WHERE id = '".$_SESSION['admin_id']."'";     
        mysqli_query($conn,$sql);

        $messageForChangePassword="Password Changed Successfully!";

      }else{

        $messageForChangePassword="Old Password does not match";
  
      }
      

    }else{

      $messageForChangePassword="Confirm Password does not match";

    }    
    
    
  }  

}

?>


<!DOCTYPE html>

<html
  lang="en"
  class="light-style layout-menu-fixed"
  dir="ltr"
  data-theme="theme-default"
  data-assets-path="assets/"
  data-template="vertical-menu-template-free"
>
  <head>
    <meta charset="utf-8" />
    <meta
      name="viewport"
      content="width=device-width, initial-scale=1.0, user-scalable=no, minimum-scale=1.0, maximum-scale=1.0"
    />

    <title>Microsites</title>

    <meta name="description" content="" />

    <!-- Favicon -->
    <link rel="icon" type="image/x-icon" href="assets/img/favicon/favicon.ico" />

    <!-- Fonts -->
    <link rel="preconnect" href="https://fonts.googleapis.com" />
    <link rel="preconnect" href="https://fonts.gstatic.com" crossorigin />
    <link
      href="https://fonts.googleapis.com/css2?family=Public+Sans:ital,wght@0,300;0,400;0,500;0,600;0,700;1,300;1,400;1,500;1,600;1,700&display=swap"
      rel="stylesheet"
    />

   
    <link rel="stylesheet" href="assets/vendor/fonts/boxicons.css" />

    <!-- Core CSS -->
    <link rel="stylesheet" href="assets/vendor/css/core.css" class="template-customizer-core-css" />
    <link rel="stylesheet" href="assets/vendor/css/theme-default.css" class="template-customizer-theme-css" />
    <link rel="stylesheet" href="assets/css/demo.css" />

    <!-- Vendors CSS -->
    <link rel="stylesheet" href="assets/vendor/libs/perfect-scrollbar/perfect-scrollbar.css" />

    <script src="assets/vendor/js/helpers.js"></script>

    <script src="assets/js/config.js"></script>
  </head>

  <body>
    <!-- Layout wrapper -->
    <div class="layout-wrapper layout-content-navbar">
      <div class="layout-container">
        

        <!-- Layout container -->
        <div class="layout-page">
          <!-- Navbar -->

         <?php include('navbar.php'); ?>

          <!-- / Navbar -->

          <!-- Content wrapper -->
          <div class="content-wrapper">
            <!-- Content -->

            <div class="container-xxl flex-grow-1 container-p-y">

              <!-- Basic Layout -->
              <div class="row">
                <div class="col-xl">
                  <div class="card mb-4">
                    <div class="card-header d-flex justify-content-between align-items-center">
                      <h5 class="mb-0" >Edit Profile</h5>
                      
                    </div>
                    <div class="card-body">

                    <span style="color:red;margin-left: 26%;">
                      <?php if(!empty($messageForprofile)){ echo $messageForprofile; $messageForprofile="";} ?>
                    </span>
                      
                      <form method="post" action="profile.php">
                        
                        <div class="mb-3">
                          <label class="form-label" for="basic-default-fullname">Username</label>
                          <input type="text" class="form-control" id="username" name="username" placeholder="Enter Username" required value="<?php echo $userdetails['username']; ?>">
                        </div>
                        <div class="mb-3">
                          <label class="form-label" for="basic-default-company">Email</label>
                          <input type="email" class="form-control" id="email" name="email" placeholder="Enter Email" required value="<?php echo $userdetails['email']; ?>">
                        </div>

                        <button type="submit" class="btn btn-primary">Save</button>

                      </form>
                    </div>
                  </div>
                </div>
                <div class="col-xl">
                  <div class="card mb-4">
                    <div class="card-header d-flex justify-content-between align-items-center">
                      <h5 class="mb-0">Change Password</h5>
                      
                    </div>
                    <div class="card-body">

                    <span style="color:red;margin-left: 26%;">
                      <?php if(!empty($messageForChangePassword)){ echo $messageForChangePassword; $messageForChangePassword="";} ?>
                    </span>
                      
                    <form method="post" action="profile.php">
                   
                        <div class="mb-3">
                          <label class="form-label" for="basic-default-fullname">Old Password</label>
                          <input type="password" class="form-control" id="password" name="password" placeholder="Enter Old Password" required>
                        </div>
                        <div class="mb-3">
                          <label class="form-label" for="basic-default-company">New Password</label>
                          <input type="password" class="form-control" id="new_password" name="new_password" placeholder="Enter New Password" required>
                        </div>

                        <div class="mb-3">
                          <label class="form-label" for="basic-default-company">Confirm Password</label>
                          <input type="password" class="form-control" id="confirm_password" name="confirm_password" placeholder="Enter Confirm Password" required>
                        </div>
                       
                        <button type="submit" class="btn btn-primary">Save</button>

                      </form>
                    </div>
                  </div>
                </div>
              </div>
            </div>
            <!-- / Content -->

          
            <div class="content-backdrop fade"></div>
          </div>
            <!-- / Content -->


            <div class="content-backdrop fade"></div>
          </div>
          <!-- Content wrapper -->
        </div>
        <!-- / Layout page -->
      </div>

      
    </div>
    

    <script src="assets/vendor/libs/jquery/jquery.js"></script>
    <script src="assets/vendor/libs/popper/popper.js"></script>
    <script src="assets/vendor/js/bootstrap.js"></script>
    <script src="assets/vendor/libs/perfect-scrollbar/perfect-scrollbar.js"></script>

    <script src="assets/vendor/js/menu.js"></script>
    <!-- endbuild -->

    <!-- Vendors JS -->

    <!-- Main JS -->
    <script src="assets/js/main.js"></script>

    <!-- Page JS -->

    <!-- Place this tag in your head or just before your close body tag. -->
    <script async defer src="https://buttons.github.io/buttons.js"></script>
    
  </body>
</html>

