Added display and handling of notifications
authorarjen <arjen>
Wed, 5 Feb 2003 09:48:14 +0000 (09:48 +0000)
committerarjen <arjen>
Wed, 5 Feb 2003 09:48:14 +0000 (09:48 +0000)
src/web/notification.php [new file with mode: 0644]
src/web/objects.php

diff --git a/src/web/notification.php b/src/web/notification.php
new file mode 100644 (file)
index 0000000..57a3c04
--- /dev/null
@@ -0,0 +1,349 @@
+<?php 
+
+/**************************************************************************
+**  (c) Copyright 2003, Andromeda Technology & Automation
+** This is free software; you can redistribute it and/or modify it under the
+** terms of the GNU General Public License, see the file COPYING.
+***************************************************************************
+** MODULE INFORMATION *
+***********************
+**      FILE NAME      : notification.php
+**      SYSTEM NAME    : Gnucomo - Gnu Computer Monitoring
+**      VERSION NUMBER : $Revision: 1.1 $
+**
+**  DESCRIPTION      : Display and handle notifications.
+**                     There are two major views to this page: either a list of
+**                     all notifications for an object or the display of a single
+**                     notification. In the 'single notification' view, actions
+**                     can be added to the notification and the status can be
+**                     changed as a result of those actions.
+**
+**                     Input: GET['oid']   - If set, list all notifications for object.
+**                            GET['notid'] - If set, display a single notification.
+**                            POST['notid']- If set, update the notification.
+**
+**  EXPORTED OBJECTS : 
+**  LOCAL    OBJECTS : 
+**  MODULES  USED    :
+***************************************************************************
+**  ADMINISTRATIVE INFORMATION *
+********************************
+**      ORIGINAL AUTHOR : Arjen Baart - arjen@andromeda.nl
+**      CREATION DATE   : Dec 12, 2002
+**      LAST UPDATE     : Feb 04, 2003
+**      MODIFICATIONS   : 
+**************************************************************************/
+
+/*****************************
+   $Log: notification.php,v $
+   Revision 1.1  2003-02-05 09:48:14  arjen
+   Added display and handling of notifications
+
+******************************/
+
+// RCSID = "$Id: notification.php,v 1.1 2003-02-05 09:48:14 arjen Exp $";
+
+ini_set('include_path', './classes:../phpclasses');
+
+require_once('page.class.php');
+
+function clientscripts()
+{
+?>
+
+<script language='JavaScript'>
+
+function CheckRemark(f)
+{
+   if (f.remark.value == "")
+   {
+      alert("Your remark is still empty");
+      return false;
+   }
+   return true;
+}
+
+</script>
+
+<?php
+}
+
+/*
+ *   Add an action to the notification $note.
+ *   The status of the notification may alter as a result.
+ */
+
+function add_action($db, $note, $actionid, $remark)
+{
+   $r = pg_exec($db, "SELECT statuscode FROM action WHERE actionid=" . $actionid);
+   $action = pg_fetch_object($r, 0);
+
+   if ($action->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 display_notification($note)
+   {
+      $res = pg_exec($this->database, "SELECT objectname FROM object WHERE objectid=" . $note->objectid);
+      $obj = pg_fetch_object($res, 0);
+      echo "<h1>Notification " . $note->notificationid . " for " . $obj->objectname . "</h1><hr>";
+
+      $r = pg_exec($this->database, "SELECT description from type_of_issue WHERE type_of_issueid ="
+                       . $note->type_of_issueid);
+      $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 . "<br>";
+      echo "Creation time : " . $note->timestamp . "<br>";
+      echo "Current status : " . $status->statusname . "<br>";
+
+      //  List all actions that occurred on this notification
+
+      echo "<h2>Action history for notification " . $note->notificationid . "</h2>";
+      echo "<table>";
+      echo "<tr><th>Time</th><th>User</th><th>Remarks</th></tr>";
+
+      $r = pg_exec($this->database, "SELECT actionid, username, timestamp, remarks
+                                     FROM action_user WHERE notificationid=" . $note->notificationid
+                                   ." ORDER BY timestamp");
+      for ($row = 0; $row < pg_numrows($r); $row++)
+      {
+         $action_user = pg_fetch_object($r, $row);
+
+         echo "<tr><td>";
+         echo $action_user->timestamp;
+         echo "</td><td>";
+         echo $action_user->username;
+         echo "</td><td>";
+         echo htmlspecialchars(stripslashes($action_user->remarks));
+         echo "</td></tr>";
+      }
+      echo "</table>";
+
+      //  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 = " . $note->notificationid . ")");
+      if (pg_numrows($r) > 0)
+      {
+         echo "<h2>Parameters involved in this notification</h2>";
+         echo "<table>";
+         echo "<tr><th>Class</th><th>Name</th><th>Description</th><th>History</th></tr>";
+
+         for ($row = 0; $row < pg_numrows($r); $row++)
+         {
+            $p = pg_fetch_object($r, $row);
+            $res = pg_exec($this->database, "SELECT * from history WHERE paramid=" . $p->paramid
+                                            . " ORDER BY modified");
+
+            echo "<tr><td>";
+            echo $p->class;
+            echo "</td><td>";
+            echo $p->name;
+            echo "</td><td>";
+            echo $p->description;
+            echo "</td><td>";
+            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 "<br>";
+            }
+            echo "</td></tr>";
+
+         }
+         echo "</table>";
+      }
+
+      //  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 = " . $note->notificationid . ")");
+      if (pg_numrows($r) > 0)
+      {
+         echo "<h2>Log entries involved in this notification</h2>";
+         echo "<table>";
+         echo "<tr><th>Time</th><th>Service</th><th>Log entry</th></tr>";
+
+         for ($row = 0; $row < pg_numrows($r); $row++)
+         {
+            $p = pg_fetch_object($r, $row);
+
+            echo "<tr><td>";
+            echo $p->object_timestamp;
+            echo "</td><td>";
+            echo $p->servicecode;
+            echo "</td><td>";
+            echo $p->rawdata;
+            echo "</td></tr>";
+
+         }
+         echo "</table>";
+      }
+
+   }
+
+   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),
+         "pen" => array (3, 6, 7, 8, 11, 18),
+         "inv" => array (3, 9),
+         "vrf" => array (12, 13),
+         "cls" => array (19)
+      );
+
+      echo "<h2>Enter a remark for the next action</h2>";
+      echo "<form method='post' onSubmit='return CheckRemark(this)'>";
+      echo "<textarea name='remark'></textarea><br>";
+
+      /*  Display a list of possible actions */
+
+      echo "<h2>Select on of the actions to take below</h2>";
+
+      $first = true;
+
+      foreach ($possible_action[$note->statuscode] as $act)
+      {
+         $action = pg_fetch_object(pg_exec("SELECT description FROM action WHERE actionid=$act"),0);
+         echo "<input type='radio' name='actionid'";
+         if ($first)
+         {
+            $first = false;
+            echo " checked='on'";
+         }
+         echo " value='$act'>" . $action->description . "<br>";
+      }
+
+      echo "<input type='submit' value='Submit action'>";
+      echo "</form>";
+   }
+
+   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 "<h1>Notifications for " . $obj->objectname . "</h1><hr>";
+
+         $res = pg_exec($this->database, "SELECT notificationid, timestamp, type_of_issueid,
+                                              statuscode, priority
+                                          FROM notification WHERE objectid=" . $_GET['oid']
+                                         . " ORDER BY notificationid");
+
+         echo "<table>";
+         $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 ="
+                          . $note->type_of_issueid);
+            $issue = pg_fetch_object($r, 0);
+            echo "<tr><td align='center'>\n";
+            echo $note->timestamp;
+            echo "</td><td>";
+            echo $note->notificationid;
+            echo "</td><td>";
+            echo "<a href='notification.php?notid=";
+            echo $note->notificationid;
+            echo "'>";
+            echo $issue->name;
+            echo "</a>";
+            echo "</td><td>";
+            echo $note->statuscode;
+            echo "</td><td>";
+            echo $note->priority;
+            echo "</td></tr>\n";
+            $row++;
+         }
+         echo "</table>";
+      }
+      else if ($_SERVER['REQUEST_METHOD'] == 'GET' && !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 ($note->statuscode == 'new')
+         {
+            $note->statuscode = add_action($this->database, $note, 2, "Displayed through web interface");
+         }
+
+         $this->display_notification($note);
+         echo "<hr>";
+         $this->notification_form($note);
+      }
+      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);
+
+         $note->statuscode = add_action($this->database, $note, $_POST['actionid'], $_POST['remark']);
+         $this->display_notification($note);
+         echo "<hr>";
+         $this->notification_form($note);
+      }
+      else
+      {
+         echo "<h1>Insufficient input to create page</h1>";
+         phpinfo();
+      }
+   }
+}
+
+$notif_page = new notification_page("Gnucomo Notifications");
+
+$notif_page->Showpage();
+
+?>
index 27cd03c..33a90e0 100644 (file)
@@ -1,16 +1,40 @@
 <?php 
 
 /**************************************************************************
+**  (c) Copyright 2003, Andromeda Technology & Automation
 ** This is free software; you can redistribute it and/or modify it under the
 ** terms of the GNU General Public License, see the file COPYING.
-***************************************************************************/
-
-/*
- *
- * Objects Administration page.
- * Input parameters: action (POST) : empty, 'Create'
- *                   objname (POST) : name of the object to create or remove
- */
+***************************************************************************
+** MODULE INFORMATION *
+***********************
+**      FILE NAME      : objects.php
+**      SYSTEM NAME    : Gnucomo - Gnu Computer Monitoring
+**      VERSION NUMBER : $Revision: 1.2 $
+**
+**  DESCRIPTION      : Objects Administration page.
+**                     Input parameters: action (POST) : empty, 'Create'
+**                                      objname (POST) : name of the object to create or remove
+**
+**  EXPORTED OBJECTS : 
+**  LOCAL    OBJECTS : 
+**  MODULES  USED    :
+***************************************************************************
+**  ADMINISTRATIVE INFORMATION *
+********************************
+**      ORIGINAL AUTHOR : Arjen Baart - arjen@andromeda.nl
+**      CREATION DATE   : Dec 04, 2002
+**      LAST UPDATE     : Feb 03, 2003
+**      MODIFICATIONS   : 
+**************************************************************************/
+
+/*****************************
+   $Log: objects.php,v $
+   Revision 1.2  2003-02-05 09:48:14  arjen
+   Added display and handling of notifications
+
+******************************/
+
+// RCSID = "$Id: objects.php,v 1.2 2003-02-05 09:48:14 arjen Exp $";
 
 session_start();
 require_once('classes/gnucomo_config.php');
@@ -93,6 +117,12 @@ else
       $r = pg_fetch_object($r, 0);
 
       $nr_params = $r->count;
+
+      $r = pg_exec ($conn, "SELECT count(notificationid) FROM notification WHERE objectid='"
+                           . $u->objectid . "'");
+      $r = pg_fetch_object($r, 0);
+
+      $nr_notifications = $r->count;
       ?>
       <tr><td align='center'><img src='server.png'><br>
              <b><?php echo $u->objectname ?></b>
@@ -101,6 +131,8 @@ else
       </td><td>
           <?php echo $nr_params?> <a href='parameter.php?oid=<?php echo $u->objectid?>'>Parameters</a>
       </td><td>
+          <?php echo $nr_notifications?> <a href='notification.php?oid=<?php echo $u->objectid?>'>Notifications</a>
+      </td><td>
           <form action='objects.php' method='post' onSubmit='return CheckRemove(this)'>
               <input type='hidden' name='objectname' value='<?php echo $u->objectname ?>'>
               <input type='submit' name='action' value='Remove'>