3 /**************************************************************************
4 ** (c) Copyright 2003, Andromeda Technology & Automation
5 ** This is free software; you can redistribute it and/or modify it under the
6 ** terms of the GNU General Public License, see the file COPYING.
7 ***************************************************************************
8 ** MODULE INFORMATION *
9 ***********************
10 ** FILE NAME : parameter_compare.php
11 ** SYSTEM NAME : Gnucomo - Gnu Computer Monitoring
12 ** VERSION NUMBER : $Revision: 1.2 $
19 ***************************************************************************
20 ** ADMINISTRATIVE INFORMATION *
21 ********************************
22 ** ORIGINAL AUTHOR : Arjen Baart - arjen@andromeda.nl
23 ** CREATION DATE : Dec 04, 2002
24 ** LAST UPDATE : Feb 03, 2003
26 **************************************************************************/
28 /*****************************
29 $Log: parameter_compare.php,v $
30 Revision 1.2 2003-02-05 09:47:39 arjen
31 Display the difference of all package class parameters for two objects
33 ******************************/
35 // RCSID = "$Id: parameter_compare.php,v 1.2 2003-02-05 09:47:39 arjen Exp $";
38 require_once('classes/gnucomo_config.php');
41 <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
44 <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
45 <link rel='stylesheet' href='gnucomo.css' type='text/css'>
46 <title>Parameter comparison</title>
53 /* Returns an associative array with all properties of a parameter (pid) */
55 function param_properties($db, $pid)
58 $r = pg_exec($db, "SELECT name, value FROM property WHERE paramid='" . $pid . "'");
59 for ($p = 0; $p < pg_numrows($r); $p++)
61 $prop = pg_fetch_object($r, $p);
62 $properties[$prop->name] = $prop->value;
67 /* Return true if both associative arrays are identical */
69 function property_compare($prop, $comp)
73 if (empty($prop) || empty($comp))
75 $equal = empty($prop) && empty($comp);
80 foreach ($prop as $name => $val)
84 $to_compare = each($comp);
85 $equal = $to_compare[0] == $name && $to_compare[1] == $val;
92 /* Display a parameter in two adjecent table cells */
94 function display_parameter($name, $properties, $css_class = "")
99 echo " class='$css_class'";
104 if ($css_class != "")
106 echo " class='$css_class'";
109 foreach ($properties as $p_name => $p_value)
111 echo " $p_name=$p_value";
116 if (empty($_SESSION['username']))
118 echo "Please log in first.";
123 $config = new gnucomo_config;
125 $config->read("gnucomo");
127 // Connect to the database
128 $conn = pg_connect($config->Database($_SESSION['username'], $_SESSION['password']));
130 if (!empty($_POST['oid']))
132 $res = pg_exec("SELECT objectid, objectname FROM object WHERE objectid=" . $_POST['oid']);
133 $obj = pg_fetch_object($res, 0);
134 echo "<h1>" . $_POST['class'] . " parameters for " . $obj->objectname;
135 $res = pg_exec("SELECT objectid, objectname FROM object WHERE objectid=" . $_POST['compare_to']);
136 $cmp_obj = pg_fetch_object($res, 0);
137 echo " compared to " . $cmp_obj->objectname . "</h1><hr>";
139 $res = pg_exec("SELECT objectid, paramid, name FROM parameter "
140 . "WHERE objectid=" . $obj->objectid . " OR objectid=" . $cmp_obj->objectid
141 . " AND class='" . $_POST['class'] . "' ORDER BY name, objectid");
146 echo "<tr><th colspan='2'>" . $obj->objectname . "</th>";
147 echo "<th colspan='2'>" . $cmp_obj->objectname . "</th></tr>\n";
148 echo "<tr><th>Name</th><th>Properties</th><th>Name</th><th>Propterties</th></tr>\n";
150 while ($row < pg_numrows($res))
152 $par = pg_fetch_object($res, $row);
154 if ($row + 1 < pg_numrows($res))
156 $nextpar = pg_fetch_object($res, $row + 1);
160 if ($nextpar && $par->name == $nextpar->name)
162 /* Both objects have this parameter */
165 $pr = param_properties($conn, $par->paramid);
166 $prnext = param_properties($conn, $nextpar->paramid);
167 if (property_compare($pr, $prnext))
169 display_parameter($par->name, $pr);
170 display_parameter($nextpar->name, $prnext);
174 // We want the parameters of $obj on the left, so we need
175 // to swap the left and right sides if appropriate.
177 if ($par->objectid == $obj->objectid)
179 display_parameter($par->name, $pr, "both");
180 display_parameter($nextpar->name, $prnext, "both");
184 display_parameter($nextpar->name, $prnext, "both");
185 display_parameter($par->name, $pr, "both");
191 /* Only one of the objects has this parameter */
193 $pr = param_properties($conn, $par->paramid);
195 if ($par->objectid == $obj->objectid)
197 /* Parameter belongs to the object on the left */
199 display_parameter($par->name, $pr, "left");
200 echo "<td> </td><td> ";
204 /* Parameter belongs to the object on the right */
207 echo " </td><td> </td>";
208 display_parameter($par->name, $pr, "right");