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 = "") { echo ""; echo $name; echo ""; foreach ($properties as $p_name => $p_value) { echo " $p_name=$p_value"; } echo ""; } if (empty($_SESSION['username'])) { echo "Please log in first."; } else { $config = new gnucomo_config; $config->read("gnucomo"); // Connect to the database $conn = pg_connect($config->Database($_SESSION['username'], $_SESSION['password'])); if (!empty($_POST['oid'])) { $res = pg_exec("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("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("SELECT objectid, paramid, name FROM parameter " . "WHERE objectid=" . $obj->objectid . " OR objectid=" . $cmp_obj->objectid . " AND class='" . $_POST['class'] . "' ORDER BY name, objectid"); ?> \n"; echo "" . $obj->objectname . ""; echo "" . $cmp_obj->objectname . "\n"; echo "NamePropertiesNamePropterties\n"; $row = 0; while ($row < pg_numrows($res)) { $par = pg_fetch_object($res, $row); $nextpar = 'false'; if ($row + 1 < pg_numrows($res)) { $nextpar = pg_fetch_object($res, $row + 1); } echo ""; if ($nextpar && $par->name == $nextpar->name) { /* Both objects have this parameter */ $row++; $pr = param_properties($conn, $par->paramid); $prnext = param_properties($conn, $nextpar->paramid); if (property_compare($pr, $prnext)) { display_parameter($par->name, $pr); display_parameter($nextpar->name, $prnext); } else { // 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, "both"); display_parameter($nextpar->name, $prnext, "both"); } else { display_parameter($nextpar->name, $prnext, "both"); display_parameter($par->name, $pr, "both"); } } } else { /* Only one of the objects has this parameter */ $pr = param_properties($conn, $par->paramid); if ($par->objectid == $obj->objectid) { /* Parameter belongs to the object on the left */ display_parameter($par->name, $pr, "left"); echo "  "; } else { /* Parameter belongs to the object on the right */ echo ""; echo "  "; display_parameter($par->name, $pr, "right"); } } echo "\n"; $row++; } echo "\n"; } } ?>