<?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('user_doorprize') . ': ' . (($doorprize) ? $doorprize->nama : null));
Ci::set_map(lang('doorprize'), 'doorprize/index');
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('user-doorprize/excel') ?>" class="btn green">
        <i class="fa fa-download"></i>
        Download Excel
    </a>
</div>
<div class="portlet light">
    <div class="portlet-body">
        <?= $pagination->create_forms($query_pagination) ?>
        <?= form_open('user-doorprize/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>#</th>
                        <th data-order="user_profile.name" class="both" style="text-align: center;"><?= lang('nama_anggota') ?></th>
                        <th data-order="doorprize.nama" class="both" style="text-align: center;"><?= lang('nama_doorprize') ?></th>
                       <th data-order="user_doorprize.created_at" class="both" colspan="2" style="text-align: center;"><?= lang('date/time') ?></th>
                    </tr>
                </thead>
                <tbody>
                    <?php if ($query_pagination['data']->count() > 0) : ?>
                        <?php foreach ($query_pagination['data'] as $data) : ?>
                            <?php $time = strtotime($data->created_at); ?>
                            <tr>
                                <?= $pagination->check_all($data->doorprize_id . '|' . $data->user_id) ?>
                                <td style="width:70px;"><?= $query_pagination['no']++ ?></td>
                                <td><?= $data->nama_anggota ?></td>
                                <td> <?= $data->nama_doorprize ?></td>
                                <td style="text-align: center;"><?= date('d/m/y', $time) ?></td>
                                <td style="text-align: center;">
                                    <?= date('H:i', $time) ?>
                                    <div class="table-button" style="display:none;">
                                        <a href="<?= base_url('user-doorprize/delete/' . $data->doorprize_id . '/' . $data->user_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="6" 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 user_doorprize = function () {
        var the;
        return {
            init: function () {
                the = this;
                script.orderTable('{$query_pagination["order"]}');
                script.handleOrder();
            }
        };
    }();
    $(document).ready(function () {
        user_doorprize.init();
    });
EOD
        , 'embed');
