title = $title; } public $title; } $locale = GetDefaultLocale(); $userInput = ""; $target = ""; $popup = 0; $layerName = ""; $mapName = ""; $sessionId = ""; $filter = ""; $resNames = array(); $resProps = array(); $matchLimit = ""; $features = NULL; $pointZoom = 500.0; GetRequestParameters(); SetLocalizedFilesPath(GetLocalizationPath()); $searchError = GetLocalizedString("SEARCHERROR", $locale); try { $featureSrvc = $siteConnection->CreateService(MgServiceType::FeatureService); //Create a temporary map runtime object, locate the layer $map = new MgMap($siteConnection); $map->Open($mapName); $layers = $map->GetLayers(); $layer = null; //fwrite($logHandle,"found layers:".$layers->GetCount()."\n"); for($i = 0; $i < $layers->GetCount(); $i++) { $layer = $layers->GetItem($i); //fwrite($logHandle,"found layer:".$layer->GetName()."\n"); if($layer->GetName() == $layerName) break; } if($layer == null) { trigger_error(FormatMessage("SEARCHLAYERNOTFOUND", $locale, array($layerName))); } $userInput = str_replace("'", "''", $userInput); //unescape strings // if(ini_get("magic_quotes_sybase") == "1") { $matchLabel = str_replace("''", "'", $matchLabel); $filter = str_replace("''", "'", $filter); } else if(get_magic_quotes_gpc() == "1") { //Unescape single quotes $filter = str_replace("\\'", "'", $filter); //Unescape double quotes $filter = str_replace('\\"', '"', $filter); //remove additional backslash $filter = str_replace("\\", "", $filter); } //fwrite($logHandle,"filter before:".$filter."\n"); //substitute the input tag with the actual user input to make up the filter $filter = str_replace('$USER_VARIABLE', $userInput, $filter); //fwrite($logHandle,"filter after:".$filter."\n"); //parse the match label string, which defines what columns to be displayed $displayAll = (count($resProps) == 0); //query the features $clsDef = $layer->GetClassDefinition(); $opts = BuildFeatureQueryOptions($clsDef); $opts->SetFilter($filter); $featureClassName = $layer->GetFeatureClassName(); $srcId = new MgResourceIdentifier($layer->GetFeatureSourceId()); $features = $featureSrvc->SelectFeatures($srcId, $featureClassName, $opts); $hasResult = $features->ReadNext(); if($hasResult) { //fwrite($logHandle,"has result\n"); $colCount = $displayAll? $features->GetPropertyCount(): count($resProps); //output the beginning of the document (head section and beginning of body section) $templ = file_get_contents("./Search.templ"); $templ = Localize($templ, $locale, GetClientOS()); print sprintf($templ, $colCount, $target, $popup, $mapName); $classDef = $features->GetClassDefinition(); $clsProps = $classDef->GetProperties(); $geomName = $classDef->GetDefaultGeometryPropertyName(); $bHasPoint = false; $xform = NULL; // layer -> map transform $agfRw = new MgAgfReaderWriter(); if ($geomName != NULL && $geomName != "") { $gidx = $clsProps->IndexOf($geomName); if ($gidx >= 0) { $geomProp = $clsProps->GetItem($gidx); if ($geomProp->GetGeometryTypes() & MgFeatureGeometricType::Point == MgFeatureGeometricType::Point) { $bHasPoint = true; // Set layer -> map transform if required $scReader = $featureSrvc->GetSpatialContexts($srcId, false); while ($scReader->ReadNext()) { if ($scReader->GetName() == $geomProp->GetSpatialContextAssociation()) { $csFactory = new MgCoordinateSystemFactory(); try { $mapCs = $csFactory->Create($map->GetMapSRS()); $layerCs = $csFactory->Create($scReader->GetCoordinateSystemWkt()); $xform = $csFactory->GetTransform($layerCs, $mapCs); } catch (MgException $ex) { } } } $scReader->Close(); } } } $idProps = $classDef->GetIdentityProperties(); $idPropNames = array(); for($j = 0; $j < $idProps->GetCount(); $j++) { $idProp = $idProps->GetItem($j); array_push($idPropNames, $idProp->GetName()); } //table headings echo "