|
|
|
|
#!/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/agendamento.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 = split(": ", $env);
|
|
|
|
|
$agi[str_replace("agi_", "", $s[0])] = trim($s[1]);
|
|
|
|
|
if (($env == "") || ($env == "\n")) {
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//parametro vindo do dialplan
|
|
|
|
|
$campanha = $argv[1];
|
|
|
|
|
$agd_id = $argv[2];
|
|
|
|
|
|
|
|
|
|
// Verifica se a campanha est<EFBFBD> ativa ou pendente
|
|
|
|
|
$query = "select cmp_status from pbx_campanha where cmp_status in ('1','6') and cmp_descricao = '$campanha'";
|
|
|
|
|
$result = pg_query($conexao, $query);
|
|
|
|
|
$row = pg_fetch_row($result);
|
|
|
|
|
$status = $row[0];
|
|
|
|
|
$numlinha = pg_num_rows($result);
|
|
|
|
|
|
|
|
|
|
if (!$numlinha) {
|
|
|
|
|
$query = "update pbx_campanha_agendamento set agd_status = 'CAMPANHA-INDISPONIVEL', agd_agendado = (agd_agendado + 1) where agd_id = '$agd_id'";
|
|
|
|
|
pg_query($query);
|
|
|
|
|
pg_close();
|
|
|
|
|
|
|
|
|
|
write("HANGUP");
|
|
|
|
|
read();
|
|
|
|
|
exit;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Verifica se h<EFBFBD> agentes disponiveis para a campanha
|
|
|
|
|
$query = "select count(*) as livres from pbx_supervisor_agentes where upper(status) = upper('livre') and upper(dac) = upper('$campanha')";
|
|
|
|
|
$result = pg_query($conexao, $query);
|
|
|
|
|
$row = pg_fetch_row($result);
|
|
|
|
|
$numlinha = $row[0];
|
|
|
|
|
|
|
|
|
|
if (!$numlinha) {
|
|
|
|
|
$query = "update pbx_campanha_agendamento set agd_status = 'AGENTES-INDISPONIVEIS', agd_agendado = (agd_agendado + 1) where agd_id = '$agd_id'";
|
|
|
|
|
pg_query($query);
|
|
|
|
|
|
|
|
|
|
$query = "select count(*) from pbx_campanha_agendamento where cmp_id = (select cmp_id from pbx_campanha where upper(cmp_descricao) = upper('$campanha')) and agd_agendado < '3' and agd_status <> 'ATENDIDA' ";
|
|
|
|
|
$result = pg_query($conexao, $query);
|
|
|
|
|
$row = pg_fetch_row($result);
|
|
|
|
|
$agendado = $row[0];
|
|
|
|
|
|
|
|
|
|
if (!$agendado && $status == '6') {
|
|
|
|
|
$query = "update pbx_campanha set cmp_status = '5' where upper(cmp_descricao) = upper('$campanha')";
|
|
|
|
|
pg_query($query);
|
|
|
|
|
pg_close();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
write("NOOP STATUS => $status");
|
|
|
|
|
read();
|
|
|
|
|
|
|
|
|
|
write("NOOP AGENDADO => $agendado");
|
|
|
|
|
read();
|
|
|
|
|
|
|
|
|
|
write("HANGUP");
|
|
|
|
|
read();
|
|
|
|
|
exit;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
fclose($in);
|
|
|
|
|
fclose($stdlog);
|
|
|
|
|
exit;
|
|
|
|
|
?>
|