<?PHP
  include "include/header.inc";
?>

<table border=0 align=center>

<?PHP

    include "include/commons.inc";
    include "include/pgsql.inc";


    $db = new DB_Pgsql;

    $query = "select host_name from host where host_id=".$db->prepInt($_REQUEST['host_id']);
    $db->query($query);
    $db->next_record();
    $hostname = $db->f("host_name");
    $db->disconnect();

    $query = "select service_name from service where service_id=".$db->prepInt($_REQUEST['service_id']);
    $db->query($query);
    $db->next_record();
    $servicename = $db->f("service_name");
    $db->disconnect();

?>

    <tr>
        <th align="center"><?PHP echo $hostname;?> - <?PHP echo $servicename;?></th>
    </tr>

    <tr>
        <td align="left" width=400>
<?PHP

    // Get statuslog history
    $query = "select * from host_statuschange where host_id=".$db->prepInt($_REQUEST['host_id'])." and service_id=".$db->prepInt($_REQUEST['service_id'])." order by log_datetime desc limit 50 offset 0";
    $db->query($query);
    echo "<table border=0><tr><th>Date</th><th>Status</th><th>Duration</th></tr>";
    $nextdatetime=time()*1000;
    while ($db->next_record()) {
      echo "<tr><td align=center>".date("D M jS H:i:s", $db->f("log_datetime")/1000)."</td><td align=center><a href=\"detail.php?host_id=$host_id&service_id=$service_id&log_datetime=".$db->f("log_datetime")."\"><img border=0 src=\"images/".$statuscodes[$db->f("log_newstatus")].".gif\"></a></td><td>";
      // Duration??
      echo displayDuration(($nextdatetime-$db->f("log_datetime"))/1000);

      $nextdatetime = $db->f("log_datetime");
      echo "</td></tr>\n";
    }
    $db->disconnect();
    echo "</table>";
?>
        </td>
    </tr>
</table>

<?PHP
  include "include/footer.inc";
?>
