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.5 $
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.5 2003-08-14 10:31:57 arjen
31 BUGFIX: Removed parameters were somtimes shown on the wrong side
32 of the parameter difference page.
34 Revision 1.4 2003/07/15 11:06:45 arjen
35 Removed parameters are displayed in a shaded style.
37 Revision 1.3 2003/02/13 09:01:29 arjen
38 All web interface pages use the page class.
40 Revision 1.2 2003/02/05 09:47:39 arjen
41 Display the difference of all package class parameters for two objects
43 ******************************/
45 // RCSID = "$Id: parameter_compare.php,v 1.5 2003-08-14 10:31:57 arjen Exp $";
47 ini_set('include_path', '.:./classes:../phpclasses');
49 require_once('page.class.php');
52 /* Returns an associative array with all properties of a parameter (pid) */
54 function param_properties($db, $pid)
57 $r = pg_exec($db, "SELECT name, value FROM property WHERE paramid='" . $pid . "'");
58 for ($p = 0; $p < pg_numrows($r); $p++)
60 $prop = pg_fetch_object($r, $p);
61 $properties[$prop->name] = $prop->value;
66 /* Return true if both associative arrays are identical */
68 function property_compare($prop, $comp)
72 if (empty($prop) || empty($comp))
74 $equal = empty($prop) && empty($comp);
79 foreach ($prop as $name => $val)
83 $to_compare = each($comp);
84 $equal = $to_compare[0] == $name && $to_compare[1] == $val;
91 /* Display a parameter in two adjecent table cells */
93 function display_parameter($name, $properties, $css_class = "", $shaded = FALSE)
97 $css_class = 'shaded';
100 if ($css_class != "")
102 echo " class='$css_class'";
107 if ($css_class != "")
109 echo " class='$css_class'";
112 foreach ($properties as $p_name => $p_value)
114 echo " $p_name=$p_value";
119 class param_diff extends page
122 function is_removed($paramid)
124 $qry ="select change_nature from history where paramid= CAST('";
125 $qry .= $paramid . "' AS BIGINT) order by modified desc";
126 $rhist = pg_exec($this->database, $qry);
127 $hist = pg_fetch_object($rhist, 0);
129 return $hist->change_nature == "REMOVED";
134 if (!empty($_POST['oid']))
136 $res = pg_exec($this->database, "SELECT objectid, objectname FROM object
137 WHERE objectid=" . $_POST['oid']);
138 $obj = pg_fetch_object($res, 0);
139 echo "<h1>" . $_POST['class'] . " parameters for " . $obj->objectname;
140 $res = pg_exec($this->database, "SELECT objectid, objectname FROM object
141 WHERE objectid=" . $_POST['compare_to']);
142 $cmp_obj = pg_fetch_object($res, 0);
143 echo " compared to " . $cmp_obj->objectname . "</h1><hr>";
145 $res = pg_exec($this->database, "SELECT objectid, paramid, name FROM parameter "
146 . "WHERE objectid=" . $obj->objectid . " OR objectid=" . $cmp_obj->objectid
147 . " AND class='" . $_POST['class'] . "' ORDER BY name, objectid");
150 echo "<tr><th colspan='2'>" . $obj->objectname . "</th>";
151 echo "<th colspan='2'>" . $cmp_obj->objectname . "</th></tr>\n";
152 echo "<tr><th>Name</th><th>Properties</th><th>Name</th><th>Propterties</th></tr>\n";
154 while ($row < pg_numrows($res))
156 $par = pg_fetch_object($res, $row);
158 if ($row + 1 < pg_numrows($res))
160 $nextpar = pg_fetch_object($res, $row + 1);
164 if ($nextpar && $par->name == $nextpar->name)
166 /* Both objects have this parameter */
169 $pr = param_properties($this->database, $par->paramid);
170 $prnext = param_properties($this->database, $nextpar->paramid);
171 if (property_compare($pr, $prnext))
179 // We want the parameters of $obj on the left, so we need
180 // to swap the left and right sides if appropriate.
182 if ($par->objectid == $obj->objectid)
184 display_parameter($par->name, $pr, $Style, $this->is_removed($par->paramid));
185 display_parameter($nextpar->name, $prnext, $Style, $this->is_removed($nextpar->paramid));
189 display_parameter($nextpar->name, $prnext, $Style, $this->is_removed($nextpar->paramid));
190 display_parameter($par->name, $pr, $Style, $this->is_removed($par->paramid));
196 /* Only one of the objects has this parameter */
198 $pr = param_properties($this->database, $par->paramid);
200 if ($par->objectid == $obj->objectid)
202 /* Parameter belongs to the object on the left */
204 display_parameter($par->name, $pr, "left", $this->is_removed($par->paramid));
205 echo "<td> </td><td> ";
209 /* Parameter belongs to the object on the right */
212 echo " </td><td> </td>";
213 display_parameter($par->name, $pr, "right", $this->is_removed($par->paramid));
224 $page = new param_diff("Gnucomo Parameter Comparison");