xml.php 13.5 KB
<?php
function geraXmlSistemas($perfil,$locaplic)
{
	if (!isset($perfil)){$perfil = "";}
	$perfil = str_replace(","," ",$perfil);
	$perfil = explode(" ",$perfil);
	$dbh = "";
	include($locaplic."/admin/php/conexao.php");
	$xml = "<"."\x3F"."xml version='1.0' encoding='UTF-8' "."\x3F".">";
	$xml .= "\n<SISTEMAS>\n";
	$q = "select * from i3geoadmin_sistemas";
	$qatlas = $dbh->query($q);
	foreach($qatlas as $row)
	{
		if($row["perfil_sistema"] == "")
		$mostra = true;
		else
		{
			$perfilS = explode(" ",str_replace(","," ",$row["perfil_sistema"]));
			$mostra = array_in_array($perfil,$perfilS);
		}
		if($mostra)
		{
			$xml .= "<SISTEMA>\n";
			$xml .= " <PERFIL>".$row["perfil_sistema"]."</PERFIL>\n";
			$xml .= " <NOMESIS>".xmlTexto_prepara($row["nome_sistema"])."</NOMESIS>\n";
			geraXmlSistemas_pegafuncoes($perfil,&$xml,$row["id_sistema"],$dbh);
			$xml .= "</SISTEMA>\n";
		}
	}
	$xml .= "</SISTEMAS>\n";
	$dbh = null;
	$dbhw = null;
	return $xml;	
}

function geraXmlDownload($locaplic)
{
	$sql = "select * from i3geoadmin_ws where tipo_ws = 'DOWNLOAD' and nome_ws <> ''";
	return geraXmlRSS($locaplic,$sql);
}
function geraXmlWS($locaplic)
{
	$sql = "select * from i3geoadmin_ws where tipo_ws = 'WS' and nome_ws <> ''";
	return geraXmlRSS($locaplic,$sql);
}
function geraXmlWMS($locaplic)
{
	$sql = "select * from i3geoadmin_ws where tipo_ws = 'WMS' and nome_ws <> ''";
	return geraXmlRSS($locaplic,$sql);
}
function geraXmlGeorss($locaplic)
{
	$sql = "select * from i3geoadmin_ws where tipo_ws = 'GEORSS' and nome_ws <> ''";
	return geraXmlRSS($locaplic,$sql);
}
function geraXmlRSS($locaplic,$sql)
{
	$dbh = "";
	include($locaplic."/admin/php/conexao.php");
	$xml = "<"."\x3F"."xml version='1.0' encoding='ISO-8859-1' "."\x3F".">";
	$xml .= "<rss version='2.0'>";
	$xml .= "<channel>\n";
	$xml .= "<title>Geo RSS</title>\n";
	$xml .= "<description>Links para enderecos Geo RSS gerados pelo i3geo</description>\n";
	$xml .= "<link></link>\n";
	$xml .= "<docs></docs>\n";
	$xml .= "<copyright></copyright>\n";
	$xml .= "<language>pt-br</language>\n";
	$xml .= "<webmaster></webmaster>\n";

	//$q = "select * from i3geoadmin_ws where tipo_ws = 'GEORSS' and nome_ws <> ''";
	$qatlas = $dbh->query($sql);
	foreach($qatlas as $row)
	{
		$xml .= "<item>\n";
		$xml .= "<category/>\n";
		$xml .= "<title>".xmlTexto_prepara($row["nome_ws"])."</title>\n";
		$xml .= "<description>".xmlTexto_prepara($row["desc_ws"])."</description>\n";
		$xml .= "<link>".xmlTexto_prepara($row["link_ws"])."</link>\n";
		$xml .= "<pubDate/>\n";
		$xml .= "<author>".xmlTexto_prepara($row["autor_ws"])."</author>\n";
		$xml .= "</item>\n";
	}
	$xml .= "</channel></rss>\n";
	$dbh = null;
	$dbhw = null;
	return $xml;
}
function geraXmlAtlas($locaplic)
{
	$dbh = "";
	include($locaplic."/admin/php/conexao.php");
	$xml = "<"."\x3F"."xml version='1.0' encoding='UTF-8' "."\x3F".">";
	$xml .= "\n<RAIZ>\n";
	$q = "select * from i3geoadmin_atlas";
	$qatlas = $dbh->query($q);
	foreach($qatlas as $row)
	{
		$xml .= "<ATLAS>\n";
		$xml .= " <ID>".$row["id_atlas"]."</ID>\n";
		$xml .= " <TITULO>".xmlTexto_prepara($row["titulo_atlas"])."</TITULO>\n";
		$xml .= " <DESCRICAO>".xmlTexto_prepara($row["desc_atlas"])."</DESCRICAO>\n";
		$xml .= " <ICONE>".$row["icone_atlas"]."</ICONE>\n";
		$xml .= " <LINKMAISINFO>".xmlTexto_prepara($row["link_atlas"])."</LINKMAISINFO>\n";
		$xml .= " <TEMPLATEHTML>".xmlTexto_prepara($row["template_atlas"])."</TEMPLATEHTML>\n";
		$xml .= " <WABERTURA>".$row["w_atlas"]."</WABERTURA>\n";
		$xml .= " <HABERTURA>".$row["h_atlas"]."</HABERTURA>\n";
		$xml .= " <PRANCHADEFAULT>".$row["pranchadefault_atlas"]."</PRANCHADEFAULT>\n";
		$xml .= " <TIPOGUIAS>".$row["tipoguias_atlas"]."</TIPOGUIAS>\n";
		$xml .= " <BASEMAPFILE>".$row["basemapfile_atlas"]."</BASEMAPFILE>\n";
		$xml .= " <PRANCHAS>\n";
		geraXmlAtlas_pegapranchas(&$xml,$row["id_atlas"],$dbh);
		$xml .= " </PRANCHAS>\n";
		$xml .= " </ATLAS>\n";
	}
	$xml .= "</RAIZ>\n";
	$dbh = null;
	$dbhw = null;
	return $xml;	
}
function geraXmlIdentifica($perfil,$locaplic)
{
	if (!isset($perfil)){$perfil = "";}
	$perfil = str_replace(","," ",$perfil);
	$perfil = explode(" ",$perfil);
	$dbh = "";
	include($locaplic."/admin/php/conexao.php");
	$xml = "<"."\x3F"."xml version='1.0' encoding='UTF-8' "."\x3F".">";
	$xml .= "\n<SISTEMAS>\n";
	$q = "select * from i3geoadmin_identifica ";
	$qi = $dbh->query($q);
	foreach($qi as $row)
	{
		$xml .= " <FUNCAO>\n";
		$xml .= "  <NOMESIS>".xmlTexto_prepara($row["nome_i"])."</NOMESIS>\n";
		$xml .= "  <ABRIR>".xmlTexto_prepara($row["abrir_i"])."</ABRIR>\n";
		$target = $row["target_i"];
		if($target == ""){$target = "_self";}
		$xml .= "  <TARGET>".$target."</TARGET>\n";
		$xml .= " </FUNCAO>\n";
	}
	$xml .= "</SISTEMAS>\n";
	$dbh = null;
	$dbhw = null;
	return $xml;	
}
function geraXmlMapas($perfil,$locaplic)
{
	if (!isset($perfil)){$perfil = "";}
	$perfil = str_replace(","," ",$perfil);
	$perfil = explode(" ",$perfil);
	$dbh = "";
	include($locaplic."/admin/php/conexao.php");
	$xml = "<"."\x3F"."xml version='1.0' encoding='UTF-8' "."\x3F".">";
	$xml .= "\n<MAPAS>\n";
	$q = "select * from i3geoadmin_mapas";
	$q = $dbh->query($q);
	foreach($q as $row)
	{
		if($row["perfil_mapa"] == "")
		$mostraMapa = true;
		else
		{
			$perfilMapa = explode(" ",str_replace(","," ",$row["perfil_mapa"]));
			$mostraMapa = array_in_array($perfil,$perfilMapa);
		}
		if($mostraMapa)
		{	
			$xml .= "<MAPA>\n";
			$xml .= " <PERFIL>".$row["perfil_mapa"]."</PERFIL>\n";
			$xml .= " <NOME>".xmlTexto_prepara($row["nome_mapa"])."</NOME>\n";
			$xml .= " <DESCRICAO>".xmlTexto_prepara($row["desc_mapa"])."</DESCRICAO>\n";
			$xml .= " <IMAGEM>".xmlTexto_prepara($row["imagem_mapa"])."</IMAGEM>\n";
			$xml .= " <TEMAS>".$row["temas_mapa"]."</TEMAS>\n";
			$xml .= " <LIGADOS>".$row["ligados_mapa"]."</LIGADOS>\n";
			$xml .= " <EXTENSAO>".$row["ext_mapa"]."</EXTENSAO>\n";
			$xml .= " <OUTROS>".xmlTexto_prepara($row["outros_mapa"])."</OUTROS>\n";
			$xml .= " <LINKDIRETO>".xmlTexto_prepara($row["linkdireto_mapa"])."</LINKDIRETO>\n";
			$xml .= " </MAPA>\n";
		}
	}
	$xml .= "</MAPAS>\n";
	$dbh = null;
	$dbhw = null;
	return $xml;
}
//
//$id_menu = id do menu que será montado
//$perfil = perfis separados por espaços
//$tipo = gruposeraiz|subgrupos|temas
//$dbh objeto com a conexão com o banco
//$locaplic = localização do i3geo no servidor
//
function geraXmlMenutemas($perfil,$id_menu,$tipo,$locaplic)
{
	$dbh = "";
	include($locaplic."/admin/php/conexao.php");
	if (!isset($perfil)){$perfil = "";}
	$perfil = str_replace(","," ",$perfil);
	$perfil = explode(" ",$perfil);
	$xml = "<"."\x3F"."xml version='1.0' encoding='UTF-8' "."\x3F".">";
	$xml .= "\n<TEMASGEO>\n";
	if(!isset($id_menu))
	$xml .= "<CABECALHO>Utilize ?id_menu=1 por exemplo</CABECALHO>\n";
	else
	$xml .= "<CABECALHO></CABECALHO>\n";
	//
	//pega os temas na raiz
	//
	$q = "select nome_tema,codigo_tema,desc_tema,link_tema,tipoa_tema,tags_tema,kml_tema,ogc_tema,download_tema,r.perfil as perfil from i3geoadmin_raiz as r,i3geoadmin_temas as temas where r.id_nivel = 0 and r.id_tema = temas.id_tema and r.id_menu = $id_menu ";
	$qtemasraiz = $dbh->query($q);
	geraXmlMenutemas_notema($qtemasraiz,&$xml,$perfil);
	$q = "select nome_grupo,desc_grupo,n1.id_grupo,n1.id_n1,n1.n1_perfil as perfil from i3geoadmin_n1 as n1,i3geoadmin_grupos as grupos where n1.id_menu = $id_menu and n1.id_grupo = grupos.id_grupo ";
	$qgrupos = $dbh->query($q);
	foreach($qgrupos as $row)
	{
		if($row["perfil"] == "")
		$mostra = true;
		else
		{
			$perfilatual = explode(" ",str_replace(","," ",$row["perfil"]));
			$mostra = array_in_array($perfil,$perfilatual);
		}
		if($mostra)
		{
			$xml .= "<GRUPO>\n";
			$xml .= " <GTIPO>".xmlTexto_prepara($row["nome_grupo"])."</GTIPO>\n";
			//
			//pega temas na raiz
			//
			$q = "select nome_tema,codigo_tema,desc_tema,link_tema,tipoa_tema,tags_tema,kml_tema,ogc_tema,download_tema,r.perfil as perfil from i3geoadmin_raiz as r,i3geoadmin_temas as temas where r.nivel = 1 and r.id_nivel = ".$row["id_n1"]." and r.id_tema = temas.id_tema and r.id_menu = $id_menu ";
			$qtemasraiz = $dbh->query($q);
			geraXmlMenutemas_notema($qtemasraiz,&$xml,$perfil);
			if(isset($tipo) && ($tipo == "subgrupos") || ($tipo == ""))
			geraXmlMenutemas_pegasubgrupos($row["id_n1"],&$xml,$dbh,$tipo,$perfil);
			$xml .= " <DTIPO>".xmlTexto_prepara($row["desc_grupo"])."</DTIPO>\n";
			$xml .= " <PERFIL>".$row["perfil"]."</PERFIL>\n";
			$xml .= "</GRUPO>\n";
		}
	}
	$xml .= "</TEMASGEO>\n";
	$dbh = null;
	$dbhw = null;
	return $xml;
}
function geraXmlMenutemas_pegasubgrupos($id_n1,$xml,$dbh,$tipo,$perfil)
{
	$q = "select subgrupos.id_subgrupo,nome_subgrupo,id_n2,n2.n2_perfil as perfil from i3geoadmin_n2 as n2,i3geoadmin_subgrupos as subgrupos where n2.id_n2 = $id_n1 and n2.id_subgrupo = subgrupos.id_subgrupo ";
	$qsgrupos = $dbh->query($q);
	foreach($qsgrupos as $row)
	{
		if($row["perfil"] == "")
		$mostra = true;
		else
		{
			$perfilatual = explode(" ",str_replace(","," ",$row["perfil"]));
			$mostra = array_in_array($perfil,$perfilatual);
		}
		if($mostra)
		{
			$xml .= "<SGRUPO>\n";
			$xml .= "<SDTIPO>".xmlTexto_prepara($row["nome_subgrupo"])."</SDTIPO>\n";
			$xml .= "<PERFIL>".xmlTexto_prepara($row["perfil"])."</PERFIL>\n";
			if(isset($tipo) && ($tipo == "temas") || ($tipo == ""))
			geraXmlMenutemas_pegatemas($row["id_n2"],&$xml,$dbh,$perfil);
			$xml .= "</SGRUPO>\n";
		}
	}
}
function geraXmlMenutemas_pegatemas($id_n2,$xml,$dbh,$perfil)
{
	$q = "select nome_tema,codigo_tema,desc_tema,link_tema,tipoa_tema,tags_tema,kml_tema,ogc_tema,download_tema,n3.n3_perfil as perfil from i3geoadmin_n3 as n3,i3geoadmin_temas as temas where n3.id_n2 = $id_n2 and n3.id_tema = temas.id_tema ";
	$qtemas = $dbh->query($q);
	geraXmlMenutemas_notema($qtemas,&$xml,$perfil);
}
function geraXmlMenutemas_notema($qtemas,$xml,$perfil)
{
	foreach($qtemas as $row)
	{
		if($row["perfil"] == "")
		$mostra = true;
		else
		{
			$perfilatual = explode(" ",str_replace(","," ",$row["perfil"]));
			$mostra = array_in_array($perfil,$perfilatual);
		}
		if($mostra)
		{
			$xml .= "<TEMA>\n";
			$xml .= "<TID>".$row["codigo_tema"]."</TID>\n";
			$xml .= "<PERFIL>".$row["perfil"]."</PERFIL>\n";
			$xml .= "<TNOME>".xmlTexto_prepara($row["nome_tema"])."</TNOME>\n";
			$xml .= "<TDESC>".xmlTexto_prepara($row["desc_tema"])."</TDESC>\n";
			$xml .= "<TLINK>".xmlTexto_prepara($row["link_tema"])."</TLINK>\n";
			$xml .= "<TIPOA>".$row["tipoa_tema"]."</TIPOA>\n";
			$xml .= "<TAGS>".xmlTexto_prepara($row["tags_tema"])."</TAGS>\n";
			$xml .= "<KML>".$row["kml_tema"]."</KML>\n";
			if($row["tipoa_tema"] == "WMS")
			$xml .= "<OGC>nao</OGC>\n";
			else
			$xml .= "<OGC>".$row["ogc_tema"]."</OGC>\n";
			$xml .= "<DOWNLOAD>".$row["download_tema"]."</DOWNLOAD>\n";
			$xml .= "</TEMA>\n";
		}
	}
}
function geraXmlAtlas_pegapranchas($xml,$id_atlas,$dbh)
{
	$q = "select * from i3geoadmin_atlasp as p where p.id_atlas = $id_atlas ";
	$qpranchas = $dbh->query($q);
	foreach($qpranchas as $row)
	{
		$xml .= "  <PRANCHA>\n";
		$xml .= "   <ID>".$row["id_prancha"]."</ID>\n";
		$xml .= "   <TITULO>".xmlTexto_prepara($row["titulo_prancha"])."</TITULO>\n";
		$xml .= "   <DESCRICAO>".xmlTexto_prepara($row["desc_prancha"])."</DESCRICAO>\n";
		$xml .= "   <ICONE>".$row["icone_prancha"]."</ICONE>\n";
		$xml .= "   <LINKMAISINFO>".xmlTexto_prepara($row["link_prancha"])."</LINKMAISINFO>\n";
		$xml .= "   <WABERTURA>".$row["w_prancha"]."</WABERTURA>\n";
		$xml .= "   <HABERTURA>".$row["h_prancha"]."</HABERTURA>\n";
		$xml .= "   <MAPEXT>".$row["mapext_prancha"]."</MAPEXT>\n";
		$xml .= "   <TEMAS>\n";
		geraXmlAtlas_pegatemas(&$xml,$row["id_prancha"],$dbh);
		$xml .= "   </TEMAS>\n";
		$xml .= "  </PRANCHA>\n";
	}	
}
function geraXmlAtlas_pegatemas($xml,$id_prancha,$dbh)
{
	$q = "select tema.codigo_tema,t.ligado_tema from i3geoadmin_atlast as t,i3geoadmin_temas as tema where tema.id_tema = t.id_tema and t.id_prancha = $id_prancha ";
	$qtemas = $dbh->query($q);
	foreach($qtemas as $row)
	{
		$xml .= "<TEMA>\n";
		$xml .= "<CODIGO>".$row["codigo_tema"]."</CODIGO>\n";
		$xml .= "<LIGADO>".$row["ligado_tema"]."</LIGADO>\n";
		$xml .= "</TEMA>\n";
	}
	
}
function geraXmlSistemas_pegafuncoes($perfil,&$xml,$id_sistema,$dbh)
{
	$q = "select * from i3geoadmin_sistemasf where id_sistema = '$id_sistema'";
	$qtemas = $dbh->query($q);
	foreach($qtemas as $row)
	{
		if($row["perfil_funcao"] == "")
		$mostra = true;
		else
		{
			$perfilF = explode(" ",str_replace(","," ",$row["perfil_funcao"]));
			$mostra = array_in_array($perfil,$perfilF);
		}
		if($mostra)
		{
			$xml .= "<FUNCAO>\n";
			$xml .= " <NOMEFUNCAO>".xmlTexto_prepara($row["nome_funcao"])."</NOMEFUNCAO>\n";
			$xml .= " <ABRIR>".$row["abrir_funcao"]."</ABRIR>\n";
			$xml .= " <JANELAW>".$row["w_funcao"]."</JANELAW>\n";
			$xml .= " <JANELAH>".$row["h_funcao"]."</JANELAH>\n";
			$xml .= " <PERFIL>".$row["perfil_funcao"]."</PERFIL>\n";
			$xml .= "</FUNCAO>\n";
		}
	}
	
}
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 xmlTexto_prepara($texto)
{
	return str_replace("&","&amp;",$texto);	
}
?>