<?php defined('BASEPATH') or exit('No direct script access allowed'); ?>
<!DOCTYPE html>
<html>
  <head>
    <title>Produk &gt; <?php echo html_escape($this->system->produk->{$produk_key}->nama);?></title>
    <?php include_once(VIEWPATH. 'includes/head.php'); ?>
    <style type="text/css">
    .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><a href="<?php echo site_url('admin/produk');?>">Produk</a></li>
        <li class="active"><span><?php echo html_escape($this->system->produk->{$produk_key}->nama);?></span></li>
      </ul>
      <div class="row">
        <div class="col-sm-4 col-md-3">
          <?php
          $params = array(array(
            'title' => 'Produk',
            'links' => array()
          ));
          foreach($this->system->produk as $pro_key=>$pro_val) {
              $params[0]['links'][] = array($pro_val->nama, site_url('admin/produk/browse/'.$pro_key), null, $pro_key == $produk_key ? true : false);
          }
          echo sidebar_menu($params);
          ?>
        </div>
        <div class="col-sm-8 col-md-9">
          <div class="row">
            <div class="col-sm-6 col-md-4 col-lg-3">
              <a class="btn btn-default btn-block" style="margin-bottom: 15px;" data-toggle="modal" data-target="#myModal" href="<?php echo site_url('admin/produk/tambah-provider/'.$produk_key);?>"><i class="fa fa-plus"></i> Tambah <?php echo html_escape($this->system->produk->{$produk_key}->form->provider->label);?></a>
            </div>
            <div class="col-sm-6 col-md-offset-4 col-md-4 col-lg-offset-6 col-lg-3">
              <a class="btn btn-danger btn-block" style="margin-bottom: 15px;" data-toggle="modal" data-target="#myModal" href="<?php echo site_url('admin/produk/kosongkan-provider/'.$produk_key);?>"><i class="fa fa-trash"></i> Hapus semua</a>
            </div>
          </div>
          <?php if (!$providers):?>
          <div class="alert alert-warning">Tidak ada <?php echo html_escape($this->system->produk->{$produk_key}->form->provider->label);?></div>
          <?php else:?>
          <?php echo form_open(site_url('admin/produk/hapus-provider/'.$produk_key),'id="form-confirm"');?>
          <div class="panel panel-default">
            <div class="panel-heading">
              <h3><?php echo $this->system->produk->{$produk_key}->mini_icon;?> <?php echo html_escape($this->system->produk->{$produk_key}->nama);?></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 style="width: 73px;">Kode</th>
                    <th><?php echo html_escape($this->system->produk->{$produk_key}->form->provider->label);?></th>
                    <th>Validasi No. HP</th>
                    <th>Total <?php echo html_escape($this->system->produk->{$produk_key}->form->voucher->label);?></th>
                    <!--<th style="width: 165px;">Harga Markup</th>-->
                    <th style="width: 39px; text-align: center;"><i class="fa fa-ellipsis-h"></i></th>
                  </tr>
                </thead>
                <tbody>
                  <?php foreach ($providers as $provider):?>
                  <tr id="provider-<?php echo $provider->op_id;?>">
                    <td class="text-center"><input type="checkbox" class="checkbox1" name="providers[]" value="<?php echo $provider->op_id;?>" <?php echo $provider->total_vouchers == 0 ? 'checked="checked"' : '';?>/></td>
                    <td><?php echo $provider->op_kode;?></td>
                    <td><a href="<?php echo site_url('admin/produk/browse/'.$provider->op_produk.'/'.$provider->op_slug);?>"><?php echo html_escape($provider->op_nama);?></a></td>
                    <td><?php echo get_validator($provider->op_id, $this->produk_model->get_validator());?></td>
                    <td><?php echo $provider->total_vouchers;?></td>
                    <td class="text-center">
                      <button type="button" class="btn btn-default btn-xs" data-container="body" data-toggle="popover" data-placement="left" data-html="true" data-content="<?php echo html_escape('<div class="list-group"><a data-toggle="modal" data-target="#myModal" class="list-group-item" href="' .
                        site_url('admin/produk/edit-provider/'.$provider->op_id) .
                        '"><i class="fa fa-pencil"></i> Edit</a><a data-toggle="modal" data-target="#myModal" class="list-group-item" href="' .
                        site_url('admin/produk/hapus-provider/'.$provider->op_produk.'/'.$provider->op_id) .
                        '"><span class="text-danger"><i class="fa fa-remove"></i> Hapus</span></a></div>');?>" data-trigger="focus">
                        <i class="fa fa-edit"></i>
                      </button>
                    </td>
                  </tr>
                  <?php endforeach;?>
                </tbody>
              </table>
            </div>
          </div>
          <div class="row" style="margin-bottom: 20px;">
            <div class="col-sm-5 col-md-3">
              <button class="btn btn-danger btn-block btn-sm" type="submit" name="delete" value="delete"><i class="fa fa-trash"></i> Hapus yang ditandai</button>
            </div>
          </div>
          <?php echo form_close();?>
          <?php endif;?>
        </div>
      </div>
    </div>
    <?php include_once(VIEWPATH.'includes/foot.php'); ?>
    <script>
    $(document).on("submit","#form-confirm", function() {
      var formData = $(this).serialize();
      if (formData.indexOf('providers') > 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;
    });
    $(document).ready(function(){$('#select-all').click(function(event){if(this.checked){$('.checkbox1').each(function(){this.checked = true;});}else{$('.checkbox1').each(function(){this.checked=false;});}});});
    </script>
  </body>
</html>