|
|
|
#!/usr/bin/php -q
|
|
|
|
<?php
|
|
|
|
include('bd.php');
|
|
|
|
|
|
|
|
ob_implicit_flush(true);
|
|
|
|
set_time_limit(6);
|
|
|
|
error_reporting(0);
|
|
|
|
$in = fopen("php://stdin", "r");
|
|
|
|
$stdlog = fopen("/var/log/asterisk/rechamada.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
|
|
|
|
$ramal_origem = $argv[1];
|
|
|
|
|
|
|
|
$query = "select dst from ast_bilhetes where cast(calldate as date) = cast(now() as date) and src = '$ramal_origem' order by calldate desc limit 1";
|
|
|
|
|
|
|
|
$result = pg_query($conexao, $query);
|
|
|
|
$row = pg_fetch_array($result);
|
|
|
|
$num_destino = $row['dst'];
|
|
|
|
|
|
|
|
//write("GET VARIABLE RECHAMADA");
|
|
|
|
//$script_rechamada=substr(strrchr(read(),"("),1,-1);
|
|
|
|
//write("EXEC System $script_rechamada '$ramal_origem' $num_destino");
|
|
|
|
write("SET VARIABLE RAMAL_ORIGEM $ramal_origem");
|
|
|
|
read();
|
|
|
|
|
|
|
|
write("SET VARIABLE RAMAL_DESTINO $num_destino");
|
|
|
|
read();
|
|
|
|
|
|
|
|
pg_close();
|
|
|
|
fclose($in);
|
|
|
|
fclose($stdlog);
|
|
|
|
exit;
|
|
|
|
?>
|