From e34bc948efe2cf6bc67f310b2ea273d1ea05f305 Mon Sep 17 00:00:00 2001 From: Edmar Moretti Date: Wed, 8 Feb 2012 21:34:31 +0000 Subject: [PATCH] Correção no uso da variável $postgis_mapa --- classesphp/funcoes_gerais.php | 49 +++++++++++++++++++++++-------------------------- classesphp/mapa_googleearth.php | 2 +- classesphp/mapa_googlemaps.php | 2 +- classesphp/mapa_openlayers.php | 2 +- ms_configura.php | 15 +++++++++------ ogc.php | 37 +++++++++++++++++-------------------- testamapfile.php | 28 +++++++++++----------------- 7 files changed, 63 insertions(+), 72 deletions(-) diff --git a/classesphp/funcoes_gerais.php b/classesphp/funcoes_gerais.php index 47654f7..6e45dd8 100644 --- a/classesphp/funcoes_gerais.php +++ b/classesphp/funcoes_gerais.php @@ -699,39 +699,36 @@ Retorno: function substituiCon($map_file,$postgis_mapa) { error_reporting(0); - if ((isset($postgis_mapa)) && (file_exists($map_file))) + if (!empty($postgis_mapa) && (file_exists($map_file))) { - if (($postgis_mapa != "") || ($postgis_mapa != " ")) + if(!@ms_newMapObj($map_file)){return false;} + $objMap = ms_newMapObj($map_file); + $numlayers = $objMap->numlayers; + for ($i=0;$i < $numlayers;++$i) { - if(!@ms_newMapObj($map_file)){return false;} - $objMap = ms_newMapObj($map_file); - $numlayers = $objMap->numlayers; - for ($i=0;$i < $numlayers;++$i) + $layer = $objMap->getlayer($i); + if ($layer->connectiontype == MS_POSTGIS) { - $layer = $objMap->getlayer($i); - if ($layer->connectiontype == MS_POSTGIS) + $lcon = $layer->connection; + if (($lcon == " ") || ($lcon == "") || (in_array($lcon,array_keys($postgis_mapa)))) { - $lcon = $layer->connection; - if (($lcon == " ") || ($lcon == "") || (in_array($lcon,array_keys($postgis_mapa)))) + // + //o metadata CONEXAOORIGINAL guarda o valor original para posterior substituição + // + if(($lcon == " ") || ($lcon == "")) { - // - //o metadata CONEXAOORIGINAL guarda o valor original para posterior substituição - // - if(($lcon == " ") || ($lcon == "")) - { - $layer->set("connection",$postgis_mapa); - $layer->setmetadata("CONEXAOORIGINAL",$lcon); - } - else - { - $layer->set("connection",$postgis_mapa[$lcon]); - $layer->setmetadata("CONEXAOORIGINAL",$lcon); - } + $layer->set("connection",$postgis_mapa); + $layer->setmetadata("CONEXAOORIGINAL",$lcon); } + else + { + $layer->set("connection",$postgis_mapa[$lcon]); + $layer->setmetadata("CONEXAOORIGINAL",$lcon); + } } } - $objMap->save($map_file); } + $objMap->save($map_file); } return true; } @@ -749,7 +746,7 @@ $postgis_mapa {string} - lista de conexão com o banco function restauraCon($map_file,$postgis_mapa) { if(!@ms_newMapObj($map_file)){return;} - if (isset($postgis_mapa) && $postgis_mapa != "") + if (!empty($postgis_mapa)) { $objMap = ms_newMapObj($map_file); $numlayers = $objMap->numlayers; @@ -2018,7 +2015,7 @@ $locaplic {string} - Diretório da aplicação. $dir_tmp {string} - Diretório temporário -$postgismapa - variavel definida em ms_configura.php +$postgis_mapa - variavel definida em ms_configura.php Retorno: diff --git a/classesphp/mapa_googleearth.php b/classesphp/mapa_googleearth.php index 1415064..b59c9c0 100644 --- a/classesphp/mapa_googleearth.php +++ b/classesphp/mapa_googleearth.php @@ -134,7 +134,7 @@ function retornaWms($map_fileX,$postgis_mapa){ if($layerName == $_GET["layer"] || $l->group == $_GET["layer"] && $l->group != "") { $l->set("status",MS_DEFAULT); - if (isset($postgis_mapa) && ($postgis_mapa != "") && ($postgis_mapa != " ")) + if (!empty($postgis_mapa)) { if ($l->connectiontype == MS_POSTGIS) { diff --git a/classesphp/mapa_googlemaps.php b/classesphp/mapa_googlemaps.php index 6ca859c..27f1e7a 100644 --- a/classesphp/mapa_googlemaps.php +++ b/classesphp/mapa_googlemaps.php @@ -144,7 +144,7 @@ if(!isset($_GET["telaR"])){//no caso de projecoes remotas, o mapfile nao´e alter if($layerName == $_GET["layer"] || $l->group == $_GET["layer"] && $l->group != "") { $l->set("status",MS_DEFAULT); - if (($postgis_mapa != "") && ($postgis_mapa != " ")) + if (!empty($postgis_mapa)) { if ($l->connectiontype == MS_POSTGIS) { diff --git a/classesphp/mapa_openlayers.php b/classesphp/mapa_openlayers.php index f123f25..40a54b0 100644 --- a/classesphp/mapa_openlayers.php +++ b/classesphp/mapa_openlayers.php @@ -99,7 +99,7 @@ if(!isset($_GET["telaR"])){//no caso de projecoes remotas, o mapfile nao e alter if($layerName == $_GET["layer"] || $l->group == $_GET["layer"] && $l->group != "") { $l->set("status",MS_DEFAULT); - if (($postgis_mapa != "") && ($postgis_mapa != " ")) + if (!empty($postgis_mapa != "")) { if ($l->connectiontype == MS_POSTGIS) { diff --git a/ms_configura.php b/ms_configura.php index e3c7ee2..5f1b6e4 100644 --- a/ms_configura.php +++ b/ms_configura.php @@ -293,29 +293,32 @@ if (strtoupper(substr(PHP_OS, 0, 3) == 'WIN')) Com o uso opcional dessa variável é possível esconder a string de conexão com o banco de dados. O Mapserver não permite esconder essa string, por isso, no i3geo, foi implementado um esquema de substituição. - Toda vez que um objeto "map" é criado via PHP Mapscript, a string de conexão é substituída de " " para o valor de $postgis_mapa. + Toda vez que um objeto "map" é criado via PHP Mapscript, a string de conexão é substituída pelo valor de $postgis_mapa. Se não for desejado a substituição, deixe essa variável em branco. Se vc especificar essa variável, o mapa será forçado a recusar o modo de operação CGI. Para mais detalhes veja a função substituiCon em classesphp/funcoes_gerais.php - Importante - se vc usar o modo de substituição de strings, as interfaces que dependem do modo CGI - para funcionarem, não serão capazes de acessar os dados. Isso afeta por exemplo, a interface Google Maps e Openlayers. - exemplo - $postgis_mapa = array( - "conexao1"=>"user=geodados password=geodados dbname=geodados host=10.1.1.36 port=5432", + "teste"=>"user=geodados password=geodados dbname=geodados host=10.1.1.36 port=5432", "conexao2"=>"user=geodados password=geodados dbname=geodadosteste host=10.1.1.36 port=5432" ) + No exemplo, vc pode usar "teste" ou "conexao2" no seu mapfile veja em i3geo/temas/testesubstring.map + + Se vc não quiser usar essa substituição, deixe como está ou use + + $postgis_mapa = "" + Tipo: {array ou string} */ $postgis_mapa = array( "teste"=>"user=postgres password=postgres dbname=postgis host=localhost port=5432 options='-c client_encoding=LATIN1'", "postgres"=>"user=postgres password=postgres dbname=postgis host=localhost port=5432", - ); //"user=geodados password=geodados dbname=geodados host=10.1.1.36 port=5432"; + ); /* Variable: utilizacgi diff --git a/ogc.php b/ogc.php index 8fe0b8a..51d0136 100644 --- a/ogc.php +++ b/ogc.php @@ -247,29 +247,26 @@ if ($tipo == "" || $tipo == "metadados") if($extensao == "") {$extensao = $extensaoMap;} $l->setmetadata("wms_extent",$extensao); - if (isset($postgis_mapa)) - { - if ($postgis_mapa != "") - { - if ($l->connectiontype == MS_POSTGIS) + if (!empty($postgis_mapa)) + { + if ($l->connectiontype == MS_POSTGIS) + { + $lcon = $l->connection; + if (($lcon == " ") || ($lcon == "") || (in_array($lcon,array_keys($postgis_mapa)))) { - $lcon = $l->connection; - if (($lcon == " ") || ($lcon == "") || (in_array($lcon,array_keys($postgis_mapa)))) + // + //o metadata CONEXAOORIGINAL guarda o valor original para posterior substituição + // + if(($lcon == " ") || ($lcon == "")) { - // - //o metadata CONEXAOORIGINAL guarda o valor original para posterior substituição - // - if(($lcon == " ") || ($lcon == "")) - { - $l->set("connection",$postgis_mapa); - $l->setmetadata("CONEXAOORIGINAL",$lcon); - } - else - { - $l->set("connection",$postgis_mapa[$lcon]); - $l->setmetadata("CONEXAOORIGINAL",$lcon); - } + $l->set("connection",$postgis_mapa); + $l->setmetadata("CONEXAOORIGINAL",$lcon); } + else + { + $l->set("connection",$postgis_mapa[$lcon]); + $l->setmetadata("CONEXAOORIGINAL",$lcon); + } } } } diff --git a/testamapfile.php b/testamapfile.php index 5427c5c..ee48e9c 100644 --- a/testamapfile.php +++ b/testamapfile.php @@ -217,28 +217,22 @@ function verifica($map,$solegenda) { $layern = $nmapa->getLayerByName($teman); $layern->set("status",MS_DEFAULT); - if (isset($postgis_mapa)) + if (!empty($postgis_mapa)) { - if (($postgis_mapa != "") || ($postgis_mapa != " ")) + if ($layern->connectiontype == MS_POSTGIS) { - if ($layern->connectiontype == MS_POSTGIS) + $lcon = $layern->connection; + error_reporting(0); + if (($lcon == " ") || ($lcon == "") || (in_array($lcon,array_keys($postgis_mapa)))) { - $lcon = $layern->connection; - error_reporting(0); - if (($lcon == " ") || ($lcon == "") || (in_array($lcon,array_keys($postgis_mapa)))) + if(($lcon == " ") || ($lcon == "")) //para efeitos de compatibilidade { - // - //o metadata CONEXAOORIGINAL guarda o valor original para posterior substituição - // - if(($lcon == " ") || ($lcon == "")) - { - $layern->set("connection",$postgis_mapa); - } - else - { - $layern->set("connection",$postgis_mapa[$lcon]); - } + $layern->set("connection",$postgis_mapa); } + else + { + $layern->set("connection",$postgis_mapa[$lcon]); + } } } } -- libgit2 0.21.2