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.2 $
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 04, 2003
35 **************************************************************************/
37 /*****************************
38 $Log: notification.php,v $
39 Revision 1.2 2003-02-13 09:01:29 arjen
40 All web interface pages use the page class.
42 Revision 1.1 2003/02/05 09:48:14 arjen
43 Added display and handling of notifications
45 ******************************/
47 // RCSID = "$Id: notification.php,v 1.2 2003-02-13 09:01:29 arjen Exp $";
49 ini_set('include_path', '.:./classes:../phpclasses');
51 require_once('page.class.php');
53 function clientscripts()
57 <script language='JavaScript'>
59 function CheckRemark(f)
61 if (f.remark.value == "")
63 alert("Your remark is still empty");
75 * Add an action to the notification $note.
76 * The status of the notification may alter as a result.
79 function add_action($db, $note, $actionid, $remark)
81 $r = pg_exec($db, "SELECT statuscode FROM action WHERE actionid=" . $actionid);
82 $action = pg_fetch_object($r, 0);
84 if ($action->statuscode != "" && $note->statuscode != $action->statuscode)
86 // Update the status of the notification.
88 $note->statuscode = $action->statuscode;
90 pg_exec($db, "UPDATE notification SET statuscode='" . $note->statuscode
91 . "' WHERE notificationid = " . $note->notificationid);
94 // Add the action to the action_user table.
96 pg_exec($db, "INSERT INTO action_user (actionid, username, notificationid,
97 timestamp, statuscode, remarks) values ('$actionid', '"
98 . $_SESSION['username'] . "', '" . $note->notificationid
99 . "', '" . date('Y-m-d H:i:s') . "', '" . $note->statuscode
100 . "', '" . $remark . "')");
102 return $note->statuscode;
105 class notification_page extends page
108 function display_notification($note)
110 $res = pg_exec($this->database, "SELECT objectname FROM object WHERE objectid=" . $note->objectid);
111 $obj = pg_fetch_object($res, 0);
112 echo "<h1>Notification " . $note->notificationid . " for " . $obj->objectname . "</h1><hr>";
114 $r = pg_exec($this->database, "SELECT description from type_of_issue WHERE type_of_issueid ="
115 . $note->type_of_issueid);
116 $issue = pg_fetch_object($r, 0);
118 $r = pg_exec($this->database, "SELECT statusname FROM status
119 WHERE statuscode = '" . $note->statuscode . "'");
121 $status = pg_fetch_object($r, 0);
123 echo "Issue : " . $issue->description . ", Priority " . $note->priority . "<br>";
124 echo "Creation time : " . $note->timestamp . "<br>";
125 echo "Current status : " . $status->statusname . "<br>";
127 // List all actions that occurred on this notification
129 echo "<h2>Action history for notification " . $note->notificationid . "</h2>";
131 echo "<tr><th>Time</th><th>User</th><th>Remarks</th></tr>";
133 $r = pg_exec($this->database, "SELECT actionid, username, timestamp, remarks
134 FROM action_user WHERE notificationid=" . $note->notificationid
135 ." ORDER BY timestamp");
136 for ($row = 0; $row < pg_numrows($r); $row++)
138 $action_user = pg_fetch_object($r, $row);
141 echo $action_user->timestamp;
143 echo $action_user->username;
145 echo htmlspecialchars(stripslashes($action_user->remarks));
150 // See if we can list any parameters for this notification
152 $r = pg_exec($this->database, "SELECT * FROM parameter WHERE paramid IN
153 ( SELECT paramid FROM parameter_notification
154 WHERE notificationid = " . $note->notificationid . ")");
155 if (pg_numrows($r) > 0)
157 echo "<h2>Parameters involved in this notification</h2>";
159 echo "<tr><th>Class</th><th>Name</th><th>Description</th><th>History</th></tr>";
161 for ($row = 0; $row < pg_numrows($r); $row++)
163 $p = pg_fetch_object($r, $row);
164 $res = pg_exec($this->database, "SELECT * from history WHERE paramid=" . $p->paramid
165 . " ORDER BY modified");
172 echo $p->description;
174 for ($hrow = 0; $hrow < pg_numrows($res); $hrow++)
176 $hist = pg_fetch_object($res, $hrow);
177 echo $hist->modified . " ";
178 echo $hist->change_nature . " ";
179 echo $hist->changed_property . " ";
180 echo $hist->new_value;
189 // See if we can list any log entries for this notification
191 $r = pg_exec($this->database, "SELECT * FROM log WHERE logid IN
192 ( SELECT logid FROM log_notification
193 WHERE notificationid = " . $note->notificationid . ")");
194 if (pg_numrows($r) > 0)
196 echo "<h2>Log entries involved in this notification</h2>";
198 echo "<tr><th>Time</th><th>Service</th><th>Log entry</th></tr>";
200 for ($row = 0; $row < pg_numrows($r); $row++)
202 $p = pg_fetch_object($r, $row);
205 echo $p->object_timestamp;
207 echo $p->servicecode;
218 function notification_form($note)
221 * Depending on the state of the notification, specific actions
222 * are possible. One such actions determines a transition to
223 * the next state. The array $possible_action lists the state transitions
227 $possible_action = array
229 "opn" => array (3, 6, 7),
230 "pen" => array (3, 6, 7, 8, 11, 18),
231 "inv" => array (3, 9),
232 "vrf" => array (12, 13),
236 echo "<h2>Enter a remark for the next action</h2>";
237 echo "<form method='post' onSubmit='return CheckRemark(this)'>";
238 echo "<textarea name='remark'></textarea><br>";
240 /* Display a list of possible actions */
242 echo "<h2>Select on of the actions to take below</h2>";
246 foreach ($possible_action[$note->statuscode] as $act)
248 $action = pg_fetch_object(pg_exec("SELECT description FROM action WHERE actionid=$act"),0);
249 echo "<input type='radio' name='actionid'";
253 echo " checked='on'";
255 echo " value='$act'>" . $action->description . "<br>";
258 echo "<input type='submit' value='Submit action'>";
265 if ($_SERVER['REQUEST_METHOD'] == 'GET' && !empty($_GET['oid']))
268 // Display a list of all notifications for this object['oid']
270 $res = pg_exec($this->database, "SELECT objectname FROM object WHERE objectid=" . $_GET['oid']);
271 $obj = pg_fetch_object($res, 0);
272 echo "<h1>Notifications for " . $obj->objectname . "</h1><hr>";
274 $res = pg_exec($this->database, "SELECT notificationid, timestamp, type_of_issueid,
276 FROM notification WHERE objectid=" . $_GET['oid']
277 . " ORDER BY notificationid");
281 while ($row < pg_numrows($res))
283 $note = pg_fetch_object($res, $row);
284 $r = pg_exec($this->database, "SELECT name from type_of_issue WHERE type_of_issueid ="
285 . $note->type_of_issueid);
286 $issue = pg_fetch_object($r, 0);
287 echo "<tr><td align='center'>\n";
288 echo $note->timestamp;
290 echo $note->notificationid;
292 echo "<a href='notification.php?notid=";
293 echo $note->notificationid;
298 echo $note->statuscode;
300 echo $note->priority;
306 else if ($_SERVER['REQUEST_METHOD'] == 'GET' && !empty($_GET['notid']))
310 // Display all information about a single notification['notid']
312 $res = pg_exec($this->database, "SELECT * from notification
313 WHERE notificationid=" . $_GET['notid']);
314 $note = pg_fetch_object($res, 0);
316 if ($note->statuscode == 'new')
318 $note->statuscode = add_action($this->database, $note, 2, "Displayed through web interface");
321 $this->display_notification($note);
323 $this->notification_form($note);
325 else if ($_SERVER['REQUEST_METHOD'] == 'POST' && !empty($_GET['notid']))
329 // Display all information about a single notification['notid']
331 $res = pg_exec($this->database, "SELECT * from notification
332 WHERE notificationid=" . $_GET['notid']);
333 $note = pg_fetch_object($res, 0);
335 $note->statuscode = add_action($this->database, $note, $_POST['actionid'], $_POST['remark']);
336 $this->display_notification($note);
338 $this->notification_form($note);
342 echo "<h1>Insufficient input to create page</h1>";
348 $notif_page = new notification_page("Gnucomo Notifications");
350 $notif_page->Showpage();