statuscode != "" && $note->statuscode != $action->statuscode)
{
// Update the status of the notification.
$note->statuscode = $action->statuscode;
pg_exec($db, "UPDATE notification SET statuscode='" . $note->statuscode
. "' WHERE notificationid = " . $note->notificationid);
}
// Add the action to the action_user table.
pg_exec($db, "INSERT INTO action_user (actionid, username, notificationid,
timestamp, statuscode, remarks) values ('$actionid', '"
. $_SESSION['username'] . "', '" . $note->notificationid
. "', '" . date('Y-m-d H:i:s') . "', '" . $note->statuscode
. "', '" . $remark . "')");
return $note->statuscode;
}
class notification_page extends page
{
function notification_list($objectid)
{
// Display a list of all notifications for this object['oid']
$res = pg_exec($this->database, "SELECT objectname FROM object WHERE objectid=" . $objectid);
$obj = pg_fetch_object($res, 0);
echo "
Notifications for " . $obj->objectname . "
";
$res = pg_exec($this->database, "SELECT notificationid, timestamp, type_of_issueid,
statuscode, priority
FROM notification WHERE objectid= CAST ('"
. $objectid ."' AS BIGINT) AND statuscode != 'cls'"
. " ORDER BY notificationid");
echo "";
echo 'Time | Number | Issue | Status | Priority |
';
$row = 0;
while ($row < pg_num_rows($res))
{
$note = pg_fetch_object($res, $row);
$r = pg_exec($this->database, "SELECT name from type_of_issue WHERE type_of_issueid = CAST('"
. $note->type_of_issueid . "' AS BIGINT)");
$issue = pg_fetch_object($r, 0);
echo "\n";
echo $note->timestamp;
echo " | ";
echo $note->notificationid;
echo " | ";
echo "";
echo $issue->name;
echo "";
echo " | ";
echo $note->statuscode;
echo " | ";
echo $note->priority;
echo " |
\n";
$row++;
//Save evidence that this notification was presented to the user.
//$note->statuscode = add_action($this->database, $note, 21,
// "This notification was displayed with others from the same object");
}
echo "
";
}
function display_notification($note)
{
$res = pg_exec($this->database, "SELECT objectname FROM object WHERE objectid= CAST ('" . $note->objectid . "' AS BIGINT)");
$obj = pg_fetch_object($res, 0);
echo "Notification " . $note->notificationid . " for " . $obj->objectname . "
";
echo "
";
$r = pg_exec($this->database, "SELECT description FROM type_of_issue WHERE type_of_issueid = CAST ('"
. $note->type_of_issueid . "' AS BIGINT)");
$issue = pg_fetch_object($r, 0);
$r = pg_exec($this->database, "SELECT statusname FROM status
WHERE statuscode = '" . $note->statuscode . "'");
$status = pg_fetch_object($r, 0);
echo "Issue : " . $issue->description . ", Priority " . $note->priority . "
";
echo "Creation time : " . $note->timestamp . "
";
echo "Current status : " . $status->statusname . "
";
// List all actions that occurred on this notification
echo "Action history for notification " . $note->notificationid . "
";
echo "";
echo "Time | User | Remarks |
";
$r = pg_exec($this->database, "SELECT actionid, username, timestamp, remarks
FROM action_user WHERE notificationid= CAST ('"
. $note->notificationid . "' AS BIGINT )"
." ORDER BY timestamp");
for ($row = 0; $row < pg_numrows($r); $row++)
{
$action_user = pg_fetch_object($r, $row);
echo "";
echo $action_user->timestamp;
echo " | ";
echo $action_user->username;
echo " | ";
echo htmlspecialchars(stripslashes($action_user->remarks));
echo " |
";
}
echo "
";
// See if we can list any parameters for this notification
$r = pg_exec($this->database, "SELECT * FROM parameter WHERE paramid IN
( SELECT paramid FROM parameter_notification
WHERE notificationid = CAST ('" . $note->notificationid
. "' AS BIGINT) )");
if (pg_numrows($r) > 0)
{
echo "Parameters involved in this notification
";
echo "";
echo "Class | Name | Description | History |
";
for ($row = 0; $row < pg_numrows($r); $row++)
{
$p = pg_fetch_object($r, $row);
$res = pg_exec($this->database, "SELECT * from history WHERE paramid= CAST('" . $p->paramid
. "' AS BIGINT) ORDER BY modified");
echo "";
echo $p->class;
echo " | ";
echo $p->name;
echo " | ";
echo $p->description;
echo " | ";
for ($hrow = 0; $hrow < pg_numrows($res); $hrow++)
{
$hist = pg_fetch_object($res, $hrow);
echo $hist->modified . " ";
echo $hist->change_nature . " ";
echo $hist->changed_property . " ";
echo $hist->new_value;
echo " ";
}
echo " |
";
}
echo "
";
}
// See if we can list any log entries for this notification
$r = pg_exec($this->database, "SELECT * FROM log WHERE logid IN
( SELECT logid FROM log_notification
WHERE notificationid = CAST ('"
. $note->notificationid . "' AS BIGINT)) ORDER BY object_timestamp");
if (pg_numrows($r) > 0)
{
echo "Log entries involved in this notification
";
echo "";
echo "Time | Service | Log entry |
";
for ($row = 0; $row < pg_numrows($r); $row++)
{
$p = pg_fetch_object($r, $row);
echo "";
echo $p->object_timestamp;
echo " | ";
echo $p->servicecode;
echo " | ";
echo htmlentities($p->rawdata);
echo " |
";
}
echo "
";
}
}
function notification_form($note)
{
/*
* Depending on the state of the notification, specific actions
* are possible. One such actions determines a transition to
* the next state. The array $possible_action lists the state transitions
* for each state.
*/
$possible_action = array
(
"opn" => array (3, 6, 7, 13),
"pen" => array (3, 6, 7, 8, 11, 18),
"inv" => array (3, 9),
"vrf" => array (12, 13),
"cls" => array (19)
);
echo "Enter a remark for the next action
";
echo "";
}
function Body()
{
if ($_SERVER['REQUEST_METHOD'] == 'GET' && !empty($_GET['oid']))
{
// Display a list of all notifications for this object['oid']
$res = pg_exec($this->database, "SELECT objectname FROM object WHERE objectid=" . $_GET['oid']);
$obj = pg_fetch_object($res, 0);
echo "
";
$res = pg_exec($this->database, "SELECT notificationid, timestamp, type_of_issueid,
statuscode, priority
FROM notification WHERE objectid= CAST ('"
. $_GET['oid'] ."' AS BIGINT) AND statuscode != 'cls'"
. " ORDER BY notificationid");
echo "";
echo 'Time | Number | Issue | Status | Priority |
';
$row = 0;
while ($row < pg_numrows($res))
{
$note = pg_fetch_object($res, $row);
$r = pg_exec($this->database, "SELECT name from type_of_issue WHERE type_of_issueid = CAST('"
. $note->type_of_issueid . "' AS BIGINT)");
$issue = pg_fetch_object($r, 0);
echo "\n";
echo $note->timestamp;
echo " | ";
echo $note->notificationid;
echo " | ";
echo "";
echo $issue->name;
echo "";
echo " | ";
echo $note->statuscode;
echo " | ";
echo $note->priority;
echo " |
\n";
$row++;
//Save evidence that this notification was presented to the user.
//$note->statuscode = add_action($this->database, $note, 21,
// "This notification was displayed with others from the same object");
}
echo "
";
}
else if ($_SERVER['REQUEST_METHOD'] == 'GET' && !empty($_GET['notid']))
{
clientscripts();
// Display all information about a single notification['notid']
$local_sql = "SELECT * from notification
WHERE notificationid = CAST('" . $_GET['notid'] . "' AS BIGINT)";
$res = pg_exec($this->database, $local_sql);
$note = pg_fetch_object($res, 0);
//Gather proof that the notification has been presented
if ($note->statuscode == 'new')
{
$note->statuscode = add_action($this->database, $note, 2,
"Notification displayed in detail through web interface");
}
else
{
$note->statuscode = add_action($this->database, $note, 20,
"Notification redisplayed in detail through web interface");
}
$this->display_notification($note);
echo "
";
$this->notification_form($note);
$this->notification_list($note->objectid);
}
else if ($_SERVER['REQUEST_METHOD'] == 'POST' && !empty($_GET['notid']))
{
clientscripts();
// Display all information about a single notification['notid']
$res = pg_exec($this->database, "SELECT * from notification
WHERE notificationid=" . $_GET['notid']);
$note = pg_fetch_object($res, 0);
if (!empty($_POST['act_on_all']))
{
// Perform the action on all notifications with the same object and issue.
$res = pg_exec($this->database, "SELECT notificationid, timestamp, type_of_issueid, statuscode
FROM notification WHERE objectid= CAST ('"
. $note->objectid ."' AS BIGINT) AND statuscode != 'cls'
AND type_of_issueid = '" . $note->type_of_issueid
. "' ORDER BY notificationid");
for ($row = 0; $row < pg_num_rows($res); $row++)
{
$similar_note = pg_fetch_object($res, $row);
$new_statuscode = add_action($this->database, $similar_note,
$_POST['actionid'], $_POST['remark']);
if ($similar_note->notificationid == $note->notificationid)
{
$note->statuscode = $new_statuscode;
}
}
}
else
{
$note->statuscode = add_action($this->database, $note, $_POST['actionid'], $_POST['remark']);
}
$this->display_notification($note);
echo "
";
$this->notification_form($note);
$this->notification_list($note->objectid);
}
else
{
echo "Insufficient input to create page
";
phpinfo();
}
}
}
$notif_page = new notification_page("Gnucomo Notifications");
$notif_page->Showpage();
?>