|
|
|
#!/usr/bin/php -q
|
|
|
|
<?php
|
|
|
|
include('bd.php');
|
|
|
|
include('util/util.php');
|
|
|
|
ob_implicit_flush(true);
|
|
|
|
set_time_limit(6);
|
|
|
|
error_reporting(0);
|
|
|
|
$in = fopen("php://stdin", "r");
|
|
|
|
$stdlog = fopen("/var/log/asterisk/prioridade_fila.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";
|
|
|
|
}
|
|
|
|
|
|
|
|
// Colocamos 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;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
//parametro vindo do dialplan
|
|
|
|
$numero = $argv[1];
|
|
|
|
$dac = $argv[2];
|
|
|
|
$numeroConsulta = IncluiDDD($numero);
|
|
|
|
$query = "select seq from pbx_prioridades_atendimento where '$numeroConsulta' similar to telefone and dac = '$dac'";
|
|
|
|
$result = pg_query($conexao, $query);
|
|
|
|
$row = pg_fetch_array($result);
|
|
|
|
$numlinha = pg_num_rows($result);
|
|
|
|
$seq = $row['seq'];
|
|
|
|
|
|
|
|
if ($numlinha) {
|
|
|
|
|
|
|
|
write("SET VARIABLE QUEUE_PRIO $seq");
|
|
|
|
read();
|
|
|
|
}
|
|
|
|
|
|
|
|
fclose($in);
|
|
|
|
fclose($stdlog);
|
|
|
|
exit;
|
|
|
|
?>
|