|
|
|
|
<?php
|
|
|
|
|
|
|
|
|
|
include_once 'util/relatoriosBase.php';
|
|
|
|
|
|
|
|
|
|
$tpLayout = 1;
|
|
|
|
|
|
|
|
|
|
class RelMsgWhatsappDetalhado extends Relatorios {
|
|
|
|
|
|
|
|
|
|
private $___uid;
|
|
|
|
|
|
|
|
|
|
public function __construct($idProg, $dbcon, $incDac) {
|
|
|
|
|
parent::__construct($idProg, $dbcon, $incDac);
|
|
|
|
|
$this->___uid = isset($_GET['uid']) ? base64_decode($_GET['uid']) : '';
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function ___FiltrosRelatorio() {
|
|
|
|
|
if ($this->___media != MEDIA_PRINT_GRID) {
|
|
|
|
|
/*
|
|
|
|
|
* Recupera os filtros da sess<EFBFBD>o do usu<EFBFBD>rio.
|
|
|
|
|
*/
|
|
|
|
|
list($this->___dataIni, $this->___dataFim, $this->___tipoRelatorio) = $_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<EFBFBD>tico' : 'Sint<EFBFBD>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 = '<a href="index.php?idProg=%s&media=%s&tipoRelatorio=%s"><img src="imgSite/%s" alt="Clique aqui para imprimir!" width="24" height="24" border="0"></a>';
|
|
|
|
|
//$prtHtml = "<a href=\"javaScript:NovaJanela('index.php?idProg=%s&media=%s&tipoRelatorio=%s', '%s', '720', '700', 'scrollbars=YES');\"><img src=\"imgSite/%s\" alt=\"Clique aqui para imprimir!\" width=\"24\" height=\"24\" border=\"0\"></a>";
|
|
|
|
|
$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 fun<EFBFBD><EFBFBD>o se necessitar de outras op<EFBFBD><EFBFBD>es de filtro.
|
|
|
|
|
*/
|
|
|
|
|
$filtro = '<table border="0" cellspacing="1" cellpadding="1" class="grid">';
|
|
|
|
|
/*
|
|
|
|
|
* Rotulos.
|
|
|
|
|
*/
|
|
|
|
|
$filtro .= '<tr>';
|
|
|
|
|
$filtro .= '<th align="center">Data Inicial </th>';
|
|
|
|
|
$filtro .= '<th align="center">Data Final </th>';
|
|
|
|
|
$filtro .= '<th align="center"> </th>';
|
|
|
|
|
$filtro .= '</tr>';
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
* Valores.
|
|
|
|
|
*/
|
|
|
|
|
$filtro .= '<tr>';
|
|
|
|
|
$filtro .= '<td align="center"><h2>%s</h2></th>';
|
|
|
|
|
$filtro .= '<td align="center"><h2>%s</h2></td>';
|
|
|
|
|
$filtro .= '<td align="center">%s</td>';
|
|
|
|
|
$filtro .= '</tr>';
|
|
|
|
|
$filtro .= '</table>';
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
* Guarda os filtros passados para recuperar na emiss<EFBFBD>o dos relat<EFBFBD>ios para impress<EFBFBD>o.
|
|
|
|
|
*/
|
|
|
|
|
$_SESSION["SSstorageFiltros"] = array($this->___dataIni, $this->___dataFim, $this->___tipoRelatorio);
|
|
|
|
|
|
|
|
|
|
return sprintf($filtro, $this->___dataIni, $this->___dataFim, $lkPrint);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
protected function ___GetDadosDb() {
|
|
|
|
|
$uid = $this->___uid;
|
|
|
|
|
|
|
|
|
|
$query = "SELECT * FROM md_message WHERE uniqueid = '$uid' ORDER BY id";
|
|
|
|
|
|
|
|
|
|
$result = $this->___GetQuery($query);
|
|
|
|
|
$row = pg_fetch_all($result);
|
|
|
|
|
$this->SetData($row ? $row : array());
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
protected function ___PreparaCsv() {
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
protected function ___PreparaExcel() {
|
|
|
|
|
$dataRel = array();
|
|
|
|
|
$filtro = $this->___FiltrosRelatorio();
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
* Inicia o relat<EFBFBD>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/Hora',
|
|
|
|
|
'Autor',
|
|
|
|
|
'Origem',
|
|
|
|
|
'Destino',
|
|
|
|
|
'Tipo',
|
|
|
|
|
'Mensagem'
|
|
|
|
|
);
|
|
|
|
|
$dadosField = array(
|
|
|
|
|
'msg_date',
|
|
|
|
|
'profile_name',
|
|
|
|
|
'src',
|
|
|
|
|
'dst',
|
|
|
|
|
'type',
|
|
|
|
|
'content'
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
* Monta a linha de cabecalio.
|
|
|
|
|
*/
|
|
|
|
|
$linha = array('LABEL');
|
|
|
|
|
foreach ($dadosCabecalio as $value) {
|
|
|
|
|
$linha[] = $value;
|
|
|
|
|
}
|
|
|
|
|
$dataRel[] = $linha;
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
* Linhas de dados.
|
|
|
|
|
*/
|
|
|
|
|
$count = 0;
|
|
|
|
|
foreach ($this->GetData()[0] as $row) {
|
|
|
|
|
$count++;
|
|
|
|
|
$row['msg_date'] = date('d/m/Y H:i:s', strtotime($row['msg_date']));
|
|
|
|
|
//$row['content'] = $this->decrypt($row['content']);
|
|
|
|
|
|
|
|
|
|
// Formata linha de dados.
|
|
|
|
|
$linha = array('DADOS');
|
|
|
|
|
foreach ($dadosField as $key) {
|
|
|
|
|
$linha[] = $row["$key"];
|
|
|
|
|
}
|
|
|
|
|
$dataRel[] = $linha;
|
|
|
|
|
}
|
|
|
|
|
$dataRel[] = array('LABEL', 'Total Mensagens: ' . $count, '', '','');
|
|
|
|
|
$this->___dataRel[] = $dataRel;
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
protected function ___PreparaGrid() {
|
|
|
|
|
$dataRel = array();
|
|
|
|
|
$dadosCabecalio = array(
|
|
|
|
|
'Data/Hora' => 'align="center"',
|
|
|
|
|
'Autor' => 'align="center"',
|
|
|
|
|
'Origem' => 'align="center"',
|
|
|
|
|
'Destino' => 'align="center"',
|
|
|
|
|
'Tipo' => 'align="center"',
|
|
|
|
|
'Mensagem' => 'align=center'
|
|
|
|
|
);
|
|
|
|
|
$dadosField = array(
|
|
|
|
|
'msg_date' => 'align="center"',
|
|
|
|
|
'profile_name' => 'align="center"',
|
|
|
|
|
'src' => 'align="center"',
|
|
|
|
|
'dst' => 'align="center"',
|
|
|
|
|
'type' => 'align="center"',
|
|
|
|
|
'content' => 'align="center"'
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
* Inicia o relat<EFBFBD>rio.
|
|
|
|
|
*/
|
|
|
|
|
$dataRel[] = '<table width="99%" cellpadding="2" class="grid">';
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
* Monta a linha de cabecalio.
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
$linha = '<tr>';
|
|
|
|
|
$linha .= "<th align=\"center\" colspan=\"7\">Mensagem WhatsApp</th>";
|
|
|
|
|
$linha .= "</tr>";
|
|
|
|
|
$dataRel[] = $linha;
|
|
|
|
|
|
|
|
|
|
$linhaC = "<tr>";
|
|
|
|
|
foreach ($dadosCabecalio as $key => $value) {
|
|
|
|
|
$linhaC .= sprintf("<th %s>%s</th>", $value, $key);
|
|
|
|
|
}
|
|
|
|
|
$linhaC .= "</tr>";
|
|
|
|
|
$dataRel[] = $linhaC;
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
* Linhas de dados.
|
|
|
|
|
*/
|
|
|
|
|
$count = 0;
|
|
|
|
|
|
|
|
|
|
foreach ($this->GetData()[0] as $row) {
|
|
|
|
|
$count++;
|
|
|
|
|
$row['msg_date'] = date('d/m/Y H:i:s', strtotime($row['msg_date']));
|
|
|
|
|
//$row['content'] = $this->decrypt($row['content']);
|
|
|
|
|
|
|
|
|
|
// Formata linha de dados.
|
|
|
|
|
$linha = "<tr>";
|
|
|
|
|
foreach ($dadosField as $key => $value) {
|
|
|
|
|
$linha .= sprintf("<td %s>%s</td>", $value, $row["$key"]);
|
|
|
|
|
}
|
|
|
|
|
$linha .= "</tr>";
|
|
|
|
|
$dataRel[] = $linha;
|
|
|
|
|
}
|
|
|
|
|
$dataRel[] = "<tr><th align='left' colspan='7' >Total: {$count}</th></tr>";
|
|
|
|
|
$dataRel[] = '</table>';
|
|
|
|
|
$this->___dataRel[] = $dataRel;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
protected function ___PreparaHtml() {
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
protected function ___PreparaPdf() {
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private function decrypt($plaintext, $key = null) {
|
|
|
|
|
$c = base64_decode($plaintext);
|
|
|
|
|
$ivlen = openssl_cipher_iv_length($cipher = "aes-256-cbc");
|
|
|
|
|
$iv = substr($c, 0, $ivlen);
|
|
|
|
|
$hmac = substr($c, $ivlen, $sha2len = 32);
|
|
|
|
|
$ciphertext_raw = substr($c, $ivlen + $sha2len);
|
|
|
|
|
$original_plaintext = openssl_decrypt($ciphertext_raw, $cipher, $key, $options = OPENSSL_RAW_DATA, $iv);
|
|
|
|
|
$calcmac = hash_hmac('sha256', $ciphertext_raw, $key, $as_binary = true);
|
|
|
|
|
if (hash_equals($hmac, $calcmac)) {
|
|
|
|
|
return utf8_decode($original_plaintext);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public function ExecutaRelatorio() {
|
|
|
|
|
global $jsStartup, $jsJQuery, $smarty;
|
|
|
|
|
try {
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
* Use esta fun<EFBFBD><EFBFBD>o para validar dados do formul<EFBFBD>rio.
|
|
|
|
|
*/
|
|
|
|
|
$this->___ValidaForm();
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
* Recupera os dados do banco.
|
|
|
|
|
*/
|
|
|
|
|
$this->___ConteudoRelatorio();
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
* Imprime relat<EFBFBD>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();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
$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');
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
$relMsgWhatsappDetalhado = new RelMsgWhatsappDetalhado($idProg, $dbcon, 1);
|
|
|
|
|
$relMsgWhatsappDetalhado->ExecutaRelatorio();
|
|
|
|
|
?>
|