<?php
include "pin/header.php";
include "pin/sidenav.php";

$user_id = $_SESSION['user_id'];
$emp_id = $_SESSION['emp_id'];
$user_role = $_SESSION['user_role'];


if(isset($_GET['delete'])){
    $q = mysqli_query($db, "DELETE FROM attendance_freeze WHERE id='$_GET[delete]'");
    if($q){
        echo '<script>alert("Attendance Freeze deleted successfully!");</script>';
    }else{
        echo '<script>alert("Failed to delete!");</script>';
    }
    echo '<script>window.location.href = "attendance_freeze.php";</script>';
}


?>


<!-- ============================================================== -->
<!-- Start Page Content here -->
<!-- ============================================================== -->

<div class="content-page">
    <div class="content">
        <div class="container-fluid">

            <div class="mt-5"></div>

            <div class="row">
                <div class="col-12">
                    <div class="card">
                        <div class="card-body p-4">
                            <h4 class="header-title mt-0 mb-1 mb-4">
                                Attendance Freeze
                            </h4>

                            <table id="basic-datatable" class="table dt-responsive nowrap custom-responsive-datatable">
                                <thead>
                                    <tr>
                                        <th>ID</th>
                                        <th>Month</th>
                                        <th>Action</th>
                                    </tr>
                                </thead>

                            </table>
                            <!-- </div> -->

                        </div> <!-- end card body-->
                    </div> <!-- end card -->
                </div><!-- end col-->
            </div>
            <!-- end row-->

        </div>
    </div> <!-- content -->

</div>

<!-- ============================================================== -->
<!-- End Page content -->
<!-- ============================================================== -->



<?php
include "pin/footer.php";
?>

<script>
    $(document).ready(function() {

        // ############################### columns
            let columns = [{data: 'id'}, {data: 'month'}, {data: 'created_at'}];
        // ############################### columns

        function show_hierarchy_data() {

            // ############################### setArray
            // ############################### setArray

            $("#filter_options").html('');
            form_fields.each(function() {
                search_filter(this);
            });

            if (setArray.length > 0) {
                loadTable('#basic-datatable', 'get_from_server/attendance_freeze_get', columns, [0, 'desc'], setArray);
            } else {
                loadTable('#basic-datatable', 'get_from_server/attendance_freeze_get', columns, [0, 'desc']);
            }
            // console.log(setArray);
            setArray = [];
            // console.log(setArray);
        }

        show_hierarchy_data();
        $("#search_filter").click(show_hierarchy_data);
    });
</script>