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.4 $
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.4 2007-01-11 13:44:29 arjen
40 Manually edit parameters.
41 View logs from abusing IP addresses.
43 Revision 1.3 2003/02/21 08:49:16 arjen
44 Keep a record of each time a notification
45 is displayed. Either on a listing or in detail.
47 Revision 1.2 2003/02/13 09:01:29 arjen
48 All web interface pages use the page class.
50 Revision 1.1 2003/02/05 09:48:14 arjen
51 Added display and handling of notifications
53 ******************************/
55 // RCSID = "$Id: notification.php,v 1.4 2007-01-11 13:44:29 arjen Exp $";
57 ini_set('include_path', '.:./classes:../phpclasses');
59 require_once('page.class.php');
61 function clientscripts()
65 <script language='JavaScript'>
67 function CheckRemark(f)
69 if (f.remark.value == "")
71 alert("Your remark is still empty");
83 * Add an action to the notification $note.
84 * The status of the notification may alter as a result.
87 function add_action($db, $note, $actionid, $remark)
89 $r = pg_exec($db, "SELECT statuscode FROM action WHERE actionid=CAST('" . $actionid."' AS BIGINT)");
90 $action = pg_fetch_object($r, 0);
92 if ($action->statuscode != "" && $note->statuscode != $action->statuscode)
94 // Update the status of the notification.
96 $note->statuscode = $action->statuscode;
98 pg_exec($db, "UPDATE notification SET statuscode='" . $note->statuscode
99 . "' WHERE notificationid = " . $note->notificationid);
102 // Add the action to the action_user table.
104 pg_exec($db, "INSERT INTO action_user (actionid, username, notificationid,
105 timestamp, statuscode, remarks) values ('$actionid', '"
106 . $_SESSION['username'] . "', '" . $note->notificationid
107 . "', '" . date('Y-m-d H:i:s') . "', '" . $note->statuscode
108 . "', '" . $remark . "')");
110 return $note->statuscode;
113 class notification_page extends page
116 function notification_list($objectid)
119 // Display a list of all notifications for this object['oid']
121 $res = pg_exec($this->database, "SELECT objectname FROM object WHERE objectid=" . $objectid);
122 $obj = pg_fetch_object($res, 0);
123 echo "<h1>Notifications for " . $obj->objectname . "</h1><hr>";
125 $res = pg_exec($this->database, "SELECT notificationid, timestamp, type_of_issueid,
127 FROM notification WHERE objectid= CAST ('"
128 . $objectid ."' AS BIGINT) AND statuscode != 'cls'"
129 . " ORDER BY notificationid");
133 while ($row < pg_numrows($res))
135 $note = pg_fetch_object($res, $row);
136 $r = pg_exec($this->database, "SELECT name from type_of_issue WHERE type_of_issueid = CAST('"
137 . $note->type_of_issueid . "' AS BIGINT)");
138 $issue = pg_fetch_object($r, 0);
139 echo "<tr><td align='center'>\n";
140 echo $note->timestamp;
142 echo $note->notificationid;
144 echo "<a href='notification.php?notid=";
145 echo $note->notificationid;
150 echo $note->statuscode;
152 echo $note->priority;
156 //Save evidence that this notification was presented to the user.
157 //$note->statuscode = add_action($this->database, $note, 21,
158 // "This notification was displayed with others from the same object");
163 function display_notification($note)
165 $res = pg_exec($this->database, "SELECT objectname FROM object WHERE objectid= CAST ('" . $note->objectid . "' AS BIGINT)");
166 $obj = pg_fetch_object($res, 0);
167 echo "<h1>Notification " . $note->notificationid . " for " . $obj->objectname . "</h1><hr>";
169 $r = pg_exec($this->database, "SELECT description FROM type_of_issue WHERE type_of_issueid = CAST ('"
170 . $note->type_of_issueid . "' AS BIGINT)");
171 $issue = pg_fetch_object($r, 0);
173 $r = pg_exec($this->database, "SELECT statusname FROM status
174 WHERE statuscode = '" . $note->statuscode . "'");
176 $status = pg_fetch_object($r, 0);
178 echo "Issue : " . $issue->description . ", Priority " . $note->priority . "<br>";
179 echo "Creation time : " . $note->timestamp . "<br>";
180 echo "Current status : " . $status->statusname . "<br>";
182 // List all actions that occurred on this notification
184 echo "<h2>Action history for notification " . $note->notificationid . "</h2>";
186 echo "<tr><th>Time</th><th>User</th><th>Remarks</th></tr>";
188 $r = pg_exec($this->database, "SELECT actionid, username, timestamp, remarks
189 FROM action_user WHERE notificationid= CAST ('"
190 . $note->notificationid . "' AS BIGINT )"
191 ." ORDER BY timestamp");
192 for ($row = 0; $row < pg_numrows($r); $row++)
194 $action_user = pg_fetch_object($r, $row);
196 echo "<tr><td class='time'>";
197 echo $action_user->timestamp;
199 echo $action_user->username;
201 echo htmlspecialchars(stripslashes($action_user->remarks));
206 // See if we can list any parameters for this notification
208 $r = pg_exec($this->database, "SELECT * FROM parameter WHERE paramid IN
209 ( SELECT paramid FROM parameter_notification
210 WHERE notificationid = CAST ('" . $note->notificationid
212 if (pg_numrows($r) > 0)
214 echo "<h2>Parameters involved in this notification</h2>";
216 echo "<tr><th>Class</th><th>Name</th><th>Description</th><th>History</th></tr>";
218 for ($row = 0; $row < pg_numrows($r); $row++)
220 $p = pg_fetch_object($r, $row);
221 $res = pg_exec($this->database, "SELECT * from history WHERE paramid= CAST('" . $p->paramid
222 . "' AS BIGINT) ORDER BY modified");
229 echo $p->description;
231 for ($hrow = 0; $hrow < pg_numrows($res); $hrow++)
233 $hist = pg_fetch_object($res, $hrow);
234 echo $hist->modified . " ";
235 echo $hist->change_nature . " ";
236 echo $hist->changed_property . " ";
237 echo $hist->new_value;
246 // See if we can list any log entries for this notification
248 $r = pg_exec($this->database, "SELECT * FROM log WHERE logid IN
249 ( SELECT logid FROM log_notification
250 WHERE notificationid = CAST ('"
251 . $note->notificationid . "' AS BIGINT)) ORDER BY object_timestamp");
252 if (pg_numrows($r) > 0)
254 echo "<h2>Log entries involved in this notification</h2>";
256 echo "<tr><th>Time</th><th>Service</th><th>Log entry</th></tr>";
258 for ($row = 0; $row < pg_numrows($r); $row++)
260 $p = pg_fetch_object($r, $row);
263 echo $p->object_timestamp;
265 echo $p->servicecode;
267 echo htmlentities($p->rawdata);
276 function notification_form($note)
279 * Depending on the state of the notification, specific actions
280 * are possible. One such actions determines a transition to
281 * the next state. The array $possible_action lists the state transitions
285 $possible_action = array
287 "opn" => array (3, 6, 7, 13),
288 "pen" => array (3, 6, 7, 8, 11, 18),
289 "inv" => array (3, 9),
290 "vrf" => array (12, 13),
294 echo "<h2>Enter a remark for the next action</h2>";
295 echo "<form method='post' onSubmit='return CheckRemark(this)'>";
296 echo "<textarea name='remark'></textarea><br>";
298 /* Display a list of possible actions */
300 echo "<h2>Select one of the actions to take below</h2>";
304 foreach ($possible_action[$note->statuscode] as $act)
306 $action = pg_fetch_object(pg_exec("SELECT description FROM action WHERE actionid= CAST('"
307 . $act . "' AS BIGINT)"),0);
308 echo "<input type='radio' name='actionid'";
312 echo " checked='on'";
314 echo " value='$act'>" . $action->description . "<br>";
317 echo "<input type='submit' value='Submit action'>";
324 if ($_SERVER['REQUEST_METHOD'] == 'GET' && !empty($_GET['oid']))
327 // Display a list of all notifications for this object['oid']
329 $res = pg_exec($this->database, "SELECT objectname FROM object WHERE objectid=" . $_GET['oid']);
330 $obj = pg_fetch_object($res, 0);
331 echo "<h1>Notifications for " . $obj->objectname . "</h1><hr>";
333 $res = pg_exec($this->database, "SELECT notificationid, timestamp, type_of_issueid,
335 FROM notification WHERE objectid= CAST ('"
336 . $_GET['oid'] ."' AS BIGINT) AND statuscode != 'cls'"
337 . " ORDER BY notificationid");
341 while ($row < pg_numrows($res))
343 $note = pg_fetch_object($res, $row);
344 $r = pg_exec($this->database, "SELECT name from type_of_issue WHERE type_of_issueid = CAST('"
345 . $note->type_of_issueid . "' AS BIGINT)");
346 $issue = pg_fetch_object($r, 0);
347 echo "<tr><td align='center'>\n";
348 echo $note->timestamp;
350 echo $note->notificationid;
352 echo "<a href='notification.php?notid=";
353 echo $note->notificationid;
358 echo $note->statuscode;
360 echo $note->priority;
364 //Save evidence that this notification was presented to the user.
365 //$note->statuscode = add_action($this->database, $note, 21,
366 // "This notification was displayed with others from the same object");
370 else if ($_SERVER['REQUEST_METHOD'] == 'GET' && !empty($_GET['notid']))
374 // Display all information about a single notification['notid']
376 $local_sql = "SELECT * from notification
377 WHERE notificationid = CAST('" . $_GET['notid'] . "' AS BIGINT)";
378 $res = pg_exec($this->database, $local_sql);
379 $note = pg_fetch_object($res, 0);
381 //Gather proof that the notification has been presented
382 if ($note->statuscode == 'new')
384 $note->statuscode = add_action($this->database, $note, 2,
385 "Notification displayed in detail through web interface");
389 $note->statuscode = add_action($this->database, $note, 20,
390 "Notification redisplayed in detail through web interface");
392 $this->display_notification($note);
394 $this->notification_form($note);
395 $this->notification_list($note->objectid);
397 else if ($_SERVER['REQUEST_METHOD'] == 'POST' && !empty($_GET['notid']))
401 // Display all information about a single notification['notid']
403 $res = pg_exec($this->database, "SELECT * from notification
404 WHERE notificationid=" . $_GET['notid']);
405 $note = pg_fetch_object($res, 0);
407 $note->statuscode = add_action($this->database, $note, $_POST['actionid'], $_POST['remark']);
408 $this->display_notification($note);
410 $this->notification_form($note);
411 $this->notification_list($note->objectid);
415 echo "<h1>Insufficient input to create page</h1>";
421 $notif_page = new notification_page("Gnucomo Notifications");
423 $notif_page->Showpage();