";
$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 = "