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.6 $
19 ***************************************************************************
20 ** ADMINISTRATIVE INFORMATION *
21 ********************************
22 ** ORIGINAL AUTHOR : Arjen Baart - arjen@andromeda.nl
23 ** CREATION DATE : Dec 04, 2002
24 ** LAST UPDATE : Dec 03, 2003
26 **************************************************************************/
28 /*****************************
29 $Log: parameter_compare.php,v $
30 Revision 1.6 2003-12-03 08:03:28 arjen
31 Optionally show or hide removed parameters from the parameter
34 Revision 1.5 2003/08/14 10:31:57 arjen
35 BUGFIX: Removed parameters were somtimes shown on the wrong side
36 of the parameter difference page.
38 Revision 1.4 2003/07/15 11:06:45 arjen
39 Removed parameters are displayed in a shaded style.
41 Revision 1.3 2003/02/13 09:01:29 arjen
42 All web interface pages use the page class.
44 Revision 1.2 2003/02/05 09:47:39 arjen
45 Display the difference of all package class parameters for two objects
47 ******************************/
49 // RCSID = "$Id: parameter_compare.php,v 1.6 2003-12-03 08:03:28 arjen Exp $";
51 ini_set('include_path', '.:./classes:../phpclasses');
53 require_once('page.class.php');
56 /* Returns an associative array with all properties of a parameter (pid) */
58 function param_properties($db, $pid)
61 $r = pg_exec($db, "SELECT name, value FROM property WHERE paramid='" . $pid . "'");
62 for ($p = 0; $p < pg_numrows($r); $p++)
64 $prop = pg_fetch_object($r, $p);
65 $properties[$prop->name] = $prop->value;
70 /* Return true if both associative arrays are identical */
72 function property_compare($prop, $comp)
76 if (empty($prop) || empty($comp))
78 $equal = empty($prop) && empty($comp);
83 foreach ($prop as $name => $val)
87 $to_compare = each($comp);
88 $equal = $to_compare[0] == $name && $to_compare[1] == $val;
95 /* Display a parameter in two adjecent table cells */
97 function display_parameter($name, $properties, $css_class = "", $shaded = FALSE)
101 $css_class = 'shaded';
104 if ($css_class != "")
106 echo " class='$css_class'";
111 if ($css_class != "")
113 echo " class='$css_class'";
116 foreach ($properties as $p_name => $p_value)
118 echo " $p_name=$p_value";
123 class param_diff extends page
126 function is_removed($paramid)
128 $qry ="select change_nature from history where paramid= CAST('";
129 $qry .= $paramid . "' AS BIGINT) order by modified desc";
130 $rhist = pg_exec($this->database, $qry);
131 $hist = pg_fetch_object($rhist, 0);
133 return $hist->change_nature == "REMOVED";
138 if (!empty($_POST['oid']))
140 $res = pg_exec($this->database, "SELECT objectid, objectname FROM object
141 WHERE objectid=" . $_POST['oid']);
142 $obj = pg_fetch_object($res, 0);
143 echo "<h1>" . $_POST['class'] . " parameters for " . $obj->objectname;
144 $res = pg_exec($this->database, "SELECT objectid, objectname FROM object
145 WHERE objectid=" . $_POST['compare_to']);
146 $cmp_obj = pg_fetch_object($res, 0);
147 echo " compared to " . $cmp_obj->objectname . "</h1><hr>";
149 $res = pg_exec($this->database, "SELECT objectid, paramid, name FROM parameter "
150 . "WHERE objectid=" . $obj->objectid . " OR objectid=" . $cmp_obj->objectid
151 . " AND class='" . $_POST['class'] . "' ORDER BY name, objectid");
154 echo "<tr><th colspan='2'>" . $obj->objectname . "</th>";
155 echo "<th colspan='2'>" . $cmp_obj->objectname . "</th></tr>\n";
156 echo "<tr><th>Name</th><th>Properties</th><th>Name</th><th>Propterties</th></tr>\n";
158 $hide_removed = true;
159 $hide_removed = $_POST['show_removed'] != 'on';
162 while ($row < pg_numrows($res))
164 // Find the next two parameters, optionally skipping removed parameters.
167 while (!$par && $row < pg_numrows($res))
169 $par = pg_fetch_object($res, $row);
170 if ($hide_removed && $this->is_removed($par->paramid))
178 while (!$nextpar && $nextrow < pg_numrows($res))
180 $nextpar = pg_fetch_object($res, $nextrow);
181 if ($hide_removed && $this->is_removed($nextpar->paramid))
189 if ($nextpar && $par->name == $nextpar->name)
191 /* Both objects have this parameter */
194 $pr = param_properties($this->database, $par->paramid);
195 $prnext = param_properties($this->database, $nextpar->paramid);
196 if (property_compare($pr, $prnext))
204 // We want the parameters of $obj on the left, so we need
205 // to swap the left and right sides if appropriate.
207 if ($par->objectid == $obj->objectid)
209 display_parameter($par->name, $pr, $Style, $this->is_removed($par->paramid));
210 display_parameter($nextpar->name, $prnext, $Style, $this->is_removed($nextpar->paramid));
214 display_parameter($nextpar->name, $prnext, $Style, $this->is_removed($nextpar->paramid));
215 display_parameter($par->name, $pr, $Style, $this->is_removed($par->paramid));
221 /* Only one of the objects has this parameter */
223 $pr = param_properties($this->database, $par->paramid);
225 if ($par->objectid == $obj->objectid)
227 /* Parameter belongs to the object on the left */
229 display_parameter($par->name, $pr, "left", $this->is_removed($par->paramid));
230 echo "<td> </td><td> ";
234 /* Parameter belongs to the object on the right */
237 echo " </td><td> </td>";
238 display_parameter($par->name, $pr, "right", $this->is_removed($par->paramid));
249 $page = new param_diff("Gnucomo Parameter Comparison");