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 $
14 ** DESCRIPTION : Objects Administration page.
15 ** Input parameters: action (POST) : empty, 'Create'
16 ** objname (POST) : name of the object to create or remove
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
28 **************************************************************************/
30 /*****************************
32 Revision 1.8 2003-08-14 10:35:07 arjen
33 Added editing of detailed object information.
35 Revision 1.7 2003/07/15 11:02:25 arjen
36 Use the new object_statistics table.
38 Revision 1.6 2003/02/21 08:46:58 arjen
39 Improved the table layout.
41 Revision 1.5 2003/02/13 09:01:29 arjen
42 All web interface pages use the page class.
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.
50 Revision 1.3 2003/02/10 15:42:24 arjen
51 Show the total number of Log entries, parameters and notifications
53 Revision 1.2 2003/02/05 09:48:14 arjen
54 Added display and handling of notifications
56 ******************************/
58 // RCSID = "$Id: objects.php,v 1.8 2003-08-14 10:35:07 arjen Exp $";
60 ini_set('include_path', '.:./classes:../phpclasses');
62 require_once('page.class.php');
64 function clientscripts()
68 <script language='JavaScript'>
70 function CheckCreate(f)
72 if (f.objectname.value == "")
74 alert("You must supply a name");
80 function CheckRemove(f)
82 var message = "Are you sure you want to remove object ";
83 message += f.objectname.value;
86 return confirm(message);
94 class object_page extends page
97 var $nr_parameters, $removed_parameters;
98 var $nr_notifications, $closed_notifications;
101 function GatherStatistics($objectid)
103 // Gather statistics on parameters
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;
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;
115 // Gather statistics on notifications
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;
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;
127 // Gather statistics on log entries
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;
140 if (isset($_POST['action']) && $_POST['action'] == 'Create' && !empty($_POST['objectname']))
142 pg_exec($this->database, "INSERT INTO object (objectname, log_count, parameter_count, notification_count)
143 VALUES ('" . $_POST['objectname'] . "', '0', '0', '0')");
146 if (isset($_POST['action']) && $_POST['action'] == 'Remove' && !empty($_POST['objectname']))
148 pg_exec($this->database, "DELETE FROM object WHERE objectname='" . $_POST['objectname'] . "'");
151 if (isset($_GET['oid']))
153 echo "<h1>Detailed information for object " . $_GET['oid'] . "</h1><hr>";
155 if (isset($_POST['action']) && $_POST['action'] == 'Save Changes')
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'];
166 pg_exec($this->database, $qry);
169 $res = pg_exec($this->database, "SELECT * FROM object
170 WHERE objectid='" . $_GET['oid'] . "'");
171 $obj = pg_fetch_object($res, 0);
173 echo "<form action='objects.php?oid=" . $obj->objectid . "' method='POST'>";
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>";
192 echo "<input type='submit' name='action' value='Save Changes'>";
197 echo "<h1>Objects Administration</h1><hr>";
199 $res = pg_exec($this->database, "SELECT * FROM object ORDER BY objectname");
203 <tr><th>Object</th><th>Description</th><th>Log entries</th>
204 <th>Parameters</th><th>Notifications</th></tr>
209 //The counters are set to zero
211 $count_notifications = 0;
212 $closed_notifications = 0;
213 $count_parameters = 0;
214 $removed_parameters = 0;
216 while ($obj < pg_numrows($res))
218 $u = pg_fetch_object($res, $obj);
220 $this->GatherStatistics($u->objectid);
222 $count_parameters += $this->nr_parameters;
223 $removed_parameters += $this->removed_parameters;
224 $count_logs = $count_logs + $this->nr_logs;
226 $count_notifications += $this->nr_notifications;
227 $closed_notifications += $this->closed_notifications;
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>
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>" ?>
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'>
252 echo "<tr><td><strong><B><br><br>TOTALS</B></strong></td>";
253 echo "<td> </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>";
261 <h2>Create new object:</h2>
264 <form action='objects.php' method='post' onSubmit='return CheckCreate(this)'>
265 Object's name (FQDN): <input name='objectname' type='text'>
267 <input type='submit' name='action' value='Create'>
277 $obj_page = new object_page("Gnucomo Objects Administration");
279 $obj_page->Showpage();