Commit eb44fdea4832325c3f4b2c926f3fbdb8d37654d4

Authored by Edmar Moretti
1 parent a1d28686

Inclusão de opção para abrir no i3geo uma variável estatística cadastrada

admin/js/estat_variavel.js
... ... @@ -429,9 +429,13 @@ function sql(tipo,id) {
429 429 ins += "<input type=text value='' id='filtrosql' />";
430 430 ins +="<p>Agrupar pela coluna<br>";
431 431 ins += "<input type=text value='' id='agruparsql' />";
  432 + ins +="<p>Tipo de layer (para o caso de mapas ou mapfiles, podendo ser point,line ou polygon)<br>";
  433 + ins += "<input type=text value='' id='tipolayer' />";
432 434 ins += '<p><input type=button id="sqljson" value="JSON" />';
433 435 ins += ' <input type=button id="sumarioestat" value="Sum&aacute;rio" />';
434 436 ins += ' <input type=button id="graficoestat" value="Gr&aacute;fico" />';
  437 + ins += ' <input type=button id="mapfileestat" value="Mapfile" />';
  438 + ins += ' <input type=button id="i3geoestat" value="i3Geo" />';
435 439  
436 440 $i("editor_bd").innerHTML = ins;
437 441 new YAHOO.widget.Button("sqljson");
... ... @@ -440,15 +444,42 @@ function sql(tipo,id) {
440 444 if($i("incluirtodascolunas").checked === true){
441 445 colunas = 1;
442 446 }
443   - window.open('../php/metaestat.php?funcao=dadosMedidaVariavel&formato=json&id_medida_variavel='+id+"&agruparpor="+$i("agruparsql").value+"&filtro="+$i("filtrosql").value+"&todasascolunas="+colunas);
  447 + window.open('../php/metaestat.php?funcao=dadosMedidaVariavel&formato=json&id_medida_variavel='+id+"&filtro="+$i("filtrosql").value+"&todasascolunas="+colunas);
444 448 };
445 449 new YAHOO.widget.Button("sumarioestat");
446 450 $i("sumarioestat-button").onclick = function(){
447 451 window.open('../php/metaestat.php?funcao=sumarioMedidaVariavel&formato=json&id_medida_variavel='+id+"&agruparpor="+$i("agruparsql").value+"&filtro="+$i("filtrosql").value);
448 452 };
  453 + new YAHOO.widget.Button("mapfileestat");
  454 + $i("mapfileestat-button").onclick = function(){
  455 + var colunas = 0;
  456 + if($i("incluirtodascolunas").checked === true){
  457 + colunas = 1;
  458 + }
  459 + window.open('../php/metaestat.php?funcao=mapfileMedidaVariavel&formato=json&id_medida_variavel='+id+"&filtro="+$i("filtrosql").value+"&todasascolunas="+colunas+"&tipolayer="+$i("tipolayer").value);
  460 + };
  461 + new YAHOO.widget.Button("i3geoestat");
  462 + $i("i3geoestat-button").onclick = function(){
  463 + var callback = {
  464 + success: function(oResponse){
  465 + var dados = YAHOO.lang.JSON.parse(oResponse.responseText);
  466 + window.open("../../ms_criamapa.php?temasa="+dados.mapfile+"&layers="+dados.layer);
  467 + core_carregando("desativa");
  468 + },
  469 + failure:core_handleFailure,
  470 + argument: { foo:"foo", bar:"bar" }
  471 + },
  472 + colunas = 0;
  473 + if($i("incluirtodascolunas").checked === true){
  474 + colunas = 1;
  475 + }
  476 + sUrl = '../php/metaestat.php?funcao=mapfileMedidaVariavel&formato=json&id_medida_variavel='+id+"&filtro="+$i("filtrosql").value+"&todasascolunas="+colunas+"&tipolayer="+$i("tipolayer").value;
  477 + core_carregando("ativa");
  478 + core_makeRequest(sUrl,callback);
  479 + };
449 480 new YAHOO.widget.Button("graficoestat");
450 481 $i("graficoestat-button").onclick = function(){
451   - callback = {
  482 + var callback = {
452 483 success: function(oResponse){
453 484 var dados = YAHOO.lang.JSON.parse(oResponse.responseText);
454 485 dados = dados.grupos;
... ... @@ -516,8 +547,8 @@ function sql(tipo,id) {
516 547 },
517 548 failure:core_handleFailure,
518 549 argument: { foo:"foo", bar:"bar" }
519   - };
520   - sUrl = '../php/metaestat.php?funcao=sumarioMedidaVariavel&formato=json&id_medida_variavel='+id+"&agruparpor="+$i("agruparsql").value+"&filtro="+document.getElementById("filtrosql").value;
  550 + },
  551 + sUrl = '../php/metaestat.php?funcao=sumarioMedidaVariavel&formato=json&id_medida_variavel='+id+"&agruparpor="+$i("agruparsql").value+"&filtro="+document.getElementById("filtrosql").value;
521 552 core_carregando("ativa");
522 553 core_makeRequest(sUrl,callback);
523 554 };
... ...
admin/php/classe_metaestat.php
... ... @@ -40,6 +40,7 @@ class Metaestat{
40 40 public $dbh;
41 41 protected $dbhw;
42 42 protected $convUTF;
  43 + public $dir_tmp;
43 44 /*
44 45 Function: __construct
45 46  
... ... @@ -48,6 +49,9 @@ class Metaestat{
48 49 function __construct(){
49 50 error_reporting(0);
50 51 include(__DIR__."/conexao.php");
  52 + //vem do include
  53 + $this->dir_tmp = $dir_tmp;
  54 + $this->locaplic = $locaplic;
51 55 if(!isset($convUTF)){
52 56 $convUTF = true;
53 57 }
... ... @@ -62,6 +66,16 @@ class Metaestat{
62 66 function __destruct(){
63 67 $this->fechaConexao;
64 68 }
  69 + function nomeRandomico($n=10){
  70 + $nomes = "";
  71 + $a = 'azertyuiopqsdfghjklmwxcvbnABCDEFGHIJKLMNOPQRSTUVWXYZ';
  72 + $max = 51;
  73 + for($i=0; $i < $n; ++$i)
  74 + {
  75 + $nomes .= $a{mt_rand(0, $max)};
  76 + }
  77 + return $nomes;
  78 + }
65 79 function fechaConexao(){
66 80 $this->dbh = null;
67 81 $this->dbhw = null;
... ... @@ -195,7 +209,7 @@ class Metaestat{
195 209 }
196 210 else{
197 211 $sql = " SELECT d.* ";
198   - $sqlgeo = " SELECT ".$dados["tabela"].".*,g.".$dados["colunaidgeo"];
  212 + $sqlgeo = $sql.",g.".$dadosgeo["colunageo"];
199 213 }
200 214 $sql .= " FROM ".$dados["esquemadb"].".".$dados["tabela"]." as d ";
201 215 $sqlgeo .= " FROM ".$dados["esquemadb"].".".$dados["tabela"]." as d,".$dadosgeo["esquemadb"].".".$dadosgeo["tabela"]." as g ";
... ... @@ -212,9 +226,57 @@ class Metaestat{
212 226 else{
213 227 $sqlgeo .= " WHERE ".$j;
214 228 }
215   - $sqlgeo = $dadosgeo["colunageo"]." from ($sqlgeo) as foo using unique ".$dados["colunaidgeo"]." using srid= ".$dadosgeo["srid"];
  229 + //atencao: cuidado ao alterar essa string pois ') as foo' pode ser usado para replace em outras funcoes
  230 + $sqlgeo = $dadosgeo["colunageo"]." from ($sqlgeo) as foo using unique ".$dados["colunaidgeo"]." using srid=".$dadosgeo["srid"];
216 231 return array("sql"=>$sql,"sqlmapserver"=>$sqlgeo,"filtro"=>$filtro);
217 232 }
  233 + function mapfileMedidaVariavel($id_medida_variavel,$filtro="",$todasascolunas = 0,$tipolayer="polygon",$titulolayer=""){
  234 + if(empty($tipolayer)){
  235 + $tipolayer = "polygon";
  236 + }
  237 + $meta = $this->listaMedidaVariavel("",$id_medida_variavel);
  238 + if($titulolayer == ""){
  239 + $titulolayer = $meta["nomemedida"];
  240 + }
  241 + $conexao = $this->listaConexao($meta["codigo_estat_conexao"],true);
  242 + $conexao = "user=".$conexao["usuario"]." password=".$conexao["senha"]." dbname=".$conexao["bancodedados"]." host=".$conexao["host"]." port=".$conexao["porta"]."";
  243 + //echo $conexao;exit;
  244 + $sql = $this->sqlMedidaVariavel($id_medida_variavel,$todasascolunas);
  245 + $sqlf = $sql["sqlmapserver"];
  246 + if(!empty($filtro)){
  247 + $sqlf = str_replace(") as foo"," AND ".$filtro." ) foo",$sqlf);
  248 + }
  249 + //echo $sqlf;exit;
  250 + $rand = $this->nomeRandomico();
  251 + $arq = $this->dir_tmp."/".$rand.".map";
  252 + $dados[] = "MAP";
  253 + $dados[] = "SYMBOLSET ".$this->locaplic."/symbols/simbolosv6.sym";
  254 + $dados[] = 'FONTSET "'.$this->locaplic.'/symbols/fontes.txt"';
  255 + $dados[] = "LAYER";
  256 + $dados[] = ' NAME "'.$rand.'"';
  257 + $dados[] = " TYPE $tipolayer";
  258 + $dados[] = ' DATA "'.$sqlf.'"';
  259 + $dados[] = ' CONNECTION "'.$conexao.'"';
  260 + $dados[] = ' CONNECTIONTYPE POSTGIS';
  261 + $dados[] = ' STATUS OFF';
  262 + $dados[] = ' METADATA';
  263 + $dados[] = ' TEMA "'.$titulolayer.'"';
  264 + $dados[] = ' CLASSE "SIM"';
  265 + $dados[] = ' END';
  266 + $dados[] = ' CLASS';
  267 + $dados[] = ' NAME ""';
  268 + $dados[] = ' STYLE';
  269 + $dados[] = ' COLOR 200 0 0';
  270 + $dados[] = ' END';
  271 + $dados[] = ' END';
  272 + $dados[] = "END";
  273 + $dados[] = "END";
  274 + $fp = fopen($arq,"w");
  275 + foreach ($dados as $dado){
  276 + fwrite($fp,$dado."\n");
  277 + }
  278 + return array("mapfile"=>$arq,"layer"=>$rand,"titulolayer"=>$titulolayer);
  279 + }
218 280 function dadosMedidaVariavel($id_medida_variavel,$filtro="",$todasascolunas = 0){
219 281 $sql = $this->sqlMedidaVariavel($id_medida_variavel,$todasascolunas);
220 282 $sqlf = $sql["sql"];
... ...
admin/php/conexao.php
... ... @@ -41,42 +41,16 @@ Free Software Foundation, Inc., no endere&amp;ccedil;o
41 41 Arquivo: i3geo/admin/php/conexao.php
42 42  
43 43 */
44   -if(isset($locaplic) && $locaplic != "")
45   -{
  44 +if(isset($locaplic) && $locaplic != ""){
46 45 include($locaplic."/ms_configura.php");
47 46 }
48   -else
49   -{
50   - if (file_exists("../../../ms_configura.php"))
51   - {
52   - include("../../../ms_configura.php");
53   - }
54   - else
55   - {
56   - if (file_exists("../../ms_configura.php"))
57   - {
58   - include("../../ms_configura.php");
59   - }
60   - else
61   - {
62   - if (file_exists("../ms_configura.php"))
63   - {
64   - include("../ms_configura.php");
65   - }
66   - else
67   - if (file_exists("ms_configura.php"))
68   - {
69   - include("ms_configura.php");
70   - }
71   - }
72   - }
  47 +else{
  48 + include(__DIR__."/../../ms_configura.php");
73 49 }
74   -if(!isset($conexaoadmin))
75   -{
  50 +if(!isset($conexaoadmin)){
76 51 $conexaoadmin = "";
77 52 }
78   -if(!isset($esquemaadmin))
79   -{
  53 +if(!isset($esquemaadmin)){
80 54 $esquemaadmin = "";
81 55 }
82 56 //
... ... @@ -84,11 +58,9 @@ if(!isset($esquemaadmin))
84 58 //
85 59 $convUTF = true;
86 60  
87   -if($conexaoadmin == "")
88   -{
  61 +if($conexaoadmin == ""){
89 62 $arquivosqlite = $locaplic."/admin/admin.db";
90   - if(!file_exists($arquivosqlite))
91   - {
  63 + if(!file_exists($arquivosqlite)){
92 64 echo "O arquivo admin.db n&atilde;o existe. Utilize i3geo/admin/criabanco.php para criar o banco de dados SQLITE.";
93 65 exit;
94 66 }
... ... @@ -97,15 +69,13 @@ if($conexaoadmin == &quot;&quot;)
97 69 if(!extension_loaded("PDO")){
98 70 echo "A extensao do PHP 'PDO' nao esta instalada.";
99 71 }
100   - try
101   - {
  72 + try {
102 73 //para escrita
103 74 $dbhw = new PDO($conAdminw);
104 75 //para leitura
105 76 $dbh = new PDO($conAdmin);
106 77 }
107   - catch (PDOException $e)
108   - {
  78 + catch (PDOException $e) {
109 79 print "Erro ao criar o objeto PDO!: " . $e->getMessage() . "<br/> Talvez exista alguma incompatibilidade entre o PHP e o banco admin.db. Vc pode apagar o arquivo menutemas/admin.db e recria-lo com admin/php/criasqlite.php";
110 80 die();
111 81 }
... ...
admin/php/editormapfile.php
... ... @@ -1144,7 +1144,7 @@ function criarNovoMap()
1144 1144 if(!file_exists($arq))
1145 1145 {
1146 1146 $dados[] = "MAP";
1147   - $dados[] = "SYMBOLSET ../symbols/simbolos.sym";
  1147 + $dados[] = "SYMBOLSET ../symbols/simbolosv6.sym";
1148 1148 $dados[] = 'FONTSET "../symbols/fontes.txt"';
1149 1149 $dados[] = "LAYER";
1150 1150 $dados[] = " NAME $codigo";
... ...
admin/php/metaestat.php
... ... @@ -511,7 +511,33 @@ switch (strtoupper($funcao))
511 511 case "DADOSMEDIDAVARIAVEL":
512 512 $m = new Metaestat();
513 513 if($formato == "json"){
514   - retornaJSON($m->dadosMedidaVariavel($id_medida_variavel,$filtro,$todasascolunas,$agruparpor));
  514 + retornaJSON($m->dadosMedidaVariavel($id_medida_variavel,$filtro,$todasascolunas));
  515 + }
  516 + exit;
  517 + break;
  518 + /*
  519 + Valor: MAPFILEMEDIDAVARIAVEL
  520 +
  521 + Cria o mapfile de uma media de uma variavel
  522 +
  523 + Parametros:
  524 +
  525 + formato
  526 +
  527 + filtro
  528 +
  529 + agruparpor
  530 +
  531 + todasascolunas - 0 ou 1
  532 +
  533 + Retorno:
  534 +
  535 + {JSON}
  536 + */
  537 + case "MAPFILEMEDIDAVARIAVEL":
  538 + $m = new Metaestat();
  539 + if($formato == "json"){
  540 + retornaJSON($m->mapfileMedidaVariavel($id_medida_variavel,$filtro,$todasascolunas,$tipolayer,$titulolayer));
515 541 }
516 542 exit;
517 543 break;
... ...
testamapfile.php
... ... @@ -102,7 +102,7 @@ if (isset($map) &amp;&amp; $map != &quot;&quot;)
102 102 if(!isset($solegenda)){$solegenda = "nao";}
103 103 if ($map == "todos")
104 104 {
105   - $tipo = "todos";
  105 + $tipo = "todos";
106 106 $conta = 0;
107 107 echo "<br>N&uacute;mero de mapas = ".(count($arqs["arquivos"]))." Faltam= ".(count($arqs["arquivos"])-$iniciar-10)."<br>";
108 108 if (!isset($iniciar)){$iniciar = 0;}
... ... @@ -121,7 +121,7 @@ if (isset($map) &amp;&amp; $map != &quot;&quot;)
121 121 echo "<hr><br><br><a href='testamapfile.php?map=todos&iniciar=".($iniciar+10)."' >Próximos mapas</a>";
122 122 }
123 123 else
124   - {verifica($map,$solegenda);}
  124 + {verifica($map,$solegenda);}
125 125 }
126 126 echo '</div>';
127 127 echo '<script>if(screen.availWidth > 700){document.getElementById("divGeral").style.width = "700px";}</script>';
... ... @@ -134,20 +134,20 @@ function verifica($map,$solegenda)
134 134 {
135 135 Header("Content-type: image/png");
136 136 ImagePng(ImageCreateFromPNG('temas/miniaturas/'.$map.".mini.png"));
137   - exit;
  137 + exit;
138 138 }
139 139 if ($tipo == "grande" && file_exists('temas/miniaturas/'.$map.".grande.png"))
140 140 {
141 141 Header("Content-type: image/png");
142 142 ImagePng(ImageCreateFromPNG('temas/miniaturas/'.$map.".grande.png"));
143   - exit;
  143 + exit;
144 144 }
145 145 ms_ResetErrorList();
146 146 $tema = "";
147 147 if(file_exists($map))
148 148 {$tema = $map;}
149 149 else
150   - {
  150 + {
151 151 $map = str_replace("\\","/",$map);
152 152 $map = basename($map);
153 153 if (file_exists('temas/'.$map))
... ... @@ -174,13 +174,13 @@ function verifica($map,$solegenda)
174 174 if($base == "" && file_exists('/var/www/i3geo/aplicmap/geral1debianv'.$versao.'.map')){
175 175 $base = "/var/www/i3geo/aplicmap/geral1debianv".$versao.".map";
176 176 }
177   - if($f == "" && file_exists('/var/www/html/i3geo/aplicmap/geral1fedorav'.$versao.'.map')){
  177 + if($base == "" && file_exists('/var/www/html/i3geo/aplicmap/geral1fedorav'.$versao.'.map')){
178 178 $base = "/var/www/html/i3geo/aplicmap/geral1fedorav".$versao.".map";
179 179 }
180   - if($f == "" && file_exists('/opt/www/html/i3geo/aplicmap/geral1fedorav'.$versao.'.map')){
  180 + if($base == "" && file_exists('/opt/www/html/i3geo/aplicmap/geral1fedorav'.$versao.'.map')){
181 181 $base = "/opt/www/html/i3geo/aplicmap/geral1v".$versao.".map";
182 182 }
183   - if($f == "")
  183 + if($base == "")
184 184 {$base = $locaplic."/aplicmap/geral1v".$versao.".map";}
185 185 }
186 186 }
... ... @@ -188,6 +188,7 @@ function verifica($map,$solegenda)
188 188 if(!file_exists($base))
189 189 {$base = $locaplic."/aplicmap/".$base;}
190 190 }
  191 + //echo $base;exit;
191 192 $mapa = ms_newMapObj($base);
192 193 error_reporting(0);
193 194 $temasn = $mapa->getAllLayerNames();
... ... @@ -204,7 +205,7 @@ function verifica($map,$solegenda)
204 205 if(($lcon == " ") || ($lcon == "")) //para efeitos de compatibilidade
205 206 {$layern->set("connection",$postgis_mapa);}
206 207 else
207   - {$layern->set("connection",$postgis_mapa[$lcon]);}
  208 + {$layern->set("connection",$postgis_mapa[$lcon]);}
208 209 }
209 210 }
210 211 }
... ... @@ -251,13 +252,13 @@ function verifica($map,$solegenda)
251 252 if ($layern->connectiontype == MS_POSTGIS)
252 253 {
253 254 $lcon = $layern->connection;
254   - error_reporting(0);
  255 + error_reporting(0);
255 256 if (($lcon == " ") || ($lcon == "") || (in_array($lcon,array_keys($postgis_mapa))))
256 257 {
257 258 if(($lcon == " ") || ($lcon == "")) //para efeitos de compatibilidade
258 259 {$layern->set("connection",$postgis_mapa);}
259 260 else
260   - {$layern->set("connection",$postgis_mapa[$lcon]);}
  261 + {$layern->set("connection",$postgis_mapa[$lcon]);}
261 262 }
262 263 }
263 264 }
... ... @@ -281,7 +282,7 @@ function verifica($map,$solegenda)
281 282 $dados = $layern->connection;
282 283 else
283 284 $dados = $layern->data;
284   - $pegarext = $teman;
  285 + $pegarext = $teman;
285 286 }
286 287 }
287 288 zoomTema($pegarext,$mapa);
... ... @@ -322,7 +323,7 @@ function verifica($map,$solegenda)
322 323 $nomec = ($objImagem->imagepath).nomeRandomico()."teste.png";
323 324 $objImagem->saveImage($nomec);
324 325 $nomer = ($objImagem->imageurl).basename($nomec);
325   -
  326 +
326 327 $nomel = ($objImagemLegenda->imagepath).nomeRandomico()."testel.png";
327 328 $objImagemLegenda->saveImage($nomel);
328 329 $nomerl = ($objImagemLegenda->imageurl).basename($nomel);
... ... @@ -346,7 +347,7 @@ function verifica($map,$solegenda)
346 347 $error = $error->next();
347 348 }
348 349 }
349   -
  350 +
350 351 }
351 352 else
352 353 {
... ... @@ -360,7 +361,7 @@ function zoomTema($nomelayer,&amp;$mapa)
360 361 {
361 362 $layer = $mapa->getlayerbyname($nomelayer);
362 363 if($layer->data == "" && $layer->connection == "")
363   - {return;}
  364 + {return;}
364 365 $prjMapa = $mapa->getProjection();
365 366 $prjTema = $layer->getProjection();
366 367 $extatual = $mapa->extent;
... ...