Added editing of detailed object information.
[gnucomo.git] / src / web / objects.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      : objects.php
11 **      SYSTEM NAME    : Gnucomo - Gnu Computer Monitoring
12 **      VERSION NUMBER : $Revision: 1.8 $
13 **
14 **  DESCRIPTION      : Objects Administration page.
15 **                     Input parameters: action (POST) : empty, 'Create'
16 **                              objname (POST) : name of the object to create or remove
17 **
18 **  EXPORTED OBJECTS : 
19 **  LOCAL    OBJECTS : 
20 **  MODULES  USED    :
21 ***************************************************************************
22 **  ADMINISTRATIVE INFORMATION *
23 ********************************
24 **      ORIGINAL AUTHOR : Arjen Baart - arjen@andromeda.nl
25 **      CREATION DATE   : Dec 04, 2002
26 **      LAST UPDATE     : Aug 04, 2003
27 **      MODIFICATIONS   : 
28 **************************************************************************/
29
30 /*****************************
31    $Log: objects.php,v $
32    Revision 1.8  2003-08-14 10:35:07  arjen
33    Added editing of detailed object information.
34
35    Revision 1.7  2003/07/15 11:02:25  arjen
36    Use the new object_statistics table.
37
38    Revision 1.6  2003/02/21 08:46:58  arjen
39    Improved the table layout.
40
41    Revision 1.5  2003/02/13 09:01:29  arjen
42    All web interface pages use the page class.
43
44    Revision 1.4  2003/02/13 08:48:23  arjen
45    Added log, notification and parameter counters to the 'object' table.
46    Counting these things at the time a user interface needs them is
47    too slow. Other programs, like gcm_daemon en gcm_input should prepare
48    these counters for quick retrieval.
49
50    Revision 1.3  2003/02/10 15:42:24  arjen
51    Show the total number of Log entries, parameters and notifications
52
53    Revision 1.2  2003/02/05 09:48:14  arjen
54    Added display and handling of notifications
55
56 ******************************/
57
58 // RCSID = "$Id: objects.php,v 1.8 2003-08-14 10:35:07 arjen Exp $";
59
60 ini_set('include_path', '.:./classes:../phpclasses');
61
62 require_once('page.class.php');
63
64 function clientscripts()
65 {
66 ?>
67
68 <script language='JavaScript'>
69
70 function CheckCreate(f)
71 {
72    if (f.objectname.value == "")
73    {
74       alert("You must supply a name");
75       return false;
76    }
77    return true;
78 }
79
80 function CheckRemove(f)
81 {
82    var message = "Are you sure you want to remove object ";
83    message += f.objectname.value;
84    message += " ?";
85
86    return confirm(message);
87 }
88
89 </script>
90
91 <?php
92 }
93
94 class object_page extends page
95 {
96
97    var $nr_parameters, $removed_parameters;
98    var $nr_notifications, $closed_notifications;
99    var $nr_logs;
100
101    function GatherStatistics($objectid)
102    {
103       //  Gather statistics on parameters
104
105       $r = pg_exec ($this->database, "SELECT statvalue FROM object_statistics WHERE objectid=CAST('"
106                            . $objectid . "' AS BIGINT) AND statname='parameters'");
107       $stat = pg_fetch_object($r, 0);
108       $this->nr_parameters = $stat->statvalue;
109
110       $r = pg_exec ($this->database, "SELECT statvalue FROM object_statistics WHERE objectid=CAST('"
111                            . $objectid . "' AS BIGINT) AND statname='removed_parameters'");
112       $stat = pg_fetch_object($r, 0);
113       $this->removed_parameters = $stat->statvalue;
114
115       //  Gather statistics on notifications
116
117       $r = pg_exec ($this->database, "SELECT statvalue FROM object_statistics WHERE objectid=CAST('"
118                            . $objectid . "' AS BIGINT) AND statname='notifications'");
119       $stat = pg_fetch_object($r, 0);
120       $this->nr_notifications = $stat->statvalue;
121
122       $r = pg_exec ($this->database, "SELECT statvalue FROM object_statistics WHERE objectid=CAST('"
123                            . $objectid . "' AS BIGINT) AND statname='closed_notifications'");
124       $stat = pg_fetch_object($r, 0);
125       $this->closed_notifications = $stat->statvalue;
126
127       //  Gather statistics on log entries
128
129       $r = pg_exec ($this->database, "SELECT statvalue FROM object_statistics WHERE objectid=CAST('"
130                            . $objectid . "' AS BIGINT) AND statname='logs'");
131       $stat = pg_fetch_object($r, 0);
132       $this->nr_logs = $stat->statvalue;
133
134    }
135
136    function Body()
137    {
138       clientscripts();
139
140    if (isset($_POST['action']) && $_POST['action'] == 'Create' && !empty($_POST['objectname']))
141    {
142       pg_exec($this->database, "INSERT INTO object (objectname, log_count, parameter_count, notification_count)
143                                VALUES ('" . $_POST['objectname'] . "', '0', '0', '0')");
144    }
145
146    if (isset($_POST['action']) && $_POST['action'] == 'Remove' && !empty($_POST['objectname']))
147    {
148       pg_exec($this->database, "DELETE FROM object WHERE objectname='" . $_POST['objectname'] . "'");
149    }
150
151    if (isset($_GET['oid']))
152    {
153       echo "<h1>Detailed information for object " . $_GET['oid'] . "</h1><hr>";
154
155       if (isset($_POST['action']) && $_POST['action'] == 'Save Changes')
156       {
157          $qry = "UPDATE object SET objectname='" . $_POST['oname'] . "'";
158          $qry .= ", objectcode='" . $_POST['ocode'] . "'";
159          $qry .= ", object_description='" . $_POST['odescription'] . "'";
160          $qry .= ", object_owner='" . $_POST['oowner'] . "'";
161          $qry .= ", physical_location='" . $_POST['olocation'] . "'";
162          $qry .= ", remark='" . $_POST['oremark'] . "'";
163          $qry .= ", timezone='" . $_POST['otimezone'] . "'";
164          $qry .= " WHERE objectid=" . $_GET['oid'];
165
166          pg_exec($this->database, $qry);
167       }
168
169       $res = pg_exec($this->database, "SELECT * FROM object
170                                        WHERE objectid='" . $_GET['oid'] . "'");
171       $obj = pg_fetch_object($res, 0);
172
173       echo "<form action='objects.php?oid=" . $obj->objectid . "' method='POST'>";
174       echo "<table>";
175
176       echo "<tr><td>Name</td><td><input name='oname' type='text' value='";
177       echo $obj->objectname . "'></td></tr>";
178       echo "<tr><td>Identification code</td><td><input name='ocode' type='text' value='";
179       echo $obj->objectcode . "'></td></tr>";
180       echo "<tr><td>Description</td><td><textarea name='odescription'>";
181       echo $obj->object_description . "</textarea></td></tr>";
182       echo "<tr><td>Owner</td><td><textarea name='oowner'>";
183       echo $obj->object_owner . "</textarea></td></tr>";
184       echo "<tr><td>Physical location</td><td><textarea name='olocation'>";
185       echo $obj->physical_location . "</textarea></td></tr>";
186       echo "<tr><td>Remarks</td><td><textarea name='oremark'>";
187       echo $obj->remark . "</textarea></td></tr>";
188       echo "<tr><td>Timezone</td><td><input name='otimezone' type='text' value='";
189       echo $obj->timezone . "'></td></tr>";
190
191       echo "</table>";
192       echo "<input type='submit' name='action' value='Save Changes'>";
193       echo "</form>";
194    }
195    else
196    {
197       echo "<h1>Objects Administration</h1><hr>";
198
199       $res = pg_exec($this->database, "SELECT * FROM object ORDER BY objectname");
200 ?>
201
202       <table>
203       <tr><th>Object</th><th>Description</th><th>Log entries</th>
204           <th>Parameters</th><th>Notifications</th></tr>
205
206 <?php
207       $obj = 0;
208
209       //The counters are set to zero
210       $count_logs = 0;
211       $count_notifications = 0;
212       $closed_notifications = 0;
213       $count_parameters = 0;
214       $removed_parameters = 0;
215
216       while ($obj < pg_numrows($res))
217       {
218          $u = pg_fetch_object($res, $obj);
219
220          $this->GatherStatistics($u->objectid);
221
222          $count_parameters += $this->nr_parameters;
223          $removed_parameters += $this->removed_parameters;
224          $count_logs = $count_logs + $this->nr_logs;
225
226          $count_notifications += $this->nr_notifications;
227          $closed_notifications += $this->closed_notifications;
228          ?>
229          <tr><td><center><a href='objects.php?oid=<?php echo $u->objectid?>'<img src='server.png'></a><br>
230                 <b><?php echo $u->objectname ?></b></center>
231          </td><td>
232                <?php echo nl2br($u->object_description) ?>
233          </td><td class='number'>
234              <?php echo "<a href='log.php?oid=$u->objectid'> $this->nr_logs </a>" ?>
235          </td><td class='number'>
236              <?php echo "<a href='parameter.php?oid=$u->objectid'>" . $this->nr_parameters
237                       . " (" . $this->removed_parameters . " removed)</a>" ?>
238          </td><td class='number'>
239              <?php echo "<a href='notification.php?oid=$u->objectid'>" . $this->nr_notifications
240                       . " (" . $this->closed_notifications . " closed)</a>" ?>
241          </td><td>
242              <form action='objects.php' method='post' onSubmit='return CheckRemove(this)'>
243                  <input type='hidden' name='objectname' value='<?php echo $u->objectname ?>'>
244                  <input type='submit' name='action' value='Remove'>
245              </form>
246          </td></tr>
247          <?php
248          $obj++;
249       }
250
251       //Show the totals
252       echo "<tr><td><strong><B><br><br>TOTALS</B></strong></td>";
253       echo "<td>&nbsp;</td>";
254       echo "<td class='number'>$count_logs</td>";
255       echo "<td class='number'>$count_parameters ($removed_parameters removed)</td>";
256       echo "<td class='number'>$count_notifications ($closed_notifications closed)</td></tr>";
257       echo "</table>";
258
259 ?>
260
261 <h2>Create new object:</h2>
262 <p>
263
264 <form action='objects.php' method='post' onSubmit='return CheckCreate(this)'>
265 Object's name (FQDN): <input name='objectname' type='text'>
266 <br>
267 <input type='submit' name='action' value='Create'>
268 </form>
269 </p>
270
271 <?php
272
273    }
274    }
275 }
276
277 $obj_page = new object_page("Gnucomo Objects Administration");
278
279 $obj_page->Showpage();
280
281 ?>
282