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

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

<style type="text/css">
    .btn-sm{ margin-bottom:4px; }
    .main-table  td, .main-table  th{ vertical-align: middle !important;  }
</style>

<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('points'); ?></span>
            </div>

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

<div class="kt-portlet kt-portlet--mobile">
    <form method="post" action="<?php echo base_url('points/student/view'); ?>">
        <!--<div class="form_components">-->
        <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 $title ?>
                </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('points_add', $operator_id) == 1) { ?>
                            <input type="submit" name="add_point" class="btn btn-success" value="<?php echo $this->lang->line('add') . ' ' . $this->lang->line('points'); ?>">
                        <?php } ?>
                        <?php if (get_ap('points_deduct', $operator_id) == 1) { ?>
                            <input type="submit" name="discount_point" class="btn btn-warning" value="<?php echo $this->lang->line('points_deduct'); ?>">
                        <?php } ?>
                        <?php if (get_ap('awards', $operator_id) == 1) { ?>
                            <input type="submit" name="award_point" class="btn btn-warning" value="<?php echo $this->lang->line('awards'); ?>">
                        <?php } ?>
                    </div>
                </div>
            </div>
        </div>

        <div class="kt-portlet__body">
            <div class="table-responsive">

                <?php if ($this->session->userdata('message')) { ?>
                    <div class="alert alert-success alert-dismissible">
                        <button type="button" class="close" data-dismiss="alert">&times;</button>
                        <?php echo $this->session->userdata('message'); ?>
                    </div>
                <?php } ?>

                <?php if ($this->session->userdata('error')) { ?>
                    <div class="alert alert-danger alert-dismissible">
                        <button type="button" class="close" data-dismiss="alert">&times;</button>
                        <?php echo $this->session->userdata('error'); ?>
                    </div>
                <?php } ?>
                <form method="post" action="<?php echo base_url('admin/student/view'); ?>">

                    <table class=" table table-striped table-bordered main-table" id="datatable">
                        <thead>
                            <tr>
                                <th><input type="checkbox" class="select_all" ></th>

                                <th><?php echo $this->lang->line('name'); ?></th>

                                <th><?php echo $this->lang->line('mobile'); ?></th>
                                <th><?php echo $this->lang->line('student_tag'); ?></th>
                                <th><?php echo $this->lang->line('total_points'); ?></th>
                                <th><?php echo $this->lang->line('total_balance'); ?></th>
                                <th width="150"><?php echo $this->lang->line('action'); ?></th>
                            </tr>
                        </thead>
                        <tbody>
                            <!-- <?php
                            if ($results) {
                                $s = 1;
                                foreach ($results as $result) {
                                    ?>
                                                              <tr>
                                                                <td><input type="checkbox" name="user[]" class="user_id" value="<?php echo $result->id; ?>"></td>
                                                                <td><img src="<?php echo base_url('assets/images/student/qrcode/' . $result->barcode); ?>" width="80" alt=""> </td>
                                                                <td><?php echo $result->name; ?> </td>
                                                                 <td><img src="<?php echo base_url('assets/images/student/' . $result->profile_image); ?>" width="80" alt=""> </td>
                                                                <td><?php echo $result->student_id; ?></td>
                                                                <td><?php echo $result->mobile; ?> </td>
                                                                <td><?php echo $result->total_points; ?> </td>
                                                                <td><?php echo $result->total_balance; ?> </td>
                                                              
            
                                                                <td>
            
            
                                    <?php
                                    $type_archived = $type == 1 ? 0 : 1;
                                    if ($result->archive_status == 0) {
                                        ?>
                                        <?php if (get_ap('student_add_archived', $operator_id) == 1) { ?>
                                                                                                    <a href="<?php echo base_url('admin/student/archived/' . $result->id . '/' . $type_archived); ?>" title='<?php echo $this->lang->line('make_a_archived'); ?>' class="btn btn-warning btn-sm" onclick="return  confirm('are you sure?');"><i class="fa fa-archive"></i></a>
                                        <?php } ?>
                                    <?php } else { ?>
                                        <?php if (get_ap('student_add_un_archived', $operator_id) == 1) { ?>
                                                                                                    <a href="<?php echo base_url('admin/student/archived/' . $result->id . '/' . $type_archived); ?>" title="<?php echo $this->lang->line('make_a_un_archived'); ?>" class="btn btn-warning btn-sm" onclick="return  confirm('are you sure?');"><i class="fa fa-undo"></i></a>
                                        <?php } ?>
                                    <?php } ?>
            
            
                                    <?php if (get_ap('student_history', $operator_id) == 1) { ?>
                                                                                    <a href="<?php echo base_url(); ?>admin/student/history/<?php echo $result->id; ?>" class="btn btn-success btn-sm"><i class="fa fa-list"></i></a>
                                    <?php } ?>
                                    <?php if (get_ap('student_edit', $operator_id) == 1) { ?>
                                                                                    <a href="<?php echo base_url(); ?>admin/student/edit/<?php echo $result->id; ?>" class="btn btn-primary btn-sm"><i class="fa fa-pencil"></i></a>
                                    <?php } ?>
                                    <?php if (get_ap('student_delete', $operator_id) == 1) { ?>
                                                                                    <a href="<?php echo base_url(); ?>admin/student/delete/<?php echo $result->id; ?>" class="btn btn-danger btn-sm" onclick="return  confirm('are you sure?');"><i class="fa fa-trash"></i></a>
                                    <?php } ?>
            
                                                                  
                                                                   
                                                                </td>
                                                              </tr>
                                    <?php
                                }
                            }
                            ?> -->
                        </tbody>
                    </table>
                </form>
            </div>
        </div>
    </form>
    <!--</div>-->
</div>

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

<script type="text/javascript">


    $(document).ready(function (e) {
        var base_url = "<?php echo base_url(); ?>"; // You can use full url here but I prefer like this
        $('#datatable').DataTable({
            "pageLength": 50,
            "lengthMenu": [[50, 100, 500, -1], [50, 100, 500, "All"]],
            "serverSide": true,
            "columnDefs": [{orderable: false, targets: [0, 6]}],
            "ajax": {
                url: base_url + 'points/student/get_student_ajax/<?php echo $type; ?>',
                type: 'POST'
            },
        }); // End of DataTable
    }); // End Document Ready Function

    $(document).on("click", ".select_all", function () {
        // alert();
        if ($(this).prop("checked")) {
            $(".user_id").prop("checked", true);
        } else {
            $(".user_id").prop("checked", false);
        }
    });
</script>

