BUGFIX: Convert special characters for HTML (<, >, and &) into
[gnucomo.git] / src / web / log.php
index 96ac2cd..04896fa 100644 (file)
-<?php 
+<?php
 
 /**************************************************************************
+**  (c) Copyright 2003, Andromeda Technology & Automation
 ** This is free software; you can redistribute it and/or modify it under the
 ** terms of the GNU General Public License, see the file COPYING.
-***************************************************************************/
+***************************************************************************
+** MODULE INFORMATION *
+***********************
+**      FILE NAME      : log.php
+**      SYSTEM NAME    : Gnucomo - Gnu Computer Monitoring
+**      VERSION NUMBER : $Revision: 1.5 $
+**
+**  DESCRIPTION      : Logs page
+**
+**  EXPORTED OBJECTS : 
+**  LOCAL    OBJECTS : 
+**  MODULES  USED    :
+***************************************************************************
+**  ADMINISTRATIVE INFORMATION *
+********************************
+**      ORIGINAL AUTHOR : Arjen Baart - arjen@andromeda.nl
+**      CREATION DATE   : Dec 04, 2002
+**      LAST UPDATE     : Jul 15, 2003
+**      MODIFICATIONS   : 
+**************************************************************************/
 
-/*
- *
- * Objects Administration page.
- * Input parameters: action (POST) : empty, 'Create'
- *                   objname (POST) : name of the object to create or remove
- */
+/*****************************
+   $Log: log.php,v $
+   Revision 1.5  2003-08-11 17:59:17  arjen
+   BUGFIX: Convert special characters for HTML (<, >, and &) into
+   their entities.
 
-session_start();
-require_once('classes/gnucomo_config.php');
-?>
+   Revision 1.4  2003/07/15 11:03:39  arjen
+   Show the log one day at a time.
 
-<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
-<html>
-<head>
-<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
-<link rel='stylesheet' href='gnucomo.css' type='text/css'>
-<title>GNUCoMo login</title>
+   Revision 1.3  2003/02/21 08:50:12  arjen
+   Database optimizations.
 
-<script language='JavaScript'>
-function CheckCreate(f)
-{
-   if (f.objectname.value == "")
-   {
-      alert("You must supply a name");
-      return false;
-   }
-   return true;
-}
+   Revision 1.2  2003/02/13 09:01:29  arjen
+   All web interface pages use the page class.
 
-function CheckRemove(f)
-{
-   var message = "Are you sure you want to remove object ";
-   message += f.objectname.value;
-   message += " ?";
+   Revision 1.2  2003/02/05 09:48:14  arjen
+   Added display and handling of notifications
 
-   return confirm(message);
-}
+******************************/
 
-</script>
+// RCSID = "$Id: log.php,v 1.5 2003-08-11 17:59:17 arjen Exp $";
 
-</head>
-<body>
-<?php
-if (empty($_SESSION['username']))
-{
-   echo "Please log in first.";
-}
-else
-{
+ini_set('include_path', '.:./classes:../phpclasses');
 
-   $config = new gnucomo_config;
+require_once('page.class.php');
 
-   $config->read("gnucomo");
 
-   //  Connect to the database
-   $conn = pg_connect($config->Database($_SESSION['username'], $_SESSION['password']));
+class log_page extends page
+{
 
-   if (!empty($_GET['oid']))
+   function Body()
    {
-      $res = pg_exec("SELECT objectname FROM object WHERE objectid=" . $_GET['oid']);
-      $obj = pg_fetch_object($res, 0);
-      echo "<h1>Log for " . $obj->objectname . "</h1><hr>";
-
-      $res = pg_exec("SELECT object_timestamp, servicecode, rawdata FROM log "
-                     ."WHERE objectid=" . $_GET['oid']);
-      
-      echo "<table>";
-      $row = 0;
-      while ($row < pg_numrows($res))
+      if (!empty($_GET['oid']))
       {
-         $log = pg_fetch_object($res, $row);
-         ?>
-         <tr><td align='center'>
-            <?php echo $log->object_timestamp?>
-         </td><td>
-            <?php echo $log->servicecode?>
-         </td><td>
-            <?php echo $log->rawdata?>
-         </td></tr>
-         <?php
-         $row++;
+         $res = pg_exec($this->database, "SELECT objectname FROM object
+                               WHERE objectid=CAST('" . $_GET['oid']. "' AS BIGINT)");
+         $obj = pg_fetch_object($res, 0);
+         echo "<h1>Log for " . $obj->objectname . "</h1><hr>";
+
+         //  Determine which day to display.
+         //  This is either from a previous button though a _POST[] variable
+         //  or the last day in the log table by default.
+
+         if (empty($_POST['logday']))
+         {
+            $res = pg_exec($this->database, "SELECT date_trunc('day',object_timestamp) FROM log
+                                  WHERE objectid='". $_GET['oid'] ."'
+                                  ORDER BY object_timestamp DESC LIMIT 1");
+
+            $last_time = pg_fetch_object($res, 0);
+            $logday = strtotime($last_time->date_trunc);
+         }
+         else
+         {
+            $logday = $_POST['logday'];
+         }
+
+         //  Make buttons to request the previous and the next day of logs.
+
+         echo "<form method='POST'>";
+         echo "<input type='submit' value='<<'>";
+         echo "<input type='hidden' name='logday' value='" . ($logday - 24 * 60 * 60) . "'>";
+         echo "</form>";
+
+         echo "<h3>" . date('F d, Y', $logday) ."</h3>";
+
+         echo "<form method='POST'>";
+         echo "<input type='submit' value='>>'>";
+         echo "<input type='hidden' name='logday' value='" . ($logday + 24 * 60 * 60) . "'>";
+         echo "</form>";
+
+         // Show the log for one day only.
+
+         $res = pg_exec($this->database, "SELECT object_timestamp, servicecode, rawdata FROM log "
+                        ."WHERE objectid = CAST('" . $_GET['oid'] . "' AS BIGINT)
+                         AND date_trunc('day', object_timestamp)='" . date('Y-m-d', $logday) . "'
+                         ORDER BY object_timestamp, logid");
+
+         echo "<table>\n";
+         echo "<tr><th>Date</th><th>Service</th><th>Log</th></tr>\n";
+         $row = 0;
+         while ($row < pg_numrows($res))
+         {
+            $log = pg_fetch_object($res, $row);
+            ?>
+            <tr><td class='time'>
+               <?php echo $log->object_timestamp?>
+            </td><td>
+               <?php echo $log->servicecode?>
+            </td><td>
+               <?php echo htmlentities($log->rawdata)?>
+            </td></tr>
+            <?php
+            $row++;
+         }
+         echo "</table>";
       }
-      echo "</table>";
    }
 }
-?>
 
-</body>
-</html>
+$page = new log_page("Gnucomo system logs");
+
+$page->Showpage();
+
+?>