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.
111 lines
3.2 KiB
111 lines
3.2 KiB
#!/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/status_discador.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 |
|
$status = $argv[1]; |
|
$id_cli = $argv[2]; |
|
$fone = $argv[3]; |
|
$tipo = $argv[4]; |
|
$agd_id = $argv[5]; |
|
|
|
if (trim(strtolower($tipo)) == 'agendamento') { |
|
|
|
$query = "update pbx_campanha_agendamento set agd_status = '$status', agd_agendado = (agd_agendado + 1) where agd_id = '$agd_id'"; |
|
pg_query($query); |
|
|
|
// Verifica se a campanha está pendente |
|
$query = "select cmp_status,cmp_id from pbx_campanha where cmp_id = (select cmp_id from pbx_campanha_agendamento where agd_id = '$agd_id')"; |
|
$result = pg_query($conexao, $query); |
|
$row = pg_fetch_row($result); |
|
$status = $row[0]; |
|
$cmp_id = $row[1]; |
|
|
|
//Verifica se ainda há agendadmento |
|
$query = "select count(*) from pbx_campanha_agendamento where cmp_id = '$cmp_id' and agd_agendado < '3' and agd_status <> 'ATENDIDA' "; |
|
$result = pg_query($conexao, $query); |
|
$row = pg_fetch_row($result); |
|
$agendado = $row[0]; |
|
|
|
write("NOOP STATUS => $status"); |
|
read(); |
|
|
|
write("NOOP AGENDADO => $agendado"); |
|
read(); |
|
|
|
|
|
if (!$agendado && $status == '6') { |
|
$query = "update pbx_campanha set cmp_status = '5' where cmp_id = '$cmp_id'"; |
|
pg_query($query); |
|
pg_close(); |
|
} |
|
} else if (trim(strtolower($status)) == 'atendida') { |
|
mostra_parametro(human); |
|
mostra_parametro($status); |
|
$query = "update pbx_campanha_contato_fone set conf_status = '$status',conf_data = 'now()' where cont_id = '$id_cli' and substr(conf_fone,(length(conf_fone) - 9),10) = '$fone' and conf_status_lista = '1'"; |
|
pg_query($query); |
|
|
|
$query = "update pbx_campanha_contato set cont_peso = '1',cont_discado = '1' where cont_id = '$id_cli'"; |
|
pg_query($query); |
|
pg_close(); |
|
} else { |
|
|
|
mostra_parametro($status); |
|
$query = "update pbx_campanha_contato_fone set conf_status = '$status',conf_data = 'now()' where cont_id = '$id_cli' and substr(conf_fone,(length(conf_fone) - 9),10) = '$fone' and conf_status_lista = '1'"; |
|
pg_query($query); |
|
|
|
$query = "update pbx_campanha_contato set cont_peso = '0',cont_discado = '0' where cont_id = '$id_cli'"; |
|
pg_query($query); |
|
|
|
$query = "delete from pbx_campanha_canais_discando where id_cliente = '$id_cli' and status = '0'"; |
|
pg_query($query); |
|
pg_close(); |
|
} |
|
|
|
function mostra_parametro($parametro) { |
|
write("EXEC Noop PARAMETRO ==> $parametro"); |
|
read(); |
|
} |
|
|
|
// clean up file handlers etc. |
|
fclose($in); |
|
fclose($stdlog); |
|
?>
|
|
|