|
|
|
|
#!/usr/bin/php -q
|
|
|
|
|
<?
|
|
|
|
|
include('bd.php');
|
|
|
|
|
include_once('util/constantes.php');
|
|
|
|
|
include_once('util/util.php');
|
|
|
|
|
include_once('funcoes/shared.php');
|
|
|
|
|
|
|
|
|
|
ob_implicit_flush(true);
|
|
|
|
|
set_time_limit(6);
|
|
|
|
|
error_reporting(0);
|
|
|
|
|
$in = fopen("php://stdin", "r");
|
|
|
|
|
$stdlog = fopen("/var/log/asterisk/pbx_info-agente.log", "w");
|
|
|
|
|
|
|
|
|
|
// Habilita modo debugging (mais verbose)
|
|
|
|
|
$debug = true;
|
|
|
|
|
|
|
|
|
|
// Do function definitions before we start the main loop
|
|
|
|
|
function read() {
|
|
|
|
|
global $in, $debug, $stdlog;
|
|
|
|
|
$input = str_replace("\n", "", fgets($in, 4096));
|
|
|
|
|
if ($debug)
|
|
|
|
|
fputs($stdlog, "read: $input\n");
|
|
|
|
|
return $input;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function write($line) {
|
|
|
|
|
global $debug, $stdlog;
|
|
|
|
|
if ($debug)
|
|
|
|
|
fputs($stdlog, "write: $line\n");
|
|
|
|
|
echo $line . "\n";
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Colocando headers AGI dentro de um array
|
|
|
|
|
while ($env = read()) {
|
|
|
|
|
$s = split(": ", $env);
|
|
|
|
|
$agi[str_replace("agi_", "", $s[0])] = trim($s[1]);
|
|
|
|
|
if (($env == "") || ($env == "\n")) {
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
$tipo = $argv[1];
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
switch ($tipo) {
|
|
|
|
|
case 'BINA_AGENTE':
|
|
|
|
|
$ramal = $argv[2];
|
|
|
|
|
$query = "select status,matricula,dac,replace(upper(modo_atendimento),'<EFBFBD>','A') as modo_atendimento from pbx_supervisor_agentes where ramal = '$ramal'";
|
|
|
|
|
$result = @pg_query($query);
|
|
|
|
|
$row = @pg_fetch_array($result);
|
|
|
|
|
$matricula = $row["matricula"];
|
|
|
|
|
$modo_atendimento = $row["modo_atendimento"];
|
|
|
|
|
|
|
|
|
|
//Utilizado no PauseQueueMember do PAUSA-AUSENTE do Asterisk 1.4
|
|
|
|
|
//write("SET VARIABLE MATRICULA $matricula");
|
|
|
|
|
//read();
|
|
|
|
|
|
|
|
|
|
//Recupera o callerid(name) setado na rota de entrada (identificador)
|
|
|
|
|
write("GET VARIABLE CALLERID(name)");
|
|
|
|
|
$bina_nome = substr(strrchr(read(), "("), 1, -1);
|
|
|
|
|
|
|
|
|
|
//Verifica se e uma ligacao ou uma consulta
|
|
|
|
|
write("GET VARIABLE CONSULTA");
|
|
|
|
|
$consulta = substr(strrchr(read(), "("), 1, -1);
|
|
|
|
|
|
|
|
|
|
if (strtoupper($row["status"]) != "PAUSA") {
|
|
|
|
|
$ramal = $argv[2];
|
|
|
|
|
$bina = $argv[3];
|
|
|
|
|
$idorigem = $argv[4];
|
|
|
|
|
$canal_agente = $argv[5];
|
|
|
|
|
|
|
|
|
|
// if ($consulta) {
|
|
|
|
|
// $query = "update pbx_supervisor_agentes set canal_agente = '$canal_agente' where ramal = '$ramal'";
|
|
|
|
|
// }
|
|
|
|
|
// else {
|
|
|
|
|
$query = "update pbx_supervisor_agentes set status = 'CHAMANDO' , origem_destino = '$bina-$bina_nome' , duracao = now() ,canal = '' , sala_1 = '' , sala_2 = '' , facilidade = '' , canal_transfer = '', tipo_ligacao = 'E' where ramal = '$ramal'";
|
|
|
|
|
pg_query($query);
|
|
|
|
|
// }
|
|
|
|
|
// write("GET VARIABLE MATRICULA-ORIGEM");
|
|
|
|
|
// $matriculaorigem = substr(strrchr(read(), "("), 1, -1);
|
|
|
|
|
//
|
|
|
|
|
if ($modo_atendimento == 'AUTOMATICO') {
|
|
|
|
|
$query = "update pbx_supervisor_agentes set canal_agente = replace('$canal_agente',';2',';1') where ramal = '$ramal'";
|
|
|
|
|
pg_query($query);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
break;
|
|
|
|
|
//Roda em atendimento manual, apos o agente atender a chamada
|
|
|
|
|
case 'FILA':
|
|
|
|
|
$canal_agente = $argv[2];
|
|
|
|
|
$ramal = $argv[3];
|
|
|
|
|
|
|
|
|
|
$query = "select matricula from pbx_supervisor_agentes where ramal = '$ramal'";
|
|
|
|
|
$result = @pg_query($query);
|
|
|
|
|
$row = @pg_fetch_array($result);
|
|
|
|
|
$matricula = $row["matricula"];
|
|
|
|
|
|
|
|
|
|
$query = "update pbx_supervisor_agentes set canal_agente = '$canal_agente' where ramal = '$ramal'";
|
|
|
|
|
pg_query($query);
|
|
|
|
|
|
|
|
|
|
write("SET VARIABLE MATRICULAMESA $matricula");
|
|
|
|
|
read();
|
|
|
|
|
|
|
|
|
|
write("SET VARIABLE MATRICULA $matricula");
|
|
|
|
|
read();
|
|
|
|
|
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// case 'BINA_AGENTE_ATIVO':
|
|
|
|
|
// $ramal = $argv[2];
|
|
|
|
|
// $bina = $argv[3];
|
|
|
|
|
// $identificador = $argv[4];
|
|
|
|
|
// $query = "update pbx_supervisor_agentes set status = 'OCUPADO' , origem_destino = '$bina' , duracao = now() ,canal = '' , sala_1 = '' , sala_2 = '' , facilidade = '' , canal_agente = '' , canal_transfer = '' ,cont_identificador = translate('$identificador','-','|'), tipo_ligacao = 'S' where ramal = '$ramal'";
|
|
|
|
|
// pg_query($query);
|
|
|
|
|
// break;
|
|
|
|
|
|
|
|
|
|
// case 'RECEPTIVO':
|
|
|
|
|
// $canal = $argv[2];
|
|
|
|
|
// $ramal = $argv[3];
|
|
|
|
|
// $query = "update pbx_supervisor_agentes set status = 'OCUPADO', canal_agente = '$canal' where ramal = '$ramal'";
|
|
|
|
|
// pg_query($query);
|
|
|
|
|
//
|
|
|
|
|
// write("GET VARIABLE MATRICULA-ORIGEM");
|
|
|
|
|
// $matriculaorigem = substr(strrchr(read(), "("), 1, -1);
|
|
|
|
|
//
|
|
|
|
|
// if ($matriculaorigem) {
|
|
|
|
|
//
|
|
|
|
|
// $query = "update pbx_supervisor_agentes set canal = '$canal' where matricula = '$matriculaorigem'";
|
|
|
|
|
// pg_query($query);
|
|
|
|
|
//
|
|
|
|
|
// }
|
|
|
|
|
//
|
|
|
|
|
// $query = "select matricula from pbx_supervisor_agentes where ramal = '$ramal'";
|
|
|
|
|
// $result = @pg_query($query);
|
|
|
|
|
// $row = @pg_fetch_array($result);
|
|
|
|
|
// $matricula = $row["matricula"];
|
|
|
|
|
//
|
|
|
|
|
// write("SET VARIABLE MATRICULAMESA $matricula");
|
|
|
|
|
// read();
|
|
|
|
|
//
|
|
|
|
|
// write("SET VARIABLE MATRICULA $matricula");
|
|
|
|
|
// read();
|
|
|
|
|
//
|
|
|
|
|
//
|
|
|
|
|
// break;
|
|
|
|
|
// case 'APLICACAO':
|
|
|
|
|
// write("GET VARIABLE GRAVACAO");
|
|
|
|
|
// $gravacao = substr(strrchr(read(), "("), 1, -1);
|
|
|
|
|
// $matricula = $argv[2];
|
|
|
|
|
// $canal = $agi["channel"];
|
|
|
|
|
//
|
|
|
|
|
// $query = "select status,motivo_pausa from pbx_supervisor_agentes where matricula = '$matricula'";
|
|
|
|
|
// $result = @pg_query($query);
|
|
|
|
|
// $row = @pg_fetch_array($result);
|
|
|
|
|
//
|
|
|
|
|
// if (strtoupper($row["status"]) == "PAUSA") {
|
|
|
|
|
// $query = "update pbx_supervisor_agentes set canal = '$canal', tipo_discagem = 'MANUAL', status_gravacao = (case when '$gravacao' = '' then 'F' else '$gravacao' end) where matricula = '$matricula'";
|
|
|
|
|
// pg_query($query);
|
|
|
|
|
// } else {
|
|
|
|
|
// $query = "update pbx_supervisor_agentes set canal = '$canal', status = 'OCUPADO', tipo_discagem = 'MANUAL', status_gravacao = (case when '$gravacao' = '' then 'F' else '$gravacao' end) where matricula = '$matricula'";
|
|
|
|
|
// pg_query($query);
|
|
|
|
|
// }
|
|
|
|
|
// break;
|
|
|
|
|
//
|
|
|
|
|
// case 'ATIVO-AUTOMATICO':
|
|
|
|
|
// $canal = $argv[2];
|
|
|
|
|
// $origem_destino = $argv[3];
|
|
|
|
|
// $ramal = $argv[4];
|
|
|
|
|
// $query = "update pbx_supervisor_agentes set canal = '$canal', status = 'OCUPADO' , origem_destino = '$origem_destino' where ramal = '$ramal'";
|
|
|
|
|
// pg_query($query);
|
|
|
|
|
// break;
|
|
|
|
|
|
|
|
|
|
// case 'ORIGINA_AGENTE':
|
|
|
|
|
// $agente = $argv[2];
|
|
|
|
|
// $uniqueid = $argv[3];
|
|
|
|
|
//
|
|
|
|
|
// /*
|
|
|
|
|
// * Fun<EFBFBD><EFBFBD>o retorna numero de Protocolo de Atendimento para o agente
|
|
|
|
|
// */
|
|
|
|
|
// $tentativa = 0;
|
|
|
|
|
// while (true) {
|
|
|
|
|
// $proto = @GetProto($conexao, $uniqueid, $agente);
|
|
|
|
|
// if ($proto == '99') {
|
|
|
|
|
// $proto = '0000-000000';
|
|
|
|
|
// break;
|
|
|
|
|
// }
|
|
|
|
|
//
|
|
|
|
|
// if (!empty($proto) || $tentativa >= NUM_TENTATIVAS_GERA_PROTO) {
|
|
|
|
|
// break;
|
|
|
|
|
// }
|
|
|
|
|
// $tentativa++;
|
|
|
|
|
// }
|
|
|
|
|
//
|
|
|
|
|
// //$query = "update pbx_supervisor_agentes set uniqueid = '$uniqueid', uniqueid2 = '$uniqueid', protocolo = '$proto' where matricula = '$agente'";
|
|
|
|
|
// $query = "update pbx_supervisor_agentes set protocolo = '$proto' where matricula = '$agente'";
|
|
|
|
|
// pg_query($query);
|
|
|
|
|
//
|
|
|
|
|
// //RegistraClassificacao();
|
|
|
|
|
//
|
|
|
|
|
// break;
|
|
|
|
|
|
|
|
|
|
// case 'DIAL_AGENTE':
|
|
|
|
|
// $agente = $argv[2];
|
|
|
|
|
// $uniqueid = $argv[3];
|
|
|
|
|
//
|
|
|
|
|
// /*
|
|
|
|
|
// * Fun<EFBFBD><EFBFBD>o retorna numero de Protocolo de Atendimento para o agente
|
|
|
|
|
// */
|
|
|
|
|
// $tentativa = 0;
|
|
|
|
|
// while (true) {
|
|
|
|
|
// $proto = @GetProto($conexao, $uniqueid, $agente);
|
|
|
|
|
// if ($proto == '99') {
|
|
|
|
|
// $proto = '0000-000000';
|
|
|
|
|
// break;
|
|
|
|
|
// }
|
|
|
|
|
// if (!empty($proto) ||$tentativa >= NUM_TENTATIVAS_GERA_PROTO) {
|
|
|
|
|
// break;
|
|
|
|
|
// }
|
|
|
|
|
// $tentativa++;
|
|
|
|
|
// }
|
|
|
|
|
//
|
|
|
|
|
// $query = "update pbx_supervisor_agentes set uniqueid = '$uniqueid', uniqueid2 = '$uniqueid', protocolo = '$proto' where matricula = '$agente'";
|
|
|
|
|
// pg_query($query);
|
|
|
|
|
//
|
|
|
|
|
// break;
|
|
|
|
|
|
|
|
|
|
//function RegistraClassificacao($conexao, $matricula, $uniqueid) {
|
|
|
|
|
// /*
|
|
|
|
|
// * N<EFBFBD>o <EFBFBD> necessario invocar este script, agente_dial.php j<EFBFBD> cumpre esta fun<EFBFBD><EFBFBD>o.
|
|
|
|
|
// */
|
|
|
|
|
// return;
|
|
|
|
|
// /*
|
|
|
|
|
// * Trata classifica<EFBFBD><EFBFBD>o
|
|
|
|
|
// * Verifica se a classifica<EFBFBD><EFBFBD>o esta ativa
|
|
|
|
|
// * Verifica se <EFBFBD> exigida a classifica<EFBFBD><EFBFBD>o
|
|
|
|
|
// */
|
|
|
|
|
//
|
|
|
|
|
// $query = "select b.prm_agente_classifica, a.exige_classificacao as prm_exige_classificacao
|
|
|
|
|
// from pbx_queues_grupos a, pbx_parametros b
|
|
|
|
|
// where nome = (select dac from pbx_supervisor_agentes where matricula = '$matricula')";
|
|
|
|
|
//
|
|
|
|
|
//
|
|
|
|
|
// $result = pg_query($conexao, $query);
|
|
|
|
|
// $dados = pg_fetch_row($result);
|
|
|
|
|
// if ($dados[0] && $dados[1]) {
|
|
|
|
|
// /*
|
|
|
|
|
// * Registra a obrigatoriedade da classifica<EFBFBD><EFBFBD>o para o agente logado quando configurado.
|
|
|
|
|
// */
|
|
|
|
|
// $query = "insert into pbx_registra_classificacao(id_dac, matricula, rgc_entrada, uid, id_login, reg_proc)values((select id from pbx_dacs where nome = (select dac from pbx_supervisor_agentes where matricula = '$matricula')), '$matricula', now(), '$uniqueid', (select max(id) from pbx_eventos_agentes where matricula = '$matricula' ), 'info_agente.php')";
|
|
|
|
|
// @pg_query($conexao, $query);
|
|
|
|
|
// }
|
|
|
|
|
//}
|
|
|
|
|
|
|
|
|
|
fclose($in);
|
|
|
|
|
fclose($stdlog);
|
|
|
|
|
exit;
|
|
|
|
|
?>
|