<?php defined('BASEPATH') or exit('No direct script access allowed'); ?>
<!DOCTYPE html>
<html>
  <head>
    <title>Admin &gt; Pembelian Massal</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>Pembelian Massal</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-sm-4 col-md-3 col-lg-3">
              <a class="btn btn-default btn-block" style="margin-bottom: 15px;" href="<?php echo site_url('admin/modules/mass-order/tambah-pengguna');?>" data-toggle="modal" data-target="#myModal"><i class="fa fa-user-plus"></i> Menambahkan</a>
            </div>
            <div class="col-sm-offset-2 col-sm-6 col-md-offset-5 col-md-4 col-lg-offset-5 col-lg-4">
              <form method="get" action="<?php echo site_url('admin/modules/mass-order/pengguna/1/'.$sort);?>">
                <div class="input-group" style="margin-bottom: 15px;">
                  <input type="text" class="form-control" name="search" minlength="3" maxlength="64" value="<?php echo html_escape($search);?>" placeholder="Cari pengguna..." />
                  <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('admin/modules/mass-order/hapus-pengguna','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/mass_order/pengguna/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/mass_order/pengguna/1/1'.($search ? '?search='.$search_encoded : ''));?>">Jumlah transaksi</a></li>
                  <li class="<?php echo $sort == 2 ? 'active' : '';?>"><a href="<?php echo site_url('admin/modules/mass_order/pengguna/1/2'.($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 style="width: 70px;">Total Trx</th>
                    <th style="width: 115px;">Terakhir Trx</th>
                    <th style="width: 115px;">Ditambahkan</th>
                  </tr>
                </thead>
                <tbody>
                  <?php foreach ($results as $result):?>
                  <tr id="user-<?php echo $result->us_id;?>">
                    <td class="text-center"><input type="checkbox" class="checkbox1" name="users[]" value="<?php echo $result->us_id;?>"/></td>
                    <td><a href="<?php echo site_url('admin/users/profil/'.@$result->us_username);?>"><?php echo ($result->us_verified ? '<span class="text-success" data-toggle="tooltip" data-title="Terverifikasi"><i class="fa fa-check-circle"></i></span> ' : '') . html_escape(@$result->us_name);?></a></td>
                    <td><?php echo $result->mo_total_trx;?></td>
                    <td><?php echo $result->mo_last_trx ? format_tanggal($result->mo_last_trx) : '';?></td>
                    <td><?php echo format_tanggal($result->mo_added);?></td>
                  </tr>
                  <?php endforeach;?>
                </tbody>
              </table>
            </div>
          </div>
          <div class="row" style="margin-bottom: 5px;">
            <div class="col-sm-5 col-md-3">
              <button class="btn btn-danger btn-sm" style="margin-bottom: 15px;" type="submit"><i class="fa fa-trash"></i> Hapus yang ditandai</button>
            </div>
            <div class="col-sm-7 col-md-9">
              <?php echo pagination(site_url('admin/modules/mass-order/pengguna'),$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();if(formData.indexOf('users')>0){$("#myModal").modal("show");$.ajax({type:"POST",url:$(this).attr("action"),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>