<?php
/*
 * *************************************************
 * Copyright (C) 2021 Earworks.                    *
 * Codeigniter Project Template Modification       *
 * Please contact our email for more information : *
 * contact@earworks.co.id                          *
 * *************************************************
 */

defined('BASEPATH') OR exit('No direct script access allowed');
Ci::set_title(lang('absen'));
Ci::set_map(Ci::$title);
?>
<h1 class="page-title">
    <?= Ci::$title ?>
    <small><?= $query_pagination['total_row'] ?> Total Data</small>
</h1>
<div class="btn-header">
<!--    <a href="<?= base_url('absen/generate-qr' . $redir) ?>" class="btn blue">
        <i class="fa fa-download"></i> Generate QR
    </a>-->
    <a href="<?= base_url('absen/create' . $redir) ?>" class="btn blue">
        <i class="fa fa-plus"></i> <?= lang('add', ['{title}' => Ci::$title]) ?>
    </a>
</div>

<div class="portlet light">
    <div class="portlet-body">
        <?= $pagination->create_forms($query_pagination) ?>
        <?= form_open('absen/check-all' . $redir, ['class' => 'check-all-form']) ?>
        <button type="submit" name="submit" value="delete_all" class="btn red btn-xs check-all-confirm" style="display:none;" onclick="return script.deletePrompt();">
            <i class="fa fa-times"></i> Delete All
        </button>
        <div class="table-responsive">
            <table class="table table-hover table-bordered sort">
                <thead>
                    <tr>
                        <?= $pagination->check_all_header() ?>
                        <th data-order="absen.id" style="width:70px;">#</th>
                        <th data-order="absen.nama" class="both"><?= lang('nama') ?></th>
                        <th class="both"><?= lang('user_absen') ?></th>
                        <th data-order="absen.slug" class="both"><?= lang('link') ?></th>
                        <th data-order="visitor_absen.visitor_id" class="both"><?= lang('count_visitor') ?></th>
                    </tr>
                </thead>
                <tbody>
                    <?php if ($query_pagination['data']->count() > 0) : ?>
                        <?php foreach ($query_pagination['data'] as $data) : ?>
                            <tr>
                                <?= $pagination->check_all($data->id) ?>
                                <td style="width:70px;"><?= $query_pagination['no']++ ?></td>
                                <td><?= $data->nama ?></td>
                                <td>
                                    <ul>
                                        <?php $user_absen = User_absen_model::get_dbo()->where('absen_id', $data['id'])->get(); ?>
                                        <?php if ($user_absen->count() > 0) : ?>
                                            <?php foreach ($user_absen as $relation) : ?>
                                                <li><?= $relation->user->profile->name ?></li>
                                            <?php endforeach; ?>
                                        <?php else : ?>
                                            <li>#</li>
                                        <?php endif; ?>
                                    </ul>
                                </td>
                                <td>
                                    <a href="<?= base_url("../home/screen/{$data->slug}") ?>" target="_blank">
                                        <?= base_url("../home/screen/{$data->slug}") ?>
                                    </a>
                                </td>
                                <td>
                                    <?= $data->count_visitor ?>
                                    <div class="table-button" style="display:none;">
        <!--                                        <a href="<?= base_url('absen/qr/' . $data->id . $redir) ?>" class="table-button-action" title="<?= lang('history') ?>">
                                            <i class="fa fa-qrcode"></i>
                                        </a>-->
                                        <a href="<?= base_url('visitor-absen/index/' . $data->id . $redir) ?>" class="table-button-action" title="<?= lang('history') ?>">
                                            <i class="fa fa-clock-o"></i>
                                        </a>
                                        <a href="<?= base_url('absen/excel/' . $data->id . $redir) ?>" class="table-button-action" title="Download Excel">
                                            <i class="fa fa-download"></i>
                                        </a>
                                        <a href="<?= base_url('absen/update/' . $data->id . $redir) ?>" class="table-button-action" title="<?= lang('edit') ?>">
                                            <i class="fa fa-pencil"></i>
                                        </a>
                                        <a href="<?= base_url('absen/delete/' . $data->id . $redir) ?>" class="table-button-action red" onclick="return script.deletePrompt();" title="<?= lang('remove') ?>">
                                            <i class="fa fa-times"></i>
                                        </a>
                                    </div>
                                </td>
                            </tr>
                        <?php endforeach; ?>
                    <?php else: ?>
                        <tr>
                            <td colspan="5" style="text-align: center;">
                                Data tidak tersedia
                            </td>
                        </tr>
                    <?php endif; ?>
                </tbody>
            </table>
        </div>
        <?= form_close() ?>
        <div class="pagination-wrapper">
            <?= $pagination->create_links(); ?>
        </div>
    </div>
</div>
<?php
Ci::set_script(<<<EOD
     var absen = function () {
        var the;
        return {
            init: function () {
                the = this;
                script.orderTable('{$query_pagination["order"]}');
                script.handleOrder();
            }
        };
    }();
    $(document).ready(function () {
        absen.init();
    });
EOD
    , 'embed');
