forked from SimplesIP/pabx-app
You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
258 lines
9.4 KiB
258 lines
9.4 KiB
#!/usr/bin/php -q |
|
<?php |
|
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 = explode(": ", $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),'Á','A') as modo_atendimento from pbx_supervisor_agentes where ramal = '$ramal'"; |
|
$result = pg_query($dbcon, $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($dbcon, $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($dbcon, $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($dbcon, $query); |
|
$row = pg_fetch_array($result); |
|
$matricula = $row["matricula"]; |
|
|
|
$query = "update pbx_supervisor_agentes set canal_agente = '$canal_agente' where ramal = '$ramal'"; |
|
pg_query($dbcon, $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($dbcon, $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($dbcon, $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($dbcon, $query); |
|
// |
|
// } |
|
// |
|
// $query = "select matricula from pbx_supervisor_agentes where ramal = '$ramal'"; |
|
// $result = pg_query($dbcon, $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($dbcon, $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($dbcon, $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($dbcon, $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($dbcon, $query); |
|
// break; |
|
|
|
// case 'ORIGINA_AGENTE': |
|
// $agente = $argv[2]; |
|
// $uniqueid = $argv[3]; |
|
// |
|
// /* |
|
// * Funçã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($dbcon, $query); |
|
// |
|
// //RegistraClassificacao(); |
|
// |
|
// break; |
|
|
|
// case 'DIAL_AGENTE': |
|
// $agente = $argv[2]; |
|
// $uniqueid = $argv[3]; |
|
// |
|
// /* |
|
// * Funçã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($dbcon, $query); |
|
// |
|
// break; |
|
|
|
//function RegistraClassificacao($conexao, $matricula, $uniqueid) { |
|
// /* |
|
// * Não é necessario invocar este script, agente_dial.php já cumpre esta função. |
|
// */ |
|
// return; |
|
// /* |
|
// * Trata classificação |
|
// * Verifica se a classificação esta ativa |
|
// * Verifica se é exigida a classificaçã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çã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; |
|
?>
|
|
|