Commit 37eb3bad793192f9cb5c835475ac8fc8395e186e

Authored by Edmar Moretti
1 parent eb71d003

Incluida opção para testar o mapfile antes de salvar no editor de mapfiles do si…

…stema de administração
admin/js/editormapfile.js
@@ -760,6 +760,7 @@ function montaEditorConexao(dados) @@ -760,6 +760,7 @@ function montaEditorConexao(dados)
760 ins += "<p>Os seguintes 'alias' estão disponíveis para uso na opção 'connection': "; 760 ins += "<p>Os seguintes 'alias' estão disponíveis para uso na opção 'connection': ";
761 ins += dados.postgis_mapa+"</p>" 761 ins += dados.postgis_mapa+"</p>"
762 } 762 }
  763 + ins += "<input type=button title='Testar' value='Testar' id=testarEditor />"
763 ins += core_geraLinhas(param) 764 ins += core_geraLinhas(param)
764 ins += "<br><br><br>" 765 ins += "<br><br><br>"
765 $i("editor_bd").innerHTML = ins 766 $i("editor_bd").innerHTML = ins
@@ -767,9 +768,14 @@ function montaEditorConexao(dados) @@ -767,9 +768,14 @@ function montaEditorConexao(dados)
767 temp += core_comboObjeto(objcontype,"valor","texto",dados.connectiontype) 768 temp += core_comboObjeto(objcontype,"valor","texto",dados.connectiontype)
768 temp += "</select>" 769 temp += "</select>"
769 $i("cConnectiontype").innerHTML = temp 770 $i("cConnectiontype").innerHTML = temp
  771 +
770 var temp = function() 772 var temp = function()
771 - {salvarDadosEditor('conexao',dados.codigoMap,dados.codigoLayer)} 773 + {salvarDadosEditor('conexao',dados.codigoMap,dados.codigoLayer,false)}
772 new YAHOO.widget.Button("salvarEditor",{ onclick: { fn: temp }}); 774 new YAHOO.widget.Button("salvarEditor",{ onclick: { fn: temp }});
  775 +
  776 + var temp = function()
  777 + {salvarDadosEditor('conexao',dados.codigoMap,dados.codigoLayer,true)}
  778 + new YAHOO.widget.Button("testarEditor",{ onclick: { fn: temp }});
773 } 779 }
774 function montaEditorMetadados(dados) 780 function montaEditorMetadados(dados)
775 { 781 {
@@ -891,11 +897,13 @@ function montaEditorGeral(dados) @@ -891,11 +897,13 @@ function montaEditorGeral(dados)
891 ] 897 ]
892 } 898 }
893 var ins = "<input type=button title='Salvar' value='Salvar' id=salvarEditor />" 899 var ins = "<input type=button title='Salvar' value='Salvar' id=salvarEditor />"
  900 + ins += "<input type=button title='Testar' value='Testar' id=testarEditor />"
894 if(dados.colunas != "") 901 if(dados.colunas != "")
895 { 902 {
896 ins += "<p>O layer possuí as seguintes colunas na tabela de atributos: "; 903 ins += "<p>O layer possuí as seguintes colunas na tabela de atributos: ";
897 ins += dados.colunas+"</p>" 904 ins += dados.colunas+"</p>"
898 } 905 }
  906 +
899 ins += core_geraLinhas(param) 907 ins += core_geraLinhas(param)
900 ins += "<br><br><br>" 908 ins += "<br><br><br>"
901 $i("editor_bd").innerHTML = ins 909 $i("editor_bd").innerHTML = ins
@@ -918,8 +926,13 @@ function montaEditorGeral(dados) @@ -918,8 +926,13 @@ function montaEditorGeral(dados)
918 $i("cToleranceunits").innerHTML = temp 926 $i("cToleranceunits").innerHTML = temp
919 927
920 var temp = function() 928 var temp = function()
921 - {salvarDadosEditor('geral',dados.codigoMap,dados.codigoLayer)} 929 + {salvarDadosEditor('geral',dados.codigoMap,dados.codigoLayer,false)}
922 new YAHOO.widget.Button("salvarEditor",{ onclick: { fn: temp }}); 930 new YAHOO.widget.Button("salvarEditor",{ onclick: { fn: temp }});
  931 +
  932 + var temp = function()
  933 + {salvarDadosEditor('geral',dados.codigoMap,dados.codigoLayer,true)}
  934 + new YAHOO.widget.Button("testarEditor",{ onclick: { fn: temp }});
  935 +
923 } 936 }
924 function montaEditorClasseGeral(dados) 937 function montaEditorClasseGeral(dados)
925 { 938 {
@@ -1105,8 +1118,9 @@ function montaEditorEstilo(dados) @@ -1105,8 +1118,9 @@ function montaEditorEstilo(dados)
1105 {salvarDadosEditor('estilo',dados.codigoMap,dados.codigoLayer,dados.indiceClasse,dados.indiceEstilo)} 1118 {salvarDadosEditor('estilo',dados.codigoMap,dados.codigoLayer,dados.indiceClasse,dados.indiceEstilo)}
1106 new YAHOO.widget.Button("salvarEditor",{ onclick: { fn: temp }}); 1119 new YAHOO.widget.Button("salvarEditor",{ onclick: { fn: temp }});
1107 } 1120 }
1108 -function salvarDadosEditor(tipo,codigoMap,codigoLayer,indiceClasse,indiceEstilo) 1121 +function salvarDadosEditor(tipo,codigoMap,codigoLayer,indiceClasse,indiceEstilo,testar)
1109 { 1122 {
  1123 + if(arguments.lenght == 5){var testar = false;}
1110 if(tipo == "conexao") 1124 if(tipo == "conexao")
1111 { 1125 {
1112 var campos = new Array("connection","data","connectiontype","tileitem","tileindex") 1126 var campos = new Array("connection","data","connectiontype","tileitem","tileindex")
@@ -1151,7 +1165,7 @@ function salvarDadosEditor(tipo,codigoMap,codigoLayer,indiceClasse,indiceEstilo) @@ -1151,7 +1165,7 @@ function salvarDadosEditor(tipo,codigoMap,codigoLayer,indiceClasse,indiceEstilo)
1151 var par = "&codigoMap="+codigoMap+"&codigoLayer="+codigoLayer+"&indiceClasse="+indiceClasse+"&indiceEstilo="+indiceEstilo 1165 var par = "&codigoMap="+codigoMap+"&codigoLayer="+codigoLayer+"&indiceClasse="+indiceClasse+"&indiceEstilo="+indiceEstilo
1152 var prog = "../php/editormapfile.php?funcao=alterarEstilo" 1166 var prog = "../php/editormapfile.php?funcao=alterarEstilo"
1153 } 1167 }
1154 - 1168 + prog += "&testar="+testar;
1155 for (i=0;i<campos.length;i++) 1169 for (i=0;i<campos.length;i++)
1156 {par += "&"+campos[i]+"="+($i(campos[i]).value)} 1170 {par += "&"+campos[i]+"="+($i(campos[i]).value)}
1157 core_carregando("ativa"); 1171 core_carregando("ativa");
@@ -1170,27 +1184,32 @@ function salvarDadosEditor(tipo,codigoMap,codigoLayer,indiceClasse,indiceEstilo) @@ -1170,27 +1184,32 @@ function salvarDadosEditor(tipo,codigoMap,codigoLayer,indiceClasse,indiceEstilo)
1170 } 1184 }
1171 else 1185 else
1172 { 1186 {
1173 - if(tipo=="conexao")  
1174 - {montaEditorConexao(YAHOO.lang.JSON.parse(o.responseText));}  
1175 - if(tipo=="metadados")  
1176 - {montaEditorMetadados(YAHOO.lang.JSON.parse(o.responseText));}  
1177 - if(tipo=="geral")  
1178 - {  
1179 - var d = YAHOO.lang.JSON.parse(o.responseText)  
1180 - montaEditorGeral(d);  
1181 - if(d.name != codigoLayer) 1187 + if(testar == false){
  1188 + if(tipo=="conexao")
  1189 + {montaEditorConexao(YAHOO.lang.JSON.parse(o.responseText));}
  1190 + if(tipo=="metadados")
  1191 + {montaEditorMetadados(YAHOO.lang.JSON.parse(o.responseText));}
  1192 + if(tipo=="geral")
1182 { 1193 {
1183 - core_pegaMapfiles("montaArvore()")  
1184 - YAHOO.example.container.panelEditor.destroy();  
1185 - YAHOO.example.container.panelEditor = null; 1194 + var d = YAHOO.lang.JSON.parse(o.responseText)
  1195 + montaEditorGeral(d);
  1196 + if(d.name != codigoLayer)
  1197 + {
  1198 + core_pegaMapfiles("montaArvore()")
  1199 + YAHOO.example.container.panelEditor.destroy();
  1200 + YAHOO.example.container.panelEditor = null;
  1201 + }
1186 } 1202 }
  1203 + if(tipo=="classeGeral")
  1204 + {montaEditorClasseGeral(YAHOO.lang.JSON.parse(o.responseText));}
  1205 + if(tipo=="classeLabel")
  1206 + {montaEditorClasseLabel(YAHOO.lang.JSON.parse(o.responseText));}
  1207 + if(tipo=="estilo")
  1208 + {montaEditorEstilo(YAHOO.lang.JSON.parse(o.responseText));}
  1209 + }
  1210 + else{
  1211 + window.open("../../testamapfile.php?map="+YAHOO.lang.JSON.parse(o.responseText).url)
1187 } 1212 }
1188 - if(tipo=="classeGeral")  
1189 - {montaEditorClasseGeral(YAHOO.lang.JSON.parse(o.responseText));}  
1190 - if(tipo=="classeLabel")  
1191 - {montaEditorClasseLabel(YAHOO.lang.JSON.parse(o.responseText));}  
1192 - if(tipo=="estilo")  
1193 - {montaEditorEstilo(YAHOO.lang.JSON.parse(o.responseText));}  
1194 core_carregando("desativa"); 1213 core_carregando("desativa");
1195 } 1214 }
1196 } 1215 }
admin/php/editormapfile.php
@@ -147,8 +147,11 @@ switch ($funcao) @@ -147,8 +147,11 @@ switch ($funcao)
147 case "alterarConexao": 147 case "alterarConexao":
148 if(verificaEditores($editores) == "nao") 148 if(verificaEditores($editores) == "nao")
149 {echo "Vc nao e um editor cadastrado. Apenas os editores definidos em i3geo/ms_configura.php podem acessar o sistema de administracao.";exit;} 149 {echo "Vc nao e um editor cadastrado. Apenas os editores definidos em i3geo/ms_configura.php podem acessar o sistema de administracao.";exit;}
150 - alterarConexao(); 150 + $retorno = alterarConexao();
  151 + if($testar == false)
151 retornaJSON(pegaConexao()); 152 retornaJSON(pegaConexao());
  153 + else
  154 + retornaJSON(array("url"=>$retorno));
152 exit; 155 exit;
153 break; 156 break;
154 case "pegaMetadados": 157 case "pegaMetadados":
@@ -169,9 +172,12 @@ switch ($funcao) @@ -169,9 +172,12 @@ switch ($funcao)
169 case "alterarGeral": 172 case "alterarGeral":
170 if(verificaEditores($editores) == "nao") 173 if(verificaEditores($editores) == "nao")
171 {echo "Vc nao e um editor cadastrado. Apenas os editores definidos em i3geo/ms_configura.php podem acessar o sistema de administracao.";exit;} 174 {echo "Vc nao e um editor cadastrado. Apenas os editores definidos em i3geo/ms_configura.php podem acessar o sistema de administracao.";exit;}
172 - alterarGeral();  
173 - $codigoLayer = $name; 175 + $retorno = alterarGeral();
  176 +
  177 + if($testar == false)
174 retornaJSON(pegaGeral()); 178 retornaJSON(pegaGeral());
  179 + else
  180 + retornaJSON(array("url"=>$retorno));
175 exit; 181 exit;
176 break; 182 break;
177 case "pegaClasseGeral": 183 case "pegaClasseGeral":
@@ -469,7 +475,7 @@ function pegaConexao() @@ -469,7 +475,7 @@ function pegaConexao()
469 } 475 }
470 function alterarConexao() 476 function alterarConexao()
471 { 477 {
472 - global $codigoMap,$codigoLayer,$locaplic,$connection,$connectiontype,$data,$tileitem,$tileindex; 478 + global $dir_tmp,$testar,$codigoMap,$codigoLayer,$locaplic,$connection,$connectiontype,$data,$tileitem,$tileindex;
473 $mapfile = $locaplic."/temas/".$codigoMap.".map"; 479 $mapfile = $locaplic."/temas/".$codigoMap.".map";
474 $mapa = ms_newMapObj($mapfile); 480 $mapa = ms_newMapObj($mapfile);
475 $layer = $mapa->getlayerbyname($codigoLayer); 481 $layer = $mapa->getlayerbyname($codigoLayer);
@@ -478,9 +484,19 @@ function alterarConexao() @@ -478,9 +484,19 @@ function alterarConexao()
478 $layer->set("data",$data); 484 $layer->set("data",$data);
479 $layer->set("tileitem",$tileitem); 485 $layer->set("tileitem",$tileitem);
480 $layer->set("tileindex",$tileindex); 486 $layer->set("tileindex",$tileindex);
481 - $mapa->save($mapfile);  
482 - removeCabecalho($mapfile);  
483 - return "ok"; 487 + if($testar == true)
  488 + {
  489 + $nome = $dir_tmp."/".$codigoMap.".map";
  490 + $mapa->save($nome);
  491 + removeCabecalho($nome,false);
  492 + return $nome;
  493 + }
  494 + else
  495 + {
  496 + $mapa->save($mapfile);
  497 + removeCabecalho($mapfile);
  498 + return "ok";
  499 + }
484 } 500 }
485 function pegaMetadados() 501 function pegaMetadados()
486 { 502 {
@@ -580,7 +596,7 @@ function pegaGeral() @@ -580,7 +596,7 @@ function pegaGeral()
580 } 596 }
581 function alterarGeral() 597 function alterarGeral()
582 { 598 {
583 - global $codigoMap,$codigoLayer,$locaplic,$name,$projection,$sizeunits,$status,$toleranceunits,$tolerance,$symbolscale,$opacity,$offsite,$minscale,$maxscale,$labelsizeitem,$labelminscale,$labelmaxscale,$labelitem,$group,$filteritem,$type,$filter; 599 + global $dir_tmp,$testar,$codigoMap,$codigoLayer,$locaplic,$name,$projection,$sizeunits,$status,$toleranceunits,$tolerance,$symbolscale,$opacity,$offsite,$minscale,$maxscale,$labelsizeitem,$labelminscale,$labelmaxscale,$labelitem,$group,$filteritem,$type,$filter;
584 error_reporting(E_ALL); 600 error_reporting(E_ALL);
585 $v = versao(); 601 $v = versao();
586 $dados = array(); 602 $dados = array();
@@ -620,6 +636,14 @@ function alterarGeral() @@ -620,6 +636,14 @@ function alterarGeral()
620 $layer->setprojection($projection); 636 $layer->setprojection($projection);
621 if($layer->getprojection() == MS_FALSE && $projection != "") 637 if($layer->getprojection() == MS_FALSE && $projection != "")
622 $layer->setprojection($projection); 638 $layer->setprojection($projection);
  639 +
  640 + if($testar == true)
  641 + {
  642 + $nome = $dir_tmp."/".$codigoMap.".map";
  643 + $mapa->save($nome);
  644 + removeCabecalho($nome,false);
  645 + return $nome;
  646 + }
623 647
624 $mapa->save($mapfile); 648 $mapa->save($mapfile);
625 removeCabecalho($mapfile); 649 removeCabecalho($mapfile);
@@ -834,15 +858,18 @@ function alterarEstilo() @@ -834,15 +858,18 @@ function alterarEstilo()
834 return "ok"; 858 return "ok";
835 } 859 }
836 860
837 -function removeCabecalho($arq) 861 +function removeCabecalho($arq,$symbolset=true)
838 { 862 {
839 global $postgis_mapa; 863 global $postgis_mapa;
840 restauraCon($arq,$postgis_mapa); 864 restauraCon($arq,$postgis_mapa);
841 $handle = fopen($arq, "r"); 865 $handle = fopen($arq, "r");
842 if ($handle) 866 if ($handle)
843 { 867 {
844 - $final[] = "SYMBOLSET ../symbols/simbolos.sym\n";  
845 - $final[] = "FONTSET ".'"'."../symbols/fontes.txt".'"'."\n"; 868 + if($symbolset)
  869 + {
  870 + $final[] = "SYMBOLSET ../symbols/simbolos.sym\n";
  871 + $final[] = "FONTSET ".'"'."../symbols/fontes.txt".'"'."\n";
  872 + }
846 $grava = false; 873 $grava = false;
847 while (!feof($handle)) 874 while (!feof($handle))
848 { 875 {
menutemas/admin.db
No preview for this file type
testamapfile.php
@@ -116,12 +116,20 @@ function verifica($map) @@ -116,12 +116,20 @@ function verifica($map)
116 } 116 }
117 ms_ResetErrorList(); 117 ms_ResetErrorList();
118 $tema = ""; 118 $tema = "";
119 - $map = str_replace("\\","/",$map);  
120 - $map = basename($map);  
121 - if (file_exists('temas/'.$map))  
122 - {$tema = 'temas/'.$map;}  
123 - if (file_exists('temas/'.$map.'.map'))  
124 - {$tema = 'temas/'.$map.".map";} 119 +
  120 + if(file_exists($map))
  121 + $tema = $map;
  122 + else
  123 + {
  124 + $map = str_replace("\\","/",$map);
  125 + $map = basename($map);
  126 + if (file_exists('temas/'.$map))
  127 + {$tema = 'temas/'.$map;}
  128 + if (file_exists('temas/'.$map.'.map'))
  129 + {$tema = 'temas/'.$map.".map";}
  130 + }
  131 +
  132 +
125 if(($tipo == "") || ($tipo == "todos")) 133 if(($tipo == "") || ($tipo == "todos"))
126 echo "<hr><br><br><span style='color:red' ><b>Testando: $tema </span><pre></b>"; 134 echo "<hr><br><br><span style='color:red' ><b>Testando: $tema </span><pre></b>";
127 if ($tema != "") 135 if ($tema != "")
@@ -137,6 +145,12 @@ function verifica($map) @@ -137,6 +145,12 @@ function verifica($map)
137 else 145 else
138 { 146 {
139 echo "erro no arquivo $map <br>"; 147 echo "erro no arquivo $map <br>";
  148 + $error = ms_GetErrorObj();
  149 + while($error && $error->code != MS_NOERR)
  150 + {
  151 + printf("<br>Error in %s: %s<br>\n", $error->routine, $error->message);
  152 + $error = $error->next();
  153 + }
140 return; 154 return;
141 } 155 }
142 $temasn = $nmapa->getAllLayerNames(); 156 $temasn = $nmapa->getAllLayerNames();