<?= $this->extend('layouts/admin') ?>
<?= $this->section('content') ?>
<?= $this->include('templates/admin/header'); ?>
<?= form_open(current_url(), $forms['attributes'], $forms['hiddens']) ?>
<table class="table table-bordered table-hover table-striped indexTable ">
  <?php foreach ($fields as $field) : ?>
    <tr>
      <td nowrap style="background-color:#e8ebe9; width:10%; text-align:right; padding-right:20px;">
        <?= getFieldLabel_AuthHelper($field,$fieldRules) ?>
      </td>
      <td style="text-align:left; padding-left:20px;">
        <?= getFieldForm_AuthHelper($field,is_null(old($field))?DEFAULT_EMPTY:old($field),$fieldFormOptions) ?>
        <?= validation_show_error($field); ?>
      </td>
    </tr>
  <?php endforeach; ?>
  <tr><td valign="bottom" colspan="2" style="text-align:center;"><?= form_submit('', '입력', array("class" => "btn btn-outline btn-primary")); ?></td></tr>
</table>
<?= form_close(); ?>
<?php if(session()->getFlashdata('error')):?><?= session()->getFlashdata('error') ?><?php endif?>
<?= $this->include('templates/admin/footer'); ?>
<script>
$(document).ready(function() {
  $(function() {
    $('#selectKey').click(function(e) {
      // console.log(document.getElementsByName('id'));
      if(document.getElementsByName('id')[0].value==''){
        alert('계정을 입력하셔야 합니다. ex)test@example.com');
        return false;
      }
      if(document.getElementsByName('authkey')[0].value==''){
        alert("인증키를 입력하셔야 합니다. ex)abdc2342");
        return false;
      }      
      $.ajax({
        type: 'get',
        url: '<?= base_url() . '/admin/cloudflare/account/selectkey' ?>',
        data: $('form').serialize(),
        success: function(msg) {
          var uid_select = document.getElementById('uid_select');
          var buffers = msg.split(/\n/);
          for(var i=0; i<buffers.length-1; i++){
            var option = document.createElement("option");
            var datas = buffers[i].split(/:/);
            option.textContent=datas[1];
            option.value=datas[0];
            uid_select.appendChild(option);
          }
          alert('키를 선택하시기 바랍니다.');
        },
        error: function(msg) {
          alert($msg);
        }
      });
      return false;
    });
  });
});
</script>
<?= $this->endSection() ?>