<?php defined('BASEPATH') or exit('No direct script access allowed'); ?>
<!DOCTYPE html>
<html>
  <head>
    <title>Admin &gt; Transaksi Via Jabber</title>
    <?php include_once(VIEWPATH.'includes/head.php'); ?>
    <style type="text/css">
    nav{margin-bottom: 15px;float: right;}
    .popover-content>.list-group{margin: -9px -15px;border-radius:0;}
    .popover-content>.list-group>.list-group-item{padding:5px 8px;border-left:0;border-right:0;}
    .popover-content>.list-group>.list-group-item:first-child{border-top:0;}
    .popover-content>.list-group>.list-group-item:last-child{border-bottom:0;}

    </style>
  </head>
  <body>
    <?php include_once(VIEWPATH. 'admin/_navbar.php'); ?>
    <div class="container">
      <ul class="breadcrumb">
        <li><a href="<?php echo site_url();?>"><i class="fa fa-home"></i></a></li>
        <li><a href="<?php echo site_url('admin');?>">Admin Panel</a></li>
        <li class="active"><span>Transaksi Via Jabber</span></li>
      </ul>
      <div class="row">
        <div class="col-sm-4 col-md-3">
          <?php include(dirname(__file__).'/_sidebar.php');?>
        </div>
        <div class="col-sm-8 col-md-9">
          <div class="row">
            <div class="col-xs-4 col-sm-3 col-md-3 col-lg-2">
              <div class="dropdown">
                <button class="btn btn-default btn-block dropdown-toggle" style="margin-bottom: 15px" type="button" id="status" data-toggle="dropdown" aria-haspopup="true" aria-expanded="true">Status <i class="fa fa-chevron-down"></i></button>
                <ul class="dropdown-menu" aria-labelledby="status">
                  <li class="<?php echo $status == 'semua' ? 'active' : '';?>"><a href="<?php echo site_url('admin/modules/jabbertrx/pengguna/semua/1/'.$sort);?>">Semua</a></li>
                  <li class="<?php echo $status == 'terverifikasi' ? 'active' : '';?>"><a href="<?php echo site_url('admin/modules/jabbertrx/pengguna/terverifikasi/1/'.$sort);?>">Terverifikasi</a></li>
                  <li class="<?php echo $status == 'belum-terverifikasi' ? 'active' : '';?>"><a href="<?php echo site_url('admin/modules/jabbertrx/pengguna/belum-terverifikasi/1/'.$sort);?>">Belum Terverifikasi</a></li>
                  <li class="<?php echo $status == 'diblokir' ? 'active' : '';?>"><a href="<?php echo site_url('admin/modules/jabbertrx/pengguna/diblokir/1/'.$sort);?>">Diblokir</a></li>
                </ul>
              </div>
            </div>
            <div class="col-xs-8 col-sm-offset-3 col-sm-6 col-md-offset-5 col-md-4 col-lg-offset-6 col-lg-4">
              <form method="get" action="<?php echo site_url('admin/modules/jabbertrx/pengguna/'.$status.'/1/'.$sort);?>">
                <div class="input-group" style="margin-bottom: 15px;">
                  <input type="text" class="form-control" name="search" minlength="3" maxlength="32" value="<?php echo html_escape($search);?>" placeholder="Cari pengirim..." />
                  <span class="input-group-btn">
                    <button type="submit" class="btn btn-primary"><i class="fa fa-search"></i></button>
                  </span>
                </div>
              </form>
            </div>
          </div>
          <?php if (!$results):?>
            <div class="alert alert-warning">Tidak ada daftar pengguna</div>
          <?php else:?>
          <?php echo form_open('#','id="form-confirm"');?>
          <div class="panel panel-default">
            <div class="panel-heading">
              <div class="dropdown pull-right">
                <a id="sort" title="Menu" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false" style="font-size: 18px;color:#333;cursor:pointer;">
                  <i class="fa fa-sort"></i>
                </a>
                <ul class="dropdown-menu" aria-labelledby="sort">
                  <li class="<?php echo $sort == 0 ? 'active' : '';?>"><a href="<?php echo site_url('admin/modules/jabbertrx/pengguna/'.$status.'/1/0'.($search ? '?search='.$search_encoded : ''));?>">Tanggal ditambahkan</a></li>
                  <li class="<?php echo $sort == 1 ? 'active' : '';?>"><a href="<?php echo site_url('admin/modules/jabbertrx/pengguna/'.$status.'/1/1'.($search ? '?search='.$search_encoded : ''));?>">Jumlah pesan</a></li>
                  <li class="<?php echo $sort == 2 ? 'active' : '';?>"><a href="<?php echo site_url('admin/modules/jabbertrx/pengguna/'.$status.'/1/2'.($search ? '?search='.$search_encoded : ''));?>">Jumlah transaksi</a></li>
                  <li class="<?php echo $sort == 3 ? 'active' : '';?>"><a href="<?php echo site_url('admin/modules/jabbertrx/pengguna/'.$status.'/1/3'.($search ? '?search='.$search_encoded : ''));?>">Terakhir mengirim pesan</a></li>
                  <li class="<?php echo $sort == 4 ? 'active' : '';?>"><a href="<?php echo site_url('admin/modules/jabbertrx/pengguna/'.$status.'/1/4'.($search ? '?search='.$search_encoded : ''));?>">Terakhir melakukan transaksi</a></li>
                </ul>
              </div>
              <h3><i class="fa fa-users"></i> Daftar Pengguna</h3>
            </div>
            <div class="table-responsive">
              <table class="table table-bordered table-hover">
                <thead>
                  <tr>
                    <th class="text-center" style="width: 40px;"><input type="checkbox" id="select-all"/></th>
                    <th>Pengguna</th>
                    <th>Jabber Pengirim</th>
                    <th>Pesan</th>
                    <th>Transaksi</th>
                    <th style="width: 115px;">Ditambahkan</th>
                  </tr>
                </thead>
                <tbody>
                  <?php foreach ($results as $sender):?>
                  <tr id="sender-<?php echo $sender->ct_id;?>">
                    <td class="text-center"><input type="checkbox" class="checkbox1" name="senders[]" value="<?php echo $sender->ct_id;?>"/></td>
                    <td><a href="<?php echo site_url('admin/users/profil/'.$sender->us_id);?>"><?php echo ($sender->us_verified ? '<span class="text-success" data-toggle="tooltip" data-title="Terverifikasi"><i class="fa fa-check-circle"></i></span> ' : '') . html_escape($sender->us_name);?></a></td>
                    <td><a href="<?php echo site_url('admin/sms/kirim?phone='.urlencode($sender->ct_sender));?>" data-toggle="modal" data-target="#myModal"><?php echo $sender->ct_blocked ? '<span class="text-danger"><i data-toggle="tooltip" title="Diblokir" class="fa fa-ban"></i></span>' : ($sender->ct_verified ? '<span class="text-success"><i data-toggle="tooltip" title="Terverifikasi" class="fa fa-check"></i></span>' : '<span class="text-muted"><i data-toggle="tooltip" title="Belum terverifikasi" class="fa fa-times"></i></span>');?> <?php echo html_escape($sender->ct_sender);?></a></td>
                    <td><strong class="text-success" data-toggle="tooltip" title="Total pesan">(<?php echo $sender->ct_total_msg;?>)</strong><?php echo ($sender->ct_last_msg ? ' <span data-toggle="tooltip" title="Terakhir mengirim pesan">'.format_tanggal($sender->ct_last_msg).'</span>' : '');?></td>
                    <td><strong class="text-success" data-toggle="tooltip" title="Total transaksi">(<?php echo $sender->ct_total_trx;?>)</strong><?php echo ($sender->ct_last_trx ? ' <span data-toggle="tooltip" title="Terakhir melakukan transaksi">'.format_tanggal($sender->ct_last_trx).'</span>' : '');?></td>
                    <td><?php echo format_tanggal($sender->ct_added);?></td>
                  </tr>
                  <?php endforeach;?>
                </tbody>
              </table>
            </div>
          </div>
          <div class="row" style="margin-bottom: 5px;">
            <div class="col-sm-4">
              <div class="input-group" style="margin-bottom: 15px;">
                <select class="form-control input-sm" name="tindakan">
                  <option value="">-- Yang Ditandai --</option>
                  <option value="1">Status Terverifikasi</option>
                  <option value="2">Status Belum Terverifikasi</option>
                  <option value="3">Ubah PIN</option>
                  <option value="4">Blokir</option>
                  <option value="5">Buka Pemblokiran</option>
                  <option value="6">Hapus</option>
                </select>
                <span class="input-group-btn">
                  <button class="btn btn-primary btn-sm" type="submit">GO</button>
                </span>
              </div>
            </div>
            <div class="col-sm-8">
              <?php echo pagination(site_url('admin/modules/jabbertrx/pengguna/'.$status),$start,$total,$this->system->set['list_per_page'],'/%d/'.$sort.($search ? '?search='.$search_encoded : ''));?>
            </div>
          </div>
          <?php echo form_close();?>
          <?php endif;?>
        </div>
      </div>
    </div>
    <?php include_once(VIEWPATH.'includes/foot.php'); ?>
    <script type="text/javascript">
    $(document).ready(function(){$('#select-all').click(function(event){if(this.checked){$('.checkbox1').each(function(){this.checked=true;});}else{$('.checkbox1').each(function(){this.checked=false;});}});});
    $(document).on("submit","#form-confirm",function() {
        var formData = $(this).serialize();
        var action = $('select[name="tindakan"] option:selected').val();
        if (formData.indexOf('senders') > 0) {
            if (action == "1" || action == '2' || action == '3' || action == "4" || action == '5' || action == '6') {
                var actionUrl;
                if (action == '1') {
                  actionUrl = "<?php echo site_url('admin/modules/jabbertrx/ubah-status-pengirim/terverifikasi');?>";
                } else if (action == '2') {
                  actionUrl = "<?php echo site_url('admin/modules/jabbertrx/ubah-status-pengirim/belum-terverifikasi');?>";
                } else if (action == "3") {
                  actionUrl = "<?php echo site_url('admin/modules/jabbertrx/ubah-pin');?>";
                } else if (action == '4') {
                    actionUrl = "<?php echo site_url('admin/modules/jabbertrx/blokir-pengirim');?>";
                } else if (action == '5') {
                    actionUrl = "<?php echo site_url('admin/modules/jabbertrx/lepas-pemblokiran-pengirim');?>";
                } else if (action == '6') {
                  actionUrl = "<?php echo site_url('admin/modules/jabbertrx/hapus-pengirim');?>";
                }
                $("#myModal").modal("show");
                $.ajax({
                    type: "POST",
                    url: actionUrl,
                    data: formData,
                    success: function(data){
                        var csrf=$(data).find('[name="<?php echo $this->security->get_csrf_token_name();?>"]').val();
                        $('#form-confirm [name="<?php echo $this->security->get_csrf_token_name();?>"]').val(csrf);
                        $("#myModal .modal-content").html(data);
                    },
                    error: function() {
                        alert("Terjadi kesalahan!");
                    }
                });
            }
        }
        return false;
    });
    </script>
  </body>
</html>