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.5 $
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.5 2007-11-21 14:38:06 arjen
40 The buttonbar at the top of each page is now a fixed 'div' element
41 instead of a framed page.
42 Contributed by Edwin Nadorp.
44 Revision 1.4 2007/01/11 13:44:29 arjen
45 Manually edit parameters.
46 View logs from abusing IP addresses.
48 Revision 1.3 2003/02/21 08:49:16 arjen
49 Keep a record of each time a notification
50 is displayed. Either on a listing or in detail.
52 Revision 1.2 2003/02/13 09:01:29 arjen
53 All web interface pages use the page class.
55 Revision 1.1 2003/02/05 09:48:14 arjen
56 Added display and handling of notifications
58 ******************************/
60 // RCSID = "$Id: notification.php,v 1.5 2007-11-21 14:38:06 arjen Exp $";
62 ini_set('include_path', '.:./classes:../phpclasses');
64 require_once('page.class.php');
66 function clientscripts()
70 <script type='text/ecmascript'>
72 function CheckRemark(f)
74 if (f.remark.value == "")
76 alert("Your remark is still empty");
88 * Add an action to the notification $note.
89 * The status of the notification may alter as a result.
92 function add_action($db, $note, $actionid, $remark)
94 $r = pg_exec($db, "SELECT statuscode FROM action WHERE actionid=CAST('" . $actionid."' AS BIGINT)");
95 $action = pg_fetch_object($r, 0);
97 if ($action->statuscode != "" && $note->statuscode != $action->statuscode)
99 // Update the status of the notification.
101 $note->statuscode = $action->statuscode;
103 pg_exec($db, "UPDATE notification SET statuscode='" . $note->statuscode
104 . "' WHERE notificationid = " . $note->notificationid);
107 // Add the action to the action_user table.
109 pg_exec($db, "INSERT INTO action_user (actionid, username, notificationid,
110 timestamp, statuscode, remarks) values ('$actionid', '"
111 . $_SESSION['username'] . "', '" . $note->notificationid
112 . "', '" . date('Y-m-d H:i:s') . "', '" . $note->statuscode
113 . "', '" . $remark . "')");
115 return $note->statuscode;
118 class notification_page extends page
121 function notification_list($objectid)
124 // Display a list of all notifications for this object['oid']
126 $res = pg_exec($this->database, "SELECT objectname FROM object WHERE objectid=" . $objectid);
127 $obj = pg_fetch_object($res, 0);
128 echo "<h1>Notifications for " . $obj->objectname . "</h1><hr>";
130 $res = pg_exec($this->database, "SELECT notificationid, timestamp, type_of_issueid,
132 FROM notification WHERE objectid= CAST ('"
133 . $objectid ."' AS BIGINT) AND statuscode != 'cls'"
134 . " ORDER BY notificationid");
137 echo '<tr><th>Time</th><th>Number</th><th>Issue</th><th>Status</th><th>Priority</th></tr>';
139 while ($row < pg_numrows($res))
141 $note = pg_fetch_object($res, $row);
142 $r = pg_exec($this->database, "SELECT name from type_of_issue WHERE type_of_issueid = CAST('"
143 . $note->type_of_issueid . "' AS BIGINT)");
144 $issue = pg_fetch_object($r, 0);
145 echo "<tr><td align='center'>\n";
146 echo $note->timestamp;
148 echo $note->notificationid;
150 echo "<a href='notification.php?notid=";
151 echo $note->notificationid;
156 echo $note->statuscode;
158 echo $note->priority;
162 //Save evidence that this notification was presented to the user.
163 //$note->statuscode = add_action($this->database, $note, 21,
164 // "This notification was displayed with others from the same object");
169 function display_notification($note)
171 $res = pg_exec($this->database, "SELECT objectname FROM object WHERE objectid= CAST ('" . $note->objectid . "' AS BIGINT)");
172 $obj = pg_fetch_object($res, 0);
173 echo "<h1>Notification " . $note->notificationid . " for " . $obj->objectname . "</h1><hr>";
174 echo "<script type='text/ecmascript'>document.getElementById('menu_title').innerHTML = '<h1>Notification " . $note->notificationid . " for " . $obj->objectname . "<\/h1>'</script><br>";
176 $r = pg_exec($this->database, "SELECT description FROM type_of_issue WHERE type_of_issueid = CAST ('"
177 . $note->type_of_issueid . "' AS BIGINT)");
178 $issue = pg_fetch_object($r, 0);
180 $r = pg_exec($this->database, "SELECT statusname FROM status
181 WHERE statuscode = '" . $note->statuscode . "'");
183 $status = pg_fetch_object($r, 0);
185 echo "Issue : " . $issue->description . ", Priority " . $note->priority . "<br>";
186 echo "Creation time : " . $note->timestamp . "<br>";
187 echo "Current status : " . $status->statusname . "<br>";
189 // List all actions that occurred on this notification
191 echo "<h2>Action history for notification " . $note->notificationid . "</h2>";
193 echo "<tr><th>Time</th><th>User</th><th>Remarks</th></tr>";
195 $r = pg_exec($this->database, "SELECT actionid, username, timestamp, remarks
196 FROM action_user WHERE notificationid= CAST ('"
197 . $note->notificationid . "' AS BIGINT )"
198 ." ORDER BY timestamp");
199 for ($row = 0; $row < pg_numrows($r); $row++)
201 $action_user = pg_fetch_object($r, $row);
203 echo "<tr><td class='time'>";
204 echo $action_user->timestamp;
206 echo $action_user->username;
208 echo htmlspecialchars(stripslashes($action_user->remarks));
213 // See if we can list any parameters for this notification
215 $r = pg_exec($this->database, "SELECT * FROM parameter WHERE paramid IN
216 ( SELECT paramid FROM parameter_notification
217 WHERE notificationid = CAST ('" . $note->notificationid
219 if (pg_numrows($r) > 0)
221 echo "<h2>Parameters involved in this notification</h2>";
223 echo "<tr><th>Class</th><th>Name</th><th>Description</th><th>History</th></tr>";
225 for ($row = 0; $row < pg_numrows($r); $row++)
227 $p = pg_fetch_object($r, $row);
228 $res = pg_exec($this->database, "SELECT * from history WHERE paramid= CAST('" . $p->paramid
229 . "' AS BIGINT) ORDER BY modified");
236 echo $p->description;
238 for ($hrow = 0; $hrow < pg_numrows($res); $hrow++)
240 $hist = pg_fetch_object($res, $hrow);
241 echo $hist->modified . " ";
242 echo $hist->change_nature . " ";
243 echo $hist->changed_property . " ";
244 echo $hist->new_value;
253 // See if we can list any log entries for this notification
255 $r = pg_exec($this->database, "SELECT * FROM log WHERE logid IN
256 ( SELECT logid FROM log_notification
257 WHERE notificationid = CAST ('"
258 . $note->notificationid . "' AS BIGINT)) ORDER BY object_timestamp");
259 if (pg_numrows($r) > 0)
261 echo "<h2>Log entries involved in this notification</h2>";
263 echo "<tr><th>Time</th><th>Service</th><th>Log entry</th></tr>";
265 for ($row = 0; $row < pg_numrows($r); $row++)
267 $p = pg_fetch_object($r, $row);
270 echo $p->object_timestamp;
272 echo $p->servicecode;
274 echo htmlentities($p->rawdata);
283 function notification_form($note)
286 * Depending on the state of the notification, specific actions
287 * are possible. One such actions determines a transition to
288 * the next state. The array $possible_action lists the state transitions
292 $possible_action = array
294 "opn" => array (3, 6, 7, 13),
295 "pen" => array (3, 6, 7, 8, 11, 18),
296 "inv" => array (3, 9),
297 "vrf" => array (12, 13),
301 echo "<h2>Enter a remark for the next action</h2>";
302 echo "<form method='post' onSubmit='return CheckRemark(this)' action=''>";
303 echo "<textarea name='remark' cols='30' rows='5'></textarea><br>";
305 /* Display a list of possible actions */
307 echo "<h2>Select one of the actions to take below</h2>";
311 foreach ($possible_action[$note->statuscode] as $act)
313 $action = pg_fetch_object(pg_exec("SELECT description FROM action WHERE actionid= CAST('"
314 . $act . "' AS BIGINT)"),0);
315 echo "<input type='radio' name='actionid'";
321 echo " value='$act'>" . $action->description . "<br>";
324 echo "<input type='submit' value='Submit action'>";
331 if ($_SERVER['REQUEST_METHOD'] == 'GET' && !empty($_GET['oid']))
334 // Display a list of all notifications for this object['oid']
336 $res = pg_exec($this->database, "SELECT objectname FROM object WHERE objectid=" . $_GET['oid']);
337 $obj = pg_fetch_object($res, 0);
338 echo "<script type='text/ecmascript'>document.getElementById('menu_title').innerHTML = '<h1>Notifications for " . $obj->objectname . "<\/h1>'</script><br>";
340 $res = pg_exec($this->database, "SELECT notificationid, timestamp, type_of_issueid,
342 FROM notification WHERE objectid= CAST ('"
343 . $_GET['oid'] ."' AS BIGINT) AND statuscode != 'cls'"
344 . " ORDER BY notificationid");
347 echo '<tr><th>Time</th><th>Number</th><th>Issue</th><th>Status</th><th>Priority</th></tr>';
349 while ($row < pg_numrows($res))
351 $note = pg_fetch_object($res, $row);
352 $r = pg_exec($this->database, "SELECT name from type_of_issue WHERE type_of_issueid = CAST('"
353 . $note->type_of_issueid . "' AS BIGINT)");
354 $issue = pg_fetch_object($r, 0);
355 echo "<tr><td align='center'>\n";
356 echo $note->timestamp;
358 echo $note->notificationid;
360 echo "<a href='notification.php?notid=";
361 echo $note->notificationid;
366 echo $note->statuscode;
368 echo $note->priority;
372 //Save evidence that this notification was presented to the user.
373 //$note->statuscode = add_action($this->database, $note, 21,
374 // "This notification was displayed with others from the same object");
378 else if ($_SERVER['REQUEST_METHOD'] == 'GET' && !empty($_GET['notid']))
382 // Display all information about a single notification['notid']
384 $local_sql = "SELECT * from notification
385 WHERE notificationid = CAST('" . $_GET['notid'] . "' AS BIGINT)";
386 $res = pg_exec($this->database, $local_sql);
387 $note = pg_fetch_object($res, 0);
389 //Gather proof that the notification has been presented
390 if ($note->statuscode == 'new')
392 $note->statuscode = add_action($this->database, $note, 2,
393 "Notification displayed in detail through web interface");
397 $note->statuscode = add_action($this->database, $note, 20,
398 "Notification redisplayed in detail through web interface");
400 $this->display_notification($note);
402 $this->notification_form($note);
403 $this->notification_list($note->objectid);
405 else if ($_SERVER['REQUEST_METHOD'] == 'POST' && !empty($_GET['notid']))
409 // Display all information about a single notification['notid']
411 $res = pg_exec($this->database, "SELECT * from notification
412 WHERE notificationid=" . $_GET['notid']);
413 $note = pg_fetch_object($res, 0);
415 $note->statuscode = add_action($this->database, $note, $_POST['actionid'], $_POST['remark']);
416 $this->display_notification($note);
418 $this->notification_form($note);
419 $this->notification_list($note->objectid);
423 echo "<h1>Insufficient input to create page</h1>";
429 $notif_page = new notification_page("Gnucomo Notifications");
431 $notif_page->Showpage();