$inicio $fim $motivo $displayTempo "; $buffDados[] = $linha; $linhas .= $linha; } $displayTempo = SecondToStrTime($somaTempo); $linha = " Quantidade $qtPausa Tempo $displayTempo "; $buffDados[] = $linha; $linhas .= $linha; $_SESSION["SSlinhasPausasDiscador"] = $buffDados; //agrupado $query = GetQuery($cmpId, $listId, $dataIni, $dataFim, $matricula, 1); $result = pg_query($dbcon, $query); $linhaAgrup = ""; while ($dados = pg_fetch_array($result)) { $motivo = $dados["motivo"]; $tempo = $dados["tempo_operacao"]; $qtAgrup = $dados["qtde"]; $displayTempoAgrup = SecondToStrTime($tempo); $linhaAgrup .= " $motivo $qtAgrup $displayTempoAgrup "; } $_SESSION["SSlinhasPausasDiscadorAgp"] = $linhaAgrup; //Atualiza template $smarty->assign("dacs", $dacs); $smarty->assign("agente", $agente); $smarty->assign("listas", $listas); $smarty->assign('dataIni', $dataIni); $smarty->assign('dataFim', $dataFim); $smarty->assign("linha", $linhas); $smarty->assign("linhaAgrupado", $linhaAgrup); $smarty->assign("imp", $imp); //Seta o template GetTemplate($smarty, $templateName); function GetQuery($cmpId, $listId, $dtIni, $dtFim, $matricula, $tipo = 0) { $idSessao = session_id(); if ($tipo == 0) { $ret = " select a.matricula, a.inicio_operacao as entrada_pausa, a.final_oepracao as saida_pausa, c.apelido, a.operacao as motivo, extract(epoch from ((a.final_oepracao - a.inicio_operacao))) as tempo_operacao from pbx_desempenho_discador a, pbx_usuarios c where c.matricula = a.matricula and a.operacao not in('livre', 'atendimento') and id_dac = '$cmpId' and a.id_sessao = '$idSessao' and a.matricula = case when('$matricula' = '0')then a.matricula else '$matricula' end order by 1, 2;"; } else { $ret = "select a.matricula, a.operacao as motivo, count(*) as qtde, sum( extract(epoch from ((a.final_oepracao - a.inicio_operacao)))) as tempo_operacao from pbx_desempenho_discador a, pbx_usuarios c where c.matricula = a.matricula and a.operacao not in('livre', 'atendimento') and id_dac = '$cmpId' and a.id_sessao = '$idSessao' and a.matricula = case when('$matricula' = '0')then a.matricula else '$matricula' end group by a.matricula, a.operacao order by 3 desc"; } return $ret; } ?>