Пример #1
0
 /**
  * Init function, parse JSON result string 
  */
 function __construct($json)
 {
     // Remove problematic characters for JSON parsing
     $json = str_replace(array('\\"'), array("''"), $json);
     $this->jsonList = PMCommon::parseJSON($json);
     //pm_logDebug(3, $this->jsonList);
     $dateAndTime = date('Y-m-d_H-i-s');
     $this->currentTimeForFileName = $dateAndTime;
     $this->tempFilePath = $_SESSION['web_imagepath'] . $this->currentTimeForFileName . '_' . session_id();
     $this->tempFileLocation = $_SESSION['web_imageurl'] . $this->currentTimeForFileName . '_' . session_id();
 }
Пример #2
0
<?php

header("Content-type: text/javascript");
require_once "../group.php";
require_once "../pmsession.php";
$gLanguage = $_SESSION["gLanguage"];
require_once "../common.php";
require_once "../locale/language_" . $gLanguage . ".php";
// Print list with locales for access via JS
foreach ($_sl as $k => $v) {
    print "PM.Locales.list['{$k}'] = '" . str_replace('\\\\r\\\\n', '\\r\\n', addslashes($v)) . "';\n";
}
// Write compressed JS functions from plugins
$plugin_jsFileList = $_SESSION['plugin_jsFileList'];
$debugLevel = $_SESSION['debugLevel'];
if (count($plugin_jsFileList) > 0) {
    foreach ($plugin_jsFileList as $jsLoc) {
        $jsFile = $_SESSION['PM_BASE_DIR'] . "/{$jsLoc}";
        print PMCommon::compressJavaScriptFile($jsFile, $debugLevel);
    }
}
print "PM.grouplist = " . PMCommon::parseJSON($_SESSION['grouplist'], false) . ";";
Пример #3
0
 /**
  * Get CSS file references
  */
 private function initCSSReference()
 {
     $cssReference = "";
     $regExpForUrlPath = '/(url\\(["\']?)([^\\/\\)][^\\)]*["\']?\\))/';
     $plugin_cssFileList = $_SESSION['plugin_cssFileList'];
     if (count($plugin_cssFileList) > 0) {
         $mergeCSS = isset($_SESSION['pm_merge_css_plugins_files']) && $_SESSION['pm_merge_css_plugins_files'] == 1;
         if ($mergeCSS) {
             $cssReference .= "<style type=\"text/css\">\n";
         }
         foreach ($plugin_cssFileList as $pf) {
             if (!$mergeCSS) {
                 $cssReference .= " <link rel=\"stylesheet\" href=\"{$pf}\" type=\"text/css\" />\n";
             } else {
                 $tmpFile = $_SESSION['PM_BASE_DIR'] . "/{$pf}";
                 if (file_exists($tmpFile) && is_file($tmpFile)) {
                     ob_start();
                     include $tmpFile;
                     $cssReferenceTmp = ob_get_contents();
                     // change path for images:
                     $path = dirname($pf) . '/';
                     $cssReferenceTmp = preg_replace($regExpForUrlPath, "\$1{$path}\$2", $cssReferenceTmp);
                     $cssReference .= $cssReferenceTmp;
                     $cssReference .= "\n";
                     ob_end_clean();
                 }
             }
         }
         if ($mergeCSS) {
             $cssReference .= "</style>\n";
         }
     }
     $dirNames = array();
     //- from config/common (custom) dir
     $dirNames[] = PM_CONFIG_LOCATION_COMMON;
     //- from config dir
     $dirNames[] = PM_CONFIG_LOCATION;
     $dirNames = array_unique($dirNames);
     $mergeCSS = isset($_SESSION['pm_merge_css_config_files']) && $_SESSION['pm_merge_css_config_files'] == 1;
     $cssReferenceFiles = array();
     foreach ($dirNames as $dirName) {
         $dirTmp = PM_BASECONFIG_DIR . "/{$dirName}";
         if (file_exists($dirTmp)) {
             $cssFiles = PMCommon::scandirByExt($dirTmp, 'css');
             $cssFiles = array_unique($cssFiles);
             foreach ($cssFiles as $cf) {
                 $cssReferenceFiles[] = "config/{$dirName}/{$cf}";
             }
         }
     }
     $cssReferenceFiles = array_unique($cssReferenceFiles);
     if ($mergeCSS && count($cssReferenceFiles) > 0) {
         $cssReference .= "<style type=\"text/css\">\n";
     }
     foreach ($cssReferenceFiles as $cssReferenceFile) {
         if ($mergeCSS) {
             $tmpFile = $_SESSION['PM_BASE_DIR'] . "/{$cssReferenceFile}";
             if (file_exists($tmpFile) && is_file($tmpFile)) {
                 ob_start();
                 include $tmpFile;
                 $cssReferenceTmp = ob_get_contents();
                 // change path for images:
                 $path = dirname($cssReferenceFile) . '/';
                 $cssReferenceTmp = preg_replace($regExpForUrlPath, "\$1{$path}\$2", $cssReferenceTmp);
                 $cssReference .= $cssReferenceTmp;
                 $cssReference .= "\n";
                 ob_end_clean();
             }
         } else {
             $cssReference .= " <link rel=\"stylesheet\" href=\"{$cssReferenceFile}\" type=\"text/css\" />\n";
         }
     }
     if ($mergeCSS && count($cssReferenceFiles) > 0) {
         $cssReference .= "</style>\n";
     }
     return $cssReference;
 }
Пример #4
0
 function dumpXYQueryResults()
 {
     $pearDbClass = $_SESSION['pearDbClass'];
     require_once "{$pearDbClass}.php";
     $eqr = $_SESSION["equeryRect"];
     // XY Layer Properties
     $XYLayerProperties = $this->glayer->getXYLayerProperties();
     if ($XYLayerProperties['noQuery']) {
         return false;
     }
     $dsn = $XYLayerProperties["dsn"];
     $xyTable = $XYLayerProperties["xyTable"];
     $x_fld = $XYLayerProperties["x_fld"];
     $y_fld = $XYLayerProperties["y_fld"];
     $classidx_fld = $XYLayerProperties["classidx_fld"];
     $oid_fld = $XYLayerProperties["oid_fld"];
     $resFieldList = $this->glayer->getResFields();
     $resFldStr = join(',', $resFieldList);
     // Prepare SQL query
     if (preg_match("/@/", $xyTable)) {
         // Check for WHERE filter in table definition
         $xyList = preg_split('/@/', $xyTable);
         $whereFilter = $xyList[1];
         $xyTable = $xyList[0];
     }
     $sql_select = "SELECT {$x_fld}, {$y_fld}, {$resFldStr} FROM {$xyTable}";
     $qr = $this->xyLayQueryList;
     $changeLayProj = PMCommon::checkProjection($this->map, $this->qLayer);
     // Map extent for limiting query
     if ($changeLayProj) {
         $mapExt = ms_newRectObj();
         $mapExt->setExtent($qr["xmin"], $qr["ymin"], $qr["xmax"], $qr["ymax"]);
         $mapExt->project($changeLayProj['mapProj'], $changeLayProj['layProj']);
         $qxmin = $mapExt->minx;
         $qymin = $mapExt->miny;
         $qxmax = $mapExt->maxx;
         $qymax = $mapExt->maxy;
     } else {
         $qxmin = $qr["xmin"];
         $qymin = $qr["ymin"];
         $qxmax = $qr["xmax"];
         $qymax = $qr["ymax"];
     }
     if ($this->search) {
         $sql_where = "WHERE " . ($whereFilter ? $whereFilter . " AND " : "") . $qr;
     } else {
         $sql_where = "WHERE " . ($whereFilter ? $whereFilter . " AND " : "") . " {$x_fld} >= {$qxmin} AND {$x_fld} <= {$qxmax} AND {$y_fld} >= {$qymin} AND {$y_fld} <= {$qymax} ";
     }
     $sql = "{$sql_select}  {$sql_where}";
     pm_logDebug(3, $query, "P.MAPPER-DEBUG: squery.php/dumpXYQueryResults() - SQL Cmd:");
     // init DB class
     $db = new $pearDbClass();
     // Connect to DB
     $dbh = $db->connect($dsn);
     if ($db->isError($dbh)) {
         PMCommon::db_logErrors($dbh);
         die;
     }
     // Execute query
     $res = $dbh->query($sql);
     if ($db->isError($res)) {
         PMCommon::db_logErrors($res);
         die;
     }
     $this->mExtMinx = 999999999;
     $this->mExtMiny = 999999999;
     $this->mExtMaxx = -999999999;
     $this->mExtMaxy = -999999999;
     // Now print results as JSON
     $nres = 0;
     $numrows = $res->numRows();
     while ($row = $res->fetchRow(2)) {
         if ($changeLayProj) {
             $nP = ms_newpointobj();
             $nP->setXY($row["{$x_fld}"], $row["{$y_fld}"]);
             $nP->project($changeLayProj['layProj'], $changeLayProj['mapProj']);
             $rx = $nP->x;
             $ry = $nP->y;
         } else {
             $rx = $row["{$x_fld}"];
             $ry = $row["{$y_fld}"];
         }
         $buf = $this->pointBuffer;
         //error_log($buf);
         $shpMinx = $rx - $buf;
         $shpMiny = $ry - $buf;
         $shpMaxx = $rx + $buf;
         $shpMaxy = $ry + $buf;
         if ($this->zoomFull) {
             $this->mExtMinx = min($this->mExtMinx, $shpMinx);
             $this->mExtMiny = min($this->mExtMiny, $shpMiny);
             $this->mExtMaxx = max($this->mExtMaxx, $shpMaxx);
             $this->mExtMaxy = max($this->mExtMaxy, $shpMaxy);
         }
         // Link for zoom to feature
         $qShpIdx = $row["{$oid_fld}"];
         $this->resultindexes[] = $row["{$x_fld}"] . "@" . $row["{$y_fld}"];
         // Output JSON
         //$qShpLink = "{\"shplink\": [\"0\",\"0\",\"" . $shpMinx ."+". $shpMiny ."+". $shpMaxx ."+". $shpMaxy ."\,0"]}";
         $qShpLink = "{\"shplink\": [\"" . $this->qLayerName . "\",\"" . $qShpIdx . "\",\"" . $shpMinx . "+" . $shpMiny . "+" . $shpMaxx . "+" . $shpMaxy . "\"" . ($this->zoomFull ? ",1" : ",0") . "]}";
         if ($nres > 0) {
             $this->qStr .= ", ";
         }
         // Add shape link
         $this->qStr .= "[" . $qShpLink;
         // Add 'normal' field values
         foreach ($resFieldList as $fn) {
             $this->qStr .= $this->printFieldValues($fn, $row["{$fn}"]);
         }
         $this->qStr .= "]";
         $nres++;
         // Stop query if result records exceed limit set in config.ini
         if ($nres > $this->limitResult) {
             break;
         }
     }
     $this->numResults = $nres;
     $res->free();
     $dbh->disconnect();
 }
Пример #5
0
 protected function drawImages($printType, $imgDPI, $imgFormat, $prefmap)
 {
     // CREATE MAP IMAGE AND PASTE SCALEBAR AND REFERENCE MAP
     switch ($printType) {
         // HTML OUTPUT
         case "html":
             // allow to redefine images drawing
             $this->map->set("width", $this->mapW);
             $this->map->set("height", $this->mapH);
             //                $this->map->set("resolution", 96);
             $images = $this->drawScaleBarAndRefMap($printType, $imgDPI);
             $sbarImg = $images['sbarImg'];
             $refImg = $images['refImg'];
             $this->pmap_setImgFormat(true);
             $mapImg = $this->map->draw();
             // CHECK iF THERE'S AN XY-LAYER AND THEN DRAW IT
             if ($this->existsXYLayer) {
                 $this->pmap_drawXYLayer($mapImg);
             }
             //$mapImg->pasteImage($sbarImg, 0, 3, $this->mapH-25);
             //if ($prefmap) $mapImg->pasteImage($refImg, -1);
             //$this->imgUrlList[] = $mapImg->saveWebImage();
             $this->imgUrlList[] = PMCommon::mapSaveWebImage($this->map, $mapImg);
             $this->imgUrlList[] = PMCommon::mapSaveWebImage($this->map, $refImg, true);
             $this->imgUrlList[] = PMCommon::mapSaveWebImage($this->map, $sbarImg);
             PMCommon::freeMsObj($mapImg);
             break;
             // PDF OUTPUT
         // PDF OUTPUT
         case "pdf":
             // Increase size and resolution for better print quality (factor set in config.ini -> pdfres)
             // Note: resolution has to be increased, too, to keep scale dependency of layers
             $pdfres = $_SESSION["pdfres"];
             $this->map->set("width", $this->mapW * $pdfres);
             $this->map->set("height", $this->mapH * $pdfres);
             $this->map->set("resolution", 96 * $pdfres);
             // MS < 6
             // Increase Label size according to magnificion for PDF output
             $this->increaseLabels($pdfres);
             $images = $this->drawScaleBarAndRefMap($printType, $imgDPI, $pdfres);
             $sbarImg = $images['sbarImg'];
             $refImg = $images['refImg'];
             $this->pmap_setImgFormat(true);
             $mapImgHR = $this->map->draw();
             // CHECK iF THERE'S AN XY-LAYER AND THEN DRAW IT
             if ($this->existsXYLayer) {
                 $this->pmap_drawXYLayer($mapImgHR);
             }
             /*$this->imgUrlList[] = $mapImgHR->saveWebImage();
               $this->imgUrlList[] = $refImg->saveWebImage();
               $this->imgUrlList[] = $sbarImg->saveWebImage();*/
             $this->imgUrlList[] = PMCommon::mapSaveWebImage($this->map, $mapImgHR);
             $this->imgUrlList[] = PMCommon::mapSaveWebImage($this->map, $refImg, true);
             //$this->imgUrlList[] = $refImg->saveWebImage();
             $this->imgUrlList[] = PMCommon::mapSaveWebImage($this->map, $sbarImg);
             PMCommon::freeMsObj($mapImgHR);
             break;
             // DOWNLOAD HIGH RESOLUTION IMAGE
         // DOWNLOAD HIGH RESOLUTION IMAGE
         case "dl":
             // Increase Label size according to DPI
             $factor = round($imgDPI / 96);
             $this->increaseLabels($factor);
             $images = $this->drawScaleBarAndRefMap($printType, $imgDPI);
             $sbarImg = $images['sbarImg'];
             $refImg = $images['refImg'];
             //$this->map->selectOutputFormat("jpeg");
             if ($imgFormat) {
                 $this->map->selectOutputFormat($imgFormat);
             } else {
                 $this->pmap_setImgFormat(true);
             }
             $mapImgHR = $this->map->draw();
             // CHECK iF THERE'S AN XY-LAYER AND THEN DRAW IT
             if ($this->existsXYLayer) {
                 $this->pmap_drawXYLayer($mapImgHR);
             }
             // GeoTIFF output
             if ($imgFormat) {
                 $tmpFileName = str_replace('\\', '/', $this->map->web->imagepath) . substr(SID, 10) . ".tif";
                 $mapImgHR->saveImage($tmpFileName, $this->map);
                 $this->imgUrlList[] = $tmpFileName;
                 // JPG or PNG output
             } else {
                 $this->imgUrlList[] = PMCommon::mapSaveWebImage($this->map, $mapImgHR);
                 $legImg = $this->map->drawLegend();
                 $this->imgUrlList[] = PMCommon::mapSaveWebImage($this->map, $legImg);
                 PMCommon::freeMsObj($legImg);
             }
             PMCommon::freeMsObj($mapImgHR);
             break;
     }
     PMCommon::freeMsObj($refImg);
     PMCommon::freeMsObj($sbarImg);
 }
Пример #6
0
 $mapheight = $pmap->pmap_returnMapH();
 $geo_scale = $pmap->pmap_returnGeoScale();
 // Check if layers in TOC should be refreshed
 $visGroupsBefore = array();
 $visGroupsAfter = array();
 if ($scaleLayers) {
     foreach ($grouplist as $grp) {
         $grpName = $grp->getGroupName();
         $layerList = $grp->getLayers();
         foreach ($layerList as $glayer) {
             $layName = $glayer->getLayerName();
             $qLayer = $map->getLayerByName($layName);
             if (PMCommon::checkScale($map, $qLayer, $geo_scale)) {
                 $visGroupsAfter[] = $layName;
             }
             if (PMCommon::checkScale($map, $qLayer, $old_geo_scale)) {
                 $visGroupsBefore[] = $layName;
             }
         }
     }
     if ($visGroupsAfter == $visGroupsBefore) {
         $refreshToc = 0;
     } else {
         $refreshToc = 1;
     }
     // original code to determinate when legend has to be refreshed
     if ($refreshToc && $oldGroups != $groups) {
         $refreshLegend = 0;
     } else {
         $refreshLegend = 1;
     }
Пример #7
0
 /**
  * EXECUTE QUERY
  */
 public function q_execMapQuery()
 {
     //--------------------------------
     // Initialize tolerance to 0
     //--------------------------------
     $msLayers = array();
     // query in specified groups only:
     if (isset($_REQUEST['groups']) && $_REQUEST['groups']) {
         $msLayers = getLayersByGroupOrLayerName($this->map, $_REQUEST['groups']);
         // all groups:
     } else {
         for ($i = 0; $i < $this->map->numlayers; $i++) {
             $msLayers[] = $this->map->getLayer($i);
         }
     }
     foreach ($msLayers as $msLayer) {
         // change tolerance only for buffer zone search.
         if ($this->queryType == 'object') {
             $msLayer->set('tolerance', 0);
         }
     }
     // Modified by Thomas RAFFIN (SIRAP)
     // to test (substitution)
     // query by point
     // Modified by Thomas RAFFIN (SIRAP)
     // use layers with complex queries that are too long to select results
     // cause maxscaledenom is not used...
     $oldDatas = array();
     for ($i = 0; $i < $this->map->numlayers; $i++) {
         $qLayer = $this->map->getLayer($i);
         $layerName = $qLayer->name;
         if ($qLayer->getMetaData('PM_RESULT_DATASUBSTITION') != '') {
             $oldDatas[$layerName] = $qLayer->data;
             $qLayer->set('data', $qLayer->getMetaData('PM_RESULT_DATASUBSTITION'));
         }
     }
     // few lines from incphp/query/query.php
     // Patch from Alessandro Pasotti for fixing problems with result returned
     $this->map->setSize($this->mapwidth, $this->mapheight);
     // Set $this->map->extent to values of current map extent
     // otherwise values of TOLERANCE in map file are not interpreted correctly
     $this->map->setExtent($this->GEOEXT['minx'], $this->GEOEXT['miny'], $this->GEOEXT['maxx'], $this->GEOEXT['maxy']);
     $this->map->preparequery();
     if ($this->queryType == 'object') {
         if (isset($_SESSION['pluginsConfig']['graphicalqueries']) && isset($_SESSION['pluginsConfig']['graphicalqueries']['bufferOnlyWithScale'])) {
             $bufferOnlyWithScale = $_SESSION['pluginsConfig']['graphicalqueries']['bufferOnlyWithScale'] == 1;
         } else {
             $bufferOnlyWithScale = true;
         }
         if (!$bufferOnlyWithScale) {
             //				PMCommon::setGroups($this->map, $this->querygroups, $this->scale, 0, 1);
             PMCommon::setGroups($this->map, $this->querygroups, 0, 0, 1);
         }
         // Search selected object
         $jsonPMResult = $_SESSION['JSON_Results'];
         // "[...]" ou "{...}"
         $PMResult = json_decode($jsonPMResult);
         // array ou class
         if ($PMResult) {
             $objUnion = false;
             // List layer of selected object
             $layersWithResult = $PMResult[0];
             // be carreful : 0.000000001 is too small !!
             $smallBuffer = 1.0E-8;
             $mapProjStr = $this->map->getProjection();
             if ($_SESSION['MS_VERSION'] < 6) {
                 $mapProjObj = ms_newprojectionobj($mapProjStr);
             } else {
                 $mapProjObj = new projectionObj($mapProjStr);
             }
             // Loop on layers
             $layerName = '';
             foreach ($layersWithResult as $layerWithResult) {
                 $objUnionLayer = false;
                 // init layer to close the last open one
                 $layer = false;
                 $layerProjObj = false;
                 // Loop on layer objects
                 foreach ($layerWithResult->values as $selectedObject) {
                     // layer name
                     $currentLayerName = $selectedObject[0]->shplink[0];
                     if ($currentLayerName != $layerName) {
                         if ($layer) {
                             $layer->close();
                         }
                         $layerName = $currentLayerName;
                         $layer = $this->map->getLayerByName($layerName);
                         $layerProjObj = false;
                         $layerProjStr = $layer->getProjection();
                         if ($mapProjStr && $layerProjStr && $mapProjStr != $layerProjStr) {
                             if ($_SESSION['MS_VERSION'] < 6) {
                                 $layerProjObj = ms_newprojectionobj($layerProjStr);
                             } else {
                                 $layerProjObj = new projectionObj($layerProjStr);
                             }
                         }
                         $layer->open();
                     }
                     $shpIndex = $selectedObject[0]->shplink[1];
                     // Retrieve shape by its index.
                     $objShape = PMCommon::resultGetShape($_SESSION['MS_VERSION'], $layer, null, $shpIndex, -1);
                     // changed for compatibility with PG layers and MS >= 5.6
                     // reproject
                     if ($layerProjObj) {
                         $objShape->project($layerProjObj, $mapProjObj);
                     }
                     // Union of the shapes
                     if ($objUnionLayer) {
                         $objUnionLayer = $objShape->union($objUnionLayer);
                     } else {
                         $objUnionLayer = $objShape;
                     }
                 }
                 // End foreach : Loop of the layer
                 // close layer if exists
                 if ($layer) {
                     $layer->close();
                 }
                 if ($objUnionLayer) {
                     // Line : Buffer to convert Line or Point to Polygon
                     if ($objUnionLayer->type == MS_SHAPE_LINE && isset($_REQUEST['select_buffer']) && $_REQUEST['select_buffer'] > 0 || $objUnionLayer->type == MS_SHAPE_POINT) {
                         $objUnionLayer = $objUnionLayer->buffer($smallBuffer);
                         // if polygon -> the outline is removed to not select contiguous objects
                     } else {
                         if ($objUnionLayer->type == MS_SHAPE_POLYGON && !isset($_REQUEST['select_buffer'])) {
                             $objBoundary = $objUnionLayer->boundary();
                             $objBoundary = $objBoundary->buffer($smallBuffer);
                             $objUnionLayer = $objUnionLayer->difference($objBoundary);
                         }
                     }
                 }
                 if ($objUnionLayer) {
                     if ($objUnion) {
                         $objUnion = $objUnion->union($objUnionLayer);
                     } else {
                         $objUnion = $objUnionLayer;
                     }
                 }
                 // End if($objUnionLayer)
             }
             // End foreach : loop of layers
             // Buffer -> Buffer zone
             if (isset($_REQUEST['select_buffer'])) {
                 if ($objUnion) {
                     $objUnion = $objUnion->buffer($_REQUEST['select_buffer']);
                     unset($_REQUEST['select_buffer']);
                 }
             }
             if ($objUnion) {
                 // Query
                 @$this->map->queryByShape($objUnion);
             }
         }
         // Query by point
     } else {
         if ($this->queryType == 'point') {
             $tmpPoint = ms_newPointObj();
             $tmpPoint->setXYZ($_REQUEST['select_pointX'], $_REQUEST['select_pointY'], 0);
             if (isset($_REQUEST['select_buffer'])) {
                 @$this->map->queryByPoint($tmpPoint, MS_MULTIPLE, $_REQUEST['select_buffer']);
             } else {
                 @$this->map->queryByPoint($tmpPoint, MS_MULTIPLE, -1);
             }
             PMCommon::freeMsObj($tmpPoint);
             // query by Shape
         } else {
             if ($this->queryType == 'polygon') {
                 //'shape')
                 $poly = $_REQUEST['select_poly'];
                 $tmpLine = ms_newLineObj();
                 $tmpPoly = explode(',', $poly);
                 foreach ($tmpPoly as $point) {
                     $tmpTab = explode(' ', $point);
                     $tmpLine->addXY($tmpTab[0], $tmpTab[1]);
                 }
                 $objPoly = ms_newShapeObj(MS_SHAPE_POLYGON);
                 $objPoly->add($tmpLine);
                 // Buffer -> Buffer zone
                 if (isset($_REQUEST['select_buffer'])) {
                     $objPoly = $objPoly->buffer($_REQUEST['select_buffer']);
                     unset($_REQUEST['select_buffer']);
                 }
                 @$this->map->queryByShape($objPoly);
                 PMCommon::freeMsObj($tmpLine);
                 PMCommon::freeMsObj($objPoly);
                 // query by PolyLine
             } else {
                 if ($this->queryType == 'line') {
                     $poly = $_REQUEST['select_line'];
                     $tmpLine = ms_newLineObj();
                     $tmpPoly = explode(',', $poly);
                     foreach ($tmpPoly as $point) {
                         $tmpTab = explode(' ', $point);
                         $tmpLine->addXY($tmpTab[0], $tmpTab[1]);
                     }
                     // Reduce the polygon to a polyline
                     for ($i = count($tmpPoly) - 1; $i >= 0; $i--) {
                         $tmpTab = explode(' ', $tmpPoly[$i]);
                         $tmpLine->addXY($tmpTab[0], $tmpTab[1]);
                     }
                     $objPoly = ms_newShapeObj(MS_SHAPE_POLYGON);
                     $objPoly->add($tmpLine);
                     // Buffer -> Buffer zone
                     if (isset($_REQUEST['select_buffer'])) {
                         $bufferLocal = $_REQUEST['select_buffer'];
                         if ($bufferLocal < 0) {
                             $bufferLocal = 0;
                         }
                         $objPoly = $objPoly->buffer($bufferLocal);
                         unset($_REQUEST['select_buffer']);
                     }
                     @$this->map->queryByShape($objPoly);
                     PMCommon::freeMsObj($tmpLine);
                     PMCommon::freeMsObj($objPoly);
                     // query by circle
                 } else {
                     if ($this->queryType == 'circle') {
                         $point = $_REQUEST['select_point'];
                         $radius = $_REQUEST['select_radius'];
                         $tmpPoint = ms_newPointObj();
                         $tmpTab = explode(' ', $point);
                         $tmpPoint->setXYZ($tmpTab[0], $tmpTab[1], 0);
                         if (isset($_REQUEST['select_buffer'])) {
                             @$this->map->queryByPoint($tmpPoint, MS_MULTIPLE, $radius + $_REQUEST['select_buffer']);
                         } else {
                             @$this->map->queryByPoint($tmpPoint, MS_MULTIPLE, $radius);
                         }
                         PMCommon::freeMsObj($tmpPoint);
                     }
                 }
             }
         }
     }
     // Modified by Thomas RAFFIN (SIRAP)
     // use layers with complex queries that are too long to select results
     // cause maxscaledenom is not used...
     // reset data tag
     foreach ($oldDatas as $qLayer => $oldData) {
         $qLayer = $this->map->getLayerByName($qLayer);
         $qLayer->set('data', $oldData);
     }
 }
Пример #8
0
$map = ms_newMapObj($PM_MAP_FILE);
//print_r($map);
$timer->start();
$jsonFile = "dynlayer_def.txt";
$dynLayers = preg_replace(array("/\\s{2,}/", "/\n/"), array(" ", ""), file_get_contents($jsonFile));
$_SESSION['dynLayers'] = json_decode($dynLayers, true);
$dyn = new DynLayer($map, json_encode($_SESSION['dynLayers']));
$dyn->createDynLayers();
//$map->getLayerByName("cities_1")->set("status", MS_ON);
$map->getLayerByName("cities_2")->set("status", MS_ON);
$map->getLayerByName("countries")->set("status", MS_ON);
//print_r($map->getAllLayerNames());
$map->selectOutputFormat("png");
$map_img = $map->draw();
$map_url = $map_img->saveWebImage();
require_once '../../incphp/common.php';
PMCommon::freeMsObj($map_img);
#$timer->stop();
#$timer->display();
$map->save("D:/webdoc/tmp/dynlayer.map");
$dynJson = json_decode($dynLayers);
$lay1 = $dynJson->newlayers->layerlist->cities_1;
unset($dynJson->newlayers->layerlist->cities_1);
// = null;
$lay1->name = "pippo";
$dynJson->newlayers->layerlist->cities_1 = $lay1;
#print_r($dynJson->newlayers->layerlist->cities_2);
//print_r($dynJson->newlayers->layerlist);
//unset($_SESSION['dynLayers']['cities_2']);
//$_SESSION['dynLayers']['cities_2'] = null;
//print_r(json_decode(json_encode($_SESSION['dynLayers'])));
Пример #9
0
 ******************************************************************************
 *
 * Copyright (c) 2003-2006 Armin Burger
 *
 * This file is part of p.mapper.
 *
 * p.mapper is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation; either version 2 of the License, or
 * (at your option) any later version. See the COPYING file.
 *
 * p.mapper is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with p.mapper; if not, write to the Free Software
 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
 *
 ******************************************************************************/
// prevent XSS
require_once "../pmsession.php";
require_once "../common.php";
require_once "../globals.php";
$sessionvar = $_REQUEST['sessionvar'];
$sessionvarJson = PMCommon::parseJSON($_SESSION['categories'], false);
pm_logDebug(3, $sessionvarJson, "x_getsessionvar.php, JSON for session var {$sessionvar}");
header("Content-Type: text/plain; charset={$defCharset}");
//echo "{" . $sessionvar . ":" . $sessionvarJson . "}";
echo $sessionvarJson;
Пример #10
0
/**
 * Get the CSS include string for HTML files generation (<link ...>)
 *
 * This function is used to easy get all the "<link>" elements for CSS
 * used in the current configuration. So, if called in a plugin, even in
 * new opening pages you can have the same appearence than in the map.phtml. 
 * 
 * @param string $pmDir: p.mapper main directory URL
 * @return string containing "<link ..."
 */
function getCSSReference($pmDir)
{
    $ret = "";
    $dirNames = array();
    //- from config/common (custom) dir
    $dirNames[] = PM_CONFIG_LOCATION_COMMON;
    //- from config dir
    $dirNames[] = PM_CONFIG_LOCATION;
    foreach ($dirNames as $dirName) {
        if (file_exists(PM_BASECONFIG_DIR . "/" . $dirName)) {
            $cssFiles = PMCommon::scandirByExt(PM_BASECONFIG_DIR . "/" . $dirName, "css");
            $cssFiles = array_unique($cssFiles);
            if (count($cssFiles) > 0) {
                foreach ($cssFiles as $cf) {
                    $ret .= " <link rel=\"stylesheet\" href=\"config/" . $dirName . "/{$cf}\" type=\"text/css\" />\n";
                }
            }
        }
    }
    return $ret;
}
Пример #11
0
                $hasTemplate = 1;
            }
            $numclasses = $mapLayer->numclasses;
            for ($cl = 0; $cl < $numclasses; $cl++) {
                $class = $mapLayer->getClass($cl);
                $classTemplate = $class->template;
                if ($class->template) {
                    $hasTemplate = 1;
                }
            }
            if ($XYLayerProperties = $glayer->getXYLayerProperties()) {
                if (!$XYLayerProperties['noQuery']) {
                    $hasTemplate = 1;
                }
            }
            if ($mapLayer->type < 3 && PMCommon::checkScale($map, $mapLayer, $scale) == 1 && $resFldList[0] != '0' && $hasTemplate) {
                $showgroups[] = $grp;
                break;
            }
        }
    }
}
// Print combo box with all visible groups
$gstr = "<form id=\"selform\"><div class=\"pm-selectbox\">";
if (count($showgroups) > 0) {
    $gstr .= _pjs("Apply on Layer") . "";
    $gstr .= "";
    $gstr .= "<select name=\"selgroup\" >";
    foreach ($showgroups as $g) {
        $gstr .= "<option value=\"" . $g->getGroupName() . "\" ";
        if ($g->getGroupName() == $activegroup) {
Пример #12
0
 /**
  * Check if group has visible layer at current scale
  * @param object $map
  * @param object $grp
  * @param int $scale
  */
 public function checkGroup($map, $grp, $scale)
 {
     $printGroup = 0;
     $glayerList = $grp->getLayers();
     if (is_array($glayerList)) {
         foreach ($glayerList as $glayer) {
             $tocLayer = $map->getLayer($glayer->getLayerIdx());
             if (PMCommon::checkScale($map, $tocLayer, $scale) == 1 && $tocLayer->type != 5) {
                 $printGroup = 1;
                 //pm_logDebug(3, "Layer: $tocLayer->name; scale: $scale; PrintGrp: $printGroup");
             }
         }
     }
     return $printGroup;
 }
Пример #13
0
 /**
  * Get the option values from a MapServer layer
  */
 protected function getOptionsFromMS($mslayer, $encoding, $keyfield, $showfield, $sort)
 {
     $qLayer = $this->map->getLayerByName($mslayer);
     $query = $qLayer->queryByAttributes($keyfield, "/()/", MS_MULTIPLE);
     if ($query == MS_SUCCESS) {
         $qLayer->open();
         $numResults = $qLayer->getNumResults();
         //error_log($numResults);
         for ($iRes = 0; $iRes < $numResults; $iRes++) {
             $qRes = $qLayer->getResult($iRes);
             $qShape = PMCommon::resultGetShape($this->msVersion, $qLayer, $qRes);
             // changed for compatibility with PG layers and MS >= 5.6
             $k = $encoding != "UTF-8" ? iconv($encoding, "UTF-8", $qShape->values[$keyfield]) : $qShape->values[$keyfield];
             $v = $encoding != "UTF-8" ? iconv($encoding, "UTF-8", $qShape->values[$showfield]) : $qShape->values[$showfield];
             $ol[$k] = trim($v);
             // avoid <, >, ...
             $ol[$k] = htmlentities($ol[$k], ENT_COMPAT, 'UTF-8');
             PMCommon::freeMsObj($qShape);
         }
         $json = $this->options_array2json($ol, $sort);
         return $json;
     }
 }
Пример #14
0
 /**
  * draw refmap image
  */
 public function drawRefMap($minx, $miny, $maxx, $maxy, $width, $height, $useAlternatFormatForMS6)
 {
     $this->activateLayers();
     // do not use RGBA in MS 6 if refmap will be used in mapObj::drawReferenceMap (transparency not supported)
     if ($useAlternatFormatForMS6 && $this->msVersion >= 6) {
         $this->internalMap->selectOutputFormat($this->altOutputFormat);
     } else {
         $this->internalMap->selectOutputFormat($this->outputFormat);
     }
     $this->internalMap->setSize($width, $height);
     $this->internalMap->setExtent($minx, $miny, $maxx, $maxy);
     $refMapImg = $this->internalMap->draw();
     $this->refMapURL = PMCommon::mapSaveWebImage($this->internalMap, $refMapImg);
     PMCommon::freeMsObj($refMapImg);
     $this->refMapImage = str_replace($this->internalMap->web->imageurl, $this->internalMap->web->imagepath, $this->refMapURL);
 }
Пример #15
0
 <?php 
// only load configuration for activated plugins
$ini['pluginsConfig'] = $_SESSION['pluginsConfig'];
// add allGroups if not defined in XML config
if (!$ini['map']['allGroups']) {
    $ini['map']['allGroups']['group'] = $_SESSION['allGroups'];
}
?>
 
 PM.ini = <?php 
echo PMCommon::parseJSON($ini, false);
?>
 ;
 
 <?php 
echo PMCommon::writeJSArrays();
?>
 
 $.merge(PM.categoriesClosed, <?php 
echo "['" . implode("','", $_SESSION['categoriesClosed']) . "']";
?>
);

// Query layers: modify query results in js
PM.modifyQueryResultsFunctions = [<?php 
if (count($plugin_jsModifyQueryResultsFunctions) > 0) {
    echo "'" . implode("','", $plugin_jsModifyQueryResultsFunctions) . "'";
}
?>
];
Пример #16
0
/**
 * Return groups available in array
 */
function getAvailableGroups($map, $onlyChecked, $onlyNonRasters, $onlyVisibleAtScale, $onlyQueryable = true, $onlyInCategories = false)
{
    // only checked groups :
    if ($onlyChecked) {
        $groupsStep1 = $_SESSION["groups"];
    } else {
        $groupsStep1 = $_SESSION["allGroups"];
    }
    $groupsStep2 = array();
    $scale = $_SESSION["geo_scale"];
    $grouplist = $_SESSION["grouplist"];
    foreach ($grouplist as $grp) {
        if (in_array($grp->getGroupName(), $groupsStep1, TRUE)) {
            $glayerList = $grp->getLayers();
            foreach ($glayerList as $glayer) {
                $mapLayer = $map->getLayer($glayer->getLayerIdx());
                $groupOk = true;
                // no raster layers / groups :
                if ($groupOk && $onlyNonRasters) {
                    if ($mapLayer->type >= 3) {
                        $groupOk = false;
                    }
                }
                // only visible layers / groups depending on scale :
                if ($groupOk && $onlyVisibleAtScale) {
                    if (PMCommon::checkScale($map, $mapLayer, $scale) != 1) {
                        $groupOk = false;
                    }
                }
                if ($groupOk && $onlyQueryable) {
                    $hasTemplate = 0;
                    if ($mapLayer->template) {
                        $hasTemplate = 1;
                    }
                    if (!$hasTemplate) {
                        $numclasses = $mapLayer->numclasses;
                        for ($cl = 0; $cl < $numclasses; $cl++) {
                            $class = $mapLayer->getClass($cl);
                            $classTemplate = $class->template;
                            if ($class->template) {
                                $hasTemplate = 1;
                                break;
                            }
                        }
                    }
                    $groupOk = $hasTemplate;
                }
                if ($groupOk) {
                    $groupsStep2[] = $grp;
                    break;
                }
            }
        }
    }
    // only layers in categories
    $groupsStep3 = array();
    if ($onlyInCategories) {
        // get Categories
        require_once $_SESSION['PM_INCPHP'] . "/layerview.php";
        $layerView = new LayerView($map, false, false);
        $categoryList = $layerView->getCategoryList();
        if (count($categoryList) > 0) {
            foreach ($categoryList as $cat) {
                $catGrps = $cat['groups'];
                $categoriesGroups = array();
                foreach ($catGrps as $catGrp) {
                    if ($catGrp) {
                        $catGrpName = $catGrp['name'];
                        foreach ($groupsStep2 as $grp) {
                            $grpName = $grp->getGroupName();
                            if ($catGrpName === $grpName) {
                                $groupsStep3[] = $grp;
                            }
                        }
                    }
                }
            }
        }
    } else {
        $groupsStep3 = $groupsStep2;
    }
    return $groupsStep3;
}
Пример #17
0
 /**
  * SEARCH VIA ATTRIBUTES
  */
 function q_execAttributeQuery()
 {
     // Definition of search parameters with external methods
     if (isset($_REQUEST['externalSearchDefinition'])) {
         $this->qLayerName = $_REQUEST['layerName'];
         $this->qSearchLayerType = $_REQUEST['layerType'];
         $fldName = $_REQUEST['fldName'];
         $this->qStr = $_REQUEST['qStr'];
         pm_logDebug(3, $_REQUEST, "Parameters for REQUEST array \nfile: query.php->q_execAttributeQuery \n");
         // Default using search.xml definitions
     } else {
         $searchitem = $_REQUEST['searchitem'];
         foreach ($_REQUEST as $key => $val) {
             if ($key != "findlist" && $key != "searchitem") {
                 $searchArray[$key] = urldecode($val);
                 //utf8_encode($val);
             }
         }
         $search = new XML_search($this->map, $_SESSION['PM_SEARCH_CONFIGFILE']);
         $searchParams = $search->getSearchParameters($this->map, $searchitem, $searchArray);
         $this->qLayerName = $searchParams['layerName'];
         $this->qSearchLayerType = $searchParams['layerType'];
         $fldName = $searchParams['firstFld'];
         $this->qStr = $searchParams['qStr'];
         pm_logDebug(2, $searchArray, "Parameters for searchArray \nfile: query.php->q_execAttributeQuery \n");
         pm_logDebug(2, $searchParams, "Parameters for searchParams \nfile: query.php->q_execAttributeQuery");
     }
     // Return layer type
     $this->qLayer = $this->map->getLayerByName($this->qLayerName);
     //$this->qSearchLayerType = $this->qLayer->connectiontype;
     // Get group and glayer objects
     $GroupGlayer = PMCommon::returnGroupGlayer($this->qLayerName);
     $this->grp = $GroupGlayer[0];
     $this->glayer = $GroupGlayer[1];
     $this->XYLayerProperties = $this->glayer->getXYLayerProperties();
     $this->layerEncoding = $this->glayer->getLayerEncoding();
     if ($this->qSearchLayerType == "shape" || $this->qSearchLayerType == "ms" || $this->qSearchLayerType == "oracle") {
         if ($layFilter = $this->qLayer->getFilterString()) {
             $mapLayerFilterItem = $this->qLayer->filteritem;
             if ($layFilter[0] == '/') {
                 $operator = '=~';
             } else {
                 $operator = '=';
             }
             $this->qStr = "(\"[{$mapLayerFilterItem}]\" {$operator} {$layFilter} AND ({$this->qStr}) )";
             pm_logDebug(3, $this->qStr, "query string including FILTER -- query.php->q_execAttributeQuery");
         }
         if ($this->qSearchLayerType == "oracle") {
             @$this->qLayer->queryByAttributes(null, $this->qStr, MS_MULTIPLE);
         } else {
             @$this->qLayer->queryByAttributes($fldName, $this->qStr, MS_MULTIPLE);
         }
     }
 }
Пример #18
0
 /**
  * DRAW XY LAYER: ADD POINTS FROM DB TO MAP IMAGE
  */
 protected function pmap_drawXYLayer($img)
 {
     $grouplist = $_SESSION["grouplist"];
     // Loop through groups and layers to find XYLayers
     foreach ($grouplist as $grp) {
         $glayerList = $grp->getLayers();
         foreach ($glayerList as $glayer) {
             $XYLayerProperties = $glayer->getXYLayerProperties();
             if ($XYLayerProperties) {
                 // XYLayer found, now process
                 $mLayer = $this->map->getLayer($glayer->getLayerIdx());
                 $mLayerStatus = $mLayer->status;
                 if ($mLayerStatus == MS_ON) {
                     // Check if XYLayer is switched ON
                     $pearDbClass = $_SESSION['pearDbClass'];
                     require_once "{$pearDbClass}.php";
                     require_once "../query/query.php";
                     // Check if Layer projection differs from Map projection
                     $changeLayProj = PMCommon::checkProjection($this->map, $mLayer);
                     // Map extent for limiting query
                     if ($changeLayProj) {
                         $me = $this->map->extent;
                         $mapExt = ms_newRectObj();
                         $mapExt->setExtent($me->minx, $me->miny, $me->maxx, $me->maxy);
                         $mapExt->project($changeLayProj['mapProj'], $changeLayProj['layProj']);
                     } else {
                         $mapExt = $this->map->extent;
                     }
                     $map_xmin = $mapExt->minx;
                     $map_ymin = $mapExt->miny;
                     $map_xmax = $mapExt->maxx;
                     $map_ymax = $mapExt->maxy;
                     if ($changeLayProj) {
                         PMCommon::freeMsObj($mapExt);
                     }
                     // XY Layer Properties
                     $dsn = $XYLayerProperties["dsn"];
                     $xyTable = $XYLayerProperties["xyTable"];
                     $x_fld = $XYLayerProperties["x_fld"];
                     $y_fld = $XYLayerProperties["y_fld"];
                     $classidx_fld = $XYLayerProperties["classidx_fld"];
                     $resFldStr = $mLayer->getMetaData("RESULT_FIELDS");
                     $resFieldList = preg_split('/[\\s,]+/', $resFldStr);
                     // Prepare query
                     if (preg_match("/@/", $xyTable)) {
                         // Check for WHERE filter in table definition
                         $xyList = preg_split('/@/', $xyTable);
                         $whereFilter = $xyList[1];
                         $xyTable = $xyList[0];
                     }
                     $sql_SELECT = "SELECT {$x_fld}, {$y_fld}, {$classidx_fld} FROM {$xyTable} ";
                     $sql_WHERE = "WHERE " . ($whereFilter ? $whereFilter . " AND " : "") . " {$x_fld} >= {$map_xmin}  AND {$x_fld} <= {$map_xmax} AND {$y_fld} >= {$map_ymin} AND {$y_fld} <= {$map_ymax}";
                     $sql = "{$sql_SELECT}  {$sql_WHERE}";
                     pm_logDebug(3, $sql, "P.MAPPER-DEBUG: map.php/pmap_drawXYLayer() - SQL Cmd:");
                     // init DB class
                     $db = new $pearDbClass();
                     // Connect to DB
                     $dbh = $db->connect($dsn);
                     if ($db->isError($dbh)) {
                         PMCommon::db_logErrors($dbh);
                         die;
                     }
                     // Execute query
                     $res = $dbh->query($sql);
                     if ($db->isError($res)) {
                         PMCommon::db_logErrors($res);
                         die;
                     }
                     // Draw points on map image
                     while ($xyRow = $res->fetchRow()) {
                         $ptX = $xyRow[0];
                         $ptY = $xyRow[1];
                         $clIdx = $xyRow[2];
                         $xyPoint = ms_newPointObj();
                         $xyPoint->setXY($ptX, $ptY);
                         $xyPoint->draw($this->map, $mLayer, $img, $clIdx, "");
                         PMCommon::freeMsObj($xyPoint);
                     }
                     //$res->free();
                     $dbh->disconnect();
                 }
             }
         }
     }
 }
Пример #19
0
 /**
  * Init function
  */
 function __construct($json, $map)
 {
     parent::__construct($json);
     $msVersion = $_SESSION['MS_VERSION'];
     $grouplist = $_SESSION['grouplist'];
     //pm_logDebug(3, $grouplist, 'grouplist in exportSHP');
     $groups = (array) $this->jsonList[0];
     $fileList = array();
     $valueList = array();
     $dbfFieldList = array();
     $cpyPrjFile = '';
     @mkdir($this->tempFilePath, 0700);
     foreach ($groups as $grp) {
         $layerNameList = array();
         $layerList = array();
         $values = $grp->values;
         if (!$values[0][0]->shplink) {
             continue;
         }
         // headers with invalid characters
         include_once '../common/pluginsMapUtils.inc.php';
         $headerListTmp = $grp->header;
         $headerList = array();
         foreach ($headerListTmp as $n => $h) {
             if ($h != '@') {
                 $newHeader = PluginsMapUtils::decodeMapFileVal($map, $h, 'ISO-8859-1');
                 // remove accents and spaces:
                 // adpated from http://www.lecoindunet.com/zone_php/scripts_utiles/remplacer-les-caracteres-accentues-dune-chaine-en-php-72
                 $bad = array(' ', 'À', 'Á', 'Â', 'Ã', 'Ä', 'Å', 'Æ', 'Ç', 'È', 'É', 'Ê', 'Ë', 'Ì', 'Í', 'Î', 'Ï', 'Ð', 'Ñ', 'Ò', 'Ó', 'Ô', 'Õ', 'Ö', 'Ø', 'Ù', 'Ú', 'Û', 'Ü', 'Ý', 'ß', 'à', 'á', 'â', 'ã', 'ä', 'å', 'æ', 'ç', 'è', 'é', 'ê', 'ë', 'ì', 'í', 'î', 'ï', 'ñ', 'ò', 'ó', 'ô', 'õ', 'ö', 'ø', 'ù', 'ú', 'û', 'ü', 'ý', 'ÿ', 'A', 'a', 'A', 'a', 'A', 'a', 'C', 'c', 'C', 'c', 'C', 'c', 'C', 'c', 'D', 'd', 'Ð', 'd', 'E', 'e', 'E', 'e', 'E', 'e', 'E', 'e', 'E', 'e', 'G', 'g', 'G', 'g', 'G', 'g', 'G', 'g', 'H', 'h', 'H', 'h', 'I', 'i', 'I', 'i', 'I', 'i', 'I', 'i', 'I', 'i', '?', '?', 'J', 'j', 'K', 'k', 'L', 'l', 'L', 'l', 'L', 'l', '?', '?', 'L', 'l', 'N', 'n', 'N', 'n', 'N', 'n', '?', 'O', 'o', 'O', 'o', 'O', 'o', 'Œ', 'œ', 'R', 'r', 'R', 'r', 'R', 'r', 'S', 's', 'S', 's', 'S', 's', 'Š', 'š', 'T', 't', 'T', 't', 'T', 't', 'U', 'u', 'U', 'u', 'U', 'u', 'U', 'u', 'U', 'u', 'U', 'u', 'W', 'w', 'Y', 'y', 'Ÿ', 'Z', 'z', 'Z', 'z', 'Ž', 'ž', '?', 'ƒ', 'O', 'o', 'U', 'u', 'A', 'a', 'I', 'i', 'O', 'o', 'U', 'u', 'U', 'u', 'U', 'u', 'U', 'u', 'U', 'u', '?', '?', '?', '?', '?', '?');
                 $good = array('_', 'A', 'A', 'A', 'A', 'A', 'A', 'AE', 'C', 'E', 'E', 'E', 'E', 'I', 'I', 'I', 'I', 'D', 'N', 'O', 'O', 'O', 'O', 'O', 'O', 'U', 'U', 'U', 'U', 'Y', 's', 'a', 'a', 'a', 'a', 'a', 'a', 'ae', 'c', 'e', 'e', 'e', 'e', 'i', 'i', 'i', 'i', 'n', 'o', 'o', 'o', 'o', 'o', 'o', 'u', 'u', 'u', 'u', 'y', 'y', 'A', 'a', 'A', 'a', 'A', 'a', 'C', 'c', 'C', 'c', 'C', 'c', 'C', 'c', 'D', 'd', 'D', 'd', 'E', 'e', 'E', 'e', 'E', 'e', 'E', 'e', 'E', 'e', 'G', 'g', 'G', 'g', 'G', 'g', 'G', 'g', 'H', 'h', 'H', 'h', 'I', 'i', 'I', 'i', 'I', 'i', 'I', 'i', 'I', 'i', 'IJ', 'ij', 'J', 'j', 'K', 'k', 'L', 'l', 'L', 'l', 'L', 'l', 'L', 'l', 'l', 'l', 'N', 'n', 'N', 'n', 'N', 'n', 'n', 'O', 'o', 'O', 'o', 'O', 'o', 'OE', 'oe', 'R', 'r', 'R', 'r', 'R', 'r', 'S', 's', 'S', 's', 'S', 's', 'S', 's', 'T', 't', 'T', 't', 'T', 't', 'U', 'u', 'U', 'u', 'U', 'u', 'U', 'u', 'U', 'u', 'U', 'u', 'W', 'w', 'Y', 'y', 'Y', 'Z', 'z', 'Z', 'z', 'Z', 'z', 's', 'f', 'O', 'o', 'U', 'u', 'A', 'a', 'I', 'i', 'O', 'o', 'U', 'u', 'U', 'u', 'U', 'u', 'U', 'u', 'U', 'u', 'A', 'a', 'AE', 'ae', 'O', 'o');
                 $newHeader = str_replace($bad, $good, $newHeader);
                 // upper case
                 $newHeader = strtoupper($newHeader);
                 // if header already exists :'FIELD_' + index
                 if (in_array($newHeader, $headerList)) {
                     $newHeader = "FIELD_{$n}";
                 }
                 $headerList[] = $newHeader;
                 // if '@' not at the beginning
             } else {
                 if ($n != 0) {
                     $headerList = array();
                     break;
                 }
             }
         }
         foreach ($values as $vList) {
             $dbfRow = array();
             foreach ($vList as $n => $v) {
                 if ($shplink = $v->shplink) {
                     //pm_logDebug(3, $shplink, "shplink");
                     $layerName = $shplink[0];
                     $shpIdxTmp = $shplink[1];
                     $shpIdx = preg_replace('/^.*@/', '', $shpIdxTmp);
                     $tileShpIdx = -1;
                     if (!in_array($layerName, $layerNameList)) {
                         $typeList = array(MS_SHP_POINT, MS_SHP_ARC, MS_SHP_POLYGON);
                         $srcLayer = $map->getLayerByName($layerName);
                         // use layers with complex queries that are too long to select results
                         $newdata = $srcLayer->getMetaData('PM_RESULT_DATASUBSTITION');
                         if ($newdata != '') {
                             $srcLayer->set('data', $newdata);
                         }
                         $srcLayerType = $srcLayer->type;
                         //error_log("type: $srcLayerType");
                         $layerNameList[] = $layerName;
                         $layerList[] = $srcLayer;
                         $valueList[$layerName] = array();
                         $srcLayer->open();
                         //pm_logDebug(3, $layerItems);
                         $outShpFname = "{$this->tempFilePath}/{$layerName}";
                         $shpFile = ms_newShapeFileObj($outShpFname, $typeList[$srcLayerType]);
                         $dbfFileName = "{$outShpFname}.dbf";
                         $cpyPrjFile = '';
                         unset($proj);
                         $proj = $srcLayer->getProjection();
                         if (empty($proj)) {
                             $proj = $map->getProjection();
                         }
                         if (!empty($proj)) {
                             $prjFile = dirname(__FILE__) . "\\shp\\";
                             $pos = strpos($proj, 'epsg:');
                             if ($pos !== false) {
                                 $proj = substr($proj, $pos + 5);
                                 $prjFile .= "{$proj}.prj";
                             }
                             if (file_exists($prjFile) && !is_dir($prjFile)) {
                                 $cpyPrjFile = "{$outShpFname}.prj";
                                 copy($prjFile, $cpyPrjFile);
                             }
                         }
                         $fileList[$layerName] = array();
                         $fileList[$layerName][] = "{$outShpFname}.shp";
                         $fileList[$layerName][] = "{$outShpFname}.shx";
                         $fileList[$layerName][] = $dbfFileName;
                         if (file_exists($cpyPrjFile)) {
                             $fileList[$layerName][] = $cpyPrjFile;
                         }
                     }
                     $srcShp = PMCommon::resultGetShape($msVersion, $srcLayer, null, $shpIdx, -1);
                     // changed for compatibility with PG layers and MS >= 5.6
                     $shpFile->addShape($srcShp);
                 } else {
                     if ($headerList) {
                         $hyperlink = $v->hyperlink;
                         if ($hyperlink) {
                             $val = $hyperlink[2];
                         } else {
                             $val = $v;
                         }
                         $fldName = $headerList[$n - 1];
                         $dbfRow[] = utf8_decode($val);
                         if (!isset($dbfFieldList[$layerName])) {
                             $dbfFieldList[$layerName] = array();
                         }
                         if (!isset($dbfFieldList[$layerName][$fldName])) {
                             $dbfFieldList[$layerName][$fldName] = array();
                         }
                         $dbfFieldList[$layerName][$fldName] = $this->getFieldType(trim($val), $dbfFieldList[$layerName][$fldName]);
                     }
                 }
             }
             $valueList[$layerName][] = $dbfRow;
         }
         // some clean up
         //            PMCommon::freeMsObj($shpFile);
         // shapefileObj: changes are committed only when the object is destroyed
         $shpFile->free();
         unset($shpFile);
         foreach ($layerList as $l) {
             $l->close();
         }
     }
     // write dBase files
     foreach ($fileList as $layerName => $files) {
         $dbfFileName = $fileList[$layerName][2];
         // Modified by Thomas RAFFIN (SIRAP)
         // bug export for groups (with many layers)
         $dbfFieldListTmp = $dbfFieldList[$layerName];
         $valueListTmp = $valueList[$layerName];
         $this->writeDbf($dbfFileName, $dbfFieldListTmp, $valueListTmp);
     }
     // Write all files to zip and remove tmp dir
     $this->tempFileLocation .= '.zip';
     $zipFilePath = "{$this->tempFilePath}.zip";
     $filesToZip = array();
     foreach ($fileList as $files) {
         foreach ($files as $file) {
             $filesToZip[] = $file;
         }
     }
     PMCommon::packFilesZip($zipFilePath, $filesToZip, true, true);
     rmdir($this->tempFilePath);
 }
Пример #20
0
 /**
  * Init function
  */
 function __construct($json)
 {
     parent::__construct($json);
     // Delimiter and quote characters
     $del = ",";
     $enc = '"';
     $groups = (array) $this->jsonList[0];
     $fileList = array();
     // Create directory
     @mkdir($this->tempFilePath, 0700);
     foreach ($groups as $grp) {
         $outputFile = $this->tempFilePath . "\\" . $grp->name . '.csv';
         $fileList[] = $outputFile;
         $fp = fopen($outputFile, 'w');
         // Header
         $headerList = $grp->header;
         $csv_header = array();
         foreach ($headerList as $h) {
             if ($h == '@') {
                 //$col--;
             } else {
                 $csv_header[] = $h;
             }
         }
         $this->fwritecsv($fp, $csv_header, $del, $enc);
         // Values
         $values = $grp->values;
         $csv_val = '';
         foreach ($values as $vList) {
             $csv_row = array();
             foreach ($vList as $v) {
                 // Links
                 if (is_object($v)) {
                     if (isset($v->shplink)) {
                     }
                     if (isset($v->hyperlink)) {
                         $csv_row[] = $v->hyperlink[2];
                         //str_replace($enc, "@@@@", $hyperlink[3]); //
                     }
                 } else {
                     $csv_row[] = $v;
                     //str_replace($enc, "@@@@", $v);
                 }
             }
             $this->fwritecsv($fp, $csv_row, $del, $enc);
         }
         fclose($fp);
         unset($fp);
     }
     // Write all csv files to zip
     $this->tempFileLocation .= '.zip';
     $zipFilePath = "{$this->tempFilePath}.zip";
     PMCommon::packFilesZip($zipFilePath, $fileList, true, true);
     // remove directory
     rmdir($this->tempFilePath);
 }
Пример #21
0
 protected function zipFiles()
 {
     $this->tempFileLocation .= '.zip';
     $zipFilePath = "{$this->tempFilePath}.zip";
     PMCommon::packFilesZip($zipFilePath, $this->fileList, true, true);
 }
Пример #22
0
 /**
  * Get Suggest records from a MS layer using generic MapScript attribute query 
  *
  * @return string
  */
 private function msSuggestMatch($searchParams)
 {
     $msVersion = $_SESSION['msVersion'];
     if (!extension_loaded('MapScript')) {
         dl("php_mapscript{$msVersion}." . PHP_SHLIB_SUFFIX);
     }
     $map = $this->map;
     pm_logDebug(3, $searchParams, "suggest.php->msSuggestMatch()");
     $mslayer = $searchParams['mslayer'];
     $searchfield = $searchParams['searchfield'];
     $sort = $searchParams['sort'];
     $encoding = $searchParams['encoding'];
     $regexleft = $searchParams['regexleft'];
     $startleft = $searchParams['startleft'];
     // many dependfields
     $dependFields = isset($searchParams['dependFields']) && $searchParams['dependFields'] ? $searchParams['dependFields'] : array();
     $left = $startleft ? "^" : "";
     $qLayer = $map->getLayerByName($mslayer);
     $qs = "";
     // Create search string
     // many dependfields
     $qsDependFieldsParts = array();
     if ($dependFields) {
         foreach ($dependFields as $fieldName => $fieldValue) {
             $depFldName = "dependfldval_{$fieldName}";
             $depFldValue = $searchParams[$depFldName];
             $depFldValue = trim($depFldValue);
             if ($depFldValue != '') {
                 $qsDependFieldsParts[] = "( \"[{$fieldName}]\" =~ /{$depFldValue}/ )";
             }
         }
     }
     if ($qsDependFieldsParts) {
         $qs .= ' (' . implode(' AND ', $qsDependFieldsParts) . ') AND ';
     }
     if (trim($searchParams['fieldtype']) == "s") {
         if ($encoding != $this->defCharset) {
             $this->search = iconv($this->defCharset, $encoding, $this->search);
         }
         $searchVal = get_magic_quotes_gpc() ? stripslashes($this->search) : $this->search;
         if ($this->msVersion >= 6) {
             $qs .= "( \"[{$searchfield}]\" ~* \"{$regexleft}{$left}{$searchVal}\" )";
         } else {
             $val = preg_replace("/\\w/ie", "'('. strtoupper('\$0') . '|' . strtolower('\$0') .')'", $searchVal);
             $qs .= "( \"[{$searchfield}]\" =~ /{$regexleft}{$left}{$val}/ )";
         }
     } else {
         $qs .= "([{$searchfield}] = {$this->search})";
     }
     if ($layFilter = $qLayer->getFilterString()) {
         $querystring = "( ({$layFilter}) AND ({$qs}) )";
     } else {
         $querystring = "( {$qs} )";
     }
     pm_logDebug(3, $querystring, "MS suggest query string, suggest.php/msSuggestMatch()");
     // Query layer
     $query = @$qLayer->queryByAttributes($searchfield, $querystring, MS_MULTIPLE);
     if ($query == MS_SUCCESS) {
         $qLayer->open();
         $numResults = $qLayer->getNumResults();
         // Return query results
         for ($iRes = 0; $iRes < $numResults; $iRes++) {
             $qRes = $qLayer->getResult($iRes);
             $qShape = PMCommon::resultGetShape($this->msVersion, $qLayer, $qRes);
             // changed for compatibility with PG layers and MS >= 5.6
             $fldValue = $qShape->values[$searchfield];
             if ($encoding != $this->defCharset) {
                 $fldValue = iconv($encoding, $this->defCharset, $fldValue);
             }
             $resArray[] = trim($fldValue);
             PMCommon::freeMsObj($qShape);
         }
         $ret = $this->suggest_array2json($resArray, $sort);
         return $ret;
     } else {
         return 0;
     }
 }