<?php
//VerificaPerfilAcesso(SEG_SUPERVISOR);
require_once("bd.php");
/*
* obtem o valor do dac selecionado
*/
$dac = isset($_GET["listaDacs"]) ? $_GET["listaDacs"] : -1;
/*
* Valores para o head das tabelas de dac e agente
*/
$imMonitor = "< img src = \"imgSite/search16.png\" title = \"Monitor\" alt = \"Monitor\" width = \"16\" height = \"16\" > ";
$tbHeadDac = array($imMonitor, 'Dac', 'Atendimento', 'Abandonadas', 'Espera', 'Tempo Espera', 'Ní vel de Servico'); //,'Tempo Ní vel de Servico'
$tbHeadAgente = array('Ramal', 'Matrí cula', 'Nome', 'Login', 'Atendimento', 'Orig/Dest', 'Status', 'Duraç ã o', '', '', '', '');
/*
* Monta as tebelas de dac e agente
*/
$tbDac = GetTbDac($dbcon, $dac, $tbHeadDac);
$tbAgente = GetTbAgente($dbcon, $dac, $tbHeadAgente);
if (IsAjax() & & isset($_GET["logoff"])) {
$isFila = strtoupper($_GET["modu"]) == "MANUAL";
$matrLogoff = $_GET["logoff"];
$dacLogoff = $_GET["dac"];
if ($isFila)
@GetUrl(AST_REM_FILA, $dacLogoff, $matrLogoff);
$result = GetUrl(AST_LOGOFF_AGENTE, $dacLogoff, $matrLogoff);
if ($result) {
$result = pg_query($dbcon, "begin");
//atualiza dados do supervisor
$query = "delete
from pbx_supervisor_agentes
where matricula = '$matrLogoff'";
$result = pg_query($dbcon, $query);
$result = @pg_affected_rows($result);
//registra o login do usuario
if ($result) {
$query = "select coalesce(max(id),0) as id from pbx_eventos_agentes where matricula = '$matrLogoff' and cast(login as date) = cast(now() as date) and flag < > 2";
$result = pg_query($dbcon, $query);
$row = @pg_fetch_row($result);
$idLogoff = $row[0];
if ($idLogoff) {
$query = "update pbx_eventos_agentes
set logoff = now(),
flag = 2
where id = $idLogoff";
$result = pg_query($dbcon, $query);
$result = @pg_affected_rows($result);
}
}
}
if ($result) {
pg_query($dbcon, "commit");
echo "O logoff do usu<EFBFBD> rio executado com sucesso!";
} else {
pg_query($dbcon, "rollback");
echo "O logoff do usu<EFBFBD> rio n<EFBFBD> o pode ser executado!" + pg_last_error($dbcon);
}
} else if (IsAjax() & & isset($_GET["pausaAgente"])) {
$matricula = $_GET["pausaAgente"];
$dac = GetDacCod($dbcon, $_GET["dac"]);
$ramal = $_GET["ramal"];
$idSession = $idSessao = "SSpausa_" . $matricula;
$pausa = $_SESSION[$idSessao];
$codMotivo = '4';
if (!$pausa) {
$result = GetUrl(AST_ADD_PAUSA, $dac, $matricula);
if ($result) {
$result = pg_query($db, "begin");
//atualiza dados do supervisor
$query = "update pbx_supervisor_agentes
set status = 'PAUSA',
duracao = now()
where matricula = '$matricula'";
$result = pg_query($dbcon, $query);
if ($result)
$result = @pg_affected_rows($result);
//registra pausa
if ($result) {
$relEvt = GetRelacionaEventos($dbcon, $matricula);
$query = "insert into pbx_eventos_agentes(matricula, ramal, id_dac, id_motivo_pausa, entrada_pausa, flag, relaciona_eventos)
values('$matricula', '$ramal', $dac, $codMotivo, now(), 0, $relEvt)";
$result = pg_query($dbcon, $query);
if ($result) {
$result = @pg_affected_rows($result);
//pega o id corrente
if ($result) {
$query = "select currval('pbx_eventos_agentes_id_seq')";
$result = pg_query($dbcon, $query);
$row = pg_fetch_row($result);
$_SESSION[$matricula . "relEvt"] = $relEvt;
$_SESSION[$matricula . "idPausa"] = $row[0];
}
}
}
if ($result) {
pg_query($db, "commit");
$_SESSION[$idSessao] = 1;
echo "O agente \"Matricula: $matricula \" foi colocado em pausa!";
} else {
pg_query($db, "rollback");
echo "A opera<EFBFBD> <EFBFBD> o n<EFBFBD> o pode ser realizada! Erro: " + pg_last_error($dbcon);
}
}
} else {
$result = GetUrl(AST_REM_PAUSA, $dac, $ramal);
if ($result) {
$result = pg_query($dbcon, "begin");
//atualiza dados do supervisor
$query = "update pbx_supervisor_agentes
set status = 'LIVRE',
duracao = now()
where matricula = '$matricula'";
$result = pg_query($dbcon, $query);
if ($result)
$result = pg_affected_rows($result);
//registra o login do usuario
if ($result) {
$idPausa = $_SESSION[$matricula . "idPausa"];
$query = "update pbx_eventos_agentes
set saida_pausa = now(),
flag = 2
where id = $idPausa ";
$result = pg_query($dbcon, $query);
if ($result)
$result = @pg_affected_rows($result);
}
}
if ($result) {
pg_query($dbcon, "commit");
$_SESSION[$idSessao] = 0;
echo "O agente \"Matricula: $matricula \" foi retirado de pausa!";
} else {
pg_query($db, "rollback");
echo "A opera<EFBFBD> <EFBFBD> o n<EFBFBD> o pode ser realizada! Erro: " + pg_last_error($dbcon);
}
}
} else if (IsAjax() & & isset($_GET["intercalarAgente"])) {
$matricula = $_GET["intercalarAgente"];
$dac = $_GET["dac"];
$idSessao = "SSinter_" . $matricula;
$intercalar = $_SESSION[$idSessao];
$_SESSION[SS_DESTINO_INTERCALAR] = $_GET["ramal"];
$query = "update pbx_supervisor_agentes
set intercalar = '{Status}'
where matricula = '$matricula'";
if (!$intercalar) {
//atualiza dados do supervisor
if (GetUrl(AST_INTERCALAR, $dac, $matricula)) {
$query = str_replace("{Status}", "1", $query);
$result = pg_query($dbcon, $query);
if ($result)
$result = pg_affected_rows($result);
if ($result)
$_SESSION[$idSessao] = 1;
echo "Inicianado a intercala<EFBFBD> <EFBFBD> o!";
}
else {
echo "N<EFBFBD> o foi poss<EFBFBD> vel realzar a opera<EFBFBD> <EFBFBD> o!";
}
} else {
echo "Opera<EFBFBD> <EFBFBD> o em andamento!";
}
} else if (IsAjax() & & isset($_GET["monitorarAgente"])) {
$matricula = $_GET["monitorarAgente"];
$dac = $_GET["dac"];
$idSessao = "SSmonitorar_" . $matricula;
$monitorar = $_SESSION[$idSessao];
$_SESSION[SS_DESTINO_INTERCALAR] = $_GET["ramal"];
$query = "update pbx_supervisor_agentes
set monitorar = '{Status}'
where matricula = '$matricula'";
if (!$monitorar) {
if (GetUrl(AST_MONITORAR, $dac, $matricula)) {
$query = str_replace("{Status}", "1", $query);
$result = pg_query($dbcon, $query);
if ($result)
$result = pg_affected_rows($result);
if ($result)
$_SESSION[$idSessao] = 1;
echo "Iniciando monitoria!";
}
else {
echo "N<EFBFBD> o foi poss<EFBFBD> vel realzar a opera<EFBFBD> <EFBFBD> o!";
}
} else {
echo "Opera<EFBFBD> <EFBFBD> o em andamento!";
}
} else if (IsAjax()) {
echo $tbDac . "#" . $tbAgente;
} else {
$jsJQuery[] = GetJqTips('img');
//define arquivo de javaScript necessarios
$jsStartup[] = "var idSet = window.setInterval(\"GetSupervisor()\", " . GetTempoSupervisor() . ");";
$ramalInter = $_SESSION[SS_RAMAL_INTERCALAR] ? $_SESSION[SS_RAMAL_INTERCALAR] : "NI";
//$smarty->assign('dacs', GetDac($dbcon, $dac));
$smarty->assign('tbDac', $tbDac);
$smarty->assign('tbAgente', $tbAgente);
$smarty->assign('ramal', $ramalInter);
DispRel($smarty);
}
function DispRel($smarty) {
$smarty->display('supervisor.tpl');
}
function GetQuery($qr, $dac) {
if ($qr == 1) {
return "select 0 as sel, dac, atendidas, abandonadas, espera, (tempo_espera * (interval '1 second')) as tempo_espera, cast(percentual_nivel_servico as varchar) || '%' as tempo_nivel_servico
from pbx_supervisor_dacs
order by 2 ";
} else {
return "select ramal,
matricula,
nome,
(LOCALTIMESTAMP(0) - tempo_login) as tempo_login,
modo_atendimento,
origem_destino,
status,
(LOCALTIMESTAMP(0) - duracao) as duracao,
'< a href = \"javaScript:LogoffAgente(''' | | matricula | | ' ' ' , ' ' ' | | upper ( modo_atendimento ) | | ' ' ' , ' ' ' | | dac | | ' ' ' ) ; \ " > < img src = \"imgSite/exit16.png\" width = \"16\" height = \"16\" border = \"0\" title = \"Logoff de Agente ! \ " alt = \"Logoff de Agente ! \ " > < / a > ' as logoff,
'< a href = \"javaScript:PausaAgente(''' | | matricula | | ' ' ' , ' ' ' | | upper ( ramal ) | | ' ' ' , ' ' ' | | dac | | ' ' ' ) ; \ " > < img src = \"imgSite/{IMG_PAUSA}\" width = \"16\" height = \"16\" border = \"0\" title = \"{ALT_PAUSA}\" alt = \"{ALT_PAUSA}\" > < / a > ' as pausa,
'< a href = \"javaScript:MonitoraAgente(''' | | matricula | | ' ' ' , ' ' ' | | upper ( ramal ) | | ' ' ' , ' ' ' | | dac | | ' ' ' ) ; \ " > < img src = \"imgSite/{IMG_MONITORAR}\" width = \"16\" height = \"16\" border = \"0\" title = \"{ALT_MONITORAR}\" alt = \"{ALT_MONITORAR}\" > < / a > ' as monitorar,
'< a href = \"javaScript:IntercalarAgente(''' | | matricula | | ' ' ' , ' ' ' | | upper ( ramal ) | | ' ' ' , ' ' ' | | dac | | ' ' ' ) ; \ " > < img src = \"imgSite/{IMG_INTERCALAR}\" width = \"16\" height = \"16\" border = \"0\" title = \"{ALT_INTERCALAR}\" alt = \"{ALT_INTERCALAR}\" > < / a > ' as intercalar,
monitorar as statusMonitorar,
intercalar as statusIntercalar
from pbx_supervisor_agentes
where dac = '$dac' order by nome ";
}
// '< a href = \"javaScript:LogoffAgente(''' | | matricula | | ' ' ' , ' ' ' | | upper ( modo_atendimento ) | | ' ' ' , ' ' ' | | dac | | ' ' ' ) ; \ " > < img src = \"imgSite/exit16.png\" width = \"16\" height = \"16\" border = \"0\" alt = \"Logoff de Agente ! \ " > < / a > ' as logoff,
// '< a href = \"javaScript:PausaAgente(''' | | matricula | | ' ' ' , ' ' ' | | upper ( ramal ) | | ' ' ' , ' ' ' | | dac | | ' ' ' ) ; \ " > < img src = \"imgSite/{IMG_PAUSA}\" width = \"16\" height = \"16\" border = \"0\" alt = \"{ALT_PAUSA}\" > < / a > ' as pausa
// '< a href = \"javaScript:IntercalarAgente(''' | | matricula | | ' ' ' , ' ' ' | | upper ( ramal ) | | ' ' ' , ' ' ' | | dac | | ' ' ' ) ; \ " > < img src = \"imgSite/{IMG_INTERCALAR}\" width = \"16\" height = \"16\" border = \"0\" alt = \"{ALT_INTERCALAR}\" > < / a > ' as intercalar
}
function GetHeadTable($colspan = 0, $title = "") {
$tb = "< table class = \"grid\" width = \"760\" border = \"0\" cellspacing = \"0\" cellpadding = \"2\" > \n";
$tb .= $colspan ? "< tr > < th colspan = \"$colspan\" > $title< / th > < / tr > " : "";
return $tb;
}
function GetCloseTable() {
return "< / table > \n";
}
function GetLinhas($dados, $headTabe = 0, $dac = "") {
$linha = "< tr > ";
$imOn = "< img src = \"imgSite/dacOn.png\" width = \"16\" border = \"0\" height = \"16\" title = \"Dac Ativo \ " alt = \"Dac Ativo \ " align = \"absmiddle\" > ";
$imOff = "< img src = \"imgSite/dacOff.png\" width = \"16\" border = \"0\" height = \"16\" title = \"Clique aqui para ativar este dac ! \ " alt = \"Clique aqui para ativar este dac ! \ " align = \"absmiddle\" > ";
$imgSet = "";
$stl = "";
$align = "align=\"center\"";
$columnEscape = array(12, 13);
for ($i = 0; $i < count ( $ dados ) ; $ i + + ) {
$stl = ($dac == $dados[1]) || ($dac == -1) ? "class=\"gridSelect\"" : "";
if ((($i == 1) & & ($dac == $dados[1])) || ($dac == -1)) {
$dadoSel = "< span id = \"dacAtivo\" > $dados[$i]< / span > ";
} else {
$dadoSel = $dados[$i];
}
if (!$headTabe & & $dac & & $i == 0) {
$imgSet = ($dac == $dados[1]) || ($dac == -1) ? $imOn : $imOff;
$linha .= "< td $ align $ stl > < a href = \" javaScript:GetSupervisor ( ' $ dados [ 1 ] ' ) ; \ " > $imgSet< / a > < / td > ";
} else {
if ($headTabe) {
$linha .= "< th > $dados[$i]< / th > ";
} else {
if ($i == 9) {
if (strtoupper($dados[6]) == 'PAUSA') {
$strTmp = str_replace("{IMG_PAUSA}", "user_off.gif", $dadoSel);
$strTmp = str_replace("{ALT_PAUSA}", "Tira o agente de Pausa!", $strTmp);
} else {
$strTmp = str_replace("{IMG_PAUSA}", "user_on.gif", $dadoSel);
$strTmp = str_replace("{ALT_PAUSA}", "Coloca Agente em pausa!", $strTmp);
}
$linha .= "< td $ align $ stl > $strTmp< / td > "; //user_on.gif
} else if ($i == 10) {
if (strtoupper($dados[12]) == 1) {
$strTmp = str_replace("{IMG_MONITORAR}", "monitorar.gif", $dadoSel);
$strTmp = str_replace("{ALT_MONITORAR}", "Encerrar!", $strTmp);
} else {
$strTmp = str_replace("{IMG_MONITORAR}", "monitorarOff.gif", $dadoSel);
$strTmp = str_replace("{ALT_MONITORAR}", "Monitorar!", $strTmp);
}
$linha .= "< td $ align $ stl > $strTmp< / td > "; //user_on.gif
} else if ($i == 11) {
if (strtoupper($dados[13]) == 1) {
$strTmp = str_replace("{IMG_INTERCALAR}", "intercalar.gif", $dadoSel);
$strTmp = str_replace("{ALT_INTERCALAR}", "Encerrar!", $strTmp);
} else {
$strTmp = str_replace("{IMG_INTERCALAR}", "intercalarOff.gif", $dadoSel);
$strTmp = str_replace("{ALT_INTERCALAR}", "Intercalar!", $strTmp);
}
$linha .= "< td $ align $ stl > $strTmp< / td > "; //user_on.gif
} else if (($i == 12) || ($i == 13)) {
;
} else {
$linha .= "< td $ align $ stl > $dadoSel< / td > ";
}
}
}
}
$linha .= "< / tr > \n";
return $linha;
}
function GetTbDac($dbcon, $dac, $head) {
//tabela de dacs
$tb = GetHeadTable(8, "Dacs Cadastrados");
$tb .= GetLinhas($head, 1);
//executa query
$result = pg_query($dbcon, GetQuery(1, $dac));
//linhas de resultado da consulta
while ($agente = @pg_fetch_row($result)) {
$tb .= GetLinhas($agente, 0, $dac);
if ($dac == -1)
$dac = $GLOBALS["dac"] = $agente[1];
}
$tb .= GetCloseTable();
return $tb;
}
function GetTbAgente($dbcon, $dac, $head) {
//tabela de dacs
$tb = GetHeadTable(12, "Agentes em Opera<EFBFBD> <EFBFBD> o");
$tb .= GetLinhas($head, 1);
//executa query
$result = pg_query($dbcon, GetQuery(2, $dac));
//linhas de resultado da consulta
while ($agente = @pg_fetch_row($result))
$tb .= GetLinhas($agente);
$tb .= GetCloseTable();
return $tb;
}
?>