<?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('doorprize'));
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('doorprize/excel') ?>" class="btn green">
        <i class="fa fa-download"></i>
        Download Excel
    </a>
    <a href="javascript:void(0)" class="btn blue" data-toggle="modal" data-target="#basic">
        <i class="fa fa-plus"></i>
        Import
    </a>
    <a href="<?= base_url('doorprize/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('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">
            <style type="text/css">
                .table-small tr td {
                    padding:3px !important;
                    vertical-align: middle;
                }
            </style>
            <table class="table table-hover table-bordered sort table-small">
                <thead>
                    <tr>
                        <?= $pagination->check_all_header() ?>
                        <th data-order="id" style="width:30px;text-align:center;">#</th>
                        <th data-order="nama" class="both"><?= lang('nama') ?></th>
                        <th data-order="slug" class="both"><?= lang('slug') ?></th>
                        <th data-order="total" class="both"><?= lang('total') ?></th>
                        <th data-order="gambar" class="both"><?= lang('gambar') ?></th>
                        <th data-order="slug" class="both"><?= lang('url') ?></th>
                        <th data-order="user_doorprize.user_id" class="both"><?= lang('count_user') ?></th>
                    </tr>
                </thead>
                <tbody>
                    <?php if ($query_pagination['data']->count() > 0) : ?>
                        <?php foreach ($query_pagination['data'] as $data) : ?>
                            <?php
                            $imgurl = base_url($data->gambar ? '../img/uploads/' . $data->gambar : '../img/icon.png');
                            $nama = $data->nama2 ? $data->nama2 : $data->nama;
                            $location = $data->location ? $data->location : 'general';
                            ?>
                            <tr>
                                <?= $pagination->check_all($data->id) ?>
                                <td style="width:30px;text-align:center;"><?= $query_pagination['no']++ ?></td>
                                <td><?= $data->nama ?></td>
                                <td><?= $data->slug ?></td>
                                <td><?= $data->total ?></td>
                                <td><?= show_file($data->gambar, '../img/uploads') ?></td>
                                <td>
                                    <a href="<?= base_url('../doorprize/index/' . $location . '/' . $data->slug) ?>" target="_blank"><?= base_url('../doorprize/index/' . $location . '/' . $data->slug) ?></a>
                                </td>
                                <td>
                                    <?= $data->count_user ?>
                                    <div class="table-button" style="display:none;">
                                        <a href="<?= base_url('user-doorprize/index/' . $data->id . $redir) ?>" class="table-button-action" title="<?= lang('user_doorprize', ['{name}' => $data->nama]) ?>">
                                            <i class="fa fa-users"></i>
                                        </a>
                                        <a href="<?= base_url('doorprize/update/' . $data->id . $redir) ?>" class="table-button-action" title="<?= lang('edit') ?>">
                                            <i class="fa fa-pencil"></i>
                                        </a>
                                        <a href="<?= base_url('doorprize/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="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>
<div class="modal fade" id="basic" tabindex="-1" role="basic" aria-hidden="true">
    <div class="modal-dialog">
        <div class="modal-content">
            <?= form_open_multipart('doorprize/import' . $redir) ?>
            <div class="modal-header">
                <button type="button" class="close" data-dismiss="modal" aria-hidden="true"></button>
                <h4 class="modal-title">Import Doorprize</h4>
            </div>
            <div class="modal-body">
                <div class="form-group" style="padding: 0px 15px;">
                    <div class="form-group" style="padding: 0px 15px;">
                        <label class="control-label">File Excel</label>
                        <?= form_upload('file', '', ['class' => 'form-control']) ?>
                    </div>
                </div>
                <div class="modal-footer">
                    <button type="button" class="btn dark btn-outline" data-dismiss="modal">Cancel</button>
                    <?= form_submit('submit', 'Submit', ['class' => 'btn blue']) ?>
                </div>
                <?= form_close() ?>
            </div>
            <!-- /.modal-content -->
        </div>
        <!-- /.modal-dialog -->
    </div>
</div>
<?php
Ci::set_script(<<<EOD
     var doorprize = function () {
        var the;
        return {
            init: function () {
                the = this;
                script.orderTable('{$query_pagination["order"]}');
                script.handleOrder();
                $('.img-view').click(function () {
                    var url = $(this).data('img');
                    var img = $('<img>', {src: url, class: 'img img-responsive'});
                    $('#modal-title').html($(this).data('nama'));
                    $('#modal-body').append(img);
                    $('#metronic-modal').modal('show');
                    $('#metronic-modal').on('hide.bs.modal', function () {
                        $('#modal-title').empty();
                        $('#modal-body').empty();
                    });
                });
            }
        };
    }();
    $(document).ready(function () {
        doorprize.init();
    });
EOD
    , 'embed');
