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 : notification.php
11 ** SYSTEM NAME : Gnucomo - Gnu Computer Monitoring
12 ** VERSION NUMBER : $Revision: 1.6 $
14 ** DESCRIPTION : Display and handle notifications.
15 ** There are two major views to this page: either a list of
16 ** all notifications for an object or the display of a single
17 ** notification. In the 'single notification' view, actions
18 ** can be added to the notification and the status can be
19 ** changed as a result of those actions.
21 ** Input: GET['oid'] - If set, list all notifications for object.
22 ** GET['notid'] - If set, display a single notification.
23 ** POST['notid']- If set, update the notification.
28 ***************************************************************************
29 ** ADMINISTRATIVE INFORMATION *
30 ********************************
31 ** ORIGINAL AUTHOR : Arjen Baart - arjen@andromeda.nl
32 ** CREATION DATE : Dec 12, 2002
33 ** LAST UPDATE : Feb 16, 2003
35 **************************************************************************/
37 /*****************************
38 $Log: notification.php,v $
39 Revision 1.6 2007-12-10 16:27:33 arjen
40 Added an option to perform one action on multiple notifications at once.
42 Revision 1.5 2007/11/21 14:38:06 arjen
43 The buttonbar at the top of each page is now a fixed 'div' element
44 instead of a framed page.
45 Contributed by Edwin Nadorp.
47 Revision 1.4 2007/01/11 13:44:29 arjen
48 Manually edit parameters.
49 View logs from abusing IP addresses.
51 Revision 1.3 2003/02/21 08:49:16 arjen
52 Keep a record of each time a notification
53 is displayed. Either on a listing or in detail.
55 Revision 1.2 2003/02/13 09:01:29 arjen
56 All web interface pages use the page class.
58 Revision 1.1 2003/02/05 09:48:14 arjen
59 Added display and handling of notifications
61 ******************************/
63 // RCSID = "$Id: notification.php,v 1.6 2007-12-10 16:27:33 arjen Exp $";
65 ini_set('include_path', '.:./classes:../phpclasses');
67 require_once('page.class.php');
69 function clientscripts()
73 <script type='text/ecmascript'>
75 function CheckRemark(f)
77 if (f.remark.value == "")
79 alert("Your remark is still empty");
91 * Add an action to the notification $note.
92 * The status of the notification may alter as a result.
95 function add_action($db, $note, $actionid, $remark)
97 $r = pg_exec($db, "SELECT statuscode FROM action WHERE actionid=CAST('" . $actionid."' AS BIGINT)");
98 $action = pg_fetch_object($r, 0);
100 if ($action->statuscode != "" && $note->statuscode != $action->statuscode)
102 // Update the status of the notification.
104 $note->statuscode = $action->statuscode;
106 pg_exec($db, "UPDATE notification SET statuscode='" . $note->statuscode
107 . "' WHERE notificationid = " . $note->notificationid);
110 // Add the action to the action_user table.
112 pg_exec($db, "INSERT INTO action_user (actionid, username, notificationid,
113 timestamp, statuscode, remarks) values ('$actionid', '"
114 . $_SESSION['username'] . "', '" . $note->notificationid
115 . "', '" . date('Y-m-d H:i:s') . "', '" . $note->statuscode
116 . "', '" . $remark . "')");
118 return $note->statuscode;
121 class notification_page extends page
124 function notification_list($objectid)
127 // Display a list of all notifications for this object['oid']
129 $res = pg_exec($this->database, "SELECT objectname FROM object WHERE objectid=" . $objectid);
130 $obj = pg_fetch_object($res, 0);
131 echo "<h1>Notifications for " . $obj->objectname . "</h1><hr>";
133 $res = pg_exec($this->database, "SELECT notificationid, timestamp, type_of_issueid,
135 FROM notification WHERE objectid= CAST ('"
136 . $objectid ."' AS BIGINT) AND statuscode != 'cls'"
137 . " ORDER BY notificationid");
140 echo '<tr><th>Time</th><th>Number</th><th>Issue</th><th>Status</th><th>Priority</th></tr>';
142 while ($row < pg_num_rows($res))
144 $note = pg_fetch_object($res, $row);
145 $r = pg_exec($this->database, "SELECT name from type_of_issue WHERE type_of_issueid = CAST('"
146 . $note->type_of_issueid . "' AS BIGINT)");
147 $issue = pg_fetch_object($r, 0);
148 echo "<tr><td align='center'>\n";
149 echo $note->timestamp;
151 echo $note->notificationid;
153 echo "<a href='notification.php?notid=";
154 echo $note->notificationid;
159 echo $note->statuscode;
161 echo $note->priority;
165 //Save evidence that this notification was presented to the user.
166 //$note->statuscode = add_action($this->database, $note, 21,
167 // "This notification was displayed with others from the same object");
172 function display_notification($note)
174 $res = pg_exec($this->database, "SELECT objectname FROM object WHERE objectid= CAST ('" . $note->objectid . "' AS BIGINT)");
175 $obj = pg_fetch_object($res, 0);
176 echo "<h1>Notification " . $note->notificationid . " for " . $obj->objectname . "</h1><hr>";
177 echo "<script type='text/ecmascript'>document.getElementById('menu_title').innerHTML = '<h1>Notification " . $note->notificationid . " for " . $obj->objectname . "<\/h1>'</script><br>";
179 $r = pg_exec($this->database, "SELECT description FROM type_of_issue WHERE type_of_issueid = CAST ('"
180 . $note->type_of_issueid . "' AS BIGINT)");
181 $issue = pg_fetch_object($r, 0);
183 $r = pg_exec($this->database, "SELECT statusname FROM status
184 WHERE statuscode = '" . $note->statuscode . "'");
186 $status = pg_fetch_object($r, 0);
188 echo "Issue : " . $issue->description . ", Priority " . $note->priority . "<br>";
189 echo "Creation time : " . $note->timestamp . "<br>";
190 echo "Current status : " . $status->statusname . "<br>";
192 // List all actions that occurred on this notification
194 echo "<h2>Action history for notification " . $note->notificationid . "</h2>";
196 echo "<tr><th>Time</th><th>User</th><th>Remarks</th></tr>";
198 $r = pg_exec($this->database, "SELECT actionid, username, timestamp, remarks
199 FROM action_user WHERE notificationid= CAST ('"
200 . $note->notificationid . "' AS BIGINT )"
201 ." ORDER BY timestamp");
202 for ($row = 0; $row < pg_numrows($r); $row++)
204 $action_user = pg_fetch_object($r, $row);
206 echo "<tr><td class='time'>";
207 echo $action_user->timestamp;
209 echo $action_user->username;
211 echo htmlspecialchars(stripslashes($action_user->remarks));
216 // See if we can list any parameters for this notification
218 $r = pg_exec($this->database, "SELECT * FROM parameter WHERE paramid IN
219 ( SELECT paramid FROM parameter_notification
220 WHERE notificationid = CAST ('" . $note->notificationid
222 if (pg_numrows($r) > 0)
224 echo "<h2>Parameters involved in this notification</h2>";
226 echo "<tr><th>Class</th><th>Name</th><th>Description</th><th>History</th></tr>";
228 for ($row = 0; $row < pg_numrows($r); $row++)
230 $p = pg_fetch_object($r, $row);
231 $res = pg_exec($this->database, "SELECT * from history WHERE paramid= CAST('" . $p->paramid
232 . "' AS BIGINT) ORDER BY modified");
239 echo $p->description;
241 for ($hrow = 0; $hrow < pg_numrows($res); $hrow++)
243 $hist = pg_fetch_object($res, $hrow);
244 echo $hist->modified . " ";
245 echo $hist->change_nature . " ";
246 echo $hist->changed_property . " ";
247 echo $hist->new_value;
256 // See if we can list any log entries for this notification
258 $r = pg_exec($this->database, "SELECT * FROM log WHERE logid IN
259 ( SELECT logid FROM log_notification
260 WHERE notificationid = CAST ('"
261 . $note->notificationid . "' AS BIGINT)) ORDER BY object_timestamp");
262 if (pg_numrows($r) > 0)
264 echo "<h2>Log entries involved in this notification</h2>";
266 echo "<tr><th>Time</th><th>Service</th><th>Log entry</th></tr>";
268 for ($row = 0; $row < pg_numrows($r); $row++)
270 $p = pg_fetch_object($r, $row);
273 echo $p->object_timestamp;
275 echo $p->servicecode;
277 echo htmlentities($p->rawdata);
286 function notification_form($note)
289 * Depending on the state of the notification, specific actions
290 * are possible. One such actions determines a transition to
291 * the next state. The array $possible_action lists the state transitions
295 $possible_action = array
297 "opn" => array (3, 6, 7, 13),
298 "pen" => array (3, 6, 7, 8, 11, 18),
299 "inv" => array (3, 9),
300 "vrf" => array (12, 13),
304 echo "<h2>Enter a remark for the next action</h2>";
305 echo "<form method='post' onSubmit='return CheckRemark(this)' action=''>";
306 echo "<textarea name='remark' cols='30' rows='5'></textarea><br>";
308 /* Display a list of possible actions */
310 echo "<h2>Select one of the actions to take below</h2>";
314 foreach ($possible_action[$note->statuscode] as $act)
316 $action = pg_fetch_object(pg_exec("SELECT description FROM action WHERE actionid= CAST('"
317 . $act . "' AS BIGINT)"),0);
318 echo "<input type='radio' name='actionid'";
324 echo " value='$act'>" . $action->description . "<br>";
327 echo "<input type='checkbox' name='act_on_all'>Perform this action on all notifications with the same issue.<br>";
328 echo "<input type='submit' value='Submit action'>";
335 if ($_SERVER['REQUEST_METHOD'] == 'GET' && !empty($_GET['oid']))
338 // Display a list of all notifications for this object['oid']
340 $res = pg_exec($this->database, "SELECT objectname FROM object WHERE objectid=" . $_GET['oid']);
341 $obj = pg_fetch_object($res, 0);
342 echo "<script type='text/ecmascript'>document.getElementById('menu_title').innerHTML = '<h1>Notifications for " . $obj->objectname . "<\/h1>'</script><br>";
344 $res = pg_exec($this->database, "SELECT notificationid, timestamp, type_of_issueid,
346 FROM notification WHERE objectid= CAST ('"
347 . $_GET['oid'] ."' AS BIGINT) AND statuscode != 'cls'"
348 . " ORDER BY notificationid");
351 echo '<tr><th>Time</th><th>Number</th><th>Issue</th><th>Status</th><th>Priority</th></tr>';
353 while ($row < pg_numrows($res))
355 $note = pg_fetch_object($res, $row);
356 $r = pg_exec($this->database, "SELECT name from type_of_issue WHERE type_of_issueid = CAST('"
357 . $note->type_of_issueid . "' AS BIGINT)");
358 $issue = pg_fetch_object($r, 0);
359 echo "<tr><td align='center'>\n";
360 echo $note->timestamp;
362 echo $note->notificationid;
364 echo "<a href='notification.php?notid=";
365 echo $note->notificationid;
370 echo $note->statuscode;
372 echo $note->priority;
376 //Save evidence that this notification was presented to the user.
377 //$note->statuscode = add_action($this->database, $note, 21,
378 // "This notification was displayed with others from the same object");
382 else if ($_SERVER['REQUEST_METHOD'] == 'GET' && !empty($_GET['notid']))
386 // Display all information about a single notification['notid']
388 $local_sql = "SELECT * from notification
389 WHERE notificationid = CAST('" . $_GET['notid'] . "' AS BIGINT)";
390 $res = pg_exec($this->database, $local_sql);
391 $note = pg_fetch_object($res, 0);
393 //Gather proof that the notification has been presented
394 if ($note->statuscode == 'new')
396 $note->statuscode = add_action($this->database, $note, 2,
397 "Notification displayed in detail through web interface");
401 $note->statuscode = add_action($this->database, $note, 20,
402 "Notification redisplayed in detail through web interface");
404 $this->display_notification($note);
406 $this->notification_form($note);
407 $this->notification_list($note->objectid);
409 else if ($_SERVER['REQUEST_METHOD'] == 'POST' && !empty($_GET['notid']))
413 // Display all information about a single notification['notid']
415 $res = pg_exec($this->database, "SELECT * from notification
416 WHERE notificationid=" . $_GET['notid']);
417 $note = pg_fetch_object($res, 0);
419 if (!empty($_POST['act_on_all']))
421 // Perform the action on all notifications with the same object and issue.
422 $res = pg_exec($this->database, "SELECT notificationid, timestamp, type_of_issueid, statuscode
423 FROM notification WHERE objectid= CAST ('"
424 . $note->objectid ."' AS BIGINT) AND statuscode != 'cls'
425 AND type_of_issueid = '" . $note->type_of_issueid
426 . "' ORDER BY notificationid");
427 for ($row = 0; $row < pg_num_rows($res); $row++)
429 $similar_note = pg_fetch_object($res, $row);
430 $new_statuscode = add_action($this->database, $similar_note,
431 $_POST['actionid'], $_POST['remark']);
432 if ($similar_note->notificationid == $note->notificationid)
434 $note->statuscode = $new_statuscode;
440 $note->statuscode = add_action($this->database, $note, $_POST['actionid'], $_POST['remark']);
442 $this->display_notification($note);
444 $this->notification_form($note);
445 $this->notification_list($note->objectid);
449 echo "<h1>Insufficient input to create page</h1>";
455 $notif_page = new notification_page("Gnucomo Notifications");
457 $notif_page->Showpage();