<?php session_start();?>
<?php include'includes/header.php'; ?>
<?php include'includes/sidebar.php';?>
<?php include'includes/functions.php';?>
<?php include'includes/navbar.php'; ?>

<!-- This page unique styles -->
<style>
/*Core setup styles*/
.sideNav{
    height: 100%;
    /*width: 220px;*/
    position: fixed;
    z-index: 9;
}
.navbar{
    top: 0;
    position: fixed;
    z-index: 9999;
}
.the-links{
    padding-top: 10px;
}
/*.nav-links{
    height: 100%;
    overflow-y: auto;
}*/
.insider{
    margin-top: 10px;
    position: relative;
}
.card{
    height: auto;
}
.cat-pag{
    position: relative;
}
.cat-page-header{
    position: sticky;
    width: 100%;
    height: 50px;
    background:#F7F9FB; 
    top: 60px;
    right: 60px;
    z-index: 1;
}
@media(max-width: 992px){
.insider{
    margin-top: 10px;
    padding-left: 10px;
    padding-right: 10px;
    }        
}
.card-header h5{
    font-size: 14px;
}

@media(max-width: 992px){
    .negative h5{
        font-size: 15px;
    }
    .negative a{
        font-size: 14px;
    }
    .negative a i{
        font-size: 14px;
    }
}
.custom-fieldset-box{
  border: 1px solid #ccc;
  padding: 10px;
  border-radius: 5px;
  position: relative;
  margin-bottom: 20px;
  background: #F7F9FB;
}
.custom-field-title{
  position: absolute;
  top: -12px;
  left: 15px;
  background: #F7F9FB;
  padding: 0 10px;
  font-weight: bold;
  color: #1E5F67;
  font-size: 15px;
}

input{
  width: 100%;
  height: 50px;
  border:2px solid #ccc;
  outline: none;
  border-radius: 5px;
  padding-left: 10px;
  padding-right: 10px;
}
select{
  width: 100%;
  height: 50px;
  border:2px solid #ccc;
  outline: none;
  border-radius: 5px;
  padding-left: 10px;
  padding-right: 10px;
}
.avater{
    width: 60px;
    height: 60px;
    border:2px solid #ccc;
    border-radius: 50%;
}
</style>
<?php

$emailAdd = $username;
?>

<div id="notification-containers" class="notification-containers"></div>
<div class="insider">
  <div class="container">
    <div class="cat-pag">
      <form action="" method="POST">
        <div class="cat-page-header d-flex justify-content-between align-items-center">
          <h5>Settings</h5>
          <div>
            <button class="btn success text-white btn-sm" onclick="openModal('modal-update'); event.preventDefault();"> <i class="fa fa-lock"></i> Password 
            </button>
              
            <button name="upd-save-btn" class="btn btn-sm info text-white"><i class="fa fa-sync"></i> Update Changes 
            </button>

          </div>
        </div>

        <div class="card mt-3">
          <div class="card-header" style="display: flex; align-items: center; justify-content: space-between;">
            <h5>MY PROFILE</h5>
          </div>
          <div class="card-body" style="background: #F7F9FB;">
            <div class="row" style="margin-top: -10px;">
              <div class="col-lg-6 mt-3">
                <div class="custom-fieldset-box">
                  <span class="custom-field-title">Title</span>
                  <div class="inner-cont">
                    <div class="input-wraps">
                      <select name="title">
                        <option value="<?=$title?>"><?=$title?></option>
                        <option value="Mr.">Mr.</option>
                        <option value="Mrs.">Mrs.</option>
                        <option value="Miss">Miss</option>
                      </select>
                    </div>
                  </div>
                </div>
              </div>

              <div class="col-lg-6 mt-3">
                  <div class="custom-fieldset-box">
                    <span class="custom-field-title">Names</span>
                    <div class="inner-cont">
                      <div class="input-wraps">
                        <input type="text" name="names" class="form-control"
                          value="<?=$names?>">                          
                      </div>
                    </div>
                  </div>
              </div>

              <div class="col-lg-6 mt-3">
                  <div class="custom-fieldset-box">
                    <span class="custom-field-title">Email Address</span>
                    <div class="inner-cont">
                      <div class="input-wraps">
                        <input type="text" name="email" class="form-control"
                          value="<?=$email?>">                          
                      </div>
                    </div>
                  </div>
              </div>

              <div class="col-lg-6 mt-3">
                  <div class="custom-fieldset-box">
                    <span class="custom-field-title">Mobile Number</span>
                    <div class="inner-cont">
                      <div class="input-wraps">
                        <input type="number" name="mobile" class="form-control"
                          value="<?=$mobile?>">                          
                      </div>
                    </div>
                  </div>
              </div>
            </div>
          </div>
        </div>
      </form>

      <!-- Updating Modal -->
      <div id="modal-update" class="modal">
        <div class="modal-content" style="margin-top:50px;">
          <div class="modal-header text-success">Change Password 
            <i class="fa fa-plus-circle"></i>
          </div>
          <div class="modal-body">
            <form action="" method="POST">
              <div class="row">
                <div class="col-lg-6 mt-3">
                  <div class="custom-fieldset-box">
                    <span class="custom-field-title">Password</span>
                    <div class="inner-cont">
                      <div class="input-wraps">
                        <input type="password" name="password" value="<?=$password?>" class="form-control">
                      </div>
                    </div>
                  </div>
                </div>

                <div class="col-lg-6 mt-3">
                  <div class="custom-fieldset-box">
                    <span class="custom-field-title">Password Again</span>
                    <div class="inner-cont">
                      <div class="input-wraps">
                        <input type="password" value="<?=$password?>" name="confirm" class="form-control">
                      </div>
                    </div>
                  </div>
                </div>
              </div>

              <div class="modal-footer">
                <button type="button" class="btn btn-danger" onclick="closeModal('modal-update')">Cancel <i class="fa fa-cancel"></i> &times;
                </button>
                <button name="upd-pass" class="btn btn-success">Update Password <i class="fa fa-user-plus"></i></button>
              </div>
            </form>
          </div>
              
        </div>
      </div>

    </div>
   
  </div>
</div>
<?php
if (isset($_POST['upd-pass'])) {
    
    $password = $_POST['password'];
    $confirm = $_POST['confirm'];
    
    if ($password != $confirm) {
        $_SESSION['message'] = 'Password does not match';
        $_SESSION['type'] = 'error';
    }else{
        $valPass = password_hash($password, PASSWORD_DEFAULT);
        $updater = "UPDATE staff SET password = ? WHERE staffId = ?";
        $insertpdo = $pdo->prepare($updater);
        if ($insertpdo->execute([$valPass, $staffId])) {
            $_SESSION['message'] = 'Password Updated Successfully.';
            $_SESSION['type'] = 'success';
        }else{
            $_SESSION['message'] = 'Something went wrong.';
            $_SESSION['type'] = 'error';

        }
        
    }

}
if (isset($_POST['upd-save-btn'])) {
  $title = $_POST['title'];
  $names = $_POST['names'];
  $email = $_POST['email'];
  $mobile = $_POST['mobile'];

  $updan = "UPDATE staff SET title = ?, fullname = ?, email = ?, phone_number = ?
          WHERE staffId = ?";
  $updStmt = $pdo->prepare($updan);
  $updStmt->execute([$title, $names, $email, $mobile, $staffId]);

  $_SESSION['message'] = 'Updated Successfully';
  $_SESSION['type'] = 'success';
}
?>


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

<script type="text/javascript">
    document.getElementById("fileImg").onchange = function(){
      document.getElementById("image").src = URL.createObjectURL(fileImg.files[0]); // Preview new image
      document.getElementById("cancel").style.display = "block";
      document.getElementById("uploads").style.display = "none";
    }
    var userImage = document.getElementById('image').src;
    document.getElementById("cancel").onclick = function(){
      document.getElementById("image").src = userImage; // Back to previous image
      document.getElementById("cancel").style.display = "none";
      document.getElementById("uploads").style.display = "block";
    }      
</script>
<script>
    $(document).ready(function () {
        $('#example').DataTable();
        $('#SelectAllBoxes').click(function () {
            $('.checkBoxes').prop('checked', this.checked);
        });
    });

    function openModal(id) {
        document.getElementById(id).style.display = "block";
    }

    function closeModal(id) {
        document.getElementById(id).style.display = "none";
    }

    function handleDelete() {
        const checked = document.querySelectorAll("input[name='checkBoxArray[]']:checked");
        if (checked.length === 0) {
            alert("No user selected!");
            return;
        }
        openModal('modal-delete');
    }
   
</script>


<!-- Modal Styling -->
<style>
    .modal {
        display: none;
        position: fixed;
        z-index: 99999;
        left: 0; top: 0;
        width: 100%; height: 100%;
        overflow: auto;
        background-color: rgba(0,0,0,0.5);

    }

    .modal-content {
        background-color: #fff;
        margin: auto;
        padding: 20px;
        border-radius: 8px;
        width: 80%;
        max-width: 500px;
        animation: fadeIn 0.3s;
    }

    .modal-header, .modal-footer {
        font-weight: bold;
    }

    @keyframes fadeIn {
        from { opacity: 0; transform: translateY(-20px); }
        to { opacity: 1; transform: translateY(0); }
    }

    
    .single-input{
        margin-top: 10px;
    }
    .single-input label{
        font-size: 15px;
        margin-left: 20px;
        font-family: sans-serif;
    }
    .my-input input{
        width: 100%;
        border:2px solid #ccc;
        outline: none;
        font-size: 16px;
        color: 888;
        height: 50px;
        border-radius: 10px;
        padding: 15px;
        text-align: left;
       /* height: 20px;*/
    }
    .my-input select{
        width: 100%;
        border:2px solid #ccc;
        outline: none;
        font-size: 16px;
        color: 888;
        height: 50px;
        border-radius: 10px;
        padding: 10px;
       /* height: 20px;*/
    }
    
</style>

<?php include'includes/notification-alert-js.php';?>

