<!-- <Link href="https://cdn.datatables.net/fixedcolumns/4.1.0/css/fixedColumns.dataTables.min.css" /> -->
<style>
    .form-group .bootstrap-select>.dropdown-toggle {
        padding: 9px 9px !important;
        font-size: 12px !important;
        border: 1px solid #c8c8c8 !important;
        background: #fff !important;
    }

    .action_subject_addbtn {
        background: #032DA4;
        border-radius: 35px;
        color: #fff;
        padding: 5px 15px;
        border: none;
        font-size: 12px;
        cursor: pointer;
        text-decoration: none;
    }

    .custom_tble th:nth-child(1),
    .custom_tble th:nth-child(2),
    .custom_tble td:nth-child(1),
    .custom_tble td:nth-child(2) {
        background: #fff;
        z-index: 9;
    }

    .table_div {
        width: 100%;
    }

    th,
    td {
        white-space: nowrap;
    }

    .table_stu_name {
        margin: auto;
    }

    .assign_Fee_startdate .form-control {
        height: calc(2.25rem + 2px);
        padding: 9px 3px;
    }

    .assign_fee_reset .subject_addbtn {
        padding: 6px 10px;
    }

    /*START : added by Nandini*/
    .dt-buttons {
        display: block !important;
    }

    /*END OF : added by Nandini*/

    .error {
        color: red;
        padding-top: 5px;
        /* font-weight:500; */
    }
</style>
<div class="wraper responsive-width">
    <main class="long-tbl-main students_list_table" id="main">

        <div class="from-group adding-class form-group_lng form_group_twobtn">

        </div>
        <!-- admin template section -->
        <div class="admin_tempblock">
            <div class="admin_tempsec">
                <div class="admin_sec">
                    <?php
                    if (!empty($this->session->flashdata('success'))) { ?>
                        <div class="alert alert-success">
                            <a href="#" class="close" data-dismiss="alert">&times;</a>
                            <strong>Success!</strong> <?php echo $this->session->flashdata('success'); ?>
                        </div>
                    <?php
                    }
                    if (!empty($this->session->flashdata('error'))) {
                    ?>
                        <div class="alert alert-danger">
                            <a href="#" class="close" data-dismiss="alert">&times;</a>
                            <strong>Failed!</strong> <?php echo $this->session->flashdata('error'); ?>
                        </div>
                    <?php } ?>
                    <div class="subsec_sec">
                        <div class="subject_r">
                            <div class="subject_lsec">
                                <div class="col-md-6 pull-left" style="padding:0">
                                    <button onclick="history.back()" type="button" class="btn subject_addbtn bg-dark">Back</button>
                                </div>



                                <?php
                                $theExportHeader = '';
                                if (isset($school_info) && !empty($school_info)) {
                                    $courseTitle = '';
                                    $monthTitle = '';
                                    if (isset($selectedCourse) && !empty($selectedCourse)) {
                                        // echo '<pre>';
                                        $courseTitle = $selectedCourse['course_name'];
                                    }

                                    $theExportHeader = $courseTitle . ' - Class Schedule';
                                }
                                $selBatch = (isset($theBatchId) && !empty($theBatchId)) ? $theBatchId : $school_info['batch_id'];

                                $selCourseId = '';
                                $selSectionId = '';
                                $sercStdStr = '';
                                if (count($_POST) > 0) {
                                    $selCourseId = $course;
                                    $selSectionId = $section;
                                }
                                ?>

                                <!-- <div class="subject_lhead"><?= $classroom['classroom_name'] ?></div> -->
                                <div class="row align-items-center">
                                    <div class="col">
                                        <div class="subject_lhead"><?= $classroom['classroom_name'] ?></div>
                                    </div>
                                    <div class="col text-right h6 mb-0">
                                        <i class="fas fa-clock fa-spin"></i>
                                        <?= date('h:i A', strtotime($start_time)) . ' - ' . date('h:i A', strtotime($end_time)) ?>
                                    </div>
                                </div>
                                <hr class="bg-primary">
                                <form method="post" action="<?php echo base_url(); ?>admin/classroom-schedule-update/<?= $url_params ?>" id="form-filter">
                                    <input type="hidden" name="batch_id" value="<?= $theBatchId ?>">
                                    <input type="hidden" name="course_id" value="<?= $course ?>">
                                    <input type="hidden" name="section_id" value="<?= $section ?>">
                                    <div class="row col-md-7 px-0 mt-3">
                                        <div class="col">
                                            <label class="has-float-label mb-0">
                                                <input type="time" id="class_start_time" name="class_start_time" class=" form-control" value="<?= $start_time ?>" placeholder='Enter Class Starts Time' required>
                                                <span>Start Time <b class="text-danger">*</b></span>
                                            </label>
                                        </div>
                                        <div class="col pr-0">
                                            <label class="has-float-label mb-0">
                                                <input type="time" id="class_end_time" name="class_end_time" class=" form-control" value="<?= $end_time ?>" placeholder='Enter Class End Time' required>
                                                <span>End Time <b class="text-danger">*</b></span>
                                            </label>
                                        </div>
                                    </div>
                                    <?php
                                    foreach ($week_days as $wd => $week_day) {
                                    ?>

                                        <div class="card my-3">
                                            <div class="card-body py-2">
                                                <div class="row align-items-center">
                                                    <div class="col-md-2 h6 small mb-0" style="font-weight:500"> <?= $week_day['title'] ?> </div>
                                                    <div class="col-md-10">
                                                        <!-- <label class="has-float-label mb-0"> -->
                                                        <select id="subject" class="form-control selectpicker col-md-6" name="subject[<?= $week_day['id'] ?>]" data-live-search="false">
                                                            <option value="">
                                                                Select Subject
                                                            </option>
                                                            <?php

                                                            foreach ($course_subjects as $cs_key => $course_subject) {

                                                                $selected = '';
                                                                foreach ($class_schedule as $c_key => $sch) {
                                                                    if ($sch['day'] == $week_day['id']) {
                                                                        echo $sch['subject'] . ' ==> ' . $course_subject['subject_id'] . '<br>';
                                                                        if ($sch['subject'] == $course_subject['subject_id']) {
                                                                            $selected = 'selected';
                                                                        }
                                                                    }
                                                                }

                                                            ?>
                                                                <option value="<?= $course_subject['subject_id'] ?>" <?= $selected ?>>
                                                                    <?= $course_subject['subject_name'] ?>
                                                                </option>
                                                            <?php
                                                            }
                                                            ?>
                                                            <option value="0>">
                                                                <?= 'Interval' ?>
                                                            </option>
                                                        </select>
                                                        <!-- <span>Subject <b class="text-danger">*</b></span>
                                                        </label> -->
                                                    </div>

                                                </div>
                                            </div>
                                        </div>
                                    <?php
                                    }
                                    ?>
                                    <div class="col-md-7 px-0">
                                        <input type="submit" name="schedule_update" value="Save" class="btn btn-sm btn-outline-success w-100 px-0">
                                    </div>
                                </form>
                            </div>
                        </div>
                    </div>
                </div>
            </div>
            <!-- admin template section end -->
    </main>
    <!--End right-top side-->
</div>

<script defer src="<?php echo base_url(); ?>assets_admin/js/bootstrap-select.min.js"></script>
<!-- <script defer src="https://cdn.datatables.net/fixedcolumns/4.1.0/js/dataTables.fixedColumns.min.js"></script> -->
<script>
    $(document).ready(function() {

        jQuery.validator.addMethod("inputregx", function(value, element) {
            return this.optional(element) || /^[a-zA-Z0-9 -]{3,50}$/.test(value);
        }, 'Please enter alpha and numeric characters only ');

        $("#form-filter").validate({

            ignore: "input[type='text']:hidden",
            rules: {
                "filter-course": {
                    required: true,
                },
                "filter-section": {
                    required: true,
                },
                "filter-fees_type[]": {
                    required: true
                },
                "filter-route-id": {
                    required: true
                }

            },
            messages: {
                "filter-course": {
                    required: "Please Select Course  ",
                },
                "filter-section": {
                    required: "Please Select Section  ",
                }
            },
            submitHandler: function(form) {
                form.submit();
            }
        });


    });
</script>

<script>
    /* Ensure that the demo table scrolls */
    $(document).ready(function() {
        var jsTheExportHeader = '<?php echo $theExportHeader; ?>';
        var table = $('#tbl').DataTable({
            scrollY: screen.height * 0.6,
            scrollX: true,
            scrollCollapse: true,
            paging: false,
            // order: [
            //     [1, 'acs']
            // ],
            fixedColumns: {
                left: 1,
                right: 1
            },
            "dom": 'lBfrtip',
            buttons: [{
                    extend: 'pdfHtml5',
                    // orientation: 'landscape',
                    exportOptions: {
                        columns: "thead th:not(.noExport)",
                        rows: function(indx, rowData, domElement) {
                            return $(domElement).css("display") != "none";
                        },
                        stripNewlines: false,
                        stripHtml: true
                    },
                    orientation: 'landscape',
                    pageSize: 'A4',
                    // customize: function(doc) {
                    //     doc.content[1].table.widths = Array(doc.content[1].table.body[0].length + 1).join('*').split('');
                    //     // doc.defaultStyle.alignment = 'center';
                    //     doc.styles.tableHeader.alignment = 'center';
                    // }
                    // messageTop: 'The information in this table is copyright to Sirius Cybernetics Corp.'
                },
                {
                    extend: 'print',
                    exportOptions: {
                        columns: "thead th:not(.noExport)",
                        rows: function(indx, rowData, domElement) {
                            return $(domElement).css("display") != "none";
                        },
                        stripNewlines: false,
                        stripHtml: true
                    },
                },
                {
                    extend: 'excelHtml5',
                    header: true,
                    footer: true,
                    title: jsTheExportHeader,

                    exportOptions: {
                        columns: "thead th:not(.noExport)",
                        rows: function(indx, rowData, domElement) {
                            return $(domElement).css("display") != "none";
                        },
                        stripNewlines: false,
                        stripHtml: true,

                    },
                    customize: function(xlsx) {
                        var sheet = xlsx.xl.worksheets['sheet1.xml'];

                        $('row c[r^="C"]', sheet).attr('s', '2');
                    }
                }
            ],
        });
    });

    $('#filter-course').change(function() {
        var course = $('#filter-course option:selected').val();
        // alert(course);
        var divData = '';
        if (course != '' && course != 0) {

            $.ajax({
                url: "<?php echo base_url(); ?>Admin/get_section_by_course",
                method: "POST",
                data: {
                    course_id: course
                },
                dataType: "json",
                success: function(response) {
                    // console.log(response);
                    // section options code and start from here 

                    divData += "<option value='' > Select Section </option>";
                    if (response.sections != '') {
                        $.each(response.sections, function(i, sectiondata) {
                            divData += "<option value='" + sectiondata.section_id + "'>" + sectiondata.section_name + "</option>";
                        });
                    }
                    // $('#course_error_msg').text();
                    else {
                        divData += "<option value=''> -- No Section's Found --</option>";

                    }
                    $('#filter-section').empty().append(divData);

                    // section options code here End from here 

                }
            });
        } else {
            divData = "<option value=''> -- Select Section -- </option>";
            $('#filter-section').empty().append(divData);
        }
    });
</script>
<script>
    jQuery(document).ready(function() {
        jQuery(".custom_tble").clone(true).appendTo('.table_div_cover').addClass('clone');
    });
</script>