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.
82 lines
1.8 KiB
82 lines
1.8 KiB
2 years ago
|
#!/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/chefe-secretaria", "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 = split(": ", $env);
|
||
|
$agi[str_replace("agi_", "", $s[0])] = trim($s[1]);
|
||
|
if (($env == "") || ($env == "\n")) {
|
||
|
break;
|
||
|
}
|
||
|
}
|
||
|
|
||
|
//parametro vindo do dialplan
|
||
|
$ramal = $argv[1];
|
||
|
$origem = $argv[2];
|
||
|
|
||
|
//Ignora o chefe-secretaria se a ligacao for da fila
|
||
|
write("GET VARIABLE DAC");
|
||
|
$dac = substr(strrchr(read(), "("), 1, -1);
|
||
|
|
||
|
if ($dac) {
|
||
|
exit;
|
||
|
}
|
||
|
|
||
|
$query = "select a.ramalsecretaria, b.excecao from pbx_ramais a left join pbx_chefe_secretaria b on a.nome = b.numero and '$origem' like b.excecao where a.nome = '$ramal' and coalesce(a.ramalsecretaria,'') <> ''";
|
||
|
$result = pg_query($conexao, $query);
|
||
|
$row = pg_fetch_array($result);
|
||
|
$numlinha = pg_num_rows($result);
|
||
|
$ramalsecretaria = $row['ramalsecretaria'];
|
||
|
$excecao = $row['excecao'];
|
||
|
|
||
|
if ($numlinha) {
|
||
|
|
||
|
if ($ramalsecretaria == $origem) {
|
||
|
|
||
|
write("SET VARIABLE secretaria $ramalsecretaria");
|
||
|
read();
|
||
|
exit;
|
||
|
}
|
||
|
|
||
|
if ($excecao) {
|
||
|
|
||
|
write("SET VARIABLE excecao $excecao");
|
||
|
read();
|
||
|
exit;
|
||
|
}
|
||
|
|
||
|
write("EXEC Goto padrao,$ramalsecretaria,1");
|
||
|
read();
|
||
|
}
|
||
|
|
||
|
fclose($in);
|
||
|
fclose($stdlog);
|
||
|
exit;
|
||
|
?>
|