<?php defined('BASEPATH') or exit('No direct script access allowed'); ?>
<!DOCTYPE html>
<html>
  <head>
    <title>Produk</title>
    <?php include_once(VIEWPATH. 'includes/head.php'); ?>
    <style type="text/css">
    .panel-icon{margin:0;padding:0;height:200px;position:relative;overflow: hidden;}
    .form-upload{top:10px;right:10px;left:10px;position:absolute;text-align:right;display:none;}
    .btn-file{position:relative;overflow:hidden;}
    .btn-file input[type=file]{position:absolute;top:0;right:0;min-width:100%;min-height:100%;font-size:100px;text-align:right;filter:alpha(opacity=0);opacity:0;outline:none;background:white;cursor:inherit;display:block;}
    .panel-icon:hover>.form-upload{display:block;}
    </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>Produk</span></li>
      </ul>
      <div class="row">
        <div class="col-sm-8 col-md-9">
          <div class="row">
            <div class="col-sm-6 col-md-4" style="margin-bottom: 15px;" >
              <a class="btn btn-default btn-block" data-toggle="modal" data-target="#myModal" href="<?php echo site_url('admin/produk/tambah-produk');?>"><i class="fa fa-plus"></i> Produk Baru</a>
            </div>
            <div class="col-sm-6 col-md-4" style="margin-bottom: 15px;">
              <a class="btn btn-default btn-block" data-toggle="modal" href="<?php echo site_url('admin/produk/urutkan-produk');?>"><i class="fa fa-sort"></i> Urutkan</a>
            </div>
          </div>
        </div>
        <div class="col-sm-4 col-md-3">
          <div class="row">
            <div class="col-xs-12" style="margin-bottom: 15px;">
              <a id="l_clear" class="btn btn-danger btn-block" data-toggle="modal" data-target="#myModal" href="<?php echo site_url('admin/produk/kosongkan-produk');?>" title="Kosongkan semua produk"><i class="fa fa-trash"></i> Kosongkan Semua</a>
            </div>
          </div>
        </div>
      </div>
      <div class="row">
        <?php foreach ($this->system->produk as $pr_key=>$pr_val) {
            $total = $this->produk_model->count($pr_key);
        ?>
        <div class="col-sm-4 col-md-3">
          <div class="panel panel-default" id="<?php echo $pr_key;?>">
            <div class="panel-heading" style="white-space: nowrap; overflow: hidden;">
              <h3>
                <a class="pull-right" href="<?php echo site_url('admin/produk/edit-produk/'.$pr_key);?>" data-toggle="modal" data-target="#myModal"><i class="fa fa-cog" data-toggle="tooltip" data-title="Pengaturan"></i></a>
                <a href="<?php echo site_url('admin/produk/browse/'.$pr_key);?>"><?php echo @$pr_val->mini_icon.' ' . $pr_val->nama;?></a>
              </h3>
            </div>
            <div class="panel-icon">
              <img src="<?php echo (file_exists(FCPATH.'assets/'.$pr_key.'.png') ? base_url('assets/'.$pr_key.'.png') : base_url('assets/produk-default.png')) . ($this->input->get('ikon') == $pr_key ? '?r='.time() : '');?>" class="img-responsive" style="margin: 0 auto;"/>
              <div class="form-upload">
                <?php echo form_open_multipart('admin/produk/upload-ikon-produk/'.$pr_key);?>
                  <label class="btn btn-default btn-xs btn-file" data-toggle="tooltip" data-title="Ubah ikon, 260x220 <= 500kb" data-placement="left">
                     <i class="fa fa-image"></i><input type="file" name="ikon" style="display: none;" accept=".png, image/png"/>
                  </label>
                <?php echo form_close();?>
              </div>
            </div>
            <ul class="list-group">
              <li class="list-group-item"><?php echo html_escape($this->system->produk->{$pr_key}->form->provider->label);?> <span class="badge" data-toggle="tooltip" data-title="Total operator" data-placement="left"><?php echo $total['providers'];?></span></li>
              <li class="list-group-item"><?php echo html_escape($this->system->produk->{$pr_key}->form->voucher->label);?> <span class="badge" data-toggle="tooltip" data-title="Total voucher" data-placement="left"><?php echo $total['vouchers'];?></span></li>
              <li class="list-group-item">Transaksi <span class="badge" data-toggle="tooltip" data-title="Total transaksi sukses" data-placement="left"><?php echo $total['trx'];?></span></li>
              <li class="list-group-item">Pendapatan <span class="badge" data-toggle="tooltip" data-title="Total pendapatan kotor" data-placement="left"><?php echo format_uang($total['gross_income']);?></span></li>
            </ul>
            <div class="panel-footer">
              <div class="row">
                <div class="col-xs-6">
                  <a class="btn btn-danger btn-sm btn-block" <?php echo (!in_array($pr_key, array('pulsa','paket_internet','token_pln','voucher_game')) ? 'href="'.site_url('admin/produk/hapus-produk/'.$pr_key).'" data-toggle="modal" data-target="#myModal"' : 'href="#" disabled="disabled"');?>><i class="fa fa-times"></i> Hapus</a>
                </div>
                <div class="col-xs-6">
                  <?php if ($pr_val->status == 'on'):?>
                  <a class="btn btn-success btn-sm btn-block" href="<?php echo site_url('admin/produk/nonaktifkan-produk/'.$pr_key);?>"><i class="fa fa-toggle-on"></i> Aktif</a>
                  <?php else:?>
                  <a class="btn btn-default btn-sm btn-block" href="<?php echo site_url('admin/produk/aktifkan-produk/'.$pr_key);?>"><i class="fa fa-toggle-off"></i> Nonaktif</a>
                  <?php endif;?>
                </div>
              </div>
            </div>
          </div>
        </div>
        <?php } ?>
      </div>
    </div>
    <?php include_once(VIEWPATH.'includes/foot.php'); ?>
    <script>$(document).on('change',':file',function(){$(this).parent().parent().submit();});</script>
  </body>
</html>