Improved the table layout.
[gnucomo.git] / src / web / objects.php
index 33a90e0..e53e686 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.2 $
+**      VERSION NUMBER : $Revision: 1.6 $
 **
 **  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 03, 2003
+**      LAST UPDATE     : Feb 14, 2003
 **      MODIFICATIONS   : 
 **************************************************************************/
 
 /*****************************
    $Log: objects.php,v $
-   Revision 1.2  2003-02-05 09:48:14  arjen
+   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
+   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
    Added display and handling of notifications
 
 ******************************/
 
-// RCSID = "$Id: objects.php,v 1.2 2003-02-05 09:48:14 arjen Exp $";
+// RCSID = "$Id: objects.php,v 1.6 2003-02-21 08:46:58 arjen Exp $";
 
-session_start();
-require_once('classes/gnucomo_config.php');
-?>
+ini_set('include_path', '.:./classes:../phpclasses');
 
-<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
-<html>
-<head>
-<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
-<link rel='stylesheet' href='gnucomo.css' type='text/css'>
-<title>GNUCoMo login</title>
+require_once('page.class.php');
+
+function clientscripts()
+{
+?>
 
 <script language='JavaScript'>
+
 function CheckCreate(f)
 {
    if (f.objectname.value == "")
@@ -69,69 +82,70 @@ function CheckRemove(f)
 
 </script>
 
-</head>
-<body>
 <?php
-if (empty($_SESSION['username']))
-{
-   echo "Please log in first.";
 }
-else
-{
-   echo "<h1>Objects Administration</h1><hr>";
 
-   $config = new gnucomo_config;
-
-   $config->read("gnucomo");
+class object_page extends page
+{
 
-   //  Connect to the database
-   $conn = pg_connect($config->Database($_SESSION['username'], $_SESSION['password']));
+   function Body()
+   {
+      clientscripts();
 
+   echo "<h1>Objects Administration</h1><hr>";
 
    if (isset($_POST['action']) && $_POST['action'] == 'Create' && !empty($_POST['objectname']))
    {
-      pg_exec($conn, "INSERT INTO object (objectname) VALUES ('"
-                     . $_POST['objectname'] . "')");
+      pg_exec($this->database, "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']))
    {
-      pg_exec($conn, "DELETE FROM object WHERE objectname='" . $_POST['objectname'] . "'");
+      pg_exec($this->database, "DELETE FROM object WHERE objectname='" . $_POST['objectname'] . "'");
    }
 
-   $res = pg_exec($conn, "SELECT objectid,objectname FROM object");
+   $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;
+   $count_parameters = 0;
+
    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 = $u->log_count;
+      $count_logs = $count_logs + $nr_logs;
 
-      $nr_logs = $r->count;
-
-      $r = pg_exec ($conn, "SELECT count(paramid) FROM parameter WHERE objectid='"
-                           . $u->objectid . "'");
+      $r = pg_exec ($this->database, "SELECT count(paramid) FROM parameter WHERE objectid=CAST('"
+                           . $u->objectid . "' AS BIGINT)");
       $r = pg_fetch_object($r, 0);
 
       $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>
-          <?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'> $nr_logs </a>" ?>
+      </td><td class='number'>
+          <?php echo "<a href='parameter.php?oid=$u->objectid'> $nr_params </a>" ?>
+      </td><td class='number'>
+          <?php echo "<a href='notification.php?oid=$u->objectid'> $nr_notifications </a>" ?>
       </td><td>
           <form action='objects.php' method='post' onSubmit='return CheckRemove(this)'>
               <input type='hidden' name='objectname' value='<?php echo $u->objectname ?>'>
@@ -141,9 +155,14 @@ else
       <?php
       $obj++;
    }
+
+   //Show the totals
+   echo "<tr><td><strong><B><br><br>TOTALS</B></strong></td>";
+   echo "<td class='number'>$count_logs</td>";
+   echo "<td class='number'>$count_parameters</td>";
+   echo "<td class='number'>$count_notifications</td></tr>";
    echo "</table>";
 
-}
 ?>
 
 <h2>Create new object:</h2>
@@ -155,5 +174,14 @@ Objects name (FQDN): <input name='objectname' type='text'>
 <input type='submit' name='action' value='Create'>
 </form>
 </p>
-</body>
-</html>
+<?php
+
+   }
+}
+
+$obj_page = new object_page("Gnucomo Objects Administration");
+
+$obj_page->Showpage();
+
+?>
+