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çõ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ção responsável por monitorar o agente * agtfila -> Chamadas em fila * agtdura -> Duração da chamada * agtfone -> Fone da chamada em curso * agtabd -> chamadas abandonadas para o agente logado * agttme -> Tempo médio de espera agente * agttma -> tempo mé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á esperar para verificar o status do agente */ $tempoStatusAgt = $this->tempoVerificaAgt; /* * tempo em segundos em que será atualizadas as informações referentes a fila, * o mesmo esta definido em 3x o tempo do agente porém nã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çã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 "\n"; echo str_repeat(' ', 128); */ //ob_end_flush(); flush(); } protected function PrintInfo($info, $id = 0) { echo str_repeat(' ', 128); echo "\n"; //echo "$id -> " . htmlentities($info) . "
"; 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(); ?>