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.4 $
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.4 2003-07-15 11:06:45 arjen
31 Removed parameters are displayed in a shaded style.
33 Revision 1.3 2003/02/13 09:01:29 arjen
34 All web interface pages use the page class.
36 Revision 1.2 2003/02/05 09:47:39 arjen
37 Display the difference of all package class parameters for two objects
39 ******************************/
41 // RCSID = "$Id: parameter_compare.php,v 1.4 2003-07-15 11:06:45 arjen Exp $";
43 ini_set('include_path', '.:./classes:../phpclasses');
45 require_once('page.class.php');
48 /* Returns an associative array with all properties of a parameter (pid) */
50 function param_properties($db, $pid)
53 $r = pg_exec($db, "SELECT name, value FROM property WHERE paramid='" . $pid . "'");
54 for ($p = 0; $p < pg_numrows($r); $p++)
56 $prop = pg_fetch_object($r, $p);
57 $properties[$prop->name] = $prop->value;
62 /* Return true if both associative arrays are identical */
64 function property_compare($prop, $comp)
68 if (empty($prop) || empty($comp))
70 $equal = empty($prop) && empty($comp);
75 foreach ($prop as $name => $val)
79 $to_compare = each($comp);
80 $equal = $to_compare[0] == $name && $to_compare[1] == $val;
87 /* Display a parameter in two adjecent table cells */
89 function display_parameter($name, $properties, $css_class = "", $shaded = FALSE)
93 $css_class = 'shaded';
98 echo " class='$css_class'";
103 if ($css_class != "")
105 echo " class='$css_class'";
108 foreach ($properties as $p_name => $p_value)
110 echo " $p_name=$p_value";
115 class param_diff extends page
118 function is_removed($paramid)
120 $qry ="select change_nature from history where paramid= CAST('";
121 $qry .= $paramid . "' AS BIGINT) order by modified desc";
122 $rhist = pg_exec($this->database, $qry);
123 $hist = pg_fetch_object($rhist, 0);
125 return $hist->change_nature == "REMOVED";
130 if (!empty($_POST['oid']))
132 $res = pg_exec($this->database, "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($this->database, "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($this->database, "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");
144 echo "<tr><th colspan='2'>" . $obj->objectname . "</th>";
145 echo "<th colspan='2'>" . $cmp_obj->objectname . "</th></tr>\n";
146 echo "<tr><th>Name</th><th>Properties</th><th>Name</th><th>Propterties</th></tr>\n";
148 while ($row < pg_numrows($res))
150 $par = pg_fetch_object($res, $row);
152 if ($row + 1 < pg_numrows($res))
154 $nextpar = pg_fetch_object($res, $row + 1);
158 if ($nextpar && $par->name == $nextpar->name)
160 /* Both objects have this parameter */
163 $pr = param_properties($this->database, $par->paramid);
164 $prnext = param_properties($this->database, $nextpar->paramid);
165 if (property_compare($pr, $prnext))
167 display_parameter($par->name, $pr, "", $this->is_removed($par->paramid));
168 display_parameter($nextpar->name, $prnext, "", $this->is_removed($nextpar->paramid));
172 // We want the parameters of $obj on the left, so we need
173 // to swap the left and right sides if appropriate.
175 if ($par->objectid == $obj->objectid)
177 display_parameter($par->name, $pr, "both", $this->is_removed($par->paramid));
178 display_parameter($nextpar->name, $prnext, "both", $this->is_removed($nextpar->paramid));
182 display_parameter($nextpar->name, $prnext, "both", $this->is_removed($nextpar->paramid));
183 display_parameter($par->name, $pr, "both", $this->is_removed($par->paramid));
189 /* Only one of the objects has this parameter */
191 $pr = param_properties($this->database, $par->paramid);
193 if ($par->objectid == $obj->objectid)
195 /* Parameter belongs to the object on the left */
197 display_parameter($par->name, $pr, "left", $this->is_removed($par->paramid));
198 echo "<td> </td><td> ";
202 /* Parameter belongs to the object on the right */
205 echo " </td><td> </td>";
206 display_parameter($par->name, $pr, "right", $this->is_removed($par->paramid));
217 $page = new param_diff("Gnucomo Parameter Comparison");