public function listaPermissoes($usrId) { $sql = "\n\t\tSELECT ma.acaoId, ma.moduloId, ma.acaoDescricao, ma.acaoPagina,\tma.acaoIndex, ma.acaoMenu\n\t\tFROM modulos_permissao AS mp\n\t\tINNER JOIN modulos_acao AS ma ON mp.acaoId = ma.acaoId\n\t\tAND mp.usrId =" . $usrId . "\n\t\tORDER BY ma.moduloId, ma.acaoId;\n\t\t"; $sqlFuncoes = new sqlFuncoes(); $sqlFuncoes->setSql($sql); return $sqlFuncoes->listaRegistros(); }
foreach ($erro as $idErro => $msgErro) { setcookie("msgErro['{$idErro}']", $msgErro, time() + 10, '/administracao/usuario-editar/' . $usrId); } header("Location: /administracao/usuario-editar/" . $usrId); exit; } // ########################################################################################### // PREPARAR O UPLOAD DA FOTO ################################################################# $fotoNome = explode('.', $usrFoto["name"]); $fotoNome = strtolower($usrApelidourl . "-" . time() . "." . $fotoNome[1]); $fotoDiretorio = $_SERVER['DOCUMENT_ROOT'] . "cms-base/imagens/usuarios/" . $fotoNome; $fotoEndereco = "/imagens/usuarios/" . $fotoNome; // ########################################################################################### // EDITAR USUARIO NA BASE DE DADOS ########################################################### require_once '../../classes/sql-funcoes.php'; $sqlUsuario = "\nUPDATE usuarios\nSET usrFoto = '{$fotoEndereco}'\nWHERE usrId = '{$usrId}'\nLIMIT 1;\n"; $sqlFuncoes = new sqlFuncoes(); $sqlFuncoes->setSql($sqlUsuario); $sqlFuncoes->atualizaRegistro(); unset($sqlFuncoes); // ########################################################################################### // DELETAR FOTO ANTIGA ####################################################################### unlink($_SERVER['DOCUMENT_ROOT'] . $usrFotoantiga); // ########################################################################################### // UPLOAD DA NOVA FOTO ####################################################################### move_uploaded_file($usrFoto["tmp_name"], $fotoDiretorio); // ########################################################################################### // RETORNA PARA A PAGINA DE EDICAO DO USUARIO ################################################ setcookie('msgOk', 'A <strong>FOTO</strong> do usuário foi alterada com sucesso.<br />', time() + 10, '/administracao/usuario-editar/' . $usrId); header("Location: /administracao/usuario-editar/" . $usrId); exit;
$permissoesAtuais[] = $permissoes[$p]['acaoId']; } // gera lista de todas as permissoes possiveis para o usuario $sql = "\nSELECT acaoId, moduloId, acaoPagina\nFROM modulos_acao\nWHERE usrRoot = 'n'\nAND acaoRestrita = 's'\nORDER BY moduloId, acaoId ASC;\n"; $sqlFuncoes = new sqlFuncoes(); $sqlFuncoes->setSql($sql); $permissoesPossiveis = $sqlFuncoes->listaRegistros(); unset($sqlFuncoes); // ########################################################################################### // ALATERA AS PERMISSOES NO BANCO DE DADOS ################################################### foreach ($permissoesPossiveis as $chave => $permissao) { if (in_array($permissao['acaoId'], $permissoesAtuais) and !array_key_exists($permissao['acaoPagina'], $_POST)) { $sql = "\n\t\tDELETE\n\t\tFROM modulos_permissao\n\t\tWHERE acaoId = " . $permissao['acaoId'] . "\n\t\tAND usrId = " . $usrId . "\n\t\tLIMIT 1;\n\t\t"; $sqlFuncoes = new sqlFuncoes(); $sqlFuncoes->setSql($sql); $sqlFuncoes->excluiRegistro(); unset($sqlFuncoes); } elseif (!in_array($permissao['acaoId'], $permissoesAtuais) and array_key_exists($permissao['acaoPagina'], $_POST)) { $sql = "\n\t\tINSERT INTO modulos_permissao\n\t\t\t(acaoId, moduloId, usrId)\n\t\tVALUES\n\t\t\t(" . $permissao['acaoId'] . ", " . $permissao['moduloId'] . ", " . $usrId . ");\n\t\t"; $sqlFuncoes = new sqlFuncoes(); $sqlFuncoes->setSql($sql); $sqlFuncoes->incluiRegisto(); unset($sqlFuncoes); } } // ########################################################################################### // REDIRECIONA PARA A PAGINA DE PERMISSOES DO USUARIO ######################################## setcookie('msgOk', 'Permissões alteradas com sucessos.', time() + 10, '/administracao/usuario-permissao/'); header("Location: /administracao/usuario-permissao/" . $usrId); exit; // ###########################################################################################
} // ########################################################################################### // CRIAR AS TABELAS DO BANCO DE DADOS ######################################################## $sqlTabelas = array(); // usuarios $sqlTabelas['usuarios'] = "\nCREATE TABLE usuarios (\n\tusrId mediumint(9) NOT NULL AUTO_INCREMENT,\n\tusrDatacricao timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP,\n\tusrEmail varchar(45) COLLATE utf8_unicode_ci NOT NULL,\n\tusrNome varchar(45) COLLATE utf8_unicode_ci NOT NULL,\n\tusrLogin char(10) COLLATE utf8_unicode_ci NOT NULL,\n\tusrApelido varchar(45) COLLATE utf8_unicode_ci NOT NULL,\n\tusrApelidourl varchar(45) COLLATE utf8_unicode_ci NOT NULL,\n\tusrFoto varchar(100) COLLATE utf8_unicode_ci NOT NULL,\n\tusrDescricao text COLLATE utf8_unicode_ci NOT NULL,\n\tusrMetadescricao text COLLATE utf8_unicode_ci NOT NULL,\n\tusrPalavraschave text COLLATE utf8_unicode_ci NOT NULL,\n\tusrSenha varchar(32) COLLATE utf8_unicode_ci NOT NULL,\n\tusrAtivo char(1) COLLATE utf8_unicode_ci NOT NULL DEFAULT 's',\n\tusrRoot char(1) COLLATE utf8_unicode_ci NOT NULL DEFAULT 'n',\n\tPRIMARY KEY (usrId),\n\tUNIQUE KEY usrEmail_UNIQUE (usrEmail),\n\tUNIQUE KEY usrLogin_UNIQUE (usrLogin),\n\tUNIQUE KEY usrApelidourl_UNIQUE (usrApelidourl),\n\tKEY usrApelido (usrApelido)\n) ENGINE=MyISAM DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci AUTO_INCREMENT=1;\n"; // acessos $sqlTabelas['acessos'] = "\nCREATE TABLE acessos (\n\tacessoId mediumint(9) NOT NULL AUTO_INCREMENT,\n\tacessoData timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP,\n\tacessoIp char(15) COLLATE utf8_unicode_ci NOT NULL,\n\tusrId mediumint(9) NOT NULL,\n\tPRIMARY KEY (acessoId),\n\tKEY usrId (usrId)\n) ENGINE=MyISAM DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci AUTO_INCREMENT=1;\n"; // modulos $sqlTabelas['modulos'] = "\nCREATE TABLE modulos (\n\tmoduloId mediumint(9) NOT NULL AUTO_INCREMENT,\n\tmoduloDescricao varchar(100) COLLATE utf8_unicode_ci NOT NULL,\n\tPRIMARY KEY (moduloId)\n) ENGINE=MyISAM DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci AUTO_INCREMENT=1;\n"; // modulos dados $sqlTabelas['modulosDados'] = "\nINSERT INTO modulos\n\t(moduloId, moduloDescricao)\nVALUES\n\t(1, 'Painel'),\n\t(2, 'Usuários'),\n\t(3, 'Configurações');\n"; // modulos_acao $sqlTabelas['modulos_acao'] = "\nCREATE TABLE modulos_acao (\n\tacaoId mediumint(9) NOT NULL AUTO_INCREMENT,\n\tmoduloId mediumint(9) NOT NULL,\n\tacaoDescricao varchar(100) COLLATE utf8_unicode_ci NOT NULL,\n\tacaoPagina varchar(100) COLLATE utf8_unicode_ci NOT NULL,\n\tacaoIndex char(1) COLLATE utf8_unicode_ci NOT NULL DEFAULT 'n',\n\tacaoMenu char(1) COLLATE utf8_unicode_ci NOT NULL DEFAULT 's',\n\tacaoRestrita char(1) COLLATE utf8_unicode_ci NOT NULL DEFAULT 's',\n\tusrRoot char(1) COLLATE utf8_unicode_ci NOT NULL DEFAULT 'n',\n\tPRIMARY KEY (acaoId),\n\tUNIQUE KEY acaoPagina (acaoPagina),\n\tKEY moduloId (moduloId)\n) ENGINE=MyISAM DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci AUTO_INCREMENT=1;\n"; // modulos_acaoDados $sqlTabelas['modulos_acaoDados'] = "\nINSERT INTO modulos_acao\n\t(moduloId, acaoDescricao, acaoPagina, acaoIndex, acaoMenu, acaoRestrita, usrRoot)\nVALUES\n\t(1, 'Painel', 'painel', 's', 's', 'n', 'n'),\n\t(2, 'Usuários',\t'usuarios', 's', 's', 'n', 'n'),\n\t(2, 'Alterar sua senha', 'usuario-alterar-senha', 'n', 's', 'n', 'n'),\n\t(2, 'Editar seus dados', 'usuario-editar', 'n', 's', 'n', 'n'),\n\t(2, 'Editar permissões', 'usuario-permissao', 'n', 'n', 's', 's'),\n\t(2, 'Novo usuário', 'usuario-novo', 'n', 's', 's', 's'),\n\t(3, 'Configurações', 'configuracoes', 's', 's', 's', 's');\n"; // modulos_permissao $sqlTabelas['modulos_permissao'] = "\nCREATE TABLE modulos_permissao (\n\tpermissaoId mediumint(9) NOT NULL AUTO_INCREMENT,\n\tacaoId mediumint(9) NOT NULL,\n\tmoduloId mediumint(9) NOT NULL,\n\tusrId mediumint(9) NOT NULL,\n\tPRIMARY KEY (permissaoId)\n) ENGINE=MyISAM DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci AUTO_INCREMENT=1;\n"; require_once '../classes/sql-funcoes.php'; foreach ($sqlTabelas as $tabela => $sql) { $sqlFuncoes = new sqlFuncoes(); $sqlFuncoes->setSql($sql); $sqlFuncoes->criarTabela(); unset($sqlFuncoes); } // ########################################################################################### // REDIRECIONA PARA A TERCEIRA PARTE DA INSTALACAO ########################################### setcookie('instalacao', $siteTitulo, time() + 10, '/instalacao/terceira-parte.php'); header('Location: /instalacao/terceira-parte.php'); exit; // ###########################################################################################
} else { if (!isset($modulo['paginaId'])) { $usrId = $sessaoId; } else { // retorna mensagem de erro setcookie('msgErro[privilegio]', 'Acesso restrito a usuários com permissão.', time() + 10, '/administracao/usuarios'); header('Location: /administracao/usuarios'); exit; } } } // ########################################################################################### // VERIFICA A EXISTENCIA DO USUARIO ########################################################## $sqlUsuario = "\nSELECT usrId, usrEmail, usrNome, usrLogin, usrApelido, usrFoto, usrDescricao, usrMetadescricao, usrPalavraschave, usrAtivo, usrRoot\nFROM usuarios\nWHERE usrId = " . $usrId . "\n"; require_once '../classes/sql-funcoes.php'; $sqlFuncoes = new sqlFuncoes(); $sqlFuncoes->setSql($sqlUsuario); $usrDados = $sqlFuncoes->listaRegistros(true); if (empty($usrDados)) { setcookie('msgErro[usrId]', 'Registro do usuário não encontrado.', time() + 10, '/administracao/usuarios'); header('Location: /administracao/usuarios'); exit; } unset($sqlFuncoes); // ########################################################################################### // CARREGA O ARQUIVO cabecalho.php ########################################################### include '../include/geral/php/cabecalho.php'; // ########################################################################################### // DEFINICAO DO FUZO E DA DATA ############################################################### date_default_timezone_set('America/Sao_Paulo'); setlocale(LC_ALL, "pt_BR");
unset($sqlFuncoes); // ########################################################################################### // SETA AS PERMISSOES DO USUARIO ############################################################# // gera lista de permissoes atuais $sql = "\nSELECT acaoId\nFROM modulos_permissao\nWHERE usrId =" . $usrId . "\nORDER BY moduloId, acaoId;\n"; $sqlFuncoes = new sqlFuncoes(); $sqlFuncoes->setSql($sql); $permissoes = $sqlFuncoes->listaRegistros(); unset($sqlFuncoes); $permissoesAtuais = array(); for ($p = 0; $p < count($permissoes); $p++) { $permissoesAtuais[] = $permissoes[$p]['acaoId']; } // gera lista de todas as permissoes possiveis para o usuario $sql = "\nSELECT ma.moduloId, m.moduloDescricao, ma.acaoId, ma.acaoDescricao, ma.acaoPagina, ma.acaoIndex\nFROM modulos_acao AS ma\nINNER JOIN modulos AS m ON ma.moduloId = m.moduloId\nAND ma.acaoRestrita = 's'\nAND\tma.usrRoot = 'n'\nORDER BY ma.moduloId, ma.acaoId ASC;\n"; $sqlFuncoes = new sqlFuncoes(); $sqlFuncoes->setSql($sql); $permissoes = $sqlFuncoes->listaRegistros(); unset($sqlFuncoes); $permissoesPossiveis = array(); for ($p = 0; $p < count($permissoes); $p++) { if ($permissoes[$p]['acaoIndex'] == "s") { $permissoesPossiveis[$permissoes[$p]['moduloId']]['moduloId'] = $permissoes[$p]['moduloId']; $permissoesPossiveis[$permissoes[$p]['moduloId']]['acaoId'] = $permissoes[$p]['acaoId']; $permissoesPossiveis[$permissoes[$p]['moduloId']]['acaoDescricao'] = $permissoes[$p]['acaoDescricao']; $permissoesPossiveis[$permissoes[$p]['moduloId']]['acaoPagina'] = $permissoes[$p]['acaoPagina']; } elseif ($permissoes[$p]['acaoIndex'] == "n") { $permissoesPossiveis[$permissoes[$p]['moduloId']]['moduloAcoes'][$permissoes[$p]['acaoId']]['moduloId'] = $permissoes[$p]['moduloId']; $permissoesPossiveis[$permissoes[$p]['moduloId']]['moduloAcoes'][$permissoes[$p]['acaoId']]['acaoId'] = $permissoes[$p]['acaoId']; $permissoesPossiveis[$permissoes[$p]['moduloId']]['moduloAcoes'][$permissoes[$p]['acaoId']]['acaoDescricao'] = $permissoes[$p]['acaoDescricao']; $permissoesPossiveis[$permissoes[$p]['moduloId']]['moduloAcoes'][$permissoes[$p]['acaoId']]['acaoPagina'] = $permissoes[$p]['acaoPagina'];
<?php // CONSULTAS A BASE DE DADOS ################################################################# // determina o nivel de permissao do usuário if (in_array(6, $sessaoPermissoes)) { $sqlUsuarios = "\n\tSELECT usrId, usrEmail, usrNome, usrLogin, usrAtivo, usrRoot\n\tFROM usuarios\n\tORDER BY usrNome;\n\t"; $listaUsuarios = "../include/administracao/php/usuarios-lista-todos.php"; } else { $sqlUsuarios = "\n\tSELECT usrId, usrEmail, usrNome\n\tFROM usuarios\n\tWHERE usrRoot = 'n'\n\tAND usrAtivo = 's'\n\tORDER BY usrNome;\n\t"; $listaUsuarios = "../include/administracao/php/usuarios-lista-ativos.php"; } // buscar usuarios require_once '../classes/sql-funcoes.php'; $sqlFuncoes = new sqlFuncoes(); $sqlFuncoes->setSql($sqlUsuarios); $usrDados = $sqlFuncoes->listaRegistros(); // ########################################################################################### // CARREGA O ARQUIVO cabecalho.php ########################################################### include '../include/geral/php/cabecalho.php'; // ########################################################################################### // DEFINICAO DO FUZO E DA DATA ############################################################### date_default_timezone_set('America/Sao_Paulo'); setlocale(LC_ALL, "pt_BR"); $dataCompleta = strftime("%A, %d de %B de %Y"); // ########################################################################################### ?> <!DOCTYPE HTML> <html><!-- InstanceBegin template="/Templates/administracao.dwt.php" codeOutsideHTMLIsLocked="false" --> <head> <meta charset="utf-8"> <meta name="author" content="Getulio Vinicius">