|
|
|
|
<?php
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
* O script executa infinitamente
|
|
|
|
|
*/
|
|
|
|
|
ini_set("max_execution_time", 0);
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
* Define um milhonesimo de segundo
|
|
|
|
|
* usado para calculos de segundo na
|
|
|
|
|
* funcao usleep
|
|
|
|
|
*/
|
|
|
|
|
define("SEG", 1000000);
|
|
|
|
|
/*
|
|
|
|
|
* Numero de segundo em que o monitor
|
|
|
|
|
* retornara informa<EFBFBD><EFBFBD>es para o agente
|
|
|
|
|
*/
|
|
|
|
|
define("TIME_SLEEP_AGT", 1);
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
* Define o tempo maximo em que informa<EFBFBD><EFBFBD>es
|
|
|
|
|
* do dac ser<EFBFBD>o retornados para a aplica<EFBFBD><EFBFBD>o.
|
|
|
|
|
*/
|
|
|
|
|
define("TIME_MIN_INFO_DAC", 10);
|
|
|
|
|
/*
|
|
|
|
|
* Este valor ser<EFBFBD> multiplicado pelo tempo
|
|
|
|
|
* definido para retornar as informa<EFBFBD><EFBFBD>es do agente, pois,
|
|
|
|
|
* as informa<EFBFBD><EFBFBD>es do dac n<EFBFBD>o precisam ser atualizadas com
|
|
|
|
|
* a mesma frequencia do agente
|
|
|
|
|
*/
|
|
|
|
|
define("TIME_ADIC_INFO_DAC", 3);
|
|
|
|
|
|
|
|
|
|
class MonitorAgente {
|
|
|
|
|
|
|
|
|
|
public function __construct($dbConect) {
|
|
|
|
|
$this->endScrp = false;
|
|
|
|
|
$this->statusAgt = false;
|
|
|
|
|
$this->matricula = GetMatricula();
|
|
|
|
|
$this->ramal = GetRamal();
|
|
|
|
|
$this->login = GetLogin();
|
|
|
|
|
$this->dac = $_SESSION[SS_DAC_CODIGO];
|
|
|
|
|
$this->dacDesc = $_SESSION[SS_DAC_DESCRICAO];
|
|
|
|
|
$this->db = $dbConect;
|
|
|
|
|
/*
|
|
|
|
|
* tempo em segundos que o aplicativo ira
|
|
|
|
|
* chacar os dados
|
|
|
|
|
*/
|
|
|
|
|
$this->tempoVerificaAgt = (SEG * TIME_SLEEP_AGT);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private function RetStatusAgt() {
|
|
|
|
|
return $this->statusAgt;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function __destruct() {
|
|
|
|
|
$this->LogoffAgente();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private function GetQueryMonitor($qr) {
|
|
|
|
|
$matricula = $this->matricula;
|
|
|
|
|
$dac = $this->dac;
|
|
|
|
|
$fila = $this->dacDesc;
|
|
|
|
|
if ($qr == 1) {
|
|
|
|
|
return "select (LOCALTIMESTAMP(0) - tempo_login) as tempo_logado, origem_destino as fone,
|
|
|
|
|
trim(status) as status_agente, (LOCALTIMESTAMP(0) - duracao) as duracao,
|
|
|
|
|
protocolo as num_protocolo, ramal as ramal_agente,
|
|
|
|
|
uniqueid2, extract(epoch from (now() - logado))::int as tempo_atualiza,
|
|
|
|
|
trim(motivo_pausa) as pausa_motivo_rt,
|
|
|
|
|
trim(uniqueid) as uniqueid, disponivel_atendimento
|
|
|
|
|
from pbx_supervisor_agentes
|
|
|
|
|
where matricula = '$matricula' ";
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if ($qr == 2) {
|
|
|
|
|
/*
|
|
|
|
|
* Informa<EFBFBD><EFBFBD>es sobre a fila de atendimento
|
|
|
|
|
*/
|
|
|
|
|
return "SELECT
|
|
|
|
|
ATENDIDAS_PA
|
|
|
|
|
,ORIGINADAS_PA
|
|
|
|
|
,round( CASE WHEN(ESPERA = 0)THEN 0 ELSE (TEMPO_ESPERA / ESPERA) END ) * INTERVAL '1 SECOND' AS TME
|
|
|
|
|
,round( CASE WHEN(ATENDIDAS_PA = 0)THEN 0 ELSE ((TEMPO_ATENDIMENTO + TEMPO_ORIGINDADA) / (ATENDIDAS_PA + ORIGINADAS_PA))END) * INTERVAL '1 SECOND' AS TMA
|
|
|
|
|
FROM (
|
|
|
|
|
SELECT fila
|
|
|
|
|
,SUM (CASE WHEN EVENTO IN ('COMPLETEAGENT','COMPLETECALLER', 'TRANSFER') THEN 1 ELSE 0 END) AS ATENDIDAS_PA
|
|
|
|
|
,SUM (CASE WHEN EVENTO IN ('COMPLETAAGENT','COMPLETACALLER', 'TRANSFERORIG') THEN 1 ELSE 0 END) AS ORIGINADAS_PA
|
|
|
|
|
,SUM (CASE WHEN EVENTO IN ('CONNECT') AND to_number(param1,'999999999') > '3' THEN 1 ELSE 0 END) AS ESPERA
|
|
|
|
|
,SUM (CASE WHEN EVENTO IN ('CONNECT') AND to_number(param1,'999999999') > '1' THEN to_number(param1,'999999999') ELSE 0 END) AS TEMPO_ESPERA
|
|
|
|
|
,SUM (CASE WHEN EVENTO IN ('COMPLETEAGENT','COMPLETECALLER') AND to_number(param2,'999999999') > '1' THEN to_number(param2,'999999999') ELSE 0 END) AS TEMPO_ATENDIMENTO
|
|
|
|
|
,SUM (CASE WHEN EVENTO IN ('COMPLETAAGENT','COMPLETACALLER') AND to_number(param2,'999999999') > '1' THEN to_number(param2,'999999999') ELSE 0 END) AS TEMPO_ORIGINDADA
|
|
|
|
|
,SUM (CASE WHEN( (EVENTO = 'ABANDON') AND (to_number(param2,'999999999') > '1') ) THEN to_number(param3,'999999999') ELSE 0 END) AS TEMPO_ABANDONO
|
|
|
|
|
FROM (
|
|
|
|
|
SELECT
|
|
|
|
|
a.calldate,b.fila,b.evento,b.param1,b.param2,b.param3,b.param4
|
|
|
|
|
FROM ast_bilhetes a
|
|
|
|
|
INNER JOIN ast_eventos_dacs b on b.uid2 = a.uniqueid
|
|
|
|
|
INNER JOIN pbx_dacs c on c.nome = b.fila
|
|
|
|
|
WHERE b.evento in ('ABANDON','COMPLETEAGENT','COMPLETECALLER','TRANSFER', 'COMPLETAAGENT','COMPLETACALLER', 'TRANSFERORIG','ENTERQUEUE')
|
|
|
|
|
AND a.calldate IS NOT NULL
|
|
|
|
|
AND a.lastapp <> 'Transferred Call'
|
|
|
|
|
AND cast(a.calldate as date) = cast(now() as date)
|
|
|
|
|
AND substring(b.agente, 7,4) = '$matricula'
|
|
|
|
|
AND c.id = $dac
|
|
|
|
|
) AS DADOS
|
|
|
|
|
GROUP BY FILA
|
|
|
|
|
) AS DADOS
|
|
|
|
|
";
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if ($qr == 3) {
|
|
|
|
|
return "select abandonadas, espera as qtde_fila from pbx_supervisor_dacs where upper(trim(dac)) = upper('$fila') ";
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private function GetDadosMonitor() {
|
|
|
|
|
//Agente
|
|
|
|
|
$dadosMonitor = array();
|
|
|
|
|
$result = @pg_query($this->db, $this->GetQueryMonitor(1));
|
|
|
|
|
$this->statusAgt = ($result && (pg_num_rows($result) > 0));
|
|
|
|
|
if ($this->statusAgt) {
|
|
|
|
|
$dadosMonitor = pg_fetch_array($result);
|
|
|
|
|
foreach ($dadosMonitor as $key => $value) {
|
|
|
|
|
if (array_key_exists($key, $this->dadosMonitor) && $value) {
|
|
|
|
|
$this->dadosMonitor[$key] = $value;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//Fila
|
|
|
|
|
$result = @pg_query($this->db, $this->GetQueryMonitor(2));
|
|
|
|
|
$this->statusAgt = ($result && (pg_num_rows($result) > 0));
|
|
|
|
|
if ($this->statusAgt) {
|
|
|
|
|
$dadosMonitor = pg_fetch_array($result);
|
|
|
|
|
foreach ($dadosMonitor as $key => $value) {
|
|
|
|
|
if (array_key_exists($key, $this->dadosMonitor) && $value) {
|
|
|
|
|
$this->dadosMonitor[$key] = $value;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//Complemento
|
|
|
|
|
$result = @pg_query($this->db, $this->GetQueryMonitor(3));
|
|
|
|
|
$this->statusAgt = ($result && (pg_num_rows($result) > 0));
|
|
|
|
|
if ($this->statusAgt) {
|
|
|
|
|
$dadosMonitor = pg_fetch_array($result);
|
|
|
|
|
foreach ($dadosMonitor as $key => $value) {
|
|
|
|
|
if (array_key_exists($key, $this->dadosMonitor)) {
|
|
|
|
|
$this->dadosMonitor[$key] = $value;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private function LogoffAgente() {
|
|
|
|
|
//se tpatend manual remove agente da fila
|
|
|
|
|
if ($_SESSION[AGT_TP_ATEND] == 0)
|
|
|
|
|
@GetUrl(AST_REM_FILA);
|
|
|
|
|
|
|
|
|
|
$result = GetUrl(AST_LOGOFF_AGENTE);
|
|
|
|
|
|
|
|
|
|
if ($result) {
|
|
|
|
|
$result = pg_query("begin");
|
|
|
|
|
//atualiza dados do supervisor
|
|
|
|
|
|
|
|
|
|
$query = "delete
|
|
|
|
|
from pbx_supervisor_agentes
|
|
|
|
|
where matricula = '$matricula'";
|
|
|
|
|
$result = pg_query($query);
|
|
|
|
|
$result = pg_affected_rows($result);
|
|
|
|
|
|
|
|
|
|
//registra o login do usuario
|
|
|
|
|
if ($result) {
|
|
|
|
|
$idLogoff = $_SESSION[AGT_ID_LOGIN];
|
|
|
|
|
$query = "update pbx_eventos_agentes
|
|
|
|
|
set logoff = now()
|
|
|
|
|
where id = $idLogoff";
|
|
|
|
|
$result = pg_query($query);
|
|
|
|
|
$result = pg_affected_rows($result);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
if ($result) {
|
|
|
|
|
pg_query("commit");
|
|
|
|
|
$_SESSION[AGT_CONECT] = 0;
|
|
|
|
|
$_SESSION[AGT_TP_ATEND] = 0;
|
|
|
|
|
$_SESSION[AGT_DAC_CONECT] = 0;
|
|
|
|
|
return true;
|
|
|
|
|
} else {
|
|
|
|
|
pg_query("rollback");
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private function VerificaAgenteLogado() {
|
|
|
|
|
$matricula = GetMatricula();
|
|
|
|
|
$query = "select count(*) from pbx_supervisor_agentes where matricula = '$matricula'";
|
|
|
|
|
$result = pg_query($query);
|
|
|
|
|
$row = pg_fetch_row($result);
|
|
|
|
|
return $row[0];
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private function RemoveAgenteFila() {
|
|
|
|
|
GetUrl(AST_REM_FILA);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private function GetEndScrp() {
|
|
|
|
|
return $this->endScrp;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
* Fun<EFBFBD><EFBFBD>o respons<EFBFBD>vel por monitorar o agente
|
|
|
|
|
* agtfila -> Chamadas em fila
|
|
|
|
|
* agtdura -> Dura<EFBFBD><EFBFBD>o da chamada
|
|
|
|
|
* agtfone -> Fone da chamada em curso
|
|
|
|
|
* agtabd -> chamadas abandonadas para o agente logado
|
|
|
|
|
* agttme -> Tempo m<EFBFBD>dio de espera agente
|
|
|
|
|
* agttma -> tempo m<EFBFBD>dio de atendimeto agente
|
|
|
|
|
* agtatd -> Quantidade de chamadas atendidas agente
|
|
|
|
|
* agtramal -> ramal do agente
|
|
|
|
|
* agtdac -> dac em que esta conectado
|
|
|
|
|
* agtstatus -> status atual do agente
|
|
|
|
|
* agthoraAtu -> hora atual
|
|
|
|
|
* agtlgd -> tempo logado
|
|
|
|
|
* agtproto -> numero do procolo de atendimento
|
|
|
|
|
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
public function Monitor() {
|
|
|
|
|
/*
|
|
|
|
|
* Fila ao qual o agente esta logado
|
|
|
|
|
*/
|
|
|
|
|
$dac = $this->dacDesc;
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
* Matricula do agente logado
|
|
|
|
|
*/
|
|
|
|
|
$matricula = $this->matricula;
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
* Tempo em segundos que o script ir<EFBFBD> esperar para verificar o status do agente
|
|
|
|
|
*/
|
|
|
|
|
$tempoStatusAgt = $this->tempoVerificaAgt;
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
* tempo em segundos em que ser<EFBFBD> atualizadas as informa<EFBFBD><EFBFBD>es referentes a fila,
|
|
|
|
|
* o mesmo esta definido em 3x o tempo do agente por<EFBFBD>m n<EFBFBD>o suporior a 10s
|
|
|
|
|
*
|
|
|
|
|
*/
|
|
|
|
|
$tempoStatusDac = (TIME_ADIC_INFO_DAC * $tempoStatusAgt) <= TIME_MIN_INFO_DAC ? (TIME_ADIC_INFO_DAC * $tempoStatusAgt) : 10;
|
|
|
|
|
$tempoDac = 0;
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
* Loop tem a dura<EFBFBD><EFBFBD>o que tiver o login do agente
|
|
|
|
|
*/
|
|
|
|
|
$displayMonitor = "";
|
|
|
|
|
$this->IniciaJS();
|
|
|
|
|
$idMessage = 0;
|
|
|
|
|
while (1) {
|
|
|
|
|
$displayMonitor = "";
|
|
|
|
|
$this->GetDadosMonitor();
|
|
|
|
|
$displayMonitor = $this->DadosMonitorAgt($this->dadosMonitor);
|
|
|
|
|
|
|
|
|
|
$idMessage++;
|
|
|
|
|
$this->PrintInfo($displayMonitor, $idMessage);
|
|
|
|
|
$this->UpdateLogoffRt($this->db);
|
|
|
|
|
$this->UpdatePausaRt($this->db);
|
|
|
|
|
usleep(15000000);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private function DadosMonitorAgt($dados) {
|
|
|
|
|
$str = "";
|
|
|
|
|
foreach ($dados as $key => $value) {
|
|
|
|
|
//$str .= sprintf("parent.document.getElementById(\"%s\").innerHTML = '%s';\n", $key, $value);
|
|
|
|
|
$str .= sprintf(" parent.GetElement('%s', '%s');\n", $key, $value);
|
|
|
|
|
}
|
|
|
|
|
return $str;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private function IniciaJS() {
|
|
|
|
|
ob_clean();
|
|
|
|
|
header("Cache-Control: no-cache, must-revalidate");
|
|
|
|
|
header("Expires: Mon, 26 Jul 1997 05:00:00 GMT");
|
|
|
|
|
/* echo str_repeat(' ', 128);
|
|
|
|
|
echo "<script type=\"text/javascript\">\n";
|
|
|
|
|
echo " <!--\n";
|
|
|
|
|
echo "function GetElement(id, value){ var obj = parent.document.getElementById(id); if(obj !== null){ parent.document.getElementById(id).innerHTML = value;}}";
|
|
|
|
|
echo " \n//-->\n";
|
|
|
|
|
echo "</script>\n";
|
|
|
|
|
|
|
|
|
|
echo str_repeat(' ', 128); */
|
|
|
|
|
//ob_end_flush();
|
|
|
|
|
flush();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
protected function PrintInfo($info, $id = 0) {
|
|
|
|
|
echo str_repeat(' ', 128);
|
|
|
|
|
echo "<script type=\"text/javascript\">\n";
|
|
|
|
|
echo " <!--\n";
|
|
|
|
|
echo $info ? $info : "$id -> mensagem <br>";
|
|
|
|
|
echo " \n//-->\n";
|
|
|
|
|
echo "</script>\n";
|
|
|
|
|
|
|
|
|
|
//echo "$id -> " . htmlentities($info) . "<br>";
|
|
|
|
|
|
|
|
|
|
echo str_repeat(' ', 128);
|
|
|
|
|
//ob_end_flush();
|
|
|
|
|
flush();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private function UpdateLogoffRt($db) {
|
|
|
|
|
if ($_SESSION[SS_PAUSA_AGENTE]) {
|
|
|
|
|
$this->UpdatePausaRt($db);
|
|
|
|
|
}
|
|
|
|
|
$matricula = GetMatricula();
|
|
|
|
|
$dac = $_SESSION[SS_DAC_CODIGO];
|
|
|
|
|
|
|
|
|
|
$query = "update pbx_supervisor_agentes
|
|
|
|
|
set logado = now()
|
|
|
|
|
where matricula = '$matricula'";
|
|
|
|
|
$result = pg_query($db, $query);
|
|
|
|
|
|
|
|
|
|
$query = "update pbx_eventos_agentes
|
|
|
|
|
set logoff = now(),
|
|
|
|
|
flag = 1
|
|
|
|
|
where matricula = '$matricula'
|
|
|
|
|
and id_dac = $dac
|
|
|
|
|
and login = (select max(login) from pbx_eventos_agentes where matricula = '$matricula' and id_dac = $dac)";
|
|
|
|
|
@pg_query($db, $query);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private function UpdatePausaRt($db) {
|
|
|
|
|
$matricula = GetMatricula();
|
|
|
|
|
$dac = $_SESSION[SS_DAC_CODIGO];
|
|
|
|
|
$query = "update pbx_eventos_agentes
|
|
|
|
|
set saida_pausa = now(),
|
|
|
|
|
flag = 1
|
|
|
|
|
where matricula = '$matricula'
|
|
|
|
|
and id_dac = $dac
|
|
|
|
|
and entrada_pausa = (select max(entrada_pausa) from pbx_eventos_agentes where matricula = '$matricula' and id_dac = $dac)";
|
|
|
|
|
@pg_query($db, $query);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private $dadosMonitor = array("qtde_fila" => 0, "duracao" => '00:00:00', "fone" => '-', "abandonadas" => '0', "tme" => '0', "tma" => '0',
|
|
|
|
|
"atendidas_pa" => '0', "num_protocolo" => '-', "ramal_agente" => '', "dac_logado" => '-',
|
|
|
|
|
"status_agente" => 'OFF', "tempo_logado" => '-', "uniqueid2" => 0, "tempo_atualiza" => 0, "pausa_motivo_rt" => '-',
|
|
|
|
|
"uniqueid" => 0, 'matricula' => '-', "disponivel_atendimento" => 1, "uf_origem" => '', "mun_origem" => '', "mun_id" => '0', "prefixo_fone" => '',
|
|
|
|
|
"disponivelFila" => '1', "originadas_pa" => '0');
|
|
|
|
|
private $endScrp;
|
|
|
|
|
private $matricula;
|
|
|
|
|
private $ramal;
|
|
|
|
|
private $dac;
|
|
|
|
|
private $dacDesc;
|
|
|
|
|
private $login;
|
|
|
|
|
private $tempoVerificaAgt;
|
|
|
|
|
private $db;
|
|
|
|
|
private $statusAgt;
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
$monitor = new MonitorAgente($dbcon);
|
|
|
|
|
$monitor->Monitor();
|
|
|
|
|
?>
|