Use the new object_statistics table.
[gnucomo.git] / src / web / objects.php
index d7d7c33..7222e7b 100644 (file)
@@ -1,4 +1,4 @@
-<?php 
+<?php
 
 /**************************************************************************
 **  (c) Copyright 2003, Andromeda Technology & Automation
@@ -9,7 +9,7 @@
 ***********************
 **      FILE NAME      : objects.php
 **      SYSTEM NAME    : Gnucomo - Gnu Computer Monitoring
-**      VERSION NUMBER : $Revision: 1.5 $
+**      VERSION NUMBER : $Revision: 1.7 $
 **
 **  DESCRIPTION      : Objects Administration page.
 **                     Input parameters: action (POST) : empty, 'Create'
 ********************************
 **      ORIGINAL AUTHOR : Arjen Baart - arjen@andromeda.nl
 **      CREATION DATE   : Dec 04, 2002
-**      LAST UPDATE     : Feb 08, 2003
+**      LAST UPDATE     : Feb 14, 2003
 **      MODIFICATIONS   : 
 **************************************************************************/
 
 /*****************************
    $Log: objects.php,v $
-   Revision 1.5  2003-02-13 09:01:29  arjen
+   Revision 1.7  2003-07-15 11:02:25  arjen
+   Use the new object_statistics table.
+
+   Revision 1.6  2003/02/21 08:46:58  arjen
+   Improved the table layout.
+
+   Revision 1.5  2003/02/13 09:01:29  arjen
    All web interface pages use the page class.
 
    Revision 1.4  2003/02/13 08:48:23  arjen
@@ -46,7 +52,7 @@
 
 ******************************/
 
-// RCSID = "$Id: objects.php,v 1.5 2003-02-13 09:01:29 arjen Exp $";
+// RCSID = "$Id: objects.php,v 1.7 2003-07-15 11:02:25 arjen Exp $";
 
 ini_set('include_path', '.:./classes:../phpclasses');
 
@@ -85,6 +91,45 @@ function CheckRemove(f)
 class object_page extends page
 {
 
+   var $nr_parameters, $removed_parameters;
+   var $nr_notifications, $closed_notifications;
+   var $nr_logs;
+
+   function GatherStatistics($objectid)
+   {
+      //  Gather statistics on parameters
+
+      $r = pg_exec ($this->database, "SELECT statvalue FROM object_statistics WHERE objectid=CAST('"
+                           . $objectid . "' AS BIGINT) AND statname='parameters'");
+      $stat = pg_fetch_object($r, 0);
+      $this->nr_parameters = $stat->statvalue;
+
+      $r = pg_exec ($this->database, "SELECT statvalue FROM object_statistics WHERE objectid=CAST('"
+                           . $objectid . "' AS BIGINT) AND statname='removed_parameters'");
+      $stat = pg_fetch_object($r, 0);
+      $this->removed_parameters = $stat->statvalue;
+
+      //  Gather statistics on notifications
+
+      $r = pg_exec ($this->database, "SELECT statvalue FROM object_statistics WHERE objectid=CAST('"
+                           . $objectid . "' AS BIGINT) AND statname='notifications'");
+      $stat = pg_fetch_object($r, 0);
+      $this->nr_notifications = $stat->statvalue;
+
+      $r = pg_exec ($this->database, "SELECT statvalue FROM object_statistics WHERE objectid=CAST('"
+                           . $objectid . "' AS BIGINT) AND statname='closed_notifications'");
+      $stat = pg_fetch_object($r, 0);
+      $this->closed_notifications = $stat->statvalue;
+
+      //  Gather statistics on log entries
+
+      $r = pg_exec ($this->database, "SELECT statvalue FROM object_statistics WHERE objectid=CAST('"
+                           . $objectid . "' AS BIGINT) AND statname='logs'");
+      $stat = pg_fetch_object($r, 0);
+      $this->nr_logs = $stat->statvalue;
+
+   }
+
    function Body()
    {
       clientscripts();
@@ -104,39 +149,46 @@ class object_page extends page
 
    $res = pg_exec($this->database, "SELECT objectid,objectname, log_count, notification_count
                                     FROM object ORDER BY objectname");
+?>
 
-   echo "<table>";
+   <table>
+   <tr><th>Object</th><th>Log entries</th>
+       <th>Parameters</th><th>Notifications</th>
+   </tr>
+
+<?php
    $obj = 0;
 
    //The counters are set to zero
    $count_logs = 0;
    $count_notifications = 0;
+   $closed_notifications = 0;
    $count_parameters = 0;
+   $removed_parameters = 0;
 
    while ($obj < pg_numrows($res))
    {
       $u = pg_fetch_object($res, $obj);
-      $nr_logs = $u->log_count;
-      $count_logs = $count_logs + $nr_logs; 
 
-      $r = pg_exec ($this->database, "SELECT count(paramid) FROM parameter WHERE objectid='"
-                           . $u->objectid . "'");
-      $r = pg_fetch_object($r, 0);
+      $this->GatherStatistics($u->objectid);
 
-      $nr_params = $r->count;
-      $count_parameters = $count_parameters + $nr_params;
+      $count_parameters += $this->nr_parameters;
+      $removed_parameters += $this->removed_parameters;
+      $count_logs = $count_logs + $this->nr_logs;
 
-      $nr_notifications = $u->notification_count;
-      $count_notifications = $count_notifications + $nr_notifications;
+      //$nr_notifications = $u->notification_count;
+      $count_notifications += $this->nr_notifications;
+      $closed_notifications += $this->closed_notifications;
       ?>
-      <tr><td align='center'><img src='server.png'><br>
-             <b><?php echo $u->objectname ?></b>
-      </td><td align='right'>
-          <?php echo $nr_logs?> <a href='log.php?oid=<?php echo $u->objectid?>'>Log entries</a>
-      </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>
+      <tr><td><center><img src='server.png'><br>
+             <b><?php echo $u->objectname ?></b></center>
+      </td><td class='number'>
+          <?php echo "<a href='log.php?oid=$u->objectid'> $this->nr_logs </a>" ?>
+      </td><td class='number'>
+          <?php echo "<a href='parameter.php?oid=$u->objectid'>" . $this->nr_parameters
+                   . " (" . $this->removed_parameters . " removed)</a>" ?>
+      </td><td class='number'>
+          <?php echo "<a href='notification.php?oid=$u->objectid'>" . $this->nr_notifications . " (" . $this->closed_notifications . " closed)</a>" ?>
       </td><td>
           <form action='objects.php' method='post' onSubmit='return CheckRemove(this)'>
               <input type='hidden' name='objectname' value='<?php echo $u->objectname ?>'>
@@ -146,12 +198,12 @@ class object_page extends page
       <?php
       $obj++;
    }
-   
+
    //Show the totals
-   echo "<tr><td><strong><br><br>TOTALS</strong></td>";
-   echo "<td>$count_logs Log entries</td>";
-   echo "<td>$count_parameters Parameters</td>";
-   echo "<td>$count_notifications Notifications</td></tr>";
+   echo "<tr><td><strong><B><br><br>TOTALS</B></strong></td>";
+   echo "<td class='number'>$count_logs</td>";
+   echo "<td class='number'>$count_parameters ($removed_parameters removed)</td>";
+   echo "<td class='number'>$count_notifications ($closed_notifications closed)</td></tr>";
    echo "</table>";
 
 ?>
@@ -160,7 +212,7 @@ class object_page extends page
 <p>
 
 <form action='objects.php' method='post' onSubmit='return CheckCreate(this)'>
-Objects name (FQDN): <input name='objectname' type='text'>
+Object's name (FQDN): <input name='objectname' type='text'>
 <br>
 <input type='submit' name='action' value='Create'>
 </form>