<?= $this->extend('layouts/front') ?>
<?= $this->section('content') ?>
<link href="/css/front/content.css" media="screen" rel="stylesheet" type="text/css" />
<div id="content">
  <div><?= html_entity_decode($viewDatas['currentCategory']->head) ?></div>
  <div class="top"><?= $this->include('templates/front/index_head') ?></div>
  <?= form_open(current_url() . '/batchjob', $viewDatas['forms']['attributes'], $viewDatas['forms']['hiddens']) ?>
  <table class="table table-hover">
    <thead>
      <tr>
        <th>#</th>
        <?php foreach ($viewDatas['fields'] as $field) : ?><?= getFieldIndex_Column_BoardHelper($field, $viewDatas) ?><?php endforeach ?>
        <th>@</th>
      </tr>
    </thead>
    <tbody>
      <?php $cnt = 0 ?>
      <?php foreach ($viewDatas['entitys'] as $entity) : ?>
        <tr id="<?= $entity->getPrimaryKey() ?>" <?= $entity->status != DEFAULTS['STATUS'] ? 'class="table-danger" rowcolor="red"' : 'rowcolor="red"' ?> onClick="indexRowCheckBoxToggle(this)">
          <td nowrap>
            <!-- 사용자가 자신의 작성한것인지 확인되면 update 가능-->
            <?php if ($viewDatas[SESSION_NAMES['ISLOGIN']] && $entity->user_uid == $viewDatas['auth'][AUTH_FIELDS['ID']]) : ?>
              <?= anchor(current_url() . '/update/' . $entity->getPrimaryKey() . '?category=' . $viewDatas['currentCategory']->getPrimaryKey(), $viewDatas['total_count'] - (($viewDatas['page'] - 1) * $viewDatas['per_page'] + $cnt), ["target" => "_self"]) ?>
            <?php else : ?>
              <?= $viewDatas['total_count'] - (($viewDatas['page'] - 1) * $viewDatas['per_page'] + $cnt) ?>
            <?php endif ?>
          </td>
          <?php foreach ($viewDatas['fields'] as $field) : ?>
            <td><?= getFieldIndex_Row_BoardHelper($field, $entity, $viewDatas) ?></td>
          <?php endforeach ?>
          <td>
            <!-- 사용자가 자신의 작성한것인지 확인되면 delete 가능-->
            <?php if ($viewDatas[SESSION_NAMES['ISLOGIN']] && $entity->user_uid == $viewDatas['auth'][AUTH_FIELDS['ID']]) : ?>
              <?= anchor(current_url() . '/delete/' . $entity->getPrimaryKey() . '?category=' . $viewDatas['currentCategory']->getPrimaryKey(), ICONS['DELETE'], ["class" => "btn btn-sm btn-danger btn-circle", "target" => "_self"]) ?>
            <?php endif ?>
          </td>
        </tr>
        <?php $cnt++ ?>
      <?php endforeach ?>
    </tbody>
  </table>
  <div class="bottom">
    <!-- 사용자가 쓰기권한이 있는지 확인-->
    <?php if (isRole_CommonHelper($viewDatas['currentRoles'], $viewDatas['currentCategory'], 'iswrite')) : ?>
      <?= anchor(current_url() . '/insert?category=' . $viewDatas['currentCategory']->getPrimaryKey(), '입력', ["class" => "btn btn-sm btn-primary btn-circle", "target" => "_self"]) ?>
    <?php endif ?>
    <?= $viewDatas['pagination'] ?>
  </div>
  <?= form_close() ?>
  <div><?= html_entity_decode($viewDatas['currentCategory']->tail) ?></div>
</div>
<?= $this->endSection() ?>