Commit 82fc776caa423ace83927a83952d16a3749af3d8

Authored by Edmar Moretti
1 parent bbd38bfd
Exists in master

--no commit message

Showing 2 changed files with 149 additions and 18 deletions   Show diff stats
@@ -26,7 +26,7 @@ Você deve ter recebido uma copia da Licença Pública Geral do @@ -26,7 +26,7 @@ Você deve ter recebido uma copia da Licença Pública Geral do
26 Free Software Foundation, Inc., no endereço 26 Free Software Foundation, Inc., no endereço
27 59 Temple Street, Suite 330, Boston, MA 02111-1307 USA. 27 59 Temple Street, Suite 330, Boston, MA 02111-1307 USA.
28 28
29 -Arquivo: i3geo/ogc.php 29 +Arquivo: i3geo/json.php
30 30
31 Parâmetros: 31 Parâmetros:
32 32
@@ -142,7 +142,7 @@ if($format == "storymap"){ @@ -142,7 +142,7 @@ if($format == "storymap"){
142 $collon = $storymap["collon"]; 142 $collon = $storymap["collon"];
143 $collat = $storymap["collat"]; 143 $collat = $storymap["collat"];
144 $colmedia = $storymap["colmedia"]; 144 $colmedia = $storymap["colmedia"];
145 - 145 +
146 $par = array( 146 $par = array(
147 "cabecalho"=>$cabecalho, 147 "cabecalho"=>$cabecalho,
148 "texto"=>$texto, 148 "texto"=>$texto,
@@ -189,7 +189,7 @@ function gdocs(){ @@ -189,7 +189,7 @@ function gdocs(){
189 "type"=>$tipos[$i] 189 "type"=>$tipos[$i]
190 ); 190 );
191 } 191 }
192 - 192 +
193 $fields[] = array( 193 $fields[] = array(
194 "id"=>"geo", 194 "id"=>"geo",
195 "type"=>"geo" 195 "type"=>"geo"
@@ -332,9 +332,10 @@ function carregaCacheArquivo(){ @@ -332,9 +332,10 @@ function carregaCacheArquivo(){
332 } 332 }
333 333
334 function pegaDadosJ(){ 334 function pegaDadosJ(){
335 - global $oMap, $tema, $versao; 335 + global $oMap, $tema, $versao, $locaplic;
336 set_time_limit(0); 336 set_time_limit(0);
337 $layer = $oMap->getlayerbyname($tema); 337 $layer = $oMap->getlayerbyname($tema);
  338 + processaPluginI3geo();
338 $layer->set("status",MS_DEFAULT); 339 $layer->set("status",MS_DEFAULT);
339 $layer->set("template","none.htm"); 340 $layer->set("template","none.htm");
340 $items = pegaItens($layer,$oMap); 341 $items = pegaItens($layer,$oMap);
@@ -344,7 +345,7 @@ function pegaDadosJ(){ @@ -344,7 +345,7 @@ function pegaDadosJ(){
344 $linhas = array(); 345 $linhas = array();
345 for ($i = 0; $i < $res_count; $i++){ 346 for ($i = 0; $i < $res_count; $i++){
346 //echo $i." - <br>"; 347 //echo $i." - <br>";
347 - if($versao == 6){ 348 + if($versao >= 6){
348 $shape = $layer->getShape($layer->getResult($i)); 349 $shape = $layer->getShape($layer->getResult($i));
349 } 350 }
350 else{ 351 else{
@@ -388,7 +389,69 @@ function pegaDadosJ(){ @@ -388,7 +389,69 @@ function pegaDadosJ(){
388 ); 389 );
389 return $resultado; 390 return $resultado;
390 } 391 }
391 - 392 +function processaPluginI3geo(){
  393 + global $locaplic, $layer;
  394 + $c = $layer->getmetadata("PLUGINI3GEO");
  395 + if($c != ""){
  396 + $cs = json_decode($c,true);
  397 + if($cs["plugin"] == "parametrossql"){
  398 + $data = $layer->data;
  399 + $cs = $cs["parametros"];
  400 + $chaves = array();
  401 + foreach($cs as $c){
  402 + $chaves[] = $c["chave"];
  403 + }
  404 + $chaves = implode(",",$chaves);
  405 + $filtro = $layer->getFilterString();
  406 + $chaves = str_ireplace(array(" and ", " or ", "select","from","where","update","delete","insert","--"),"",$chaves);
  407 + $chaves = explode(",",$chaves);
  408 + $n = count($chaves);
  409 + //a variavel $plugin vem da URL e contem os valores
  410 + //que devem ser substituidos
  411 + //se $plugin for vazio, usa o primeiro valor definido na configuracao do plugin
  412 + //A ordem dos valores deve ser exatamente a ordem das chaves
  413 + if(empty($plugin)){
  414 + $plugin = array();
  415 + foreach($cs as $c){
  416 + if($c["chave"] != ""){
  417 + //valores definidos no plugin como uma string
  418 + if($c["valores"] != ""){
  419 + $temp = explode(",",$c["valores"]);
  420 + $plugin[] = $temp[0];
  421 + }
  422 + elseif ($c["prog"] != ""){
  423 + $plugin[] = execProg($locaplic."/".$c["prog"]);
  424 + }
  425 + }
  426 + }
  427 + $plugin = implode(",",$plugin);
  428 + }
  429 + $layer->setmetadata("TEMA",$layer->getmetadata("TEMA")." - ".$plugin);
  430 + $valores = str_ireplace(array(" and ", " or ", "select","from","where","update","delete","insert","--"),"",$plugin);
  431 + $valores = explode(",",strip_tags($valores));
  432 + for($i = 0; $i < $n; $i++){
  433 + if($chaves[$i] != ""){
  434 + $v = $valores[$i];
  435 + $data = str_replace($chaves[$i],$v,$data);
  436 + if($filtro != ""){
  437 + $filtro = str_replace($chaves[$i],$v,$filtro);
  438 + }
  439 + }
  440 + }
  441 + if($filtro != ""){
  442 + $layer->setfilter($filtro);
  443 + }
  444 + $layer->set("data",$data);
  445 + }
  446 + }
  447 +}
  448 +//utilizada para obter os dados default quando se utiliza o plugin parametrossql
  449 +function execProg($prog){
  450 + include($prog);
  451 + //$retorno variavel deve ser retornada pelo programa $prog
  452 + //veja como exemplo i3geo/aplicmap/daods/listaano.php
  453 + return $retorno[0]["v"];
  454 +}
392 function converteenc($texto){ 455 function converteenc($texto){
393 if (!mb_detect_encoding($texto,"UTF-8",true)){ 456 if (!mb_detect_encoding($texto,"UTF-8",true)){
394 $texto = mb_convert_encoding($texto,"UTF-8","ISO-8859-1"); 457 $texto = mb_convert_encoding($texto,"UTF-8","ISO-8859-1");
@@ -351,7 +351,7 @@ else{ @@ -351,7 +351,7 @@ else{
351 if($extensao == ".map"){ 351 if($extensao == ".map"){
352 //cria o mapfile com base no sistema de metadados estatisticos 352 //cria o mapfile com base no sistema de metadados estatisticos
353 //verifica se o id_medida_variavel existe no mapfile e nao foi passado como um parametro 353 //verifica se o id_medida_variavel existe no mapfile e nao foi passado como um parametro
354 - if(!isset($id_medida_variavel) && $temai3geo == true){ 354 + if(!isset($id_medida_variavel) && $temai3geo == true){
355 $nmap = ms_newMapobj($locaplic."/temas/".$tx.".map"); 355 $nmap = ms_newMapobj($locaplic."/temas/".$tx.".map");
356 $l = $nmap->getlayer(0); 356 $l = $nmap->getlayer(0);
357 $teste = $l->getmetadata("METAESTAT_ID_MEDIDA_VARIAVEL"); 357 $teste = $l->getmetadata("METAESTAT_ID_MEDIDA_VARIAVEL");
@@ -667,10 +667,11 @@ else{ @@ -667,10 +667,11 @@ else{
667 } 667 }
668 $oMap->setSymbolSet($locaplic."/symbols/".basename($oMap->symbolsetfilename)); 668 $oMap->setSymbolSet($locaplic."/symbols/".basename($oMap->symbolsetfilename));
669 $oMap->setFontSet($locaplic."/symbols/".basename($oMap->fontsetfilename)); 669 $oMap->setFontSet($locaplic."/symbols/".basename($oMap->fontsetfilename));
  670 + //verifica se existem layers com plugin definido e processa conforme o tipo de plugin
  671 + processaPluginI3geo();
670 // 672 //
671 //caso seja download ou json ou csv 673 //caso seja download ou json ou csv
672 - //  
673 - 674 + //
674 processaOutputformatMapfile(); 675 processaOutputformatMapfile();
675 676
676 $oMap->save($nomeMapfileTmp); 677 $oMap->save($nomeMapfileTmp);
@@ -750,7 +751,7 @@ if(isset($_GET[&quot;Z&quot;]) &amp;&amp; isset($_GET[&quot;X&quot;])){ @@ -750,7 +751,7 @@ if(isset($_GET[&quot;Z&quot;]) &amp;&amp; isset($_GET[&quot;X&quot;])){
750 $x = $_GET["X"]; 751 $x = $_GET["X"];
751 $y = $_GET["Y"]; 752 $y = $_GET["Y"];
752 $z = $_GET["Z"]; 753 $z = $_GET["Z"];
753 - 754 +
754 if(file_exists($tema)){ 755 if(file_exists($tema)){
755 $layer0 = $oMap->getlayer(0); 756 $layer0 = $oMap->getlayer(0);
756 $layer0->set("status",MS_DEFAULT); 757 $layer0->set("status",MS_DEFAULT);
@@ -771,7 +772,7 @@ if(isset($_GET[&quot;Z&quot;]) &amp;&amp; isset($_GET[&quot;X&quot;])){ @@ -771,7 +772,7 @@ if(isset($_GET[&quot;Z&quot;]) &amp;&amp; isset($_GET[&quot;X&quot;])){
771 if ($layer0->getmetadata("cortepixels") != ""){ 772 if ($layer0->getmetadata("cortepixels") != ""){
772 $cortePixels = $layer0->getmetadata("cortepixels"); 773 $cortePixels = $layer0->getmetadata("cortepixels");
773 } 774 }
774 - 775 +
775 if($cache == true){ 776 if($cache == true){
776 carregaCacheImagem($cachedir,$nomeMapfileTmp,"/googlemaps/$layer0->name/$z/$x/$y"); 777 carregaCacheImagem($cachedir,$nomeMapfileTmp,"/googlemaps/$layer0->name/$z/$x/$y");
777 } 778 }
@@ -797,10 +798,10 @@ if(isset($_GET[&quot;Z&quot;]) &amp;&amp; isset($_GET[&quot;X&quot;])){ @@ -797,10 +798,10 @@ if(isset($_GET[&quot;Z&quot;]) &amp;&amp; isset($_GET[&quot;X&quot;])){
797 $oMap->setsize(256,256); 798 $oMap->setsize(256,256);
798 $oMap->setExtent($poPoint1->x,$poPoint1->y,$poPoint2->x,$poPoint2->y); 799 $oMap->setExtent($poPoint1->x,$poPoint1->y,$poPoint2->x,$poPoint2->y);
799 800
800 -  
801 - 801 +
  802 +
802 $oMap->setProjection("proj=merc,a=6378137,b=6378137,lat_ts=0.0,lon_0=0.0,x_0=0.0,y_0=0,k=1.0,units=m"); 803 $oMap->setProjection("proj=merc,a=6378137,b=6378137,lat_ts=0.0,lon_0=0.0,x_0=0.0,y_0=0,k=1.0,units=m");
803 - 804 +
804 // 805 //
805 //se o layer foi marcado para corte altera os parametros para ampliar o mapa 806 //se o layer foi marcado para corte altera os parametros para ampliar o mapa
806 //antes de gerar a imagem 807 //antes de gerar a imagem
@@ -925,19 +926,19 @@ if(strtolower($OUTPUTFORMAT) == &quot;geojson&quot; || strtolower($OUTPUTFORMAT) == &quot;json&quot; @@ -925,19 +926,19 @@ if(strtolower($OUTPUTFORMAT) == &quot;geojson&quot; || strtolower($OUTPUTFORMAT) == &quot;json&quot;
925 exit; 926 exit;
926 } 927 }
927 $oMap->owsdispatch($req); 928 $oMap->owsdispatch($req);
928 - 929 +
929 $contenttype = ms_iostripstdoutbuffercontenttype(); 930 $contenttype = ms_iostripstdoutbuffercontenttype();
930 ms_iostripstdoutbuffercontentheaders(); 931 ms_iostripstdoutbuffercontentheaders();
931 //grava em disco 932 //grava em disco
932 $contents = ms_iogetstdoutbufferstring(); 933 $contents = ms_iogetstdoutbufferstring();
933 file_put_contents($arq,$contents); 934 file_put_contents($arq,$contents);
934 //envia para download 935 //envia para download
935 - 936 +
936 header("Content-type: application/json; subtype=geojson"); 937 header("Content-type: application/json; subtype=geojson");
937 - 938 +
938 ms_iogetStdoutBufferBytes(); 939 ms_iogetStdoutBufferBytes();
939 ms_ioresethandlers(); 940 ms_ioresethandlers();
940 - 941 +
941 exit; 942 exit;
942 } 943 }
943 if(strtolower($OUTPUTFORMAT) == "shape-zip"){ 944 if(strtolower($OUTPUTFORMAT) == "shape-zip"){
@@ -1417,4 +1418,71 @@ function converteenc($texto){ @@ -1417,4 +1418,71 @@ function converteenc($texto){
1417 } 1418 }
1418 return $texto; 1419 return $texto;
1419 } 1420 }
  1421 +function processaPluginI3geo(){
  1422 + global $oMap, $locaplic;
  1423 + $numlayers = $oMap->numlayers;
  1424 + for ($i=0;$i < $numlayers;$i++){
  1425 + $l = $oMap->getlayer($i);
  1426 + $c = $l->getmetadata("PLUGINI3GEO");
  1427 + if($c != ""){
  1428 + $cs = json_decode($c,true);
  1429 + if($cs["plugin"] == "parametrossql"){
  1430 + $data = $l->data;
  1431 + $cs = $cs["parametros"];
  1432 + $chaves = array();
  1433 + foreach($cs as $c){
  1434 + $chaves[] = $c["chave"];
  1435 + }
  1436 + $chaves = implode(",",$chaves);
  1437 + $filtro = $l->getFilterString();
  1438 + $chaves = str_ireplace(array(" and ", " or ", "select","from","where","update","delete","insert","--"),"",$chaves);
  1439 + $chaves = explode(",",$chaves);
  1440 + $n = count($chaves);
  1441 + //a variavel $plugin vem da URL e contem os valores
  1442 + //que devem ser substituidos
  1443 + //se $plugin for vazio, usa o primeiro valor definido na configuracao do plugin
  1444 + //A ordem dos valores deve ser exatamente a ordem das chaves
  1445 + if(empty($plugin)){
  1446 + $plugin = array();
  1447 + foreach($cs as $c){
  1448 + if($c["chave"] != ""){
  1449 + //valores definidos no plugin como uma string
  1450 + if($c["valores"] != ""){
  1451 + $temp = explode(",",$c["valores"]);
  1452 + $plugin[] = $temp[0];
  1453 + }
  1454 + elseif ($c["prog"] != ""){
  1455 + $plugin[] = execProg($locaplic."/".$c["prog"]);
  1456 + }
  1457 + }
  1458 + }
  1459 + $plugin = implode(",",$plugin);
  1460 + }
  1461 + $l->setmetadata("TEMA",$l->getmetadata("TEMA")." - ".$plugin);
  1462 + $valores = str_ireplace(array(" and ", " or ", "select","from","where","update","delete","insert","--"),"",$plugin);
  1463 + $valores = explode(",",strip_tags($valores));
  1464 + for($i = 0; $i < $n; $i++){
  1465 + if($chaves[$i] != ""){
  1466 + $v = $valores[$i];
  1467 + $data = str_replace($chaves[$i],$v,$data);
  1468 + if($filtro != ""){
  1469 + $filtro = str_replace($chaves[$i],$v,$filtro);
  1470 + }
  1471 + }
  1472 + }
  1473 + if($filtro != ""){
  1474 + $l->setfilter($filtro);
  1475 + }
  1476 + $l->set("data",$data);
  1477 + }
  1478 + }
  1479 + }
  1480 +}
  1481 +//utilizada para obter os dados default quando se utiliza o plugin parametrossql
  1482 +function execProg($prog){
  1483 + include($prog);
  1484 + //$retorno variavel deve ser retornada pelo programa $prog
  1485 + //veja como exemplo i3geo/aplicmap/daods/listaano.php
  1486 + return $retorno[0]["v"];
  1487 +}
1420 ?> 1488 ?>