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.7 $
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.7 2007-11-21 14:38:06 arjen
31 The buttonbar at the top of each page is now a fixed 'div' element
32 instead of a framed page.
33 Contributed by Edwin Nadorp.
35 Revision 1.6 2003/12/03 08:03:28 arjen
36 Optionally show or hide removed parameters from the parameter
39 Revision 1.5 2003/08/14 10:31:57 arjen
40 BUGFIX: Removed parameters were somtimes shown on the wrong side
41 of the parameter difference page.
43 Revision 1.4 2003/07/15 11:06:45 arjen
44 Removed parameters are displayed in a shaded style.
46 Revision 1.3 2003/02/13 09:01:29 arjen
47 All web interface pages use the page class.
49 Revision 1.2 2003/02/05 09:47:39 arjen
50 Display the difference of all package class parameters for two objects
52 ******************************/
54 // RCSID = "$Id: parameter_compare.php,v 1.7 2007-11-21 14:38:06 arjen Exp $";
56 ini_set('include_path', '.:./classes:../phpclasses');
58 require_once('page.class.php');
61 /* Returns an associative array with all properties of a parameter (pid) */
63 function param_properties($db, $pid)
66 $r = pg_exec($db, "SELECT name, value FROM property WHERE paramid='" . $pid . "'");
67 for ($p = 0; $p < pg_numrows($r); $p++)
69 $prop = pg_fetch_object($r, $p);
70 $properties[$prop->name] = $prop->value;
75 /* Return true if both associative arrays are identical */
77 function property_compare($prop, $comp)
81 if (empty($prop) || empty($comp))
83 $equal = empty($prop) && empty($comp);
88 foreach ($prop as $name => $val)
92 $to_compare = each($comp);
93 $equal = $to_compare[0] == $name && $to_compare[1] == $val;
100 /* Display a parameter in two adjecent table cells */
102 function display_parameter($name, $properties, $css_class = "", $shaded = FALSE)
106 $css_class = 'shaded';
109 if ($css_class != "")
111 echo " class='$css_class'";
116 if ($css_class != "")
118 echo " class='$css_class'";
121 foreach ($properties as $p_name => $p_value)
123 echo " $p_name=$p_value";
128 class param_diff extends page
131 function is_removed($paramid)
133 $qry ="select change_nature from history where paramid= CAST('";
134 $qry .= $paramid . "' AS BIGINT) order by modified desc";
135 $rhist = pg_exec($this->database, $qry);
136 $hist = pg_fetch_object($rhist, 0);
138 return $hist->change_nature == "REMOVED";
143 if (!empty($_POST['oid']))
145 $res = pg_exec($this->database, "SELECT objectid, objectname FROM object
146 WHERE objectid=" . $_POST['oid']);
147 $obj = pg_fetch_object($res, 0);
148 echo "<h1>" . $_POST['class'] . " parameters for " . $obj->objectname;
149 $res = pg_exec($this->database, "SELECT objectid, objectname FROM object
150 WHERE objectid=" . $_POST['compare_to']);
151 $cmp_obj = pg_fetch_object($res, 0);
152 echo " compared to " . $cmp_obj->objectname . "</h1><hr>";
154 $res = pg_exec($this->database, "SELECT objectid, paramid, name FROM parameter "
155 . "WHERE objectid=" . $obj->objectid . " OR objectid=" . $cmp_obj->objectid
156 . " AND class='" . $_POST['class'] . "' ORDER BY name, objectid");
159 echo "<tr><th colspan='2'>" . $obj->objectname . "</th>";
160 echo "<th colspan='2'>" . $cmp_obj->objectname . "</th></tr>\n";
161 echo "<tr><th>Name</th><th>Properties</th><th>Name</th><th>Propterties</th></tr>\n";
163 $hide_removed = true;
164 $hide_removed = empty($_POST['show_removed']) || $_POST['show_removed'] != 'on';
167 while ($row < pg_numrows($res))
169 // Find the next two parameters, optionally skipping removed parameters.
172 while (!$par && $row < pg_numrows($res))
174 $par = pg_fetch_object($res, $row);
175 if ($hide_removed && $this->is_removed($par->paramid))
183 while (!$nextpar && $nextrow < pg_numrows($res))
185 $nextpar = pg_fetch_object($res, $nextrow);
186 if ($hide_removed && $this->is_removed($nextpar->paramid))
194 if ($nextpar && $par->name == $nextpar->name)
196 /* Both objects have this parameter */
199 $pr = param_properties($this->database, $par->paramid);
200 $prnext = param_properties($this->database, $nextpar->paramid);
201 if (property_compare($pr, $prnext))
209 // We want the parameters of $obj on the left, so we need
210 // to swap the left and right sides if appropriate.
212 if ($par->objectid == $obj->objectid)
214 display_parameter($par->name, $pr, $Style, $this->is_removed($par->paramid));
215 display_parameter($nextpar->name, $prnext, $Style, $this->is_removed($nextpar->paramid));
219 display_parameter($nextpar->name, $prnext, $Style, $this->is_removed($nextpar->paramid));
220 display_parameter($par->name, $pr, $Style, $this->is_removed($par->paramid));
225 /* Only one of the objects has this parameter */
227 $pr = param_properties($this->database, $par->paramid);
229 if ($par->objectid == $obj->objectid)
231 /* Parameter belongs to the object on the left */
233 display_parameter($par->name, $pr, "left", $this->is_removed($par->paramid));
234 echo "<td> </td><td> ";
238 /* Parameter belongs to the object on the right */
241 echo " </td><td> </td>";
242 display_parameter($par->name, $pr, "right", $this->is_removed($par->paramid));
253 $page = new param_diff("Gnucomo Parameter Comparison");