classe_menutemas.php
14.7 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
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
<?php
/*
Title: Menu
Manipulação dos temas do arquivo menutemas.xml.
Lista temas, grupos,etc.
About: Licença
I3Geo Interface Integrada de Ferramentas de Geoprocessamento para Internet
Direitos Autorais Reservados (c) 2006 Ministério do Meio Ambiente Brasil
Desenvolvedor: Edmar Moretti edmar.moretti@mma.gov.br
Este programa é software livre; você pode redistribuí-lo
e/ou modificá-lo sob os termos da Licença Pública Geral
GNU conforme publicada pela Free Software Foundation;
tanto a versão 2 da Licença.
Este programa é distribuído na expectativa de que seja útil,
porém, SEM NENHUMA GARANTIA; nem mesmo a garantia implícita
de COMERCIABILIDADE OU ADEQUAÇÃO A UMA FINALIDADE ESPECÍFICA.
Consulte a Licença Pública Geral do GNU para mais detalhes.
Você deve ter recebido uma cópia da Licença Pública Geral do
GNU junto com este programa; se não, escreva para a
Free Software Foundation, Inc., no endereço
59 Temple Street, Suite 330, Boston, MA 02111-1307 USA.
File: classe_menutemas.php
19/6/2007
*/
/*
Class: Menutemas
*/
class Menutemas
{
/*
Variable: $mapa
Objeto mapa
*/
protected $mapa;
/*
Variable: $arquivo
Arquivo map file
*/
protected $arquivo;
/*
Variable: $layers
Array com os layers
*/
protected $layers;
/*
Variable: $perfil
Perfil do usuário atual
*/
protected $perfil;
/*
Variable: $xmlsistemas
xml com a lista de sistemas
*/
protected $xmlsistemas;
/*
function: __construct
Cria um objeto Menutemas
parameters:
$map_file - string $map_file Endereço do mapfile no servidor.
*/
function __construct($map_file="",$perfil="",$locsistemas="")
{
$this->perfil = $perfil;
$this->xmlsistemas = "";
if ($locsistemas != "")
$this->xmlsistemas = simplexml_load_file($locsistemas);
if ($map_file != "")
{
$this->mapa = ms_newMapObj($map_file);
$this->arquivo = $map_file;
if ($this->mapa)
{
for ($i=0;$i < ($this->mapa->numlayers);$i++)
{$this->layers[] = $this->mapa->getlayer($i);}
}
}
}
/*
function: pegaListaDeMapas
Le o arquivo xml com a lista de mapas existente no xml $locmapas.
O perfil do usuário é armazenado na seção na inicialização do I3Geo.
Parameters:
locmapas - endereço do arquivo xml.
return:
array
*/
function pegaListaDeMapas($locmapas)
{
$this->xml = simplexml_load_file($locmapas);
$mapas = array();
//pega os sistemas checando os perfis
foreach($this->xml->MAPA as $s)
{
$ps = mb_convert_encoding($s->PERFIL,"HTML-ENTITIES","auto");
$perfis = explode(",",$ps);
if ((in_array($this->perfil,$perfis)) || ($ps == ""))
{
$n = mb_convert_encoding($s->NOME,"HTML-ENTITIES","auto");
$i = mb_convert_encoding($s->IMAGEM,"HTML-ENTITIES","auto");
$t = mb_convert_encoding($s->TEMAS,"HTML-ENTITIES","auto");
$l = mb_convert_encoding($s->LIGADOS,"HTML-ENTITIES","auto");
$e = mb_convert_encoding($s->EXTENSAO,"HTML-ENTITIES","auto");
$o = mb_convert_encoding($s->OUTROS,"HTML-ENTITIES","auto");
$k = mb_convert_encoding($s->LINKDIRETO,"HTML-ENTITIES","auto");
$mapas[] = array("NOME"=>$n,"IMAGEM"=>$i,"TEMAS"=>$t,"LIGADOS"=>$l,"EXTENSAO"=>$e,"OUTROS"=>$o,"LINK"=>$k);
}
}
return (array("mapas"=>$mapas));
}
/*
function: pegaListaDeGrupos
Pega a lista de grupos, subgrupos e sistemas adicionais.
O perfil do usuário é armazenado na seção na inicialização do I3Geo.
Os grupos e subgrupos são definidos no xml menutemas/menutemas.xml e os sistemas em menutemas/sistemas.xml.
Parameters:
idmenu - id que identifica o xml que será utilizado (definido na variável $menutemas em ms_configura.php)
listasistemas - sim|nao pega a lista de sistemas para montar a árvore de sistemas
return:
array
*/
function pegaListaDeGrupos($idmenu="",$listasistemas="sim")
{
$this->xml = "";
if (file_exists("../ms_configura.php"))
{require_once("../ms_configura.php");}
if ((isset($menutemas)) && ($menutemas != "") && ($idmenu != ""))
{
foreach ($menutemas as $m)
{
if (($m["idmenu"] == $idmenu))
{$this->xml = simplexml_load_file($m["arquivo"]);}
}
}
if ($this->xml == "")
{
if (file_exists("../menutemas/menutemas.xml"))
{$this->xml = simplexml_load_file("../menutemas/menutemas.xml");}
else
{$this->xml = simplexml_load_file("menutemas/menutemas.xml");}
}
$sistemas = array();
$grupos = array();
$temasraiz = array();
//pega os grupos
//verifica se existem temas na raiz do menu
foreach($this->xml->TEMA as $temar)
{
$down = "nao";
$temp = mb_convert_encoding($temar->DOWNLOAD,"HTML-ENTITIES","auto");
if (($temp == "sim") || ($temp == "SIM"))
{$down = "sim";}
$link = " ";
$temp = mb_convert_encoding($temar->TLINK,"HTML-ENTITIES","auto");
if ($temp != "")
{$link = $temp;}
$tid = mb_convert_encoding($temar->TID,"HTML-ENTITIES","auto");
$nome = mb_convert_encoding($temar->TNOME,"HTML-ENTITIES","auto");
$temasraiz[] = array("tid"=>$tid,"nome"=>$nome,"link"=>$link,"down"=>$down);
}
foreach($this->xml->GRUPO as $grupo)
{
$incluigrupo = TRUE;
$temp = mb_convert_encoding($grupo->PERFIL,"HTML-ENTITIES","auto");
if ($temp != "")
{
$incluigrupo = FALSE;
$perfis = explode(",",$temp);
if (in_array($this->perfil,$perfis))
{$incluigrupo = TRUE;}
}
//verifica se existem temas no nível de grupo
if ($incluigrupo == TRUE)
{
$temas = array();
foreach($grupo->TEMA as $temar)
{
$down = "nao";
$temp = mb_convert_encoding($temar->DOWNLOAD,"HTML-ENTITIES","auto");
if (($temp == "sim") || ($temp == "SIM"))
{$down = "sim";}
$link = " ";
$temp = mb_convert_encoding($temar->TLINK,"HTML-ENTITIES","auto");
if ($temp != "")
{$link = $temp;}
$tid = mb_convert_encoding($temar->TID,"HTML-ENTITIES","auto");
$nome = mb_convert_encoding($temar->TNOME,"HTML-ENTITIES","auto");
$temas[] = array("tid"=>$tid,"nome"=>$nome,"link"=>$link,"down"=>$down);
}
$subgrupos = array();
foreach($grupo->SGRUPO as $sgrupo)
{
$incluisgrupo = TRUE;
$temp = mb_convert_encoding($sgrupo->PERFIL,"HTML-ENTITIES","auto");
if ($temp != "")
{
$incluisgrupo = FALSE;
$perfis = explode(",",$temp);
if (in_array($this->perfil,$perfis))
{$incluisgrupo = TRUE;}
}
if ($incluisgrupo == TRUE)
{
//verifica se existem temas que podem receber download
$down = "nao";
foreach($sgrupo->TEMA as $tema)
{
$temp = mb_convert_encoding($tema->DOWNLOAD,"HTML-ENTITIES","auto");
if (($temp == "sim") || ($temp == "SIM"))
{$down = "sim";}
}
$nome = mb_convert_encoding($sgrupo->SDTIPO,"HTML-ENTITIES","auto");
$subgrupos[] = array("nome"=>$nome,"download"=>$down);
}
}
if (function_exists("mb_convert_encoding"))
{$nome = mb_convert_encoding($grupo->GTIPO,"HTML-ENTITIES","auto");}
else
{$nome = $grupo->GTIPO;}
$grupos[] = array("nome"=>$nome,"subgrupos"=>$subgrupos,"temasgrupo"=>$temas);
}
}
$grupos[] = array("temasraiz"=>$temasraiz);
//pega os sistemas checando os perfis
$sistemas = array();
if ($listasistemas == "sim")
{
foreach($this->xmlsistemas->SISTEMA as $s)
{
$nomesis = mb_convert_encoding($s->NOMESIS,"HTML-ENTITIES","auto");
$ps = mb_convert_encoding($s->PERFIL,"HTML-ENTITIES","auto");
$perfis = explode(",",$ps);
if ((in_array($this->perfil,$perfis)) || ($ps == ""))
{
$funcoes = array();
foreach($s->FUNCAO as $f)
{
$n = mb_convert_encoding($f->NOMEFUNCAO,"HTML-ENTITIES","auto");
$a = mb_convert_encoding($f->ABRIR,"HTML-ENTITIES","auto");
$w = mb_convert_encoding($f->JANELAW,"HTML-ENTITIES","auto");
$h = mb_convert_encoding($f->JANELAH,"HTML-ENTITIES","auto");
$p = mb_convert_encoding($f->PERFIL,"HTML-ENTITIES","auto");
if ((in_array($this->perfil,$perfis)) || ($p == ""))
{$funcoes[] = array("NOME"=>$n,"ABRIR"=>$a,"W"=>$w,"H"=>$h);}
}
$sistemas[] = array("NOME"=>$nomesis,"FUNCOES"=>$funcoes);
}
}
}
$grupos[] = array("idmenu"=>$idmenu);
$grupos[] = array("sistemas"=>$sistemas);
return ($grupos);
}
/*
function: pegaListaDeTemas
Le o arquivo xml com os temas e retorna um array com a lista de temas de um subgrupo.
parameters:
$grupo - Id do grupo.
$subgrupo - Id do subgrupo
return:
array
*/
function pegaListaDeTemas($grupo,$subgrupo,$idmenu)
{
$this->xml = "";
if (file_exists("../ms_configura.php"))
{require_once("../ms_configura.php");}
if ((isset($menutemas)) && ($menutemas != "") && ($idmenu != ""))
{
foreach ($menutemas as $m)
{
if (($m["idmenu"] == $idmenu))
{$this->xml = simplexml_load_file($m["arquivo"]);}
}
}
if ($this->xml == "")
{
if (file_exists("../menutemas/menutemas.xml"))
{$this->xml = simplexml_load_file("../menutemas/menutemas.xml");}
else
{$this->xml = simplexml_load_file("menutemas/menutemas.xml");}
}
$contagrupo = 0;
$temas = array();
foreach($this->xml->GRUPO as $g)
{
$incluigrupo = TRUE;
if ($g->PERFIL != "")
{
$incluigrupo = FALSE;
$perfis = explode(",",$g->PERFIL);
if (in_array($this->perfil,$perfis))
{$incluigrupo = TRUE;}
}
if ($incluigrupo == TRUE)
{
if ($contagrupo == $grupo)
{
$contasubgrupo = 0;
foreach ($g->SGRUPO as $s)
{
$incluisgrupo = TRUE;
if ($s->PERFIL != "")
{
$incluisgrupo = FALSE;
$perfis = explode(",",$s->PERFIL);
if (in_array($this->perfil,$perfis))
{$incluisgrupo = TRUE;}
}
if ($incluisgrupo == TRUE)
{
if ($contasubgrupo == $subgrupo)
{
foreach($s->TEMA as $tema)
{
$inclui = TRUE;
if ($tema->PERFIL != "")
{
$inclui = FALSE;
$perfis = explode(",",$tema->PERFIL);
if (in_array($this->perfil,$perfis))
{$inclui = TRUE;}
}
if ($inclui == TRUE)
{
$down = "nao";
if (($tema->DOWNLOAD == "sim") || ($tema->DOWNLOAD == "SIM"))
{$down = "sim";}
$link = " ";
if ($tema->TLINK != "")
{$link = mb_convert_encoding($tema->TLINK,"HTML-ENTITIES","auto");}
$tid = mb_convert_encoding($tema->TID,"HTML-ENTITIES","auto");
if (function_exists("mb_convert_encoding"))
{$nome = mb_convert_encoding($tema->TNOME,"HTML-ENTITIES","auto");}
else
{$nome = $tema->TNOME;}
$temas[] = array("tid"=>$tid,"nome"=>$nome,"link"=>$link,"down"=>$down);
}
}
}
$contasubgrupo = $contasubgrupo + 1;
}
}
}
$contagrupo = $contagrupo + 1;
}
}
return ($temas);
}
/*
function: procurartemas
Procura um tema no menu de temas.
Le o arquivo de temas xml e retorna o nome do mapfile correspondente.
parameters:
$procurar - String que será procurada.
*/
function procurartemas($procurar)
{
if (file_exists("../menutemas/menutemas.xml"))
{$this->xml = simplexml_load_file("../menutemas/menutemas.xml");}
else
{$this->xml = simplexml_load_file("menutemas/menutemas.xml");}
$listadetemas = array();
$resultado = array();
foreach($this->xml->GRUPO as $grupo)
{
$incluigrupo = TRUE;
$temp = mb_convert_encoding($grupo->PERFIL,"HTML-ENTITIES","auto");
if ($temp != "")
{
$incluigrupo = FALSE;
$perfis = explode(",",$temp);
if (in_array($this->perfil,$perfis))
{$incluigrupo = TRUE;}
}
if ($incluigrupo == TRUE)
{
foreach($grupo->SGRUPO as $sgrupo)
{
$incluisgrupo = TRUE;
if ($this->perfil != "")
{
$temp = mb_convert_encoding($sgrupo->PERFIL,"HTML-ENTITIES","auto");
$perfis = explode(",",$temp);
if (!in_array($this->perfil,$perfis))
{$incluisgrupo = FALSE;}
}
if ($incluisgrupo == TRUE)
{
foreach($sgrupo->TEMA as $tema)
{
$inclui = TRUE;
if ($this->perfil != "")
{
$temp = mb_convert_encoding($tema->PERFIL,"HTML-ENTITIES","auto");
$perfis = explode(",",$temp);
if (!in_array($this->perfil,$perfis))
{$inclui = FALSE;}
}
if ($inclui == TRUE)
{
$down = "nao";
$temp = mb_convert_encoding($tema->DOWNLOAD,"HTML-ENTITIES","auto");
if (($temp == "sim") || ($temp == "SIM"))
{$down = "sim";}
$link = mb_convert_encoding($tema->TLINK,"HTML-ENTITIES","auto");
$tid = mb_convert_encoding($tema->TID,"HTML-ENTITIES","auto");
if (function_exists("mb_convert_encoding"))
{$texto = array("tid"=>$tid,"nome"=>(mb_convert_encoding($tema->TNOME,"HTML-ENTITIES","auto")),"link"=>$link,"download"=>$down);}
else
{$texto = array("tid"=>$tid,"nome"=>$tema->TNOME,"link"=>$link,"download"=>$down);}
$p1 = $this->removeAcentos($procurar);
$p1 = $this->removeAcentos(htmlentities($p1));
$pp1 = $this->removeAcentos(mb_convert_encoding($tema->TNOME,"auto","auto"));
$pp1 = $this->removeAcentos(mb_convert_encoding($tema->TNOME,"auto","auto"));
$pp1 = $this->removeAcentos(htmlentities($pp1));
//$listadetemas[] = array("tid"=>"","nome"=>$pp1);
if (stristr($pp1,$p1))
{$listadetemas[] = $texto;}
}
}
if (count($listadetemas) > 0)
{
if (function_exists("mb_convert_encoding"))
{$subgrupo[] = array("subgrupo"=>(mb_convert_encoding($sgrupo->SDTIPO,"HTML-ENTITIES","auto")),"temas"=>$listadetemas);}
else
{$subgrupo[] = array("subgrupo"=>$sgrupo->SDTIPO,"temas"=>$listadetemas);}
}
}
$listadetemas = array();
}
if (count($subgrupo) > 0)
{
if (function_exists("mb_convert_encoding"))
{$resultado[] = array("grupo"=>(mb_convert_encoding($grupo->GTIPO,"HTML-ENTITIES","auto")),"subgrupos"=>$subgrupo);}
else
{$resultado[] = array("grupo"=>$grupo->GTIPO,"subgrupos"=>$subgrupo);}
}
$subgrupo = array();
}
}
return ($resultado);
}
function removeAcentos($s)
{
$s = ereg_replace("[áàâã]","a",$s);
$s = ereg_replace("[ÁÀÂÃ]","A",$s);
$s = ereg_replace("[éèê]","e",$s);
$s = ereg_replace("[í]","i",$s);
$s = ereg_replace("[Í]","I",$s);
$s = ereg_replace("[ÉÈÊ]","E",$s);
$s = ereg_replace("[óòôõ]","o",$s);
$s = ereg_replace("[ÓÒÔÕ]","O",$s);
$s = ereg_replace("[úùû]","u",$s);
$s = ereg_replace("[ÚÙÛ]","U",$s);
$s = str_replace("ç","c",$s);
$s = str_replace("Ç","C",$s);
//$s = ereg_replace(" ","",$s);
return $s;
}
}
?>