<?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('users'));
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('users/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('users/check-all' . $redir, ['class' => 'check-all-form']) ?>
        <button type="submit" name="submit" value="delete_all" class="btn btn-xs btn-danger 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="id" style="width:70px;">#</th>
                        <th data-order="username" class="both"><?= lang('username') ?></th>
                        <th data-order="name" class="both"><?= lang('name') ?></th>
                        <th data-order="email" class="both"><?= lang('email') ?></th>
                        <th data-order="phone" class="both"><?= lang('phone') ?></th>
                        <th data-order="status" class="both"><?= lang('status') ?></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->username ?></td>
                                <td><?= $data->profile->name ?></td>
                                <td><?= $data->profile->email ?></td>
                                <td><?= $data->profile->phone ?></td>
                                <td>
                                    <?= User_model::status_label($data->status) ?>
                                    <div class="table-button" style="display:none;">
                                        <a href="<?= base_url('users/update/' . $data->id . $redir) ?>" class="table-button-action" title="<?= lang('edit') ?>">
                                            <i class="fa fa-pencil"></i>
                                        </a>
                                        <a href="<?= base_url('users/delete/' . $data->id . $redir) ?>" class="table-button-action red" title="<?= lang('remove') ?>" onclick="return script.deletePrompt();">
                                            <i class="fa fa-times"></i>
                                        </a>
                                    </div>
                                </td>
                            </tr>
                        <?php endforeach; ?>
                    <?php else : ?>
                        <tr>
                            <td colspan="7" 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 users = function () {
        var the;
        return {
            init: function () {
                the = this;
                script.orderTable('{$query_pagination["order"]}');
                script.handleOrder();
            }
        };
    }();
    $(document).ready(function () {
        users.init();
    });
EOD
        , 'embed');
