name] = $prop->value;
}
return $properties;
}
/* Return true if both associative arrays are identical */
function property_compare($prop, $comp)
{
$equal = true;
if (empty($prop) || empty($comp))
{
$equal = empty($prop) && empty($comp);
}
else
{
reset($comp);
foreach ($prop as $name => $val)
{
if ($equal)
{
$to_compare = each($comp);
$equal = $to_compare[0] == $name && $to_compare[1] == $val;
}
}
}
return $equal;
}
/* Display a parameter in two adjecent table cells */
function display_parameter($name, $properties, $css_class = "", $shaded = FALSE)
{
if ($shaded)
{
$css_class = 'shaded';
}
echo "
";
echo $name;
echo " | ";
foreach ($properties as $p_name => $p_value)
{
echo " $p_name=$p_value";
}
echo " | ";
}
class param_diff extends page
{
function is_removed($paramid)
{
$qry ="select change_nature from history where paramid= CAST('";
$qry .= $paramid . "' AS BIGINT) order by modified desc";
$rhist = pg_exec($this->database, $qry);
$hist = pg_fetch_object($rhist, 0);
return $hist->change_nature == "REMOVED";
}
function Body()
{
if (!empty($_POST['oid']))
{
$res = pg_exec($this->database, "SELECT objectid, objectname FROM object
WHERE objectid=" . $_POST['oid']);
$obj = pg_fetch_object($res, 0);
echo "" . $_POST['class'] . " parameters for " . $obj->objectname;
$res = pg_exec($this->database, "SELECT objectid, objectname FROM object
WHERE objectid=" . $_POST['compare_to']);
$cmp_obj = pg_fetch_object($res, 0);
echo " compared to " . $cmp_obj->objectname . "
";
$res = pg_exec($this->database, "SELECT objectid, paramid, name FROM parameter "
. "WHERE objectid=" . $obj->objectid . " OR objectid=" . $cmp_obj->objectid
. " AND class='" . $_POST['class'] . "' ORDER BY name, objectid");
echo "\n";
echo "" . $obj->objectname . " | ";
echo "" . $cmp_obj->objectname . " |
\n";
echo "Name | Properties | Name | Propterties |
\n";
$hide_removed = true;
$hide_removed = empty($_POST['show_removed']) || $_POST['show_removed'] != 'on';
$row = 0;
while ($row < pg_numrows($res))
{
// Find the next two parameters, optionally skipping removed parameters.
$par = false;
while (!$par && $row < pg_numrows($res))
{
$par = pg_fetch_object($res, $row);
if ($hide_removed && $this->is_removed($par->paramid))
{
$par = false;
$row++;
}
}
$nextpar = false;
$nextrow = $row + 1;
while (!$nextpar && $nextrow < pg_numrows($res))
{
$nextpar = pg_fetch_object($res, $nextrow);
if ($hide_removed && $this->is_removed($nextpar->paramid))
{
$nextpar = false;
$nextrow++;
}
}
echo "";
if ($nextpar && $par->name == $nextpar->name)
{
/* Both objects have this parameter */
$row++;
$pr = param_properties($this->database, $par->paramid);
$prnext = param_properties($this->database, $nextpar->paramid);
if (property_compare($pr, $prnext))
{
$Style = "";
}
else
{
$Style = "both";
}
// We want the parameters of $obj on the left, so we need
// to swap the left and right sides if appropriate.
if ($par->objectid == $obj->objectid)
{
display_parameter($par->name, $pr, $Style, $this->is_removed($par->paramid));
display_parameter($nextpar->name, $prnext, $Style, $this->is_removed($nextpar->paramid));
}
else
{
display_parameter($nextpar->name, $prnext, $Style, $this->is_removed($nextpar->paramid));
display_parameter($par->name, $pr, $Style, $this->is_removed($par->paramid));
}
}
else
{
/* Only one of the objects has this parameter */
$pr = param_properties($this->database, $par->paramid);
if ($par->objectid == $obj->objectid)
{
/* Parameter belongs to the object on the left */
display_parameter($par->name, $pr, "left", $this->is_removed($par->paramid));
echo " | ";
}
else
{
/* Parameter belongs to the object on the right */
echo " | ";
echo " | | ";
display_parameter($par->name, $pr, "right", $this->is_removed($par->paramid));
}
}
echo "
\n";
$row++;
}
echo "
\n";
}
}
}
$page = new param_diff("Gnucomo Parameter Comparison");
$page->Showpage();
?>