<?php
if ($_SESSION['user_role'] > 1) {
    $date = date('Y-m-d');
?>
    <div class="page-header">
        <div class="page-header-left d-flex align-items-center">
            <div class="page-header-title">
                <h5 class="m-b-10 text-danger"><?= $this_on ?> ХИЧЭЭЛИЙН ЖИЛ</h5>
            </div>
            <ul class="breadcrumb">
                <li class="breadcrumb-item"><a href="/">Эхлэл</a></li>
            </ul>
        </div>
    </div>
    <div class="main-content">
        <div class="card stretch stretch-full">
            <div class="card-header">
                <h5 class="card-title">ЦАГ/ИРЦ БҮРТГЭЛ</h5>
            </div>
            <div class="card-body">
                <div class="row mb-3 p-3">
                    <div class="col-md">
                        <select class="form-control" id="turul">
                            <option value="2">Суралцагчдын ирц бүртгэл</option>
                            <option value="1">Багш, ажилтны цаг бүртгэл</option>
                        </select>
                    </div>
                    <div class="col-md">
                        <input type="date" class="form form-control mb-3" name="date" id="date_get" value="<?= $date ?>" autocompleted />
                    </div>
                    <div class="col-md-2">
                        <button class="btn btn-warning w-100" type="button" onclick="get_student()" id="show">ХАРАХ</button>
                    </div>
                </div>
                <div id="main">

                </div>
            </div>
        </div>
    </div>
    <?php require ROOT . "/pages/main-end.php"; ?>
    <div class="modal fade" id="detial" tabindex="-1" aria-labelledby="detialLabel" aria-hidden="true">
        <div class="modal-dialog modal-lg">
            <div class="modal-content">
                <div class="modal-header">
                    <h5 class="modal-title" id="detialLabel">ИРЦ БҮРТГЭЛ</h5>
                    <button type="button" class="btn-close" data-bs-dismiss="modal" aria-label="Close"></button>
                </div>
                <div class="modal-body" id="modal-body">

                </div>
            </div>
        </div>
    </div>
    <script src="https://cdn.jsdelivr.net/npm/apexcharts"></script>
    <script>
        function get_student() {
            $("#show").attr("disabled", true);
            let url = "/home/student-home";
            if ($('#turul').val() == 1) {
                url = "/home/time-home";
            }
            $.ajax({
                url: url,
                type: "POST",
                data: {
                    date: $('#date_get').val()
                },
                error: function(xhr, textStatus, errorThrown) {
                    $("#main").html("<div style='text-align: center;'>Алдаа гарлаа !</div>");
                    $("#show").removeAttr("disabled");
                },
                beforeSend: function() {
                    $('#main').html("<div class='loadText'><div class='loader'></div>Түр хүлээнэ үү ...</div>");
                },
                success: function(data) {
                    $('#main').html(data);
                    $("#show").removeAttr("disabled");
                },
                async: true
            });
        }



        function detial(id) {
            console.log(id);
            row_click(id)
            $.ajax({
                url: "/att/detial",
                type: "POST",
                data: {
                    mode: 2,
                    id: id
                },
                error: function(xhr, textStatus, errorThrown) {
                    $("#modal-body").html("<div style='text-align: center;'>Алдаа гарлаа !</div>");
                },
                beforeSend: function() {
                    $('#modal-body').html("<div style='text-align: center;'>Түр хүлээнэ үү ...</div>");
                },
                success: function(data) {
                    $('#modal-body').html(data);
                },
                async: true
            });
        }
    </script>
<?php } else echo "Хандах эрх хүрэлцэхгүй байна"; ?>