<?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_user'));
Ci::set_map(Ci::$title);
$wa_str = 'https://api.whatsapp.com/send/?phone={phone}&text=Selamat+siang+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%0a%0aDresscode+:%0a*L*+:+Atasan+Putih+atau+Biru+dan+Bawahan+Formal+Gelap%0a*P*+:+Dress+Terang+Putih+atau+Biru%0aMain+Course+:+*{main_course}*%0aNo.+Meja+:+*{table}*%0a%0aMohon+bantuan+Bapak/Ibu+untuk+*menunjukkan+QR+Code*+yang+diterima+saat+registrasi+dan+menunjukkan+*message+WA+yang+dikirimkan+sistem*.%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="javascript:void(0)" class="btn blue" data-toggle="modal" data-target="#import">
        <i class="fa fa-plus"></i>
        Import
    </a>
    <a href="<?= base_url('visitor-user/pdf') ?>" class="btn green">
        <i class="fa fa-download"></i>
        PDF
    </a>
    <a href="<?= base_url('visitor-user/excel') ?>" class="btn green">
        <i class="fa fa-download"></i>
        Download Excel
    </a>
    <a href="<?= base_url('visitor-user/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('visitor-user/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="users.id" style="width:70px;">#</th>-->
                        <th data-order="users.username" class="both"><?= lang('phone') ?></th>
                        <th data-order="user_profile.name" class="both"><?= lang('name') ?></th>
                        <th data-order="user_profile.optic" class="both"><?= lang('optic') ?></th>
<!--                     <th data-order="user_profile.email" class="both"><?= lang('email') ?></th>-->
                        <th data-order="user_profile.table" class="both" style="width:50px;"><?= lang('table') ?></th>
                        <!--<th data-order="user_profile.seat" class="both" style="width:50px;"><?= lang('seat') ?></th>-->
                        <th data-order="user_profile.info_tambahan" class="both"><?= lang('info_tambahan') ?></th>
                        <th data-order="users.created_at" class="both" colspan="2"><?= lang('date') ?></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->optic ?></td>
        <!--                    <td><?= $data->profile->email ?></td>-->
                                <td><?= $data->profile->table ?></td>
                                <!--<td><?= $data->profile->seat ?></td>-->
                                <td> <?= $data->profile->info_tambahan ?></td>
                                <td style="width:120px;"><?= $data->created_at ? date('d-m-Y', strtotime($data->created_at)) : '-' ?></td>
                                <td style="width:70px;">
                                    <?= $data->created_at ? date('H:i', strtotime($data->created_at)) : '-' ?>
                                    <div class="table-button" style="display:none;">
                                        <a href="<?= base_url('visitor-user/qr/' . $data->id . $redir) ?>" class="table-button-action" title="QR Image">
                                            <i class="fa fa-qrcode"></i>
                                        </a>
                                        <a href="<?= strtr($wa_str, ['{id}' => $data->id, '{name}' => urlencode($data->name), '{phone}' => '62' . $data->phone, '{main_course}' => $data->main_course, '{table}' => $data->table ]) ?>" class="table-button-action" title="Whatsapp" target="_BLANK">
                                            <i class="fa fa-whatsapp"></i>
                                        
                                        </a>
                                        <a href="<?= base_url('visitor-user/email/' . $data->id . $redir) ?>" class="table-button-action" title="Notify Seat Number (Email)">
                                            <i class="fa fa-envelope"></i>
                                        </a>
                                        <a href="<?= base_url('visitor-user/update/' . $data->id . $redir) ?>" class="table-button-action" title="<?= lang('edit') ?>">
                                            <i class="fa fa-pencil"></i>
                                        </a>
                                        <a href="<?= base_url('visitor-user/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="9" 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 id="import" class="modal fade" role="dialog">
    <div class="modal-dialog">
        <?= form_open_multipart('visitor-user/import?redir=' . urlencode(current_url() . url_query())) ?>
        <!-- Modal content-->
        <div class="modal-content">
            <div class="modal-header">
                <button type="button" class="close" data-dismiss="modal">&times;</button>
                <h4 class="modal-title">Import User</h4>
            </div>
            <div class="modal-body">
                <div class="form-group">
                    <?= lang('file', [], 'file', ['class' => 'control-label']) ?>
                    <?= form_upload('file', null, ['class' => 'form-control']) ?>
                </div>
            </div>
            <div class="modal-footer">
                <?= form_submit('submit', 'Upload', ['class' => 'btn btn-primary']) ?>
            </div>
        </div>
        <?= form_close() ?>
    </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');
