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.1 $
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.1 2003-02-05 09:48:14 arjen
40 Added display and handling of notifications
42 ******************************/
44 // RCSID = "$Id: notification.php,v 1.1 2003-02-05 09:48:14 arjen Exp $";
46 ini_set('include_path', './classes:../phpclasses');
48 require_once('page.class.php');
50 function clientscripts()
54 <script language='JavaScript'>
56 function CheckRemark(f)
58 if (f.remark.value == "")
60 alert("Your remark is still empty");
72 * Add an action to the notification $note.
73 * The status of the notification may alter as a result.
76 function add_action($db, $note, $actionid, $remark)
78 $r = pg_exec($db, "SELECT statuscode FROM action WHERE actionid=" . $actionid);
79 $action = pg_fetch_object($r, 0);
81 if ($action->statuscode != "" && $note->statuscode != $action->statuscode)
83 // Update the status of the notification.
85 $note->statuscode = $action->statuscode;
87 pg_exec($db, "UPDATE notification SET statuscode='" . $note->statuscode
88 . "' WHERE notificationid = " . $note->notificationid);
91 // Add the action to the action_user table.
93 pg_exec($db, "INSERT INTO action_user (actionid, username, notificationid,
94 timestamp, statuscode, remarks) values ('$actionid', '"
95 . $_SESSION['username'] . "', '" . $note->notificationid
96 . "', '" . date('Y-m-d H:i:s') . "', '" . $note->statuscode
97 . "', '" . $remark . "')");
99 return $note->statuscode;
102 class notification_page extends page
105 function display_notification($note)
107 $res = pg_exec($this->database, "SELECT objectname FROM object WHERE objectid=" . $note->objectid);
108 $obj = pg_fetch_object($res, 0);
109 echo "<h1>Notification " . $note->notificationid . " for " . $obj->objectname . "</h1><hr>";
111 $r = pg_exec($this->database, "SELECT description from type_of_issue WHERE type_of_issueid ="
112 . $note->type_of_issueid);
113 $issue = pg_fetch_object($r, 0);
115 $r = pg_exec($this->database, "SELECT statusname FROM status
116 WHERE statuscode = '" . $note->statuscode . "'");
118 $status = pg_fetch_object($r, 0);
120 echo "Issue : " . $issue->description . ", Priority " . $note->priority . "<br>";
121 echo "Creation time : " . $note->timestamp . "<br>";
122 echo "Current status : " . $status->statusname . "<br>";
124 // List all actions that occurred on this notification
126 echo "<h2>Action history for notification " . $note->notificationid . "</h2>";
128 echo "<tr><th>Time</th><th>User</th><th>Remarks</th></tr>";
130 $r = pg_exec($this->database, "SELECT actionid, username, timestamp, remarks
131 FROM action_user WHERE notificationid=" . $note->notificationid
132 ." ORDER BY timestamp");
133 for ($row = 0; $row < pg_numrows($r); $row++)
135 $action_user = pg_fetch_object($r, $row);
138 echo $action_user->timestamp;
140 echo $action_user->username;
142 echo htmlspecialchars(stripslashes($action_user->remarks));
147 // See if we can list any parameters for this notification
149 $r = pg_exec($this->database, "SELECT * FROM parameter WHERE paramid IN
150 ( SELECT paramid FROM parameter_notification
151 WHERE notificationid = " . $note->notificationid . ")");
152 if (pg_numrows($r) > 0)
154 echo "<h2>Parameters involved in this notification</h2>";
156 echo "<tr><th>Class</th><th>Name</th><th>Description</th><th>History</th></tr>";
158 for ($row = 0; $row < pg_numrows($r); $row++)
160 $p = pg_fetch_object($r, $row);
161 $res = pg_exec($this->database, "SELECT * from history WHERE paramid=" . $p->paramid
162 . " ORDER BY modified");
169 echo $p->description;
171 for ($hrow = 0; $hrow < pg_numrows($res); $hrow++)
173 $hist = pg_fetch_object($res, $hrow);
174 echo $hist->modified . " ";
175 echo $hist->change_nature . " ";
176 echo $hist->changed_property . " ";
177 echo $hist->new_value;
186 // See if we can list any log entries for this notification
188 $r = pg_exec($this->database, "SELECT * FROM log WHERE logid IN
189 ( SELECT logid FROM log_notification
190 WHERE notificationid = " . $note->notificationid . ")");
191 if (pg_numrows($r) > 0)
193 echo "<h2>Log entries involved in this notification</h2>";
195 echo "<tr><th>Time</th><th>Service</th><th>Log entry</th></tr>";
197 for ($row = 0; $row < pg_numrows($r); $row++)
199 $p = pg_fetch_object($r, $row);
202 echo $p->object_timestamp;
204 echo $p->servicecode;
215 function notification_form($note)
218 * Depending on the state of the notification, specific actions
219 * are possible. One such actions determines a transition to
220 * the next state. The array $possible_action lists the state transitions
224 $possible_action = array
226 "opn" => array (3, 6, 7),
227 "pen" => array (3, 6, 7, 8, 11, 18),
228 "inv" => array (3, 9),
229 "vrf" => array (12, 13),
233 echo "<h2>Enter a remark for the next action</h2>";
234 echo "<form method='post' onSubmit='return CheckRemark(this)'>";
235 echo "<textarea name='remark'></textarea><br>";
237 /* Display a list of possible actions */
239 echo "<h2>Select on of the actions to take below</h2>";
243 foreach ($possible_action[$note->statuscode] as $act)
245 $action = pg_fetch_object(pg_exec("SELECT description FROM action WHERE actionid=$act"),0);
246 echo "<input type='radio' name='actionid'";
250 echo " checked='on'";
252 echo " value='$act'>" . $action->description . "<br>";
255 echo "<input type='submit' value='Submit action'>";
262 if ($_SERVER['REQUEST_METHOD'] == 'GET' && !empty($_GET['oid']))
265 // Display a list of all notifications for this object['oid']
267 $res = pg_exec($this->database, "SELECT objectname FROM object WHERE objectid=" . $_GET['oid']);
268 $obj = pg_fetch_object($res, 0);
269 echo "<h1>Notifications for " . $obj->objectname . "</h1><hr>";
271 $res = pg_exec($this->database, "SELECT notificationid, timestamp, type_of_issueid,
273 FROM notification WHERE objectid=" . $_GET['oid']
274 . " ORDER BY notificationid");
278 while ($row < pg_numrows($res))
280 $note = pg_fetch_object($res, $row);
281 $r = pg_exec($this->database, "SELECT name from type_of_issue WHERE type_of_issueid ="
282 . $note->type_of_issueid);
283 $issue = pg_fetch_object($r, 0);
284 echo "<tr><td align='center'>\n";
285 echo $note->timestamp;
287 echo $note->notificationid;
289 echo "<a href='notification.php?notid=";
290 echo $note->notificationid;
295 echo $note->statuscode;
297 echo $note->priority;
303 else if ($_SERVER['REQUEST_METHOD'] == 'GET' && !empty($_GET['notid']))
307 // Display all information about a single notification['notid']
309 $res = pg_exec($this->database, "SELECT * from notification
310 WHERE notificationid=" . $_GET['notid']);
311 $note = pg_fetch_object($res, 0);
313 if ($note->statuscode == 'new')
315 $note->statuscode = add_action($this->database, $note, 2, "Displayed through web interface");
318 $this->display_notification($note);
320 $this->notification_form($note);
322 else if ($_SERVER['REQUEST_METHOD'] == 'POST' && !empty($_GET['notid']))
326 // Display all information about a single notification['notid']
328 $res = pg_exec($this->database, "SELECT * from notification
329 WHERE notificationid=" . $_GET['notid']);
330 $note = pg_fetch_object($res, 0);
332 $note->statuscode = add_action($this->database, $note, $_POST['actionid'], $_POST['remark']);
333 $this->display_notification($note);
335 $this->notification_form($note);
339 echo "<h1>Insufficient input to create page</h1>";
345 $notif_page = new notification_page("Gnucomo Notifications");
347 $notif_page->Showpage();