<?php $operator_id = $this->session->userdata('admin')['operator_id'];
?>

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

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

<style type="text/css">
    .middle-table td{ vertical-align: middle; }
    .btn.btn-sm i, .btn-group-sm > .btn i{
        margin: 0px !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">
    <!--<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>
    <div class="kt-portlet__body">
        
            <span class="pull-right">
                <?php if (get_ap('points_add', $operator_id) == 1) { ?>
                    <a href="<?php echo base_url(); ?>points/student/add_point/<?php echo $result->id; ?>" class="btn btn-success btn-sm"><i class="fa fa-plus"></i></a>
                <?php } ?>
                <?php if (get_ap('points_deduct', $operator_id) == 1) { ?>
                    <a href="<?php echo base_url(); ?>points/student/minus_point/<?php echo $result->id; ?>" class="btn btn-success btn-sm"><i class="fa fa-minus"></i></a>
                <?php } ?>
                <?php if (get_ap('student', $operator_id) == 1) { ?>
                    <a href="<?php echo base_url(); ?>user/show/<?php echo $result->id; ?>" class="btn btn-success btn-sm"><i class="fa fa-user"></i></a>
                <?php } ?>
            </span>

        </h3>


        <div class="form_detail">


            <?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
            $full_score = 0;
            if ($score_history) {
                foreach ($score_history as $key_points => $value_points) {
                    if ($value_points->type == 2)
                        $full_score -= $value_points->points;
                    else
                        $full_score += $value_points->points;
                    //echo "<br>";
                }
            }
            ?>

            <table width="100%" >
                <tr>
                    <td>
                        <table class="table  table-bordered middle-table">
                            <tr >
                                <td rowspan="3" align="center" >
                                    <?php
//                                    if ($result->profile_image) {
//                                        if (strpos($result->profile_image, 'http') !== false) {
//                                            $profile = $result->profile_image;
//                                        } else {
//                                            $profile = base_url('assets/images/student/' . $result->profile_image);
//                                        }
//                                    } else {
                                        $profile = base_url('assets/images/student/user.png');
//                                    }
                                    ?>
                                    <img src="<?php echo $profile; ?>" width="84" alt=""></td>
                                <td><?php echo $this->lang->line('name'); ?>: <?php echo $result->username; ?></td>
                                <td>id: <?php echo $result->cid_user; ?></td>
                                <td><?php echo $this->lang->line('mobile'); ?>: <?php echo $result->phone; ?></td>
                                <!--<td rowspan="3" align="center" ><img src="<?php //echo base_url("assets/images/student/qrcode/" . $result->barcode); ?>" width="80" height="80" alt=""></td>-->
                            </tr>
                            <tr>
                                <td><?php echo $this->lang->line('email'); ?>: <?php echo $result->email; ?></td>
                                <td colspan="2"><?php echo $this->lang->line('student_tag'); ?>: <?php echo $result->tag_name2; ?></td>
                            </tr>
                            <tr>
                                <td><?php echo $this->lang->line('season_points'); ?>  : <?php echo $full_score; ?></td>
                                <td><?php echo $this->lang->line('total_points'); ?> : <?php echo $result->total_points; ?></td>
                                <td><?php echo $this->lang->line('total_balance'); ?> : <?php echo $result->total_balance; ?> </td>
                            </tr>


                        </table>
                    </td>
                </tr>


                <tr>
                    <td>
                        <table class="table  table-bordered">
                            <tr><td><?php echo $this->lang->line('points'); ?> # </td><td><?php echo $this->lang->line('student_tag'); ?></td><td><?php echo $this->lang->line('the_type'); ?> </td><td><?php echo $this->lang->line('points'); ?> </td><td><?php echo $this->lang->line('balance'); ?></td><td><?php echo $this->lang->line('category'); ?></td><td><?php echo $this->lang->line('notes'); ?></td><td><?php echo $this->lang->line('credit_date'); ?></td><td><?php echo $this->lang->line('action'); ?></td></tr>
                            <?php
                            if ($history) {
                                $s = 1;
                                foreach ($history as $key => $history_value) {

                                    $award_name = $history_value->award_name ? $history_value->award_name : "";

                                    if ($history_value->type == 1)
                                        $type = "<span class='btn btn-success btn-sm'>" . $this->lang->line('credit') . "</span>";
                                    else if ($award_name != "")
                                        $type = "<span class='btn btn-primary btn-sm'>" . $this->lang->line('debit') . "</span>";
                                    else
                                        $type = "<span class='btn btn-danger btn-sm'>" . $this->lang->line('debit') . "</span>";
                                    $category = $history_value->cname ? $history_value->cname : "";
                                    $notes = $history_value->notes_name ? $history_value->notes_name : "";
                                    $discount = $history_value->discount_name ? $history_value->discount_name : "";
                                    $memo_notes = $history_value->memo_notes ? $history_value->memo_notes : "";

                                    $tpoint = $history_value->type == 1 ? $history_value->points : " - " . $history_value->points;
                                    $tbalance = $history_value->type == 1 ? $history_value->balance : "-" . $history_value->balance;


                                    if ($history_value->upload_filename) {
                                        if (strpos($history_value->upload_filename, 'http') !== false) {
                                            $file_name = $history_value->upload_filename;
                                        } else {
                                            $file_name = base_url('uploads/students/' . $history_value->upload_filename);
                                        }
                                    }
                                    ?>
                                    <tr>
                                        <td><?php echo $s++; ?></td>
                                        <td><?php echo $history_value->tag_name2; ?></td>
                                        <td><?php echo $type; ?></td>
                                        <td><?php echo $tpoint; ?></td>
                                        <td><?php echo $tbalance; ?></td>
                                        <td><?php echo $category; ?><?php echo $discount; ?><?php echo $award_name; ?></td>
                                        <td><?php echo $notes; ?><?php echo $memo_notes; ?></td>
                                        <td><?php echo date("d-m-Y", strtotime($history_value->update_on)); ?></td>
                                        <td>
                                    <?php if ($history_value->upload_filename) { ?>
                                                <a href="<?php echo $file_name; ?>" class="btn btn-warning btn-sm" target="_new" ><i class="fa fa-paperclip"></i></a>
        <?php } ?>
        <?php if (get_ap('remove_points', $operator_id) == 1) { ?><a href="<?php echo base_url(); ?>admin/student/remove_points/<?php echo $history_value->history_id; ?>" class="btn btn-danger  btn-sm" onclick="return  confirm('are you sure?');"><i class="fa fa-trash"></i></a><?php } ?></td>
                                    </tr>
        <?php
    }
}
?>
                        </table>
                    </td>
                </tr>


            </table>


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

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