Added log, notification and parameter counters to the 'object' table.
[gnucomo.git] / src / web / objects.php
index e322a04..6c7120b 100644 (file)
@@ -9,7 +9,7 @@
 ***********************
 **      FILE NAME      : objects.php
 **      SYSTEM NAME    : Gnucomo - Gnu Computer Monitoring
-**      VERSION NUMBER : $Revision: 1.3 $
+**      VERSION NUMBER : $Revision: 1.4 $
 **
 **  DESCRIPTION      : Objects Administration page.
 **                     Input parameters: action (POST) : empty, 'Create'
 
 /*****************************
    $Log: objects.php,v $
-   Revision 1.3  2003-02-10 15:42:24  arjen
+   Revision 1.4  2003-02-13 08:48:23  arjen
+   Added log, notification and parameter counters to the 'object' table.
+   Counting these things at the time a user interface needs them is
+   too slow. Other programs, like gcm_daemon en gcm_input should prepare
+   these counters for quick retrieval.
+
+   Revision 1.3  2003/02/10 15:42:24  arjen
    Show the total number of Log entries, parameters and notifications
 
    Revision 1.2  2003/02/05 09:48:14  arjen
@@ -37,7 +43,7 @@
 
 ******************************/
 
-// RCSID = "$Id: objects.php,v 1.3 2003-02-10 15:42:24 arjen Exp $";
+// RCSID = "$Id: objects.php,v 1.4 2003-02-13 08:48:23 arjen Exp $";
 
 session_start();
 require_once('classes/gnucomo_config.php');
@@ -93,8 +99,8 @@ else
 
    if (isset($_POST['action']) && $_POST['action'] == 'Create' && !empty($_POST['objectname']))
    {
-      pg_exec($conn, "INSERT INTO object (objectname) VALUES ('"
-                     . $_POST['objectname'] . "')");
+      pg_exec($conn, "INSERT INTO object (objectname, log_count, parameter_count, notification_count) VALUES ('"
+                     . $_POST['objectname'] . "', '0', '0', '0')");
    }
 
    if (isset($_POST['action']) && $_POST['action'] == 'Remove' && !empty($_POST['objectname']))
@@ -102,7 +108,7 @@ else
       pg_exec($conn, "DELETE FROM object WHERE objectname='" . $_POST['objectname'] . "'");
    }
 
-   $res = pg_exec($conn, "SELECT objectid,objectname FROM object");
+   $res = pg_exec($conn, "SELECT objectid,objectname, log_count, notification_count FROM object ORDER BY objectname");
 
    echo "<table>";
    $obj = 0;
@@ -115,11 +121,7 @@ else
    while ($obj < pg_numrows($res))
    {
       $u = pg_fetch_object($res, $obj);
-      $r = pg_exec($conn, "SELECT count(logid) FROM log WHERE objectid='"
-                           . $u->objectid . "'");
-      $r = pg_fetch_object($r, 0);
-
-      $nr_logs = $r->count;
+      $nr_logs = $u->log_count;
       $count_logs = $count_logs + $nr_logs; 
 
       $r = pg_exec ($conn, "SELECT count(paramid) FROM parameter WHERE objectid='"
@@ -129,16 +131,12 @@ else
       $nr_params = $r->count;
       $count_parameters = $count_parameters + $nr_params;
 
-      $r = pg_exec ($conn, "SELECT count(notificationid) FROM notification WHERE objectid='"
-                           . $u->objectid . "'");
-      $r = pg_fetch_object($r, 0);
-
-      $nr_notifications = $r->count;
+      $nr_notifications = $u->notification_count;
       $count_notifications = $count_notifications + $nr_notifications;
       ?>
       <tr><td align='center'><img src='server.png'><br>
              <b><?php echo $u->objectname ?></b>
-      </td><td>
+      </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>