classe_menutemas.php 28.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 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 954 955 956 957 958 959 960 961 962 963 964 965 966 967 968 969 970 971 972 973 974 975 976
<?php
/*
Title: classe_menutemas.php

Manipulação dos temas do arquivo menutemas.xml ou sistema de administração

Quando o i3Geo está configurado para acessar o sistema de administração, os métodos desta classe
passam a utilizar a classe i3geo/admin/php/classe_arvore.php

Lista temas, grupos,etc.

Licenca:

GPL2


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.

Arquivo:

i3geo/classesphp/classe_menutemas.php

*/
/*
Classe: Menutemas
*/
class Menutemas
{
/*
function: __construct

Cria um objeto Menutemas

parameters:

$map_file - (opcional) endereço do mapfile no servidor

$perfil - (opcional) lista dos perfis, separados por espaços, que devem restringir a lista de menus, grupos, temas e etc.

$locsistemas - (opcional) endereço do xml com a lista de sistemas adicionais que serão listados na opção de adiçao de temas

$locaplic - (opcional) endereço físico do i3geo

$menutemas - (opcional) array contendo a lista de menus para compor a árvore de temas (veja o i3geo/ms_configura)

$urli3geo - (opcional) url onde está o i3geo (p.ex. http://localhost/i3geo

$editores - (opcional) array com os editores cadastrados no ms_configura.php
*/  	
	function __construct($map_file="",$perfil="",$locsistemas="",$locaplic="",$menutemas="",$urli3geo="",$editores="")
	{
		error_reporting(0);
		$perfil = str_replace(" ",",",$perfil);
		$this->perfil = explode(",",$perfil);
		$this->locsistemas = $locsistemas;
		$this->xmlsistemas = "";
		$this->locaplic = $locaplic;
		$this->menutemas = $menutemas;
		$this->urli3geo = $urli3geo;
		if (($map_file != "") && (file_exists($map_file)))
		{
			$this->mapa = ms_newMapObj($map_file);
			$this->arquivo = $map_file;
			if ($this->mapa)
			{
				$c = $this->mapa->numlayers;
				for ($i=0;$i < $c;++$i)
				{$this->layers[] = $this->mapa->getlayer($i);}
			}
		}
		//
		//verifica se o ip atual está cadastrado como um dos editores
		//editores podem ver as coisas marcadas como não publicado
		//no sistema de administração
		//
		$this->editor = false;
		if($editores != "")
		{$this->editor = $this->verificaeditores($editores);}
		$this->editores = $editores;
	}
/*
function: pegaListaDeMenus

Pega a lista de menus do banco de dados de administração.

O perfil do usuário é armazenado na seção na inicialização do I3Geo.

Parametros:

return:
array
*/
	function pegaListaDeMenus()
	{
		$resultado = array();
		//necessário por conta da inclusao do conexao.php
		$locaplic = $this->locaplic;
		//
		//se $menutemas estiver "", o i3geo
		//irá utilizar o sistema de administração para pegar os menus
		//
		if($this->menutemas == "")
		{
			if(!isset($this->locaplic))
			{return "locaplic nao foi definido";}
			include_once($this->locaplic."/admin/php/classe_arvore.php");
			$arvore = new Arvore($this->locaplic);
			$resultado = $arvore->pegaListaDeMenus($this->perfil);
			unset($arvore);
		}
		else
		{$resultado = $this->menutemas;}
		if(count($resultado) == 0)
		{$resultado[] = array("publicado"=>"SIM","idmenu"=>"i3geo (xml)","arquivo"=>"../menutemas/menutemas.xml","status"=>"aberto");}
		return ($resultado);
	}
/*
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.

Parametros:

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

listasgrupos - sim|nao lista também os subgrupos associados

return:

array
*/
	function pegaListaDeGrupos($idmenu="",$listasistemas="sim",$listasgrupos="sim")
	{
		//
		//lê os arquivos xml
		//"&tipo=gruposeraiz" pega apenas os nomes dos grupos e temas na raiz
		//
		//necessário por conta da inclusao do conexao.php
		$locaplic = $this->locaplic;
		include_once($this->locaplic."/admin/php/xml.php");
		if($listasgrupos == "sim")
		{$tipo = "";}
		else
		{$tipo = "gruposeraiz";}
		$this->xml = "";
		$tempm = $this->pegaListaDeMenus();
		$xmls = array();
		foreach($tempm as $menu)
		{
			if($menu["idmenu"] == $idmenu || $idmenu == "")
			{
				if(!isset($menu["url"])){$menu["url"] = "";} //para efeitos de compatibilidade entre versões do i3geo
				$ondexml = $menu["arquivo"];
				//if(!isset($menu["publicado"])){$ondexml = $menu["url"];}
				if($ondexml != "" && $this->menutemas != "")
				{
					$xml = simplexml_load_file($ondexml);
					$grupos = $this->retornaGrupos($xml,$listasistemas,$idmenu,$listasgrupos);
				}
				else //pega o xml do sistema de administração
				{
					include_once("../admin/php/classe_arvore.php");
					$arvore = new Arvore($this->locaplic);
					$grupos = $arvore->formataGruposMenu($idmenu,$this->perfil,$listasgrupos);
					unset($arvore);
				}
			}
		}
		return ($grupos);
	}
	function retornaGrupos($xml,$listasistemas,$idmenu,$listasgrupos)
	{
		$sistemas = array();
		$grupos = array();
		$temasraiz = array();
		//
		//pega os temas na raiz
		//
		foreach($xml->TEMA as $temar)
		{
			$down = "sim";
			$ogc = "sim";
			$temp = $this->ixml($temar,"DOWNLOAD");
			if (($temp == "nao") || ($temp == "NAO"))
			{$down = "nao";}
			$temp = $this->ixml($temar,"OGC");
			if (($temp == "nao") || ($temp == "NAO"))
			{$ogc = "nao";}
			$link = " ";
			$temp = $this->ixml($temar,"TLINK");
			if ($temp != "")
			{$link = $temp;}
			$tid = $this->ixml($temar,"TID");
			$nome = $this->ixml($temar,"TNOME");
			$temasraiz[] = array("tid"=>$tid,"nome"=>$nome,"link"=>$link,"download"=>$down,"ogc"=>$ogc);
		}
		foreach($xml->GRUPO as $grupo)
		{
			$incluigrupo = TRUE;
			//filtra pelo perfil
			$temp = $this->ixml($grupo,"PERFIL");
			if ($temp != "")
			{
				$incluigrupo = FALSE;
				$perfis = str_replace(","," ",$temp);
				$perfis = explode(" ",$perfis);
				if ($this->array_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 = "sim";
					$ogc = "sim";
					$temp = $this->ixml($temar,"DOWNLOAD");
					if (($temp == "nao") || ($temp == "NAO"))
					{$down = "nao";}
					$temp = $this->ixml($temar,"OGC");
					if (($temp == "nao") || ($temp == "NAO"))
					{$ogc = "nao";}
					$link = " ";
					$temp = $this->ixml($temar,"TLINK");
					if ($temp != "")
					{$link = $temp;}
					$tid = $this->ixml($temar,"TID");
					$nome = $this->ixml($temar,"TNOME");
					$temas[] = array("tid"=>$tid,"nome"=>$nome,"link"=>$link,"download"=>$down,"ogc"=>$ogc);
				}
				$grupodown = "sim";
				$grupoogc = "sim";
				foreach($grupo->SGRUPO as $sgrupo)
				{
					foreach($sgrupo->TEMA as $tema)
					{
						$temp = $this->ixml($tema,"DOWNLOAD");
						if (($temp == "nao") || ($temp == "NAO"))
						{$grupodown = "nao";}
						else
						{$grupodown = "sim";}
						$temp = $this->ixml($tema,"OGC");
						if (($temp == "nao") || ($temp == "NAO"))
						{$grupoogc = "nao";}
						else
						{$grupoogc = "sim";}						
					}
				}
				$subgrupos = array();
				if($listasgrupos=="sim")
				{
					foreach($grupo->SGRUPO as $sgrupo)
					{
						$incluisgrupo = TRUE;
						$temp = $this->ixml($sgrupo,"PERFIL");
						if ($temp != "")
						{
							$incluisgrupo = FALSE;
							$perfis = str_replace(","," ",$temp);
							$perfis = explode(" ",$perfis);
							if ($this->array_in_array($this->perfil,$perfis))
							{$incluisgrupo = TRUE;}
						}
						if ($incluisgrupo == TRUE)
						{
							//verifica se existem temas que podem receber download
							$down = "sim";
							$ogc = "sim";
							foreach($sgrupo->TEMA as $tema)
							{
								$temp = $this->ixml($tema,"DOWNLOAD");
								if (($temp == "nao") || ($temp == "NAO"))
								{$down = "nao";}
								else
								{$down = "sim";}
								$temp = $this->ixml($tema,"OGC");
								if (($temp == "nao") || ($temp == "NAO"))
								{$ogc = "nao";}
								else
								{$ogc = "sim";}
							}
							$nome = $this->ixml($sgrupo,"SDTIPO");
							$subgrupos[] = array("nome"=>$nome,"download"=>$down,"ogc"=>$ogc);
						}
					}
				}
				$nome = $this->ixml($grupo,"GTIPO");
				$grupos[] = array("nome"=>$nome,"ogc"=>$grupoogc,"download"=>$grupodown,"subgrupos"=>$subgrupos,"temasgrupo"=>$temas);
			}
		}
		$grupos[] = array("temasraiz"=>$temasraiz);
		//pega os sistemas checando os perfis
		$sistemas = array();
		if ($listasistemas == "sim")
		{$sistemas = pegaSistemas();}
		$grupos[] = array("idmenu"=>$idmenu);
		$grupos[] = array("sistemas"=>$sistemas);
		return($grupos);		
		
	}
/*
function: pegaListaDeSubGrupos

Pega a lista de sub-grupos.

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.

Parametros:

idmenu - id que identifica o xml que será utilizado (definido na variável $menutemas em ms_configura.php)

grupo - código do grupo

return:

array
*/
	function pegaListaDeSubGrupos($codgrupo,$idmenu="")
	{
		$locaplic=$this->locaplic;
		include_once($this->locaplic."/admin/php/xml.php");
		$tipo = "subgrupos";
		$this->xml = "";
		foreach($this->pegaListaDeMenus() as $menu)
		{
			if($menu["idmenu"] == $idmenu || $idmenu == "")
			{
				if(!isset($menu["url"])){$menu["url"] = "";} //para efeitos de compatibilidade entre versões do i3geo
				$ondexml = $menu["arquivo"];
				if($menu["url"] != ""){$ondexml = $menu["url"];}
				if($ondexml != "" && $this->menutemas != "")
				{$this->xml = simplexml_load_file($ondexml);}
				else //pega o xml do sistema de administração
				{
					//$this->xml = simplexml_load_string(geraXmlMenutemas(implode(" ",$this->perfil),$idmenu,$tipo,$this->locaplic));
					//echo geraXmlMenutemas(implode(" ",$this->perfil),$idmenu,$tipo,$this->locaplic);exit;	
					include_once("../admin/php/classe_arvore.php");
					$arvore = new Arvore($this->locaplic);
					$subGrupos = $arvore->formataSubgruposGrupo($idmenu,$codgrupo,$this->perfil);
					unset($arvore);
					return($subGrupos);
				}
			}
		}
		$conta = 0;
		$subgrupos[] = array();
		foreach($this->xml->GRUPO as $grupo)
		{
			$temp = $this->ixml($grupo,"PERFIL");
			if ($conta == $codgrupo)
			{
				$incluigrupo = TRUE;
				if ($temp != "")
				{
					$incluigrupo = FALSE;
					$perfis = str_replace(","," ",$temp);
					$perfis = explode(" ",$perfis);
					if ($this->array_in_array($this->perfil,$perfis))
					{$incluigrupo = TRUE;}
				}
				//verifica se existem temas no nível de grupo
				if ($incluigrupo == TRUE)
				{
					$subgrupos = array();
					foreach($grupo->SGRUPO as $sgrupo)
					{
						$incluisgrupo = TRUE;
						$temp = $this->ixml($sgrupo,"PERFIL");
						if ($temp != "")
						{
							$incluisgrupo = FALSE;
							$perfis = str_replace(","," ",$temp);
							$perfis = explode(" ",$perfis);
							if ($this->array_in_array($this->perfil,$perfis))
							{$incluisgrupo = TRUE;}
						}
						if (($incluisgrupo == TRUE))
						{
							$down = "sim";
							$ogc = "sim";
							foreach($sgrupo->TEMA as $tema)
							{
								$temp = $this->ixml($tema,"DOWNLOAD");
								if (($temp == "nao") || ($temp == "NAO"))
								{$down = "nao";}
								else
								{$down = "sim";}
								$temp = $this->ixml($tema,"OGC");
								if (($temp == "nao") || ($temp == "NAO"))
								{$ogc = "nao";}
								else
								{$ogc = "sim";}					
							}
							$nome = $this->ixml($sgrupo,"SDTIPO");
							$subgrupos[] = array("nome"=>$nome,"ogc"=>$ogc,"download"=>$down);
						}
					}
				}
				$temas = array();
				foreach($grupo->TEMA as $temar)
				{
					$down = "sim";
					$ogc = "sim";
					$temp = $this->ixml($temar,"DOWNLOAD");
					if (($temp == "nao") || ($temp == "NAO"))
					{$down = "nao";}
					$temp = $this->ixml($temar,"OGC");
					if (($temp == "nao") || ($temp == "NAO"))
					{$ogc = "nao";}
					$link = " ";
					$temp = $this->ixml($temar,"TLINK");
					if ($temp != "")
					{$link = $temp;}
					$tid = $this->ixml($temar,"TID");
					$nome = $this->ixml($temar,"TNOME");
					$temas[] = array("tid"=>$tid,"nome"=>$nome,"link"=>$link,"download"=>$down,"ogc"=>$ogc);
				}
			}
			$conta = $conta + 1;
		}
		return (array("subgrupo"=>$subgrupos,"temasgrupo"=>$temas));
	}
/*
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)
	{
		include_once($this->locaplic."/admin/php/xml.php");
		$tipo = "";
		$this->xml = "";
		foreach($this->pegaListaDeMenus() as $menu)
		{
			if($menu["idmenu"] == $idmenu || $idmenu == "")
			{
				if(!isset($menu["url"])){$menu["url"] = "";} //para efeitos de compatibilidade entre versões do i3geo
				$ondexml = $menu["arquivo"];
				if($menu["url"] != ""){$ondexml = $menu["url"];}
				if($ondexml != "" && $this->menutemas != "")
				{$this->xml = simplexml_load_file($ondexml);}
				else //pega os dados do sistema de administração
				{
					//$this->xml = simplexml_load_string(geraXmlMenutemas(implode(" ",$this->perfil),$idmenu,$tipo,$this->locaplic));	
					include_once("../admin/php/classe_arvore.php");
					$arvore = new Arvore($this->locaplic);
					$temas = $arvore->formataTemasSubgrupo($subgrupo,$this->perfil);
					unset($arvore);
					return($temas);
				}
			}
		}
		$contagrupo = 0;
		$temas = array();
		foreach($this->xml->GRUPO as $g)
		{
			$incluigrupo = TRUE;
			if ($this->ixml($g,"PERFIL") != "")
			{
				$incluigrupo = FALSE;
				$temp = $this->ixml($g,"PERFIL");
				$perfis = str_replace(","," ",$temp);
				$perfis = explode(" ",$perfis);
				if ($this->array_in_array($this->perfil,$perfis))
				{$incluigrupo = TRUE;}
			}
			if ($incluigrupo == TRUE)
			{
				if ($contagrupo == $grupo)
				{
					$contasubgrupo = 0;
					foreach ($g->SGRUPO as $s)
					{
						$incluisgrupo = TRUE;
						if ($this->ixml($s,"PERFIL") != "")
						{
							$incluisgrupo = FALSE;
							$temp = $this->ixml($s,"PERFIL");
							$perfis = str_replace(","," ",$temp);
							$perfis = explode(" ",$perfis);
							if ($this->array_in_array($this->perfil,$perfis))
							{$incluisgrupo = TRUE;}
						}
						if ($incluisgrupo == TRUE)
						{
							if ($contasubgrupo == $subgrupo)
							{
								foreach($s->TEMA as $tema)
								{
									$inclui = TRUE;
									if ($this->ixml($tema,"PERFIL") != "")
									{	
										$inclui = FALSE;
										$temp = $this->ixml($tema,"PERFIL");
										$perfis = str_replace(","," ",$temp);
										$perfis = explode(" ",$perfis);
										if ($this->array_in_array($this->perfil,$perfis))
										{$inclui = TRUE;}
									}
									if ($inclui == TRUE)
									{
										$down = "sim";
										if (($tema->DOWNLOAD == "nao") || ($tema->DOWNLOAD == "NAO"))
										{$down = "nao";}
										$ogc = "sim";
										if (($tema->OGC == "nao") || ($tema->OGC == "NAO"))
										{$ogc = "nao";}
										$link = " ";
										if ($tema->TLINK != "")
										{$link = $this->ixml($tema,"TLINK");}
										$tid = $this->ixml($tema,"TID");
										$nome = $this->ixml($tema,"TNOME");
										$temas[] = array("nacessos"=>($this->ixml($tema,"NACESSOS")),"tid"=>$tid,"nome"=>$nome,"link"=>$link,"download"=>$down,"ogc"=>$ogc,"kmz"=>"nao");
									}
								}
							}
							$contasubgrupo = $contasubgrupo + 1;
						}
					}
				}
				$contagrupo = $contagrupo + 1;
			}
		}
		return ($temas);
	}
/*
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.

Parametros:

locmapas - endereço do arquivo xml.

return:
array
*/
	function pegaListaDeMapas($locmapas)
	{
		//necessário por conta da inclusao do conexao.php
		$locaplic = $this->locaplic;
		$perfilgeral = implode(" ",$this->perfil);
		if($locmapas != "")
		{$this->xml = simplexml_load_file($locmapas);}
		else
		{
			include_once($this->locaplic."/admin/php/xml.php");
			$this->xml = simplexml_load_string(geraXmlMapas(implode(" ",$this->perfil),$this->locaplic,$this->editores));
		}
		$mapas = array();
		//pega os sistemas checando os perfis
		foreach($this->xml->MAPA as $s)
		{
			$ps = $this->ixml($s,"PERFIL");
			$perfis = str_replace(","," ",$ps);
			$perfis = explode(" ",$perfis);
			if (($this->array_in_array($this->perfil,$perfis)) || ($ps == ""))
			{
				$n = $this->ixml($s,"NOME");
				$i = $this->ixml($s,"IMAGEM");
				$t = $this->ixml($s,"TEMAS");
				$l = $this->ixml($s,"LIGADOS");
				$e = $this->ixml($s,"EXTENSAO");
				$o = $this->ixml($s,"OUTROS");
				$k = $this->ixml($s,"LINKDIRETO");
				$p = $this->ixml($s,"PUBLICADO");
				$mapas[] =  array("PUBLICADO"=>$p,"NOME"=>$n,"IMAGEM"=>$i,"TEMAS"=>$t,"LIGADOS"=>$l,"EXTENSAO"=>$e,"OUTROS"=>$o,"LINK"=>$k);
			}
		}
		return (array("mapas"=>$mapas));
	}	
/*
function: pegaSistemas

Retorna a lista de sistemas especiais de adição de temas.

parameters:

Return:

Array
*/
	function pegaSistemas()
	{
		error_reporting(0);
		include_once($this->locaplic."/admin/php/xml.php");
		if ($this->locsistemas != "")
		{$xmlsistemas = simplexml_load_file($this->locsistemas);}
		else
		{$xmlsistemas = simplexml_load_string(geraXmlSistemas(implode(" ",$this->perfil),$this->locaplic,$this->editores));}
		foreach($xmlsistemas->SISTEMA as $s)
		{
			$publicado = $this->ixml($s,"PUBLICADO");
			if(strtolower($publicado) != "nao" || $this->editor)
			{
				$nomesis = $this->ixml($s,"NOMESIS");
				$ps = $this->ixml($s,"PERFIL");
				$perfis = str_replace(","," ",$ps);
				$perfis = explode(" ",$perfis);
				if (($this->array_in_array($this->perfil,$perfis)) || ($ps == ""))
				{
					$funcoes = array();
					foreach($s->FUNCAO as $f)
					{
						$n = $this->ixml($f,"NOMEFUNCAO");
						$a = $this->ixml($f,"ABRIR");
						$w = $this->ixml($f,"JANELAW");
						$h = $this->ixml($f,"JANELAH");
						$p = $this->ixml($f,"PERFIL");
						if (($this->array_in_array($this->perfil,$perfis)) || ($p == ""))
						{$funcoes[] = array("NOME"=>$n,"ABRIR"=>$a,"W"=>$w,"H"=>$h);}
					}
					$sistemas[] =  array("PUBLICADO"=>$publicado,"NOME"=>$nomesis,"FUNCOES"=>$funcoes);
				}
			}
		}
		return $sistemas;		
	}

/*
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)
	{
		include_once($this->locaplic."/admin/php/xml.php");
		$tipo = "";
		$this->xml = "";
		if($this->menutemas != "")
		{
			foreach($this->pegaListaDeMenus() as $menu)
			{
				if(!isset($menu["url"])){$menu["url"] = "";} //para efeitos de compatibilidade entre versões do i3geo
				$ondexml = $menu["arquivo"];
				if($menu["url"] != ""){$ondexml = $menu["url"];}
				$this->xml[] = simplexml_load_file($ondexml);
			}
		}
		else
		{
				//$this->xml[] = simplexml_load_string(geraXmlMenutemas(implode(" ",$this->perfil),$menu["idmenu"],$tipo,$this->locaplic));	
				include_once("../admin/php/classe_arvore.php");
				$arvore = new Arvore($this->locaplic);
				$temas = $arvore->procuraTemas($procurar,$this->perfil);
				unset($arvore);
				return($temas);
		}
		$resultado = array();
		$texto = array();
		foreach ($this->xml as $xml)
		{
			$listadetemas = array();
			$subgrupo = array();
			foreach($xml->GRUPO as $grupo)
			{
				$incluigrupo = TRUE;
				$temp = $this->ixml($grupo,"PERFIL");
				if ($temp != "")
				{
					$incluigrupo = FALSE;
					$perfis = str_replace(","," ",$temp);
					$perfis = explode(" ",$perfis);
					if ($this->array_in_array($this->perfil,$perfis))
					{$incluigrupo = TRUE;}
				}
				if ($incluigrupo == TRUE)
				{
					foreach($grupo->SGRUPO as $sgrupo)
					{
						$incluisgrupo = TRUE;
						if ($this->perfil != "")
						{
							$temp = $this->ixml($sgrupo,"PERFIL");
							$perfis = str_replace(","," ",$temp);
							$perfis = explode(" ",$perfis);
							if (!$this->array_in_array($this->perfil,$perfis))
							{$incluisgrupo = FALSE;}
						}
						if ($incluisgrupo == TRUE)
						{
							foreach($sgrupo->TEMA as $tema)
							{
								$inclui = TRUE;
								if ($this->perfil != "")
								{
									$temp = $this->ixml($tema,"PERFIL");
									$perfis = str_replace(","," ",$temp);
									$perfis = explode(" ",$perfis);
									if (!$this->array_in_array($this->perfil,$perfis))
									{$inclui = FALSE;}
								}
								if ($inclui == TRUE)
								{
									$down = "nao";
									$temp = $this->ixml($tema,"DOWNLOAD");
									if (($temp == "sim") || ($temp == "SIM"))
									{$down = "sim";}
									$link = $this->ixml($tema,"TLINK");
									$tid = $this->ixml($tema,"TID");
									
									if(!isset($texto[$tid]))
									{
										$texto[$tid] = array("tid"=>$tid,"nome"=>($this->ixml($tema,"TNOME")),"link"=>$link,"download"=>$down);
										$p1 = $this->removeAcentos($procurar);
										$p1 = $this->removeAcentos(htmlentities($p1));
										$pp1 = $this->removeAcentos($this->ixml($tema,"TNOME"));
										$pp1 = $this->removeAcentos($pp1);
										$pp1 = $this->removeAcentos(htmlentities($pp1));
										if (stristr($pp1,$p1) || stristr($this->ixml($tema,"TNOME"),htmlentities($procurar)))
										{
											$listadetemas[] = $texto[$tid];
										}
										else
										if($this->ixml($tema,"TAGS") != "")
										{
											$pp1 = $this->ixml($tema,"TAGS");
											$pp1 = $this->removeAcentos($pp1);
											if (stristr($pp1,$p1))
											{$listadetemas[] = $texto[$tid];}	
										}
									}
								}
							}
							if (count($listadetemas) > 0)
							{
								$subgrupo[] = array("subgrupo"=>($this->ixml($sgrupo,"SDTIPO")),"temas"=>$listadetemas);
							}
							$listadetemas = array();
						}
						
					}
					if (count($subgrupo) > 0)
					{
						$resultado[] = array("grupo"=>($this->ixml($grupo,"GTIPO")),"subgrupos"=>$subgrupo);
					}
					$subgrupo = array();
				}
			}
		}
		return ($resultado);
	}
/*
function: listaTags

Lista os tags registrados nos menus de temas.

Parametros:

rss - (opcional) endereço de um RSS para cruzar com as tags.

nrss - (opcional) número de registros no rss que serão considerados

*/
	function listaTags($rss="",$nrss="")
	{
		include_once($this->locaplic."/admin/php/xml.php");
		$tipo = "";
		//carrega os títulos e links do rss especificado
		$noticiasRSS = array(); //guarda as notícias originais do RRS
		if($rss != "")
		{
			$conta = 0;
			foreach ( simplexml_load_file($rss)->channel->item as $item )
			{
				if($conta < $nrss)
				$noticiasRSS[] = array("desc"=>($this->ixml($item,"description")),"titulo"=>($this->ixml($item,"title")),"link"=>($this->ixml($item,"link")));
				$conta++;
			}	
		}
		$this->xml = array();
		foreach($this->pegaListaDeMenus() as $menu)
		{
			if(!isset($menu["url"])){$menu["url"] = "";} //para efeitos de compatibilidade entre versões do i3geo
			$ondexml = $menu["arquivo"];
			if($menu["url"] != ""){$ondexml = $menu["url"];}
			if($ondexml != "")
			{$this->xml[] = simplexml_load_file($ondexml);}
			else //pega o xml do sistema de administração
			{
				$this->xml[] = simplexml_load_string(geraXmlMenutemas(implode(" ",$this->perfil),$menu["idmenu"],$tipo,$this->locaplic));	
			}
		}

		$resultado = array();
		$noticias = array();
		foreach ($this->xml as $xml)
		{
			foreach($xml->GRUPO as $grupo)
			{
				$incluigrupo = TRUE;
				$temp = $this->ixml($grupo,"PERFIL");
				if ($temp != "")
				{
					$incluigrupo = FALSE;
					$perfis = explode(",",$temp);
					if ($this->array_in_array($this->perfil,$perfis))
					{$incluigrupo = TRUE;}
				}
				if ($incluigrupo == TRUE)
				{
					foreach($grupo->SGRUPO as $sgrupo)
					{
						$incluisgrupo = TRUE;
						if ($this->perfil != "")
						{
							$temp = $this->ixml($sgrupo,"PERFIL");
							$perfis = str_replace(","," ",$temp);
							$perfis = explode(" ",$perfis);
							if (!$this->array_in_array($this->perfil,$perfis))
							{$incluisgrupo = FALSE;}
						}
						if ($incluisgrupo == TRUE)
						{
							foreach($sgrupo->TEMA as $tema)
							{
								$inclui = TRUE;
								if ($this->perfil != "")
								{
									$perfis = str_replace(","," ",$temp);
									$perfis = explode(" ",$perfis);
									if (!$this->array_in_array($this->perfil,$perfis))
									{$inclui = FALSE;}
								}
								if ($inclui == TRUE)
								{
									$tid = $this->ixml($tema,"TID");
									$tags = explode(" ",$this->ixml($tema,"TAGS"));
									foreach ($tags as $tag)
									{
										if($tag != "")
										{
											if(!isset($resultado[$tag]))
											{
												$resultado[$tag] = array($tid);
												//busca noticias
												if(count($noticiasRSS) > 0)
												{
													foreach($noticiasRSS as $noticia)
													{
														$titulo = explode(" ",strtolower($this->removeAcentos($noticia["desc"])));
														$t = $this->removeAcentos($tag);
														if(in_array(strtolower($t),$titulo))
														{
															//echo $noticia["link"]."<br>";
															if(!isset($noticias[$tag]))
															$noticias[$tag] = array("titulo"=>$noticia["titulo"],"link"=>$noticia["link"]);
															else
															$noticias[$tag] = array_merge($noticias[$tag],array("titulo"=>$noticia["titulo"],"link"=>$noticia["link"]));
														}
													}	
												}
											}
											else
											{
												$resultado[$tag] = array_merge($resultado[$tag],array($tid));
											}
										}
									}
								}
							}
						}
					}
				}
			}
		}
		ksort($resultado);
		foreach(array_keys($resultado) as $k)
		{
			
			if(isset($noticias[$k]))
			{$not = array($noticias[$k]);}
			else
			{$not = array();}
			$final[] = array("tag"=>$k,"temas"=>$resultado[$k],"noticias"=>$not);
		}
		return ($final);
	}
	
	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);
		//$str = htmlentities($s);
		$str = preg_replace("/(&)([a-z])([a-z]+;)/i", '$2', $s);
		$str = preg_replace("/[^A-Z0-9]/i", ' ', $str);
		$str = preg_replace("/\s+/i", ' ', $str);
		return $str;
	}
	/*
	Function: array_in_array

	Procura ocorrências de um array em outro array
	*/
	function array_in_array($needle, $haystack)
	{
    	//Make sure $needle is an array for foreach
    	if(!is_array($needle)) $needle = array($needle);
    	//For each value in $needle, return TRUE if in $haystack
    	foreach($needle as $pin)
        	if(in_array($pin, $haystack)) return TRUE;
    	//Return FALSE if none of the values from $needle are found in $haystack
    	return FALSE;
	}
	function verificaEditores($editores)
	{
		$editor = false;
		foreach ($editores as $e)
		{
			$e = gethostbyname($e);
			$ip = "UNKNOWN";
			if (getenv("HTTP_CLIENT_IP")) $ip = getenv("HTTP_CLIENT_IP");
			else if(getenv("HTTP_X_FORWARDED_FOR")) $ip = getenv("HTTP_X_FORWARDED_FOR");
			else if(getenv("REMOTE_ADDR")) $ip = getenv("REMOTE_ADDR");
			else $ip = "UNKNOWN";
			if ($e == $ip){$editor=true;}
		}
		return $editor;
	}
	function ixml($no,$nome)
	{
		return mb_convert_encoding($no->$nome,"HTML-ENTITIES","auto");
	}

}
?>