$v) { $variables[$k] = json_decode($v,true); } # Turn off the warning reporting error_reporting(E_ERROR | E_PARSE); $qValue = json_decode(stripslashes($_REQUEST['qstring']),true); //$qString = implode("','",$qstring); $output = $_REQUEST['output']; $queryItem = $_REQUEST['qitem']; $layersToSearch = explode(':', $_REQUEST['qlayers']); # get some config $tempDirectory = $CONFIGURATION['temp']; # get some layout information $maxRows = $CONFIGURATION['label_rows']; $maxColumns = $CONFIGURATION['label_columns']; # This will load the line template into an Array $labelLines = (int)$CONFIGURATION['label_lines']; $lineTemplate = array(); for($i = 1; $i <= $labelLines; $i++) { array_push($lineTemplate, $CONFIGURATION['label_line_'.$i]); } $mapbook = getMapbook(); $msXML = $mapbook->getElementsByTagName('map-source'); # Array to store the popups found. $content = ''; $totalResults = 0; $firstResult = false; $resultFeatures = array(); for($i = 0; $i < $msXML->length; $i++) { $node = $msXML->item($i); $layers = $node->getElementsByTagName('layer'); for($l = 0; $l < $layers->length; $l++) { $layer = $layers->item($l); $layerName = $layer->getAttribute('name'); $path = $node->getAttribute('name').'/'.$layerName; if(in_array($path, $layersToSearch)) { $file = $node->getElementsByTagName('file')->item(0)->firstChild->nodeValue; # Okay, now it's time to cook if(substr($file,0,1) == '.') { $file = $CONFIGURATION['root'].$file; } $map = ms_newMapObj($file); # Create an array of query layers $queryLayers = array(); if($layerName == 'all') { for($ml = 0; $ml < $map->numlayers; $ml++) { array_push($queryLayers, $map->getLayer($ml)); } } else { # Turn on the specific layer array_push($queryLayers, $map->getLayerByName($layerName)); } # Iterate through the queryLayers... foreach($queryLayers as $queryLayer) { foreach($qValue as $queryValue) { $queryLayer->set('template', $queryLayer->getMetaData('itemquery')); if($altTemplate) { $queryLayer->set('template', $queryLayer->getMetaData($altTemplate)); } $queryLayer->set('status', MS_DEFAULT); $queryString = $queryLayer->getMetaData('itemquery-filter'); $queryString = str_replace('[qitem]', $queryItem, $queryString); $queryString = str_replace('[qstring]', $queryValue, $queryString); $queryLayer->setFilter($queryString); $filterItem = $queryLayer->getMetaData('itemquery-filteritem'); if($filterItem) { $queryLayer->set('filteritem', $filterItem); } if($queryItem) { $queryLayer->set('filteritem', $queryItem); } $queryLayer->queryByRect($queryLayer->getExtent()); $queryLayer->open(); $numResults = $queryLayer->getNumResults(); for($rx = 0; $rx < $numResults; $rx++) { $res = $queryLayer->getResult($rx); array_push($resultFeatures, $queryLayer->getFeature($res->shapeindex)); } } $queryLayer->close(); } } } } $numRecords = sizeof($resultFeatures); $allAddresses = array(); # this is added to support a more elaborate CSV format $csv_addresses = array(); for($i = 0; $i < $numRecords; $i++) { $rec = $resultFeatures[$i]->values; $address = array(); for($line = 0; $line < $labelLines; $line++) { $address[$line] = $lineTemplate[$line]; foreach($rec as $k=>$v) { $address[$line] = str_replace('%'.$k.'%', trim($v), $address[$line]); } $address[$line] = trim($address[$line]); } array_push($allAddresses, $address); # build the virtual csv file $current_address = $CONFIGURATION['csv_record']; foreach($rec as $k=>$v) { $current_address = str_replace('%'.$k.'%', trim($v), $current_address); } $csv_addresses[] = $current_address; } //dbase_close($dbase); # So I wrote this to just test the functionality. It seems to work pretty well. if($output == 'html') { print "
"; $i = 0; $column = 0; $row = 0; while($i < $numRecords) { if($row == 0 and $column == 0) { print "";
for($line = 0; $line < $labelLines; $line++) {
print $allAddresses[$i][$line]." "; } print " | ";
$i++;
$column++;
if($column >= $maxColumns) {
print "