<!-- ======= Sidebar ======= -->
<aside id="sidebar" class="sidebar">

    <ul class="sidebar-nav" id="sidebar-nav">


        <?php
        switch ($_SESSION['strJenisAkses']) {
            case "DIR":
                include_once('menu.dir2.php');
                break;
            case "MGR":
                include_once('menu.mgr2.php');
                break;
            case "SPV":
                include_once('menu.spv2.php');
                break;
            case "STAFF":
                include_once('menu.staff2.php');
                break;
        }
        ?>
        <script src="assets/libs/js/jquery-3.6.0.min.js"></script>

        <li class="nav-item">
            <a class="nav-link collapsed" data-bs-target="#forms-nav" data-bs-toggle="collapse" href="#">
                <i class="bi bi-gear"></i><span>Pengaturan</span><i class="bi bi-chevron-down ms-auto"></i>
            </a>
            <ul id="forms-nav" class="nav-content collapse " data-bs-parent="#sidebar-nav">
                <li>
                    <a href="#" data-bs-toggle="modal" data-bs-target="#basicModal">
                        <i class="bi bi-circle"></i><span>Ubah sandi</span>
                    </a>
                </li>
                <!--
                <li>
                    <a href="?menu=iplist">
                        <i class="bi bi-circle"></i><span>IP LIST</span>
                    </a>
                </li>
    -->
            </ul>
        </li>
        <!--
        <li class="nav-item">
            <a class="nav-link collapsed" data-bs-target="#forms-produksi" data-bs-toggle="collapse" href="#">
                <i class="bi bi-columns-gap"></i><span>Produksi</span><i class="bi bi-chevron-down ms-auto"></i>
            </a>
            <ul id="forms-produksi" class="nav-content collapse " data-bs-parent="#sidebar-nav">
                <li>
                    <a href="?menu=lotfg">
                        <i class="bi bi-circle"></i><span>Nomer Lot FG</span>
                    </a>
                </li>
            </ul>
        </li>

        <li class="nav-item">
            <a class="nav-link collapsed" data-bs-target="#forms-gudang" data-bs-toggle="collapse" href="#">
                <i class="bi bi-box-seam"></i><span>Gudang</span><i class="bi bi-chevron-down ms-auto"></i>
            </a>
            <ul id="forms-gudang" class="nav-content collapse " data-bs-parent="#sidebar-nav">
                <li>
                    <a href="?menu=bj">
                        <i class="bi bi-circle"></i><span>Penerimaan FG</span>
                    </a>
                </li>
                <li>
                    <a href="?menu=Laporanfggudang">
                        <i class="bi bi-circle"></i><span>Laporan Penerimaan FG</span>
                    </a>
                </li>
            </ul>
        </li>
    -->
        <li class="nav-heading">Other</li>

        <li class="nav-item">
            <a class="nav-link collapsed" href="logout.php">
                <i class="bi bi-box-arrow-right"></i>
                <span>Keluar</span>
            </a>
        </li><!-- End Profile Page Nav -->

    </ul>

</aside><!-- End Sidebar-->


<div class="modal fade" id="basicModal" tabindex="-1" style="display: none;" aria-hidden="true">
    <div class="modal-dialog">
        <div class="modal-content">
            <div class="modal-header">
                <h5 class="modal-title">Ubah Sandi</h5>
                <button type="button" class="btn-close" data-bs-dismiss="modal" aria-label="Close"></button>
            </div>
            <div class="modal-body">
                <div class="row g-3">
                    <div class="col-12">
                        <label class="form-label">Sandi lama anda</label>
                        <input type="password" class="form-control" id="strSandiLama">
                    </div>
                    <div class="col-12">
                        <label class="form-label">Sandi baru anda</label>
                        <input type="password" class="form-control" id="strSandiBaru">
                    </div>
                    <div class="col-12">
                        <label class="form-label">Ulangi sandi baru anda</label>
                        <input type="password" class="form-control" id="strSandiKonfirmasi">
                    </div>
                </div>
            </div>
            <div class="modal-footer">
                <button type="button" class="btn btn-secondary" data-bs-dismiss="modal">Batal</button>
                <button type="button" class="btn btn-primary" onclick="ubahsandi()">Simpan</button>
            </div>
        </div>
    </div>
</div>

<script src="assets/libs/js/jquery-3.6.0.min.js"></script>
<script>
    function ubahsandi() {
        var strSandiLama = $("#strSandiLama").val();
        var strSandiBaru = $("#strSandiBaru").val();
        var strSandiKonfirmasi = $("#strSandiKonfirmasi").val();
        if (strSandiLama == "") {
            Swal.fire({
                title: "Sandi lama harus diisi",
                icon: "Warning"
            });
        } else {
            if (strSandiBaru == "") {
                Swal.fire({
                    title: "Sandi baru harus diisi",
                    icon: "Warning"
                });
            } else {
                if (strSandiKonfirmasi == "") {
                    Swal.fire({
                        title: "Sandi konfirmasi harus diisi",
                        icon: "Warning"
                    });
                } else {
                    $.ajax({
                        url: "pengaturan/ubahsandi/simpan.ubah.sandi2.php",
                        type: 'POST',
                        cache: false,
                        data: {
                            strSandiLama: strSandiLama,
                            strSandiBaru: strSandiBaru,
                            strSandiKonfirmasi: strSandiKonfirmasi
                        },
                        success: function(data) {
                            if (data == 1) {
                                Swal.fire({
                                    title: "Sandi telah diubah",
                                    icon: "success"
                                });
                                $("#basicModal").modal("hide");
                                document.getElementById('strSandiLama').value = "";
                                document.getElementById('strSandiBaru').value = "";
                                document.getElementById('strSandiKonfirmasi').value = "";
                            } else {
                                if (data == 0) {
                                    Swal.fire({
                                        title: "Sandi gagal diubah",
                                        icon: "warning"
                                    });
                                }
                            }
                        }
                    });
                }
            }
        }

    }
</script>