<?php defined('BASEPATH') or exit('No direct script access allowed');?>
<?php echo form_open($form_action,'id="form"');?>
  <input type="hidden" name="tindakan" value="ubah_pin" />
  <div class="table-responsive">
    <table class="table table-bordered">
      <thead>
        <tr>
          <th style="width: 120px;">Pengirim</th>
          <th style="width: 120px;">PIN Baru</th>
        </tr>
      </thead>
      <tbody>
        <?php foreach ($results as $result):?>
        <tr id="sender-<?php echo $result->ct_id;?>">
          <td style="vertical-align: middle;"><?php echo $result->ct_blocked ? '<span class="text-danger"><i data-toggle="tooltip" title="Diblokir" class="fa fa-ban"></i></span>' : ($result->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($result->ct_sender);?></td>
          <td>
            <input type="hidden" name="senders[]" value="<?php echo $result->ct_id;?>" />
            <div class="form-group has-feedback" style="margin-bottom: 0;">
              <input type="number" class="form-control input-sm pin" name="pin[<?php echo $result->ct_id;?>]" value="<?php echo html_escape(@$this->input->post("pin[$result->ct_id]"));?>" min="1000" max="9999" required="required"/>
              <span style="display: none;" class="glyphicon form-control-feedback" aria-hidden="true"></span>              
            </div>
          </td>
        </tr>
        <?php endforeach;?>
      </tbody>
    </table>
  </div>
  <div class="form-group" style="margin-bottom:0">
    <div class="pull-right">
      <button type="submit" class="btn btn-primary"><i class="fa fa-check"></i> Simpan</button>
      &nbsp;
      <a href="<?php echo current_url();?>" data-dismiss="modal" class="btn btn-default"><i class="fa fa-remove"></i> Batal</a>
    </div>
    <div class="clearfix"></div>
  </div>
<?php echo form_close();?>
<script type="text/javascript">$(document).on('change keyup paste','.pin',function(){var pin=parseInt($(this).val());var container=$(this).parent();var icon=$(this).next();if(pin>=1000&&pin<=9999){container.removeClass('has-error');container.addClass('has-success');icon.removeClass("glyphicon-remove");icon.addClass("glyphicon-ok");icon.show();var next=container.parent().parent().next();if(next.length){next.find('.pin').focus();}else{$('#form button[type="submit"]').focus();}}else{if(!container.hasClass('has-error')){container.removeClass('has-success');container.addClass('has-error');icon.removeClass("glyphicon-ok");icon.addClass("glyphicon-remove");icon.show();}}});$(document).on('submit','#form',function(){if($(this).find('.has-error').length){alert('Pastikan semua PIN sudah benar.');return false;}else{return true;}});</script>
