Display the difference of all package class parameters for two objects
authorarjen <arjen>
Wed, 5 Feb 2003 09:47:39 +0000 (09:47 +0000)
committerarjen <arjen>
Wed, 5 Feb 2003 09:47:39 +0000 (09:47 +0000)
src/web/parameter.php
src/web/parameter_compare.php

index f7d4c02..f02148f 100644 (file)
@@ -1,16 +1,39 @@
 <?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      : parameter.php
+**      SYSTEM NAME    : Gnucomo - Gnu Computer Monitoring
+**      VERSION NUMBER : $Revision: 1.2 $
+**
+**  DESCRIPTION      : 
+**
+**  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: parameter.php,v $
+   Revision 1.2  2003-02-05 09:47:39  arjen
+   Display the difference of all package class parameters for two objects
+
+******************************/
+
+// RCSID = "$Id: parameter.php,v 1.2 2003-02-05 09:47:39 arjen Exp $";
 
-/*
- *
- * Objects Administration page.
- * Input parameters: action (POST) : empty, 'Create'
- *                   objname (POST) : name of the object to create or remove
- */
 
 session_start();
 require_once('classes/gnucomo_config.php');
@@ -85,15 +108,16 @@ else
       echo "<h1>Parameters for " . $obj->objectname . "</h1>";
 
       $res = pg_exec("SELECT paramid, class, name, description FROM parameter "
-                     ."WHERE objectid=" . $_GET['oid']);
+                     ."WHERE objectid=" . $_GET['oid'] . "order by class, name");
       
      ?>
      <form action='parameter_compare.php' method='post'>
        <input type='hidden' name='oid' value='<?php echo $_GET['oid'] ?>'>
        Compare to object:
-       <select>
+       <select name='compare_to'>
          <?php object_selection($conn, $_GET['oid']); ?>
        </select>
+       <input type='hidden' name='class' value='package'>
        <input type='submit' value=' Show Difference'>
      </form>
      <?php
index dfae1f5..ea2e258 100644 (file)
@@ -1,16 +1,38 @@
 <?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      : parameter_compare.php
+**      SYSTEM NAME    : Gnucomo - Gnu Computer Monitoring
+**      VERSION NUMBER : $Revision: 1.2 $
+**
+**  DESCRIPTION      : 
+**
+**  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   : 
+**************************************************************************/
 
-/*
- *
- * Objects Administration page.
- * Input parameters: action (POST) : empty, 'Create'
- *                   objname (POST) : name of the object to create or remove
- */
+/*****************************
+   $Log: parameter_compare.php,v $
+   Revision 1.2  2003-02-05 09:47:39  arjen
+   Display the difference of all package class parameters for two objects
+
+******************************/
+
+// RCSID = "$Id: parameter_compare.php,v 1.2 2003-02-05 09:47:39 arjen Exp $";
 
 session_start();
 require_once('classes/gnucomo_config.php');
@@ -21,33 +43,76 @@ require_once('classes/gnucomo_config.php');
 <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>
+<title>Parameter comparison</title>
+
 
-<script language='JavaScript'>
-function CheckCreate(f)
+</head>
+<body>
+<?php
+
+/*  Returns an associative array with all properties of a parameter (pid) */
+
+function param_properties($db, $pid)
 {
-   if (f.objectname.value == "")
+   $properties = NULL;
+   $r = pg_exec($db, "SELECT name, value FROM property WHERE paramid='" . $pid . "'");
+   for ($p = 0; $p < pg_numrows($r); $p++)
    {
-      alert("You must supply a name");
-      return false;
+      $prop = pg_fetch_object($r, $p);
+      $properties[$prop->name] = $prop->value;
    }
-   return true;
+   return $properties;
 }
 
-function CheckRemove(f)
+/*  Return true if both associative arrays are identical */
+
+function property_compare($prop, $comp)
 {
-   var message = "Are you sure you want to remove object ";
-   message += f.objectname.value;
-   message += " ?";
+   $equal = true;
 
-   return confirm(message);
+   if (empty($prop) || empty($comp))
+   {
+      $equal = empty($prop) && empty($comp);
+   }
+   else
+   {
+      reset($comp);
+      foreach ($prop as $name => $val)
+      {
+         if ($equal)
+         {
+            $to_compare = each($comp);
+            $equal = $to_compare[0] == $name && $to_compare[1] == $val;
+         }
+      }
+   }
+   return $equal;
 }
 
-</script>
+/*   Display a parameter in two adjecent table cells  */
+
+function display_parameter($name, $properties, $css_class = "")
+{
+   echo "<td";
+   if ($css_class != "")
+   {
+      echo " class='$css_class'";
+   }
+   echo ">";
+   echo $name;
+   echo "</td><td";
+   if ($css_class != "")
+   {
+      echo " class='$css_class'";
+   }
+   echo ">";
+   foreach ($properties as $p_name => $p_value)
+   {
+      echo " $p_name=$p_value";
+   }
+   echo "</td>";
+}
 
-</head>
-<body>
-<?php
 if (empty($_SESSION['username']))
 {
    echo "Please log in first.";
@@ -62,45 +127,91 @@ else
    //  Connect to the database
    $conn = pg_connect($config->Database($_SESSION['username'], $_SESSION['password']));
 
-   if (!empty($_GET['oid']))
+   if (!empty($_POST['oid']))
    {
-      $res = pg_exec("SELECT objectname FROM object WHERE objectid=" . $_GET['oid']);
+      $res = pg_exec("SELECT objectid, objectname FROM object WHERE objectid=" . $_POST['oid']);
       $obj = pg_fetch_object($res, 0);
-      echo "<h1>Parameters for " . $obj->objectname . "</h1><hr>";
+      echo "<h1>" . $_POST['class'] . " parameters for " . $obj->objectname;
+      $res = pg_exec("SELECT objectid, objectname FROM object WHERE objectid=" . $_POST['compare_to']);
+      $cmp_obj = pg_fetch_object($res, 0);
+      echo " compared to " . $cmp_obj->objectname . "</h1><hr>";
 
-      $res = pg_exec("SELECT paramid, class, name, description FROM parameter "
-                     ."WHERE objectid=" . $_GET['oid']);
+      $res = pg_exec("SELECT objectid, paramid, name FROM parameter "
+                     . "WHERE objectid=" . $obj->objectid . " OR objectid=" . $cmp_obj->objectid
+                     . " AND class='" . $_POST['class'] . "' ORDER BY name, objectid");
       
      ?>
-     <form action='parameter_compare.php' method='post'>
-     </form>
      <?php
-      echo "<table>";
+      echo "<table>\n";
+      echo "<tr><th colspan='2'>" . $obj->objectname . "</th>";
+      echo "<th colspan='2'>" . $cmp_obj->objectname . "</th></tr>\n";
+      echo "<tr><th>Name</th><th>Properties</th><th>Name</th><th>Propterties</th></tr>\n";
       $row = 0;
       while ($row < pg_numrows($res))
       {
          $par = pg_fetch_object($res, $row);
-         ?>
-         <tr><td align='center'>
-            <?php echo $par->class?>
-         </td><td>
-            <?php echo $par->name?>
-         </td><td>
-            <?php echo $par->description?>
-         </td><td>
-            <?php
-               $r = pg_exec($conn, "SELECT name, value FROM property WHERE paramid='" . $par->paramid . "'");
-               for ($p = 0; $p < pg_numrows($r); $p++)
+         $nextpar = 'false';
+         if ($row + 1 < pg_numrows($res))
+         {
+            $nextpar = pg_fetch_object($res, $row + 1);
+         }
+         echo "<tr>";
+
+         if ($nextpar && $par->name == $nextpar->name)
+         {
+            /*  Both objects have this parameter */
+            $row++;
+
+            $pr = param_properties($conn, $par->paramid);
+            $prnext = param_properties($conn, $nextpar->paramid);
+            if (property_compare($pr, $prnext))
+            {
+               display_parameter($par->name, $pr);
+               display_parameter($nextpar->name, $prnext);
+            }
+            else
+            {
+               // We want the parameters of $obj on the left, so we need
+               // to swap the left and right sides if appropriate.
+
+               if ($par->objectid == $obj->objectid)
+               {
+                  display_parameter($par->name, $pr, "both");
+                  display_parameter($nextpar->name, $prnext, "both");
+               }
+               else
                {
-                  $prop = pg_fetch_object($r, $p);
-                  echo $prop->name . "=" . $prop->value . " ";
+                  display_parameter($nextpar->name, $prnext, "both");
+                  display_parameter($par->name, $pr, "both");
                }
-            ?>
-         </td></tr>
-         <?php
+            }
+         }
+         else
+         {
+            /*  Only one of the objects has this parameter */
+
+            $pr = param_properties($conn, $par->paramid);
+
+            if ($par->objectid == $obj->objectid)
+            {
+               /*  Parameter belongs to the object on the left */
+
+               display_parameter($par->name, $pr, "left");
+               echo "<td>&nbsp;</td><td>&nbsp;";
+            }
+            else
+            {
+               /*  Parameter belongs to the object on the right */
+
+               echo "<td>";
+               echo "&nbsp;</td><td>&nbsp;</td>";
+               display_parameter($par->name, $pr, "right");
+            }
+         }
+         echo "</tr>\n";
          $row++;
       }
-      echo "</table>";
+      echo "</table>\n";
    }
 }
 ?>