";
$totResults = 0;
//LOOP ON LAYERS
for ($i = 0; $i < $tot; $i++) {
$oLayer = $oMap->getLayer($i);
//CHECKING GROUPS FOR VISIBILITY
if ($oLayer->type != MS_LAYER_RASTER) {
//echo($oLayer->group);
//if BASE group
/*if ($oLayer->group == "")
$oLayer->set('status', MS_ON);
//if on visible group
elseif (in_array($oLayer->group, $aGroup)) {
$oLayer->set('status', MS_ON);
if (!$oLayer->isVisible() && ($oLayer->minscale < $scale && $oLayer->maxscale > $scale)) {
$oLayer->set("minscale", 0);
$oLayer->set("maxscale", (200000000)); // has to be greater that map maximum scale
}
} else {
$oLayer->set('status', MS_OFF);
if (!$oLayer->isVisible() && ($oLayer->minscale < $scale && $oLayer->maxscale > $scale)) {
$oLayer->set("minscale", 0);
$oLayer->set("maxscale", (200000000)); // has to be greater that map maximum scale
}
continue;
}*/
$szSearchfield = $oLayer->getMetaData('searchfield');
//PRINTING STUFF
if($oLayer->connectiontype == MS_POSTGIS){
// $searchstring = "\"".$szSearchfield."~* '".$searchstring."'\""; //old search string
//**Rebuild the searchstring afresh for each layer
$searchstr = "\"".$szSearchfield."~* '".$searchstring."'\"";
}
//echo "
Searchstring:
" . $searchstring . "
";
//echo "
Searchfield:
" . $szSearchfield . "
";
//echo "
Searchfield:
" . "\$oLayer->queryByAttributes($szSearchfield, $searchstr, MS_MULTIPLE) == MS_SUCCESS". "
";
if ($szSearchfield != "") //**since we are checking all layers this should skip all without searchfield set
if ($oLayer->queryByAttributes($szSearchfield, $searchstr, MS_MULTIPLE) == MS_SUCCESS) {
//echo "
num records:".$oLayer->getNumResults();
$totR = $oLayer->getNumResults();
$totResults = $totResults + $totR;
echo "
Layer Name:
" . $oLayer->name . "
";
if($max_results_per_layer < $totR) echo "
results: $max_results_per_layer of $totR (limited output)
";
else echo "
results: $totR
";
$oLayer->open();
// METADATA
$szFields = $oLayer->getMetaData("fields");
//echo "
Fields".$szFields;
if ($szFields != '') {
$aField = explode(',', $szFields);
foreach ($aField as $key => $value) {
$field = explode(':', $value);
$fields[$field[0]] = (count($field) == 2) ? $field[1] : null;
}
}
//get hyiperlink
$szHyperlink = $oLayer->getMetaData("hyperlink");
if ($szHyperlink != '') {
$hyperlink = explode('|', $szHyperlink);
} else
$hyperlink = null;
//END METADATA
echo "
";
if ($totR) {
$oResultCache = $oLayer->getResult($i);
$oShape = $oLayer->getShape($oResultCache->tileindex, $oResultCache->shapeindex);
$aKeys = array_keys($oShape->values);
foreach ($aKeys as $key) {
$aKeysNormal[] = strtoupper($key);
}
echo "";
foreach ($fields as $key => $value) {
if (in_array(strtoupper($key), $aKeysNormal)) {
echo "" . $fields[$key] . " | ";
} else
unset ($fields[$key]);
}
if ($hyperlink) {
if (in_array($hyperlink[0], $aKeys))
echo "" . $hyperlink[0] . " - hyperlink | ";
else
$hyperlink = null;
}
echo "Zoom to | ";
echo "
";
/* //ALL FIELDS
echo "";
foreach($aKeys as $key){
echo "$key | ";
}
echo "
";*/
if ($oShape)
$oShape->free();
}
if ($totR > $max_results_per_layer)
$totR = $max_results_per_layer;
for ($a = 0; $a < $totR; $a++) {
$oResultCache = $oLayer->getResult($a);
$oShape = $oLayer->getShape($oResultCache->tileindex, $oResultCache->shapeindex);
$aValues = $oShape->values;
//Calculate centroid for example tooltipe needs
$x_c = ($oShape->bounds->minx + $oShape->bounds->maxx) / 2;
$y_c = ($oShape->bounds->miny + $oShape->bounds->maxy) / 2;
//$aTmp = array_merge( $aTmp , array('x' => $x,'y' => $y, 'id' => $result->shapeindex));
//Calculate area coordinates for example function gotorectangle
$xmin = $oShape->bounds->minx;
$xmax = $oShape->bounds->maxx;
$ymin = $oShape->bounds->miny;
$ymax = $oShape->bounds->maxy;
echo "";
//echo "".print_r($aValues)." | ";
foreach ($fields as $key => $value) {
if ($aValues[strtoupper($key)]) {
$val = $aValues[strtoupper($key)];
} else
if ($aValues[strtolower($key)]) {
$val = $aValues[strtolower($key)];
} else
if ($aValues[$key]) {
$val = $aValues[$key];
} else {
$val = " ";
}
echo "$val | ";
}
echo " | ";
//if($value)echo "$value | ";
//else echo " | ";
echo "
";
$oShape->free();
}
echo "
";
if ($totR > $max_results_per_layer)
echo "Too many values to output, please reduce the request.";
$oLayer->close();
$fields = array ();
}
}
}
//$image=$oMap->drawQuery();
//$url=$image->saveWebImage();
if ($totResults) {
// echo "
tot res:$totResults
";
} else
echo "
no matching results
";
?>