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.3 $
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.3 2003-02-13 09:01:29 arjen
31 All web interface pages use the page class.
33 Revision 1.2 2003/02/05 09:47:39 arjen
34 Display the difference of all package class parameters for two objects
36 ******************************/
38 // RCSID = "$Id: parameter_compare.php,v 1.3 2003-02-13 09:01:29 arjen Exp $";
40 ini_set('include_path', '.:./classes:../phpclasses');
42 require_once('page.class.php');
45 /* Returns an associative array with all properties of a parameter (pid) */
47 function param_properties($db, $pid)
50 $r = pg_exec($db, "SELECT name, value FROM property WHERE paramid='" . $pid . "'");
51 for ($p = 0; $p < pg_numrows($r); $p++)
53 $prop = pg_fetch_object($r, $p);
54 $properties[$prop->name] = $prop->value;
59 /* Return true if both associative arrays are identical */
61 function property_compare($prop, $comp)
65 if (empty($prop) || empty($comp))
67 $equal = empty($prop) && empty($comp);
72 foreach ($prop as $name => $val)
76 $to_compare = each($comp);
77 $equal = $to_compare[0] == $name && $to_compare[1] == $val;
84 /* Display a parameter in two adjecent table cells */
86 function display_parameter($name, $properties, $css_class = "")
91 echo " class='$css_class'";
98 echo " class='$css_class'";
101 foreach ($properties as $p_name => $p_value)
103 echo " $p_name=$p_value";
108 class param_diff extends page
113 if (!empty($_POST['oid']))
115 $res = pg_exec($this->database, "SELECT objectid, objectname FROM object WHERE objectid=" . $_POST['oid']);
116 $obj = pg_fetch_object($res, 0);
117 echo "<h1>" . $_POST['class'] . " parameters for " . $obj->objectname;
118 $res = pg_exec($this->database, "SELECT objectid, objectname FROM object WHERE objectid=" . $_POST['compare_to']);
119 $cmp_obj = pg_fetch_object($res, 0);
120 echo " compared to " . $cmp_obj->objectname . "</h1><hr>";
122 $res = pg_exec($this->database, "SELECT objectid, paramid, name FROM parameter "
123 . "WHERE objectid=" . $obj->objectid . " OR objectid=" . $cmp_obj->objectid
124 . " AND class='" . $_POST['class'] . "' ORDER BY name, objectid");
127 echo "<tr><th colspan='2'>" . $obj->objectname . "</th>";
128 echo "<th colspan='2'>" . $cmp_obj->objectname . "</th></tr>\n";
129 echo "<tr><th>Name</th><th>Properties</th><th>Name</th><th>Propterties</th></tr>\n";
131 while ($row < pg_numrows($res))
133 $par = pg_fetch_object($res, $row);
135 if ($row + 1 < pg_numrows($res))
137 $nextpar = pg_fetch_object($res, $row + 1);
141 if ($nextpar && $par->name == $nextpar->name)
143 /* Both objects have this parameter */
146 $pr = param_properties($this->database, $par->paramid);
147 $prnext = param_properties($this->database, $nextpar->paramid);
148 if (property_compare($pr, $prnext))
150 display_parameter($par->name, $pr);
151 display_parameter($nextpar->name, $prnext);
155 // We want the parameters of $obj on the left, so we need
156 // to swap the left and right sides if appropriate.
158 if ($par->objectid == $obj->objectid)
160 display_parameter($par->name, $pr, "both");
161 display_parameter($nextpar->name, $prnext, "both");
165 display_parameter($nextpar->name, $prnext, "both");
166 display_parameter($par->name, $pr, "both");
172 /* Only one of the objects has this parameter */
174 $pr = param_properties($this->database, $par->paramid);
176 if ($par->objectid == $obj->objectid)
178 /* Parameter belongs to the object on the left */
180 display_parameter($par->name, $pr, "left");
181 echo "<td> </td><td> ";
185 /* Parameter belongs to the object on the right */
188 echo " </td><td> </td>";
189 display_parameter($par->name, $pr, "right");
200 $page = new param_diff("Gnucomo Parameter Comparison");