Browse Source

Merge pull request 'Páginas de pesquisa carregando mais rápido, implementei botão de excluir opção da pesquisa.' (#4) from Claudio/pabx-pesquisa:dev into master

Reviewed-on: SimplesIP/pabx-pesquisa#4
master
Claudio 4 months ago
parent
commit
e16d1d9e75
  1. 8
      .vscode/settings.json
  2. 12
      etc_asterisk/extensions_rotas_entrada.conf
  3. 4
      www/html/aplicativo/cadastros/pesquisa/pesquisa.php
  4. 123
      www/html/aplicativo/cadastros/pesquisa/pesquisaCad.php
  5. 29
      www/html/aplicativo/cadastros/pesquisa/pesquisaFuncoes.php
  6. 113
      www/html/aplicativo/cadastros/pesquisa/pesquisaRel.php
  7. 494
      www/html/aplicativo/contacteFunc.php
  8. 545
      www/html/aplicativo/scriptApl/pesquisa/index.js

8
.vscode/settings.json vendored

@ -0,0 +1,8 @@
{
"editor.tabSize": 4,
"files.encoding": "iso88591",
"[javascript]": {
"editor.tabSize": 4,
},
"prettier.tabWidth": 4
}

12
etc_asterisk/extensions_rotas_entrada.conf

@ -1,6 +1,6 @@
[entrada-VEIRTA-SIP]
include => entrada-VEIRTA-SIP-custom
exten => _90XX,1,Set(CDR(direcao)=E)
exten => _90XX,n,Set(__TIPO=EXTERNA)
exten => _90XX,n,AGI(${INTEGRACAO},7,${IF($[ "X${CALLERID(NUM)}" = "X" ]? "-" : ${CALLERID(NUM):-11})},${UNIQUEID},${IDORIGEM},${URA})
exten => _90XX,n,Hangup()
[entrada-VERITA_LOCAL]
include => entrada-VERITA_LOCAL-custom
exten => _9XXX,1,Set(CDR(direcao)=E)
exten => _9XXX,n,Set(__TIPO=EXTERNA)
exten => _9XXX,n,AGI(${INTEGRACAO},7,${IF($[ "X${CALLERID(NUM)}" = "X" ]? "-" : ${CALLERID(NUM):-11})},${UNIQUEID},${IDORIGEM},${URA})
exten => _9XXX,n,Hangup()

4
www/html/aplicativo/cadastros/pesquisa/pesquisa.php

@ -212,7 +212,6 @@ function preparaClonarPesquisa($ppId)
$jsJQuery[] = "let isCloning = true;";
pg_query($dbcon, 'commit;');
}
function existeClonagemProcessando($ppId)
@ -229,7 +228,8 @@ function existeClonagemProcessando($ppId)
}
}
function isCloning($dbcon){
function isCloning($dbcon)
{
$query = "SELECT COUNT(*) AS clone FROM pbx_pesquisa_clone";
$result = pg_query($dbcon, $query);
$response = pg_fetch_assoc($result);

123
www/html/aplicativo/cadastros/pesquisa/pesquisaCad.php

@ -6,8 +6,9 @@
$fields['user_reg'] = $_SESSION['SSlogin'];
$tpLayout = 1;
$upload = 1;
$path = "/var/log/asterisk/pesquisa_cad.log";
define("LOG_PATH", "/var/log/asterisk/pesquisa_cad.log");
$jsJQuery[] = '$("#msg_pesquisa").text("");';
fopen($path, 'a');
try {
@ -25,6 +26,16 @@
__apiJson(['error' => true, 'message' => 'Error!']);
}
}
if ($action == 'delOption') {
file_put_contents(LOG_PATH, "\nBotao delOption pressionado!\n", FILE_APPEND);
$isDeleted = __deleteOption($fields['pp_id'], $fields['pq_index'], $fields['po_index']);
if ($isDeleted) {
__apiJson(['error' => false, 'message' => 'sucesso!']);
} else {
__apiJson(['error' => true, 'message' => 'Error!']);
}
}
exit();
}
@ -79,13 +90,14 @@
* @return array
* @throws Exception
*/
function __questoes($fields) {
function __questoes($fields)
{
$opcoes = [];
foreach ($fields['qst_descricao'] as $k => $opc) {
$multAudio = count($_FILES['pp_audio']['name'][$k]) > 1 ? 1 : 0;
$opcoes[$k] = [
'pq_id' => $fields['count_descricao'][$k],
'pq_tipo' => $fields['pqt_id'] == 2 ? 2 : isset($fields['pq_tipo'][$k]) ? 2 : 1,
'pq_tipo' => $fields['pqt_id'] == 2 ? 2 : (isset($fields['pq_tipo'][$k]) ? 2 : 1),
'pqt_id' => $fields['pqt_id'],
'pq_questao' => $opc[0],
'pq_display' => $k,
@ -111,7 +123,8 @@
return $opcoes;
}
function __audioPesquisa($ppId) {
function __audioPesquisa($ppId)
{
$files = ['pp_audio_saudacao' => 'sauda', 'pp_audio_encerramento' => 'encerra'];
$msgErro = '';
@ -131,7 +144,8 @@
return ($msgErro == '');
}
function __audioQuestao($ppId, $pq_id, $display) {
function __audioQuestao($ppId, $pq_id, $display)
{
$msgErro = '';
foreach ($_FILES as $k => $v) {
if ($k != 'pp_audio') {
@ -147,7 +161,7 @@
$multAudio = null;
if ($y > 0) {
$multAudio = strtolower(LimpaString(str_replace(' ', '_', $nameFile), false,  false));
$multAudio = strtolower(LimpaString(str_replace(' ', '_', $nameFile), false, false));
}
$nameFileNew = RemoveEspaco(sprintf("pesquisa_questao_%s_%s%s.mp3", $ppId, $pq_id, ($multAudio ? "_{$multAudio}" : "")));
MoveFile($tmpName, $nameFile, $nameFileNew, true, $msgErro);
@ -157,7 +171,8 @@
return ($msgErro == '');
}
function __getImgAudios($ppId, $pqId = null, $saudacao = false, $pq_display = null) {
function __getImgAudios($ppId, $pqId = null, $saudacao = false, $pq_display = null)
{
$aud = $pqId ? "&pq_id=$pqId" : '';
$sauda = $saudacao ? "&sauda=1" : '';
$imgAudio = "<img src=\"imgSite/sound22.png\" width=\"22\" height=\"22\" border=\"0\" align=\"absmiddle\">";
@ -165,7 +180,8 @@
return $imgAudio;
}
function __selectQuestoes($params, $isValid = false) {
function __selectQuestoes($params, $isValid = false)
{
$dados = __getQuestoes($params['pp_id']);
$ret = sprintf('<select %s name="qst_opcoes[%s][%s]" style="width: 150px" title="Selecione o uma da questao">\n', $isValid, $params['pq_display'], $params['po_display']);
@ -197,7 +213,8 @@
return $ret;
}
function __selectTipo($tipo = null){
function __selectTipo($tipo = null)
{
$dados = __getTipo();
$readonly = $tipo ? "disabled" : '';
@ -212,7 +229,8 @@
}
function __apiJson($array) {
function __apiJson($array)
{
if ($array['error'] == false) {
header("HTTP/1.1 200 OK");
} else {
@ -225,7 +243,8 @@
### BANCO DE DADOS ###
##############################
function __pesquisa($fields, $id = null) {
function __pesquisa($fields, $id = null)
{
$pesquisa = [
'pp_nome' => $fields['pp_nome'],
'pp_audio_saudacao' => $_FILES['pp_audio_saudacao']['name'],
@ -263,7 +282,8 @@
return $pqId['pp_id'];
}
function __pesquisaQuestao($ppId, $dados) {
function __pesquisaQuestao($ppId, $dados)
{
if (empty($ppId)) {
throw new Exception("Pesquisa não foi localizada!");
@ -329,7 +349,8 @@
return true;
}
function __pesquisaOpcao($ppId, $pqId, $dados) {
function __pesquisaOpcao($ppId, $pqId, $dados)
{
foreach ($dados['opcoes'] as $k => $v) {
$v['pp_id'] = $ppId;
$v['pq_id'] = $pqId;
@ -370,7 +391,8 @@
return false;
}
function __getPesquisa($ppId) {
function __getPesquisa($ppId)
{
$sql = "SELECT *,
(SELECT count(pq_display) FROM pbx_pesquisa_questoes WHERE pp_id = a.pp_id) AS count_qst,
(SELECT count(po_display) FROM pbx_pesquisa_opcoes WHERE pq_id = b.pq_id) AS count_opc
@ -389,14 +411,16 @@
return $resp;
}
function __getPesquisaMovimento($ppId) {
function __getPesquisaMovimento($ppId)
{
$sql = "SELECT count(*) as movimento FROM pbx_pesquisa_movimento WHERE pp_id = {$ppId}";
$result = pg_query($GLOBALS["dbcon"], $sql);
$resp = pg_fetch_assoc($result);
return $resp['movimento'];
}
function __getQuestoes($ppId) {
function __getQuestoes($ppId)
{
$sql = "SELECT *
FROM pbx_pesquisa_questoes a
INNER JOIN pbx_pesquisa_opcoes b ON a.pq_id = b.pq_id
@ -411,7 +435,8 @@
return $resp;
}
function __deleteQuestao($ppId, $pqId) {
function __deleteQuestao($ppId, $pqId)
{
if (__getPesquisaMovimento($ppId)) {
throw new Exception('A pesquisa possui dados que não poderão ser excluídos.');
@ -440,7 +465,8 @@
* @param type $ppId
* @param type $pqId
*/
function __deleteOptionTipo($ppId, $pqId){
function __deleteOptionTipo($ppId, $pqId)
{
$query = "SELECT po_id FROM pbx_pesquisa_opcoes WHERE pp_id = {$ppId} AND pq_id = {$pqId} AND po_tecla > 1;";
$result = pg_query($GLOBALS["dbcon"], $query);
$dados = pg_fetch_all($result);
@ -453,7 +479,8 @@
}
}
function __getTipo(){
function __getTipo()
{
$sql = "SELECT * FROM pbx_pequisa_tipo;";
$result = pg_query($GLOBALS["dbcon"], $sql);
$resp = pg_fetch_all($result);
@ -464,11 +491,46 @@
return null;
}
/** Deleta questao, baseado nos indices da questao e da opcao.
*
* @param type $ppId,
* @param type $qIndex,
* @param type $oIndex
*/
function __deleteOption($ppId, $qIndex, $oIndex)
{
if (__getPesquisaMovimento($ppId)) {
throw new Exception('A pesquisa possui dados que não poderão ser excluídos.');
}
$sql = "DELETE FROM pbx_pesquisa_opcoes WHERE po_id IN
(
SELECT po_id FROM pbx_pesquisa_questoes a
INNER JOIN pbx_pesquisa_opcoes b ON a.pq_id = b.pq_id
WHERE a.pp_id = $ppId
AND a.pq_display = $qIndex
AND b.po_display = $oIndex
)
";
file_put_contents(LOG_PATH, "Iniciando query: $sql\n", FILE_APPEND);
if (!pg_query($GLOBALS["dbcon"], $sql)) {
file_put_contents(LOG_PATH, "Query falhou\n", FILE_APPEND);
throw new Exception('Não foi possível excluir a opção!');
}
file_put_contents(LOG_PATH, "Query bem sucedida\n", FILE_APPEND);
return true;
}
##############################
### TEMPLATE ###
##############################
function __template($dados, $movimento = null) {
function __template($dados, $movimento = null)
{
$isValid = $movimento ? 'disabled' : '';
$table = '';
@ -478,6 +540,8 @@
$lastPq_id = null;
foreach ($dados as $k => $v) {
$slc = __selectQuestoes($v, $isValid);
//esse 'if' so sera executado uma vez por questao. Seu conteudo insere a todo o cabecalho da questao.
if ($lastPq_id != $v['pq_id']) {
$lastPq_id = $v['pq_id'];
$countPq_id++;
@ -567,13 +631,29 @@
</div>';
}
$deleteBtn = '';
//sea pesquia nao tiver movimentos,
if (!__getPesquisaMovimento($v['pp_id'])) {
// botao de excluir opcao. So sera inserido se a opção for a ultima.
$deleteBtn = ($v['count_opc'] == $v['po_display']) && $v['count_opc'] > 2 ? '<a href="#" id="delOp_' .
$v['pq_display'] .
"|" .
$v['po_display'] .
'" ><img id="delOpc_' .
$v['pq_display'] .
"|" .
$v['po_display'] .
'" src="imgSite/fecha16.png" width="12" height="12" border="0" align="absmiddle"></a>' : '';
}
//lista de opcoes da questao
$table .= '<tr>
<td colspan="3">
&nbsp;&nbsp;
<input name="po_id[' . $countPq_id . '][' . $v['po_display'] . ']" type="number" value="' . $v['po_id'] . '" hidden="true" />
' . $v['po_display'] . ') <input name="qst_tecla[' . $countPq_id . '][' . $v['po_display'] . ']" class="qst_tecla" type="number" value="' . $v['po_tecla'] . '" size="4" maxlength="2" min="0" max="999" required style="width:60px" ' . $isValid . '>
<input name="qst_descricao[' . $countPq_id . '][' . $v['po_display'] . ']" type="text" value="' . $v['po_opcao'] . '" title="Descreva aqui a opção" size="50" style="width:360px" maxlength="60" ' . $isValid . ' required>
' . $slc . '
' . $slc . $deleteBtn . '
</td>
</tr>';
}
@ -597,4 +677,3 @@
font-style: italic;
}
</style>';
?>

29
www/html/aplicativo/cadastros/pesquisa/pesquisaFuncoes.php

@ -4,10 +4,19 @@
* Function interna
*/
function GetPesquisaRel($db, $plId, $matricula = null) {
define("LOG_PATH", '/var/log/asterisk/relatorio_pesquisaRel.log');
function GetPesquisaRel($db, $plId, $matricula = null)
{
$ret = "";
$sel = "";
$query = sprintf("SELECT DISTINCT a.pl_id, pl_descricao, pl_data_inicio, pl_data_fim, b.pp_id, b.pp_nome
//reduzi os filtros da query porque estava extremamente lenta, demorando 300 segundos para executar.
$query = "SELECT a.pl_id, pl_descricao, pl_data_inicio, pl_data_fim, b.pp_id, b.pp_nome
FROM pbx_pesquisa_liberacao a
INNER JOIN pbx_pesquisa b ON a.pp_id = b.pp_id
ORDER BY a.data_reg DESC";
//query antiga
/* $query = sprintf("SELECT DISTINCT a.pl_id, pl_descricao, pl_data_inicio, pl_data_fim, b.pp_id, b.pp_nome
FROM pbx_pesquisa_liberacao a
INNER JOIN pbx_pesquisa b ON a.pp_id = b.pp_id
INNER JOIN pbx_pesquisa_movimento f ON a.pp_id = f.pp_id
@ -16,9 +25,12 @@ function GetPesquisaRel($db, $plId, $matricula = null) {
INNER JOIN pbx_fila_grupos e ON e.gp_id = d.gp_id
WHERE EXISTS(SELECT '' FROM pbx_pesquisa_movimento WHERE pl_id = a.pl_id AND e.id = id_dac)
%s", $matricula ? " and c.matricula = '$matricula'" : "");
$query .= " ORDER BY b.pp_nome";
$query .= " ORDER BY a.data_reg DESC"; */
//$query .= " ORDER BY b.pp_nome";
$result = pg_query($db, $query);
file_put_contents(LOG_PATH, "\nQuery: $query\n", FILE_APPEND);
if (!$plId) {
$ret = '<option value="0" selected="selected">---------------------</option>';
}
@ -31,7 +43,8 @@ function GetPesquisaRel($db, $plId, $matricula = null) {
return $ret;
}
function GetDadosPesq($db, $lst, &$plId, &$plDescricao, &$ppId, &$ppNome, &$datas) {
function GetDadosPesq($db, $lst, &$plId, &$plDescricao, &$ppId, &$ppNome, &$datas)
{
$dados = explode("|", $lst);
$plId = $dados[0];
$plDescricao = $dados[1];
@ -41,7 +54,8 @@ function GetDadosPesq($db, $lst, &$plId, &$plDescricao, &$ppId, &$ppNome, &$data
$ppNome = $dados[5];
}
function GetPesquisaDac($db, $idDac) {
function GetPesquisaDac($db, $idDac)
{
$ret = "";
$sel = "";
$login = GetLogin();
@ -67,7 +81,8 @@ function GetPesquisaDac($db, $idDac) {
return $ret;
}
function GetPesquisaAgente($db, $plId, $matricula, $idDac, $dtIni, $dtFim, $incTodos) {
function GetPesquisaAgente($db, $plId, $matricula, $idDac, $dtIni, $dtFim, $incTodos)
{
$ret = "";
$sel = "";
$dataIni = soNumero($dtIni) == "" ? "null" : "'$dtIni'";
@ -104,5 +119,3 @@ function GetPesquisaAgente($db, $plId, $matricula, $idDac, $dtIni, $dtFim, $incT
$ret = '<option value="0" selected="selected">---------------------</option>';
return $ret;
}
?>

113
www/html/aplicativo/cadastros/pesquisa/pesquisaRel.php

@ -3,7 +3,8 @@
include_once 'util/relatoriosBase.php';
require("pesquisaFuncoes.php");
class RelPesquisa extends Relatorios {
class RelPesquisa extends Relatorios
{
private $___lstPesquisa = '';
private $___plId;
@ -13,28 +14,36 @@
private $___tipoRelatorio;
private $___datas = array();
private $dataKing;
const LOG_PATH = '/var/log/asterisk/relatorio_pesquisaRel.log';
public function __construct($idProg, $dbcon, $incDac) {
public function __construct($idProg, $dbcon, $incDac)
{
parent::__construct($idProg, $dbcon, $incDac);
$this->___dac = isset($_POST["listaDacs"]) ? $_POST["listaDacs"] : 0;
$this->___lstPesquisa = isset($_POST["lstPesquisa"]) ? $_POST["lstPesquisa"] : '0| | | |0| ';
$this->___tipoRelatorio = 1;
file_put_contents(self::LOG_PATH, "\n\n################## INICIANDO LOG RELATORIO DE PESQUISA ##################\n", FILE_APPEND);
}
private function setPlID(){
private function setPlID()
{
if ($this->___lstPesquisa) {
$this->___plId = explode('|', $this->___lstPesquisa)[0];
}
}
function ___FiltrosRelatorio() {
//essa funcao esta levando minutos para executar
function ___FiltrosRelatorio()
{
file_put_contents(self::LOG_PATH, "\n\n*********** DENTRO DE ___FiltrosRelatorio() ***********\n", FILE_APPEND);
//seta o id da pesquisa cujo relatorio sera gerado, na var $___ppId.
$this->setPlID();
$lstPesquisa = GetPesquisaRel($this->GetDbCon(), $this->___plId);
if ($this->___media != MEDIA_PRINT_GRID) {
/*
* Recupera os filtros da sessao do usuario.
*/
file_put_contents(self::LOG_PATH, "\nMIDIA NAO EH GRID\n", FILE_APPEND);
// Recupera os filtros da sessao do usuario.
list($this->___dac, $this->___dataIni, $this->___dataFim) = $_SESSION["SSstorageFiltros"];
if ($this->___media == MEDIA_PRINT_HTML) {
@ -53,12 +62,15 @@
return $fltCsv;
}
file_put_contents(self::LOG_PATH, "\nMidia eh gid. buscando DAC...", FILE_APPEND);
//Retorna HTML select com a lista de filas disponiveis ao usuario.
if ($this->GetIncDac()) {
$dacs = GetDac($this->GetDbCon(), $this->___dac, "", 0, 1, 0, 0, 1);
}
$lkPrint = "";
if ($this->___dataCount) {
file_put_contents(self::LOG_PATH, "\nGerando link de exel.", FILE_APPEND);
$prt = '<a href="index.php?idProg=%s&media=%s&tipoRelatorio=%s&download=Excel&pesquisa=%s"><img src="imgSite/%s" alt="Clique aqui para imprimir!" width="24" height="24" border="0"></a>';
if ($this->getPermissao()) {
@ -74,6 +86,8 @@
/*
* Personalise esta funcao se necessitar de outras opnioes de filtro.
*/
file_put_contents(self::LOG_PATH, "\nGerando HTML do filtro...", FILE_APPEND);
$filtro = '<table border="0" cellspacing="1" cellpadding="1">';
/*
* Rotulos.
@ -107,10 +121,12 @@
*/
$_SESSION["SSstorageFiltros"] = array($this->___dac, $this->___dataIni, $this->___dataFim, $this->___tipoRelatorio);
file_put_contents(self::LOG_PATH, "\nRetornando HTML filtro...\n", FILE_APPEND);
return sprintf($filtro, $this->___dataIni, $this->___dataFim, $lkPrint);
}
protected function ___GetDadosDb($pqId = null) {
protected function ___GetDadosDb($pqId = null)
{
$dataIni = FormatDtMssql($this->___dataIni);
$dataFim = FormatDtMssql($this->___dataFim);
$plId = $this->___plId;
@ -218,11 +234,12 @@
}
}
protected function ___PreparaCsv() {
protected function ___PreparaCsv()
{
}
protected function ___PreparaExcel() {
protected function ___PreparaExcel()
{
$dataRel = array();
$filtro = $this->___FiltrosRelatorio();
@ -357,7 +374,8 @@
$this->___dataRel[] = $dataRel;
}
protected function ___PreparaGrid() {
protected function ___PreparaGrid()
{
/*
* Inicia o relatório.
@ -529,18 +547,18 @@
$dataRel[] = '</table>';
$this->___dataRel[] = $dataRel;
}
protected function ___PreparaHtml() {
protected function ___PreparaHtml()
{
}
protected function ___PreparaPdf() {
protected function ___PreparaPdf()
{
}
private function __PerguntaResposta($perguntas, $respostas){
private function __PerguntaResposta($perguntas, $respostas)
{
$total = count(explode(';', $perguntas));
$json = sprintf('{%s"}', RemoveAcentos($respostas));
$resps = json_decode($json, true);
@ -556,7 +574,8 @@
return $newResponse;
}
protected function __CalculaPorcentagem($coluna, $array) {
protected function __CalculaPorcentagem($coluna, $array)
{
$somaQtd = 0;
foreach ($array as $value) {
if ($value['pq_questao'] == $coluna) {
@ -570,12 +589,15 @@
* Cria uma conexao com a base de dados do king
* @throws Exception
*/
protected function connectMysql() {
protected function connectMysql()
{
$data = $this->GetConfKing();
try {
$instance = new PDO("mysql:host={$data['king_host']};dbname={$data['king_base']}",
$instance = new PDO(
"mysql:host={$data['king_host']};dbname={$data['king_base']}",
$data['king_user'],
$data['king_password']);
$data['king_password']
);
$instance->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
return $instance;
} catch (Exception $ex) {
@ -588,14 +610,16 @@
* @global type $dbcon
* @return array
*/
protected function GetConfKing() {
protected function GetConfKing()
{
global $dbcon;
$query = "SELECT * FROM pbx_kingdialer_config WHERE id_king = 1";
$result = pg_query($dbcon, $query);
return pg_fetch_assoc($result);
}
protected function getDataKing(){
protected function getDataKing()
{
$conect = $this->connectMysql();
$this->setPlID();
$plId = $this->___plId;
@ -625,7 +649,8 @@
}
}
private function getPermissao(){
private function getPermissao()
{
$query = sprintf("SELECT fun_id FROM pbx_usuarios a
INNER JOIN pbx_grupo_usuario b ON a.id = b.user_id
INNER JOIN pbx_grupo_funcoes c ON c.gp_id = b.gp_id
@ -639,43 +664,51 @@
return false;
}
public function ExecutaRelatorio() {
public function ExecutaRelatorio()
{
global $jsStartup, $jsJQuery, $smarty, $dbcon;
try {
/*
* Use esta função para validar dados do formulário.
*/
file_put_contents(self::LOG_PATH, "\nVai validar", FILE_APPEND);
//Use esta funcao para validar dados do relatorio
$this->___ValidaForm();
/*
* Recupera os dados do banco.
*/
file_put_contents(self::LOG_PATH, "\nValidou. Vai recuperar do banco.", FILE_APPEND);
// Recupera os dados do banco.
$this->___ConteudoRelatorio();
file_put_contents(self::LOG_PATH, "\nRecuperou. Vai imprimir o relatorio.", FILE_APPEND);
/*
* Imprime relatório de acordo com a media passada.
*/
// Imprime relatório de acordo com a media passada.
// Imprime relatório de acordo com a media passada.
$conteudoRelatorio = $this->___ImprimeRelatorio();
file_put_contents(self::LOG_PATH, "\nImprimiu.\n", FILE_APPEND);
} catch (Exception $exc) {
$this->SetMsg($exc->getMessage());
$jsStartup[] = sprintf("alert('%s');", $this->GetMsg());
$this->___GravaLog();
}
/*
* Inclua os scripts necessários aqui.
*/
//Inclua os scripts necessários aqui.
//Inclua os scripts necessários aqui.
$jsJQuery[] = "\$('#dataIni').keypress(function(){formataDataHora(this);}) ";
$jsJQuery[] = "\$('#dataFim').keypress(function(){formataDataHora(this);}) ";
$smarty->assign('filtros', $this->___FiltrosRelatorio());
file_put_contents(self::LOG_PATH, "\nVai adicionar os filtros ao template.", FILE_APPEND);
$smarty->assign('filtros', $this->___FiltrosRelatorio()); // <-- ta demorando minutos nessa parte
file_put_contents(self::LOG_PATH, "\nFiltros adicionados. Adicionando conteudo.", FILE_APPEND);
$smarty->assign('conteudo', $conteudoRelatorio);
file_put_contents(self::LOG_PATH, "\nConteudo adicionado. Adicionando mensagem.", FILE_APPEND);
$smarty->assign('msg', $this->GetMsg());
file_put_contents(self::LOG_PATH, "\nMensagem adicionada. Vai template!!!", FILE_APPEND);
GetTemplate($smarty, 'relatoriosGrid.tpl');
file_put_contents(self::LOG_PATH, "\nO template jah foi meu filho...\n\n", FILE_APPEND);
}
}
$relPesquisa = new RelPesquisa($idProg, $dbcon, 1);
$relPesquisa->ExecutaRelatorio();

494
www/html/aplicativo/contacteFunc.php

File diff suppressed because it is too large Load Diff

545
www/html/aplicativo/scriptApl/pesquisa/index.js

@ -7,208 +7,310 @@ const request = ({ url, type, data }, handle) => {
error: function (err) {
console.log(err);
},
})
}
});
};
const buildResponse = (qst, opc) => {
return `<tr>
<td colspan="3"> &nbsp;&nbsp;
<input name="po_id[${qst}][${opc}]" type="number" value="791" hidden="true">
${opc}) <input name="qst_tecla[${qst}][${opc}]" class="qst_tecla" type="number" value="2" size="4" maxlength="2" min="0" max="999" required="" style="width:60px">
<input name="qst_descricao[${qst}][${opc}]" type="text" value="NÃO" title="Descreva aqui a opção" size="50" style="width:360px" maxlength="60" required="">
<input name="qst_descricao[${qst}][${opc}]" type="text" value="NãO" title="Descreva aqui a opção" size="50" style="width:360px" maxlength="60" required="">
</td>
</tr>`;
}
};
const optionResponse = (num, numEle) => {
$('#box' + num + ' input[name="qst_tecla[' + numEle + '][1]"]').prop('name', 'qst_tecla[' + num + '][1]')
$('#box' + num + ' input[name="qst_descricao[' + numEle + '][1]"]').prop('name', 'qst_descricao[' + num + '][1]')
$('#box' + num + ' input[name="qst_tecla[' + numEle + '][2]"]').prop('name', 'qst_tecla[' + num + '][2]')
$('#box' + num + ' input[name="qst_descricao[' + numEle + '][2]"]').prop('name', 'qst_descricao[' + num + '][2]')
if($("#pqt_id").val() == 2 && !$('#pp_id').val()){
$(`#tableResponse${num} tr:nth-last-child(1)`).remove()
$(`#box${num} #addResponse`+ numEle).remove()
$("#box" + num + ' input[name="qst_tecla[' + numEle + '][1]"]').prop("name", "qst_tecla[" + num + "][1]");
$("#box" + num + ' input[name="qst_descricao[' + numEle + '][1]"]').prop("name", "qst_descricao[" + num + "][1]");
$("#box" + num + ' input[name="qst_tecla[' + numEle + '][2]"]').prop("name", "qst_tecla[" + num + "][2]");
$("#box" + num + ' input[name="qst_descricao[' + numEle + '][2]"]').prop("name", "qst_descricao[" + num + "][2]");
if ($("#pqt_id").val() == 2 && !$("#pp_id").val()) {
$(`#tableResponse${num} tr:nth-last-child(1)`).remove();
$(`#box${num} #addResponse` + numEle).remove();
}
if ($('#count' + numEle).val() == 1) {
$("#tableResponse" + num).append(buildResponse(num, 2))
}
if ($("#count" + numEle).val() == 1) {
$("#tableResponse" + num).append(buildResponse(num, 2));
}
};
const __resizeForms = () => {
const elements = ['body']
elements.forEach(e => {
const elements = ["body"];
elements.forEach((e) => {
let alturaJanela = $(e).height();
let novaAltura = alturaJanela * 1.2;
let novaLargura = novaAltura * 1.5;
// window.resizeTo(novaLargura, novaAltura);
})
}
});
};
const createDeleteOptionBtn = (pq_index, po_index) => {
return $(
'<a href="#" id="delOp_' +
pq_index +
"|" +
po_index +
'" ><img id="delOpc_' +
pq_index +
"|" +
po_index +
'" src="imgSite/fecha16.png" width="12" height="12" border="0" align="absmiddle"></a>'
);
};
$(function () {
let ultimoEle = null
let ultimoEle = null;
const ppId = $("#pp_id").val();
$('.box').slideToggle('fast')
let el = document.getElementById('questions');
__resizeForms()
$(".box").slideToggle("fast");
let el = document.getElementById("questions");
__resizeForms();
if($('#pqt_id').prop('disabled')){
if ($("#pqt_id").prop("disabled")) {
$("#newquestion").show();
}
$('#pqt_id').change(function() {
$("#pqt_id").change(function () {
if ($(this).val() > 0) {
$("#labelQuestoes").show();
$("#newquestion").show();
$("#questions").show();
} else {
$("#labelQuestoes").hide()
$("#newquestion").hide()
$("#questions").hide()
$("#labelQuestoes").hide();
$("#newquestion").hide();
$("#questions").hide();
}
if ($(this).val() == 2) {
$('#addResponse1').hide()
$("#box1 #tableResponse1 tr:nth-last-child(1) td").hide()
$('#box1 input[name="qst_tecla[1][2]"]').hide()
$('#box1 input[name="qst_descricao[1][2]"]').hide()
$('#box1 #pq_tipo1').hide()
$('#box1 #pq_tipol1').hide()
$("#addResponse1").hide();
$("#box1 #tableResponse1 tr:nth-last-child(1) td").hide();
$('#box1 input[name="qst_tecla[1][2]"]').hide();
$('#box1 input[name="qst_descricao[1][2]"]').hide();
$("#box1 #pq_tipo1").hide();
$("#box1 #pq_tipol1").hide();
} else {
$('#addResponse1').show()
$("#box1 #tableResponse1 tr:nth-last-child(1) td").show()
$('#box1 input[name="qst_tecla[1][2]"]').show()
$('#box1 input[name="qst_descricao[1][2]"]').show()
$('#box1 #pq_tipo1').show()
$('#box1 #pq_tipol1').show()
$("#addResponse1").show();
$("#box1 #tableResponse1 tr:nth-last-child(1) td").show();
$('#box1 input[name="qst_tecla[1][2]"]').show();
$('#box1 input[name="qst_descricao[1][2]"]').show();
$("#box1 #pq_tipo1").show();
$("#box1 #pq_tipol1").show();
}
})
});
$('#btGravar').click(function () {
$('#formGeral').find('input[type="file"]').each(function () {
if (!$(this).val() && !$('#pp_id').val()) {
alert('Existe campos de áudios que não foram preenchidos, por favor, verifique todos os dados repassados!');
$("#btGravar").click(function () {
$("#formGeral")
.find('input[type="file"]')
.each(function () {
if (!$(this).val() && !$("#pp_id").val()) {
alert("Existe campos de áudios que não foram preenchidos, por favor, verifique todos os dados repassados!");
return;
}
});
});
el.addEventListener('click', function (e) {
if (e.target.id.indexOf('animate') >= 0) {
let numBox = e.target.id.replace('animate', '')
let box = $('#box' + numBox);
let qtdRow = $("#tableResponse" + numBox + " tr").length
$("#box" + numBox + " div.scrollingArea").height(320 + (Number(qtdRow) * 25))
if (box.is(':visible')) {
box.slideToggle('slow');
$('#' + e.target.id).attr("src", "imgSite/expand.jpg");
$('#labelRotas' + numBox).text(" Exibir Questão");
el.addEventListener("click", function (e) {
if (e.target.id.indexOf("animate") >= 0) {
let numBox = e.target.id.replace("animate", "");
let box = $("#box" + numBox);
let qtdRow = $("#tableResponse" + numBox + " tr").length;
$("#box" + numBox + " div.scrollingArea").height(320 + Number(qtdRow) * 25);
if (box.is(":visible")) {
box.slideToggle("slow");
$("#" + e.target.id).attr("src", "imgSite/expand.jpg");
$("#labelRotas" + numBox).text(" Exibir Questão");
} else {
$('#' + e.target.id).attr("src", "imgSite/collapse.jpg");
$('#labelRotas' + numBox).text(" Ocultar Questão");
box.slideToggle('slow');
$("#" + e.target.id).attr("src", "imgSite/collapse.jpg");
$("#labelRotas" + numBox).text(" Ocultar Questão");
box.slideToggle("slow");
}
}
if (e.target.id.indexOf('delOpc') >= 0) {
let numDelOpc = e.target.id.replace('delOpc_', '')
let nums = numDelOpc.split("|")
let ct = $("#count" + nums[0]).val()
$("#count" + nums[0]).val(Number(ct) - 1)
$("#tableResponse" + nums[0] + " tr:nth-last-child(1)").remove()
if (e.target.id.indexOf("delOpc") >= 0) {
e.preventDefault();
let numDelOpc = e.target.id.replace("delOpc_", "");
let nums = numDelOpc.split("|");
//nums[0]: indice da questao. Inicia com 1.
//nums[1]: indice da opcao
//requisicao ajax para excluir a questao do banco
request(
{
type: "POST",
url: `index.php?idProg=182&ajax=1&a=delOption`,
data: { pp_id: ppId, pq_index: nums[0], po_index: nums[1] },
},
function (res) {
if (res.error === false) {
// ct recebe o numero de opcoes que a pesquisa atual possui
let ct = $("#count" + nums[0]).val();
$("#count" + nums[0]).val(Number(ct) - 1);
$("#tableResponse" + nums[0] + " tr:nth-last-child(1)").remove();
if (ct > 3) {
$("#tableResponse" + nums[0] + ' tbody tr:nth-last-child(1) td').append(ultimoEle)
const deleteBtn = createDeleteOptionBtn(nums[0], nums[1] - 1);
$("#tableResponse" + nums[0] + " tbody tr:nth-last-child(1) td").append(deleteBtn);
}
} else {
window.alert("Não foi possível excluir a opção.");
}
}
);
if ($("#tableResponse" + nums[0] + " tr").length == 3) {
$("#pq_tipo" + nums[0]).show()
$("#pq_tipol" + nums[0]).show()
$("#pq_tipo" + nums[0]).show();
$("#pq_tipol" + nums[0]).show();
}
}
if (e.target.id.indexOf('addResponse') >= 0) {
e.preventDefault()
let numTable = e.target.id.replace('addResponse', '')
$('#pq_tipo' + numTable).hide()
$('#pq_tipol' + numTable).hide()
let ct = $("#count" + numTable).val()
if (e.target.id.indexOf("addResponse") >= 0) {
e.preventDefault();
let numTable = e.target.id.replace("addResponse", "");
$("#pq_tipo" + numTable).hide();
$("#pq_tipol" + numTable).hide();
let ct = $("#count" + numTable).val();
let htg = $("#box" + numTable + " .scrollingArea").height()
$("#box" + numTable + " div.scrollingArea").height(Number(htg) + 25)
let htg = $("#box" + numTable + " .scrollingArea").height();
$("#box" + numTable + " div.scrollingArea").height(Number(htg) + 25);
ct = ct > 1 ? ct : 2;
ct++
let strSpace = ct > 9 ? " &nbsp;" : " &nbsp;&nbsp; "
$("#tableResponse" + numTable).append('<tr><td colspan="3">' + strSpace + ct + ')\n\
<input name="po_id[' + numTable + '][' + ct + ']" type="number" value="" hidden="true">\n\
<input name="qst_tecla[' + numTable + '][' + ct + ']" class="qst_tecla" type="number" value="" size="4" maxlength="2" min="0" max="999" style="width:60px" required>\n\
<input name="qst_descricao[' + numTable + '][' + ct + ']" type="text" value="" title="Descreva aqui a opção" size="50" style="width:360px" maxlength="60" required>\n\
ct++;
let strSpace = ct > 9 ? " &nbsp;" : " &nbsp;&nbsp; ";
$("#tableResponse" + numTable).append(
'<tr><td colspan="3">' +
strSpace +
ct +
')\n\
<input name="po_id[' +
numTable +
"][" +
ct +
']" type="number" value="" hidden="true">\n\
<input name="qst_tecla[' +
numTable +
"][" +
ct +
']" class="qst_tecla" type="number" value="" size="4" maxlength="2" min="0" max="999" style="width:60px" required>\n\
<input name="qst_descricao[' +
numTable +
"][" +
ct +
']" type="text" value="" title="Descreva aqui a opção" size="50" style="width:360px" maxlength="60" required>\n\
</td>\n\
</tr>')
let novoEle = $('<a href="#" id="delOp_' + numTable + '|' + ct + '" ><img id="delOpc_' + numTable + '|' + ct + '" src="imgSite/fecha16.png" width=\"12\" height=\"12\" border=\"0\" align=\"absmiddle\"></a>')
$("#tableResponse" + numTable + ' tbody tr:nth-last-child(1) td').append(novoEle)
</tr>'
);
// novo botao de excluir opcao
let novoEle = $(
'<a href="#" id="delOp_' +
numTable +
"|" +
ct +
'" ><img id="delOpc_' +
numTable +
"|" +
ct +
'" src="imgSite/fecha16.png" width="12" height="12" border="0" align="absmiddle"></a>'
);
//removendo botao anterior de excluir opcao
const prev = ct - 1;
$("#delOp_" + numTable + "\\|" + prev).remove();
$("#tableResponse" + numTable + " tbody tr:nth-last-child(1) td").append(novoEle);
if (ct > 3) {
$(ultimoEle).remove()
$(ultimoEle).remove();
}
ultimoEle = novoEle
$("#count" + numTable).val(ct)
ultimoEle = novoEle;
$("#count" + numTable).val(ct);
}
if (e.target.id.indexOf('addAudio') >= 0) {
let q = e.target.id.replace('addAudio', '')
let v = $('#countAudio' + q).val() ? $('#countAudio' + q).val() : 1;
$('#audioQuestion' + q).append('<tr><td><span style="font-size: 12px"><b>Áudio (' + v + '):</b></span></td><td><input type="file" name="pp_audio[' + q + '][' + v + ']" title="Informe um audio para questão" size="40" style="width:560px" required/> &nbsp;&nbsp; <a href="#" id="delAudio' + v + '" title="DELETAR ÁUDIO"><img src="imgSite/fecha16.png" name="animate" width="13" height="13" align="absmiddle" id="deleteAudio' + q + '|' + v + '"/></a></td></tr>')
$('#countAudio' + q).val(Number(v) + 1)
let htg = $("#box" + q + " .scrollingArea").height()
$("#box" + q + " div.scrollingArea").height(Number(htg) + 25)
$('#delAudio' + (v - 1)).remove()
if (e.target.id.indexOf("addAudio") >= 0) {
let q = e.target.id.replace("addAudio", "");
let v = $("#countAudio" + q).val() ? $("#countAudio" + q).val() : 1;
$("#audioQuestion" + q).append(
'<tr><td><span style="font-size: 12px"><b>áudio (' +
v +
'):</b></span></td><td><input type="file" name="pp_audio[' +
q +
"][" +
v +
']" title="Informe um audio para questão" size="40" style="width:560px" required/> &nbsp;&nbsp; <a href="#" id="delAudio' +
v +
'" title="DELETAR ÁUDIO"><img src="imgSite/fecha16.png" name="animate" width="13" height="13" align="absmiddle" id="deleteAudio' +
q +
"|" +
v +
'"/></a></td></tr>'
);
$("#countAudio" + q).val(Number(v) + 1);
let htg = $("#box" + q + " .scrollingArea").height();
$("#box" + q + " div.scrollingArea").height(Number(htg) + 25);
$("#delAudio" + (v - 1)).remove();
}
if (e.target.id.indexOf('deleteAudio') >= 0) {
let q = e.target.id.replace('deleteAudio', '').split("|")
let v = $('#countAudio' + q[0]).val();
$('#countAudio' + q[0]).val(Number(v) - 1)
$('#audioQuestion' + q[0] + ' tr:nth-last-child(1)').remove()
if ((q[1] - 1) > 0) {
$('#audioQuestion' + q[0] + ' tr:nth-last-child(1) td:nth-last-child(1)').append('<a href="#" id="delAudio' + (q[1] - 1) + '" title="DELETAR ÁUDIO"><img src="imgSite/fecha16.png" name="animate" width="13" height="13" align="absmiddle" id="deleteAudio' + q[0] + '|' + (q[1] - 1) + '"/></a>')
if (e.target.id.indexOf("deleteAudio") >= 0) {
let q = e.target.id.replace("deleteAudio", "").split("|");
let v = $("#countAudio" + q[0]).val();
$("#countAudio" + q[0]).val(Number(v) - 1);
$("#audioQuestion" + q[0] + " tr:nth-last-child(1)").remove();
if (q[1] - 1 > 0) {
$("#audioQuestion" + q[0] + " tr:nth-last-child(1) td:nth-last-child(1)").append(
'<a href="#" id="delAudio' +
(q[1] - 1) +
'" title="DELETAR ÁUDIO"><img src="imgSite/fecha16.png" name="animate" width="13" height="13" align="absmiddle" id="deleteAudio' +
q[0] +
"|" +
(q[1] - 1) +
'"/></a>'
);
}
}
if (e.target.id.indexOf('deleteQuestion') >= 0) {
let q = e.target.id.replace('deleteQuestion', '').split('|')
if (e.target.id.indexOf("deleteQuestion") >= 0) {
let q = e.target.id.replace("deleteQuestion", "").split("|");
let question = q[0];
let display = q[1];
let ppId = $("#pp_id").val()
let ppId = $("#pp_id").val();
request({type: 'POST', url: `index.php?idProg=182&ajax=1&a=delQuestion`, data: {pp_id: ppId, pq_id: question}}, function (res) {
request(
{
type: "POST",
url: `index.php?idProg=182&ajax=1&a=delQuestion`,
data: { pp_id: ppId, pq_id: question },
},
function (res) {
if (res.error === false) {
let oldDisplay = (display - 1)
let oldpqId = $('input[name="count_descricao[' + oldDisplay + ']"]').val()
let oldDisplay = display - 1;
let oldpqId = $('input[name="count_descricao[' + oldDisplay + ']"]').val();
if (oldDisplay > 1) {
let selector = `<td align="right"><a href="#" id="delQuestion${oldDisplay}" title="DELETAR QUESTÃO"><img src="imgSite/fecha16.png" name="animate" width="13" height="13" align="absmiddle" id="deleteQuestion${oldpqId}|${oldDisplay}"/></a></td>`;
$('#collapse' + oldDisplay + ' #cabRota table tbody tr:nth-last-child(1)').append(selector)
$("#collapse" + oldDisplay + " #cabRota table tbody tr:nth-last-child(1)").append(selector);
}
$('#collapse' + display).remove();
$("#collapse" + display).remove();
}
})
}
);
}
if (e.target.id.indexOf('deleteNewQuestion') >= 0) {
let q = e.target.id.replace('deleteNewQuestion', '')
let novoEle = null
if (e.target.id.indexOf("deleteNewQuestion") >= 0) {
let q = e.target.id.replace("deleteNewQuestion", "");
let novoEle = null;
$("#collapse" + q).remove();
let labelPergunta = $('#collapse' + (q - 1) + ' #cabRota #labelPergunta').text()
let labelPergunta = $("#collapse" + (q - 1) + " #cabRota #labelPergunta").text();
//Validacao para que a primeira pergunta nao seja possivel de remover "(q - 1) > 1"
if (!labelPergunta && (q - 1) > 1) {
let novoEle = $('<td align="right"><a href="#" id="delnewQuestion' + (q - 1) + '" title="DELETAR QUESTÃO"><img src="imgSite/fecha16.png" name="animate" width="13" height="13" align="absmiddle" id="deleteNewQuestion' + (q - 1) + '" /></a><td>')
$('#collapse' + (q - 1) + ' #cabRota table tbody tr:nth-last-child(1)').append(novoEle)
$('#collapse' + (q - 1) + ' #cabRota table tbody tr td:nth-last-child(1)').remove()
if (!labelPergunta && q - 1 > 1) {
let novoEle = $(
'<td align="right"><a href="#" id="delnewQuestion' +
(q - 1) +
'" title="DELETAR QUESTãO"><img src="imgSite/fecha16.png" name="animate" width="13" height="13" align="absmiddle" id="deleteNewQuestion' +
(q - 1) +
'" /></a><td>'
);
$("#collapse" + (q - 1) + " #cabRota table tbody tr:nth-last-child(1)").append(novoEle);
$("#collapse" + (q - 1) + " #cabRota table tbody tr td:nth-last-child(1)").remove();
}
}
});
@ -216,126 +318,143 @@ $(function () {
$("#newquestion").click(function () {
let div = $('div[id^="collapse"]:last');
let num = parseInt(div.prop("id").match(/\d+/g), 10) + 1;
let numEle = (num - 1)
$('#pqt_id').prop("readonly", true );
$('#pqt_id').css({"pointer-events": "none", opacity: 0.5})
//REMOVE O BOTÃO DE DELETE
$('#collapse' + numEle + ' #cabRota table tbody tr td:nth-child(3)').remove()
$('#collapse' + numEle).clone().prop('id', 'collapse' + num).appendTo('#questions');
$('#collapse' + num + ' #box' + numEle).prop('id', 'box' + num)
$('#collapse' + num + ' #animate' + numEle).prop('id', 'animate' + num)
$('#collapse' + num + ' #labelRotas' + numEle).prop('id', 'labelRotas' + num)
$('#collapse' + num + ' #labelPergunta').text('')
//RECRIAÇÃO DOS IDS E NAMES PARA O NOVO FORM
$('#box' + num + ' #pq_tipo' + numEle).prop('id', 'pq_tipo' + num).show()
$('#box' + num + ' #pq_tipol' + numEle).prop('id', 'pq_tipol' + num).show()
$('#pq_tipo' + num).removeAttr('checked')
$('#box' + num + ' input[name="qst_descricao[' + numEle + '][0]"]').prop('name', 'qst_descricao[' + num + '][0]')
$('#box' + num + ' input[name="pq_tipo[' + numEle + ']"').prop('name', 'pq_tipo[' + num + ']')
$('#box' + num + ' input[name="pp_audio[' + numEle + '][0]"]').prop('name', 'pp_audio[' + num + '][0]')
$('#box' + num + ' input[name="pp_audio[' + num + '][0]"]').prop('required',true);
$('#box' + num + ' input[name="pp_audio[' + num + '][0]"]').prop('id', num)
$('#box' + num + ' input[name="pp_audio[' + num + '][0]"]').val('')
$('#box' + num + ' #escuta_audio' + numEle).remove()
$('#box' + num + ' input[name="po_id[' + numEle + '][1]"]').prop('name', 'po_id[' + num + '][1]')
$('#box' + num + ' input[name="po_id[' + numEle + '][2]"]').prop('name', 'po_id[' + num + '][2]')
$('#box' + num + ' select[name="qst_opcoes[' + numEle + '][1]"]').remove()
$('#box' + num + ' select[name="qst_opcoes[' + numEle + '][2]"]').remove()
$('#box' + num + ' input[name="count_descricao[' + numEle + ']"]').prop('name', 'count_descricao[' + num + ']')
$('#box' + num + ' #tableResponse' + numEle).prop('id', 'tableResponse' + num)
$('#box' + num + ' #addResponse' + numEle).prop('id', 'addResponse' + num)
$('#addResponse' + num).show()
optionResponse(num, numEle)
$('#box' + num + ' #countAudio' + numEle).prop('id', 'countAudio' + num).prop('value', 1)
$('#box' + num + ' #audioQuestion' + numEle).prop('id', 'audioQuestion' + num);
$('#box' + num + ' #viewAudio' + numEle).prop('id', 'viewAudio' + num);
$('#box' + num + ' #addAudio' + numEle).prop('id', 'addAudio' + num);
$('table#audioQuestion' + num + ' tbody tr').each(function (indice) {
let numEle = num - 1;
$("#pqt_id").prop("readonly", true);
$("#pqt_id").css({ "pointer-events": "none", opacity: 0.5 });
//REMOVE O BOTãO DE DELETE
$("#collapse" + numEle + " #cabRota table tbody tr td:nth-child(3)").remove();
$("#collapse" + numEle)
.clone()
.prop("id", "collapse" + num)
.appendTo("#questions");
$("#collapse" + num + " #box" + numEle).prop("id", "box" + num);
$("#collapse" + num + " #animate" + numEle).prop("id", "animate" + num);
$("#collapse" + num + " #labelRotas" + numEle).prop("id", "labelRotas" + num);
$("#collapse" + num + " #labelPergunta").text("");
//RECRIAãO DOS IDS E NAMES PARA O NOVO FORM
$("#box" + num + " #pq_tipo" + numEle)
.prop("id", "pq_tipo" + num)
.show();
$("#box" + num + " #pq_tipol" + numEle)
.prop("id", "pq_tipol" + num)
.show();
$("#pq_tipo" + num).removeAttr("checked");
$("#box" + num + ' input[name="qst_descricao[' + numEle + '][0]"]').prop("name", "qst_descricao[" + num + "][0]");
$("#box" + num + ' input[name="pq_tipo[' + numEle + ']"').prop("name", "pq_tipo[" + num + "]");
$("#box" + num + ' input[name="pp_audio[' + numEle + '][0]"]').prop("name", "pp_audio[" + num + "][0]");
$("#box" + num + ' input[name="pp_audio[' + num + '][0]"]').prop("required", true);
$("#box" + num + ' input[name="pp_audio[' + num + '][0]"]').prop("id", num);
$("#box" + num + ' input[name="pp_audio[' + num + '][0]"]').val("");
$("#box" + num + " #escuta_audio" + numEle).remove();
$("#box" + num + ' input[name="po_id[' + numEle + '][1]"]').prop("name", "po_id[" + num + "][1]");
$("#box" + num + ' input[name="po_id[' + numEle + '][2]"]').prop("name", "po_id[" + num + "][2]");
$("#box" + num + ' select[name="qst_opcoes[' + numEle + '][1]"]').remove();
$("#box" + num + ' select[name="qst_opcoes[' + numEle + '][2]"]').remove();
$("#box" + num + ' input[name="count_descricao[' + numEle + ']"]').prop("name", "count_descricao[" + num + "]");
$("#box" + num + " #tableResponse" + numEle).prop("id", "tableResponse" + num);
$("#box" + num + " #addResponse" + numEle).prop("id", "addResponse" + num);
$("#addResponse" + num).show();
optionResponse(num, numEle);
$("#box" + num + " #countAudio" + numEle)
.prop("id", "countAudio" + num)
.prop("value", 1);
$("#box" + num + " #audioQuestion" + numEle).prop("id", "audioQuestion" + num);
$("#box" + num + " #viewAudio" + numEle).prop("id", "viewAudio" + num);
$("#box" + num + " #addAudio" + numEle).prop("id", "addAudio" + num);
$("table#audioQuestion" + num + " tbody tr").each(function (indice) {
if (indice >= 1) {
$(this).remove()
$(this).remove();
}
});
$('#box' + num + ' #pesquisaId' + numEle).prop('id', 'pesquisaId' + num)
$("#box" + num + " #pesquisaId" + numEle).prop("id", "pesquisaId" + num);
//$('#box' + num + ' #count' + numEle).prop('id', 'count' + num)
$('#box' + num + ' #count' + numEle).remove()
$('#tableResponse' + num + ' tbody tr td:nth-child(1)').append(`<input name="count${num}" id="count${num}" type="number" value="2" hidden="">`)
$('#box' + num + ' input[name="count' + numEle + '"]').prop('name', 'count' + num)
$('#box' + num + ' #countAsk' + numEle).prop('id', 'countAsk' + num)
$('#countAsk' + num).text(num + ')')
$('#count' + num).val(2)
$("#box" + num + " #count" + numEle).remove();
$("#tableResponse" + num + " tbody tr td:nth-child(1)").append(`<input name="count${num}" id="count${num}" type="number" value="2" hidden="">`);
$("#box" + num + ' input[name="count' + numEle + '"]').prop("name", "count" + num);
$("#box" + num + " #countAsk" + numEle).prop("id", "countAsk" + num);
$("#countAsk" + num).text(num + ")");
$("#count" + num).val(2);
if (!$(`input[name="qst_descricao[3][2]"`).val()) {
$("#tableResponse" + num).append(buildResponse(num, 2))
$("#tableResponse" + num).append(buildResponse(num, 2));
}
$('table#tableResponse' + num + ' tbody tr').each(function (indice) {
$("table#tableResponse" + num + " tbody tr").each(function (indice) {
if (indice > 2) {
$(this).remove()
$(this).remove();
}
});
let novoEle = $('<td align="right"><a href="#" id="delnewQuestion' + num + '" title="DELETAR QUESTÃO"><img src="imgSite/fecha16.png" name="animate" width="13" height="13" align="absmiddle" id="deleteNewQuestion' + num + '" /></a><td>')
$('#collapse' + num + ' #cabRota table tbody tr:nth-last-child(1)').append(novoEle)
$('#collapse' + num + ' #cabRota table tbody tr td:nth-last-child(1)').remove()
$('#box' + num + ' #saveResponse' + numEle).prop('id', 'saveResponse' + num)
$('#collapse' + num + ' input').val('');
})
let novoEle = $(
'<td align="right"><a href="#" id="delnewQuestion' +
num +
'" title="DELETAR QUESTãO"><img src="imgSite/fecha16.png" name="animate" width="13" height="13" align="absmiddle" id="deleteNewQuestion' +
num +
'" /></a><td>'
);
$("#collapse" + num + " #cabRota table tbody tr:nth-last-child(1)").append(novoEle);
$("#collapse" + num + " #cabRota table tbody tr td:nth-last-child(1)").remove();
$("#box" + num + " #saveResponse" + numEle).prop("id", "saveResponse" + num);
$("#collapse" + num + " input").val("");
});
$('#audio_saudacao').click(function () {
$('#saudacao').html('<input type="file" name="pp_audio_saudacao" id="pp_audio_saudacao" style="width: 451px"/>');
$("#audio_saudacao").click(function () {
$("#saudacao").html('<input type="file" name="pp_audio_saudacao" id="pp_audio_saudacao" style="width: 451px"/>');
});
$('#audio_encerramento').click(function () {
$('#encerramento').html('<input type="file" name="pp_audio_encerramento" id="pp_audio_encerramento" style="width: 451px" />');
$("#audio_encerramento").click(function () {
$("#encerramento").html('<input type="file" name="pp_audio_encerramento" id="pp_audio_encerramento" style="width: 451px" />');
});
el.addEventListener('change', function (e) {
if (e.target.id.indexOf('pq_tipo') >= 0) {
let q = e.target.id.replace('pq_tipo', '')
if($('#pq_tipo' + q).prop("checked")){
el.addEventListener("change", function (e) {
if (e.target.id.indexOf("pq_tipo") >= 0) {
let q = e.target.id.replace("pq_tipo", "");
if ($("#pq_tipo" + q).prop("checked")) {
$("#addResponse" + q).hide();
$("#box" + q +" #tableResponse"+ q +" tr:nth-child(3)").remove()
$("#box" + q + " #tableResponse" + q + " tr:nth-child(3)").remove();
} else {
$("#addResponse" + q).show();
$("#box"+ q +" #tableResponse"+ q).append(`<tr><td colspan="3"> &nbsp;&nbsp; <input name="po_id[${q}][2]" type="number" value="" hidden="true">2) <input name="qst_tecla[${q}][2]" class="qst_tecla" type="number" value="" size="4" maxlength="2" min="0" max="999" required="" style="width:60px"> <input name="qst_descricao[${q}][2]" type="text" value="" title="Descreva aqui a opção" size="50" style="width:360px" maxlength="60" required=""></td></tr>`)
$("#box" + q + " #tableResponse" + q).append(
`<tr><td colspan="3"> &nbsp;&nbsp; <input name="po_id[${q}][2]" type="number" value="" hidden="true">2) <input name="qst_tecla[${q}][2]" class="qst_tecla" type="number" value="" size="4" maxlength="2" min="0" max="999" required="" style="width:60px"> <input name="qst_descricao[${q}][2]" type="text" value="" title="Descreva aqui a opão" size="50" style="width:360px" maxlength="60" required=""></td></tr>`
);
}
}
let x = e.target.name.indexOf('[')
let y = e.target.name.indexOf(']')
let idtecla = e.target.name.substring((x + 1), y)
let posi = e.target.name.replace("qst_tecla[" + idtecla + "]", '').replace('[', '').replace(']', '')
let ar = []
$('#tableResponse' + idtecla + ' .qst_tecla').each(function (i, el) {
ar.push($(this).val())
})
let x = e.target.name.indexOf("[");
let y = e.target.name.indexOf("]");
let idtecla = e.target.name.substring(x + 1, y);
let posi = e.target.name
.replace("qst_tecla[" + idtecla + "]", "")
.replace("[", "")
.replace("]", "");
let ar = [];
$("#tableResponse" + idtecla + " .qst_tecla").each(function (i, el) {
ar.push($(this).val());
});
ar.splice((posi - 1), 1);
ar.splice(posi - 1, 1);
const maxValue = ar.reduce(function (prev, current) {
return prev > current ? prev : current;
});
if (ar.indexOf(e.target.value) >= 0) {
$('input[name="' + e.target.name + '"]').val(Number(maxValue) + 1)
$('input[name="' + e.target.name + '"]').val(Number(maxValue) + 1);
}
});
});

Loading…
Cancel
Save