<?php defined('BASEPATH') or exit('No direct script access allowed'); ?>
<?php init_head(); ?>

<?php
$CI = &get_instance();

// Determine whether to show Export button only when there is data
$CI->db->from(db_prefix().'coi_disclosures');

// Respect permissions: if user only has view_own, count only own records
if (staff_cant('view', 'coi_disclosure') && staff_can('view_own', 'coi_disclosure')) {
    $CI->db->where('staff_id', get_staff_user_id());
}

$hasData = $CI->db->count_all_results() > 0;
?>

<div id="wrapper">
  <div class="content">
    <div class="row">


 <div class="col-md-12 tw-mb-3">
                  <h4 class="tw-my-0 tw-font-bold tw-text-xl">
                    <?php echo _l('coi_disclosure'); ?></h4>
                 <br>
             <div class="_buttons tw-mb-2">
  <?php if (staff_can('create', 'coi_disclosure')) { ?>
                  <a href="<?php echo admin_url('coi_disclosure/create'); ?>" class="btn btn-primary">
                    <i class="fa fa-plus"></i> <?php echo _l('coi_disclosure_new'); ?>
                  </a>
                <?php } ?>

              <?php if ($hasData) { ?>
                  <a class="btn btn-success" href="<?php echo admin_url('coi_disclosure/export_excel'); ?>">
                    <i class="fa fa-file-excel-o"></i> Export Excel
                  </a>
                <?php } ?>
                </div>
                
            </div>





        
      <div class="col-md-12">
        <div class="panel_s">
          <div class="panel-body">

           

            <hr class="hr-panel-heading" />

            <?php
              $table_data = [];
              $table_data[] = _l('id');
              $table_data[] = _l('name');
              $table_data[] = _l('staff_id'); // if you prefer "Staff ID" text: replace with 'Staff ID'
              $table_data[] = _l('department');
              $table_data[] = 'Yes Count';
              $table_data[] = _l('date'); // signed date
              $table_data[] = _l('date_created');
            ?>

            <?php render_datatable($table_data, 'coi-disclosure'); ?>

          </div>
        </div>
      </div>
    </div>
  </div>
</div>

<?php init_tail(); ?>

<script>
$(function () {
  initDataTable(
    '.table-coi-disclosure',
    '<?php echo admin_url('coi_disclosure/table'); ?>',
    undefined,
    undefined,
    undefined,
    [0, 'desc'] // order by ID desc
  );
});
</script>
