";
else
$xml = "<"."\x3F"."xml version='1.0' encoding='ISO-8859-1' "."\x3F".">";
$xml .= "\n\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(strtolower($row["publicado_sistema"] == "nao"))
{$mostra = false;}
if($editor)
{$mostra = true;}
if($mostra)
{
$xml .= "\n";
$xml .= " ".$row["perfil_sistema"]."\n";
$xml .= " ".$row["publicado_sistema"]."\n";
$xml .= " ".xmlTexto_prepara($row["nome_sistema"])."\n";
geraXmlSistemas_pegafuncoes($perfil,&$xml,$row["id_sistema"],$dbh);
$xml .= "\n";
}
}
$xml .= "\n";
$dbh = null;
$dbhw = null;
return $xml;
}
function geraRSStemas($locaplic,$id_n2)
{
$sql = "select t.nome_tema as nome_ws,'' as desc_ws,'php/parsemapfile.php?id='||t.codigo_tema as link_ws,t.link_tema as autor_ws from i3geoadmin_n3 as n3,i3geoadmin_temas as t where t.id_tema = n3.id_tema and n3.id_n2 = '$id_n2' and n3.n3_perfil = '' order by nome_ws";
return geraXmlRSS($locaplic,$sql,"Lista de temas");
}
function geraRSSsubgrupos($locaplic,$id_n1)
{
$sql = "select g.nome_subgrupo as nome_ws,'' as desc_ws,'rsstemas.php?id='||n2.id_n2 as link_ws,'' as autor_ws from i3geoadmin_n2 as n2,i3geoadmin_subgrupos as g where g.id_subgrupo = n2.id_subgrupo and n2.id_n1 = '$id_n1' and n2.n2_perfil = '' order by nome_ws";
return geraXmlRSS($locaplic,$sql,"Lista de sub-grupos");
}
function geraRSSgrupos($locaplic)
{
//$sql = "select g.nome_grupo as nome_ws,'' as desc_ws,'rsssubgrupos.php?id='||n1.id_n1 as link_ws,'' as autor_ws from i3geoadmin_n1 as n1,i3geoadmin_grupos as g where g.id_grupo = n1.id_grupo and n1.n1_perfil = '' order by nome_ws";
$sql = "select g.nome_grupo as nome_ws,'' as desc_ws,'rsssubgrupos.php?id='||n1.id_n1 as link_ws,'' as autor_ws ";
$sql .= "from i3geoadmin_n1 as n1,i3geoadmin_grupos as g, i3geoadmin_n2 as n2, i3geoadmin_n3 as n3 ";
$sql .= "where g.id_grupo = n1.id_grupo and n2.id_n1 = n1.id_n1 and n3.id_n2 = n2.id_n2 and n1.n1_perfil = '' group by nome_ws,desc_ws,link_ws,autor_ws order by nome_ws";
return geraXmlRSS($locaplic,$sql,"Lista de grupos");
}
function geraXmlDownload($locaplic)
{
$sql = "select * from i3geoadmin_ws where tipo_ws = 'DOWNLOAD' and nome_ws <> ''";
return geraXmlRSS($locaplic,$sql,"Enderecos para download");
}
function geraXmlWS($locaplic)
{
$sql = "select * from i3geoadmin_ws where tipo_ws = 'WS' and nome_ws <> ''";
return geraXmlRSS($locaplic,$sql,"Web services");
}
function geraXmlKmlrss($locaplic)
{
$sql = "select * from i3geoadmin_ws where tipo_ws = 'KML' and nome_ws <> ''";
return geraXmlRSS($locaplic,$sql,"Web services");
}
function geraXmlWMS($locaplic)
{
$sql = "select * from i3geoadmin_ws where tipo_ws = 'WMS' and nome_ws <> '' order by nome_ws";
return geraXmlRSS($locaplic,$sql,"Web services WMS-OGC");
}
function geraXmlGeorss($locaplic)
{
$sql = "select * from i3geoadmin_ws where tipo_ws = 'GEORSS' and nome_ws <> ''";
return geraXmlRSS($locaplic,$sql,"Georss");
}
function geraRSStemasDownload($locaplic)
{
$protocolo = explode("/",$_SERVER['SERVER_PROTOCOL']);
$url = strtolower($protocolo[0])."://".$_SERVER['HTTP_HOST'].(str_replace("/admin/rsstemasdownload.php","",$_SERVER['PHP_SELF']));
$sql = "select '".$url."/datadownload.htm?'||codigo_tema as link_ws, g.nome_grupo||' -> '||sg.nome_subgrupo||' -> '||nome_tema as nome_ws, desc_tema as desc_ws, link_tema as autor_ws ";
$sql .= "
from i3geoadmin_temas as t,i3geoadmin_n3 as n3, i3geoadmin_n2 as n2, i3geoadmin_n1 as n1, i3geoadmin_grupos as g, i3geoadmin_subgrupos as sg
where
t.id_tema = n3.id_tema
and n3.id_n2 = n2.id_n2
and n2.id_subgrupo = sg.id_subgrupo
and n2.id_n1 = n1.id_n1
and n1.id_grupo = g.id_grupo
and (t.download_tema = 'sim' or t.download_tema = 'SIM')
and n3.n3_perfil = ''
and n2.n2_perfil = ''
and n1.n1_perfil = ''
";
//echo $sql;exit;
return geraXmlRSS($locaplic,$sql,"Temas para download");
}
function geraRSStemasKml($locaplic)
{
$protocolo = explode("/",$_SERVER['SERVER_PROTOCOL']);
$url = strtolower($protocolo[0])."://".$_SERVER['HTTP_HOST'].(str_replace("/admin/rsstemasdownload.php","",$_SERVER['PHP_SELF']));
$sql = "select '".$url."/pacotes/kmlmapserver/kmlservice.php?request=kml&map='||codigo_tema||'&typename='||codigo_tema as link_ws, g.nome_grupo||' -> '||sg.nome_subgrupo||' -> '||nome_tema as nome_ws, desc_tema as desc_ws, link_tema as autor_ws ";
$sql .= "
from i3geoadmin_temas as t,i3geoadmin_n3 as n3, i3geoadmin_n2 as n2, i3geoadmin_n1 as n1, i3geoadmin_grupos as g, i3geoadmin_subgrupos as sg
where
t.id_tema = n3.id_tema
and n3.id_n2 = n2.id_n2
and n2.id_subgrupo = sg.id_subgrupo
and n2.id_n1 = n1.id_n1
and n1.id_grupo = g.id_grupo
and (t.kml_tema = 'sim' or t.kml_tema = 'SIM')
and n3.n3_perfil = ''
and n2.n2_perfil = ''
and n1.n1_perfil = ''
";
//echo $sql;exit;
return geraXmlRSS($locaplic,$sql,"Temas em KML");
}
function geraRSStemasOgc($locaplic)
{
$protocolo = explode("/",$_SERVER['SERVER_PROTOCOL']);
$url = strtolower($protocolo[0])."://".$_SERVER['HTTP_HOST'].(str_replace("/admin/rsstemasdownload.php","",$_SERVER['PHP_SELF']));
$sql = "select '".$url."/ogc.php?request=getcapabilities&service=wms&tema='||codigo_tema as link_ws, g.nome_grupo||' -> '||sg.nome_subgrupo||' -> '||nome_tema as nome_ws, desc_tema as desc_ws, link_tema as autor_ws ";
$sql .= "
from i3geoadmin_temas as t,i3geoadmin_n3 as n3, i3geoadmin_n2 as n2, i3geoadmin_n1 as n1, i3geoadmin_grupos as g, i3geoadmin_subgrupos as sg
where
t.id_tema = n3.id_tema
and n3.id_n2 = n2.id_n2
and n2.id_subgrupo = sg.id_subgrupo
and n2.id_n1 = n1.id_n1
and n1.id_grupo = g.id_grupo
and (t.ogc_tema != 'nao' or t.ogc_tema != 'NAO')
and n3.n3_perfil = ''
and n2.n2_perfil = ''
and n1.n1_perfil = ''
";
//echo $sql;exit;
return geraXmlRSS($locaplic,$sql,"Temas em KML");
}
function geraXmlRSS($locaplic,$sql,$descricao)
{
$dbh = "";
include($locaplic."/admin/php/conexao.php");
if($convUTF)
$xml = "<"."\x3F"."xml version='1.0' encoding='UTF-8' "."\x3F".">";
else
$xml = "<"."\x3F"."xml version='1.0' encoding='ISO-8859-1' "."\x3F".">";
$xml .= "";
$xml .= "\n";
$xml .= "RSS\n";
$xml .= "$descricao\n";
$xml .= "\n";
$xml .= "\n";
$xml .= "Gerado pelo i3Geo\n";
$xml .= "pt-br\n";
$xml .= "\n";
$qatlas = $dbh->query($sql);
foreach($qatlas as $row)
{
$xml .= "- \n";
$xml .= "\n";
$xml .= "".entity_decode($row["nome_ws"])."\n";
$xml .= "".entity_decode($row["desc_ws"])."\n";
$xml .= "".xmlTexto_prepara($row["link_ws"])."\n";
$xml .= "\n";
$xml .= "".xmlTexto_prepara($row["autor_ws"])."\n";
$xml .= "".xmlTexto_prepara($row["nacessos"])."\n";
$xml .= "".xmlTexto_prepara($row["nacessosok"])."\n";
$xml .= "".xmlTexto_prepara($row["id_ws"])."\n";
$xml .= "
\n";
}
$xml .= "\n";
$dbh = null;
$dbhw = null;
return $xml;
}
function geraXmlAtlas($locaplic,$editores)
{
error_reporting(0);
$dbh = "";
include($locaplic."/admin/php/conexao.php");
if($convUTF)
$xml = "<"."\x3F"."xml version='1.0' encoding='UTF-8' "."\x3F".">";
else
$xml = "<"."\x3F"."xml version='1.0' encoding='ISO-8859-1' "."\x3F".">";
$xml .= "\n\n";
//$q = "select * from i3geoadmin_atlas";
$qatlas = $dbh->query("select * from i3geoadmin_atlas");
$editor = verificaEditores($editores);
foreach($qatlas as $row)
{
$mostra = true;
if(strtolower($row["publicado_atlas"] == "nao"))
{$mostra = false;}
if($editor)
{$mostra = true;}
if($mostra)
{
$xml .= "\n";
$xml .= " ".$row["id_atlas"]."\n";
$xml .= " ".$row["publicado_atlas"]."\n";
$xml .= " ".xmlTexto_prepara($row["titulo_atlas"])."\n";
$xml .= " ".xmlTexto_prepara($row["desc_atlas"])."\n";
$xml .= " ".$row["icone_atlas"]."\n";
$xml .= " ".xmlTexto_prepara($row["link_atlas"])."\n";
$xml .= " ".xmlTexto_prepara($row["template_atlas"])."\n";
$xml .= " ".$row["w_atlas"]."\n";
$xml .= " ".$row["h_atlas"]."\n";
$xml .= " ".$row["pranchadefault_atlas"]."\n";
$xml .= " ".$row["tipoguias_atlas"]."\n";
$xml .= " ".$row["basemapfile_atlas"]."\n";
$xml .= " \n";
geraXmlAtlas_pegapranchas(&$xml,$row["id_atlas"],$dbh);
$xml .= " \n";
$xml .= " \n";
}
}
$xml .= "\n";
$dbh = null;
$dbhw = null;
return $xml;
}
function geraXmlIdentifica($perfil,$locaplic,$editores)
{
$editor = verificaEditores($editores);
if (!isset($perfil)){$perfil = "";}
$perfil = str_replace(","," ",$perfil);
$perfil = explode(" ",$perfil);
$dbh = "";
include($locaplic."/admin/php/conexao.php");
if($convUTF)
$xml = "<"."\x3F"."xml version='1.0' encoding='UTF-8' "."\x3F".">";
else
$xml = "<"."\x3F"."xml version='1.0' encoding='ISO-8859-1' "."\x3F".">";
$xml .= "\n\n";
$q = "select * from i3geoadmin_identifica ";
$qi = $dbh->query($q);
foreach($qi as $row)
{
$mostra = true;
if(strtolower($row["publicado_i"] == "nao"))
{$mostra = false;}
if($editor)
{$mostra = true;}
if($mostra)
{
$xml .= " \n";
$xml .= " ".xmlTexto_prepara($row["nome_i"])."\n";
$xml .= " ".xmlTexto_prepara($row["abrir_i"])."\n";
$xml .= " ".$row["publicado_i"]."\n";
$target = $row["target_i"];
if($target == ""){$target = "_self";}
$xml .= " ".$target."\n";
$xml .= " \n";
}
}
$xml .= "\n";
$dbh = null;
$dbhw = null;
return $xml;
}
function geraXmlMapas($perfil,$locaplic,$editores)
{
if (!isset($perfil)){$perfil = "";}
$perfil = str_replace(","," ",$perfil);
$perfil = explode(" ",$perfil);
$dbh = "";
include($locaplic."/admin/php/conexao.php");
if($convUTF)
$xml = "<"."\x3F"."xml version='1.0' encoding='UTF-8' "."\x3F".">";
else
$xml = "<"."\x3F"."xml version='1.0' encoding='ISO-8859-1' "."\x3F".">";
$xml .= "\n\n";
$q = "select * from i3geoadmin_mapas";
$q = $dbh->query($q);
$editor = verificaEditores($editores);
foreach($q as $row)
{
$mostraMapa = false;
if($row["perfil_mapa"] == "")
{$mostraMapa = true;}
else
{
$perfilMapa = explode(" ",str_replace(","," ",$row["perfil_mapa"]));
$mostraMapa = array_in_array($perfil,$perfilMapa);
}
if(strtolower($row["publicado_mapa"] == "nao"))
{$mostraMapa = false;}
if($editor)
{$mostraMapa = true;}
if($mostraMapa)
{
$xml .= "\n";
$xml .= " ".$row["perfil_mapa"]."\n";
$xml .= " ".xmlTexto_prepara($row["nome_mapa"])."\n";
$xml .= " ".xmlTexto_prepara($row["desc_mapa"])."\n";
$xml .= " ".xmlTexto_prepara($row["imagem_mapa"])."\n";
$xml .= " ".$row["temas_mapa"]."\n";
$xml .= " ".$row["ligados_mapa"]."\n";
$xml .= " ".$row["ext_mapa"]."\n";
$xml .= " ".xmlTexto_prepara($row["outros_mapa"])."\n";
$xml .= " ".xmlTexto_prepara($row["linkdireto_mapa"])."\n";
$xml .= " ".$row["publicado_mapa"]."\n";
$xml .= "\n";
}
}
$xml .= "\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);
if($convUTF)
$xml = "<"."\x3F"."xml version='1.0' encoding='UTF-8' "."\x3F".">";
else
$xml = "<"."\x3F"."xml version='1.0' encoding='ISO-8859-1' "."\x3F".">";
$xml .= "\n\n";
if(!isset($id_menu))
$xml .= "Utilize ?id_menu=1 por exemplo\n";
else
$xml .= "\n";
//
//pega os temas na raiz
//
$q = "select nacessos,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)
{
//filtra pelo perfil
if($row["perfil"] == "")
{$mostra = true;}
else
{
$perfilatual = explode(" ",str_replace(","," ",$row["perfil"]));
$mostra = array_in_array($perfil,$perfilatual);
}
if($mostra)
{
$xml .= "\n";
$xml .= " ".xmlTexto_prepara($row["nome_grupo"])."\n";
//
//pega temas na raiz
//
$q = "select nacessos,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 .= " ".xmlTexto_prepara($row["desc_grupo"])."\n";
$xml .= " ".$row["perfil"]."\n";
$xml .= "\n";
}
}
$xml .= "\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_n1 = $id_n1 and n2.id_subgrupo = subgrupos.id_subgrupo ";
//echo $q;exit;
$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 .= "\n";
$xml .= "".xmlTexto_prepara($row["nome_subgrupo"])."\n";
$xml .= "".xmlTexto_prepara($row["perfil"])."\n";
if(isset($tipo) && ($tipo == "temas") || ($tipo == ""))
geraXmlMenutemas_pegatemas($row["id_n2"],&$xml,$dbh,$perfil);
$xml .= "\n";
}
}
}
function geraXmlMenutemas_pegatemas($id_n2,$xml,$dbh,$perfil)
{
$q = "select nacessos,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 .= "\n";
$xml .= "".$row["codigo_tema"]."\n";
$xml .= "".$row["perfil"]."\n";
$xml .= "".xmlTexto_prepara($row["nome_tema"])."\n";
$xml .= "".xmlTexto_prepara($row["desc_tema"])."\n";
$xml .= "".xmlTexto_prepara($row["link_tema"])."\n";
$xml .= "".$row["tipoa_tema"]."\n";
$xml .= "".xmlTexto_prepara($row["tags_tema"])."\n";
$xml .= "".$row["kml_tema"]."\n";
if($row["tipoa_tema"] == "WMS")
$xml .= "nao\n";
else
$xml .= "".$row["ogc_tema"]."\n";
$xml .= "".$row["download_tema"]."\n";
$xml .= "".$row["nacessos"]."\n";
$xml .= "\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 .= " \n";
$xml .= " ".$row["id_prancha"]."\n";
$xml .= " ".xmlTexto_prepara($row["titulo_prancha"])."\n";
$xml .= " ".xmlTexto_prepara($row["desc_prancha"])."\n";
$xml .= " ".$row["icone_prancha"]."\n";
$xml .= " ".xmlTexto_prepara($row["link_prancha"])."\n";
$xml .= " ".$row["w_prancha"]."\n";
$xml .= " ".$row["h_prancha"]."\n";
$xml .= " ".$row["mapext_prancha"]."\n";
$xml .= " \n";
geraXmlAtlas_pegatemas(&$xml,$row["id_prancha"],$dbh);
$xml .= " \n";
$xml .= " \n";
}
}
function geraXmlAtlas_pegatemas($xml,$id_prancha,$dbh)
{
$q = "select t.codigo_tema,t.ligado_tema from i3geoadmin_atlast as t where t.id_prancha = $id_prancha";
//echo $q;
$qtemas = $dbh->query($q);
foreach($qtemas as $row)
{
$xml .= "\n";
$xml .= "".$row["codigo_tema"]."\n";
$xml .= "".$row["ligado_tema"]."\n";
$xml .= "\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 .= "\n";
$xml .= " ".xmlTexto_prepara($row["nome_funcao"])."\n";
$xml .= " ".xmlTexto_prepara($row["abrir_funcao"])."\n";
$xml .= " ".$row["w_funcao"]."\n";
$xml .= " ".$row["h_funcao"]."\n";
$xml .= " ".$row["perfil_funcao"]."\n";
$xml .= "\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("&","&",$texto);
}
function entity_decode($texto)
{
return html_entity_decode($texto);
}
function verificaEditores($editores)
{
$editor = "nao";
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="sim";}
}
return $editor;
}
?>