<?php
defined('BASEPATH') OR exit('No direct script access allowed');

function status($value)
{
  if($value == 'active')
  {
    $result = '<span class="badge bg-success">'.$value.'</span>';
  }
  else $result = '<span class="badge bg-danger">'.$value.'</span>';

  return $result;
}

function value_array($key)
{
  $array = "";

  foreach ($key as $column => $value){ $array .= ", ".$column.": "."'".$value."'"; };

  return $array;
}

?>

<div class="table-responsive">
  <table class="table table-sm table-bordered table-striped table-hover">
    <thead>
      <tr>
        <th style="text-align: center;">ID</th>
        <th style="text-align: center;">Name</th>
        <th style="text-align: center;">Description</th>
        <th style="text-align: center;">Altitude</th>
        <th style="text-align: center;">Latitude</th>
        <th style="text-align: center;">Longitude</th>
        <th style="text-align: center;">Status</th>
        <th style="text-align: center;">Organization ID</th>
        <th style="text-align: center; width: 130px">Aksi</th>
      </tr>
    </thead>
    <tbody>
      <?php foreach ($data as $key){ ?>
        <tr>
          <td style="text-align: center;"><?php echo $key->id ?></td>  
          <td style="text-align: center;"><?php echo $key->name ?></td>     
          <td style="text-align: center;"><?php echo $key->description ?></td> 
          <td style="text-align: center;"><?php echo $key->position_altitude ?></td> 
          <td style="text-align: center;"><?php echo $key->position_latitude ?></td> 
          <td style="text-align: center;"><?php echo $key->position_longitude ?></td>
          <td style="text-align: center;"><?php echo status($key->status) ?></td>
          <td style="text-align: center;"><?php echo $key->organization_id ?></td>  
          <td style="text-align: center;">       	
            <button type="button" class="btn btn-xs btn-info" onclick="edit_data({table_name: 'mapping_lokasi'<?php echo value_array($key) ?>})"> <i class="fa fa-edit"> Edit </i></button>
            <button class="btn btn-warning btn-rounded btn-xs" onclick="edit_data({table_name: 'mapping_lokasi'<?php echo value_array($key) ?>})"><i class="fas fa-clone"></i></button>
            <button class="btn btn-danger btn-rounded btn-xs" onclick="hapus_data({table_name: 'mapping_lokasi'<?php echo value_array($key) ?>})"><i class="fas fa-times"></i></button>
          </td>
          </td>
        </tr> 
      <?php } ?>
    </tbody>
  </table>
</div>
