<?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('visitor_absen'));
Ci::set_map(lang('absen') . ' (' . $absen->nama . ')', 'absen/index');
Ci::set_map(Ci::$title);
?>

<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="user_profile.name" class="both" style="text-align:center;"><?= lang('nama_user') ?></th>
                        <th data-order="visitor_profile.name" class="both"  style="text-align:center;"><?= lang('nama_visitor') ?></th>
                          <th data-order="visitor_absen.souvenir" class="both"  style="text-align:center;"><?= lang('souvenir') ?></th>
                        <th colspan="2" data-order="visitor_absen.created_at" class="both" style="text-align:center;"><?= lang('created_at') ?></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><?= $data->nama_user ?></td>
                                <td><?= $data->nama_visitor ?></td>
                                <td><?= $data->souvenir == 1 ? 'Yes' : 'No' ?></td>
                                <td><?= $data->created_at ? date('d-m-Y', strtotime($data->created_at)) : '-' ?></td>
                                <td>
                                    <?= $data->created_at ? date('H:i', strtotime($data->created_at)) : '-' ?>
                                    <div class="table-button" style="display:none;">
                                        <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 page_script = function () {
        var the;
        return {
            init: function () {
                the = this;
                script.orderTable('{$query_pagination["order"]}');
                script.handleOrder();
                console.log('asd');
            }
        };
    }();
    $(document).ready(function () {
        page_script.init();
    });
EOD
        , 'embed');
