<?php defined('BASEPATH') or exit('No direct script access allowed'); ?>
<!DOCTYPE html>
<html>
  <head>
    <title>Pengaturan Deposit</title>
    <?php include_once(VIEWPATH. 'includes/head.php'); ?>
  </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/pengaturan');?>">Pengaturan</a></li>
        <li class="active"><span>Deposit</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="panel panel-default">
            <div class="panel-heading">
              <h3><i class="fa fa-cog"></i> Deposit</h3>
            </div>
            <div class="panel-body">
              <?php echo form_open();?>
                <div class="form-group">
                  <label>Siapa yang boleh melakukan deposit?</label>
                  <div>
                    <div class="radio-inline"><label style="font-weight: normal;"><input type="radio" name="status" value="1" <?php echo ($set->status == 1 ? 'checked="checked"' : '');?>/> Semua member</label></div>
                    <div class="radio-inline"><label style="font-weight: normal;"><input type="radio" name="status" value="2" <?php echo ($set->status == 2 ? 'checked="checked"' : '');?>/> Hanya member terverifikasi</label></div>
                    <div class="radio-inline"><label style="font-weight: normal;"><input type="radio" name="status" value="0" <?php echo ($set->status == 0 ? 'checked="checked"' : '');?>/> Tidak semua</label></div>
                  </div>
                </div>
                <div class="form-group">
                  <label for="max_balance" class="control-label">Limit Saldo Akun</label>
                  <input type="number" class="form-control" name="max_balance" id="max_balance" value="<?php echo set_value('max_balance', $max_balance);?>" required="required" placeholder="5000000"/>
                  <p class="help-block">Jika sisa saldo akun melebihi limit maka tidak bisa melakukan deposit atau menerima transferan saldo dari pengguna lain.</p>
                </div>
                <div class="form-group">
                  <label class="control-label">Metode Pembayaran</label>
                  <?php
                    foreach ($this->payment->get() as $payment):
                    if ($payment->key == 'balance')
                      continue;
                    ?>
                    <div class="checkbox" style="margin-top: 2px;margin-bottom: 2px;">
                      <label style="font-weight: normal;"><input type="checkbox" name="payments[]" value="<?php echo $payment->key;?>" <?php echo @in_array($payment->key, $set->payments) ? 'checked="checked"' : '';?>/> <?php echo ($payment->status == 'on' ? $payment->nama : '<span class="text-muted">'.$payment->nama.' (Tidak aktif)</span>');?></label>
                    </div>
                  <?php endforeach;?>
                </div>
                <div class="form-group">
                  <label for="min" class="control-label">Minimal</label>
                  <input type="number" class="form-control" name="min" id="min" value="<?php echo $set->min;?>" required="required" placeholder="10000"/>
                </div>
                <div class="form-group">
                  <label for="max" class="control-label">Maksimal</label>
                  <input type="number" class="form-control" name="max" id="max" value="<?php echo $set->max;?>" required="required" placeholder="1000000"/>
                </div>
                <div class="form-group">
                  <label for="multiple" class="control-label">Kelipatan</label>
                  <input type="number" class="form-control" name="multiple" id="multiple" value="<?php echo $set->multiple;?>" required="required" placeholder="10000"/>
                </div>
                <div class="form-group">
                  <label for="range" class="control-label">Range harga unik</label>
                  <input type="text" class="form-control" name="range" id="range" value="<?php echo html_escape($set->range);?>" maxlength="12" required/>
                  <p class="help-block">Range harga unik untuk deposit sebaiknya lebih besar dari range harga unik transaksi.</p>
                </div>
                <?php
                  $waktu = array();
                  foreach ($set->waktu as $t_key=>$t_val) {
                    if ($t_val)
                      $waktu[] = str_replace(["mon", "tue", "wed", "thu", "fri", "sat", "sun"], ["sen", "sel", "rab", "kam", "jum", "sab", "min"], $t_key) . $t_val;
                  }
                ?>
                <div class="form-group">
                  <label>Hari dan Jam Deposit</label>
                  <div class="input-group">
                    <input type="text" class="form-control" name="waktu" id="waktu" value="<?php echo set_value('waktu', implode('|', $waktu));?>" required="required" maxlength="255"/>
                    <span class="input-group-addon">
                      <a id="waktu-edit" href="#" title="Edit"><i class="fa fa-edit"></i></a>
                    </span>
                  </div>
                  <p class="help-block">Hari dan Jam yang diperbolehkan untuk deposit</p>
                </div>
                <div class="form-group">
                  <label for="time" class="control-label">Jangka Waktu</label>
                  <input type="number" class="form-control" name="time" id="time" value="<?php echo html_escape($set->time);?>" required="required" placeholder="8"/>
                  <p class="help-block">Maksimal jam pembayaran deposit, apabila melebihi jangka waktu ini dan member belum melakukan deposit maka dianggap kadaluarsa atau tidak berlaku lagi.</p>
                </div>
                <div class="form-group">
                  <label for="process" class="control-label">Pemrosesan</label>
                  <select class="form-control" name="process" id="process">
                    <option value="auto" <?php echo $set->process == 'auto' ? 'selected="selected"' : '';?>>Otomatis</option>
                    <option value="semiauto" <?php echo $set->process == 'semiauto' ? 'selected="selected"' : '';?>>Semi otomatis</option>
                  </select>
                  <p class="help-block">
                    <ul class="list-unstyled">
                      <li><strong>Otomatis</strong>: Setelah pembayaran diterima maka sistem akan memproses secara otomatis dan saldo akan ditambahkan ke akum member.</li>
                      <li><strong>Semi otomatis</strong>: Setelah pembayaran diterima maka administrator akan mengkonfirmasikan pembayaran tersebut dan kemudian mengambil tindakan menyetui atau menolak deposit.</li>
                    </ul>
                  </p>
                </div>
                <div class="form-group">
                  <label>Kirimkan pemberitahuan SMS ke nomor HP user?</label>
                  <div>
                    <div class="radio-inline"><label style="font-weight: normal;"><input type="radio" name="sms" value="1" <?php echo (@$set->sms == 1 ? 'checked="checked"' : '');?>/> Ya</label></div>
                    <div class="radio-inline"><label style="font-weight: normal;"><input type="radio" name="sms" value="0" <?php echo (@$set->sms == 0 ? 'checked="checked"' : '');?>/> Tidak</label></div>
                  </div>
                </div>
                <div class="alert alert-info">
                  <h5>Pemberitahuan Administrator</h5>
                  <div class="form-group">
                    <label class="control-label">Email</label>
                    <input type="email" class="form-control" name="email_notification" id="email_notification" value="<?php echo html_escape($set->email_notification);?>" maxlength="64"/>
                  </div>
                  <div class="form-group">
                    <label class="control-label">SMS</label>
                    <input type="number" class="form-control" name="sms_notification" id="sms_notification" value="<?php echo html_escape($set->sms_notification);?>" maxlength="13"/>
                  </div>
                  <p class="help-block">Pemberitahun untuk Administrator tentang pembayaran deposit yang sudah diterima.</p>
                </div>
                <div>
                  <button type="submit" class="btn btn-primary" name="submit" value="save">Simpan</button>
                </div>
              <?php echo form_close();?>
            </div>
          </div>
        </div>
      </div>
    </div>
    <?php include_once(VIEWPATH.'includes/foot.php'); ?>
    <script type="text/javascript">
    $("#waktu-edit").click(function() {
      var hari = ["Senin", "Selasa", "Rabu", "Kamis", "Jumat", "Sabtu", "Minggu"];
      var content = '<div class="modal-header"><button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">&times;</span></button><h4 class="modal-title"><i class="fa fa-clock-o"></i> Hari dan Jam Deposit</h4></div>';
      content += '<div class="modal-body"><div class="row">';
      for (d = 0; d < hari.length; d++) {
        content += '<div class="col-sm-6" style="'+(d == (hari.length - 1) ? '' : 'margin-bottom: 15px')+'"><label>'+hari[d]+'</label><div class="input-group"><span class="input-group-addon"><i class="fa fa-clock-o"></i></span><input type="text" class="form-control" name="off_'+hari[d].substr(0,3).toLowerCase()+'" value="" placeholder="06:00-11:59,13:00-16:59,dst..." maxlength="59"/></div></div>';
      }
      content += '</div></div>';
      content += '<div class="modal-footer"><button class="btn btn-primary" type="button" id="waktu-save-btn"><i class="fa fa-check"></i> Simpan</button>&nbsp;<button class="btn btn-default" data-dismiss="modal" type="button"><i class="fa fa-remove"></i> Batal</button></div>';
      $("#myModal").modal("show");
      var modalContent = $("#myModal .modal-content").html(content);
      var data = $("#waktu").val();
      if (data != "") {
        var days = data.split("|");
        if (days.length > 0) {
          for (i = 0; i < days.length; i++) {
            $(modalContent).find('input[name="off_'+days[i].substr(0, 3)+'"]').val(days[i].substr(3));
          }
        }
      }
      return false;
    });
    $(document).on("click", "#waktu-save-btn", function() {
      var days = ["sen", "sel", "rab", "kam", "jum", "sab", "min"];
      var waktu = [];
      for (e = 0; e < days.length; e++) {
        var t = $('input[name="off_'+days[e]+'"]').val();
        if (t) {
          waktu.push(days[e] + t);
        }
      }
      $("#waktu").val(waktu.join("|"));
      $('#myModal').removeClass("in").hide();
      $("body").removeClass("modal-open").removeAttr("style");
      $('.modal-backdrop').remove();
      return false;
    });
    </script>
  </body>
</html>