/** * Init function */ function __construct($json) { parent::__construct($json); if (!(require_once 'Spreadsheet/Excel/Writer.php')) { pm_logDebug(0, "Missing PEAR packages Spreadsheet_Excel_Writer (and maybe OLE). See plugin Readme.txt for details."); } $this->tempFilePath .= '.xls'; $this->tempFileLocation .= '.xls'; $this->workbook = new Spreadsheet_Excel_Writer($this->tempFilePath); // For UTF encoding $this->workbook->setVersion(8); $format_bold = $this->workbook->addFormat(); $format_bold->setBold(); $format_title = $this->workbook->addFormat(); $format_title->setBold(); $format_title->setColor('blue'); $worksheet = $this->workbook->addWorksheet(); $worksheet->setInputEncoding('UTF-8'); $groups = (array) $this->jsonList[0]; $r = 0; foreach ($groups as $grp) { $worksheet->write($r, 0, $grp->description, $format_title); $r++; $headerList = $grp->header; $hL = count($headerList); $col = 0; for ($hi = 0; $hi < $hL; $hi++) { $headline = $headerList[$hi]; if ($headline == '@') { //$col--; } else { $worksheet->write($r, $col, $headline, $format_bold); $col++; } } $r++; $values = $grp->values; foreach ($values as $vList) { $vcol = 0; foreach ($vList as $v) { // Links if (is_object($v)) { if (isset($v->shplink)) { } if (isset($v->hyperlink)) { $worksheet->write($r, $vcol, utf8_decode($v->hyperlink[2])); $vcol++; } } else { if (is_string($v)) { $worksheet->writeString($r, $vcol, $v); } else { $worksheet->write($r, $vcol, $v); } $vcol++; } } $r++; } $r++; } $this->workbook->close(); }
* 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 if (isset($_REQUEST['PM_INCPHP'])) { exit; } require_once '../../incphp/pmsession.php'; require_once '../../incphp/common.php'; require_once '../../incphp/globals.php'; $projIn = isset($_REQUEST['proj']) ? $_REQUEST['proj'] : false; $units = -1; $projInfo = ''; if (!isset($_SESSION['pluginsConfig']['unitAndProj'])) { pm_logDebug(0, "P.MAPPER-ERROR: Configuration under '<pluginsConfig><unitAndProj>' is missing. Check your config.xml file ({$_SESSION['PM_BASECONFIG_DIR']}/config_{$_SESSION['config']}.xml)."); } else { // get map projection description : init=EPSG:27562 if (isset($_SESSION['pluginsConfig']['unitAndProj']['projections']['prj'])) { $prjList = $_SESSION['pluginsConfig']['unitAndProj']['projections']['prj']; if ($prjList) { if ($projIn === false) { $mapProjection = $map->getProjection(); $mapProjection = preg_replace('/^\\+/', '', $mapProjection); // get map units if (strcasecmp('init=epsg:4326', $mapProjection) !== 0) { $units = $map->units; } } else { $mapProjection = "init={$projIn}"; }
/** * 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); } } }
public function getSrsList() { if (!$this->capabilities) { return '0'; } include_once "epsg_list.inc"; $capSrsStr = $this->capabilities->Capability->Layer->SRS; $capSrsList = preg_split("/\\s+/", $capSrsStr[0]); pm_logDebug(3, $capSrsList, "SRS List"); return $capSrsList; foreach ($capSrsList as $s) { /*if (array_key_exists((string)$s, $srsList)) { $srsList[(string)$s] = $epsgL[substr((string)$s, 5)]; } else { $srsList[(string)$s] = "EPSG:" . (string)$s; }*/ } return $srsList; }
/** * Check INI settings for errors */ private function _initConfig() { /*** Test if resolution tag is set ***/ if ($this->map->resolution != "96") { pm_logDebug(1, "P.MAPPER-ERROR: RESOLUTION tag not set to 96. This value is needed for proper function of PDF print."); } /*** LAYERS ***/ // Test for groups with blanks $gList = $this->map->getAllGroupNames(); foreach ($gList as $gr) { if (preg_match('/\\s/', $gr)) { pm_logDebug(0, "P.MAPPER-ERROR: Group '{$gr}' defined in the map file has blanks in its name. This is not possible for the p.mapper application. Remove blanks or substitute with e.g. '_'."); } } // Test for layers with blanks $gList = $this->map->getAllLayerNames(); foreach ($gList as $ly) { if (preg_match('/\\s/', $ly)) { pm_logDebug(0, "P.MAPPER-ERROR: Layer '{$ly}' defined in the map file has blanks in its name. This is not possible for the p.mapper application. Remove blanks or substitute with e.g. '_'."); } } /*** USER AGENT (Browser type) ***/ $ua = $_SERVER["HTTP_USER_AGENT"]; if (preg_match("/gecko/i", $ua)) { $_SESSION['userAgent'] = "mozilla"; } elseif (preg_match("/opera/i", $ua)) { $_SESSION['userAgent'] = "opera"; } elseif (preg_match("/MSIE/i", $ua)) { $_SESSION['userAgent'] = "ie"; } $_SESSION['web_imagepath'] = str_replace('\\', '/', $this->map->web->imagepath); $_SESSION['web_imageurl'] = str_replace('\\', '/', $this->map->web->imageurl); $ms_Version = ms_GetVersion(); $msvL = explode('.', substr($ms_Version, strpos($ms_Version, "version") + 8, 5)); $_SESSION['MS_VERSION'] = (double) "{$msvL[0]}.{$msvL[1]}{$msvL[2]}"; // MS >= 6 if ($_SESSION['MS_VERSION'] >= 6) { if ($this->map->defresolution != "96") { pm_logDebug(1, "P.MAPPER-ERROR: DEFRESOLUTION tag not set to 96. This value is needed for proper function of PDF print."); } } }
* 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 * ******************************************************************************/ require_once "../group.php"; require_once "../pmsession.php"; require_once "../common.php"; require_once "../globals.php"; require_once "../layerview.php"; $categories = $_SESSION['useCategories'] ? $_SESSION['categories'] : false; $layerView = new LayerView($map, $categories, false); $groupList = json_encode($layerView->getGroupList()); pm_logDebug(3, $groupList, "Group list: "); //$categoryList = $layerView->getCategoryList(); //pm_logDebug(3, $categoryList, "category List: "); //$groupList = $layerView->getGroupNameList(); //pm_logDebug(3, $groupList, "Group list: "); header("Content-Type: text/plain; charset={$defCharset}"); // return JS object literals "{}" for XMLHTTP request echo "{\"groupList\":{$groupList}}";
public static function calculateExtent($map, $groups, $applyMapExtentIfNull = false, $addBuffer = false) { $mapExtent = ms_newrectObj(); $layers = getLayersByGroupOrLayerName($map, $groups); foreach ($layers as $layer) { $layerExtent = false; if ($layer) { if ($layer->connectiontype == MS_POSTGIS || $layer->connectiontype == MS_ORACLESPATIAL) { //get dns string containing : type of database, user name, password, host and database. $dsn = PluginsMapUtils::getDSNConnection($layer); if ($dsn) { // code from mapserver mailing list (by Armin Burger): // get table and filter : $data = PluginsMapUtils::getQueryParamsFromDataString($layer, false, false); $mapLayerFilter = $data['mapLayerFilter']; $fromTable = $data['fromTable']; $geomFld = $data['geomFld']; $sql = 'SELECT ST_xmin(extent) AS minx, ST_ymin(extent) AS miny, ST_xmax(extent) AS maxx, ST_ymax(extent) AS maxy '; $sql .= "FROM (SELECT St_Extent({$geomFld}) AS extent FROM {$fromTable} "; $sql .= ($mapLayerFilter ? "WHERE {$mapLayerFilter}" : '') . ' '; $sql .= ') AS bar'; $sql .= ' WHERE extent IS NOT NULL'; pm_logDebug(4, "calculateExtent - sql:{$sql}"); // DB: require_once dirname(__FILE__) . '/easyMDB2.inc.php'; $edb = new Easy_MDB2(); $edb->setDSN($dsn); $edb->start(); $qresultE = $edb->selectByQuery($sql, ''); $resValues = $qresultE['values'][0]; if ($resValues) { $resIsValid = true; foreach ($resValues as $val) { if (!isset($val) || $val == 0 || $val == -1) { $resIsValid = false; break; } } if ($resIsValid) { $layerExtent = ms_newRectObj(); $layerExtent->setExtent($resValues['minx'], $resValues['miny'], $resValues['maxx'], $resValues['maxy']); } } } } else { if ($layer->type != MS_LAYER_RASTER && ($layer->connectiontype == MS_SHAPEFILE || $layer->connectiontype == MS_TILED_SHAPEFILE || $layer->connectiontype == MS_OGR)) { // SHP layer, OGR layer $layerExtent = @$layer->getExtent(); } } if ($layerExtent) { // change projection $mapProjStr = $map->getProjection(); $layerProjStr = $layer->getProjection(); if ($mapProjStr && $layerProjStr && $mapProjStr != $layerProjStr) { if ($_SESSION['MS_VERSION'] < 6) { $mapProjObj = ms_newprojectionobj($mapProjStr); $layerProjObj = ms_newprojectionobj($layerProjStr); } else { $mapProjObj = new projectionObj($mapProjStr); $layerProjObj = new projectionObj($layerProjStr); } $layerExtent->project($layerProjObj, $mapProjObj); } // add buffer around freshly calculated extent if ($addBuffer) { $minx = $layerExtent->minx; $miny = $layerExtent->miny; $maxx = $layerExtent->maxx; $maxy = $layerExtent->maxy; $pointBuffer = isset($_SESSION['pointBuffer']) ? $_SESSION['pointBuffer'] : 50; $shapeQueryBuffer = isset($_SESSION['shapeQueryBuffer']) ? $_SESSION['shapeQueryBuffer'] : 0.01; $buf = 0; if ($layer->type == MS_LAYER_POINT || $layer->type == MS_LAYER_ANNOTATION) { $buf = $pointBuffer; // set buffer depending on dimensions of your coordinate system } else { if (isset($shapeQueryBuffer) && $shapeQueryBuffer > 0) { $buf = $shapeQueryBuffer * (($maxx - $minx + ($maxy - $miny)) / 2); } } if ($buf > 0) { $minx -= $buf; $miny -= $buf; $maxx += $buf; $maxy += $buf; $layerExtent->setExtent($minx, $miny, $maxx, $maxy); } } if ($mapExtent->minx == -1 && $mapExtent->miny == -1 && $mapExtent->maxx == -1 && $mapExtent->maxy == -1) { $minx = $layerExtent->minx; $miny = $layerExtent->miny; $maxx = $layerExtent->maxx; $maxy = $layerExtent->maxy; } else { $minx = $layerExtent->minx < $mapExtent->minx ? $layerExtent->minx : $mapExtent->minx; $miny = $layerExtent->miny < $mapExtent->miny ? $layerExtent->miny : $mapExtent->miny; $maxx = $layerExtent->maxx > $mapExtent->maxx ? $layerExtent->maxx : $mapExtent->maxx; $maxy = $layerExtent->maxy > $mapExtent->maxy ? $layerExtent->maxy : $mapExtent->maxy; } $mapExtent->setExtent($minx, $miny, $maxx, $maxy); } } } if ($mapExtent->minx == -1 || $mapExtent->miny == -1 || $mapExtent->maxx == -1 || $mapExtent->maxy == -1) { $mapExtent = $map->extent; if (!$applyMapExtentIfNull) { $mapExtent->setExtent(0, 0, 1, 1); } } return $mapExtent; }
<?php require_once "../../incphp/pmsession.php"; require_once "../../incphp/globals.php"; require_once "../../incphp/common.php"; require_once "projection.php"; $clickX = $_REQUEST['x']; $clickY = $_REQUEST['y']; $fromPrj = $map->getProjection(); if (!isset($_SESSION['pluginsConfig']['coordinates'])) { pm_logDebug(0, "P.MAPPER-ERROR: Configuration under '<pluginsConfig><coordinates>' is missing. Check your config.xml file."); return false; } $prjCfg = $_SESSION['pluginsConfig']['coordinates']; $mapPrj = $prjCfg['mapPrj']; $mapPrjName = _p($mapPrj['name']); $showX = round($clickX, $mapPrj['roundTo']); $showY = round($clickY, $mapPrj['roundTo']); $prjJson = "["; $prjJson .= "{\"prjName\": \"{$mapPrjName}\", \"x\": {$showX}, \"y\": {$showY}},"; $prjList = $prjCfg['prj']; $prjTmp = array(); foreach ($prjList as $p) { $prjName = _p($p['name']); $roundTo = $p['roundTo']; $toPrj = $p['definition']; $prj = new Projection($clickX, $clickY, $fromPrj, $toPrj); $x = $prj->getX(); $y = $prj->getY(); //round values $x = round($x, $roundTo);
/** * 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(); } } } } }
protected function getDataFilePath($inpath) { $config_dir = $_SESSION['PM_CONFIG_DIR']; if ($inpath[0] == "/" || $inpath[1] == ":") { $retPath = $inpath; } else { if ($inpath[0] == "\$") { if ($this->dataRoot[0] == "/" || $this->dataRoot[1] == ":") { $retPath = $this->dataRoot . substr($inpath, 1); } else { $retPath = str_replace('\\', '/', realpath($config_dir . "/" . $this->dataRoot)) . substr($inpath, 1); } } else { $retPath = str_replace('\\', '/', realpath($config_dir . "/" . $inpath)); } } //error_log($retPath); pm_logDebug(3, $retPath, "Data path for XML search \nfile: " . __FILE__ . "\nfunction: " . __FUNCTION__); return $retPath; }
****************************************************************************** * * 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;
/** * Calculte map size */ private function calculateSize() { $width = $this->refMapWidth; //$this->internalMap->width; $height = $this->refMapHeight; //$this->internalMap->height; if ($this->autoSize && ($this->decreaseHeight || $this->decreaseWidth)) { $minHeight = $this->refMapHeight / 3; $minWidth = $this->refMapWidth / 3; $stepHeight = $this->decreaseHeight ? $this->stepSize : 0; $stepWidth = $this->decreaseWidth ? $this->stepSize : 0; $size = PluginsMapUtils::calculateSize($this->internalMap, $this->refMapExtent, $this->refMapHeight, $this->refMapWidth, $minHeight, $minWidth, $stepHeight, $stepWidth); $width = $size['width']; $height = $size['height']; } pm_logDebug(4, $this->refMapExtent, 'refMapExtent 3:'); pm_logDebug(4, "width={$width};height={$height}"); $this->internalMap->setSize($width, $height); $this->internalMap->setExtent($this->refMapExtent->minx, $this->refMapExtent->miny, $this->refMapExtent->maxx, $this->refMapExtent->maxy); $this->refMapExtent = $this->internalMap->extent; $this->refMapWidth = $width; $this->refMapHeight = $height; $this->refMapMinX = $this->refMapExtent->minx; $this->refMapMinY = $this->refMapExtent->miny; $this->refMapMaxX = $this->refMapExtent->maxx; $this->refMapMaxY = $this->refMapExtent->maxy; }
/** * 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; } }
* ******************************************************************************/ require_once "../pmsession.php"; //Send some headers to keep the user's browser from caching the response. header("Cache-Control: no-cache, must-revalidate, private, pre-check=0, post-check=0, max-age=0"); header("Expires: " . gmdate('D, d M Y H:i:s', time()) . " GMT"); header("Last-Modified: " . gmdate("D, d M Y H:i:s") . " GMT"); header("Pragma: no-cache"); header("Content-Type: text/plain; charset=utf-8"); // MapObj modifiers require_once "../globals.php"; require_once "../common.php"; require_once "../query/suggest.php"; $searchGet = isset($_REQUEST['q']) ? $_REQUEST['q'] : ''; $searchitem = $_REQUEST['searchitem']; $fldname = $_REQUEST['fldname']; //error_log("$searchitem $fldname $searchGet "); pm_logDebug(3, $_REQUEST, "request"); // initialize return value $ret = ""; // Run suggest query if (isset($searchGet) && strlen($searchGet) > 0) { $search = addslashes($searchGet); $suggest = new Suggest($map, $search, $searchitem, $fldname, $_REQUEST); $ret = $suggest->returnJson(); } //error_log("return: " . $ret); //echo "{searchGet:'$searchGet', retvalue:$ret, fldname:'$fldname'}"; if ($ret) { echo $ret; }
function writeDbf($dbfFileName, $dbfFieldList, $valueList) { $defList = array(); foreach ($dbfFieldList as $name => $def) { $defList[] = array_merge(array(substr($name, 0, 10)), $def); } pm_logDebug(3, $defList, 'defList'); $dbfFile = dbase_create($dbfFileName, $defList); //array(array('PROG_ID', 'N', 5, 0))); foreach ($valueList as $row) { pm_logDebug(3, $row, 'row'); dbase_add_record($dbfFile, $row); } dbase_close($dbfFile); }
/** * * Legend generated by MapServer (embed in image) * */ private function applyLegendObjToMap($map, $printSettings) { if ($printSettings) { if (isset($printSettings['legendposition']) && $printSettings['legendposition'] == 'imgms') { $msLegPosition = isset($printSettings['msLegPosition']) && $printSettings['msLegPosition'] ? $printSettings['msLegPosition'] : 'lr'; if (strpos('MS_', $msLegPosition) !== 0) { $msLegPosition = 'MS_' . strtoupper($msLegPosition); } $msLegPosition = constant($msLegPosition); $msImgColor = isset($printSettings['msImgColor']) && $printSettings['msImgColor'] ? $printSettings['msImgColor'] : '255 255 255'; $msTxtColor = isset($printSettings['msTxtColor']) && $printSettings['msTxtColor'] ? $printSettings['msTxtColor'] : '0 0 0'; $msTxtOutlineColor = isset($printSettings['msTxtOutlineColor']) && $printSettings['msTxtOutlineColor'] ? $printSettings['msTxtOutlineColor'] : '-1 -1 -1'; $msTxtSize = isset($printSettings['msTxtSize']) && $printSettings['msTxtSize'] ? $printSettings['msTxtSize'] : 18; $msIconH = isset($printSettings['msIconH']) && $printSettings['msIconH'] ? $printSettings['msIconH'] : 18; $msIconW = isset($printSettings['msIconW']) && $printSettings['msIconW'] ? $printSettings['msIconW'] : 12; try { if ($msLegPosition !== NULL) { $map->legend->set('position', $msLegPosition); } $msLegPosition = $map->legend->position; $spacingLeft = ' '; $spacingRight = ''; switch ($msLegPosition) { case MS_UR: case MS_LR: $spacingRight = ' '; break; case MS_UL: case MS_LL: case MS_UC: case MS_LC: default: break; } $colorTmp = preg_split('/[\\s,]/', $msImgColor); if ($colorTmp) { $map->legend->imagecolor->setRGB($colorTmp[0], $colorTmp[1], $colorTmp[2]); } $colorTmp = preg_split('/[\\s,]/', '0 0 0'); if ($colorTmp) { $map->legend->outlinecolor->setRGB($colorTmp[0], $colorTmp[1], $colorTmp[2]); } $map->legend->set('keysizex', $msIconW); $map->legend->set('keysizey', $msIconH); $colorTmp = preg_split('/[\\s,]/', $msTxtColor); if ($colorTmp) { $map->legend->label->color->setRGB($colorTmp[0], $colorTmp[1], $colorTmp[2]); } $colorTmp = preg_split('/[\\s,]/', $msTxtOutlineColor); if ($colorTmp) { $map->legend->label->outlinecolor->setRGB($colorTmp[0], $colorTmp[1], $colorTmp[2]); } $map->legend->label->set('size', $msTxtSize); $map->legend->status = MS_EMBED; // change names of classes with "_p" function $numLayers = $map->numlayers; for ($iLayer = 0; $iLayer < $numLayers; $iLayer++) { $layer = $map->getLayer($iLayer); $numClasses = $layer->numclasses; for ($iClass = 0; $iClass < $numClasses; $iClass++) { $class = $layer->getClass($iClass); $classDesc = $class->name; if ($classDesc) { $classDesc = $spacingLeft . _p($classDesc) . $spacingRight; $class->set('name', $classDesc); } } } } catch (Exception $e) { pm_logDebug(0, 'Print MS legend error: ' . $e->getMessage()); } } } }
/** * * Test if data base élément exists (table, fields, fields with types) * * @param string $schemaName schema name * @param string $msg $tableName table name * @param string or array $fieldsName fields names (optional) * @param string or array $fieldsType (N => numérique, S => string, or any data_type) * * @return true if all exists * * @example * * tableOrFieldsExists('MySchema', 'MayTable') * * tableOrFieldsExists('MySchema', 'MayTable', 'fieldName') * * tableOrFieldsExists('MySchema', 'MayTable', 'fieldName', 'N') * * $fields[] = 'field1' * $fields[] = 'field2' * $dataTypes['field1'] = 'S' * $dataTypes['field2'] = 'integer' * tableOrFieldsExists('MySchema', 'MayTable', $fields, $dataTypes) * * tableOrFieldsExists('MySchema', 'MayTable', $fields, 'varchar') */ public function tableOrFieldsExists($schemaName, $tableName, $fieldsName = NULL, $fieldsType = NULL) { $ret = false; $req = ''; $nbRes = 1; if (isset($schemaName) || isset($tableName)) { $fieldsArray = NULL; // We test only if table exists if (!isset($fieldsName)) { $req = "SELECT table_name FROM information_schema.tables WHERE table_schema='{$schemaName}' AND table_name='{$tableName}'"; // Else we test if table and flields exists } else { $fieldsArray = array(); if (is_array($fieldsName)) { $fieldsArray = $fieldsName; } else { $fieldsArray[] = $fieldsName; } if (!isset($fieldsArray[1])) { $strFields = "= '{$fieldsArray['0']}'"; } else { $strFields = implode('\', \'', $fieldsArray); $strFields = "IN ('{$strFields}')"; } $req .= "SELECT column_name, data_type FROM information_schema.columns WHERE \n\t\t\t\ttable_schema='{$schemaName}' AND \n\t\t\t\ttable_name='{$tableName}' \n\t\t\t\tAND column_name {$strFields}"; $nbRes = count($fieldsArray); } $result = $this->dbh->query($req); if ($this->db->isError($result)) { pm_logDebug(0, "ERROR - Easy_MDB2 (IsExists - \"{$schema}\".\"{$table}\") \n" . $result->getMessage()); } else { if ($result->numRows() == $nbRes) { $ret = true; } } if ($ret && isset($fieldsArray) && $fieldsArray && isset($fieldsType) && $fieldsType) { while (($row = $result->fetchRow()) && $ret) { $dataType = $row['data_type']; $dataName = $row['column_name']; if (!is_array($fieldsType)) { $type = $fieldsType; } else { if (!isset($fieldsType[$dataName])) { continue; } else { $type = $fieldsType[$dataName]; } } switch ($type) { case 'N': if ($dataType != 'smallint' && $dataType != 'integer' && $dataType != 'bigint' && $dataType != 'decimal' && $dataType != 'numeric' && $dataType != 'real' && $dataType != 'double precision' && $dataType != 'serial' && $dataType != 'bigserial') { $ret = false; } break; case 'S': if ($dataType != 'character varying' && $dataType != 'varchar' && $dataType != 'character' && $dataType != 'char' && $dataType != 'text') { $ret = false; } break; default: if ($type != $dataType) { $ret = false; } break; } } } } return $ret; }
/** * Return extent of layer as array * @param bool $inMapProjection define if extent shall be returned in map projection * @return object extent with minx, miny, maxx, maxy properties */ public function getLayerExtent($inMapProjection) { // PostgIS layers if ($this->layer->connectiontype == 6) { $data = trim($this->layer->data); $dataList1 = preg_split("/\\s/", $data); $dataList2 = preg_split("/using/i", $data); $geomFld = array_shift($dataList1); // use filter for layer extent $filter = trim($this->layer->getFilterString()); if (!$filter) { $filter = "TRUE"; } $sql = "select ST_xmin(extent) as minx, ST_ymin(extent) as miny, ST_xmax(extent) as maxx, ST_ymax(extent) as maxy \n from (SELECT St_Extent({$geomFld}) as extent " . substr($dataList2[0], strlen($geomFld)) . "WHERE {$filter}) as bar"; pm_logDebug(3, $sql, "P.MAPPER-DEBUG: pmaplayer.php/getLayerExtent() - SQL for PG layer extent"); // load DLL on Win if required if (PHP_OS == "WINNT" || PHP_OS == "WIN32") { if (!extension_loaded('pgsql')) { if (function_exists("dl")) { dl('php_pgsql.dll'); } else { error_log("P.MAPPER ERROR: This version of PHP does support the 'dl()' function. Please enable 'php_pgsql.dll' in your php.ini"); return false; } } } $connString = $this->layer->connection; if (!($connection = pg_Connect($connString))) { error_log("P.MAPPER: Could not connect to database"); error_log("P.MAPPER: PG Connection error: " . pg_last_error($connection)); exit; } $qresult = pg_query($connection, $sql); if (!$qresult) { error_log("P.MAPPER: PG Query error for : {$query}" . pg_result_error($qresult)); } $pgE = pg_fetch_object($qresult); $layerExt = ms_newRectObj(); $layerExt->setExtent($pgE->minx, $pgE->miny, $pgE->maxx, $pgE->maxy); } else { $layerExt = @$this->layer->getExtent(); // Raster layers (no extent function available, so take map extent) if (!$layerExt) { $layerExt = $this->map->extent; } pm_logDebug(3, $this->layer->type, "pmap layerInfo"); } // if layer projection != map projection, reproject layer extent if ($inMapProjection) { $mapProjStr = $this->map->getProjection(); $layerProjStr = $this->layer->getProjection(); if ($mapProjStr && $layerProjStr && $mapProjStr != $layerProjStr) { if ($_SESSION['MS_VERSION'] < 6) { $mapProjObj = ms_newprojectionobj($mapProjStr); $layerProjObj = ms_newprojectionobj($layerProjStr); } else { $mapProjObj = new projectionObj($mapProjStr); $layerProjObj = new projectionObj($layerProjStr); } $layerExt->project($layerProjObj, $mapProjObj); } } pm_logDebug(3, $layerExt, "pmap layerExt"); return $layerExt; }
/** * Parse DATA tag from PostGIS layer */ private function pgLayerParseData($layer) { $pg_data = $layer->data; //"the_geom from images"; $dl = preg_split('/ from /i', $pg_data); $data_list['geocol'] = trim($dl[0]); $flds = trim($dl[1]); if (substr($flds, 0, 1) == '(') { // is of type "the_geom from (select the_geom, oid, from mytable) AS foo USING UNIQUE gid USING SRID=4258" $tabl = preg_split('/as ([a-z]|_|[A-Z]|[0-9])+ using unique /i', $dl[2]); $unique_list = preg_split('/[\\s,]+/', $tabl[1]); $data_list['dbtable'] = $flds . " from " . trim($tabl[0]) . " as foo "; $data_list['unique_field'] = trim($unique_list[0]); } else { $tabl = preg_split('/using unique/i', $dl[1]); if (count($tabl) > 1) { // is of type "the_geom from mytable USING UNIQUE gid " $data_list['dbtable'] = trim($tabl[0]); //$data_list['unique_field'] = trim($tabl[1]); $unique_list = preg_split('/[\\s]+/', trim($tabl[1])); $data_list['unique_field'] = trim($unique_list[0]); } else { // is of type "the_geom from mytable" $dbtable = trim($dl[1]); $data_list['dbtable'] = $dbtable; $data_list['unique_field'] = "oid"; pm_logDebug(2, "P.MAPPER Warning: no UNIQUE field specified for PostGIS table '{$dbtable}'. Trying using OID field..."); } } return $data_list; }
/** * Return print settings for given paper size and orientation */ function getPrintParams($papersize, $orientation, $maptype) { $ret = array(); if ($this->outputType == 'pdf' || $this->outputType == 'html') { $outputType = $this->outputType; $pdfSettings = (array) $this->xml->settings->{$outputType}; foreach ($pdfSettings as $k => $v) { $ret[$k] = $this->evalString($v); } $ret['printtitle'] = $this->getPrintTitle(); if (isset($ret['additionnalTitle']) && isset($ret['additionnalTitle']->before) && isset($ret['additionnalTitle']->before->text)) { $text = (string) $ret['additionnalTitle']->before->text; if ($text) { $text = $this->evalString($text); $ret['additionnalTitle']->before->text = $text; } } if (isset($ret['additionnalTitle']) && isset($ret['additionnalTitle']->after) && isset($ret['additionnalTitle']->after->text)) { $text = (string) $ret['additionnalTitle']->after->text; if ($text) { $text = $this->evalString($text); $ret['additionnalTitle']->after->text = $text; } } $xmlSettings = $this->xml->xpath("/print/settings/{$outputType}/format[@papersize=\"{$papersize}\" and @orientation=\"{$orientation}\"]/map[@type=\"{$maptype}\"]"); foreach ($xmlSettings[0]->attributes() as $k => $v) { $ret[$k] = (string) $v; } pm_logDebug(3, $ret, "{$outputType} printing settings"); } return $ret; }