|
|
|
#!/usr/bin/php -q
|
|
|
|
<?php
|
|
|
|
include('bd.php');
|
|
|
|
|
|
|
|
ob_implicit_flush(true);
|
|
|
|
set_time_limit(6);
|
|
|
|
$in = fopen("php://stdin", "r");
|
|
|
|
$stdlog = fopen("/var/log/asterisk/agente_fila.log", "w");
|
|
|
|
|
|
|
|
// toggle debugging output (more verbose)
|
|
|
|
$debug = false;
|
|
|
|
|
|
|
|
function read() {
|
|
|
|
global $in, $debug, $stdlog;
|
|
|
|
$input = str_replace("\n", "", fgets($in, 4096));
|
|
|
|
if ($debug)
|
|
|
|
fputs($stdlog, "read: $input\n");
|
|
|
|
return $input;
|
|
|
|
}
|
|
|
|
|
|
|
|
function errlog($line) {
|
|
|
|
global $err;
|
|
|
|
echo "VERBOSE \"$line\"\n";
|
|
|
|
}
|
|
|
|
|
|
|
|
function write($line) {
|
|
|
|
global $debug, $stdlog;
|
|
|
|
if ($debug)
|
|
|
|
fputs($stdlog, "write: $line\n");
|
|
|
|
echo $line . "\n";
|
|
|
|
}
|
|
|
|
|
|
|
|
// parse agi headers into array
|
|
|
|
while ($env = read()) {
|
|
|
|
$s = explode(": ", $env);
|
|
|
|
$agi[str_replace("agi_", "", $s[0])] = trim($s[1]);
|
|
|
|
if (($env == "") || ($env == "\n")) {
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
//parametro vindo do dialplan
|
|
|
|
$tipo = $argv[1];
|
|
|
|
|
|
|
|
$canal = $argv[2];
|
|
|
|
$matricula = $argv[3];
|
|
|
|
$uniqueid = $argv[4];
|
|
|
|
$fila = $argv[5];
|
|
|
|
$canalagente = $argv[6]; //Deve ser utilizado para ligacao entre dois agentes , canal_agente = '$canalagente'
|
|
|
|
$ramal = $argv[7];
|
|
|
|
|
|
|
|
switch ($tipo) {
|
|
|
|
case 'ORIGEM':
|
|
|
|
|
|
|
|
$query = "update pbx_supervisor_agentes set canal = '$canal' , status = 'OCUPADO' where matricula = '$matricula'";
|
|
|
|
pg_query($query);
|
|
|
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
case 'DESTINO':
|
|
|
|
|
|
|
|
$query = "update pbx_supervisor_agentes set canal_agente = '$canal' , status = 'OCUPADO' where matricula = '$matricula'";
|
|
|
|
pg_query($query);
|
|
|
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
write("SET VARIABLE MATRICULAMESA $matricula");
|
|
|
|
read();
|
|
|
|
|
|
|
|
// clean up file handlers etc.
|
|
|
|
fclose($in);
|
|
|
|
fclose($stdlog);
|
|
|
|
?>
|