", $msgAudio);
if ($restringAudio) {
continue;
}
$linkAudioFone = '';
} else {
if ($downloadAudio && $infoDispositivo->isMobile()) { //$infoDispositivo->isMobile
$audioMobile = str_ireplace(".WAV", ".MP3", $userField);
$linkAudio = "" . "" . "";
} else if ($downloadAudio) {
$linkAudio = "" . "" . "";
}
$uniqueid = trim($dados["uniqueid"]);
$audioFone = substr($userField, 0, -4);
$linkAudioFone = "" . "" . "";
}
$data = date('d/m/Y H:i:s', strtotime($dados['calldate']));
$duration = SecondToStrTime($dados['duration']);
$dados["src"] = strtoupper($dados["src"]) == "S" ? "-" : ocultarTelefone($dados["src"]);
$dst = ocultarTelefone($dados["destino"]);
$fila = !$dados['fila'] ? '-' : $dados['fila'];
$apelido = !$dados['apelido'] ? '-' : $dados['apelido'];
$tipo = $dados['direcao'];
$clasDesc = !$dados["clas_descricao"] ? '-' : $dados["clas_descricao"];
$ItemDesc = !$dados["clit_descricao"] ? '-' : $dados["clit_descricao"];
$linhas .= "
";
if ($mostaCallcenter)
$linhas .= "$fila |
$apelido | \n";
$linhas .= " $data |
$duration |
{$dados['src']} |
$dst |
$tipo | \n";
if ($mostaCallcenter)
$linhas .= "$proto |
$protoparceiro |
$clasDesc |
$ItemDesc | \n";
$linhas .= "$linkAudio $linkAudioFone |
";
$contaReg++;
}
} //Post Back
// ($dbcon, $codDac, $disableb = "", $incTodos = 0, $soAtivo = 1, $incCampanha = 0, $matricula = 0, $useNull = 0, $valueUseNull='', $useSelect=1)
$cssBlock = '';
$dacs = GetDac($dbcon, $_SESSION["listaDacs"], "", 1, 0, 1, 0, 0, '', 1, 1);
$agentes = GetAgtAudio($dbcon);
$class = GetClassAudio($dbcon);
$itemClas = GetClassItemAudio($dbcon);
$linhas .= "
Total de Registros |
$pagMostra de $totalReg |
";
$jsJQuery[] = "\$('#dataIni').keypress(function(){formataDataHora(this);}) ";
$jsJQuery[] = "\$('#dataFim').keypress(function(){formataDataHora(this);}) ";
//Tamanho da tabela dos filtros
$filtroWidth = 190;
$erro = '';
//if($isPostBack){$erro = ""; if(pg_last_error($dbcon)) $erro = "Ocorreram erros durante a operação. Erro: " . pg_last_error($dbcon);}
$smarty->assign('erro', $erro);
$smarty->assign('filtroWidth', $filtroWidth);
$smarty->assign('dtIni', IsPostBack() || $exitAudio || isset($_GET['pgn']) ? $_SESSION["dataIni"] : date('d/m/Y'));
$smarty->assign('dtFim', IsPostBack() || $exitAudio || isset($_GET['pgn']) ? $_SESSION["dataFim"] : date('d/m/Y'));
$smarty->assign('duracao', $_SESSION["duracao"]);
$smarty->assign('src', $_SESSION["src"]);
$smarty->assign('dst', $_SESSION["dst"]);
$smarty->assign('proto', $_SESSION["proto"]);
$smarty->assign('tipo', $_SESSION["tipoConsulta"]);
$smarty->assign('dacs', $dacs);
$smarty->assign('agentes', $agentes);
$smarty->assign('class', $class);
$smarty->assign('itemClas', $itemClas);
$smarty->assign('linhas', $linhas);
$smarty->assign('mostraCallcenter', $mostaCallcenter);
$smarty->assign('nomeRamalMonitor', (RAMAL_MONITOR_AUDIO));
$smarty->assign('canalRamallMonitor', (CANAL_MONITOR_AUDIO));
$smarty->assign('ramal_monitor', GetRamalMonitorar(RAMAL_MONITOR_AUDIO));
$smarty->assign('colspan', $colspan + 1);
$smarty->assign('links', $links);
GetTemplate($smarty, 'audio.tpl');
}
function GetQuery($db) {
//print "agente ".$_POST["listaAgente"]."
";
$dt = !soNumero($_SESSION["dataIni"]) ? "null" : FormatDtMssql($_SESSION["dataIni"]);
$dtFim = !soNumero($_SESSION["dataFim"]) ? "null" : FormatDtMssql($_SESSION["dataFim"]);
$src = !soNumero($_SESSION["src"]) ? "null" : soNumero($_SESSION["src"]);
$dst = !soNumero($_SESSION["dst"]) ? "null" : soNumero($_SESSION["dst"]);
$proto = !soNumero($_SESSION["proto"]) ? "null" : soNumero($_SESSION["proto"]);
$dac = $_SESSION["listaDacs"];
$agente = $_SESSION["listaAgente"];
$class = $_SESSION["listaClass"];
$classItem = $_SESSION["listaItem"];
$tipo = $_SESSION["tipoConsulta"];
$duracao = $_SESSION["duracao"];
return GetDadosRelAudio($db, $crcCode, $dt, $dtFim, $src, $dst, $proto, $tipo, $dac, $agente, $class, $classItem, $duracao);
}
function GetDadosRelAudio($db, $crcCode, $dt, $dtFim, $src, $dst, $proto, $tipo, $dac, $agente, $class, $classItem, $duracao) {
$query = '';
$verProto = soNumero($proto);
$isProto = !empty($verProto);
if ($src != 'null') {
$src = QuotedStr("%$src%");
}
if ($dst != 'null') {
$dst = QuotedStr("%$dst%");
}
if ($proto != 'null') {
$proto = QuotedStr($proto);
}
if ($dt != 'null') {
$dt = QuotedStr("$dt");
}
if ($dtFim != 'null') {
$dtFim = QuotedStr("$dtFim");
}
$idUser = GetIdUser();
$dacTd = explode("|", $dac);
$dacs = '';
$y = 0;
if ($dacTd[1]) {
$dacs .= "AND c.id IN (";
foreach ($dacTd as $nDac) {
if ($y != 0) {
$dacs .= ", ";
}
$dacs .= "$nDac ";
$y = 1;
}
$dacs .= ") ";
} else {
$dac = "AND c.id = $dac ";
}
/*
* Variaveis globais indicam o tipo de query executada no momento,
* esses valores são modificados dentro das funções GetAgtAudio(), GetClassAudio(), GetClassItemAudio(),
* ou seja todos usam GetQuery para retornar uma query especifica para cada situação.
*/
$getAgt = isset($GLOBALS['getAgt']) && $GLOBALS['getAgt'];
$getClass = isset($GLOBALS['getClass']) && $GLOBALS['getClass'];
$getItem = isset($GLOBALS['getItem']) && $GLOBALS['getItem'];
if ((($tipo == 1) or ( $tipo == 2)) && !($getAgt || $getClass || $getItem)) {
$query = "drop table if exists tmp_restricao_ramal;
create temporary table tmp_restricao_ramal as
SELECT distinct x.nome FROM pbx_grupo_audio_ramal x, pbx_grupo_usuario y WHERE y.gp_id = x.gp_id AND y.user_id = '{$idUser}';
create index \"tmpRestricaoRamalNome\" on tmp_restricao_ramal(nome);\n\n";
$query .= "drop table if exists tmp_restricao_sigame;
create temporary table tmp_restricao_sigame as
select sigame_externo from pbx_sip_ramais where nome in (select nome from tmp_restricao_ramal) and sigame_externo <> ''; ";
}
$addPdx = !($getAgt || $getClass || $getItem);
if (($tipo == 0) || ($tipo == 2) || ($isProto)) {
if ($getAgt) {
$query .= "SELECT DISTINCT d.matricula, d.apelido\n";
} else if ($getClass) {
$query .= "SELECT DISTINCT h.clas_id, h.clas_descricao\n";
} else if ($getItem) {
$query .= "SELECT DISTINCT g.clit_id, g.clit_descricao\n";
} else {
$query .= " SELECT DISTINCT a.data_bilhete, a.uniqueid, CASE WHEN(b.evento <> '') THEN 'Fila' ELSE 'Ramal' END AS tipo,
CASE WHEN(b.evento in('COMPLETECALLER', 'COMPLETEAGENT','COMPLETEAGENTRAMAL','COMPLETECALLERRAMAL'))THEN 'entrada' ELSE 'saida' END AS direcao,
c.id AS iddac, b.fila, d.apelido, a.calldate, a.src,
a.dst AS destino,
a.userfield, e.protocolo, h.clas_id, h.clas_descricao, g.clit_id, g.clit_descricao,
CASE WHEN(b.evento IN('TRANSFERORIG', 'TRANSFER') )THEN strtoint(param4) ELSE strtoint(param2) END AS duration,
1 AS acesso_audio \n";
}
$query .= "FROM pbx_bilhetes a
LEFT JOIN pbx_eventos_dacs b ON b.uid2 = a.uniqueid AND b.evento IN('COMPLETAAGENT','COMPLETACALLER','TRANSFERORIG', 'COMPLETECALLER', 'COMPLETEAGENT', 'TRANSFER','COMPLETEAGENTRAMAL','COMPLETECALLERRAMAL')
LEFT JOIN pbx_dacs c ON c.nome = b.fila
LEFT JOIN pbx_usuarios d ON d.matricula = SUBSTRING(b.agente, 7,4)
LEFT JOIN pbx_protocolo_reg e ON e.uniqueid = a.uniqueid
LEFT JOIN pbx_classifica_reg f ON f.id_bilhetes = a.uniqueid
LEFT JOIN pbx_classifica_item g ON g.clas_id = f.clas_id and g.clit_id = f.clit_id
LEFT JOIN pbx_classifica_atendimento h ON h.clas_id = f.clas_id
WHERE a.billsec > 3 \n
AND exists(SELECT '' FROM pbx_fila_audios x, pbx_grupo_usuario y WHERE y.gp_id = x.gp_id AND y.user_id = '{$idUser}' and x.id = c.id)\n";
if ($isProto) {
$query .= "AND (e.protocolo = $proto or e.protoparceiro = $proto) ";
} else {
$query .= "AND a.data_bilhete >= COALESCE($dt, a.data_bilhete)
AND a.data_bilhete <= COALESCE($dtFim, a.data_bilhete) ";
if ($src != 'null') {
$query .= " AND a.src LIKE $src ";
}
if ($dst != 'null')
$query .= " and a.dst like $dst ";
// $query .= " AND (CASE WHEN(b.evento IN('COMPLETECALLER', 'COMPLETEAGENT','COMPLETEAGENTRAMAL','COMPLETECALLERRAMAL') AND d.apelido IS NOT NULL) THEN
// (SELECT MAX(destino) FROM pbx_bilhetes_complemento WHERE uniqueid2 = a.uniqueid AND direcao = 'fila-ramal')
// ELSE
// (SELECT destino FROM pbx_bilhetes_complemento WHERE uniqueid2 = a.uniqueid AND id = (SELECT MAX(id) FROM pbx_bilhetes_complemento WHERE uniqueid2 = a.uniqueid))
// END LIKE $dst)";
if ($dac) {
$query .= $dacs ? $dacs : $dac;
}
if ($agente && !$getAgt) {
$query .= " AND d.matricula = '$agente' ";
}
if (($class && !$getClass) || ($getItem && !$getClass)) {
$query .= " AND h.clas_id = '$class' ";
}
if ($classItem && !$getItem) {
$query .= " AND g.clit_id = '$classItem' ";
}
}
$query .= "AND COALESCE(a.userfield, '') <> '' AND a.lastapp <> 'Transferred Call' \n";
// if(GetLogin() == 'administrador') { echo $query; exit; }
}
if ((($tipo == 1) || ($tipo == 2)) && !$isProto && $addPdx) {
if ($tipo == 2) {
$query .= "UNION ALL \n";
}
$query .= " SELECT a.data_bilhete, a.uniqueid, 'PBX' AS tipo, tplg_descricao AS direcao,
0 as iddac, '' AS fila, '' AS apelido, a.calldate,
a.src, a.dst AS destino, a.userfield, 0 AS protocolo,
0::INTEGER AS clas_id, ''::VARCHAR(30) AS clas_descricao,
0::INTEGER AS clit_id, ''::VARCHAR(30) AS clit_descricao,
MAX(billsec) AS duration,
1 AS acesso_audio
FROM pbx_bilhetes a
INNER JOIN pbx_tipo_ligacao b ON b.tplg_codigo = a.tipo_chamada
WHERE NOT EXISTS(SELECT '' FROM pbx_eventos_dacs WHERE uid2 = a.uniqueid)
AND not exists(select '' from tmp_restricao_ramal where (nome = a.src or nome = a.dst))
AND NOT EXISTS(SELECT '' FROM tmp_restricao_sigame where (sigame_externo = a.src or sigame_externo = a.dst))
AND a.data_bilhete >= COALESCE($dt, a.data_bilhete)
AND a.data_bilhete <= COALESCE($dtFim, a.data_bilhete)";
if ($src != 'null') {
$query .= " AND a.src LIKE $src ";
}
if ($dst != 'null') {
$query .= " AND a.dst LIKE $dst ";
}
$query .= "AND COALESCE(a.userfield, '') NOT IN('', 'chamada-a-cobrar', 'fora-do-horario') AND a.billsec > 3 AND a.disposition = 'ANSWERED'
AND a.lastapp <> 'Transferred Call'
GROUP BY a.data_bilhete, a.uniqueid, tplg_descricao, a.calldate, a.src, a.dst, a.userfield \n";
}
if ($getAgt || $getClass || $getItem) {
$query .= "ORDER BY 2 \n";
} else if ($tipo == 0) {
$query .= "ORDER BY a.calldate DESC \n";
} else if ($tipo == 1) {
$query .= "ORDER BY a.calldate DESC \n";
} else if ($tipo == 2) {
$query .= "ORDER BY 8 \n";
}
if ($_GET['query'] == 1) {
echo $query;
}
// if(GetLogin() == 'amarildo.pereira') echo $query;
return $query;
}
function GetAgtAudio($db) {
$codSel = $_SESSION["listaAgente"];
$GLOBALS['getAgt'] = 1;
$sel = !$codSel ? 'selected="selected"' : '';
$select = "";
$GLOBALS['getAgt'] = 0;
return $select;
}
function GetClassAudio($db) {
$codSel = $_SESSION["listaClass"];
$GLOBALS['getClass'] = 1;
$sel = !$codSel ? 'selected="selected"' : '';
$select = "";
$GLOBALS['getClass'] = 0;
return $select;
}
function GetClassItemAudio($db) {
$codSel = $_SESSION["listaItem"];
$GLOBALS['getItem'] = 1;
$sel = !$codSel ? 'selected="selected"' : '';
$select = "";
$GLOBALS['getItem'] = 0;
return $select;
}
function GetAudioFoneAutomatico($file) {
if ($file) {
$dirMp3 = '/var/www/html/aplicativo/audio/';
$filepath = VerificaCharFinal($_SESSION[SS_PRM_PATH_AUDIO]) . $file;
$pathFileWav = sprintf("%s%s", $dirMp3, $file);
$patFileUlaw = str_ireplace('.WAV', '.ulaw', $pathFileWav);
/*
* Renomeia o file para mostrar corretamente.
*/
$file = str_ireplace('.WAV', '.ulaw', $file);
/*
* Cria o arquivo wav localmente.
*/
@file_put_contents($pathFileWav, @file_get_contents($filepath));
/*
* Convert para ulaw.
*/
$comando = "ffmpeg -i $arqOrigem -ar 8000 -ac 1 -ab 64 -f mulaw $arqDestino";
exec($comando);
/*
* Pega o tamanho do arquivo mp3 criado.
*/
$fsize = filesize($patFileUlaw);
header('Content-Description: File Transfer');
header('Content-Transfer-Encoding: binary');
header('Content-Type: ' . GetMimeContentType($file));
if ($fsize)
header('Content-Length: ' . $fsize);
header('Content-Disposition: attachment; filename="' . $file . '"');
header('Connection: close');
readfile($patFileUlaw);
unlink($pathFileWav);
unlink($patFileUlaw);
exit;
}
}
?>