editortexto.php
13.5 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
<?php
// TODO incluir autocomplete no editor (eh possivel?)
// TODO incluir a lista de itens que podem ser usados em METADATA
?>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
<html>
<head>
<meta http-equiv="content-type" content="text/html; charset=ISO-8859-1">
<title>Editor texto</title>
<script src="../../pacotes/codemirror/lib/codemirror.js"></script>
<script src="../../pacotes/codemirror/mode/scribe/scribe.js"></script>
<link rel=stylesheet href="../../pacotes/codemirror/doc/docs.css">
<link rel="stylesheet" href="../../pacotes/codemirror/lib/codemirror.css">
<link rel="stylesheet" href="../../pacotes/codemirror/theme/ambiance.css">
<link rel="stylesheet" href="../../pacotes/codemirror/theme/cobalt.css">
<link rel="stylesheet" href="../../pacotes/codemirror/theme/night.css">
<link rel="stylesheet" href="../../pacotes/codemirror/theme/neo.css">
<link rel="stylesheet" href="../../pacotes/codemirror/theme/elegant.css">
<link rel="stylesheet" type="text/css" href="../html/admin.css">
<style type="text/css">
body {
margin-left: 10px;
font-size: 14px;
margin: auto;
background: white;
min-width: 1000px;
}
.CodeMirror {
height: 600px;
float: left;
width: 100%;
}
#selectComboMapfile {
width: 100%;
text-overflow: ellipsis;
font-size: 14px;
}
.cm-s-elegant span.cm-builtin {
color: red;
}
.cm-s-elegant span.cm-keyword.cm-block {
color: blue;
}
</style>
</head>
<body class=" yui-skin-sam ">
<div class="" id="divGeral" style="width: 100%;">
<div id=cabecalhoPrincipal style="min-height: 85px;"></div>
<form onsubmit="atualizaTextArea()" action="editortexto.php?mapfile=<?php echo $_GET["mapfile"];?>" method=post>
<fieldset style="position: relative; float: left; width: 48%; padding: 5px;">
<legend>Editor</legend>
<input type=submit value="Salvar" /> <input type=button value="Testar" onclick="testar()" /> <input type=button value="Testar no i3Geo" onclick="abrirI3geo()" /> <input type=button value="Tabela" onclick="abrirTabela()" /> (Salve antes de testar) Mais detalhes sobre a edição de
mapfiles: <a href="http://mapserver.org/mapfile/index.html#mapfile" target="_new">Documentação do Mapserver</a> <br> <br>
<?php
// evita erros removendo caracteres PHP
if (isset ( $_POST ["texto"] )) {
$gravarTexto = $_POST ["texto"];
$_POST ["texto"] = "";
}
include_once (dirname ( __FILE__ ) . "/login.php");
$versao = versao ();
$versao = $versao ["principal"];
// pega a extensao geografica
if (isset ( $base ) && $base != "") {
if (file_exists ( $base )) {
$f = $base;
} else {
$f = $locaplic . "/aplicmap/" . $base . ".map";
}
} else {
$f = "";
if (strtoupper ( substr ( PHP_OS, 0, 3 ) == 'WIN' )) {
$f = $locaplic . "/aplicmap/geral1windowsv" . $versao . ".map";
} else {
if ($f == "" && file_exists ( '/var/www/i3geo/aplicmap/geral1debianv' . $versao . '.map' )) {
$f = "/var/www/i3geo/aplicmap/geral1debianv" . $versao . ".map";
}
if ($f == "" && file_exists ( '/var/www/html/i3geo/aplicmap/geral1fedorav' . $versao . '.map' )) {
$f = "/var/www/html/i3geo/aplicmap/geral1fedorav" . $versao . ".map";
}
if ($f == "" && file_exists ( '/opt/www/html/i3geo/aplicmap/geral1fedorav' . $versao . '.map' )) {
$f = "/opt/www/html/i3geo/aplicmap/geral1v" . $versao . ".map";
}
if ($f == "") {
$f = $locaplic . "/aplicmap/geral1v" . $versao . ".map";
}
}
}
if (@ms_newMapObj ( $f )) {
$mapa = ms_newMapObj ( $f );
$c = $mapa->extent;
$extensao = $c->minx . "," . $c->miny . "," . $c->maxx . "," . $c->maxy;
}
if (verificaOperacaoSessao ( "admin/php/editortexto" ) == false) {
echo "Vc nao pode realizar essa operacao.";
exit ();
}
error_reporting ( 0 );
$mapfile = $locaplic . "/temas/" . $_GET ["mapfile"] . ".map";
if (! file_exists ( $mapfile )) {
echo "Arquivo $mapfile não existe.";
exit ();
}
// remove o cache OGC
$agora = intval ( time () / 1000 );
$nomeMapfileTmp = $dir_tmp . "/ogc_" . md5 ( $mapfile ) . "_" . $agora . ".map";
$nomeMapfileTmp = str_replace ( ",", "", $nomeMapfileTmp );
$nomeMapfileTmp = str_replace ( " ", "", $nomeMapfileTmp );
chmod ( $nomeMapfileTmp, 0777 );
unlink ( $nomeMapfileTmp );
//
if ($_POST ["tipo"] == "gravar") {
$fp = fopen ( $mapfile, "w" );
if ($fp == false) {
echo "<span style=color:red <b>Não foi possível salvar o arquivo. Verifique as permissões ou se há algum erro no mapfile</b></span><br><br>";
} else {
// remove itens vazios
$novoTexto = array ();
$testar = array (
"TEMPORIZADOR",
"PALLETESTEP",
"LTEMPOITEMIMAGEM",
"METAESTAT_ID_MEDIDA_VARIAVEL",
"GMOPACITY",
"GMSTATUS",
"ICONETEMA",
"LTEMPOITEMTITULO",
"DESCRIPTION_TEMPLATE",
"LTEMPOITEMLINK",
"TILES",
"METAESTAT_CODIGO_TIPO_REGIAO",
"ARQUIVOTEMAORIGINAL",
"PALLETEFILE",
"NOMEORIGINAL",
"OLSTATUS",
"PERMITEDOWNLOAD",
"LTEMPOFORMATODATA",
"FILTROORIGINAL",
"PERMITECOMENTARIO",
"LTEMPOITEMICONE",
"DATAORIGINAL",
"PLUGINI3GEO",
"METAESTAT",
"ITEMBUSCARAPIDA",
"ARQUIVODOWNLOAD",
"ARQUIVOKMZ",
"PERMITEKML",
"PERMITEOGC",
"CONVCARACTER",
"CORTEPIXELS",
"EDITORSQL",
"LTEMPOCONVENCODE",
"LTEMPOITEMFIM",
"OLOPACITY",
"LEGENDAWMS",
"LEGENDAIMG",
"KEYIMAGE",
"TILEINDEX",
"TILEITEM",
"SYMBOL",
"LABELITEM",
"FILTERITEM",
"GROUP",
"ENCODING",
"TIP",
"CLASSE",
"ITENSDESC",
"CLASSESNOME",
"ITENSLINK",
"ESCALA",
"CLASSESSIMBOLO",
"MENSAGEM",
"EXTENSAO",
"CLASSESITEM",
"ESCONDIDO",
"CLASSESCOR",
"DOWNLOAD",
"CLASSESTAMANHO",
"ITENS",
"TEMA",
"APLICAEXTENSAO",
"IDENTIFICA",
"TRANSITIONEFFECT"
);
foreach ( preg_split ( '~[\r\n]+~', $gravarTexto ) as $line ) {
$teste = strtoupper ( $line );
$teste = trim ( $teste );
$teste = str_replace ( array (
" ",
"'",
'"'
), "", $teste );
$teste = preg_replace ( '/[\n\r\t ]*/', '', $teste );
$passou = true;
foreach ( $testar as $t ) {
if ($teste == $t) {
$passou = false;
}
}
if ($passou == true) {
$novoTexto [] = $line;
}
}
fwrite ( $fp, implode ( "\r\n", $novoTexto ) );
}
fclose ( $fp );
// verifica os metadata que sao armazenados tambem no banco de dados de administracao
// isso e necessario para manter a consistencia caso o usuario altere manualmente os valores
// cria o objeto map
$mapa = ms_newMapObj ( $mapfile );
$codigo_tema = $_GET ["mapfile"];
$layer = $mapa->getlayerbyname ( $codigo_tema );
if ($layer == "") {
echo "<br><span style='color:red;'>Atenção: não existe nenhum LAYER com NAME igual a " . $codigo_tema . "</span><br>";
} else {
include ("conexao.php");
// pega o metadata
$meta = $layer->getmetadata ( "permitedownload" );
$meta = strtoupper ( $meta );
if ($meta != "" && ($meta == "SIM" || $meta == "NAO")) {
// grava no banco
$dbhw->query ( "UPDATE " . $esquemaadmin . "i3geoadmin_temas SET download_tema='$meta' WHERE codigo_tema = '$codigo_tema'" );
}
$meta = $layer->getmetadata ( "permiteogc" );
$meta = strtoupper ( $meta );
if ($meta != "" && ($meta == "SIM" || $meta == "NAO")) {
$dbhw->query ( "UPDATE " . $esquemaadmin . "i3geoadmin_temas SET ogc_tema='$meta' WHERE codigo_tema = '$codigo_tema'" );
}
$meta = $layer->getmetadata ( "permitekml" );
$meta = strtoupper ( $meta );
if ($meta != "" && ($meta == "SIM" || $meta == "NAO")) {
$dbhw->query ( "UPDATE " . $esquemaadmin . "i3geoadmin_temas SET kml_tema='$meta' WHERE codigo_tema = '$codigo_tema'" );
}
$meta = $layer->getmetadata ( "permitekmz" );
$meta = strtoupper ( $meta );
if ($meta != "" && ($meta == "SIM" || $meta == "NAO")) {
$dbhw->query ( "UPDATE " . $esquemaadmin . "i3geoadmin_temas SET kmz_tema='$meta' WHERE codigo_tema = '$codigo_tema'" );
}
$dbhw = null;
$dbh = null;
}
}
?>
<div style="float: left;">
Estilo: <select onchange="mudaEstilo(this.value)">
<option value=elegant>Elegant</option>
<option value=ambiance>Ambiance</option>
<option value=cobalt>Cobalt</option>
<option value=night>Night</option>
<option value=neo>Neo</option>
</select> <input type=button value="+ extender" onclick="editorCM.setSize('1100px')" /> <input type=button value="- reduzir" onclick="editorCM.setSize('')" />
</div>
<br> <br>
<?php
echo "<TEXTAREA id=editor name=texto cols=100 rows=20 style='width:100%;float:left;height:600px'>";
echo file_get_contents ( $mapfile );
echo "</TEXTAREA>";
?>
<p> </p>
<p style="font-size:10px;">Ctrl+a - Seleciona tudo<br>
Ctrl+d - Apaga a linha<br>
Ctrl-z - Desfazer<br>
Ctrl-Up - Sobe<br>
Alt-left - Início da linha</p>
</fieldset>
<fieldset style="top: 5px; position: relative; width: 48%; padding: 10px;">
<legend>Mapfile em edição</legend>
<div id=filtroDeLetras></div>
<div id="comboMapfiles" style="height:160px;">Aguarde...</div>
<?php
$mapfile = str_replace ( "\\", "/", $mapfile );
$servidor = "http://".$_SERVER ["SERVER_NAME"].":".$_SERVER ["SERVER_PORT"]."/".basename($locaplic)."/admin/php/preview.php";
if (! empty ( $extensao )) {
echo "<iframe id='mapaPreview' src='../../mashups/openlayers3.php?mapext=" . $extensao . "&servidor=". $servidor . "&fundo=e_wsm&nocache=sim&DESLIGACACHE=sim&controles=navigation,panzoombar,scaleline,mouseposition&botoes=identifica&largura=550&altura=400&temas=" . $mapfile . "' style='position:relative;top:2px;overflow:hidden;width:100%;height:450px;border:0px solid gray;'>";
} else {
echo "<iframe id='mapaPreview' src='../../mashups/openlayers3.php?servidor=". $servidor . "&fundo=e_wsm&nocache=sim&DESLIGACACHE=sim&controles=navigation,panzoombar,scaleline,mouseposition&botoes=identifica&largura=550&altura=400&temas=" . $mapfile . "' style='position:relative;top:2px;overflow:hidden;width:100%;height:450px;border:0px solid gray;'>";
}
echo "</iframe>";
echo "<input type=hidden name=tipo value=gravar />";
if (! @ms_newMapObj ( $mapfile )) {
echo "<span style=color:red <b>Não foi possível criar o mapa. Verifique as permissões ou se há algum erro no mapfile</b></span><br><br>";
} else {
$mapa = ms_newMapObj ( $mapfile );
$n = $mapa->numlayers;
echo "<br>Obs.: o corte de imagens não é considerado no preview";
echo "<br>Ajudante de cores RGB: <input type=text value='clique' size=10 id='corrgb' onclick=\"i3GEO.util.abreCor('','corrgb','rgbSep')\" />";
echo "<br><br>Colunas dos layers:<br><br>";
for($i = 0; $i < $n; $i ++) {
if (@$mapa->getlayer ( $i )) {
$l = $mapa->getlayer ( $i );
echo $l->name . ": " . (implode ( ",", pegaItens ( $l ) )) . "<br><br>";
} else {
echo "<span style=color:red <b>Não foi possível criar o LAYER {$l->name}. Verifique as permissões ou se há algum erro no mapfile</b></span><br><br>";
}
}
}
?>
</fieldset>
</form>
</div>
<script type="text/javascript" src="../js/core.js"></script>
<script type="text/javascript" src="../dicionario/core.js"></script>
<script src="../../classesjs/classe_util.js" type="text/javascript"></script>
<script>
i3GEO.configura = {locaplic: "../../"};
cabecalhoGeral("cabecalhoPrincipal","","../html/");
core_listaDeLetras("filtroDeLetras","filtraLetra",true);
var editorCM = CodeMirror.fromTextArea(document.getElementById("editor"), {
mode: 'scribe',
tabMode: 'indent',
lineNumbers: true,
theme: "elegant"
});
function getSelectedRange() {
return { from: editorCM.getCursor(true), to: editorCM.getCursor(false) };
}
function mudaEstilo(novo){
editorCM.setOption('theme',novo);
}
function atualizaTextArea(){
document.getElementById("editor").value = editorCM.getValue();
}
function filtraLetra(letra) {
letraAtual = letra;
if (letra == "Todos") {
letra = "";
}
i3GEO.util.insereCookie("I3GEOletraAdmin", letra);
core_pegaMapfiles("comboMapfiles()", letra);
}
function comboMapfiles(){
var n = $mapfiles.length,
i,ins;
ins = "<select size=8 id='selectComboMapfile' onchange='mudaMapfile(this)'><option value=''>Edite outro mapfile</option>";
for(i=0;i<n;i++){
if($mapfiles[i].extensao === "map"){
ins += "<option title='"+$mapfiles[i].nome+"' value='"+$mapfiles[i].codigo+"'>"+$mapfiles[i].codigo+" - "+$mapfiles[i].nome+"</optiona>";
}
}
ins += "</select>";
$i("comboMapfiles").innerHTML = ins;
$i("selectComboMapfile").value = "<?php echo $_GET["mapfile"];?>";
};
core_pegaMapfiles("comboMapfiles()","","");
function mudaMapfile(obj){
if(obj.value != ""){
window.location.href = "editortexto.php?mapfile="+obj.value;
}
}
function testar(){
window.open("../../testamapfile.php?map=<?php echo $_GET["mapfile"]; ?>");
}
function abrirI3geo(){
window.open("../../ms_criamapa.php?layers=<?php echo $_GET["mapfile"]; ?>");
}
function abrirTabela(){
window.open("../../ferramentas/recline/default.php?tema=<?php echo $_GET["mapfile"]; ?>");
}
</script>