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.3 $
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.3 2003-02-21 08:49:16 arjen
40 Keep a record of each time a notification
41 is displayed. Either on a listing or in detail.
43 Revision 1.2 2003/02/13 09:01:29 arjen
44 All web interface pages use the page class.
46 Revision 1.1 2003/02/05 09:48:14 arjen
47 Added display and handling of notifications
49 ******************************/
51 // RCSID = "$Id: notification.php,v 1.3 2003-02-21 08:49:16 arjen Exp $";
53 ini_set('include_path', '.:./classes:../phpclasses');
55 require_once('page.class.php');
57 function clientscripts()
61 <script language='JavaScript'>
63 function CheckRemark(f)
65 if (f.remark.value == "")
67 alert("Your remark is still empty");
79 * Add an action to the notification $note.
80 * The status of the notification may alter as a result.
83 function add_action($db, $note, $actionid, $remark)
85 $r = pg_exec($db, "SELECT statuscode FROM action WHERE actionid=CAST('" . $actionid."' AS BIGINT)");
86 $action = pg_fetch_object($r, 0);
88 if ($action->statuscode != "" && $note->statuscode != $action->statuscode)
90 // Update the status of the notification.
92 $note->statuscode = $action->statuscode;
94 pg_exec($db, "UPDATE notification SET statuscode='" . $note->statuscode
95 . "' WHERE notificationid = " . $note->notificationid);
98 // Add the action to the action_user table.
100 pg_exec($db, "INSERT INTO action_user (actionid, username, notificationid,
101 timestamp, statuscode, remarks) values ('$actionid', '"
102 . $_SESSION['username'] . "', '" . $note->notificationid
103 . "', '" . date('Y-m-d H:i:s') . "', '" . $note->statuscode
104 . "', '" . $remark . "')");
106 return $note->statuscode;
109 class notification_page extends page
112 function display_notification($note)
114 $res = pg_exec($this->database, "SELECT objectname FROM object WHERE objectid= CAST ('" . $note->objectid . "' AS BIGINT)");
115 $obj = pg_fetch_object($res, 0);
116 echo "<h1>Notification " . $note->notificationid . " for " . $obj->objectname . "</h1><hr>";
118 $r = pg_exec($this->database, "SELECT description FROM type_of_issue WHERE type_of_issueid = CAST ('"
119 . $note->type_of_issueid . "' AS BIGINT)");
120 $issue = pg_fetch_object($r, 0);
122 $r = pg_exec($this->database, "SELECT statusname FROM status
123 WHERE statuscode = '" . $note->statuscode . "'");
125 $status = pg_fetch_object($r, 0);
127 echo "Issue : " . $issue->description . ", Priority " . $note->priority . "<br>";
128 echo "Creation time : " . $note->timestamp . "<br>";
129 echo "Current status : " . $status->statusname . "<br>";
131 // List all actions that occurred on this notification
133 echo "<h2>Action history for notification " . $note->notificationid . "</h2>";
135 echo "<tr><th>Time</th><th>User</th><th>Remarks</th></tr>";
137 $r = pg_exec($this->database, "SELECT actionid, username, timestamp, remarks
138 FROM action_user WHERE notificationid= CAST ('"
139 . $note->notificationid . "' AS BIGINT )"
140 ." ORDER BY timestamp");
141 for ($row = 0; $row < pg_numrows($r); $row++)
143 $action_user = pg_fetch_object($r, $row);
145 echo "<tr><td class='time'>";
146 echo $action_user->timestamp;
148 echo $action_user->username;
150 echo htmlspecialchars(stripslashes($action_user->remarks));
155 // See if we can list any parameters for this notification
157 $r = pg_exec($this->database, "SELECT * FROM parameter WHERE paramid IN
158 ( SELECT paramid FROM parameter_notification
159 WHERE notificationid = CAST ('" . $note->notificationid
161 if (pg_numrows($r) > 0)
163 echo "<h2>Parameters involved in this notification</h2>";
165 echo "<tr><th>Class</th><th>Name</th><th>Description</th><th>History</th></tr>";
167 for ($row = 0; $row < pg_numrows($r); $row++)
169 $p = pg_fetch_object($r, $row);
170 $res = pg_exec($this->database, "SELECT * from history WHERE paramid= CAST('" . $p->paramid
171 . "' AS BIGINT) ORDER BY modified");
178 echo $p->description;
180 for ($hrow = 0; $hrow < pg_numrows($res); $hrow++)
182 $hist = pg_fetch_object($res, $hrow);
183 echo $hist->modified . " ";
184 echo $hist->change_nature . " ";
185 echo $hist->changed_property . " ";
186 echo $hist->new_value;
195 // See if we can list any log entries for this notification
197 $r = pg_exec($this->database, "SELECT * FROM log WHERE logid IN
198 ( SELECT logid FROM log_notification
199 WHERE notificationid = CAST ('"
200 . $note->notificationid . "' AS BIGINT))");
201 if (pg_numrows($r) > 0)
203 echo "<h2>Log entries involved in this notification</h2>";
205 echo "<tr><th>Time</th><th>Service</th><th>Log entry</th></tr>";
207 for ($row = 0; $row < pg_numrows($r); $row++)
209 $p = pg_fetch_object($r, $row);
212 echo $p->object_timestamp;
214 echo $p->servicecode;
225 function notification_form($note)
228 * Depending on the state of the notification, specific actions
229 * are possible. One such actions determines a transition to
230 * the next state. The array $possible_action lists the state transitions
234 $possible_action = array
236 "opn" => array (3, 6, 7),
237 "pen" => array (3, 6, 7, 8, 11, 18),
238 "inv" => array (3, 9),
239 "vrf" => array (12, 13),
243 echo "<h2>Enter a remark for the next action</h2>";
244 echo "<form method='post' onSubmit='return CheckRemark(this)'>";
245 echo "<textarea name='remark'></textarea><br>";
247 /* Display a list of possible actions */
249 echo "<h2>Select one of the actions to take below</h2>";
253 foreach ($possible_action[$note->statuscode] as $act)
255 $action = pg_fetch_object(pg_exec("SELECT description FROM action WHERE actionid= CAST('"
256 . $act . "' AS BIGINT)"),0);
257 echo "<input type='radio' name='actionid'";
261 echo " checked='on'";
263 echo " value='$act'>" . $action->description . "<br>";
266 echo "<input type='submit' value='Submit action'>";
273 if ($_SERVER['REQUEST_METHOD'] == 'GET' && !empty($_GET['oid']))
276 // Display a list of all notifications for this object['oid']
278 $res = pg_exec($this->database, "SELECT objectname FROM object WHERE objectid=" . $_GET['oid']);
279 $obj = pg_fetch_object($res, 0);
280 echo "<h1>Notifications for " . $obj->objectname . "</h1><hr>";
282 $res = pg_exec($this->database, "SELECT notificationid, timestamp, type_of_issueid,
284 FROM notification WHERE objectid= CAST ('"
285 . $_GET['oid'] ."' AS BIGINT) AND statuscode != 'cls'"
286 . " ORDER BY notificationid");
290 while ($row < pg_numrows($res))
292 $note = pg_fetch_object($res, $row);
293 $r = pg_exec($this->database, "SELECT name from type_of_issue WHERE type_of_issueid = CAST('"
294 . $note->type_of_issueid . "' AS BIGINT)");
295 $issue = pg_fetch_object($r, 0);
296 echo "<tr><td align='center'>\n";
297 echo $note->timestamp;
299 echo $note->notificationid;
301 echo "<a href='notification.php?notid=";
302 echo $note->notificationid;
307 echo $note->statuscode;
309 echo $note->priority;
313 //Save evidence that this notification was presented to the user.
314 $note->statuscode = add_action($this->database, $note, 21,
315 "This notification was displayed with others from the same object");
319 else if ($_SERVER['REQUEST_METHOD'] == 'GET' && !empty($_GET['notid']))
323 // Display all information about a single notification['notid']
325 $local_sql = "SELECT * from notification
326 WHERE notificationid = CAST('" . $_GET['notid'] . "' AS BIGINT)";
327 $res = pg_exec($this->database, $local_sql);
328 $note = pg_fetch_object($res, 0);
330 //Gather proof that the notification has been presented
331 if ($note->statuscode == 'new')
333 $note->statuscode = add_action($this->database, $note, 2,
334 "Notification displayed in detail through web interface");
338 $note->statuscode = add_action($this->database, $note, 20,
339 "Notification redisplayed in detail through web interface");
341 $this->display_notification($note);
343 $this->notification_form($note);
345 else if ($_SERVER['REQUEST_METHOD'] == 'POST' && !empty($_GET['notid']))
349 // Display all information about a single notification['notid']
351 $res = pg_exec($this->database, "SELECT * from notification
352 WHERE notificationid=" . $_GET['notid']);
353 $note = pg_fetch_object($res, 0);
355 $note->statuscode = add_action($this->database, $note, $_POST['actionid'], $_POST['remark']);
356 $this->display_notification($note);
358 $this->notification_form($note);
362 echo "<h1>Insufficient input to create page</h1>";
368 $notif_page = new notification_page("Gnucomo Notifications");
370 $notif_page->Showpage();