"; $agentes .= ""; if (!IsAjax()) $idDac = $_SESSION["listaDacs"]; else $idDac = $_GET["listaDacs"]; $dtAgtIni = FormatDtMssql($_SESSION["dataIni"]); $dtAgtFim = FormatDtMssql($_SESSION["dataFim"]); $query = " select distinct matricula, apelido as nome from pbx_bilhetes a, pbx_eventos_dacs b, pbx_usuarios c, pbx_dacs d where b.uid2 = a.uniqueid and c.matricula = substring(b.agente, 7, 4) and d.nome = b.fila and b.evento in('CONNECT', 'COMPLETECALLER', 'COMPLETEAGENT' , 'TRANSFER', 'COMPLETAAGENT','COMPLETACALLER','TRANSFERORIG') \n"; if ($idDac) $query .= " and d.id = $idDac "; $query .= " and a.lastapp <> 'Transferred Call' and coalesce(a.userfield, '') <> '' and cast(a.calldate as date) >= '$dtAgtIni' and cast(a.calldate as date) <= '$dtAgtFim' order by 2"; $result = pg_query($dbcon, $query); //if(IsAdmin())echo $query; $numAgt = 0; while ($dados = @pg_fetch_row($result)) { if ($codSel == $dados[0]) { $sel = "selected"; $i = 1; } else { $sel = ""; } $agentes .= ""; $numAgt++; } $agentes .= ""; if (!$numAgt) $agentes = str_replace('Todos', '------', $agentes); if (IsAjax()) { echo $agentes; } else { //relatorio $imp = 0; $linhas = ""; //Verifica se é o primeiro acesso a pagia $isPostBack = isset($_GET["idProg"]) ? 0 : 1; if ($isPostBack || !$exitAudio) { $setQuery = !$exitAudio ? $_SESSION["setQuery"] : GetQuery($trocaDac); $result = pg_query($dbcon, $setQuery); $_SESSION["setQuery"] = $setQuery; $contaReg = 0; $audio = array(); $audioTemp = array(); $dadosSaida = array(); $dadosTipo = array(); while ($dados = @pg_fetch_array($result)) { $fila = trim($dados[fila]); if ($fila <> '-') { $dados['tipo'] = 'ext_fila'; } $dadosSaida[] = $dados; $userField = trim($dados["userfield"]); $tipo = ($dados["direcao"]); if (!$dadosTipo[$userField][$tipo]) $dadosTipo[$userField][$tipo] = 0; else $dadosTipo[$userField][$tipo] ++; if (!$audioTemp[$userField]) $audioTemp[$userField] = 1; else $audioTemp[$userField] ++; } $dados = array(); foreach ($dadosSaida as $dados) { $userField = trim($dados["userfield"]); $linkAudio = "" . "" . ""; // $repAudio = ""; $data = date('d/m/Y H:i:s', strtotime($dados['calldate'])); $duration = SecondToStrTime($dados['duration']); $dados["src"] = strtoupper($dados["src"]) == "S" ? "-" : $dados["src"]; $dst = $dados["destino"]; $idAud = array_search($dados[userfield], $audio); $fila = trim($dados[fila]); $tipo = GetTipoAudio($dados["tipo"], $fila); $proto = substr($dados["protocolo"], 0, 4) . '-' . substr($dados["protocolo"], 4, 6); if (($idAud === false) && !empty($userField)) { if ($audioTemp[$userField] > 1) $tipo = GetTipoAudioDupl($dadosTipo[$userField], $dados["direcao"], $dados[fila]); $linhas .= " $fila $dados[apelido] $data $duration $dados[src] $dst $tipo $proto $linkAudio "; $contaReg++; } $audio[] = $userField; } } $linhas .= " Total de Registros $contaReg "; $jsJQuery[] = "\$('#listaDacs').change(function(){GetAgtFromAudio();}) "; $jsJQuery[] = "\$('#dataIni').keypress(function(){formataDataHora(this);}) "; $jsJQuery[] = "\$('#dataIni').blur(function(){GetAgtFromAudio();}) "; $jsJQuery[] = "\$('#dataFim').keypress(function(){formataDataHora(this);}) "; $jsJQuery[] = "\$('#dataFim').blur(function(){GetAgtFromAudio();}) "; 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('dtIni', $_SESSION["dataIni"]); $smarty->assign('dtFim', $_SESSION["dataFim"]); $smarty->assign('dacs', $dacs); $smarty->assign('agentes', $agentes); $smarty->assign('src', $_SESSION["src"]); $smarty->assign('dst', $_SESSION["dst"]); $smarty->assign('proto', $_SESSION["proto"]); $smarty->assign('linhas', $linhas); $smarty->assign('tipoLigacao', $tipoLigacao); DispRel($smarty); } function DispRel($smarty) { $smarty->display('audio.tpl'); //$smarty->display('audioOld.tpl'); } function GetQuery($trocaDac) { //print "agente ".$_POST["listaAgente"]."
"; $dac = $_POST["listaDacs"]; $agente = ((!$_POST["listaAgente"]) || ($trocaDac)) ? $_SESSION["listaAgente"] : $_POST["listaAgente"]; $dt = !$_POST["dataIni"] ? $_SESSION["dataIni"] : $_POST["dataIni"]; $dtFim = !$_POST["dataFim"] ? $_SESSION["dataFim"] : $_POST["dataFim"]; $src = !$_POST["src"] ? $_SESSION["src"] : $_POST["src"]; $dst = !$_POST["dst"] ? $_SESSION["dst"] : $_POST["dst"]; $proto = soNumero($_SESSION["proto"]); $tpLigacao = $_SESSION["tipoLigacao"]; $query = "select * from ( select distinct case coalesce(c.direcao, '-') when('entrada-pstn')then 'entrada-pstn' when('ext-ramais')then 'interna' when('interna')then 'interna' when('saida-pstn')then 'saida-pstn' when('ext-fila')then 'ext-fila' when('-')then (case when(b.fila is not null)then 'ext-fila' else 'ni' end) else 'interna' end as tipo, c.direcao, e.id as iddac, coalesce(b.fila, '-') as fila, coalesce(d.apelido, '-') as apelido, coalesce(d.matricula, '-') as matricula, a.calldate, a.src, a.dst as destino, case when(coalesce(b.fila, '') <> '')then case when( (b.evento in('COMPLETECALLER', 'COMPLETEAGENT', 'COMPLETAAGENT','COMPLETACALLER')) and (coalesce(b.param2, '') <> ''))then b.param2::int else case when( (b.evento in('TRANSFER','TRANSFERORIG')) and (coalesce(b.param4, '') <> ''))then b.param4::int else 0 end end else a.billsec end as duration, a.userfield, f.protocolo from pbx_bilhetes a left outer join pbx_eventos_dacs b on b.uid2 = a.uniqueid and b.evento in('CONNECT','COMPLETAAGENT','COMPLETACALLER','TRANSFERORIG', 'COMPLETECALLER', 'COMPLETEAGENT' , 'TRANSFER') left outer join pbx_bilhetes_complemento c on c.uniqueid2 = a.uniqueid left outer join pbx_usuarios d on d.matricula = substring(b.agente, 7, 4) left outer join pbx_dacs e on e.nome = b.fila left outer join pbx_protocolo_reg f on f.uniqueid = a.uniqueid where 1=1 and a.lastapp <> 'Transferred Call' ) as a where 1=1 and a.duration > 0 "; if (empty($proto)) { if ($dac) $query .= " and a.idDac = $dac "; if (!empty($dt)) $query .= " and cast(a.calldate as date) >= '" . FormatDtMssql($dt) . "'\n"; if (!empty($dtFim)) $query .= " and cast(a.calldate as date) <= '" . FormatDtMssql($dtFim) . "'\n"; if ($agente) $query .= " and a.matricula = '" . $agente . "'\n"; if ($src) $query .= " and a.src like '%" . $src . "%'\n"; if ($dst) $query .= " and a.destino like '%" . $dst . "%'\n"; if (($tpLigacao == 'ext-fila') || ($tpLigacao == 'entrada-pstn')) { $query .= $dac ? "and a.tipo in( 'ext-fila', 'entrada-pstn') and fila <> '-' " : " and a.tipo in( 'ext-fila', 'entrada-pstn') and fila = '-' "; } else if ($tpLigacao) { $query .= " and a.tipo = '$tpLigacao' "; } } else { $query .= " and a.protocolo = '$proto' \n"; } $query .= " order by 6 desc\n "; //if(IsAdmin()) echo $query; return $query; } function GetTipoAudio($tipo, $fila) { if ($fila <> '-') return 'Fila'; if ($tipo == 'ext-entrada') return 'Entrada'; else if ($tipo == 'ext-saida') return 'Saída'; else if ($tipo == 'ext-fila') return 'Fila'; else return 'interna'; } function GetTipoAudioDupl($dadosTipo, $tipo, $fila) { if (array_key_exists('ext-fila', $dadosTipo)) return $fila == '-' ? 'Entrada' : 'Fila'; if (array_key_exists('entrada-pstn', $dadosTipo)) return 'Entrada'; if (array_key_exists('saida-pstn', $dadosTipo)) return 'Saída'; if (array_key_exists('ext-ramais', $dadosTipo)) return 'interna'; return ($tipo); } ?>