<?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_data'));
Ci::set_map(Ci::$title);
$wa_str = 'https://api.whatsapp.com/send/?phone={phone}&text=Selamat+sore+Bapak/Ibu+*{name}*,%0a%0aMohon+izin+reminder+terkait+dengan+acara+Group+Customer+Appreciation+tahun+2023+yang+akan+diadakan+pada:%0a%0aHari/Tanggal+:+*Selasa,+5+Desember+2023*%0aWaktu+:+*18:00+-+21:00+WIB*%0aTempat+:+*Dua+Mutiara+Ballroom+JW+Marriott+Hotel*%0aAlamat+:+Jalan+DR+Ide+Anak+Agung+Gde+Agung+Kav+E.1.2+No.+1-2,+Kawasan+Mega+Kuningan,+Kuningan+Tim.,+Setia+Budi,+Kota+Jakarta+Selatan,+DKI+Jakarta%0aDresscode+:+L:Atasan+Putih+atau+Biru+dan+Bawahan+Formal+Gelap%0a++++++++P:Dress+Terang+Putih+atau+Biru%0aMain+Course+:+{main_course}%0a%0aNo.+Meja+:+{table}%0a%0aTerima+kasih+atas+waktu+dan+kerjasamanya.+Kami+tunggu+kehadiran+Bapak/Ibu+di+acara+kami+🙏&app_absent=0';
?>

<h1 class="page-title">
    <?= Ci::$title ?>
    <small><?= $query_pagination['total_row'] ?> Total Data</small>
</h1>
<div class="btn-header">
<!--    <a href="<?= base_url('user-data/generate-qr' . $redir) ?>" class="btn blue">
        <i class="fa fa-download"></i> Generate QR
    </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('user-data/excel') ?>" class="btn green">
        <i class="fa fa-download"></i>
        Download Excel
    </a>
    <a href="<?= base_url('user-data/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('user-data/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_data.id" style="width:70px;">#</th>
                        <th data-order="user_data.phone" class="both"><?= lang('phone') ?></th>
                        <th data-order="user_data.email" class="both"><?= lang('email') ?></th>
                        <th data-order="user_data.name" class="both"><?= lang('profile') ?></th>
<!--                        <th data-order="user_data.name" class="both"><?= lang('name') ?></th>
                        <th data-order="user_data.optic" class="both"><?= lang('optic') ?></th>
                        <th data-order="user_data.pax" class="both"><?= lang('pax') ?></th>-->
                        <th data-order="user_data.status" class="both"><?= lang('status') ?></th>
                    </tr>
                </thead>
                <tbody>
                    <?php if ($query_pagination['data']->count() > 0) : ?>
                        <?php foreach ($query_pagination['data'] as $data) : ?>
                            <?php $status = User_data_model::status_label($data->status) ?>
                            <tr>
                                <?= $pagination->check_all($data->id) ?>
                                <td style="width:70px;"><?= $query_pagination['no']++ ?></td>
                                <td><?= $data->phone ?></td>
                                <td><?= $data->email ?></td>
                                <td>
                                    <?= $data->name ?> (<?= $data->pax ?> pax)<br />
                                    <?= $data->optic ?><br />
                                    <?= $data->location ?>
                                </td>
                                <td>
                                    <?= is_array($status) ? '-' : $status ?>
                                    <div class="table-button" style="display:none;">
                                        <?php if ($data->status != User_data_model::STATUS_MAIL_SENT) : ?>
                                            <a href="<?= base_url('user-data/email/' . $data->id . $redir) ?>" class="table-button-action" title="<?= lang('email') ?>">
                                                <i class="fa fa-envelope"></i>
                                            </a>
                                        <?php endif; ?>
                                        <a href="<?= strtr($wa_str, ['{id}' => $data->id, '{name}' => urlencode($data->name), '{phone}' => '62' . $data->phone]) ?>" class="table-button-action" title="Whatsapp" target="_BLANK">
                                            <i class="fa fa-whatsapp"></i>
                                        </a>

                                        <a href="<?= base_url('user-data/update/' . $data->id . $redir) ?>" class="table-button-action" title="<?= lang('edit') ?>">
                                            <i class="fa fa-pencil"></i>
                                        </a>
                                        <a href="<?= base_url('user-data/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('user-data/import' . $redir) ?>
            <div class="modal-header">
                <button type="button" class="close" data-dismiss="modal" aria-hidden="true"></button>
                <h4 class="modal-title">Import Data</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 page_script = function () {
        var the;
        return {
            init: function () {
                the = this;
                script.orderTable('{$query_pagination["order"]}');
                script.handleOrder();
            }
        };
    }();
    $(document).ready(function () {
        page_script.init();
    });
EOD
    , 'embed');
