<?php 
    include 'header.php'; 
    $namaku=$_SESSION['nama_karyawan'];
    $user=$_SESSION['username'];
?>

<div class="container">

  <div class="my-4 border-bottom">
    <h2 class="fw-semibold fs-3"></h2>
  </div>

<section class="content">
    <div class="row justify-content-center">
        <section class="col-lg-5">
            <?php if(isset($_GET['alert'])){ 
                if($_GET['alert'] == "sukses"){ 
                    echo "<div class='alert alert-success'>Password berhasil diganti!</div>"; 
                } else { 
                    echo "<div class='alert alert-danger'>Password belum berhasil diganti...!</div>"; 
                } 
            } ?>
            <div class="card card-info">
                <div class="card-header">
                    <span class="card-title fw-semibold">Ganti Password dari User : <?php echo $user; ?> </span>
                </div>
                <div class="card-body">
                    <div style="background-color: #DCDCDC; padding: 15px; border-radius: 15px; box-shadow: 0 0 15px rgba(0, 0, 0, 0.5);">
                        <form action="gantipassword_act.php" method="post" onsubmit="return validatePassword()">
                            <div class="form-group mb-2">
                                <label class="form-label">Masukkan Password Lama </label>
                                <input type="password" class="form-control" placeholder="Masukkan Password Lama .." name="password_lama" id="password_lama" required="required" min="5">
                            </div>
                            <div class="form-group mb-2">
                                <label class="form-label">Masukkan Password Baru</label>
                                <input type="password" class="form-control" placeholder="Masukkan Password Baru .." name="password" id="password" required="required" min="5">
                            </div>
                            <div class="form-group mb-2">
                                <label class="form-label">Ulangi Password Baru</label>
                                <input type="password" class="form-control" placeholder="Ulangi Password Baru .." name="password2" id="password2" required="required" min="5">
                                <span id="passwordError" style="color: red;"></span>
                            </div>
                            <div class="form-group mb-2">
                                <input type="submit" class="btn btn-primary" value="Simpan">
                            </div>
                        </form>
                    </div>
                </div>
            </div>
        </section>
    </div>
</section>

<script>
    function validatePassword() {
        var password = document.getElementById("password").value;
        var password2 = document.getElementById("password2").value;
        
        if (password !== password2) {
            document.getElementById("passwordError").innerHTML = "Password tidak sama!";
            return false;
        } else {
            document.getElementById("passwordError").innerHTML = "";
            return true;
        }
    }
</script>

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