"; $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ário executado com sucesso!"; } else { pg_query($dbcon, "rollback"); echo "O logoff do usuário nã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ção nã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ção nã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ção!"; } else { echo "Não foi possível realzar a operação!"; } } else { echo "Operaçã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ão foi possível realzar a operação!"; } } else { echo "Operaçã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, '\"Logoff' as logoff, '\"{ALT_PAUSA}\"' as pausa, '\"{ALT_MONITORAR}\"' as monitorar, '\"{ALT_INTERCALAR}\"' as intercalar, monitorar as statusMonitorar, intercalar as statusIntercalar from pbx_supervisor_agentes where dac = '$dac' order by nome "; } // '\"Logoff' as logoff, // '\"{ALT_PAUSA}\"' as pausa // '\"{ALT_INTERCALAR}\"' as intercalar } function GetHeadTable($colspan = 0, $title = "") { $tb = "\n"; $tb .= $colspan ? "" : ""; return $tb; } function GetCloseTable() { return "
$title
\n"; } function GetLinhas($dados, $headTabe = 0, $dac = "") { $linha = ""; $imOn = "\"Dac"; $imOff = "\"Clique"; $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 = "$dados[$i]"; } else { $dadoSel = $dados[$i]; } if (!$headTabe && $dac && $i == 0) { $imgSet = ($dac == $dados[1]) || ($dac == -1) ? $imOn : $imOff; $linha .= "$imgSet"; } else { if ($headTabe) { $linha .= "$dados[$i]"; } 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 .= "$strTmp"; //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 .= "$strTmp"; //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 .= "$strTmp"; //user_on.gif } else if (($i == 12) || ($i == 13)) { ; } else { $linha .= "$dadoSel"; } } } } $linha .= "\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çã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; } ?>