From 36987e22ba62c80574f250d06189bc996192ed22 Mon Sep 17 00:00:00 2001 From: Edmar Moretti Date: Thu, 5 Jan 2012 12:56:55 +0000 Subject: [PATCH] Inclusão de matadata nos layers para controlar a conversão de caracteres --- admin/js/editormapfile.js | 12 ++++++++++-- admin/php/editormapfile.php | 7 ++++--- classesphp/classe_atributos.php | 47 +++++++++++++++++++++++++++++++++++++++-------- ferramentas/tabela/relatorio.php | 6 +++++- ms_configura.php | 2 +- temas/testeutf8postgis.map | 19 ++++++++++--------- testamapfile.php | 9 ++++++--- 7 files changed, 75 insertions(+), 27 deletions(-) diff --git a/admin/js/editormapfile.js b/admin/js/editormapfile.js index 00fbf55..e667e2d 100644 --- a/admin/js/editormapfile.js +++ b/admin/js/editormapfile.js @@ -1349,6 +1349,8 @@ function montaEditorDados(dados) "linhas":[ {ajuda:"Type of connection. Default is local.", titulo:"Connectiontype",id:"",value:"",div:"
",tipo:"text"}, + {ajuda:"Aplica a conversão de caracteres nas ferramentas que obtém os dados descritivos referentes aos elementos do LAYER. Em alguns casos, a conversão pode provocar problemas de acentuação. Se isso ocorrer, na ferramenta tabela por exemplo, experimente marcar essa opção como 'nao'", + titulo:"Conversão de caracteres (METADATA: CONVCARACTER)",id:"",value:dados.convcaracter,tipo:"text",div:"
"}, {ajuda:"Database connection string to retrieve remote data.An SDE connection string consists of a hostname, instance name, database name, username and password separated by commas.A PostGIS connection string is basically a regular PostgreSQL connection string, it takes the form of 'user=nobody password=****** dbname=dbname host=localhost port=5432' An Oracle connection string: user/pass[@db] . Se vc tiver problemas com acentuação, experimente algo como: user=postgres password=postgres dbname=pgutf8 host=localhost port=5432 options='-c client_encoding=LATIN1'", titulo:"Connection",id:"connection",value:dados.connection,tipo:"text"}, {ajuda:"Full filename of the spatial data to process. No file extension is necessary for shapefiles. Can be specified relative to the SHAPEPATH option from the Map Object.If this is an SDE layer, the parameter should include the name of the layer as well as the geometry column, i.e. 'mylayer,shape,myversion'.If this is a PostGIS layer, the parameter should be in the form of ' from ', where 'columnname' is the name of the column containing the geometry objects and 'tablename' is the name of the table from which the geometry data will be read.For Oracle, use 'shape FROM table' or 'shape FROM (SELECT statement)' or even more complex Oracle compliant queries! Note that there are important performance impacts when using spatial subqueries however. Try using MapServer's FILTER whenever possible instead. You can also see the SQL submitted by forcing an error, for instance by submitting a DATA parameter you know won't work, using for example a bad column name. Exemplo postgis: the_geom FROM (select * FROM biomas) as foo USING UNIQUE gid USING SRID=4291 . Exemplo shapefile: c://ms4w/Apache/htdocs/geodados/brasil/limitespol/localidades.shp", @@ -1410,7 +1412,13 @@ function montaEditorDados(dados) temp += core_comboObjeto(objlayertypes,"valor","texto",dados.type) temp += "" $i("cType").innerHTML = temp - + + if($i("cConvcaracter")){ + temp = "" + $i("cConvcaracter").innerHTML = temp + } var temp = function() {salvarDadosEditor('conexao',dados.codigoMap,dados.codigoLayer,false)} @@ -1866,7 +1874,7 @@ function salvarDadosEditor(tipo,codigoMap,codigoLayer,indiceClasse,indiceEstilo, } if(tipo == "conexao") { - var campos = new Array("cache","projection","type","connection","data","connectiontype","tileitem","tileindex","filteritem","filter","tipooriginal") + var campos = new Array("cache","projection","type","connection","data","connectiontype","tileitem","tileindex","filteritem","filter","tipooriginal","convcaracter"); var par = "&codigoMap="+codigoMap+"&codigoLayer="+codigoLayer var prog = "../php/editormapfile.php?funcao=alterarConexao" } diff --git a/admin/php/editormapfile.php b/admin/php/editormapfile.php index d5ef203..e187ee4 100644 --- a/admin/php/editormapfile.php +++ b/admin/php/editormapfile.php @@ -1485,7 +1485,7 @@ function pegaConexao() if($dados["projection"] == "null") {$dados["projection"] = "";} $dados["projection"] = str_replace("+i","i",$dados["projection"]); - + $dados["convcaracter"] = $layer->getmetadata("convcaracter"); $dados["colunas"] = implode(" ,",pegaItens($layer)); if($layer->connectiontype == 7 || $layer->connectiontype == 9){ $dados["tipooriginal"] = $layer->getmetadata("tipooriginal"); @@ -1494,7 +1494,7 @@ function pegaConexao() } function alterarConexao() { - global $cache,$tipooriginal,$filteritem,$filter,$projection,$type,$dir_tmp,$testar,$codigoMap,$codigoLayer,$locaplic,$connection,$connectiontype,$data,$tileitem,$tileindex; + global $convcaracter,$cache,$tipooriginal,$filteritem,$filter,$projection,$type,$dir_tmp,$testar,$codigoMap,$codigoLayer,$locaplic,$connection,$connectiontype,$data,$tileitem,$tileindex; $mapfile = $locaplic."/temas/".$codigoMap.".map"; $mapa = ms_newMapObj($mapfile); $layer = $mapa->getlayerbyname($codigoLayer); @@ -1516,7 +1516,8 @@ function alterarConexao() if($layer->connectiontype == 7 || $layer->connectiontype== 9){ $layer->setmetadata("tipooriginal",$tipooriginal); } - $layer->setmetadata("cache",$cache); + $layer->setmetadata("cache",$cache); + $layer->setmetadata("convcaracter",$convcaracter); if($testar == "true") { $nome = $dir_tmp."/".$codigoMap.".map"; diff --git a/classesphp/classe_atributos.php b/classesphp/classe_atributos.php index 33c4ee5..55d777c 100644 --- a/classesphp/classe_atributos.php +++ b/classesphp/classe_atributos.php @@ -275,13 +275,18 @@ $tipo - Tipo de busca brasil|null $shapes = retornaShapesMapext($this->layer,$this->mapa); } $registros[] = array(); + if(strtoupper($this->layer->getmetadata("convcaracter")) == "NAO") + {$convC = false;} + else + {$convC = true;} foreach($shapes as $shape) { $valitem = array(); foreach ($items as $item) { $v = trim($shape->values[$item]); - $v = $this->converte($v); + if($convC == true) + {$v = $this->converte($v);} $valitem[] = $v; } $registros[] = implode(";",$valitem); @@ -335,6 +340,10 @@ $tipolista - Indica se serão mostrados todos os registros ou apenas os seleciona $res_count = count($shapes); $registros = array(); //lista apenas os selecionados + if(strtoupper($this->layer->getmetadata("convcaracter")) == "NAO") + {$convC = false;} + else + {$convC = true;} if ($tipolista == "selecionados") { $chk = "CHECKED"; @@ -350,7 +359,8 @@ $tipolista - Indica se serão mostrados todos os registros ou apenas os seleciona foreach ($items as $item) { $valori = trim($shape->values[$item]); - $valori = $this->converte($valori); + if($convC == true) + {$valori = $this->converte($valori);} $valitem[] = array("item"=>$item,"valor"=>$valori); } $registros[] = array("indice"=>$indx,"valores"=>$valitem,"status"=>$chk); @@ -395,7 +405,8 @@ $tipolista - Indica se serão mostrados todos os registros ou apenas os seleciona { $valori = ($shape->values[$item]); } - $valori = $this->converte($valori); + if($convC == true) + {$valori = $this->converte($valori);} $valitem[] = array("item"=>$item,"valor"=>$valori); } //if (in_array($shp_index,$shp_atual)) @@ -460,6 +471,10 @@ $onde - Tipo de abrangência espacial (brasil ou mapa) $this->layer = $l; if ($l->data == "") {return "Erro. O tema não tem tabela";} + if(strtoupper($this->layer->getmetadata("convcaracter")) == "NAO") + {$convC = false;} + else + {$convC = true;} $filtro = $l->getfilterstring(); if ($filtro != ""){$l->setfilter("");} $buscas = "ÁÃÓÕÔáàãâóòôõúûíéêç"; @@ -481,7 +496,8 @@ $onde - Tipo de abrangência espacial (brasil ou mapa) { if (strtr($v,$buscas,$trocas) == strtr($palavra,$buscas,$trocas)) { - $v = $this->converte($v); + if($convC == true) + {$v = $this->converte($v);} $r[] = array("item" => $item,"valor" => $v); $encontrado = "sim"; } @@ -490,7 +506,8 @@ $onde - Tipo de abrangência espacial (brasil ou mapa) { if (stristr(strtr($v,$buscas,$trocas),strtr($palavra,$buscas,$trocas))) { - $v = $this->converte($v); + if($convC == true) + {$v = $this->converte($v);} $r[] = array("item" => $item,"valor" => $v); $encontrado = "sim"; } @@ -1163,6 +1180,10 @@ $listaDeTemas - (opcional) Lista com os códigos dos temas que serão identificado $layer->set("template","none.htm"); $pt = ms_newPointObj(); $pt->setXY($x, $y); + if(strtoupper($layer->getmetadata("convcaracter")) == "NAO") + {$convC = false;} + else + {$convC = true;} // //operação especial para o caso de wms // @@ -1216,7 +1237,8 @@ $listaDeTemas - (opcional) Lista com os códigos dos temas que serão identificado if(trim($v) != "") { $va = trim($v); - $va = $this->converte($va); + if($convC == true) + {$va = $this->converte($va);} $n[] = array("alias"=>trim($t[0]),"valor"=>$va,"link"=>"","img"=>""); } } @@ -1232,7 +1254,10 @@ $listaDeTemas - (opcional) Lista com os códigos dos temas que serão identificado $linha = explode("|",$linha); for($i=0;$i < count($cabecalho);++$i) { - $va = $this->converte($linha[$i]); + if($convC == true) + {$va = $this->converte($linha[$i]);} + else + {$va = $linha[$i];} $n[] = array("alias"=>$cabecalho[$i],"valor"=>$va,"link"=>"","img"=>""); } } @@ -1320,6 +1345,10 @@ $listaDeTemas - (opcional) Lista com os códigos dos temas que serão identificado $ident = @$layer->queryByPoint($pt, 1, -1); $sopen = $layer->open(); $res_count = $layer->getNumresults(); + if(strtoupper($layer->getmetadata("convcaracter")) == "NAO") + {$convC = false;} + else + {$convC = true;} if($sopen == MS_FAILURE){return "erro";} for ($i = 0; $i < $res_count; ++$i) { @@ -1355,6 +1384,8 @@ $listaDeTemas - (opcional) Lista com os códigos dos temas que serão identificado foreach ($itens as $it) { $val = $shape->values[$it]; + if($convC == true) + {$val = $this->converte($val);} $link = $lks[$conta]; foreach($itens as $t) { @@ -1374,7 +1405,7 @@ $listaDeTemas - (opcional) Lista com os códigos dos temas que serão identificado {$etiqueta = "sim";} $arraytemp = array( "alias"=>$this->converte($itensdesc[$conta]), - "valor"=>$this->converte($val), + "valor"=>$val, "link"=>$link, "img"=>$img, "tip"=>$etiqueta diff --git a/ferramentas/tabela/relatorio.php b/ferramentas/tabela/relatorio.php index b2fc4f5..574c691 100644 --- a/ferramentas/tabela/relatorio.php +++ b/ferramentas/tabela/relatorio.php @@ -50,6 +50,10 @@ if ($layer->getNumresults() > 0){$existesel = "sim";} if ($existesel == "nao") {$layer->querybyrect($mapa->extent);} $layer->open(); +if(strtoupper($layer->getmetadata("convcaracter")) == "NAO") +{$convC = false;} +else +{$convC = true;} //$registros[] = array(); $res_count = $layer->getNumresults(); for ($i = 0; $i < $res_count; $i++) @@ -62,7 +66,7 @@ for ($i = 0; $i < $res_count; $i++) foreach ($itensrel as $item) { $v = trim($shape->values[$item]); - if (function_exists("mb_convert_encoding")) + if (function_exists("mb_convert_encoding") && $convC == true) {$v = mb_convert_encoding($v,"UTF-8","ISO-8859-1");} $valitem[$item] = $v; } diff --git a/ms_configura.php b/ms_configura.php index 3e44626..5e32b7f 100644 --- a/ms_configura.php +++ b/ms_configura.php @@ -312,7 +312,7 @@ if (strtoupper(substr(PHP_OS, 0, 3) == 'WIN')) */ $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'", + "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/temas/testeutf8postgis.map b/temas/testeutf8postgis.map index d4896a5..33d84c0 100644 --- a/temas/testeutf8postgis.map +++ b/temas/testeutf8postgis.map @@ -1,20 +1,19 @@ -MAP - - - FONTSET "../symbols/fontes.txt" - SYMBOLSET "../symbols/simbolos.sym" +MAP + FONTSET "../symbols/fontes.txt" + SYMBOLSET "../symbols/simbolos.sym" LAYER - #CONNECTION "teste" - CONNECTION "user=postgres password=postgres dbname=postgis host=localhost port=5432 options='-c client_encoding=ISO-8859-1'" + CONNECTION "teste" CONNECTIONTYPE POSTGIS DATA "the_geom FROM (select * FROM teste.estados) as foo USING UNIQUE gid USING SRID=4291" METADATA + "cache" "" "CLASSE" "SIM" "permitekmz" "" "permitedownload" "" "download" "SIM" - "permitekml" "sim" "permiteogc" "sim" + "permitekml" "sim" + "convcaracter" "SIM" "TEMA" "Teste UTF8 Postgis" END NAME "testeutf8postgis" @@ -27,9 +26,11 @@ MAP STYLE ANGLE 360 COLOR 196 185 103 - OPACITY 100 SYMBOL 0 + WIDTH 1 END END END + END + diff --git a/testamapfile.php b/testamapfile.php index 1ff6c0f..a0b2bd3 100644 --- a/testamapfile.php +++ b/testamapfile.php @@ -136,7 +136,7 @@ function verifica($map,$solegenda) $tema = ""; if(file_exists($map)) - $tema = $map; + {$tema = $map;} else { $map = str_replace("\\","/",$map); @@ -151,6 +151,8 @@ function verifica($map,$solegenda) if(($tipo == "") || ($tipo == "todos")) {echo "


Testando: $tema
";}
 	if(!file_exists($tema))
+	{$tema = $locaplic."/".$tema;}
+	if(!file_exists($tema))
 	{echo "Arquivo ".$map." não encontrado.";exit;}
 	if ($tema != "")
 	{
@@ -189,13 +191,14 @@ function verifica($map,$solegenda)
 			eval($pegarext."(\$mapa);");
 		}
 		else{
-			if(@ms_newMapObj($locaplic."/".$tema))
+			if(@ms_newMapObj($tema))
 			{
-				$nmapa = ms_newMapObj($locaplic."/".$tema);
+				$nmapa = ms_newMapObj($tema);
 			}
 			else
 			{
 				echo "erro no arquivo $map 
"; + echo "Obs.: em alguns testes o mapfile pode falhar se o endereço dos arquivos de símbolos estiverem
definidos de forma relativa ao invés de absoluta. Nesses casos, ao abrir o i3Geo,
o mapfile poderá funcionar.
"; $error = ms_GetErrorObj(); while($error && $error->code != MS_NOERR) { -- libgit2 0.21.2