diff --git a/admin1/cadastros/perfis/exec.php b/admin1/cadastros/perfis/exec.php new file mode 100755 index 0000000..bb8c1f8 --- /dev/null +++ b/admin1/cadastros/perfis/exec.php @@ -0,0 +1,326 @@ + '' + ); + $id_perfil = i3GeoAdminInsertUnico($dbhw,"i3geoadmin_perfis",$dataCol,"perfil","id_perfil"); + $retorna = alterar ( $id_perfil, $perfil,$dbhw ); + + return $retorna; + } catch ( PDOException $e ) { + return false; + } +} +// $papeis deve ser um array +function alterar($id_perfil, $perfil,$dbhw) { + global $esquemaadmin; + //pega o nome conforme o ID + $original = pegaDados ( "SELECT perfil from ".$esquemaadmin."i3geoadmin_perfis WHERE id_perfil = $id_perfil", $dbh, false ); + $original = $original[0]["perfil"]; + + if($convUTF){ + $perfil = utf8_encode($perfil); + } + $dataCol = array( + "perfil" => $perfil + ); + $resultado = i3GeoAdminUpdate ( $dbhw, "i3geoadmin_perfis", $dataCol, "WHERE id_perfil = $id_perfil" ); + if ($resultado == false) { + return false; + } + + $q = $dbhw->query("select * from ".$esquemaadmin."i3geoadmin_mapas"); + foreach($q as $row){ + $t = $row['perfil_mapa']; + $i = $row['id_mapa']; + $ts = trim(str_replace(" ".$original." ",$perfil," ".$t." ")); + if($t != $ts){ + $dataCol = array( + "perfil_mapa" => $ts + ); + i3GeoAdminUpdate($dbhw,"i3geoadmin_mapas",$dataCol,"WHERE id_mapa = $i"); + } + } + $q = $dbhw->query("select * from ".$esquemaadmin."i3geoadmin_menus"); + foreach($q as $row){ + $t = $row['perfil_menu']; + $i = $row['id_menu']; + $ts = trim(str_replace(" ".$original." ",$perfil," ".$t." ")); + if($t != $ts){ + $dataCol = array( + "perfil_menu" => $ts + ); + i3GeoAdminUpdate($dbhw,"i3geoadmin_menus",$dataCol,"WHERE id_menu = $i"); + } + } + $q = $dbhw->query("select * from ".$esquemaadmin."i3geoadmin_n1"); + foreach($q as $row){ + $t = $row['n1_perfil']; + $i = $row['id_n1']; + $ts = trim(str_replace(" ".$original." ",$perfil," ".$t." ")); + if($t != $ts){ + $dataCol = array( + "n1_perfil" => $ts + ); + i3GeoAdminUpdate($dbhw,"i3geoadmin_n1",$dataCol,"WHERE id_n1 = $i"); + } + } + $q = $dbhw->query("select * from ".$esquemaadmin."i3geoadmin_n2"); + foreach($q as $row){ + $t = $row['n2_perfil']; + $i = $row['id_n2']; + $ts = trim(str_replace(" ".$original." ",$perfil," ".$t." ")); + if($t != $ts){ + $dataCol = array( + "n2_perfil" => $ts + ); + i3GeoAdminUpdate($dbhw,"i3geoadmin_n2",$dataCol,"WHERE id_n2 = $i"); + } + } + $q = $dbhw->query("select * from ".$esquemaadmin."i3geoadmin_n3"); + foreach($q as $row){ + $t = $row['n3_perfil']; + $i = $row['id_n3']; + $ts = trim(str_replace(" ".$original." ",$perfil," ".$t." ")); + if($t != $ts){ + $dataCol = array( + "n3_perfil" => $ts + ); + i3GeoAdminUpdate($dbhw,"i3geoadmin_n3",$dataCol,"WHERE id_n3 = $i"); + } + } + $q = $dbhw->query("select * from ".$esquemaadmin."i3geoadmin_raiz"); + foreach($q as $row){ + $t = $row['perfil']; + $i = $row['id_raiz']; + $ts = trim(str_replace(" ".$original." ",$perfil," ".$t." ")); + if($t != $ts){ + $dataCol = array( + "perfil" => $ts + ); + i3GeoAdminUpdate($dbhw,"i3geoadmin_raiz",$dataCol,"WHERE id_raiz = $i"); + } + } + $q = $dbhw->query("select * from ".$esquemaadmin."i3geoadmin_sistemas"); + foreach($q as $row) + { + $t = $row['perfil_sistema']; + $i = $row['id_sistema']; + $ts = trim(str_replace(" ".$original." ",$perfil," ".$t." ")); + if($t != $ts){ + $dataCol = array( + "perfil_sistema" => $ts + ); + i3GeoAdminUpdate($dbhw,"i3geoadmin_sistemas",$dataCol,"WHERE id_sistema = $i"); + } + } + $q = $dbhw->query("select * from ".$esquemaadmin."i3geoadmin_sistemasf"); + foreach($q as $row){ + $t = $row['perfil_funcao']; + $i = $row['id_funcao']; + $ts = trim(str_replace(" ".$original." ",$perfil," ".$t." ")); + if($t != $ts){ + $dataCol = array( + "perfil_funcao" => $ts + ); + i3GeoAdminUpdate($dbhw,"i3geoadmin_sistemasf",$dataCol,"WHERE id_funcao = $i"); + } + } + return $id_perfil; +} +function excluir($id_perfil, $dbhw) { + global $esquemaadmin; + //pega o nome conforme o ID + $dados = pegaDados ( "SELECT perfil from ".$esquemaadmin."i3geoadmin_perfis WHERE id_perfil = $id_perfil", $dbh, false ); + $perfil = $dados[0]["perfil"]; + $resultado = i3GeoAdminExclui ( $esquemaadmin . "i3geoadmin_perfis", "id_perfil", $id_perfil, $dbhw, false ); + if ($resultado == false) { + return false; + } + //remove o perfil de outras tabelas + $q = $dbhw->query("select * from ".$esquemaadmin."i3geoadmin_mapas"); + foreach($q as $row){ + $t = $row['perfil_mapa']; + $i = $row['id_mapa']; + $ts = trim(str_replace(" ".$perfil." ",""," ".$t." ")); + if($t != $ts){ + $dataCol = array( + "perfil_mapa" => $ts + ); + i3GeoAdminUpdate($dbhw,"i3geoadmin_mapas",$dataCol,"WHERE id_mapa = $i"); + } + } + $q = $dbhw->query("select * from ".$esquemaadmin."i3geoadmin_menus"); + foreach($q as $row){ + $t = $row['perfil_menu']; + $i = $row['id_menu']; + $ts = trim(str_replace(" ".$perfil." ",""," ".$t." ")); + if($t != $ts){ + $dataCol = array( + "perfil_menu" => $ts + ); + i3GeoAdminUpdate($dbhw,"i3geoadmin_menus",$dataCol,"WHERE id_menu = $i"); + } + } + $q = $dbhw->query("select * from ".$esquemaadmin."i3geoadmin_n1"); + foreach($q as $row){ + $t = $row['perfil_n1']; + $i = $row['id_n1']; + $ts = trim(str_replace(" ".$perfil." ",""," ".$t." ")); + if($t != $ts){ + $dataCol = array( + "perfil_n1" => $ts + ); + i3GeoAdminUpdate($dbhw,"i3geoadmin_n1",$dataCol,"WHERE id_n1 = $i"); + } + } + $q = $dbhw->query("select * from ".$esquemaadmin."i3geoadmin_n2"); + foreach($q as $row){ + $t = $row['perfil_n2']; + $i = $row['id_n2']; + $ts = trim(str_replace(" ".$perfil." ",""," ".$t." ")); + if($t != $ts){ + $dataCol = array( + "perfil_n2" => $ts + ); + i3GeoAdminUpdate($dbhw,"i3geoadmin_n2",$dataCol,"WHERE id_n2 = $i"); + } + } + $q = $dbhw->query("select * from ".$esquemaadmin."i3geoadmin_n3"); + foreach($q as $row){ + $t = $row['perfil_n3']; + $i = $row['id_n3']; + $ts = trim(str_replace(" ".$perfil." ",""," ".$t." ")); + if($t != $ts){ + $dataCol = array( + "perfil_n3" => $ts + ); + i3GeoAdminUpdate($dbhw,"i3geoadmin_n3",$dataCol,"WHERE id_n3 = $i"); + } + } + $q = $dbhw->query("select * from ".$esquemaadmin."i3geoadmin_raiz"); + foreach($q as $row){ + $t = $row['perfil']; + $i = $row['id_raiz']; + $ts = trim(str_replace(" ".$perfil." ",""," ".$t." ")); + if($t != $ts){ + $dataCol = array( + "perfil" => $ts + ); + i3GeoAdminUpdate($dbhw,"i3geoadmin_raiz",$dataCol,"WHERE id_raiz = $i"); + } + } + $q = $dbhw->query("select * from ".$esquemaadmin."i3geoadmin_sistemasf"); + foreach($q as $row){ + $t = $row['perfil_funcao']; + $i = $row['id_funcao']; + $ts = trim(str_replace(" ".$perfil." ",""," ".$t." ")); + if($t != $ts){ + $dataCol = array( + "perfil_funcao" => $ts + ); + i3GeoAdminUpdate($dbhw,"i3geoadmin_sistemasf",$dataCol,"WHERE id_funcao = $i"); + } + } + return $resultado; +} +?> diff --git a/admin1/cadastros/perfis/index.js b/admin1/cadastros/perfis/index.js new file mode 100755 index 0000000..36d84ca --- /dev/null +++ b/admin1/cadastros/perfis/index.js @@ -0,0 +1,214 @@ +/* +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@gmail.com + +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; + +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. + + */ +i3GEOadmin.perfis = { + //variavel global indicando o elemento que recebera a lista de perfis + ondeLista: "", + //conteudo html do formulario de adicao de operacao + formAdiciona: "", + init: function(onde){ + i3GEOadmin.perfis.ondeLista = onde; + i3GEOadmin.perfis.lista(); + }, + /* +Function: lista + +Obtém a lista de perfis + */ + lista: function(){ + i3GEOadmin.core.iconeAguarde(i3GEOadmin.perfis.ondeLista); + $.post( + "exec.php?funcao=lista" + ) + .done( + function(data, status){ + //valor do filtro atual + var filtro = i3GEOadmin.perfis.valorFiltro(); + //objeto json com os dados viondos do banco + var json = jQuery.parseJSON(data); + //template do form de cada operacao + var templateLista = $("#templateLista").html(); + //lista todas as perfis + var html = Mustache.to_html( + "{{#data}}" + templateLista + "{{/data}}", + $.extend( + {}, + i3GEOadmin.perfis.dicionario, + { + "data": json, + "onExcluir": "i3GEOadmin.perfis.excluirDialogo",//funcao + "onSalvar": "i3GEOadmin.perfis.salvarDialogo"//funcao + } + ) + ); + i3GEOadmin.perfis.ondeLista.html(html); + //filtro + html = Mustache.to_html( + "{{#data}}" + $("#templateFiltro").html() + "{{/data}}", + {"data":json} + ); + $("#filtro").html("" + html); + $("#filtro").combobox(); + if(filtro != ""){ + i3GEOadmin.perfis.defineFiltro(filtro); + i3GEOadmin.perfis.filtra(i3GEOadmin.perfis.pegaFiltro()); + } + //monta um template para o modal de inclusao de novo usuario + if(i3GEOadmin.perfis.formAdiciona == ""){ + html = Mustache.to_html( + $("#templateLista").html(), + $.extend( + {}, + i3GEOadmin.perfis.dicionario, + { + "id_perfil": "modal", + "excluir": i3GEOadmin.perfis.dicionario.cancelar, + "onExcluir": "i3GEOadmin.core.fechaModalGeral",//funcao + "onSalvar": "i3GEOadmin.perfis.adiciona"//funcao + } + ) + ); + i3GEOadmin.perfis.formAdiciona = html; + } + $.material.init(); + } + ) + .fail(function(data){ + i3GEOadmin.perfis.ondeLista.html(""); + i3GEOadmin.core.mostraErro(data.status + " " +data.statusText); + }); + }, + adicionaDialogo: function(){ + i3GEOadmin.core.abreModalGeral(i3GEOadmin.perfis.formAdiciona); + }, +// os parametros sao obtidos do formulario aberto do modal + adiciona: function(){ + var parametros = $("#form-modal form").serialize(); + i3GEOadmin.core.fechaModalGeral(); + i3GEOadmin.core.modalAguarde(true); + $.post( + "exec.php?funcao=adicionar", + parametros + ) + .done( + function(data, status){ + i3GEOadmin.core.modalAguarde(false); + i3GEOadmin.core.iconeAguarde(i3GEOadmin.perfis.ondeLista); + i3GEOadmin.perfis.lista(); + } + ) + .fail( + function(data){ + i3GEOadmin.core.modalAguarde(false); + i3GEOadmin.core.mostraErro(data.status + " " +data.statusText); + } + ); + }, + excluirDialogo: function(id){ + var hash = { + "mensagem": i3GEOadmin.perfis.dicionario.confirma, + "onBotao1": "i3GEOadmin.perfis.excluir('"+id+"')", + "botao1": i3GEOadmin.perfis.dicionario.sim, + "onBotao2": "i3GEOadmin.core.fechaModalConfirma();", + "botao2": i3GEOadmin.perfis.dicionario.nao + }; + i3GEOadmin.core.abreModalConfirma(hash); + }, + excluir: function(id){ + i3GEOadmin.core.modalAguarde(true); + $.post( + "exec.php?funcao=excluir", + "id_perfil="+id + ) + .done( + function(data, status){ + i3GEOadmin.core.modalAguarde(false); + var json = jQuery.parseJSON(data)*1; + $("#form-" + json).remove(); + } + ) + .fail( + function(data){ + i3GEOadmin.core.modalAguarde(false); + i3GEOadmin.core.mostraErro(data.status + " " +data.statusText); + } + ); + }, + salvarDialogo: function(id){ + var hash = { + "mensagem": i3GEOadmin.perfis.dicionario.confirma, + "onBotao1": "i3GEOadmin.perfis.salvar('"+id+"')", + "botao1": i3GEOadmin.perfis.dicionario.sim, + "onBotao2": "i3GEOadmin.core.fechaModalConfirma();", + "botao2": i3GEOadmin.perfis.dicionario.nao + }; + i3GEOadmin.core.abreModalConfirma(hash); + }, + salvar: function(id){ + var parametros = $("#form-" + id + " form").serialize(); + i3GEOadmin.core.fechaModalGeral(); + i3GEOadmin.core.modalAguarde(true); + $.post( + "exec.php?funcao=alterar", + "id_perfil="+ id+"&"+parametros + ) + .done( + function(data, status){ + i3GEOadmin.core.modalAguarde(false); + i3GEOadmin.core.iconeAguarde(i3GEOadmin.perfis.ondeLista); + i3GEOadmin.perfis.lista(); + } + ) + .fail( + function(data){ + i3GEOadmin.core.modalAguarde(false); + i3GEOadmin.core.mostraErro(data.status + " " +data.statusText); + } + ); + }, + pegaFiltro: function(){ + return $i("filtro"); + }, + valorFiltro: function(){ + return i3GEOadmin.perfis.pegaFiltro().value; + }, + defineFiltro: function(valor){ + i3GEOadmin.perfis.pegaFiltro().value = valor; + }, + filtra: function(obj){ + $("#corpo .panel").each( + function(i,el){ + if(obj.value == ""){ + $(el).show(); + } + else { + $(el).hide(); + } + } + ); + if(obj.value != ""){ + $("#"+obj.value).show(); + } + } +}; \ No newline at end of file diff --git a/admin1/cadastros/perfis/index.php b/admin1/cadastros/perfis/index.php new file mode 100755 index 0000000..850f4e9 --- /dev/null +++ b/admin1/cadastros/perfis/index.php @@ -0,0 +1,133 @@ + +