<?= $this->tabs->render($this); ?>

<?php
/**
 * Create a DateTime from a string and use the util helper to
 * format it
 *
 * @param $self Reference to the current view that contains the helper.
 * @param $dateString The String that will be converted.
 * @return String The formatted string.
 */
function formatDateString($self,$dateString){
    $d = new DateTime($dateString);
    return $self->util()->showTime($d->getTimestamp());
}
$paginator = $downtimes->paginate();
$downtimes = $downtimes->fetchAll();
?>
<form method="get" class="form-inline" action="<?= $this->href(
    'monitoring/list/downtimes?',
    array(
        'action' => 'downtimes'
    ));
?>">
  <label>Sort By</label>
  <br/>
  <?=
  $this->formSelect(
      'sort',
      $this->sort,
      array('class' => 'autosubmit'),
      array(
        'downtime_is_in_effect'         => 'Is In Effect',
        'object_type'                   => 'Service/Host',
        'host_name'                     => 'Host Name',
        'service_description'           => 'Service Name',
        'downtime_entry_time'           => 'Entry Time',
        'downtime_author_name'          => 'Author',
        'downtime_comment_data'         => 'Comment',
        'downtime_scheduled_start_time' => 'Start',
        'downtime_scheduled_end_time'   => 'End',
        'downtime_trigger_time'         => 'Trigger Time',
        'downtime_internal_downtime_id' => 'Downtime ID',
        'downtime_duration'             => 'Duration',
      )
  );
  ?>
  <noscript>
    <button class="btn btn-small btn-default" >
      <i>{{REFRESH_ICON}}</i>
    </button>
  </noscript>
</form>
<?=
    $this->paginationControl(
        $paginator,
        null,
        array(
            'mixedPagination.phtml',
            'default'
        ),
        array('preserve' => $this->preserve)
    )
?>

<table class="table table-condensed">
  <thead>
    <tr>
      <th>Is In Effect</th>
      <th>Object</th>
      <th>Host Name</th>
      <th>Service Name</th>
      <th>Entry Time</th>
      <th>Author</th>
      <th>Comment</th>
      <th>Start Time</th>
      <th>End Time</th>
      <th>Type</th>
      <th>Trigger Time</th>
      <th>Downtime ID</th>
      <th>Trigger ID</th>
      <th>Duration</th>
    </tr>
  </thead>

  <?php foreach ($downtimes as $downtime): ?>

  <tr>
    <td>
      <?= ($downtime->downtime_is_in_effect == 0 ? 'False' : '<b>True</b>'); ?>
    </td>
    <td>
      <div>
        <?php if ($downtime->object_type == 'service'): ?>
          {{SERVICE_ICON}}
        <?php endif; ?>

        <?php if ($downtime->object_type == 'host'): ?>
          {{HOST_ICON}}
        <?php endif; ?>
      </div>
    </td>
    <td>
      <?= $downtime->host_name ?>
    </td>
    <td>
      <?= $downtime->service_description ?>
    </td>
    <td>
      <?= formatDateString($this,$downtime->downtime_entry_time); ?>
    </td>
    <td>
      <?= $downtime->downtime_author_name ?>
    </td>
    <td>
      <?= $downtime->downtime_comment_data ?>
    </td>
    <td>
      <?= formatDateString($this,$downtime->downtime_scheduled_start_time); ?>
    </td>
    <td>
      <?= formatDateString($this,$downtime->downtime_scheduled_end_time); ?>
    </td>
    <td>
      <?= $downtime->downtime_is_fixed == 1 ? 'Fixed' : 'Not Fixed' ?>
    </td>
    <td>
      <?php
        $date = formatDateString($this,$downtime->downtime_trigger_time);
        echo $date != 'undef' ? $date : 'N/A';
      ?>
    </td>
    <td>
      <?= $downtime->downtime_internal_downtime_id ?>
    </td>
    <td>
      <?= $downtime->downtime_triggered_by_id == 0 ?
      'N/A' : $downtime->downtime_triggered_by_id ?>
    </td>
    <td>
      <?= $this->util()->showHourMin(intval($downtime->downtime_duration)); ?>
    </td>
    <td>
    </td>
  </tr>
  <?php endforeach ?>
</table>
