From 2d8f28e500ba98cfbfce6911723d76da10861649 Mon Sep 17 00:00:00 2001 From: Matheo Bonucia Date: Mon, 5 Feb 2024 18:12:07 +0000 Subject: [PATCH] foram corrigidos querys do tipo insert no BD para Ramais Secretaria e outras novas features do script gerador de formularios nesse commit, foram finalizados todas as funcionalidade do script, implementado flexibilizacoes na criacao de formularios, faltando agora corrigir nome das chaves para melhor entendimento, adicionar mais comentarios e fazer a documentacao --- admin/cadAutomatico.php | 24 ++++++- admin/cadRamais.php | 139 +++++++++++++++++------------------- admin/css/cadRamal.css | 10 ++- include/util/funcoesApl.php | 39 +++++++--- 4 files changed, 122 insertions(+), 90 deletions(-) diff --git a/admin/cadAutomatico.php b/admin/cadAutomatico.php index b20f6bf5..91f69766 100644 --- a/admin/cadAutomatico.php +++ b/admin/cadAutomatico.php @@ -44,6 +44,12 @@ function gerarFormulario($__prog, $configuracao, $titulo, $acao, $param, $id = n // Itera sobre os elementos do grupo foreach ($grupo['conteudo'] as $elemento) { // Se não for hidden, gera a div e o elemento normalmente + // Caso queria adicionar uma div individual e com uma classe + if (isset($elemento['abrir-div'])) { + $props_div = $elemento['abrir-div']; + $attributes = gerarAtributos($props_div); + $formulario .= '
'; + } list($divInicial, $divContent) = gerarDivInicial($elemento); $formulario .= $divInicial; @@ -59,6 +65,9 @@ function gerarFormulario($__prog, $configuracao, $titulo, $acao, $param, $id = n } else { $formulario .= ''; } + if (isset($elemento['fechar-div'])) { + $formulario .= '
'; + } $formulario .= ''; } } @@ -111,6 +120,10 @@ function gerarDivInicial($elemento) break; } switch ($tipo) { + + case 'titulo': + $divContent = 'coluna-titulo'; + break; case 'toggle': $divContent = 'coluna-content-toggle'; break; @@ -186,17 +199,22 @@ function gerarAtributos($props) continue; // Ignorar o atributo se o valor for falso } + // Adicionar o nome do atributo $atributos .= $atributo; - // Adicionar valor apenas se não for booleano (true/false) ou se for verdadeiro - if (!is_bool($valor) || $valor) { + // Adicionar valor apenas se a chave for 'checked' ou 'selected' + if ($atributo === 'checked' || $atributo === 'selected') { + // Não adicionar valor mesmo se for verdadeiro + $atributos .= null; + } elseif (!is_bool($valor) || $valor) { + // Adicionar valor se não for booleano (true/false) ou se for verdadeiro para outros atributos $atributos .= '="' . $valor . '"'; } $atributos .= ' '; } - return $atributos; + return trim($atributos); // Remover espaço extra no final, se houver } function gerarSelect($props) diff --git a/admin/cadRamais.php b/admin/cadRamais.php index 75fc7253..cf7a51ef 100644 --- a/admin/cadRamais.php +++ b/admin/cadRamais.php @@ -369,7 +369,7 @@ if ($renderizar) { ?> GrvAudita($dbcon, $idProg, 'pbx_sip_ramais', 'INS', array(), $novo, $fields, array('id'), true); InsereRotasRamais($dbcon, $rotas, $nome2); - InsereRamaisChf($dbcon, $nome2); + InsereRamaisChf($dbcon, $nome2, $org_id); if ($sigame_interno == '') { $sigame_interno2 = 'F'; @@ -465,7 +465,7 @@ if ($renderizar) { ?> GrvAudita($dbcon, $idProg, 'pbx_sip_ramais', 'UPD', $velho, $novo, $filds, array('id'), true); InsereRotasRamais($dbcon, $rotas, $nome); - InsereRamaisChf($dbcon, $nome); + InsereRamaisChf($dbcon, $nome, $org_id); if ($inseri_voice == 0) { if (($v_nome != '') || ($v_email != '')) { @@ -700,11 +700,11 @@ if ($renderizar) { ?> [ 'titulo' => '', 'classes' => 'normal', - 'tipo' => 'normal', + 'tipo' => 'titulo', 'props' => [ [ 'type' => 'radio', - 'name' => 'tipoRota[' . [$idRota] . ']', + 'name' => 'tipoRota[' . $idRota . ']', 'class' => 'tipoRotaSim', 'value' => '1;' . $idRota, 'checked' => ($tipoAcesso == 1) ? true : false, @@ -714,11 +714,11 @@ if ($renderizar) { ?> [ 'titulo' => '', 'classes' => 'normal', - 'tipo' => 'normal', + 'tipo' => 'titulo', 'props' => [ [ 'type' => 'radio', - 'name' => 'tipoRota[' . [$idRota] . ']', + 'name' => 'tipoRota[' . $idRota . ']', 'class' => 'tipoRotaNao', 'value' => '0;' . $idRota, 'checked' => ($tipoAcesso == 0) ? true : false, @@ -728,11 +728,11 @@ if ($renderizar) { ?> [ 'titulo' => '', 'classes' => 'normal', - 'tipo' => 'normal', + 'tipo' => 'titulo', 'props' => [ [ 'type' => 'radio', - 'name' => 'tipoRota[' . [$idRota] . ']', + 'name' => 'tipoRota[' . $idRota . ']', 'class' => 'tipoRotaSenha', 'value' => '2;' . $idRota, 'checked' => ($tipoAcesso == 2) ? true : false, @@ -742,11 +742,11 @@ if ($renderizar) { ?> [ 'titulo' => '', 'classes' => 'normal', - 'tipo' => 'normal', + 'tipo' => 'titulo', 'props' => [ [ 'type' => 'radio', - 'name' => 'tipoRota[' . [$idRota] . ']', + 'name' => 'tipoRota[' . $idRota . ']', 'class' => 'tipoRotaAgente', 'value' => '3;' . $idRota, 'checked' => ($tipoAcesso == 3) ? true : false, @@ -831,7 +831,7 @@ if ($renderizar) { ?> $optionsChefeSecretaria = []; while ($dados5 = pg_fetch_array($result5)) { - $excecao = $dados5[0]; + $excecao = $dados5[1]; $optionsChefeSecretaria[$excecao] = [ 'label' => $excecao, 'attributes' => [], @@ -1022,7 +1022,7 @@ if ($renderizar) { ?> 'type' => 'number', 'min' => '0', 'step' => 'any', - 'class' => 'validate[required,custom[onlyNumber],length[0,100]]', + 'required' => 'required', 'id' => 'qtde2', 'value' => '1', 'size' => '5', @@ -1362,7 +1362,6 @@ if ($renderizar) { ?> [ 'name' => 'dispositivo', 'type' => 'text', - 'class' => 'validate[optional,length[0,100]]', 'id' => 'dispositivo2', 'value' => ($acao == 'edita') ? $dispositivo : null, 'size' => '20', @@ -1389,7 +1388,6 @@ if ($renderizar) { ?> 'size' => '20', 'maxlength' => '20', 'pattern' => '\d+', - 'required' => 'optional', ] ] ], @@ -1406,7 +1404,6 @@ if ($renderizar) { ?> 'size' => '20', 'maxlength' => '20', 'pattern' => '\d+', - 'required' => 'optional', ] ] ] @@ -1425,11 +1422,10 @@ if ($renderizar) { ?> 'name' => 'sigame_nao_atende', 'type' => 'text', 'id' => 'sigame_nao_atende2', - 'value' => ($acao == 'edita') ? $sigame_naoatende : null, + 'value' => ($acao == "edita") ? $sigame_naoatende : null, 'size' => '20', 'maxlength' => '20', 'pattern' => '\d+', - 'required' => 'optional', ] ] ], @@ -1442,11 +1438,10 @@ if ($renderizar) { ?> 'name' => 'sigame_ocupado', 'type' => 'text', 'id' => 'sigame_ocupado2', - 'value' => ($acao == 'edita') ? $sigame_ocupado : null, + 'value' => ($acao == "edita") ? $sigame_ocupado : null, 'size' => '20', 'maxlength' => '20', 'pattern' => '\d+', - 'required' => 'optional', ] ] ], @@ -1528,7 +1523,7 @@ if ($renderizar) { ?> 'type' => 'checkbox', 'id' => 'gravacao_saida', 'value' => 'V', - 'checked' => ($gravacao_saida == 'V') ? true : false, + 'checked' => ($gravacao_saida == "V") ? true : false, ] ] ], @@ -1541,10 +1536,9 @@ if ($renderizar) { ?> 'name' => 'timeout', 'type' => 'text', 'id' => 'timeout', - 'value' => ($acao == 'edita') ? $timeout : null, + 'value' => ($acao == "edita") ? $timeout : null, 'size' => '10', 'maxlength' => '10', - 'required' => 'optional', 'pattern' => '\d+', ] ] @@ -1589,7 +1583,6 @@ if ($renderizar) { ?> [ 'name' => 'v_numero', 'type' => 'text', - 'required' => 'optional', 'id' => 'v_numero', 'value' => ($inseri_voice == 0) ? $v_numero : null, 'size' => '15', @@ -1604,7 +1597,6 @@ if ($renderizar) { ?> [ 'name' => 'v_nome', 'type' => 'text', - 'required' => 'optional', 'id' => 'v_nome', 'value' => ($inseri_voice == 0) ? $v_nome : null, 'size' => '30', @@ -1619,7 +1611,6 @@ if ($renderizar) { ?> [ 'name' => 'v_senha', 'type' => 'password', - 'required' => 'optional', 'id' => 'v_senha', 'value' => ($inseri_voice == 0) ? $v_senha : null, 'size' => '10', @@ -1641,9 +1632,8 @@ if ($renderizar) { ?> 'name' => 'v_email', 'autocomplete' => 'off', 'type' => 'text', - 'required' => 'optional', 'id' => 'v_email3', - 'value' => ($acao == 'edita') ? $v_email : null, + 'value' => ($acao == "edita") ? $v_email : null, 'size' => '30', ] ] @@ -1658,7 +1648,7 @@ if ($renderizar) { ?> 'type' => 'checkbox', 'id' => 'envelope', 'value' => 'yes', - 'checked' => (($inseri_voice == 0) && ($envelope == 'yes')) || ($inseri_voice != 0) ? true : false, + 'checked' => (($inseri_voice == 0) && ($envelope == "yes")) || ($inseri_voice != 0) ? true : false, ] ] ], @@ -1672,7 +1662,7 @@ if ($renderizar) { ?> 'type' => 'checkbox', 'id' => 'attach', 'value' => 'yes', - 'checked' => (($inseri_voice == 0) && ($attach == 'yes')) || ($inseri_voice != 0) ? true : false, + 'checked' => (($inseri_voice == 0) && ($attach == "yes")) || ($inseri_voice != 0) ? true : false, ] ] ], @@ -1693,7 +1683,7 @@ if ($renderizar) { ?> 'type' => 'checkbox', 'id' => 'saycid', 'value' => 'yes', - 'checked' => (($inseri_voice == 0) && ($saycid == 'yes')) || ($inseri_voice != 0) ? true : false, + 'checked' => (($inseri_voice == 0) && ($saycid == "yes")) || ($inseri_voice != 0) ? true : false, ] ] ], @@ -1707,7 +1697,7 @@ if ($renderizar) { ?> 'type' => 'checkbox', 'id' => 'delete', 'value' => 'yes', - 'checked' => (($inseri_voice == 0) && ($delete == 'yes')) || ($inseri_voice != 0) ? true : false, + 'checked' => (($inseri_voice == 0) && ($delete == "yes")) || ($inseri_voice != 0) ? true : false, ] ] ], @@ -1799,6 +1789,10 @@ if ($renderizar) { ?> 'div-collapse-id' => 'collapseChefeSec', 'conteudo' => [ [ + 'abrir-div' => [ + 'class' => '', + 'style' => 'margin-top: 35px;', + ], 'titulo' => 'Ramal Secretária', 'tipo' => 'normal', 'classes' => 'toggle', @@ -1807,11 +1801,12 @@ if ($renderizar) { ?> 'name' => 'ramalSecretaria', 'type' => 'text', 'id' => 'ramalSecretaria', - 'value' => ($acao == 'edita') ? $ramalSecretaria : null, + 'value' => ($acao == "edita") ? $ramalSecretaria : null, ] ] ], [ + 'fechar-div' => 'teste', 'titulo' => 'Exeções', 'classes' => 'toggle', 'tipo' => 'normal', @@ -1833,11 +1828,13 @@ if ($renderizar) { ?> 'name' => 'btIncluirRamalExecao', 'onClick' => 'incExcecao();', 'style' => 'cursor:pointer', + 'value' => '>', ], [ 'name' => 'btExcluirExcessao', 'onClick' => 'remExcecao();', 'style' => 'cursor:pointer', + 'value' => '<', ] ] ], @@ -1894,57 +1891,49 @@ if ($renderizar) { ?> document.getElementById('marcaTodos').checked = 'checked'; } - function LimpaImagem() { - $('#imgSim').attr("src", "imgSite/bullet-link-active.gif"); - $('#imgNao').attr("src", "imgSite/bullet-link-active.gif"); - $('#imgSenha').attr("src", "imgSite/bullet-link-active.gif"); - $('#imgAgente').attr("src", "imgSite/bullet-link-active.gif"); - } - - $("#simCheck").mouseover(function() { - $(this).css("cursor", "pointer"); - }); - $("#naoCheck").mouseover(function() { - $(this).css("cursor", "pointer"); - }); - $("#senhaCheck").mouseover(function() { - $(this).css("cursor", "pointer"); - }); - $("#agenteCheck").mouseover(function() { - $(this).css("cursor", "pointer"); - }); + document.addEventListener('DOMContentLoaded', function() { + var simCheck = document.getElementById('simCheck'); - $(document).ready(function() { - $('#simCheck').click(function() { - $('.tipoRotaSim').attr("checked", true); - LimpaImagem(); - $('#imgSim').attr("src", "imgSite/bullet-link-hover.gif"); + simCheck.addEventListener('click', function() { + var tipoRotaSim = document.querySelectorAll('.tipoRotaSim'); + for (var i = 0; i < tipoRotaSim.length; i++) { + tipoRotaSim[i].checked = true; + } }); }); - $(document).ready(function() { - $('#naoCheck').click(function() { - $('.tipoRotaNao').attr("checked", true); - LimpaImagem(); - $('#imgNao').attr("src", "imgSite/bullet-link-hover.gif"); - }); + document.addEventListener('DOMContentLoaded', function() { + var naoCheck = document.getElementById('naoCheck'); + + naoCheck.addEventListener('click', function() { + var tipoRotaNao = document.querySelectorAll('.tipoRotaNao'); + for (var i = 0; i < tipoRotaNao.length; i++) { + tipoRotaNao[i].checked = true; + } + }) }); - $(document).ready(function() { - $('#senhaCheck').click(function() { - $('.tipoRotaSenha').attr("checked", true); - LimpaImagem(); - $('#imgSenha').attr("src", "imgSite/bullet-link-hover.gif"); - }); + document.addEventListener('DOMContentLoaded', function() { + var senhaCheck = document.getElementById('senhaCheck'); + + senhaCheck.addEventListener('click', function() { + var tipoRotaSenha = document.querySelectorAll('.tipoRotaSenha'); + for (var i = 0; i < tipoRotaSenha.length; i++) { + tipoRotaSenha[i].checked = true; + } + }) }); - $(document).ready(function() { - $('#agenteCheck').click(function() { - $('.tipoRotaAgente').attr("checked", true); - LimpaImagem(); - $('#imgAgente').attr("src", "imgSite/bullet-link-hover.gif"); - }); - }) + document.addEventListener('DOMContentLoaded', function() { + var agenteCheck = document.getElementById('agenteCheck'); + + agenteCheck.addEventListener('click', function() { + var tipoRotaAgente = document.querySelectorAll('.tipoRotaAgente'); + for (var i = 0; i < tipoRotaAgente.length; i++) { + tipoRotaAgente[i].checked = true; + } + }) + }); diff --git a/admin/css/cadRamal.css b/admin/css/cadRamal.css index c7729c3e..fa87c4e9 100755 --- a/admin/css/cadRamal.css +++ b/admin/css/cadRamal.css @@ -64,7 +64,7 @@ select[multiple] { } .container-content { - width: 74%; + width: 75%; flex: 1; } @@ -407,7 +407,7 @@ input[type="radio"], input[type="checkbox"] { max-width: 14px; height: 14px; - margin: 0 4px; + margin: 0; } .switch { @@ -489,4 +489,10 @@ input:checked+.slider:before { width: 78%; flex: 1; } +} + +@media screen and (min-width: 850px) { + .container-content { + width: 94%; + } } \ No newline at end of file diff --git a/include/util/funcoesApl.php b/include/util/funcoesApl.php index 790f49e2..67d03681 100755 --- a/include/util/funcoesApl.php +++ b/include/util/funcoesApl.php @@ -2165,19 +2165,38 @@ function GetObsProdAgente($db = null, $dac = 0) * Chefe Secretária */ -function InsereRamaisChf($conn, $ramal) +function InsereRamaisChf($conn, $ramal, $org_id) { - $excecoes = $_POST['ramalSecExcecoesInc']; + try { + $excecoes = $_POST['ramalSecExcecoesInc']; - $query = "delete from pbx_chefe_secretaria where numero = '$ramal'"; - pg_query($conn, $query); + // Prevenção contra injeção de SQL no DELETE + $query_delete = "DELETE FROM pbx_chefe_secretaria WHERE numero = $1 AND org_id = $2"; + $result_delete = pg_query_params($conn, $query_delete, array($ramal, $org_id)); - foreach ($excecoes as $exc) { - global $idProg; - $query = "insert into pbx_chefe_secretaria(numero, excecao)values('$ramal', '$exc');"; - pg_query($conn, $query); - $novo = array('numero' => $ramal, 'excecao' => $exc); - GrvAudita($conn, $idProg, 'pbx_chefe_secretaria', 'INS', array(), $novo, array('numero', 'excecao'), array('numero'), true); + if (!$result_delete) { + throw new Exception("Erro ao deletar registros."); + } + + foreach ($excecoes as $exc) { + global $idProg; + + // Prevenção contra injeção de SQL no INSERT + $query_insert = "INSERT INTO pbx_chefe_secretaria(numero, excecao, org_id) VALUES ($1, $2, $3)"; + $result_insert = pg_query_params($conn, $query_insert, array($ramal, $exc, $org_id)); + + if (!$result_insert) { + throw new Exception("Erro ao inserir exceção."); + } + + $novo = array('numero' => $ramal, 'excecao' => $exc, 'org_id' => $org_id); + + // Função GrvAudita deve garantir a segurança ao manipular as informações. + GrvAudita($conn, $idProg, 'pbx_chefe_secretaria', 'INS', array(), $novo, array('numero', 'excecao'), array('numero'), true); + } + } catch (Exception $e) { + // Tratamento de exceção + echo "Erro: " . $e->getMessage(); } }