The buttonbar at the top of each page is now a fixed 'div' element
[gnucomo.git] / src / web / log.php
1 <?php
2
3 /**************************************************************************
4 **  (c) Copyright 2003, Andromeda Technology & Automation
5 ** This is free software; you can redistribute it and/or modify it under the
6 ** terms of the GNU General Public License, see the file COPYING.
7 ***************************************************************************
8 ** MODULE INFORMATION *
9 ***********************
10 **      FILE NAME      : log.php
11 **      SYSTEM NAME    : Gnucomo - Gnu Computer Monitoring
12 **      VERSION NUMBER : $Revision: 1.8 $
13 **
14 **  DESCRIPTION      : Logs page
15 **
16 **  EXPORTED OBJECTS : 
17 **  LOCAL    OBJECTS : 
18 **  MODULES  USED    :
19 ***************************************************************************
20 **  ADMINISTRATIVE INFORMATION *
21 ********************************
22 **      ORIGINAL AUTHOR : Arjen Baart - arjen@andromeda.nl
23 **      CREATION DATE   : Dec 04, 2002
24 **      LAST UPDATE     : Jul 15, 2003
25 **      MODIFICATIONS   : 
26 **************************************************************************/
27
28 /*****************************
29    $Log: log.php,v $
30    Revision 1.8  2007-11-21 14:38:06  arjen
31    The buttonbar at the top of each page is now a fixed 'div' element
32    instead of a framed page.
33    Contributed by Edwin Nadorp.
34
35    Revision 1.7  2007/10/27 08:38:18  arjen
36    Removed link to advanced log analysis
37
38    Revision 1.6  2005/06/04 07:18:26  arjen
39    Added a view for the log analysis with a link from the log page.
40
41    Revision 1.5  2003/08/11 17:59:17  arjen
42    BUGFIX: Convert special characters for HTML (<, >, and &) into
43    their entities.
44
45    Revision 1.4  2003/07/15 11:03:39  arjen
46    Show the log one day at a time.
47
48    Revision 1.3  2003/02/21 08:50:12  arjen
49    Database optimizations.
50
51    Revision 1.2  2003/02/13 09:01:29  arjen
52    All web interface pages use the page class.
53
54    Revision 1.2  2003/02/05 09:48:14  arjen
55    Added display and handling of notifications
56
57 ******************************/
58
59 // RCSID = "$Id: log.php,v 1.8 2007-11-21 14:38:06 arjen Exp $";
60
61 ini_set('include_path', '.:./classes:../phpclasses');
62
63 require_once('page.class.php');
64
65
66 class log_page extends page
67 {
68
69    function Body()
70    {
71       if (!empty($_GET['oid']))
72       {
73          $oid = $_GET['oid'];
74          $res = pg_exec($this->database, "SELECT objectname FROM object
75                                WHERE objectid=CAST('$oid' AS BIGINT)");
76          $obj = pg_fetch_object($res, 0);
77          echo "<script type='text/ecmascript'>
78                document.getElementById('menu_title').innerHTML = \"<h1>Log for "
79                 . $obj->objectname . "<\/h1>\"
80                </script>";
81
82          //  Determine which day to display.
83          //  This is either from a previous button though a _POST[] variable
84          //  or the last day in the log table by default.
85
86          if (empty($_GET['logday']))
87          {
88             $res = pg_exec($this->database, "SELECT date_trunc('day',object_timestamp) FROM log
89                                   WHERE objectid='$oid'
90                                   ORDER BY object_timestamp DESC LIMIT 1");
91
92             if( pg_num_rows($res) > 0 )
93             {
94                $last_time = pg_fetch_object($res, 0);
95                $logday = strtotime($last_time->date_trunc);
96             }
97             else
98             {
99                $logday = "";
100             }
101          }
102          else
103          {
104             $logday = $_GET['logday'];
105          }
106
107          //  Make buttons to request the previous and the next day of logs.
108
109          echo "<div id=\"log_date\">";
110          $logday1 = $logday - 24 * 60 * 60;
111          echo "<a href=\"log.php?oid=$oid&amp;logday=$logday1\" title=\"previous day\">&lt;&lt;</a>";
112          echo "&nbsp;" . date('F d, Y', $logday) . "&nbsp;";
113          $logday2 = $logday + 24 * 60 * 60;
114          echo "<a href=\"log.php?oid=$oid&amp;logday=$logday2\" title=\"next day\">&gt;&gt;</a>";
115          echo "</div>";
116
117          // Show the log for one day only.
118
119          $res = pg_exec($this->database, "SELECT logid, object_timestamp, servicecode, rawdata FROM log "
120                         ."WHERE objectid = CAST('$oid' AS BIGINT)
121                          AND date_trunc('day', object_timestamp)='" . date('Y-m-d', $logday) . "'
122                          ORDER BY object_timestamp, logid");
123
124          echo "<table>\n";
125          echo "<tr><th>Date</th><th>Service</th><th>Log</th></tr>\n";
126          $row = 0;
127          while ($row < pg_numrows($res))
128          {
129             $log = pg_fetch_object($res, $row);
130             ?>
131             <tr><td class='time'>
132                  <?php echo $log->object_timestamp?>
133             </td><td>
134                <?php echo $log->servicecode?>
135             </td><td>
136                <?php echo htmlentities($log->rawdata)?>
137             </td></tr>
138             <?php
139             $row++;
140          }
141          echo "</table>";
142       }
143    }
144 }
145
146 $page = new log_page("Gnucomo system logs");
147
148 $page->Showpage();
149
150 ?>