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.
189 lines
6.2 KiB
189 lines
6.2 KiB
2 years ago
|
#!/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/agente_campanha.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 = split(": ", $env);
|
||
|
$agi[str_replace("agi_", "", $s[0])] = trim($s[1]);
|
||
|
if (($env == "") || ($env == "\n")) {
|
||
|
break;
|
||
|
}
|
||
|
}
|
||
|
|
||
|
|
||
|
//parametro vindo do dialplan
|
||
|
$campanha = $argv[1];
|
||
|
$troncos_pa = $argv[2];
|
||
|
|
||
|
write("GET VARIABLE MEMBERINTERFACE");
|
||
|
$MEMBERINTERFACE = substr(strrchr(read(), "("), 1, -1);
|
||
|
$MATRICULA = substr($MEMBERINTERFACE, 6);
|
||
|
|
||
|
write("GET VARIABLE CDR(channel)");
|
||
|
$CANAL = substr(strrchr(read(), "("), 1, -1);
|
||
|
|
||
|
write("GET VARIABLE IDENTIFICADOR_CLI");
|
||
|
$identificador = substr(strrchr(read(), "("), 1, -1);
|
||
|
|
||
|
$FONE = substr($agi["callerid"], -10);
|
||
|
|
||
|
write("GET VARIABLE CDR(uniqueid)");
|
||
|
$UNIQUEID = substr(strrchr(read(), "("), 1, -1);
|
||
|
|
||
|
write("GET VARIABLE TIPOLIGACAO");
|
||
|
$TIPOLIGACAO = substr(strrchr(read(), "("), 1, -1);
|
||
|
|
||
|
write("GET VARIABLE ID_CLI");
|
||
|
$ID = substr(strrchr(read(), "("), 1, -1);
|
||
|
|
||
|
write("GET VARIABLE AUDIO");
|
||
|
$AUDIO = substr(strrchr(read(), "("), 1, -1);
|
||
|
|
||
|
write("SET VARIABLE MATRICULA $MATRICULA");
|
||
|
read();
|
||
|
|
||
|
write("DATABASE PUT SALA $MATRICULA F");
|
||
|
read();
|
||
|
|
||
|
write("DATABASE PUT TRANSFER $MATRICULA F");
|
||
|
read();
|
||
|
|
||
|
write("DATABASE PUT CONFERENCIA $MATRICULA F");
|
||
|
read();
|
||
|
|
||
|
write("DATABASE PUT CLIENTE $MATRICULA $CANAL");
|
||
|
read();
|
||
|
|
||
|
|
||
|
if ($AUDIO) {
|
||
|
write("SET VARIABLE CDR(userfield) $AUDIO");
|
||
|
read();
|
||
|
$GRAVACAO = 'V';
|
||
|
}
|
||
|
|
||
|
$query = "update pbx_supervisor_agentes set id_eventos_agente = '0',cont_identificador=translate('$identificador','-','|'),status='OCUPADO',duracao=now(),origem_destino='$FONE',canal='$CANAL',uniqueid = '$UNIQUEID',tipo_ligacao = '$TIPOLIGACAO',tipo_discagem = 'AUTOMATICA',status_gravacao = '$GRAVACAO',canal_agente = '$MEMBERINTERFACE',status_agente = '0' ,motivo_pausa = '0' ,canal_transfer = '' where matricula = '$MATRICULA'";
|
||
|
pg_query($query);
|
||
|
|
||
|
if ($TIPOLIGACAO == 'RECEPTIVA') {
|
||
|
|
||
|
$query = "select id_cliente,canal,substring(canal FROM (POSITION ('/' IN canal) + 1) FOR (POSITION ('@' IN canal) - 7)) as cont_fone from pbx_campanha_canais_discando where status = '0' order by id_canais desc limit 1";
|
||
|
$result = @pg_query($conexao, $query);
|
||
|
$row = @pg_fetch_array($result);
|
||
|
$idcliente = $row['id_cliente'];
|
||
|
$canal = $row['canal'];
|
||
|
$cont_fone = substr($row['cont_fone'], -10);
|
||
|
|
||
|
if ($canal) {
|
||
|
write("EXEC SoftHangup $canal");
|
||
|
read();
|
||
|
|
||
|
$query = "update pbx_campanha_contato set cont_discado = '0', cont_peso = '-10' where cont_id = '$idcliente'";
|
||
|
pg_query($query);
|
||
|
|
||
|
$query = "update pbx_campanha_contato_fone set conf_status = '0',conf_data = 'now()' where cont_id = '$idcliente' and substr(conf_fone,(length(conf_fone) - 9),10) = '$cont_fone' and conf_status_lista = '1'";
|
||
|
pg_query($query);
|
||
|
}
|
||
|
|
||
|
write("EXEC PauseQueueMember |$MEMBERINTERFACE");
|
||
|
read();
|
||
|
|
||
|
$query = "update pbx_campanha_canais_discando set status = '1' where id_cliente = '$idcliente'";
|
||
|
pg_query($query);
|
||
|
pg_close();
|
||
|
|
||
|
fclose($in);
|
||
|
fclose($stdlog);
|
||
|
|
||
|
exit;
|
||
|
}
|
||
|
|
||
|
if ($troncos_pa > '1') {
|
||
|
|
||
|
$query = "select id_cliente,canal,substring(canal FROM (POSITION ('/' IN canal) + 1) FOR (POSITION ('@' IN canal) - 7)) as cont_fone from pbx_campanha_canais_discando where status = '0' and id_cliente <> '$ID' order by id_canais desc limit ($troncos_pa - 1)";
|
||
|
$result = @pg_query($conexao, $query);
|
||
|
while ($row = @pg_fetch_array($result)) {
|
||
|
$idcliente = $row['id_cliente'];
|
||
|
$canal = $row['canal'];
|
||
|
$cont_fone = substr($row['cont_fone'], -10);
|
||
|
|
||
|
if ($canal) {
|
||
|
write("EXEC SoftHangup $canal");
|
||
|
read();
|
||
|
|
||
|
$query = "update pbx_campanha_contato set cont_discado = '0', cont_peso = '-10' where cont_id = '$idcliente'";
|
||
|
pg_query($query);
|
||
|
|
||
|
$query = "update pbx_campanha_contato_fone set conf_status = '0',conf_data = 'now()' where cont_id = '$idcliente' and substr(conf_fone,(length(conf_fone) - 9),10) = '$cont_fone' and conf_status_lista = '1'";
|
||
|
pg_query($query);
|
||
|
}
|
||
|
|
||
|
$query = "delete from pbx_campanha_canais_discando where id_cliente = '$idcliente' and status = '0'";
|
||
|
pg_query($query);
|
||
|
}
|
||
|
}
|
||
|
|
||
|
|
||
|
$query = "select cmp_aguarda_agente,cmp_id from pbx_campanha where cmp_status <> 0 and cmp_descricao = '$campanha'";
|
||
|
$result = @pg_query($conexao, $query);
|
||
|
$row = @pg_fetch_array($result);
|
||
|
$cmp_aguarda_agente = $row['cmp_aguarda_agente'];
|
||
|
$cmp_id_campanha = $row['cmp_id'];
|
||
|
|
||
|
if ($cmp_aguarda_agente) {
|
||
|
write("EXEC PauseQueueMember |$MEMBERINTERFACE");
|
||
|
read();
|
||
|
}
|
||
|
|
||
|
$query = "update pbx_campanha_contato set cont_peso = '0',cont_discado = '1' where cont_id = '$ID'";
|
||
|
pg_query($query);
|
||
|
|
||
|
//Identifica agente na tabela pbx_campanha_contatos_fone
|
||
|
|
||
|
$query = "update pbx_campanha_contato_fone set agente = '$MATRICULA',conf_status = 'HUMAN-ATENDIDA', conf_data = 'now()' where substr(conf_fone,(length(conf_fone) - 9),10) = '$FONE' and cont_id = '$ID' and cmp_id = '$cmp_id_campanha' and conf_status_lista = '1' ";
|
||
|
pg_query($query);
|
||
|
|
||
|
|
||
|
$query = "delete from pbx_campanha_canais_discando where id_cliente='$ID' and status = '0'";
|
||
|
pg_query($query);
|
||
|
|
||
|
|
||
|
//Relatorio de desempenho do discador
|
||
|
$query = "insert into pbx_campanha_complemento(uniqueid, matricula, login_id, cmp_id, list_id, cont_id,conf_id) (select '$UNIQUEID','$MATRICULA',(select max(id) from pbx_eventos_agentes where login::date = cast(now() as date) and matricula = '$MATRICULA' and id_dac = '$cmp_id_campanha'),cmp_id,list_id,cont_id,conf_id from pbx_campanha_contato_fone where substr(conf_fone,(length(conf_fone) - 9),10) = '$FONE' and cont_id = '$ID' and cmp_id = '$cmp_id_campanha' and conf_status_lista = '1') ";
|
||
|
pg_query($query);
|
||
|
pg_close();
|
||
|
|
||
|
|
||
|
// clean up file handlers etc.
|
||
|
fclose($in);
|
||
|
fclose($stdlog);
|
||
|
?>
|