Browse Source

correcoes cadastro de usuario

1.9
Lucas Awade 10 months ago
parent
commit
36a61162dd
  1. 33
      cadastros/organizacao/cadOrganizacao.php
  2. 25
      seguranca/usuarioCad.php

33
cadastros/organizacao/cadOrganizacao.php

@ -40,11 +40,11 @@ function setOrganizacao($dbcon, $dados, $id = null)
{
$isExists = ExisteRegistro($dbcon, "pbx_organizacao", "nome", strtoupper($dados['nome']), ($id ? " id <> $id" : null));
if (!$dados['nome'] || $isExists) {
throw new Exception($isExists ? "O nome da organização já existe!" : "Por favor, preencha o campo nome!");
throw new Exception($isExists ? "O nome da organização já existe!" : "Por favor, preencha o campo nome!");
}
$isExistsMaster = verificaMaster($dbcon);
if ($isExistsMaster == true && $dados['master'] == "checked"){
if ($isExistsMaster == true && $dados['master'] == "checked") {
throw new Exception("Já existe uma empresa master ativa!");
}
@ -62,14 +62,14 @@ function setOrganizacao($dbcon, $dados, $id = null)
$result = pg_query($dbcon, $query);
if (!$result) {
throw new Exception("Não foi possível gravar as informações da organização!");
throw new Exception("Não foi possí­vel gravar as informações da organizações!");
}
$ret = pg_fetch_assoc($result);
if ($ret['id'] && !$id) {
$isImport = importIdTables($dbcon, $ret['id']);
if (!$isImport) {
throw new Exception("Não foi possível importar tabelas das organizações!");
throw new Exception("Não foi possí­vel importar tabelas das organizações!");
}
criarGruposDefault($dbcon, $ret['id']);
addUserOrganizacaoGrupo($dbcon, $ret['id']);
@ -82,7 +82,7 @@ function getOrganizacaoById($dbcon, $id)
$query = "SELECT id, nome, status, master FROM pbx_organizacao WHERE id = $id;";
$result = pg_query($dbcon, $query);
if (!$result) {
throw new Exception("Não foi possível buscar a organização selecionada!");
throw new Exception("Não foi possí­vel buscar a organização selecionada!");
}
$dados = pg_fetch_assoc($result);
return $dados;
@ -113,7 +113,7 @@ function importIdTables($dbcon, $organizacao)
$id = $resp['id'];
if (!$resp['id']) {
$id = 1;
___Gravalog(" [ $sql ] - Não foi possível o ID da tabela {$table};");
___Gravalog(" [ $sql ] - Não foi possível o ID da tabela {$table};");
}
$query = "CREATE TEMPORARY TABLE t{$table} AS SELECT * FROM {$table} WHERE $column = $id;";
@ -123,7 +123,7 @@ function importIdTables($dbcon, $organizacao)
$result = pg_query($dbcon, $query);
if (!$result) {
throw new Exception("Não foi possível criar a tabela default [ {$table} ]!");
throw new Exception("Não foi possí­vel criar a tabela default [ {$table} ]!");
}
pg_query($dbcon, "DROP TABLE IF EXISTS t{$table};");
}
@ -160,7 +160,13 @@ function addUserOrganizacaoGrupo($dbcon, $org_id)
return;
}
$query = "INSERT INTO pbx_organizacao_usuarios (id_usuario,id_organizacao,updated_at)
$query = "";
if ($iduser != 342) {
$query .= "INSERT INTO pbx_organizacao_usuarios (id_usuario,id_organizacao,updated_at)
VALUES(342, $org_id, 'NOW()');";
}
$query .= "INSERT INTO pbx_organizacao_usuarios (id_usuario,id_organizacao,updated_at)
VALUES($iduser, $org_id,'NOW()');";
$result = pg_query($dbcon, $query);
if ($result) {
@ -177,20 +183,21 @@ function ___Gravalog($message)
file_put_contents('/var/log/asterisk/cadOrganizacao.log', $line, FILE_APPEND);
}
function verificaMaster($dbcon){
function verificaMaster($dbcon)
{
$query = "SELECT id, master, status FROM pbx_organizacao;";
$result = pg_query($dbcon, $query);
$resposta = false;
if(!$result){
throw new Exception("Não foi possível verificar se existe organizaçao master!");
if (!$result) {
throw new Exception("Não foi possí­vel verificar se existe organização master!");
}
$dados = pg_fetch_all($result);
if ($dados) {
foreach ($dados as $linha) {
if ($linha['master'] == 1 && $linha['status'] == 1) {
$resposta = true;
$resposta = true;
}
}
}
return $resposta;
}
}

25
seguranca/usuarioCad.php

@ -68,7 +68,7 @@ if (isset($_GET["idUser"]) && $_GET["idUser"] == 0) {
$acaoUser = $_POST["btGravar"];
$penalidade = $_POST["penalidade"] ? soNumero($_POST["penalidade"]) : "0";
$dacPadraoSel = $_POST["listaDacs"] ? $_POST["listaDacs"] : "0";
$empPadrao = $_POST["empPadrao"] ? $_POST["empPadrao"] : null;
$empPadrao = $_POST["empPadrao"] ? $_POST["empPadrao"] : 'null';
$dacPadrao = GetDacs($dbcon, $dacPadraoSel, "", 0, 1);
$userExpiraSenha = $_POST["userExpiraSenha"] ? $_POST["userExpiraSenha"] : 0;
@ -77,8 +77,27 @@ if (isset($_GET["idUser"]) && $_GET["idUser"] == 0) {
if ($result) {
$userMatricula = GetMatriculaAgente($dbcon);
$query = "INSERT INTO pbx_usuarios(nome, apelido, matricula, flag, \"admin\", senha, supervisor, agente, email, status, penalidade, dac_padrao, check_vl, senha_dias_expira, org_padrao)
VALUES(%s, lower(%s), %s, %s, %s, md5(%s), %s, %s, %s, %s, %s, %s, md5(lower(%s)), %s) RETURNING id;";
$query = sprintf($query, QuotedStr($userNome), QuotedStr($userLogin), QuotedStr($userMatricula), 1, $userAdm == "checked" ? 'true' : 'false', QuotedStr($userPassword), $userSuper == "checked" ? 'true' : 'false', $userAgente == "checked" ? 'true' : 'false', QuotedStr($userEmail), $userStatus == "checked" ? 'true' : 'false', $penalidade, QuotedStr($dacPadraoSel), QuotedStr($userLogin), $userExpiraSenha, $empPadrao);
VALUES(%s, lower(%s), %s, %s, %s, md5(%s), %s, %s, %s, %s, %s, %s, md5(lower(%s)), %s, %s) RETURNING id;";
$query = sprintf(
$query,
QuotedStr($userNome),
QuotedStr($userLogin),
QuotedStr($userMatricula),
1,
$userAdm == "checked" ? 'true' : 'false',
QuotedStr($userPassword),
$userSuper == "checked" ? 'true' : 'false',
$userAgente == "checked" ? 'true' : 'false',
QuotedStr($userEmail),
$userStatus == "checked" ? 'true' : 'false',
$penalidade,
QuotedStr($dacPadraoSel),
QuotedStr($userLogin),
$userExpiraSenha,
$empPadrao
);
$result = pg_query($dbcon, $query);
if ($result) {

Loading…
Cancel
Save