___dac = isset($_POST["listaDacs"]) ? $_POST["listaDacs"] : 0; $this->___lstPesquisa = isset($_POST["lstPesquisa"]) ? $_POST["lstPesquisa"] : '0| | | |0| '; $this->___protocolo = isset($_POST['protocolo']) ? $_POST['protocolo'] : ''; $this->___matricula = isset($_POST["matricula"]) ? $_POST["matricula"] : 0; $this->___opcResposta = isset($_POST["lstOpcoes"]) ? $_POST["lstOpcoes"] : -1; $this->___GetRelAudio(); } function ___ValidaForm() { parent::___ValidaForm(); if (!IsPostBack()) { return; } if (!$this->___lstPesquisa) { GeraExcept('Informe uma pesquisa!'); } } function ___FiltrosRelatorio() { global $dbcon; if ($this->___lstPesquisa) { $lstPesq = explode('|', $this->___lstPesquisa); $this->___plId = $lstPesq[0]; $this->___ppId = $lstPesq[4]; } $lstPesquisa = GetPesquisaRel($dbcon, $this->___plId, $this->___matricula); if ($this->___media != MEDIA_PRINT_GRID) { /* * Recupera os filtros da sessao do usuario. */ list($this->___dac, $this->___dataIni, $this->___dataFim) = $_SESSION["SSstorageFiltros"]; if ($this->___media == MEDIA_PRINT_HTML) { $fila = $this->GetIncDac() ? 'Fila: ' . GetDacDesc($this->GetDbCon(), $this->GetIdProg() . ' ') : ''; return sprintf("%sData Inicial: %s Data Final: %s Tipo: %s", $fila, $this->___dataIni, $this->___dataFim, ($this->___tipoRelatorio ? 'Analítico' : 'Sintético')); } $fltCsv = array(); if ($this->GetIncDac()) { $fltCsv[] = 'Fila:' . GetDacDesc($this->GetDbCon(), $this->___dac); } $fltCsv[] = "Data Inicial:" . $this->___dataIni; $fltCsv[] = "Data Final:" . $this->___dataFim; $fltCsv[] = "Data Emissao:" . date('d/m/Y H:i:s'); $fltCsv[] = "Emitido Por:" . GetLogin(); return $fltCsv; } if ($this->GetIncDac()) { $dacs = GetDac($this->GetDbCon(), $this->___dac, "", 0, 1, 0, 0, 1); } $lkPrint = ""; if ($this->___dataCount) { $prt = 'Clique aqui para imprimir!'; $prtHtml = "\"Clique"; $lkPrint .= sprintf($prtHtml, $this->GetidProg(), MEDIA_PRINT_HTML, $this->___tipoRelatorio, substr(LimpaString(GetDispProgSel($this->GetIdProg())), 0, 20), 'print.gif'); $lkPrint .= sprintf($prt, $this->GetidProg(), MEDIA_PRINT_EXCEL, $this->___tipoRelatorio, 'prt-xls.png'); $lkPrint .= sprintf($prt, $this->GetidProg(), MEDIA_PRINT_PDF, $this->___tipoRelatorio, 'prt-pdf.png'); $lkPrint .= sprintf($prt, $this->GetidProg(), MEDIA_PRINT_CSV, $this->___tipoRelatorio, 'prt-csv.png'); } //$tipoRel = !$this->___tipoRelatorio ? '' : 'checked="checked"'; /* * Personalise esta funcao se necessitar de outras opnioes de filtro. */ $filtro = ''; /* * Rotulos. */ $filtro .= ''; $filtro .= ''; $filtro .= ''; $filtro .= ''; $filtro .= ''; $filtro .= ""; $filtro .= ""; $filtro .= ""; $filtro .= ""; if ($this->GetIncDac()) $filtro .= ''; $filtro .= ''; $filtro .= ''; $filtro .= ''; $filtro .= ''; $filtro .= ''; $filtro .= ''; /* * Valores. */ $filtro .= ''; if ($this->GetIncDac()) $filtro .= sprintf('', $dacs); $filtro .= ''; $filtro .= ''; $filtro .= ""; $filtro .= ""; $filtro .= ''; $filtro .= ''; $filtro .= ''; $filtro .= '
Pesquisa  Opção  
" . $this->GetOpcoesPesquisa($dbcon, $this->___ppId, $this->___opcResposta) . "
FilaData InicialData Final Agente Protocolo 
%s%s
'; /* * Guarda os filtros passados para recuperar na emissao dos relatoios para impressao. */ $_SESSION["SSstorageFiltros"] = array($this->___dac, $this->___dataIni, $this->___dataFim); return sprintf($filtro, $this->___dataIni, $this->___dataFim, $lkPrint); } protected function ___GetDadosDb($pqId = null) { global $dbcon; $dataIni = FormatDtMssql($this->___dataIni); $dataFim = FormatDtMssql($this->___dataFim); $plId = $this->___plId; $ppId = $this->___ppId; $dac = $this->___dac; $ppNome = $this->___ppNome; $plDescricao = $this->___plDescricao; $datas = $this->___datas; $protocolo = $this->___protocolo; $matricula = $this->___matricula; GetDadosPesq($dbcon, $this->___lstPesquisa, $plId, $plDescricao, $ppId, $ppNome, $datas); $query = "SELECT DISTINCT e.pp_nome, a.id_dac, f.nome AS nome_dac, a.pm_data, a.user_reg, c.nome AS agente, b.userfield, d.protocolo, b.src, g.po_opcao FROM pbx_pesquisa_movimento a INNER JOIN pbx_bilhetes b ON (substring(dcontext,1,3) = 'psq' AND b.accountcode = a.uniqueid) OR (b.accountcode = '' AND b.uniqueid = a.uniqueid) INNER JOIN pbx_eventos_dacs h ON h.uid2 = b.uniqueid INNER JOIN pbx_usuarios c ON c.matricula = substring(h.agente, 7,4) LEFT JOIN pbx_protocolo_reg d ON d.uniqueid = a.uniqueid INNER JOIN pbx_pesquisa e ON e.pp_id = a.pp_id INNER JOIN pbx_dacs f ON f.id = a.id_dac INNER JOIN pbx_pesquisa_opcoes g ON g.pp_id = a.pp_id AND g.po_id = a.po_id WHERE b.lastapp <> 'Transferred Call' AND COALESCE(b.userfield, '') <> '' AND duration > 0 AND evento IN ('COMPLETEAGENT','COMPLETECALLER', 'TRANSFER','COMPLETEAGENTRAMAL','COMPLETECALLERRAMAL', 'COMPLETACALLER', 'COMPLETAAGENT') "; if (!$protocolo) { $query .= "AND a.id_dac = '$dac' AND a.pp_id = '$ppId' AND a.pm_data >= '$dataIni' AND a.pm_data <= '$dataFim' "; } if ($matricula && !$protocolo) { $query .= " AND a.user_reg = '$matricula' "; } if (!$protocolo && ($this->___opcResposta != '-1')) { $query .= "AND g.po_id = '{$this->___opcResposta}' "; } if ($protocolo) { $query .= "AND d.protocolo = '$protocolo' "; } $query .= " ORDER BY c.nome, a.pm_data"; $result = $this->___GetQuery($query); $row = pg_fetch_all($result); $this->SetData($row ? $row : array()); } protected function ___PreparaCsv() { global $dbcon; $dataRel = array(); $filtro = $this->___FiltrosRelatorio(); /* * Inicia o relatório. */ $dataRel[] = GenerateCsvFromArray($filtro); $dadosCabecalio = array('Data', 'Agente', 'Numero Cliente', 'Protocolo', 'Opção', 'Audio'); $dadosField = array('pm_data', 'agente', 'src', 'protocolo', 'po_opcao', 'userfield'); $dataRel[] = GenerateCsvFromArray($dadosCabecalio); /* * Monta a linha de cabecalio. */ /* * Linhas de dados. */ foreach ($this->GetData()[0] as $row) { ; $dac = GetDacDesc($dbcon, $this->___dac); $downloadAudio = VerificaPerfilAcesso($dbcon, GetIdProgFromNomeArq('downloadAudio.php')); $acessoAudio = GetAcessoAudio($dac); if (!$downloadAudio || IsAdmin() || !$acessoAudio) { $msgAudio = "[ SEM PERMISSAO ]"; } else { $msgAudio = sprintf("[ %s ]", RemoveAcentos($row['userfield'])); } $row['agente'] = RemoveAcentos($row['agente']); $row['pm_data'] = date('d/m/Y', strtotime($row['pm_data'])); $row['protocolo'] = $row['protocolo'] ? $row['protocolo'] : ' ---- '; $row['userfield'] = $msgAudio; $linha = array(); foreach ($dadosField as $key) { $linha[] = $row["$key"]; } $dataRel[] = GenerateCsvFromArray($linha); } $this->___dataRel[] = $dataRel; } protected function ___PreparaExcel() { global $dbcon; $dataRel = array(); $filtro = $this->___FiltrosRelatorio(); /* * Inicia o relatório. */ /* * Cria os filtros */ $linha = array('LABEL'); foreach ($filtro as $values) { list($label, $value) = explode(":", $values); $linha[] = $label; } $dataRel[] = $linha; $linha = array('DADOS'); foreach ($filtro as $values) { list($label, $value) = explode(":", $values); $linha[] = $value; } $dataRel[] = $linha; $dadosCabecalio = array('Data', 'Agente', 'Numero Cliente', 'Protocolo', 'Opcao', 'Audio'); $dadosField = array('pm_data', 'agente', 'src', 'protocolo', 'po_opcao', 'userfield'); $linha = array('LABEL'); foreach ($dadosCabecalio as $value) { $linha[] = $value; } $dataRel[] = $linha; /* * Monta a linha de cabecalio. */ /* * Linhas de dados. */ foreach ($this->GetData()[0] as $row) { $dac = GetDacDesc($dbcon, $this->___dac); $downloadAudio = VerificaPerfilAcesso($dbcon, GetIdProgFromNomeArq('downloadAudio.php')); $acessoAudio = GetAcessoAudio($dac); if (!$downloadAudio || IsAdmin() || !$acessoAudio) { $msgAudio = "[ SEM PERMISSAO ]"; } else { $msgAudio = sprintf("[ %s ]", RemoveAcentos($row['userfield'])); } $row['agente'] = RemoveAcentos($row['agente']); $row['pm_data'] = date('d/m/Y', strtotime($row['pm_data'])); $row['protocolo'] = $row['protocolo'] ? $row['protocolo'] : ' ---- '; $row['userfield'] = $msgAudio; $linha = array('DADOS'); foreach ($dadosField as $key) { $linha[] = $row["$key"]; } $dataRel[] = $linha; } $this->___dataRel[] = $dataRel; } protected function ___PreparaGrid() { global $dbcon, $infoDispositivo; $dataRel = array(); $dadosCabecalio = array( 'Data' => 'align="left"', 'Agente' => 'align="left"', 'Numero Cliente' => 'align="left"', 'Protocolo' => 'align="center"', 'Opção' => 'align="center"', 'Áudio' => 'align="center"' ); $dadosField = array( 'pm_data' => 'align="left"', 'agente' => 'align="left"', 'src' => 'align="left"', 'protocolo' => 'align="center"', 'po_opcao' => 'align="right"', 'userfield' => 'align="center"' ); /* * Monta a linha de cabecalio. */ $dataRel[] = ''; $dataRel[] = ""; $linha = ''; foreach ($dadosCabecalio as $key => $value) { $linha .= sprintf("", $value, $key); } $linha .= ""; $dataRel[] = $linha; /* * Verifica se retornou dados */ if (!IsPostBack() || !count($this->GetData()[0])) { $dataRel[] = sprintf("
Relatório Pesquisa de Áudio
%s
%s
", count($dadosCabecalio), (!IsPostBack() ? 'Informe os parametros e clique em consultar!' : 'Nenhum registro encontado!')); $this->___dataRel[] = $dataRel; return; } /* * Linhas de dados. */ $total = 0; foreach ($this->GetData()[0] as $row) { $row['pm_data'] = date('d/m/Y', strtotime($row['pm_data'])); $row['protocolo'] = $row['protocolo'] ? $row['protocolo'] : ' ---- '; $dac = GetDacDesc($dbcon, $this->___dac); $downloadAudio = VerificaPerfilAcesso($dbcon, GetIdProgFromNomeArq('downloadAudio.php')); $acessoAudio = GetAcessoAudio($dac); if (!$downloadAudio || IsAdmin() || !$acessoAudio) { if (IsAdmin()) { $msgAudio = "Usuário Administrador não tem permissão para acessar áudios!"; } else { $msgAudio = "Este usuário não possui permissões para acessar áudios!"; } $linkAudio = sprintf("", $msgAudio); } else { if ($infoDispositivo->isMobile()) { $audioMobile = str_ireplace(".WAV", ".MP3", $row['userfield']); $linkAudio = "" . "" . ""; } else { $linkAudio = "" . "" . ""; } } $row['userfield'] = $linkAudio; // Formata linha de dados. $linha = ""; foreach ($dadosField as $key => $value) { $linha .= sprintf("%s", $value, $row["$key"]); } $linha .= ""; $dataRel[] = $linha; $total++; } $dataRel[] = "Total $total"; /* * Fecha relatorio. */ $dataRel[] = ''; $this->___dataRel[] = $dataRel; } protected function ___PreparaHtml() { } protected function ___PreparaPdf() { global $dbcon; list($this->___dac, $this->___dataIni, $this->___dataFim) = $_SESSION["SSstorageFiltros"]; /** * TABELA DADOS PRINCIPAIS */ $dadosCabecalio = array( 'Data' => 'C', 'Agente' => 'C', 'Numero Cliente' => 'C', 'Protocolo' => 'C', 'Opção' => 'C', 'Áudio' => 'C' ); $dadosField = array( 'pm_data' => 'C', 'agente' => 'L', 'src' => 'C', 'protocolo' => 'C', 'po_opcao' => 'C', 'userfield' => 'C' ); $dados = $this->GetData()[0]; $z = 0; $dataQst = array(); $widthHeader = array(15, 37, 37, 10, 15, 45); foreach ($dados as $row) { $dac = GetDacDesc($dbcon, $this->___dac); $downloadAudio = VerificaPerfilAcesso($dbcon, GetIdProgFromNomeArq('downloadAudio.php')); $acessoAudio = GetAcessoAudio($dac); if (!$downloadAudio || IsAdmin() || !$acessoAudio) { $msgAudio = "[ SEM PERMISSÃO ]"; } else { $msgAudio = "[ {$row['userfield']} ]"; } $dataQst[$z]['pm_data'] = date('d/m/Y', strtotime($row['pm_data'])); $dataQst[$z]['agente'] = $row['agente']; $dataQst[$z]['src'] = $row['src']; $dataQst[$z]['protocolo'] = $row['protocolo'] ? $row['protocolo'] : ' ---- '; $dataQst[$z]['po_opcao'] = $row['po_opcao']; $dataQst[$z]['userfield'] = $msgAudio; $z++; } //$totalizador = array('Total: ', $row['pq_questao'], 'Resp.: ' . $somaTotalQtd, number_format(($somaTotalQtd / $somaTotalQtd) * 100.0, 2, ',', '.') . '%'); $tables = array($dadosCabecalio, $dadosField, $dataQst, $widthHeader, '', 0); $this->___dataRel = array($tables); } protected function __CalculaPorcentagem($coluna, $array) { $somaQtd = 0; foreach ($array as $value) { if ($value['pq_questao'] == $coluna) { $somaQtd += $value['num_resp']; } } return $somaQtd; } private function ___GetRelAudio() { if (isset($_GET['audioMobile'])) { $dir = "/var/www/html/aplicativo/audio/"; $filepath = VerificaCharFinal($_SESSION[SS_PRM_PATH_AUDIO]) . $_GET["audio"]; $fileOrig = $dir . $_GET["audio"]; @file_put_contents($fileOrig, @file_get_contents($filepath)); $audioMobile = $_GET['audioMobile']; $file = $dir . $audioMobile; if (!file_exists($file)) { $cmd = "ffmpeg -i $fileOrig -acodec libmp3lame $file"; //$cmd = "ffmpeg -i $fileOrig -f mp3 $file"; $dbcon = $GLOBALS['dbcon']; ExecutaComando($cmd, $dbcon); } $file = "/audio/" . $audioMobile; @header("Location: $file"); exit; } if (isset($_GET["audio"]) || isset($_GET["repAudio"])) { $file = $_GET["audio"] ? $_GET["audio"] : $_GET["repAudio"]; $filepath = VerificaCharFinal($_SESSION[SS_PRM_PATH_AUDIO]) . $_GET["audio"]; if (!@file_get_contents($filepath)) { $jsStartup[] = "alert('Arquivo não encontrado!');"; $exitAudio = 1; } else { if (isset($_GET["audio"])) { DownloadAudio($file, $filepath); exit; } } } } private function GetOpcoesPesquisa($db, $ppId, $id) { $query = "select distinct po_opcao, b.pq_questao,po_id " . "from pbx_pesquisa_opcoes a " . "inner join pbx_pesquisa_questoes b ON a.pq_id = b.pq_id " . "where a.pp_id = '$ppId' " . "and exists (select '' from pbx_pesquisa_movimento where pp_id = a.pp_id and po_id = a.po_id) order by po_opcao "; $result = pg_query($db, $query); //echo $query; $sel = ''; if ($id == -1) { $sel = "selected=\"selected\""; } $ret = ""; return $ret; } public function ExecutaRelatorio() { global $jsStartup, $jsJQuery, $smarty; try { /* * Use esta função para validar dados do formulário. */ $this->___ValidaForm(); /* * Recupera os dados do banco. */ $this->___ConteudoRelatorio(); /* * Imprime relatório de acordo com a media passada. */ $conteudoRelatorio = $this->___ImprimeRelatorio(); } catch (Exception $exc) { $this->SetMsg($exc->getMessage()); $jsStartup[] = sprintf("alert('%s');", $this->GetMsg()); $this->___GravaLog(); } /* * Inclua os scripts necessários aqui. */ $jsJQuery[] = "\$('#dataIni').keypress(function(){formataDataHora(this);}) "; $jsJQuery[] = "\$('#dataFim').keypress(function(){formataDataHora(this);}) "; $smarty->assign('filtros', $this->___FiltrosRelatorio()); $smarty->assign('conteudo', $conteudoRelatorio); $smarty->assign('msg', $this->GetMsg()); GetTemplate($smarty, 'relatoriosGrid.tpl'); } } $relPesquisa = new RelPesquisaAudio($idProg, $dbcon, 1); $relPesquisa->ExecutaRelatorio(); ?>