
<?php $this->load->view('site/layout'); ?>
<link href="<?php echo base_url() ?>public/plugins/custom/datatables/datatables.bundle.css" rel="stylesheet" type="text/css" />

<link href="<?php echo base_url() ?>public/css/custom_css.css" rel="stylesheet" type="text/css" />
<style>
    .select2_plug{
        width: 100%;
    }
    .alert.alert-light .alert-text hr{
        border-top-color: #ccc;
    }
    .rtl .dt-buttons{
        float: left;
    }
</style>

<?php $this->load->view('site/navbar'); ?>
<div class="kt-content  kt-grid__item kt-grid__item--fluid kt-grid kt-grid--hor" id="kt_content">
    <!-- begin:: Content Head -->
    <div class="kt-subheader  kt-grid__item" id="kt_subheader">
        <div class="kt-container  kt-container--fluid ">
            <div class="kt-subheader__main">
                <h3 class="kt-subheader__title"><a href="<?php echo base_url() ?>Dashboard/"><?php echo $this->lang->line('dashboard'); ?></a></h3>
                <span class="kt-subheader__separator kt-subheader__separator--v"></span>
                <span class="kt-subheader__desc"><?php echo $this->lang->line('products'); ?></span>
            </div>

        </div>
    </div>
</div>
<!-- 
        <div class="row">
     <div class="col-md-12">
<div  style="float:right">

        </div>   </div>
    </div> -->


<div class="kt-container  kt-container--fluid  kt-grid__item kt-grid__item--fluid" >
    <button class="btn btn-primary mb-3" onclick="toggle_filter()"><?= $this->lang->line('show_hide_filter') ?></button>
    <div class="alert alert-light alert-elevate" role="alert" id="filter_container">
        <div class="alert-text">
            <form method="post" action="" >
                <div class="row">
                    <div class="col-md-6">
                        <?php if (in_array('username', $show_fields)) { ?>
                            <div class="form-group row">  
                                <lable class="col-2 col-form-label"><?php echo $this->lang->line('name') ?></lable>
                                <div class="col-9">
                                    <select multiple name="username[]" class="topnav form-control select2_plug" >
                                        <?php foreach ($username as $value) { ?>
                                            <option value="<?php echo $value->username; ?>"><?php echo $value->username; ?></option>
                                        <?php } ?>
                                    </select> 
                                </div>
                            </div>
                        <?php } ?>
                        <?php if (in_array('cid_user', $show_fields)) { ?>
                            <div class="form-group row">
                                <lable class="col-2 col-form-label"><?php echo $this->lang->line('civil-no') ?></lable> 
                                <div class="col-9">
                                    <select multiple name="civil_id[]" class="select2_plug">
                                        <?php foreach ($username as $value) { ?>
                                            <option value="<?php echo $value->cid_user; ?>"><?php echo $value->cid_user; ?></option>
                                        <?php } ?>
                                    </select> 
                                </div>
                            </div>
                        <?php } ?>
                        <?php if (in_array('country', $show_fields)) { ?>
                            <div class="form-group row">
                                <lable class="col-2 col-form-label"><?php echo $this->lang->line('nationality') ?></lable> 
                                <div class="col-9">
                                    <select multiple name="nationality" class="select2_plug">
                                        <?php foreach ($nationality as $value) { ?>
                                            <option value="<?php
                                            if ($this->session->userdata('language') == 'english') {
                                                echo $value->english;
                                            } else {
                                                echo $value->arabic;
                                            }
                                            ?>"><?php
                                                        if ($this->session->userdata('language') == 'english') {
                                                            echo $value->english;
                                                        } else {
                                                            echo $value->arabic;
                                                        }
                                                        ?></option>
                                        <?php } ?>
                                    </select> 
                                </div>
                            </div>
                        <?php } ?>
                    </div>
                    <div class="col-md-6">
                        <?php if (in_array('city', $show_fields)) { ?>
                            <div class="form-group row">
                                <label class="col-2 col-form-label"><?php echo $this->lang->line('region') ?></label> 
                                <div class="col-9">
                                    <select multiple name="region[]" class="select2_plug">
                                        <?php foreach ($region as $value) { ?>
                                            <option value="<?php
                                            if ($this->session->userdata('language') == 'english') {
                                                echo $value->english;
                                            } else {
                                                echo $value->arabic;
                                            }
                                            ?>"><?php
                                                        if ($this->session->userdata('language') == 'english') {
                                                            echo $value->english;
                                                        } else {
                                                            echo $value->arabic;
                                                        }
                                                        ?></option>
                                        <?php } ?>
                                    </select> 
                                </div>
                            </div> 
                        <?php } ?>
                        <div class="form-group row">
                            <lable class="col-2 col-form-label"><?php echo $this->lang->line('status') ?></lable> 
                            <div class="col-9">
                                <select multiple name="status[]" class="select2_plug">
                                    <option value="0" ><?php echo $this->lang->line('active') ?></option>
                                    <option value="1"><?php echo $this->lang->line('not-active') ?></option>
                                </select> 
                            </div>
                        </div>
                        <?php if (in_array('sex', $show_fields)) { ?>
                            <div class="form-group row">
                                <lable class="col-2 col-form-label"><?php echo $this->lang->line('sex') ?></lable> 
                                <div class="col-9">
                                    <select multiple name="sex[]" class="select2_plug">
                                        <option value="<?php echo $this->lang->line('male') ?>" ><?php echo $this->lang->line('male') ?></option>
                                        <option value="<?php echo $this->lang->line('female') ?>" ><?php echo $this->lang->line('female') ?></option>
                                    </select> 
                                </div>
                            </div>
                        <?php } ?>
                        <div class="form-group row">
                            <lable class="col-2 col-form-label"><?php echo $this->lang->line('date') ?></lable> 
                            <div class="col-9">
                                <input type="text" class="form-control" name="start_expiry" id="start_expiry" value="<?= $this->input->post() ? $this->input->post('start_expiry') : '' ?>">
                            </div>
                            <div class="col-1" style="padding-left: 0px;padding-right: 0px">
                            <a onclick="clear_date()" class="btn btn-light btn-text-primary btn-hover-text-primary font-weight-bold"><?= $this->lang->line('clear') ?></a>
                        </div>
                        </div>
                    </div>
                </div>
                <div class="row" >
                    <div  class="col-md-6">
                        <div class="form-group">
                            <button class="btn btn-primary" ><?php echo $this->lang->line('search') ?></button> 
                        </div>
                    </div>
                </div>
            </form>

        </div>
    </div>
</div>
<div class="kt-portlet kt-portlet--mobile">
    <?php if ($this->session->flashdata('msg')) { ?>
        <div class="alert alert-success">
            <a href="#" class="close" data-dismiss="alert" aria-label="close" title="close">×</a>
            <?= $this->session->flashdata('msg') ?>
        </div>
    <?php } ?>
    <div class="kt-portlet__head kt-portlet__head--lg">
        <div class="kt-portlet__head-label">
            <span class="kt-portlet__head-icon">
                <i class="kt-font-brand flaticon2-line-chart"></i>
            </span>
            <h3 class="kt-portlet__head-title">
                <?php echo $this->lang->line('the-students'); ?>
            </h3>
        </div> <div class="kt-portlet__head-toolbar">
            <div class="kt-portlet__head-wrapper">
                <div class="kt-portlet__head-actions">
                    &nbsp;
                    <?php if (get_ap('student_add', $this->operator_id)) { ?>
                        <a href="<?= base_url() ?>/<?= $this->thispage ?>/add/" class="btn btn-brand btn-elevate btn-icon-sm">
                            <i class="la la-plus"></i>
                            <?php echo $this->lang->line('add-a-member') ?>
                        </a>
                    <?php } ?>
                </div>
            </div>
        </div>
    </div>
    <div class="kt-portlet__body">

        <!--begin: Datatable -->
        <table class="table table-bordered table-hover" id="list_table" > <!-- style="display: inline-block;overflow-x: scroll" -->
            <thead>
                <tr>
                    <th><?php echo $this->lang->line('sno') ?></th>
                    <?php if (in_array('username', $show_fields)) { ?>
                        <th><?php echo $this->lang->line('the-name') ?></th>
                    <?php } ?>
                    <?php if (in_array('cid_user', $show_fields)) { ?>
                        <th><?php echo $this->lang->line('civil-no') ?></th>
                    <?php } ?>
                    <?php if (in_array('phone', $show_fields)) { ?>
                        <th><?php echo $this->lang->line('mobile') ?></th>
                    <?php } ?>
<!--   <th><?php echo $this->lang->line('status') ?></th>  -->
                    <?php if (in_array('country', $show_fields)) { ?>
                        <th ><?php echo $this->lang->line('nationality') ?></th>
                    <?php } ?>
                    <?php //if (in_array('city', $show_fields)) { ?>
    <!--<th><?php //echo $this->lang->line('region')      ?></th>-->
                    <?php //} ?>
                    <th ><?php echo $this->lang->line('register') ?></th>
                    <!--  <th ><?php echo $this->lang->line('invoices') ?></th>  -->
                    <!-- <th ><?php echo $this->lang->line('absent') ?></th> -->
                    <th ><?php echo $this->lang->line('action'); ?></th>

            </thead>
            <tbody>     <?php
                $count = 1;
                foreach ($all_groups as $row) {
                    ?>

                    <tr>
                        <td><?php echo $count++; ?></td>
                        <?php if (in_array('username', $show_fields)) { ?>
                            <td><?= $row['username']; ?></td>
                        <?php } ?>
                        <?php if (in_array('cid_user', $show_fields)) { ?>
                            <td><?= $row['cid_user']; ?></td>
                        <?php } ?>
                        <?php if (in_array('phone', $show_fields)) { ?>
                            <td style="direction: ltr;"><?= $row['phone_code'].  $row['phone']; ?></td>
                        <?php } ?>
           <!--<td><?php
                        if ($row['stop'] == '1')
                            echo '<span class="label label-danger">' . $this->lang->line('off') . '</span>';
                        else
                            echo '<span class="label label-success">' . $this->lang->line('continuous') . '</span>';
                        ?></td>-->
                        <?php if (in_array('country', $show_fields)) { ?>
                            <td><?= $row['nationality']; ?> </td>
                        <?php } ?>
                    <!--<td><?//= $row['region']; ?> </td>-->

                        <td><?= date("Y/m/d", $row['since_time_register']); ?> </td>
            <!--  <td> </td>  -->

                        <td> 
                            <?php
                            //$controller_path = dirname(__DIR__, 3);
                            // if (file_exists($controller_path . '/controllers/absent')) {
                            ?>
    <!--                                <a href="<?//= base_url('' . $this->thispage . '/show_absent/' . $row['id']) ?>" class="btn btn-sm btn-clean btn-icon btn-icon-md" title="show absent">
                                    <i class="fa fa-file"></i></a>-->
                            <?php // }   ?>
                            <?php if (get_ap('student_profile', $this->operator_id)) { ?>
                                <a href="<?= base_url('' . $this->thispage . '/show/' . $row['id']) ?>" class="btn btn-sm btn-clean btn-icon btn-icon-md" title="show details">
                                    <i class="fa fa-eye"></i></a>
                            <?php } ?>
                            <?php if (get_ap('student_block', $this->operator_id)) { ?>
                                <?php if ($row['block'] == 0) { ?>
                                    <a onclick="block_dialog(<?php echo $row['id'] ?>)" class="btn btn-sm btn-clean btn-icon btn-icon-md" title="<?= $this->lang->line('block') ?>">
                                        <i class="fas fa-user-alt-slash text-danger"></i></a>
                                <?php } else { ?>
                                    <a onclick="show_block_reason('<?php echo $row['block_reason'] ?>')" class="btn btn-sm btn-clean btn-icon btn-icon-md" title="<?= $this->lang->line('show') . ' ' . $this->lang->line('block_reason') ?>">
                                        <span class="label label-danger label-inline mr-2"><?= $this->lang->line('blocked') ?></span></a>
                                    <a onclick="unblock(<?php echo $row['id'] ?>)" class="btn btn-sm btn-clean btn-icon btn-icon-md" title="<?= $this->lang->line('unblock') ?>">
                                        <i class="fas fa-user-check text-success"></i></a>
                                    <?php
                                }
                            }
                            ?>

                            <?php if (get_ap('student_edit', $this->operator_id)) { ?>

                                <a href="<?= base_url('' . $this->thispage . '/edit/' . $row['id']) ?>" class="btn btn-sm btn-clean btn-icon btn-icon-md" title="Edit">
                                    <i class="la la-edit"></i>
                                </a>
                            <?php } ?>
                            <?php if (get_ap('student_del', $this->operator_id)) { ?>

                                <a onclick="alert_box(<?php echo $row['id'] ?>)" class="btn btn-sm btn-clean btn-icon btn-icon-md" title="Delete">
                                    <i class="la la-trash"></i>
                                </a>
                            <?php } ?>
                        </td>
                    </tr><?php } ?>
            </tbody>
        </table>

        <!--end: Datatable -->
    </div>
</div>
</div>


<div class="modal fade" id="exampleModal" tabindex="-1" role="dialog" aria-labelledby="exampleModalLabel" aria-hidden="true">
    <div class="modal-dialog" role="document">
        <div class="modal-content">
            <div class="modal-header">
                <h5 class="modal-title" id="exampleModalLabel"><?= $this->lang->line('block_student') ?></h5>
                <button type="button" class="close" data-dismiss="modal" aria-label="Close">
                    <i aria-hidden="true" class="ki ki-close"></i>
                </button>
            </div>

            <form action="<?= base_url('User/block') ?>" method="post" >
                <div class="modal-body">
                    <div class="form-group row">
                        <label for="example-email-input" class="col-2 col-form-label"> <?php echo $this->lang->line('block_reason') ?></label>
                        <div class="col-10">
                            <textarea rows="3" class="form-control" name="block_reason"></textarea>
                        </div>
                    </div>
                    <input type="hidden" name="user_id" id="user_id" />

                </div>
                <div class="modal-footer">
                    <button type="button" class="btn btn-light-primary font-weight-bold" data-dismiss="modal">Close</button>
                    <button type="submit" class="btn btn-primary font-weight-bold">Block</button>
                </div> 
            </form>

        </div>
    </div>
</div>

<div class="modal fade" id="block_reason_modal" tabindex="-1" role="dialog" aria-labelledby="exampleModalLabel" aria-hidden="true">
    <div class="modal-dialog" role="document">
        <div class="modal-content">
            <div class="modal-header">
                <h5 class="modal-title" id="exampleModalLabel"><?= $this->lang->line('block_student') ?></h5>
                <button type="button" class="close" data-dismiss="modal" aria-label="Close">
                    <i aria-hidden="true" class="ki ki-close"></i>
                </button>
            </div>

            <div class="modal-body">
                <span id="block_reason"/>
            </div>
            <div class="modal-footer">
                <button type="button" class="btn btn-light-primary font-weight-bold" data-dismiss="modal">Close</button>
            </div>
        </div>
    </div>
</div>

<?php $this->load->view('site/footer_2'); ?>

   <!--  <script src="<?php echo base_url() ?>public/plugins/global/plugins.bundle.js" type="text/javascript"></script>
    <script src="<?php echo base_url() ?>public/js/scripts.bundle.js" type="text/javascript"></script> -->

<!--end::Global Theme Bundle -->

<!--begin::Page Vendors(used by this page) -->
<!-- <script src="<?php echo base_url() ?>public/plugins/custom/datatables/datatables.bundle.js" type="text/javascript"></script> -->

<!--end::Page Vendors -->

<!--begin::Page Scripts(used by this page) -->
<!--  <script src="<?php echo base_url() ?>public/js/pages/crud/datatables/basic/basic.js" type="text/javascript"></script> -->
<script>function clear_date() {
        $("#start_expiry").val('');
    }
</script>
<script>
    $("#filter_container").hide();
    $(".select2_plug").select2();
    function alert_box(id) {
        var result = confirm("Are You Confirm!")
        if (result) {
            window.location.href = "<?= base_url('' . $this->thispage . '/del/') ?>" + id;
        }
    }
    function toggle_filter() {
        $("#filter_container").toggle();
        $(".select2_plug").select2();
    }
    function block_dialog(id) {
        $("#user_id").val(id);
        $("#exampleModal").modal('show');
    }

    function unblock(id) {
        var result = confirm("Are You Sure you want to unblock this student!")
        if (result) {
            window.location.href = "<?= base_url('' . $this->thispage . '/unblock/') ?>" + id;
        }
    }
    function show_block_reason(reason) {
        $("#block_reason").text(reason);
        $("#block_reason_modal").modal('show');
    }

    $(function () {
        $("#list_table").DataTable({dom: 'Bfrtip',
            destroy: true,
            buttons: [
                {
                    extend: 'excelHtml5',
                    charset: 'UTF-16LE',
                    fieldSeparator: '\t',
                    bom: true
                },
                {
                    extend: 'csvHtml5',
                    charset: 'UTF-16LE',
                    fieldSeparator: '\t',
                    bom: true
                },
                {
                    extend: 'pdfHtml5',
                    charset: 'UTF-16LE',
                    fieldSeparator: '\t',
                    bom: true
                },
                {
                    extend: 'print',
                    autoPrint: false,
                    footer: true
                }

            ]
        });
//            buttons: [
//                'copyHtml5',
//                'excelHtml5',
//                'csvHtml5',
//                'pdfHtml5'
//            ]
    });


</script>