3638 lines
135 KiB
PHP
3638 lines
135 KiB
PHP
#!/usr/bin/php -q
|
|
<?php
|
|
function logStart() {
|
|
|
|
if ($GLOBALS['isXampp']) {
|
|
$GLOBALS['logfile'] = "hitagi-entrada-debug.html";
|
|
} else {
|
|
$GLOBALS['logfile'] = "/var/www/html/hitmanager/agi-debug.html";
|
|
}
|
|
$fp = fopen($GLOBALS['logfile'],'w');
|
|
fwrite($fp,date("Y-m-d H:i:s"));
|
|
fclose($fp);
|
|
|
|
}
|
|
|
|
function logAdd($texto) {
|
|
|
|
if (isset($GLOBALS['logfile'])) {
|
|
$fp = fopen($GLOBALS['logfile'],'a');
|
|
fwrite($fp,$texto);
|
|
fclose($fp);
|
|
}
|
|
|
|
}
|
|
|
|
function logAddFgItem($fgItem = array()) {
|
|
|
|
$id = isset($fgItem['id']) ? $fgItem['id'] : '';
|
|
$idmaster = isset($fgItem['idmaster']) ? $fgItem['idmaster'] : '';
|
|
$idnext = isset($fgItem['idnext']) ? $fgItem['idnext'] : '';
|
|
$cmd = isset($fgItem['cmd']) ? $fgItem['cmd'] : '';
|
|
$variation = isset($fgItem['variation']) ? $fgItem['variation'] : '';
|
|
$value = isset($fgItem['value']) ? $fgItem['value'] : '';
|
|
$value2 = isset($fgItem['value2']) ? $fgItem['value2'] : '';
|
|
$value3 = isset($fgItem['value3']) ? $fgItem['value3'] : '';
|
|
$fp = fopen($GLOBALS['logfile'],'a');
|
|
fwrite($fp,'id: ' . $id . '<br>');
|
|
fwrite($fp,'idmaster: ' . $idmaster . '<br>');
|
|
fwrite($fp,'idnext: ' . $idnext . '<br>');
|
|
fwrite($fp,'cmd: ' . $cmd . '<br>');
|
|
fwrite($fp,'variation: ' . $variation . '<br>');
|
|
fwrite($fp,'value: ' . $value . '<br>');
|
|
fwrite($fp,'value2: ' . $value2 . '<br>');
|
|
fwrite($fp,'value3: ' . $value3 . '<br>');
|
|
if (isset($fgItem['defaultvalues'])) {
|
|
foreach ($fgItem['defaultvalues'] as $rowkey => $rowvalue) {
|
|
fwrite($fp,$rowkey . ': ' . $rowvalue . '<br>');
|
|
}
|
|
}
|
|
fclose($fp);
|
|
|
|
}
|
|
|
|
function logIVRAddFgItem($fgItem = array(),$result = array()) {
|
|
|
|
if ($GLOBALS['uniqueid'] != '') {
|
|
|
|
if (count($result) > 0) {
|
|
$fgItem['result'] = $result;
|
|
}
|
|
$target_dir = $GLOBALS['appdir'] . DIRECTORY_SEPARATOR . "logivr" . DIRECTORY_SEPARATOR;
|
|
if (!file_exists($target_dir)) {
|
|
mkdir($target_dir, 0777);
|
|
}
|
|
$target_json = $target_dir . $GLOBALS['uniqueid'] . '.json';
|
|
$target_content = json_encode($fgItem) . ",\n";
|
|
if (!file_exists($target_json)) {
|
|
file_put_contents($target_json,$target_content);
|
|
} else {
|
|
file_put_contents($target_json,$target_content,FILE_APPEND);
|
|
}
|
|
}
|
|
|
|
}
|
|
|
|
function logIVRAddFgItemLast($fgItem = array(),$result = array()) {
|
|
|
|
if ($GLOBALS['uniqueid'] != '') {
|
|
|
|
if (count($result) > 0) {
|
|
$fgItem['result'] = $result;
|
|
}
|
|
$target_dir = $GLOBALS['appdir'] . DIRECTORY_SEPARATOR . "logivr" . DIRECTORY_SEPARATOR;
|
|
if (!file_exists($target_dir)) {
|
|
mkdir($target_dir, 0777);
|
|
}
|
|
$target_json = $target_dir . $GLOBALS['uniqueid'] . '-last.json';
|
|
$target_content = json_encode($fgItem);
|
|
file_put_contents($target_json,$target_content);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
// --------------------------------------------------------------------------------------------------------------------------------
|
|
|
|
function agiAddCallback($args = array()) {
|
|
|
|
// https://www.voip-info.org/asterisk-auto-dial-out/
|
|
|
|
$args['ramal'] = isset($args['ramal']) ? $args['ramal'] : '';
|
|
$args['numero'] = isset($args['numero']) ? $args['numero'] : '';
|
|
|
|
//$calldata = "Channel: PJSIP/" . $args['ramal'] . "\n";
|
|
//$calldata.= "Context: padrao\n";
|
|
//$calldata.= "Extension: " . $args['numero'] . "\n";
|
|
|
|
$calldata = "Channel: Local/" . $args['ramal'] . "@padrao" . "\n";
|
|
$calldata.= "Context: padrao\n";
|
|
$calldata.= "Extension: 0" . $args['numero'] . "\n";
|
|
|
|
// MaxRetries
|
|
// RetryTime
|
|
// WaitTime
|
|
$filename = time() . '-' . rand(100,999) . '.call';
|
|
|
|
if (file_exists('/var/www/html/hitmanager/dial/')) {
|
|
$target = '/var/www/html/hitmanager/dial/' . $filename;
|
|
file_put_contents($target,$calldata);
|
|
$time = time()+30;
|
|
touch($target,$time);
|
|
}
|
|
|
|
if (file_exists('/var/spool/asterisk/outgoing/')) {
|
|
$target2 = '/var/spool/asterisk/outgoing/' . $filename;
|
|
rename($target,$target2);
|
|
}
|
|
|
|
}
|
|
|
|
function agiRecordFilaIfAuditoria($args = array()) {
|
|
|
|
$return = '';
|
|
$args['idqueue'] = isset($args['idqueue']) ? $args['idqueue'] : '';
|
|
$gravar = hitpbxCheckAuditoria(array('idqueue' => $args['idqueue']));
|
|
if ($gravar) {
|
|
$response = agiRunRecord(array('tipo' => 'auditoria_fila','idqueue' => $args['idqueue']));
|
|
}
|
|
return $return;
|
|
|
|
}
|
|
|
|
function agiRecordRamaisIfAuditoria($args = array()) {
|
|
|
|
$return = '';
|
|
$args['ramal'] = isset($args['ramal']) ? $args['ramal'] : '';
|
|
$args['ramais'] = isset($args['ramais']) ? $args['ramais'] : array();
|
|
if ($args['ramal'] != '') {
|
|
$args['ramais'][] = $args['ramal'];
|
|
}
|
|
foreach ($args['ramais'] as $ramal) {
|
|
$gravar = hitpbxCheckAuditoria(array('ramal' => $ramal));
|
|
if ($gravar) {
|
|
//$response = agiRunCmd('EXEC NOOP SIM'.$ramal);
|
|
$response = agiRunRecord(array('tipo' => 'auditoria_ramal','ramal' => $ramal));
|
|
} else {
|
|
//$response = agiRunCmd('EXEC NOOP NAO'.$ramal);
|
|
}
|
|
}
|
|
return $return;
|
|
|
|
}
|
|
|
|
function agiRunCmd($command = '') {
|
|
|
|
logAdd('<br>agiRunCmd<br><br>');
|
|
logAdd('command: ' . $command . '<br>');
|
|
|
|
$return = '';
|
|
|
|
if (!$GLOBALS['isXampp']) {
|
|
|
|
fwrite($GLOBALS['stdout'], $command . "\n");
|
|
fflush($GLOBALS['stdout']);
|
|
|
|
while ($line = fgets($GLOBALS['stdin'])) {
|
|
logAdd('line: ' . $line . "<br>");
|
|
$return.= $line;
|
|
if (strpos($line, 'result=') !== false) {
|
|
|
|
if (substr($line,0,22) != '100 result=0 Trying...') {
|
|
break;
|
|
}
|
|
|
|
}
|
|
}
|
|
$return = trim($return);
|
|
logAdd('return: ' . $return . '<br><br>');
|
|
|
|
}
|
|
|
|
return $return;
|
|
|
|
}
|
|
|
|
function agiRunDialNumeroExterno($numero = '') {
|
|
|
|
$return = '';
|
|
|
|
//$cmd = 'EXEC Dial SIP/SER2105/'.$numero.',30,Tt ""';
|
|
$cmd = 'EXEC Dial Local/'.$numero.'@checksaida,30,Tt ""';
|
|
$response = agiRunCmd($cmd);
|
|
|
|
$cmd = 'GET VARIABLE DIALSTATUS';
|
|
$response = agiRunCmd($cmd);
|
|
$explodido = explode("(",$response);
|
|
if (count($explodido) > 1) {
|
|
$return = substr($explodido[1],0,-1);
|
|
if ($return != 'ANSWER') {
|
|
$cmd = 'EXEC PLAYBACK /var/lib/asterisk/sounds/pt_BR/exten-unavail ""';
|
|
$response = agiRunCmd($cmd);
|
|
}
|
|
}
|
|
|
|
return $return;
|
|
|
|
}
|
|
|
|
function agiRunDialRamal($ramal = '') {
|
|
|
|
// logAdd('<hr>agiRunDialRamal '.$ramal.'<br><br>');
|
|
|
|
$return = '';
|
|
|
|
$runNext = true;
|
|
|
|
$desvio = hitpbxGetDesvioFrom(array('tipo' => 'ramal','value' => $ramal));
|
|
if (count($desvio)) {
|
|
$runNext = false;
|
|
if ($desvio['shortname'] == 'numeroexterno') {
|
|
$return = agiRunDialNumeroExterno($desvio['numero']);
|
|
}
|
|
if ($desvio['shortname'] == 'queue') {
|
|
$queuestatus = agiRunQueue(array('id' => $desvio['queue']));
|
|
if ($queuestatus == '') { $return = 'ANSWER'; }
|
|
}
|
|
if ($desvio['shortname'] == 'ramal') {
|
|
$return = agiRunDialRamal($desvio['ramal']);
|
|
}
|
|
if ($desvio['shortname'] == 'voicemail') {
|
|
agiRunVoicemail($desvio['ramal']);
|
|
$return = 'ANSWER';
|
|
}
|
|
if ($desvio['shortname'] == 'numeroexterno') {
|
|
agiRunDialNumeroExterno($desvio['numero']);
|
|
}
|
|
}
|
|
|
|
if ($runNext) {
|
|
|
|
$ramais_vai_tocar = array();
|
|
|
|
$cmd = 'EXEC Dial ';
|
|
|
|
$ramais_secretaria = hitpbxGetRamaisSecretariaFromRamal($ramal);
|
|
if (count($ramais_secretaria)) {
|
|
foreach ($ramais_secretaria as $ramal) {
|
|
|
|
$response = agiRunCmd('GET FULL VARIABLE ${PJSIP_DIAL_CONTACTS('.$ramal.')}');
|
|
$contacts = str_replace('200 result=1 (','',$response);
|
|
$contacts = substr($contacts,0,-1);
|
|
|
|
$ramais_vai_tocar[] = $ramal;
|
|
if ($cmd != 'EXEC Dial ') { $cmd.= '&'; }
|
|
//$cmd.= 'PJSIP/'.$ramal;
|
|
//$cmd.= '${PJSIP_DIAL_CONTACTS('.$ramal.')}';
|
|
$cmd.= $contacts;
|
|
|
|
$response = agiRunCmd('GET FULL VARIABLE ${PJSIP_DIAL_CONTACTS(SIP'.$ramal.')}');
|
|
$contacts2 = str_replace('200 result=1 (','',$response);
|
|
$contacts2 = substr($contacts2,0,-1);
|
|
$cmd.= '&' . $contacts2;
|
|
|
|
}
|
|
$cmd.= ',30,Tt ""';
|
|
} else {
|
|
|
|
$response = agiRunCmd('GET FULL VARIABLE ${PJSIP_DIAL_CONTACTS('.$ramal.')}');
|
|
$contacts = str_replace('200 result=1 (','',$response);
|
|
$contacts = substr($contacts,0,-1);
|
|
|
|
$ramais_vai_tocar[] = $ramal;
|
|
//$cmd.= 'PJSIP/' . $ramal;
|
|
//$cmd.= '${PJSIP_DIAL_CONTACTS('.$ramal.')}';
|
|
$cmd.= $contacts;
|
|
|
|
$response = agiRunCmd('GET FULL VARIABLE ${PJSIP_DIAL_CONTACTS(SIP'.$ramal.')}');
|
|
$contacts2 = str_replace('200 result=1 (','',$response);
|
|
$contacts2 = substr($contacts2,0,-1);
|
|
$cmd.= '&' . $contacts2;
|
|
|
|
$ring_timeout = hitpbxGetRingTimeoutFromRamal($ramal);
|
|
if (empty($ring_timeout)) {
|
|
$cmd.= ',30,Tt ""';
|
|
} else {
|
|
$cmd.= ','.$ring_timeout.',Tt ""';
|
|
}
|
|
}
|
|
|
|
/*
|
|
$uniqueid = agiVarGet('UNIQUEID');
|
|
$argssend = array();
|
|
$argssend["companyId"] = "1";
|
|
$argssend["crmPhone"] = $GLOBALS['callerid'];
|
|
$argssend["operation"] = "inboundAnsweredCall";
|
|
$argssend["crmAgent"] = $ramal;
|
|
$argssend["srcPhone"] = $GLOBALS['callerid'];
|
|
$argssend["dstPhone"] = $ramal;
|
|
$argssend["operationStatus"] = "update-answer";
|
|
$argssend["uniqueid"] = $uniqueid;
|
|
crmSend($argssend);
|
|
*/
|
|
|
|
// ...
|
|
$response = agiRecordRamaisIfAuditoria(array('ramais' => $ramais_vai_tocar));
|
|
$response = agiRunCmd($cmd);
|
|
// ...
|
|
|
|
//$argssend["operationStatus"] = "hangup";
|
|
//crmSend($argssend);
|
|
|
|
$cmd = 'GET VARIABLE DIALSTATUS';
|
|
$response = agiRunCmd($cmd);
|
|
$explodido = explode("(",$response);
|
|
if (count($explodido) > 1) {
|
|
$return = substr($explodido[1],0,-1);
|
|
if ($return != 'ANSWER') {
|
|
$cmd = 'EXEC PLAYBACK /var/lib/asterisk/sounds/pt_BR/exten-unavail ""';
|
|
$response = agiRunCmd($cmd);
|
|
$callback = hitpbxGetCallbackFromRamal($ramal);
|
|
if ($callback == '1') {
|
|
$callerid = agiVarGet('CALLERID');
|
|
$arr = array(
|
|
'ramal' => $ramal,
|
|
'numero' => $callerid
|
|
);
|
|
agiAddCallback($arr);
|
|
}
|
|
}
|
|
}
|
|
|
|
}
|
|
|
|
return $return;
|
|
|
|
}
|
|
|
|
function agiRunDialRamalGrupo($callgroup = '') {
|
|
|
|
$return = '';
|
|
|
|
$runNext = true;
|
|
|
|
$desvio = hitpbxGetDesvioFrom(array('tipo' => 'ramalgrupo','value' => $callgroup));
|
|
if (count($desvio)) {
|
|
$runNext = false;
|
|
if ($desvio['shortname'] == 'queue') {
|
|
$queuestatus = agiRunQueue(array('id' => $desvio['queue']));
|
|
if ($queuestatus == '') { $return = 'ANSWER'; }
|
|
}
|
|
if ($desvio['shortname'] == 'ramal') {
|
|
$return = agiRunDialRamal($desvio['ramal']);
|
|
}
|
|
if ($desvio['shortname'] == 'ramalgrupo') {
|
|
$return = agiRunDialRamalGrupo($desvio['callgroup']);
|
|
}
|
|
if ($desvio['shortname'] == 'voicemail') {
|
|
agiRunVoicemail($desvio['ramal']);
|
|
$return = 'ANSWER';
|
|
}
|
|
if ($desvio['shortname'] == 'numeroexterno') {
|
|
agiRunDialNumeroExterno($desvio['numero']);
|
|
}
|
|
}
|
|
|
|
if ($runNext) {
|
|
|
|
$ramais_vai_tocar = array();
|
|
|
|
$cmd = 'EXEC Dial ';
|
|
$query = "SELECT ramal FROM tab_ramal WHERE callgroup = '".mysqli_real_escape_string($GLOBALS['db'],$callgroup)."'";
|
|
$query_result = mysqli_query($GLOBALS['db'],$query) or die(mysqli_error($GLOBALS['db']));
|
|
while ($resultLinha = mysqli_fetch_assoc($query_result)) {
|
|
if ($cmd != 'EXEC Dial ') {
|
|
$cmd.= '&';
|
|
}
|
|
$cmd.= 'PJSIP/'.$resultLinha['ramal'];
|
|
$ramais_vai_tocar[] = $resultLinha['ramal'];
|
|
}
|
|
$cmd.= ' ""';
|
|
|
|
$response = agiRecordRamaisIfAuditoria(array('ramais' => $ramais_vai_tocar));
|
|
$response = agiRunCmd($cmd);
|
|
|
|
$cmd = 'GET VARIABLE DIALSTATUS';
|
|
$response = agiRunCmd($cmd);
|
|
$explodido = explode("(",$response);
|
|
if (count($explodido) > 1) {
|
|
$return = substr($explodido[1],0,-1);
|
|
if ($return != 'ANSWER') {
|
|
$cmd = 'EXEC PLAYBACK /var/lib/asterisk/sounds/pt_BR/exten-unavail ""';
|
|
$response = agiRunCmd($cmd);
|
|
}
|
|
}
|
|
|
|
}
|
|
|
|
return $return;
|
|
|
|
}
|
|
|
|
function agiRunQueue($args = array()) {
|
|
|
|
$return = '';
|
|
|
|
$args['id'] = isset($args['id']) ? $args['id'] : '';
|
|
$args['timeout'] = isset($args['timeout']) ? $args['timeout'] : '';
|
|
|
|
$runNext = true;
|
|
|
|
$cmd = 'SET VARIABLE __AGIQUEUEID "Q' . $args['id'] . '"';
|
|
$response = agiRunCmd($cmd);
|
|
|
|
$queuenome = hitpbxGetQueuenomeFromId($args['id']);
|
|
$cmd = 'SET VARIABLE __AGIQUEUENOME "' . $queuenome . '"';
|
|
$response = agiRunCmd($cmd);
|
|
|
|
// teste
|
|
// $cmd = 'GET FULL VARIABLE ${QUEUE_WAITING_COUNT(' . $args['id'] . ')}';
|
|
// $cmd = 'GET FULL VARIABLE ${QUEUE_MEMBER(' . $args['id'] . ',ready)}';
|
|
// $response = agiRunCmd($cmd);
|
|
|
|
// $cmd = 'SET VARIABLE AGICALLBACKQUEUEID 32';
|
|
// $response = agiRunCmd($cmd);
|
|
// ...
|
|
|
|
// MONITOR_FILENAME=FILA_${STRFTIME(${EPOCH},,%Y-%m-%d_%H-%M-%S)}_${UNIQUEID}_${CALLERID(num)}_${EXTEN}
|
|
// $cmd = "SET VARIABLE MONITOR_FILENAME FILA_" . date("Y-m-d_H-i-s") . "_" . $GLOBALS['uniqueid'] . "_" . $GLOBALS['callerid'] . "_" . $GLOBALS['fgId'];
|
|
$cmd = "SET VARIABLE MONITOR_FILENAME QUEUE_" . date("Y-m-d") . "_" . date("H-i-s") . "_" . $GLOBALS['uniqueid'] . "_" . $GLOBALS['callerid'] . "_" . $GLOBALS['fgId'];
|
|
$response = agiRunCmd($cmd);
|
|
// $cmd = "SET VARIABLE GLOBAL(AGIRECORDNAME) QUEUE_" . date("Y-m-d") . "_" . date("H-i-s") . "_" . $GLOBALS['uniqueid'] . "_" . $GLOBALS['callerid'] . "_" . $GLOBALS['fgId'];
|
|
$cmd = "SET VARIABLE __AGIRECORDNAME QUEUE_" . date("Y-m-d") . "_" . date("H-i-s") . "_" . $GLOBALS['uniqueid'] . "_" . $GLOBALS['callerid'] . "_" . $GLOBALS['fgId'];
|
|
$response = agiRunCmd($cmd);
|
|
|
|
$desvio = hitpbxGetDesvioFrom(array('tipo' => 'queue','value' => $args['id']));
|
|
|
|
if ($GLOBALS['isXampp']) {
|
|
$rnd = rand(1,100);
|
|
if ($rnd >= 80) {
|
|
$desvio = array();
|
|
} else if ($rnd >= 60) {
|
|
$desvio = array('shortname' => 'queue','queue' => '3');
|
|
} else if ($rnd >= 40) {
|
|
$desvio = array('shortname' => 'ramal','ramal' => '1001');
|
|
} else if ($rnd >= 20) {
|
|
$desvio = array('shortname' => 'voicemail','ramal' => '1001');
|
|
} else {
|
|
$desvio = array('shortname' => 'numeroexterno','ramal' => 'numero');
|
|
}
|
|
}
|
|
|
|
if (count($desvio)) {
|
|
// logAdd("desvio: ".json_encode($desvio)."<br>");
|
|
$runNext = false;
|
|
if ($desvio['shortname'] == 'queue') {
|
|
$return = agiRunQueue(array('id' => $desvio['queue']));
|
|
}
|
|
if ($desvio['shortname'] == 'ramal') {
|
|
$response = agiRunDialRamal($desvio['ramal']);
|
|
if ($response == 'ANSWER') { $return = ''; }
|
|
}
|
|
if ($desvio['shortname'] == 'voicemail') {
|
|
agiRunVoicemail($desvio['ramal']);
|
|
$return = '';
|
|
}
|
|
if ($desvio['shortname'] == 'numeroexterno') {
|
|
agiRunDialNumeroExterno($desvio['numero']);
|
|
}
|
|
}
|
|
|
|
if ($runNext) {
|
|
|
|
// $response = agiRunCmd('SET VARIABLE GLOBAL(AGIIVRSTOP) NAO');
|
|
$response = agiRunCmd('SET VARIABLE __AGIIVRSTOP NAO');
|
|
|
|
if (empty($args['timeout'])) {
|
|
$cmd = 'EXEC Queue Q' . $args['id'] . ',ctT';
|
|
} else {
|
|
$cmd = 'EXEC Queue Q' . $args['id'] . ',ctT,,,' . $args['timeout'];
|
|
}
|
|
|
|
$response = agiRecordFilaIfAuditoria(array('idqueue' => $args['id']));
|
|
$response = agiRunCmd($cmd);
|
|
|
|
$cmd = 'GET VARIABLE QUEUESTATUS';
|
|
$response = agiRunCmd($cmd);
|
|
logAdd('GET VARIABLE QUEUESTATUS: '.$response.'<br>');
|
|
|
|
if ($GLOBALS['isXampp']) {
|
|
$rnd = rand(1,100);
|
|
if ($rnd >= 50) {
|
|
$response = 'TIMEOUT';
|
|
} else {
|
|
$response = '';
|
|
}
|
|
}
|
|
|
|
// logAdd("QUEUESTATUS: ".$response);
|
|
|
|
if (strpos($response,'TIMEOUT')) {
|
|
$return = 'timeout';
|
|
}
|
|
|
|
// ...
|
|
// $agiivrstop = agiVarGet("GLOBAL(AGIIVRSTOP)");
|
|
$agiivrstop = agiVarGet("AGIIVRSTOP");
|
|
$agiivrstop = str_replace('"','',$agiivrstop);
|
|
// logAdd('AGIIVRSTOP: '.$agiivrstop.'<br>');
|
|
if ($agiivrstop == 'SIM') {
|
|
// logAdd('FOI SIM<br>');
|
|
$return = 'stopivr';
|
|
}
|
|
// ...
|
|
|
|
}
|
|
|
|
return $return;
|
|
|
|
}
|
|
|
|
function agiRunRecord($args = array()) {
|
|
|
|
/*
|
|
Layout dos arquivos:
|
|
TIPO_DATA_HORA_UNIQUEID_CALLERID_ORIGEM_DESTINO
|
|
Exemplo ramal:
|
|
AUDITORIA-RAMAL_2023-11-29_10-33-55_1701264825.168_2004_2005.wav
|
|
Exemplo fial de atendimento (o destino é o id da tab_queue)
|
|
AUDITORIA-QUEUE_2023-11-29_10-54-36_1701266065.175_2004_14.wav
|
|
*/
|
|
|
|
$return = '';
|
|
$args['tipo'] = isset($args['tipo']) ? $args['tipo'] : '';
|
|
if ($args['tipo'] == 'auditoria_fila') {
|
|
$args['idqueue'] = isset($args['idqueue']) ? $args['idqueue'] : '';
|
|
if (is_numeric($args['idqueue'])) {
|
|
$uniqueid = agiVarGet('UNIQUEID');
|
|
$callerid = agiVarGet('CALLERID');
|
|
//$cmd = 'EXEC MixMonitor AUDITORIA-QUEUE_'.date("Y-m-d").'_'.date("H-i-s").'_'.$uniqueid.'_'.$callerid.'_'.$args['idqueue'].'.wav';
|
|
$cmd = 'EXEC MixMonitor AUDITORIA-QUEUE_'.date("Y-m-d").'_'.date("H-i-s").'_'.$uniqueid.'_'.$callerid.'_'.$args['idqueue'].'.ogg';
|
|
$response = agiRunCmd($cmd);
|
|
}
|
|
}
|
|
if ($args['tipo'] == 'auditoria_ramal') {
|
|
$args['ramal'] = isset($args['ramal']) ? $args['ramal'] : '';
|
|
if (is_numeric($args['ramal'])) {
|
|
$uniqueid = agiVarGet('UNIQUEID');
|
|
$callerid = agiVarGet('CALLERID');
|
|
//$cmd = 'EXEC MixMonitor AUDITORIA-RAMAL_'.date("Y-m-d").'_'.date("H-i-s").'_'.$uniqueid.'_'.$callerid.'_'.$args['ramal'].'.wav';
|
|
$cmd = 'EXEC MixMonitor AUDITORIA-RAMAL_'.date("Y-m-d").'_'.date("H-i-s").'_'.$uniqueid.'_'.$callerid.'_'.$args['ramal'].'.ogg';
|
|
$response = agiRunCmd($cmd);
|
|
}
|
|
}
|
|
return $return;
|
|
|
|
}
|
|
|
|
function agiRunVoicemail($ramal = '') {
|
|
|
|
$return = agiRunCmd('EXEC VOICEMAIL ' . $ramal);
|
|
return $return;
|
|
|
|
}
|
|
|
|
function agiVarGet($varName = '') {
|
|
|
|
$return = '';
|
|
|
|
if ($GLOBALS['isXampp']) {
|
|
|
|
$return = '';
|
|
|
|
} else {
|
|
|
|
//$cmd = 'GET VARIABLE UNIQUEID'; // 200 result=1 (1695911399.249)
|
|
//$cmd = 'GET VARIABLE CALLERID(all)'; // 200 result=1 ("" <2001>)
|
|
//$cmd = 'GET VARIABLE EXTEN'; // 200 result=1 (2501)
|
|
|
|
$cmd = '';
|
|
if ($varName == 'CALLERID') {
|
|
$cmd = 'GET VARIABLE CALLERID(all)';
|
|
} else {
|
|
$cmd = 'GET VARIABLE ' . $varName;
|
|
}
|
|
|
|
$response = agiRunCmd($cmd);
|
|
|
|
if ($varName == 'CALLERID') {
|
|
if (substr($response,0,14) == '200 result=1 (') {
|
|
$explodido = explode('<',$response);
|
|
$return = substr($explodido[1],0,-2);
|
|
}
|
|
} else {
|
|
$explodido = explode("(",$response);
|
|
if (count($explodido) > 1) {
|
|
$explodido = explode(")",$explodido[1]);
|
|
$return = $explodido[0];
|
|
}
|
|
}
|
|
|
|
}
|
|
|
|
return $return;
|
|
|
|
}
|
|
|
|
function agiVarSet($varName = '', $varValue = '') {
|
|
|
|
if ($GLOBALS['isXampp']) {
|
|
|
|
return '';
|
|
|
|
} else {
|
|
|
|
if ($varName == 'CALLERID') {
|
|
$varName = 'CALLERID(num)';
|
|
}
|
|
$return = agiRunCmd('SET VARIABLE ' . $varName . ' ' . $varValue);
|
|
return $return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
// --------------------------------------------------------------------------------------------------------------------------------
|
|
|
|
function crmSend($args = array()) {
|
|
|
|
$podeenviar = true;
|
|
|
|
$url = 'http://172.31.187.24:6004/api/v1/crm/call-journaling';
|
|
|
|
$headers = [
|
|
'Authorization' => 'Bearer 2ivck10D3o9qAZi0pkKudVDl9bdEVXY2s8gdxZ0jYgL1DZWTgDz6wDiIjlWgYmJtVOoqf0b42ZTLBRrfo8WoAaScRsujz3jQUNXdchSg0o43YilZGmVhheGJNAeIQRknHEll4nRJ7avcFgmDGoYbEey7TSC8EHS4Z3gzeufYYSfnKNDBwwzBURIQrTOxYFe3tBHsGOzwnuD2lU5tnEx7tr2XRO4zRNYeNY4lMBOFM0mRuyAe4kuqTrKXmJ8As200',
|
|
'Content-Type' => 'application/json'
|
|
];
|
|
|
|
$postfields_arr = array();
|
|
$postfields_arr["companyId"] = isset($args['companyId']) ? $args['companyId'] : "1";
|
|
$postfields_arr["crmPhone"] = isset($args['crmPhone']) ? $args['crmPhone'] : "";
|
|
$postfields_arr["operation"] = isset($args['operation']) ? $args['operation'] : "";
|
|
$postfields_arr["crmAgent"] = isset($args['crmAgent']) ? $args['crmAgent'] : "";
|
|
$postfields_arr["srcPhone"] = isset($args['srcPhone']) ? $args['srcPhone'] : "";
|
|
$postfields_arr["dstPhone"] = isset($args['dstPhone']) ? $args['dstPhone'] : "";
|
|
$postfields_arr["operationStatus"] = isset($args['operationStatus']) ? $args['operationStatus'] : "";
|
|
$postfields_arr["uniqueid"] = isset($args['uniqueid']) ? $args['uniqueid'] : "";
|
|
$postfields_json = json_encode($postfields_arr);
|
|
|
|
$curl = curl_init();
|
|
|
|
curl_setopt_array($curl, array(
|
|
CURLOPT_URL => $url,
|
|
CURLOPT_RETURNTRANSFER => true,
|
|
CURLOPT_ENCODING => '',
|
|
CURLOPT_MAXREDIRS => 10,
|
|
CURLOPT_TIMEOUT => 0,
|
|
CURLOPT_FOLLOWLOCATION => true,
|
|
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
|
|
CURLOPT_CUSTOMREQUEST => 'POST',
|
|
CURLOPT_POSTFIELDS => $postfields_json,
|
|
CURLOPT_HTTPHEADER => array(
|
|
'Authorization: Bearer 2ivck10D3o9qAZi0pkKudVDl9bdEVXY2s8gdxZ0jYgL1DZWTgDz6wDiIjlWgYmJtVOoqf0b42ZTLBRrfo8WoAaScRsujz3jQUNXdchSg0o43YilZGmVhheGJNAeIQRknHEll4nRJ7avcFgmDGoYbEey7TSC8EHS4Z3gzeufYYSfnKNDBwwzBURIQrTOxYFe3tBHsGOzwnuD2lU5tnEx7tr2XRO4zRNYeNY4lMBOFM0mRuyAe4kuqTrKXmJ8As200',
|
|
'Content-Type: application/json',
|
|
'Cookie: connect.sid=s%3Aw2hpzj8eiKSybRG2rqPdSfSXUjXieDWR.W%2BoGXKAGgPqQMC9cKR6FTKRsfyrg%2Bvfo9MUDm9gSAv8'
|
|
),
|
|
));
|
|
|
|
if ($podeenviar) {
|
|
$response = curl_exec($curl);
|
|
$httpcode = curl_getinfo($curl, CURLINFO_HTTP_CODE);
|
|
curl_close($curl);
|
|
}
|
|
|
|
}
|
|
|
|
// --------------------------------------------------------------------------------------------------------------------------------
|
|
|
|
function fgItemGetChildrenFrom($fgItemFrom = array()) {
|
|
|
|
// logAdd('<hr>fgItemGetChildrenFrom<br><br>');
|
|
// logAddFgItem($fgItemFrom);
|
|
// logAdd("<br>");
|
|
|
|
$return = array();
|
|
reset($GLOBALS['fgItens']);
|
|
foreach ($GLOBALS['fgItens'] as $fgItem) {
|
|
if ($fgItem['cmd'] != 'start') {
|
|
if ($fgItem['idmaster'] == $fgItemFrom['id']) {
|
|
$return[$fgItem['id']] = $fgItem;
|
|
}
|
|
}
|
|
}
|
|
return $return;
|
|
|
|
}
|
|
|
|
function fgItemGetMasterFrom($fgItemFrom = array()) {
|
|
|
|
// logAdd('<hr>fgItemGetMasterFrom<br><br>');
|
|
// logAddFgItem($fgItemFrom);
|
|
|
|
$return = array();
|
|
if (isset($GLOBALS['fgItens'][$fgItemFrom['idmaster']])) {
|
|
$return = $GLOBALS['fgItens'][$fgItemFrom['idmaster']];
|
|
}
|
|
return $return;
|
|
|
|
}
|
|
|
|
function fgItemIsDialplanCheckvar($fgItem = array()) {
|
|
|
|
if (isset($fgItem['defaultvalues']['cmd'])) {
|
|
if ($fgItem['defaultvalues']['cmd'] == 'dialplan.checkvar') {
|
|
return true;
|
|
}
|
|
}
|
|
if ($fgItem['cmd'] == 'dialplan.checkvar') {
|
|
return true;
|
|
}
|
|
return false;
|
|
|
|
}
|
|
|
|
function fgItemRun($fgItem = array()) {
|
|
|
|
// logAdd("<hr>fgItemRun<br><br>");
|
|
// logAddFgItem($fgItem);
|
|
// logAdd("<br>");
|
|
|
|
if (count($fgItem) > 0) {
|
|
|
|
if ($fgItem['cmd'] == 'agi.exec') {
|
|
fgItemRunAgiExec($fgItem);
|
|
return;
|
|
}
|
|
if ($fgItem['cmd'] == 'blacklist.check') {
|
|
fgItemRunBlacklistCheck($fgItem);
|
|
return;
|
|
}
|
|
if ($fgItem['cmd'] == 'blacklist.true') {
|
|
fgItemRunBlacklistTrue($fgItem);
|
|
return;
|
|
}
|
|
if ($fgItem['cmd'] == 'blacklist.false') {
|
|
fgItemRunBlacklistFalse($fgItem);
|
|
return;
|
|
}
|
|
if ($fgItem['cmd'] == 'callerid.change') {
|
|
fgItemRunCalleridChange($fgItem);
|
|
return;
|
|
}
|
|
if ($fgItem['cmd'] == 'cnpj.check') {
|
|
fgItemRunCNPJCheck($fgItem);
|
|
return;
|
|
}
|
|
if ($fgItem['cmd'] == 'cnpj.true') {
|
|
fgItemRunCNPJCheckTrue($fgItem);
|
|
return;
|
|
}
|
|
if ($fgItem['cmd'] == 'cnpj.false') {
|
|
fgItemRunCNPJCheckFalse($fgItem);
|
|
return;
|
|
}
|
|
if ($fgItem['cmd'] == 'condtempo.check') {
|
|
fgItemRunCondTempoCheck($fgItem);
|
|
return;
|
|
}
|
|
if ($fgItem['cmd'] == 'condtempo.true') {
|
|
fgItemRunCondTempoCheckTrue($fgItem);
|
|
return;
|
|
}
|
|
if ($fgItem['cmd'] == 'condtempo.false') {
|
|
fgItemRunCondTempoCheckFalse($fgItem);
|
|
return;
|
|
}
|
|
if ($fgItem['cmd'] == 'cpf.check') {
|
|
fgItemRunCPFCheck($fgItem);
|
|
return;
|
|
}
|
|
if ($fgItem['cmd'] == 'cpf.true') {
|
|
fgItemRunCPFCheckTrue($fgItem);
|
|
return;
|
|
}
|
|
if ($fgItem['cmd'] == 'cpf.false') {
|
|
fgItemRunCPFCheckFalse($fgItem);
|
|
return;
|
|
}
|
|
if ($fgItem['cmd'] == 'dialextension') {
|
|
fgItemRunDialExtension($fgItem);
|
|
return;
|
|
}
|
|
if ($fgItem['cmd'] == 'dialgroupextension') {
|
|
fgItemRunDialGroupExtension($fgItem);
|
|
return;
|
|
}
|
|
if ($fgItem['cmd'] == 'dialplan.checkvar') {
|
|
fgItemRunDialplanCheckvar($fgItem);
|
|
return;
|
|
}
|
|
if ($fgItem['cmd'] == 'dialplan.gosub') {
|
|
fgItemRunDialplanGosub($fgItem);
|
|
return;
|
|
}
|
|
if ($fgItem['cmd'] == 'dialplan.setvar') {
|
|
fgItemRunDialplanSetvar($fgItem);
|
|
return;
|
|
}
|
|
if ($fgItem['cmd'] == 'dialdigit') {
|
|
fgItemRunDialdigit($fgItem);
|
|
return;
|
|
}
|
|
if ($fgItem['cmd'] == 'digit') {
|
|
fgItemRunDigit($fgItem);
|
|
return;
|
|
}
|
|
if ($fgItem['cmd'] == 'digitinvalid') {
|
|
fgItemRunDigitInvalid($fgItem);
|
|
return;
|
|
}
|
|
if ($fgItem['cmd'] == 'expediente.check') {
|
|
fgItemRunExpedienteCheck($fgItem);
|
|
return;
|
|
}
|
|
if ($fgItem['cmd'] == 'expediente.false') {
|
|
fgItemRunExpedienteFalse($fgItem);
|
|
return;
|
|
}
|
|
if ($fgItem['cmd'] == 'expediente.true') {
|
|
fgItemRunExpedienteTrue($fgItem);
|
|
return;
|
|
}
|
|
if ($fgItem['cmd'] == 'feriado.check') {
|
|
fgItemRunFeriadoCheck($fgItem);
|
|
return;
|
|
}
|
|
if ($fgItem['cmd'] == 'feriado.false') {
|
|
fgItemRunFeriadoFalse($fgItem);
|
|
return;
|
|
}
|
|
if ($fgItem['cmd'] == 'feriado.true') {
|
|
fgItemRunFeriadoTrue($fgItem);
|
|
return;
|
|
}
|
|
if ($fgItem['cmd'] == 'ivr.redirect') {
|
|
fgItemRunIVRRedirect($fgItem);
|
|
return;
|
|
}
|
|
if ($fgItem['cmd'] == 'nomatch') {
|
|
fgItemRunNoMatch($fgItem);
|
|
return;
|
|
}
|
|
if ($fgItem['cmd'] == 'pesqsat') {
|
|
fgItemRunPesqSat($fgItem);
|
|
return;
|
|
}
|
|
if ($fgItem['cmd'] == 'playaudio') {
|
|
fgItemRunPlayaudio($fgItem);
|
|
return;
|
|
}
|
|
if ($fgItem['cmd'] == 'queue') {
|
|
fgItemRunQueue($fgItem);
|
|
return;
|
|
}
|
|
if ($fgItem['cmd'] == 'queue.waitingcount') {
|
|
fgItemRunQueueWaitingCount($fgItem);
|
|
return;
|
|
}
|
|
if ($fgItem['cmd'] == 'queue.waitingcount-greater') {
|
|
fgItemRunQueueWaitingCountGreater($fgItem);
|
|
return;
|
|
}
|
|
if ($fgItem['cmd'] == 'queue.withcallback') {
|
|
fgItemRunQueueWithCallback($fgItem);
|
|
return;
|
|
}
|
|
if ($fgItem['cmd'] == 'queue.withcallback-noready') {
|
|
fgItemRunQueueWithCallbackNoReady($fgItem);
|
|
return;
|
|
}
|
|
if ($fgItem['cmd'] == 'record') {
|
|
fgItemRunRecord($fgItem);
|
|
return;
|
|
}
|
|
if ($fgItem['cmd'] == 'start') {
|
|
fgItemRunStart($fgItem);
|
|
return;
|
|
}
|
|
if ($fgItem['cmd'] == 'timeout') {
|
|
fgItemRunTimeout($fgItem);
|
|
return;
|
|
}
|
|
if ($fgItem['cmd'] == 'timeoutwithlimit') {
|
|
fgItemRunTimeoutWithLimit($fgItem);
|
|
return;
|
|
}
|
|
if ($fgItem['cmd'] == 'timeoutwithlimit.limit') {
|
|
fgItemRunTimeoutWithLimitLimit($fgItem);
|
|
return;
|
|
}
|
|
if ($fgItem['cmd'] == 'voicemail') {
|
|
fgItemRunVoicemail($fgItem);
|
|
return;
|
|
}
|
|
if ($fgItem['cmd'] == 'whitelist.check') {
|
|
fgItemRunWhitelistCheck($fgItem);
|
|
return;
|
|
}
|
|
if ($fgItem['cmd'] == 'whitelist.false') {
|
|
fgItemRunWhitelistFalse($fgItem);
|
|
return;
|
|
}
|
|
if ($fgItem['cmd'] == 'whitelist.true') {
|
|
fgItemRunWhitelistTrue($fgItem);
|
|
return;
|
|
}
|
|
if (isset($fgItem['defaultvalues']['cmd'])) {
|
|
if ($fgItem['defaultvalues']['cmd'] == 'dialplan.checkvar') {
|
|
fgItemRunDialplanCheckvar($fgItem);
|
|
return;
|
|
}
|
|
if ($fgItem['defaultvalues']['cmd'] == 'dialplan.gosub') {
|
|
fgItemRunDialplanGosub($fgItem);
|
|
return;
|
|
}
|
|
if ($fgItem['defaultvalues']['cmd'] == 'dialplan.setvar') {
|
|
fgItemRunDialplanSetvar($fgItem);
|
|
return;
|
|
}
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
function fgItemRunNextFrom($fgItemFrom = array()) {
|
|
|
|
// logAdd("<hr>fgItemRunNextFrom<br><br>");
|
|
// logAddFgItem($fgItemFrom);
|
|
// logAdd("<br>");
|
|
|
|
$cmds_nonext = array();
|
|
$cmds_nonext[] = 'blacklist.false';
|
|
$cmds_nonext[] = 'blacklist.true';
|
|
$cmds_nonext[] = 'cnpf.false';
|
|
$cmds_nonext[] = 'cnpf.true';
|
|
$cmds_nonext[] = 'condtempo.false';
|
|
$cmds_nonext[] = 'condtempo.true';
|
|
$cmds_nonext[] = 'cpf.false';
|
|
$cmds_nonext[] = 'cpf.true';
|
|
$cmds_nonext[] = 'dialdigit';
|
|
$cmds_nonext[] = 'digit';
|
|
$cmds_nonext[] = 'expediente.false';
|
|
$cmds_nonext[] = 'expediente.true';
|
|
$cmds_nonext[] = 'feriado.false';
|
|
$cmds_nonext[] = 'feriado.true';
|
|
$cmds_nonext[] = 'nomatch';
|
|
$cmds_nonext[] = 'queue.waitingcount-greater';
|
|
$cmds_nonext[] = 'queue.withcallback-noready';
|
|
$cmds_nonext[] = 'timeout';
|
|
$cmds_nonext[] = 'timeoutwithlimit';
|
|
$cmds_nonext[] = 'timeoutwithlimit.limit';
|
|
$cmds_nonext[] = 'voicemail';
|
|
$cmds_nonext[] = 'whitelist.false';
|
|
$cmds_nonext[] = 'whitelist.true';
|
|
|
|
$run_next = true;
|
|
|
|
if (isset($fgItemFrom['idnext'])) {
|
|
if (isset($GLOBALS['fgItens'][$fgItemFrom['idnext']])) {
|
|
fgItemRun($GLOBALS['fgItens'][$fgItemFrom['idnext']]);
|
|
$run_next = false;
|
|
}
|
|
}
|
|
|
|
$fgItemChildren = fgItemGetChildrenFrom($fgItemFrom);
|
|
foreach ($fgItemChildren as $fgItemChild) {
|
|
if (($run_next) && (!in_array($fgItemChild['cmd'],$cmds_nonext))) {
|
|
fgItemRun($fgItemChild);
|
|
$run_next = false;
|
|
}
|
|
}
|
|
|
|
}
|
|
|
|
// --------------------------------------------------------------------------------------------------------------------------------
|
|
|
|
function fgItemRunAgiExec($fgItem = array()) {
|
|
|
|
logAdd("<hr>fgItemRunAgiExec<br><br>");
|
|
logAddFgItem($fgItem);
|
|
logAdd("<br>");
|
|
|
|
logIVRAddFgItemLast($fgItem);
|
|
|
|
$result = array();
|
|
|
|
$scriptname = isset($fgItem['defaultvalues']['scriptname']) ? $fgItem['defaultvalues']['scriptname'] : '';
|
|
$value = isset($fgItem['value']) ? $fgItem['value'] : '';
|
|
$value2 = isset($fgItem['value2']) ? $fgItem['value2'] : '';
|
|
$value3 = isset($fgItem['value3']) ? $fgItem['value3'] : '';
|
|
|
|
$defaultvalues_value = isset($fgItem['defaultvalues']['value']) ? $fgItem['defaultvalues']['value'] : '';
|
|
$defaultvalues_value2 = isset($fgItem['defaultvalues']['value2']) ? $fgItem['defaultvalues']['value2'] : '';
|
|
$defaultvalues_value3 = isset($fgItem['defaultvalues']['value3']) ? $fgItem['defaultvalues']['value3'] : '';
|
|
|
|
$cmd = 'EXEC AGI '.$scriptname.',"'.$value.'","'.$value2.'","'.$value3.'","'.$defaultvalues_value.'","'.$defaultvalues_value2.'","'.$defaultvalues_value3.'"';
|
|
$result[] = $cmd;
|
|
$response = agiRunCmd($cmd);
|
|
$result[] = $response;
|
|
|
|
logIVRAddFgItem($fgItem,$result);
|
|
|
|
fgItemRunNextFrom($fgItem);
|
|
|
|
}
|
|
|
|
function fgItemRunBlacklistCheck($fgItem = array()) {
|
|
|
|
logAdd("<hr>fgItemRunBlacklistCheck<br><br>");
|
|
logAddFgItem($fgItem);
|
|
logAdd("<br>");
|
|
|
|
logIVRAddFgItemLast($fgItem);
|
|
|
|
$result = array();
|
|
|
|
if ($GLOBALS['isXampp']) {
|
|
$rnd = rand(1,100);
|
|
$esta_na_lista = ($rnd > 50) ? true : false;
|
|
} else {
|
|
$esta_na_lista = hitpbxCheckBlacklist($callerid);
|
|
}
|
|
|
|
if ($esta_na_lista) {
|
|
$result[] = 'Is True';
|
|
} else {
|
|
$result[] = 'Is False';
|
|
}
|
|
|
|
$run_next = true;
|
|
|
|
$cmdTarget = $esta_na_lista ? 'blacklist.true' : 'blacklist.false';
|
|
$fgItemChildren = fgItemGetChildrenFrom($fgItem);
|
|
foreach ($fgItemChildren as $fgItemChild) {
|
|
if ($run_next) {
|
|
if ($fgItemChild['cmd'] == $cmdTarget) {
|
|
logIVRAddFgItem($fgItem,$result);
|
|
fgItemRun($fgItemChild);
|
|
$run_next = false;
|
|
}
|
|
}
|
|
}
|
|
|
|
if ($run_next) {
|
|
$result[] = 'Not found next icon "blacklist.true" or "blacklist.false"';
|
|
logIVRAddFgItem($fgItem,$result);
|
|
}
|
|
|
|
}
|
|
|
|
function fgItemRunBlacklistFalse($fgItem = array()) {
|
|
|
|
logAdd("<hr>fgItemRunBlacklistFalse<br><br>");
|
|
logAddFgItem($fgItem);
|
|
logAdd("<br>");
|
|
|
|
logIVRAddFgItemLast($fgItem);
|
|
logIVRAddFgItem($fgItem);
|
|
|
|
fgItemRunNextFrom($fgItem);
|
|
|
|
}
|
|
|
|
function fgItemRunBlacklistTrue($fgItem = array()) {
|
|
|
|
logAdd("<hr>fgItemRunBlacklistTrue<br><br>");
|
|
logAddFgItem($fgItem);
|
|
logAdd("<br>");
|
|
|
|
logIVRAddFgItemLast($fgItem);
|
|
logIVRAddFgItem($fgItem);
|
|
|
|
fgItemRunNextFrom($fgItem);
|
|
|
|
}
|
|
|
|
function fgItemRunCalleridChange($fgItem = array()) {
|
|
|
|
logAdd('<hr>fgItemRunCalleridChange<br><br>');
|
|
logAddFgItem($fgItem);
|
|
logAdd("<br>");
|
|
|
|
logIVRAddFgItemLast($fgItem);
|
|
|
|
$result = array();
|
|
|
|
$varname = 'CALLERID(num)';
|
|
if (isset($fgItem['value2'])) {
|
|
if (trim($fgItem['value2']) != '') {
|
|
$varname = 'CALLERID(' . $fgItem['value2'] . ')';
|
|
}
|
|
}
|
|
$varvalue = $fgItem['value'];
|
|
|
|
$cmd = 'SET VARIABLE ' . $varname . ' ' . $varvalue;
|
|
$result[] = $cmd;
|
|
$response = agiRunCmd($cmd);
|
|
$result[] = $response;
|
|
|
|
logIVRAddFgItem($fgItem,$result);
|
|
|
|
fgItemRunNextFrom($fgItem);
|
|
|
|
}
|
|
|
|
function fgItemRunCNPJCheck($fgItem = array()) {
|
|
|
|
logAdd('<hr>fgItemRunCNPJCheck<br><br>');
|
|
logAddFgItem($fgItem);
|
|
logAdd("<br>");
|
|
|
|
logIVRAddFgItemLast($fgItem);
|
|
|
|
$result = array();
|
|
|
|
if ($GLOBALS['isXampp']) {
|
|
$rnd = rand(1,100);
|
|
$validado = ($rnd > 50) ? true : false;
|
|
} else {
|
|
$validado = validarCNPJ($GLOBALS['digitado']);
|
|
}
|
|
|
|
$tmp = ($validado) ? 'Yes' : 'No';
|
|
$result[] = 'CNPJ Validado: ' . $tmp;
|
|
logIVRAddFgItem($fgItem,$result);
|
|
|
|
$run_next = true;
|
|
|
|
$cmdTarget = $validado ? 'cnpj.true' : 'cnpj.false';
|
|
$fgItemChildren = fgItemGetChildrenFrom($fgItem);
|
|
foreach ($fgItemChildren as $fgItemChild) {
|
|
if ($run_next) {
|
|
if ($fgItemChild['cmd'] == $cmdTarget) {
|
|
fgItemRun($fgItemChild);
|
|
$run_next = false;
|
|
}
|
|
}
|
|
}
|
|
|
|
}
|
|
|
|
function fgItemRunCNPJCheckFalse($fgItem = array()) {
|
|
|
|
logAdd("<hr>fgItemRunCNPJCheckFalse<br><br>");
|
|
logAddFgItem($fgItem);
|
|
logAdd("<br>");
|
|
|
|
logIVRAddFgItemLast($fgItem);
|
|
logIVRAddFgItem($fgItem);
|
|
|
|
fgItemRunNextFrom($fgItem);
|
|
|
|
}
|
|
|
|
function fgItemRunCNPJCheckTrue($fgItem = array()) {
|
|
|
|
logAdd("<hr>fgItemRunCNPJCheckTrue<br><br>");
|
|
logAddFgItem($fgItem);
|
|
logAdd("<br>");
|
|
|
|
logIVRAddFgItemLast($fgItem);
|
|
logIVRAddFgItem($fgItem);
|
|
|
|
fgItemRunNextFrom($fgItem);
|
|
|
|
}
|
|
|
|
function fgItemRunCondTempoCheck($fgItem = array()) {
|
|
|
|
logAdd('<hr>fgItemRunCondTempoCheck<br><br>');
|
|
logAddFgItem($fgItem);
|
|
logAdd("<br>");
|
|
|
|
logIVRAddFgItemLast($fgItem);
|
|
|
|
$result = array();
|
|
|
|
if ($GLOBALS['isXampp']) {
|
|
|
|
$rnd = rand(1,100);
|
|
$periodo_match = ($rnd > 50) ? true : false;
|
|
|
|
} else {
|
|
|
|
$periodo_match = false;
|
|
$periodo_id = isset($fgItem['value']) ? $fgItem['value'] : '';
|
|
|
|
$query = "SELECT * FROM tab_periodo ";
|
|
$query.= "WHERE id = '".mysqli_real_escape_string($GLOBALS['db'],$periodo_id)."' ";
|
|
|
|
$weekday = date('D');
|
|
if ($weekday == 'Mon') { $query.= "AND (monday = '1' OR (monday = '0' AND tuesday = '0' AND wednesday = '0' AND thursday = '0' AND friday = '0' AND saturday = '0' AND sunday = '0')) "; }
|
|
if ($weekday == 'Tue') { $query.= "AND (tuesday = '1' OR (monday = '0' AND tuesday = '0' AND wednesday = '0' AND thursday = '0' AND friday = '0' AND saturday = '0' AND sunday = '0')) "; }
|
|
if ($weekday == 'Wed') { $query.= "AND (wednesday = '1' OR (monday = '0' AND tuesday = '0' AND wednesday = '0' AND thursday = '0' AND friday = '0' AND saturday = '0' AND sunday = '0')) "; }
|
|
if ($weekday == 'Thu') { $query.= "AND (thursday = '1' OR (monday = '0' AND tuesday = '0' AND wednesday = '0' AND thursday = '0' AND friday = '0' AND saturday = '0' AND sunday = '0')) "; }
|
|
if ($weekday == 'Fri') { $query.= "AND (friday = '1' OR (monday = '0' AND tuesday = '0' AND wednesday = '0' AND thursday = '0' AND friday = '0' AND saturday = '0' AND sunday = '0')) "; }
|
|
if ($weekday == 'Sat') { $query.= "AND (saturday = '1' OR (monday = '0' AND tuesday = '0' AND wednesday = '0' AND thursday = '0' AND friday = '0' AND saturday = '0' AND sunday = '0')) "; }
|
|
if ($weekday == 'Sun') { $query.= "AND (sunday = '1' OR (monday = '0' AND tuesday = '0' AND wednesday = '0' AND thursday = '0' AND friday = '0' AND saturday = '0' AND sunday = '0')) "; }
|
|
|
|
$hhmmss = date("H:i:s");
|
|
$query.= "AND ((time_start <= '".$hhmmss."' AND time_stop >= '".$hhmmss."') OR (time_start = '00:00:00' AND time_stop = '00:00:00')) ";
|
|
|
|
$day = date('d');
|
|
$query.= "AND ((day_start <= '".$day."' AND day_stop >= '".$day."') OR (day_start = '0' AND day_stop = '0')) ";
|
|
|
|
$month = date('m');
|
|
$query.= "AND ((month_start <= '".$month."' AND month_stop >= '".$month."') OR (month_start = '0' AND month_stop = '0')) ";
|
|
|
|
$year = date('Y');
|
|
$query.= "AND ((year_start <= '".$year."' AND year_stop >= '".$year."') OR (year_start = '0' AND year_stop = '0')) ";
|
|
|
|
$query_result = mysqli_query($GLOBALS['db'],$query);
|
|
if (mysqli_num_rows($query_result) > 0) {
|
|
$periodo_match = true;
|
|
}
|
|
|
|
}
|
|
|
|
$tmp = ($periodo_match) ? 'Yes' : 'No';
|
|
$result[] = 'Condição de tempo: ' . $tmp;
|
|
logIVRAddFgItem($fgItem,$result);
|
|
|
|
$run_next = true;
|
|
|
|
$cmdTarget = $periodo_match ? 'condtempo.true' : 'condtempo.false';
|
|
$fgItemChildren = fgItemGetChildrenFrom($fgItem);
|
|
foreach ($fgItemChildren as $fgItemChild) {
|
|
if ($run_next) {
|
|
if ($fgItemChild['cmd'] == $cmdTarget) {
|
|
fgItemRun($fgItemChild);
|
|
$run_next = false;
|
|
}
|
|
}
|
|
}
|
|
|
|
}
|
|
|
|
function fgItemRunCondTempoCheckFalse($fgItem = array()) {
|
|
|
|
logAdd("<hr>fgItemRunCondTempoCheckFalse<br><br>");
|
|
logAddFgItem($fgItem);
|
|
logAdd("<br>");
|
|
|
|
logIVRAddFgItemLast($fgItem);
|
|
logIVRAddFgItem($fgItem);
|
|
|
|
fgItemRunNextFrom($fgItem);
|
|
|
|
}
|
|
|
|
function fgItemRunCondTempoCheckTrue($fgItem = array()) {
|
|
|
|
logAdd("<hr>fgItemRunCondTempoCheckTrue<br><br>");
|
|
logAddFgItem($fgItem);
|
|
logAdd("<br>");
|
|
|
|
logIVRAddFgItemLast($fgItem);
|
|
logIVRAddFgItem($fgItem);
|
|
|
|
fgItemRunNextFrom($fgItem);
|
|
|
|
}
|
|
|
|
function fgItemRunCPFCheck($fgItem = array()) {
|
|
|
|
logAdd('<hr>fgItemRunCPFCheck<br><br>');
|
|
logAddFgItem($fgItem);
|
|
logAdd("<br>");
|
|
|
|
logIVRAddFgItemLast($fgItem);
|
|
|
|
$result = array();
|
|
|
|
if ($GLOBALS['isXampp']) {
|
|
$rnd = rand(1,100);
|
|
$validado = ($rnd > 50) ? true : false;
|
|
} else {
|
|
$validado = validarCPF($GLOBALS['digitado']);
|
|
}
|
|
|
|
$tmp = ($validado) ? 'Yes' : 'No';
|
|
$result[] = 'CPF Validado: ' . $tmp;
|
|
logIVRAddFgItem($fgItem,$result);
|
|
|
|
$run_next = true;
|
|
|
|
$cmdTarget = $validado ? 'cpf.true' : 'cpf.false';
|
|
$fgItemChildren = fgItemGetChildrenFrom($fgItem);
|
|
foreach ($fgItemChildren as $fgItemChild) {
|
|
if ($run_next) {
|
|
if ($fgItemChild['cmd'] == $cmdTarget) {
|
|
fgItemRun($fgItemChild);
|
|
$run_next = false;
|
|
}
|
|
}
|
|
}
|
|
|
|
}
|
|
|
|
function fgItemRunCPFCheckFalse($fgItem = array()) {
|
|
|
|
logAdd("<hr>fgItemRunCPFCheckFalse<br><br>");
|
|
logAddFgItem($fgItem);
|
|
logAdd("<br>");
|
|
|
|
logIVRAddFgItemLast($fgItem);
|
|
logIVRAddFgItem($fgItem);
|
|
|
|
fgItemRunNextFrom($fgItem);
|
|
|
|
}
|
|
|
|
function fgItemRunCPFCheckTrue($fgItem = array()) {
|
|
|
|
logAdd("<hr>fgItemRunCPFCheckTrue<br><br>");
|
|
logAddFgItem($fgItem);
|
|
logAdd("<br>");
|
|
|
|
logIVRAddFgItemLast($fgItem);
|
|
logIVRAddFgItem($fgItem);
|
|
|
|
fgItemRunNextFrom($fgItem);
|
|
|
|
}
|
|
|
|
function fgItemRunDialdigit($fgItem = array()) {
|
|
|
|
logAdd("<hr>fgItemRunDialdigit<br><br>");
|
|
logAddFgItem($fgItem);
|
|
logAdd("<br>");
|
|
|
|
logIVRAddFgItemLast($fgItem);
|
|
|
|
$result = array();
|
|
|
|
$run_next = true;
|
|
|
|
$tamanho = strlen($GLOBALS['digitado']);
|
|
if (($tamanho != 3) && ($tamanho != 4)) {
|
|
|
|
$result[] = 'Digito não validado como ramal';
|
|
logIVRAddFgItem($fgItem,$result);
|
|
|
|
fgItemRunNextFrom($fgItem);
|
|
|
|
$run_next = false;
|
|
|
|
}
|
|
|
|
if ($run_next) {
|
|
|
|
$queue = hitpbxGetQueueFromNumeroExterno(array('numero_externo' => $GLOBALS['digitado']));
|
|
if (count($queue) > 0) {
|
|
|
|
$result[] = 'Direcionado pelo "numero externo" para fila id "' . $queue['id'] . '"';
|
|
$response = agiRunQueue(array('id' => $queue['id']));
|
|
$result[] = 'agiRunQueue => ' . $response;
|
|
logIVRAddFgItem($fgItem,$result);
|
|
fgItemRunNextFrom($fgItem);
|
|
$run_next = false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if ($run_next) {
|
|
|
|
$dialcontacts = '';
|
|
|
|
$ramais_secretaria = hitpbxGetRamaisSecretariaFromRamal($GLOBALS['digitado']);
|
|
if (count($ramais_secretaria)) {
|
|
|
|
logAdd("Desvio para ramal scretária<br>");
|
|
foreach ($ramais_secretaria as $ramal) {
|
|
|
|
$result[] = 'Tem ramal secretária ' . $ramal;
|
|
|
|
$cmd = 'GET FULL VARIABLE ${PJSIP_DIAL_CONTACTS('.$ramal.')}';
|
|
$result[] = $cmd;
|
|
$response = agiRunCmd($cmd);
|
|
if ($GLOBALS['isXampp']) {
|
|
$response = '200 result=1 (' . $ramal . ')';
|
|
}
|
|
$result[] = $response;
|
|
$contacts = str_replace('200 result=1 (','',$response);
|
|
$contacts = substr($contacts,0,-1);
|
|
if ($dialcontacts != '') {
|
|
$dialcontacts.= '&';
|
|
}
|
|
$dialcontacts.= $contacts;
|
|
|
|
$cmd = 'GET FULL VARIABLE ${PJSIP_DIAL_CONTACTS(SIP'.$ramal.')}';
|
|
$result[] = $cmd;
|
|
$response = agiRunCmd();
|
|
if ($GLOBALS['isXampp']) {
|
|
$response = '200 result=1 (SIP' . $ramal . ')';
|
|
}
|
|
$result[] = $response;
|
|
$contacts = str_replace('200 result=1 (','',$response);
|
|
$contacts = substr($contacts,0,-1);
|
|
if ($dialcontacts != '') {
|
|
$dialcontacts.= '&';
|
|
}
|
|
$dialcontacts.= $contacts;
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
$cmd = 'GET FULL VARIABLE ${PJSIP_DIAL_CONTACTS('.$GLOBALS['digitado'].')}';
|
|
$result[] = $cmd;
|
|
$response = agiRunCmd($cmd);
|
|
if ($GLOBALS['isXampp']) {
|
|
$response = '200 result=1 (' . $GLOBALS['digitado'] . ')';
|
|
}
|
|
$result[] = $response;
|
|
$contacts = str_replace('200 result=1 (','',$response);
|
|
$contacts = substr($contacts,0,-1);
|
|
if ($dialcontacts != '') {
|
|
$dialcontacts.= '&';
|
|
}
|
|
$dialcontacts.= $contacts;
|
|
|
|
$cmd = 'GET FULL VARIABLE ${PJSIP_DIAL_CONTACTS(SIP'.$GLOBALS['digitado'].')}';
|
|
$result[] = $cmd;
|
|
$response = agiRunCmd($cmd);
|
|
if ($GLOBALS['isXampp']) {
|
|
$response = '200 result=1 (SIP' . $GLOBALS['digitado'] . ')';
|
|
}
|
|
$result[] = $response;
|
|
$contacts = str_replace('200 result=1 (','',$response);
|
|
$contacts = substr($contacts,0,-1);
|
|
if ($dialcontacts != '') {
|
|
$dialcontacts.= '&';
|
|
}
|
|
$dialcontacts.= $contacts;
|
|
|
|
}
|
|
|
|
$cmd = 'EXEC Dial ' . $dialcontacts . ',30,TtU(update_call^'.$GLOBALS['callerid'].'^'.$GLOBALS['digitado'].'^'.$GLOBALS['uniqueid'].') ""';
|
|
$result[] = $cmd;
|
|
$response = agiRunCmd($cmd);
|
|
$result[] = $response;
|
|
|
|
logAdd("numerodiscado: ".$dialcontacts."<br>");
|
|
$GLOBALS['numerodiscado'] = $dialcontacts;
|
|
|
|
$cmd = 'GET VARIABLE DIALSTATUS';
|
|
$result[] = $cmd;
|
|
$response = agiRunCmd($cmd);
|
|
if ($GLOBALS['isXampp']) {
|
|
$rnd = rand(1,100);
|
|
if ($rnd >= 50) {
|
|
$response = '200 result=1 (ANSWER)';
|
|
} else {
|
|
$response = '200 result=1 (NO ANSWER)';
|
|
}
|
|
}
|
|
$result[] = $response;
|
|
$explodido = explode("(",$response);
|
|
if (count($explodido) > 1) {
|
|
$dialstatus = substr($explodido[1],0,-1);
|
|
} else {
|
|
$dialstatus = '';
|
|
}
|
|
|
|
logAdd("dialstatus: ".$dialstatus."<br>");
|
|
$GLOBALS['dialstatus'] = $dialstatus;
|
|
|
|
if ($dialstatus == 'ANSWER') {
|
|
|
|
$result[] = 'DialStatus: ' . $dialstatus;
|
|
logIVRAddFgItem($fgItem,$result);
|
|
|
|
fgItemRunNextFrom($fgItem);
|
|
|
|
} else {
|
|
|
|
$cmd = 'EXEC PLAYBACK /var/lib/asterisk/sounds/pt_BR/exten-unavail ""';
|
|
$result[] = $cmd;
|
|
$response = agiRunCmd($cmd);
|
|
$result[] = $response;
|
|
|
|
$run_next = true;
|
|
|
|
$fgItemChildren = fgItemGetChildrenFrom($fgItem);
|
|
foreach ($fgItemChildren as $fgItemChild) {
|
|
if ($run_next) {
|
|
if ($fgItemChild['cmd'] == 'timeoutwithlimit') {
|
|
logIVRAddFgItem($fgItem,$result);
|
|
fgItemRun($fgItemChild);
|
|
$run_next = false;
|
|
}
|
|
}
|
|
}
|
|
|
|
$fgItemChildren = fgItemGetChildrenFrom($fgItem);
|
|
foreach ($fgItemChildren as $fgItemChild) {
|
|
if ($run_next) {
|
|
if ($fgItemChild['cmd'] == 'timeout') {
|
|
logIVRAddFgItem($fgItem,$result);
|
|
fgItemRun($fgItemChild);
|
|
$run_next = false;
|
|
}
|
|
}
|
|
}
|
|
|
|
$fgItemChildren = fgItemGetChildrenFrom($fgItem);
|
|
foreach ($fgItemChildren as $fgItemChild) {
|
|
if ($run_next) {
|
|
if ($fgItemChild['cmd'] == 'voicemail') {
|
|
logIVRAddFgItem($fgItem,$result);
|
|
fgItemRun($fgItemChild);
|
|
$run_next = false;
|
|
}
|
|
}
|
|
}
|
|
|
|
if ($run_next) {
|
|
$result[] = 'Não achou "timeoutwithlimit", "timeout" ou "voicemail"';
|
|
logIVRAddFgItem($fgItem,$result);
|
|
fgItemRunNextFrom($fgItem);
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
function fgItemRunDialplanCheckvar($fgItem = array()) {
|
|
|
|
logAdd("<hr>fgItemRunDialplanCheckvar<br><br>");
|
|
logAddFgItem($fgItem);
|
|
logAdd("<br>");
|
|
|
|
logIVRAddFgItemLast($fgItem);
|
|
|
|
$result = array();
|
|
|
|
$nomatch = true;
|
|
$run_next = true;
|
|
$fgItemMaster = fgItemGetMasterFrom($fgItem);
|
|
$fgItemChildren = fgItemGetChildrenFrom($fgItemMaster);
|
|
foreach ($fgItemChildren as $fgItemChild) {
|
|
if (($run_next) && (fgItemIsDialplanCheckvar($fgItemChild))) {
|
|
$varname = (isset($fgItemChild['defaultvalues']['varname'])) ? $fgItemChild['defaultvalues']['varname'] : '';
|
|
$varvalue = (isset($fgItemChild['defaultvalues']['varvalue'])) ? $fgItemChild['defaultvalues']['varvalue'] : '';
|
|
if (isset($fgItemChild['value2'])) {
|
|
if ($fgItemChild['value2'] != '') {
|
|
$varname = $fgItemChild['value2'];
|
|
}
|
|
}
|
|
if (isset($fgItemChild['value'])) {
|
|
if ($fgItemChild['value'] != '') {
|
|
$varvalue = $fgItemChild['value'];
|
|
}
|
|
}
|
|
if (isset($fgItemChild['varname'])) {
|
|
$varname = $fgItemChild['varname'];
|
|
}
|
|
if (isset($fgItemChild['varvalue'])) {
|
|
$varvalue = $fgItemChild['varvalue'];
|
|
}
|
|
$result[] = 'GET VARIABLE ' . strtoupper($varname);
|
|
$response = agiVarGet(strtoupper($varname));
|
|
if ($GLOBALS['isXampp']) {
|
|
$rnd = rand(1,100);
|
|
if ($rnd >= 50) {
|
|
$response = 'ABC';
|
|
} else {
|
|
$response = 'XYZ';
|
|
}
|
|
}
|
|
$result[] = $response;
|
|
logAdd("<hr>");
|
|
logAdd("varvalue: ".$varvalue." => ");
|
|
logAdd("agiVarGet(".strtoupper($varname)."): ".$response."<br>");
|
|
if ($response == $varvalue) {
|
|
|
|
logAdd("<hr>fgItemRunDialplanCheckvar<br><br>");
|
|
logAddFgItem($fgItem);
|
|
logAdd("<br>");
|
|
|
|
$result[] = 'Is Match: Yes';
|
|
logIVRAddFgItem($fgItem,$result);
|
|
|
|
fgItemRunNextFrom($fgItemChild);
|
|
$nomatch = false;
|
|
$run_next = false;
|
|
|
|
} else {
|
|
|
|
$result[] = 'Is Match: No';
|
|
|
|
}
|
|
}
|
|
}
|
|
if ($nomatch) {
|
|
$result[] = 'No Match';
|
|
$run_next = true;
|
|
$fgItemChildren = fgItemGetChildrenFrom($fgItemMaster);
|
|
foreach ($fgItemChildren as $fgItemChild) {
|
|
if ($run_next) {
|
|
if ($fgItemChild['cmd'] == 'nomatch') {
|
|
logIVRAddFgItem($fgItem,$result);
|
|
fgItemRun($fgItemChild);
|
|
$run_next = false;
|
|
}
|
|
}
|
|
}
|
|
if ($run_next) {
|
|
$result[] = 'No found next icon "nomatch"';
|
|
logIVRAddFgItem($fgItem,$result);
|
|
}
|
|
}
|
|
|
|
}
|
|
|
|
function fgItemRunDialExtension($fgItem = array()) {
|
|
|
|
logAdd("<hr>fgItemRunDialExtension<br><br>");
|
|
logAddFgItem($fgItem);
|
|
logAdd("<br>");
|
|
|
|
logIVRAddFgItemLast($fgItem);
|
|
|
|
$result = array();
|
|
|
|
$dialstatus = agiRunDialRamal($fgItem['value']);
|
|
|
|
if ($GLOBALS['isXampp']) {
|
|
$GLOBALS['numerodiscado'] = $fgItem['value'];
|
|
$rnd = rand(1,100);
|
|
if ($rnd >= 50) {
|
|
$dialstatus = 'ANSWER';
|
|
} else {
|
|
$dialstatus = 'NO ANSWER';
|
|
}
|
|
}
|
|
|
|
$result[] = 'DialStatus: ' . $dialstatus;
|
|
logAdd("dialstatus: ".$dialstatus."<br>");
|
|
|
|
if ($dialstatus != 'ANSWER') {
|
|
|
|
$result[] = 'DialStatu not equal "ANSWER"';
|
|
|
|
$run_next = true;
|
|
|
|
$fgItemChildren = fgItemGetChildrenFrom($fgItem);
|
|
foreach ($fgItemChildren as $fgItemChild) {
|
|
if ($run_next) {
|
|
if ($fgItemChild['cmd'] == 'timeoutwithlimit') {
|
|
logIVRAddFgItem($fgItem,$result);
|
|
fgItemRun($fgItemChild);
|
|
$run_next = false;
|
|
}
|
|
}
|
|
}
|
|
|
|
$fgItemChildren = fgItemGetChildrenFrom($fgItem);
|
|
foreach ($fgItemChildren as $fgItemChild) {
|
|
if ($run_next) {
|
|
if ($fgItemChild['cmd'] == 'timeout') {
|
|
logIVRAddFgItem($fgItem,$result);
|
|
fgItemRun($fgItemChild);
|
|
$run_next = false;
|
|
}
|
|
}
|
|
}
|
|
|
|
$fgItemChildren = fgItemGetChildrenFrom($fgItem);
|
|
foreach ($fgItemChildren as $fgItemChild) {
|
|
if ($run_next) {
|
|
if ($fgItemChild['cmd'] == 'voicemail') {
|
|
logIVRAddFgItem($fgItem,$result);
|
|
fgItemRun($fgItemChild);
|
|
$run_next = false;
|
|
}
|
|
}
|
|
}
|
|
|
|
if ($run_next) {
|
|
$result[] = 'No found icon "timeoutwithlimit", "timeout" or "voicemail"';
|
|
logIVRAddFgItem($fgItem,$result);
|
|
fgItemRunNextFrom($fgItem);
|
|
}
|
|
|
|
} else {
|
|
|
|
logIVRAddFgItem($fgItem,$result);
|
|
fgItemRunNextFrom($fgItem);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
function fgItemRunDialGroupExtension($fgItem = array()) {
|
|
|
|
logAdd("<hr>fgItemRunDialGroupExtension<br><br>");
|
|
logAddFgItem($fgItem);
|
|
logAdd("<br>");
|
|
|
|
logIVRAddFgItemLast($fgItem);
|
|
|
|
$result = array();
|
|
|
|
$dialstatus = agiRunDialRamalGrupo($fgItem['value']);
|
|
|
|
if ($GLOBALS['isXampp']) {
|
|
$GLOBALS['numerodiscado'] = '1111';
|
|
$rnd = rand(1,100);
|
|
if ($rnd >= 50) {
|
|
$dialstatus = 'ANSWER';
|
|
} else {
|
|
$dialstatus = 'NO ANSWER';
|
|
}
|
|
}
|
|
|
|
$result[] = 'DialStatus: ' .$dialstatus;
|
|
logAdd("dialstatus: ".$dialstatus."<br>");
|
|
|
|
if ($dialstatus != 'ANSWER') {
|
|
|
|
$result[] = 'DialStatu not equal "ANSWER"';
|
|
|
|
$run_next = true;
|
|
|
|
$fgItemChildren = fgItemGetChildrenFrom($fgItem);
|
|
foreach ($fgItemChildren as $fgItemChild) {
|
|
if ($run_next) {
|
|
if ($fgItemChild['cmd'] == 'timeoutwithlimit') {
|
|
logIVRAddFgItem($fgItem,$result);
|
|
fgItemRun($fgItemChild);
|
|
$run_next = false;
|
|
}
|
|
}
|
|
}
|
|
|
|
$fgItemChildren = fgItemGetChildrenFrom($fgItem);
|
|
foreach ($fgItemChildren as $fgItemChild) {
|
|
if ($run_next) {
|
|
if ($fgItemChild['cmd'] == 'timeout') {
|
|
logIVRAddFgItem($fgItem,$result);
|
|
fgItemRun($fgItemChild);
|
|
$run_next = false;
|
|
}
|
|
}
|
|
}
|
|
|
|
$fgItemChildren = fgItemGetChildrenFrom($fgItem);
|
|
foreach ($fgItemChildren as $fgItemChild) {
|
|
if ($run_next) {
|
|
if ($fgItemChild['cmd'] == 'voicemail') {
|
|
logIVRAddFgItem($fgItem,$result);
|
|
fgItemRun($fgItemChild);
|
|
$run_next = false;
|
|
}
|
|
}
|
|
}
|
|
|
|
if ($run_next) {
|
|
|
|
$result[] = 'No found icon "timeoutwithlimit", "timeout" or "voicemail"';
|
|
logIVRAddFgItem($fgItem,$result);
|
|
|
|
fgItemRunNextFrom($fgItem);
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
logIVRAddFgItem($fgItem,$result);
|
|
fgItemRunNextFrom($fgItem);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
function fgItemRunDialplanGosub($fgItem = array()) {
|
|
|
|
logAdd("<hr>fgItemRunDialplanGosub<br><br>");
|
|
logAddFgItem($fgItem);
|
|
logAdd("<br>");
|
|
|
|
logIVRAddFgItemLast($fgItem);
|
|
|
|
$result = array();
|
|
|
|
$ctxname = isset($fgItem['defaultvalues']['ctxname']) ? $fgItem['defaultvalues']['ctxname'] : '';
|
|
$ctxname = isset($fgItem['ctxname']) ? $fgItem['ctxname'] : $ctxname;
|
|
|
|
$ctxexten = isset($fgItem['defaultvalues']['ctxexten']) ? $fgItem['defaultvalues']['ctxexten'] : '1001';
|
|
$ctxexten = isset($fgItem['ctxexten']) ? $fgItem['ctxexten'] : $ctxexten;
|
|
if (isset($fgItem['value'])) {
|
|
if ($fgItem['value'] != '') {
|
|
$ctxexten = $fgItem['value'];
|
|
}
|
|
}
|
|
|
|
if (($ctxname != '') && ($ctxexten != '')) {
|
|
|
|
$cmd = 'GOSUB ' . $ctxname . ' ' . $ctxexten . ' 1';
|
|
$result[] = $cmd;
|
|
$response = agiRunCmd($cmd);
|
|
$result[] = $response;
|
|
|
|
} else {
|
|
|
|
$result[] = 'Empty ctxname and(or) ctxexten';
|
|
|
|
}
|
|
|
|
logIVRAddFgItem($fgItem,$result);
|
|
|
|
fgItemRunNextFrom($fgItem);
|
|
|
|
}
|
|
|
|
function fgItemRunDialplanSetvar($fgItem = array()) {
|
|
|
|
logAdd("<hr>fgItemRunDialplanSetvar<br><br>");
|
|
logAddFgItem($fgItem);
|
|
logAdd("<br>");
|
|
|
|
logIVRAddFgItemLast($fgItem);
|
|
|
|
$result = array();
|
|
|
|
$varnameget = isset($fgItem['defaultvalues']['varnameget']) ? $fgItem['defaultvalues']['varnameget'] : 'AGIDIGITADO';
|
|
$varnameget = isset($fgItem['value2']) ? $fgItem['value2'] : $varnameget;
|
|
$varnameget = isset($fgItem['varnameget']) ? $fgItem['varnameget'] : $varnameget;
|
|
|
|
$varnameset = isset($fgItem['defaultvalues']['varname']) ? $fgItem['defaultvalues']['varname'] : '';
|
|
$varnameset = isset($fgItem['defaultvalues']['varnameset']) ? $fgItem['defaultvalues']['varnameset'] : $varnameset;
|
|
$varnameset = isset($fgItem['value3']) ? $fgItem['value3'] : $varnameset;
|
|
$varnameset = isset($fgItem['varnameset']) ? $fgItem['varnameset'] : $varnameset;
|
|
|
|
$varvalue = isset($fgItem['value']) ? $fgItem['value'] : '';
|
|
if ($varvalue == '') {
|
|
if ($varnameget != '') {
|
|
$result[] = 'GET VARIABLE ' . strtoupper($varnameget);
|
|
$varvalue = agiVarGet(strtoupper($varnameget));
|
|
if ($GLOBALS['isXampp']) {
|
|
$varvalue = 'ABC';
|
|
}
|
|
$result[] = $varvalue;
|
|
} else {
|
|
$result[] = 'Empty varnameget';
|
|
}
|
|
} else {
|
|
$result[] = 'Empty varvalue';
|
|
}
|
|
|
|
if ($varvalue != '') {
|
|
$result[] = 'SET VARIABLE ' . strtoupper($varname) . ' ' . $varvalue;
|
|
$response = agiVarSet(strtoupper($varnameset),$varvalue);
|
|
$result[] = $response;
|
|
} else {
|
|
$result[] = 'Empty varvalue';
|
|
$cmd = 'SET VARIABLE ' . strtoupper($varname) . ' ""';
|
|
$result[] = $cmd;
|
|
$response = agiRunCmd($cmd);
|
|
$result[] = $response;
|
|
}
|
|
|
|
logIVRAddFgItem($fgItem,$result);
|
|
|
|
fgItemRunNextFrom($fgItem);
|
|
|
|
}
|
|
|
|
function fgItemRunDigit($fgItem = array()) {
|
|
|
|
logAdd('<hr>fgItemRunDigit<br><br>');
|
|
logAddFgItem($fgItem);
|
|
logAdd("<br>");
|
|
|
|
logIVRAddFgItemLast($fgItem);
|
|
|
|
$result = array();
|
|
|
|
// queue_log
|
|
// 1353461660|1353461627.33271|NONE|NONE|INFO|IVRAPPEND|1|ivr-2
|
|
// QueueLog(queuename,uniqueid,agent,event,[additionalinfo])
|
|
// $cmd = 'EXEC QUEUELOG NONE,' . $GLOBALS['uniqueid'] . ',NONE,NONE,INFO|IVRAPPEND|' . $fgItem['value'] . '|' . $GLOBALS['fgId'];
|
|
// $result[] = $cmd;
|
|
// $response = agiRunCmd($cmd);
|
|
// $result[] = $response;
|
|
|
|
/*
|
|
$cmd = 'EXEC QUEUELOG NONE,' . $GLOBALS['uniqueid'] . ',NONE,NONE,INFO|IVRAPPEND|' . $GLOBALS['digitado'];
|
|
$result[] = $cmd;
|
|
$response = agiRunCmd($cmd);
|
|
$result[] = $response;
|
|
*/
|
|
|
|
/*
|
|
$cmd = 'EXEC QUEUELOG NONE,' . $GLOBALS['uniqueid'] . ',NONE,INFO|IVRAPPEND|' . $GLOBALS['digitado'];
|
|
$result[] = $cmd;
|
|
$response = agiRunCmd($cmd);
|
|
$result[] = $response;
|
|
*/
|
|
// ...
|
|
|
|
logIVRAddFgItem($fgItem,$result);
|
|
|
|
fgItemRunNextFrom($fgItem);
|
|
|
|
}
|
|
|
|
function fgItemRunDigitInvalid($fgItem = array()) {
|
|
|
|
logAdd("<hr>fgItemRunDigitInvalid<br><br>");
|
|
logAddFgItem($fgItem);
|
|
logAdd("<br>");
|
|
|
|
logIVRAddFgItemLast($fgItem);
|
|
logIVRAddFgItem($fgItem);
|
|
|
|
fgItemRunNextFrom($fgItem);
|
|
|
|
}
|
|
|
|
function fgItemRunExpedienteCheck($fgItem = array()) {
|
|
|
|
logAdd("<hr>fgItemRunExpedienteCheck<br><br>");
|
|
logAddFgItem($fgItem);
|
|
logAdd("<br>");
|
|
|
|
logIVRAddFgItemLast($fgItem);
|
|
|
|
$result = array();
|
|
|
|
$arrDay = array(
|
|
'0' => array('dom_inicio','dom_fim'),
|
|
'1' => array('seg_inicio','seg_fim'),
|
|
'2' => array('ter_inicio','ter_fim'),
|
|
'3' => array('qua_inicio','qua_fim'),
|
|
'4' => array('qui_inicio','qui_fim'),
|
|
'5' => array('sex_inicio','sex_fim'),
|
|
'6' => array('sab_inicio','sab_fim'),
|
|
);
|
|
$w = date("w");
|
|
$agora = date("H:i:s");
|
|
$query = "SELECT * FROM tab_expediente ";
|
|
$query.= "WHERE " . $arrDay[$w][0] . " <= '" . $agora . "' AND " . $arrDay[$w][1] . " >= '" . $agora . "' ";
|
|
if (isset($fgItem['value'])) {
|
|
if ($fgItem['value'] != '') {
|
|
$query.= "AND id = '" . mysqli_real_escape_string($GLOBALS['db'],$fgItem['value']) . "'";
|
|
}
|
|
}
|
|
$query_result = mysqli_query($GLOBALS['db'],$query);
|
|
if (mysqli_num_rows($query_result) > 0) {
|
|
$isTrue = true;
|
|
} else {
|
|
$isTrue = false;
|
|
}
|
|
|
|
if ($GLOBALS['isXampp']) {
|
|
$rnd = rand(1,100);
|
|
$isTrue = ($rnd >= 50);
|
|
}
|
|
|
|
if ($isTrue) {
|
|
$result[] = "Is True<br>";
|
|
logAdd("isTrue: Yes<br>");
|
|
} else {
|
|
$result[] = "Is False";
|
|
logAdd("isTrue: No<br>");
|
|
}
|
|
|
|
$run_next = true;
|
|
$fgItemChildren = fgItemGetChildrenFrom($fgItem);
|
|
$cmdTarget = $isTrue ? 'expediente.true' : 'expediente.false';
|
|
foreach ($fgItemChildren as $fgItemChild) {
|
|
if ($run_next) {
|
|
if ($fgItemChild['cmd'] == $cmdTarget) {
|
|
logIVRAddFgItem($fgItem,$result);
|
|
fgItemRun($fgItemChild);
|
|
$run_next = false;
|
|
}
|
|
}
|
|
}
|
|
|
|
if ($run_next) {
|
|
$result[] = 'Not found next icon "expediente.true" or "expediente.false"';
|
|
logIVRAddFgItem($fgItem,$result);
|
|
}
|
|
|
|
}
|
|
|
|
function fgItemRunExpedienteFalse($fgItem = array()) {
|
|
|
|
logAdd("<hr>fgItemRunExpedienteFalse<br><br>");
|
|
logAddFgItem($fgItem);
|
|
logAdd("<br>");
|
|
|
|
logIVRAddFgItemLast($fgItem);
|
|
logIVRAddFgItem($fgItem);
|
|
|
|
fgItemRunNextFrom($fgItem);
|
|
|
|
}
|
|
|
|
function fgItemRunExpedienteTrue($fgItem = array()) {
|
|
|
|
logAdd("<hr>fgItemRunExpedienteTrue<br><br>");
|
|
logAddFgItem($fgItem);
|
|
logAdd("<br>");
|
|
|
|
logIVRAddFgItemLast($fgItem);
|
|
logIVRAddFgItem($fgItem);
|
|
|
|
fgItemRunNextFrom($fgItem);
|
|
|
|
}
|
|
|
|
function fgItemRunFeriadoCheck($fgItem = array()) {
|
|
|
|
logAdd("<hr>fgItemRunFeriadoCheck<br><br>");
|
|
logAddFgItem($fgItem);
|
|
logAdd("<br>");
|
|
|
|
logIVRAddFgItemLast($fgItem);
|
|
|
|
$result = array();
|
|
|
|
$hojeDia = date("d");
|
|
$hojeMes = date("m");
|
|
$query = "SELECT * FROM tab_feriado WHERE mes = '".$hojeMes."' AND dia = '".$hojeDia."'";
|
|
$query_result = mysqli_query($GLOBALS['db'],$query);
|
|
$isTrue = (mysqli_num_rows($query_result) > 0);
|
|
|
|
if ($GLOBALS['isXampp']) {
|
|
$rnd = rand(1,100);
|
|
$isTrue = ($rnd >= 50);
|
|
}
|
|
|
|
if ($isTrue) {
|
|
$result[] = 'Is True';
|
|
logAdd("isTrue: Yes<br>");
|
|
} else {
|
|
$result[] = 'Is False';
|
|
logAdd("isTrue: No<br>");
|
|
}
|
|
|
|
$run_next = true;
|
|
$fgItemChildren = fgItemGetChildrenFrom($fgItem);
|
|
$cmdTarget = $isTrue ? 'feriado.true' : 'feriado.false';
|
|
foreach ($fgItemChildren as $fgItemChild) {
|
|
if ($run_next) {
|
|
if ($fgItemChild['cmd'] == $cmdTarget) {
|
|
logIVRAddFgItem($fgItem,$result);
|
|
fgItemRun($fgItemChild);
|
|
$run_next = false;
|
|
}
|
|
}
|
|
}
|
|
|
|
if ($run_next) {
|
|
$result[] = 'Not found next icon "feriado.true" "feriado.false"';
|
|
logIVRAddFgItem($fgItem,$result);
|
|
}
|
|
|
|
}
|
|
|
|
function fgItemRunFeriadoFalse($fgItem = array()) {
|
|
|
|
logAdd("<hr>fgItemRunFeriadoFalse<br><br>");
|
|
logAddFgItem($fgItem);
|
|
logAdd("<br>");
|
|
|
|
logIVRAddFgItemLast($fgItem);
|
|
logIVRAddFgItem($fgItem);
|
|
|
|
fgItemRunNextFrom($fgItem);
|
|
|
|
}
|
|
|
|
function fgItemRunFeriadoTrue($fgItem = array()) {
|
|
|
|
logAdd("<hr>fgItemRunFeriadoTrue<br><br>");
|
|
logAddFgItem($fgItem);
|
|
logAdd("<br>");
|
|
|
|
logIVRAddFgItemLast($fgItem);
|
|
logIVRAddFgItem($fgItem);
|
|
|
|
fgItemRunNextFrom($fgItem);
|
|
|
|
}
|
|
|
|
function fgItemRunIVRRedirect($fgItem = array()) {
|
|
|
|
logAdd("<hr>fgItemRunIVRRedirect<br><br>");
|
|
logAddFgItem($fgItem);
|
|
logAdd("<br>");
|
|
|
|
logIVRAddFgItemLast($fgItem);
|
|
|
|
$result = array();
|
|
|
|
$fgId = $fgItem['value'];
|
|
if ($fgId != '') {
|
|
|
|
if ($GLOBALS['isXampp']) {
|
|
$target = "dial" . DIRECTORY_SEPARATOR . $fgId . '.json';
|
|
} else {
|
|
$target = '/var/www/html/fluxograma/data-json/' . $fgId . '.json';
|
|
}
|
|
logAdd("target: ".$target."<br>");
|
|
if (file_exists($target)) {
|
|
|
|
logAdd("target exists<br>");
|
|
$GLOBALS['fgItemStart'] = array();
|
|
$GLOBALS['fgItens'] = array();
|
|
$itens = file_get_contents($target);
|
|
$itens = json_decode($itens,true);
|
|
foreach ($itens as $item) {
|
|
$GLOBALS['fgItens'][$item['id']] = $item;
|
|
if ($item['cmd'] == 'start') {
|
|
$GLOBALS['fgItemStart'] = $item;
|
|
}
|
|
}
|
|
unset($itens);
|
|
if (count($GLOBALS['fgItemStart']) > 0) {
|
|
logIVRAddFgItem($fgItem,$result);
|
|
fgItemRunNextFrom($GLOBALS['fgItemStart']);
|
|
} else {
|
|
$result[] = 'Icon "start" not found in ' . $target;
|
|
logIVRAddFgItem($fgItem,$result);
|
|
}
|
|
|
|
} else {
|
|
|
|
logAdd("target no exists<br>");
|
|
$result[] = 'Target not found: ' . $target;
|
|
logIVRAddFgItem($fgItem,$result);
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
$result[] = 'Empty value (DID) to redirect';
|
|
logIVRAddFgItem($fgItem,$result);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
function fgItemRunNoMatch($fgItem = array()) {
|
|
|
|
logAdd("<hr>fgItemRunNoMatch<br><br>");
|
|
logAddFgItem($fgItem);
|
|
logAdd("<br>");
|
|
|
|
logIVRAddFgItemLast($fgItem);
|
|
logIVRAddFgItem($fgItem);
|
|
|
|
fgItemRunNextFrom($fgItem);
|
|
|
|
}
|
|
|
|
function fgItemRunPesqSat($fgItem = array()) {
|
|
|
|
logAdd("<hr>fgItemRunPesqSat ???<br><br>");
|
|
logAddFgItem($fgItem);
|
|
logAdd("<br>");
|
|
|
|
logIVRAddFgItemLast($fgItem);
|
|
|
|
$result = array();
|
|
|
|
$id_pesqsat = is_numeric($fgItem['value']) ? $fgItem['value'] : '';
|
|
$audiofile = '';
|
|
|
|
if ($GLOBALS['isXampp']) {
|
|
|
|
$audiofile = 'pesquisa';
|
|
|
|
} else {
|
|
|
|
$query = "INSERT INTO tab_pesqsat_nota SET ";
|
|
$query.= "id_pesqsat = '" . mysqli_real_escape_string($GLOBALS['db'],$id_pesqsat) . "', ";
|
|
$query.= "uniqueid = '" . mysqli_real_escape_string($GLOBALS['db'],$GLOBALS['uniqueid']) . "', ";
|
|
$query.= "nota = '100'";
|
|
$query_result = mysqli_query($GLOBALS['db'],$query);
|
|
|
|
$query = "SELECT audio FROM tab_pesqsat WHERE id = '" . mysqli_real_escape_string($GLOBALS['db'],$id_pesqsat) . "'";
|
|
$query_result = mysqli_query($GLOBALS['db'],$query);
|
|
if (mysqli_num_rows($query_result) > 0) {
|
|
$resultLinha = mysqli_fetch_assoc($query_result);
|
|
$explodido = explode('.',$resultLinha['audio']);
|
|
$audiofile = $explodido[0];
|
|
}
|
|
|
|
}
|
|
|
|
if ($audiofile != '') {
|
|
|
|
$digito_timeout = '3000'; // milisegundos
|
|
$digito_qtd = '2';
|
|
|
|
$GLOBALS['digitado'] = '';
|
|
|
|
$cmd = 'SET VARIABLE AGIDIGITADO ""';
|
|
$result[] = $cmd;
|
|
$response = agiRunCmd($cmd);
|
|
$result[] = $response;
|
|
|
|
$cmd = 'GET DATA /var/lib/asterisk/sounds/cliente/'.$audiofile.' '.$digito_timeout.' '.$digito_qtd;
|
|
$result[] = $cmd;
|
|
$response = agiRunCmd($cmd);
|
|
$result[] = $response;
|
|
|
|
/*
|
|
if (strpos($response,'= (timeout)') === false) {
|
|
$explodido = explode('=',$response);
|
|
if (isset($explodido[1])) {
|
|
$GLOBALS['digitado'] = $explodido[1];
|
|
}
|
|
}
|
|
*/
|
|
// 200 result= (timeout)
|
|
// 200 result=4 (timeout)
|
|
if (strpos($response,'= (timeout)') === false) {
|
|
if (strpos($response,'(timeout)') !== false) {
|
|
$response = trim(str_replace('(timeout)','',$response));
|
|
}
|
|
$explodido = explode('=',$response);
|
|
$GLOBALS['digitado'] = $explodido[1];
|
|
}
|
|
|
|
$result[] = 'Digitado: ' . $GLOBALS['digitado'];
|
|
|
|
$run_next = true;
|
|
|
|
if ($GLOBALS['digitado'] == '') {
|
|
|
|
$fgItemChildren = fgItemGetChildrenFrom($fgItem);
|
|
foreach ($fgItemChildren as $fgItemChild) {
|
|
if ($run_next) {
|
|
if ($fgItemChild['cmd'] == 'timeoutwithlimit') {
|
|
logIVRAddFgItem($fgItem,$result);
|
|
fgItemRun($fgItemChild);
|
|
$run_next = false;
|
|
}
|
|
}
|
|
}
|
|
|
|
$fgItemChildren = fgItemGetChildrenFrom($fgItem);
|
|
foreach ($fgItemChildren as $fgItemChild) {
|
|
if ($run_next) {
|
|
if ($fgItemChild['cmd'] == 'timeout') {
|
|
logIVRAddFgItem($fgItem,$result);
|
|
fgItemRun($fgItemChild);
|
|
$run_next = false;
|
|
}
|
|
}
|
|
}
|
|
|
|
if ($run_next) {
|
|
$result[] = 'Not found next icon "timeoutwithlimit" or "timeout"';
|
|
logIVRAddFgItem($fgItem,$result);
|
|
}
|
|
|
|
$run_next = false;
|
|
|
|
}
|
|
|
|
if ($run_next) {
|
|
|
|
if (!$GLOBALS['isXampp']) {
|
|
$query = "UPDATE tab_pesqsat_nota SET ";
|
|
$query.= "nota = '" . mysqli_real_escape_string($GLOBALS['db'],$GLOBALS['digitado']) . "' ";
|
|
$query.= "WHERE id_pesqsat = '" . mysqli_real_escape_string($GLOBALS['db'],$id_pesqsat) . "' ";
|
|
$query.= "AND uniqueid = '" . mysqli_real_escape_string($GLOBALS['db'],$GLOBALS['uniqueid']) . "'";
|
|
$query_result = mysqli_query($GLOBALS['db'],$query);
|
|
}
|
|
logIVRAddFgItem($fgItem,$result);
|
|
fgItemRunNextFrom($fgItem);
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
$result[] = 'Empty audiofile';
|
|
logIVRAddFgItem($fgItem,$result);
|
|
fgItemRunNextFrom($fgItem);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
function fgItemRunPlayaudio($fgItem = array()) {
|
|
|
|
logAdd("<hr>fgItemRunPlayaudio<br><br>");
|
|
logAddFgItem($fgItem);
|
|
logAdd("<br>");
|
|
|
|
logIVRAddFgItemLast($fgItem);
|
|
|
|
$result = array();
|
|
|
|
$GLOBALS['digitado'] = '';
|
|
|
|
$cmd = 'SET VARIABLE AGIDIGITADO ""';
|
|
$result[] = $cmd;
|
|
$response = agiRunCmd($cmd);
|
|
$result[] = $response;
|
|
|
|
if ($GLOBALS['isXampp']) {
|
|
|
|
$rnd = rand(1,100);
|
|
if ($rnd >= 60) {
|
|
$GLOBALS['digitado'] = rand(0,9);
|
|
} else if ($rnd >= 40) {
|
|
$GLOBALS['digitado'] = 'A';
|
|
} else if ($rnd >= 20) {
|
|
$GLOBALS['digitado'] = '1001';
|
|
} else {
|
|
$GLOBALS['digitado'] = '';
|
|
}
|
|
|
|
} else {
|
|
|
|
// Nome do arquivo sem a extensão
|
|
$explodido = explode('.',$fgItem['value']);
|
|
$audiofile = $explodido[0];
|
|
|
|
$digito_timeout = isset($fgItem['value2']) ? trim($fgItem['value2']) : 2;
|
|
$digito_timeout = !empty($digito_timeout) ? $digito_timeout : 0;
|
|
$digito_timeout = $digito_timeout * 1000; // segundos para milisegundos
|
|
|
|
$digito_qtd = isset($fgItem['value3']) ? $fgItem['value3'] : 1;
|
|
$digito_qtd = (!empty($digito_qtd)) ? $digito_qtd : '1';
|
|
|
|
$digito_say = isset($fgItem['value4']) ? $fgItem['value4'] : 'false';
|
|
|
|
$cmd = 'GET DATA /var/lib/asterisk/sounds/cliente/'.$audiofile.' '.$digito_timeout.' '.$digito_qtd;
|
|
$result[] = $cmd;
|
|
$response = agiRunCmd($cmd);
|
|
$result[] = $response;
|
|
|
|
// 200 result= (timeout)
|
|
// 200 result=4 (timeout)
|
|
if (strpos($response,'= (timeout)') === false) {
|
|
if (strpos($response,'(timeout)') !== false) {
|
|
$response = trim(str_replace('(timeout)','',$response));
|
|
}
|
|
$explodido = explode('=',$response);
|
|
$GLOBALS['digitado'] = $explodido[1];
|
|
}
|
|
|
|
}
|
|
|
|
logAdd("digitado: " . $GLOBALS['digitado'] . "<br>");
|
|
$result[] = "Digitado: " . $GLOBALS['digitado'];
|
|
|
|
$run_next = true;
|
|
|
|
if ($GLOBALS['digitado'] == '') {
|
|
|
|
$fgItemChildren = fgItemGetChildrenFrom($fgItem);
|
|
foreach ($fgItemChildren as $fgItemChild) {
|
|
if ($run_next) {
|
|
if ($fgItemChild['cmd'] == 'timeoutwithlimit') {
|
|
logIVRAddFgItem($fgItem,$result);
|
|
fgItemRun($fgItemChild);
|
|
$run_next = false;
|
|
}
|
|
}
|
|
}
|
|
|
|
$fgItemChildren = fgItemGetChildrenFrom($fgItem);
|
|
foreach ($fgItemChildren as $fgItemChild) {
|
|
if ($run_next) {
|
|
if ($fgItemChild['cmd'] == 'timeout') {
|
|
logIVRAddFgItem($fgItem,$result);
|
|
fgItemRun($fgItemChild);
|
|
$run_next = false;
|
|
}
|
|
}
|
|
}
|
|
|
|
if ($run_next) {
|
|
$result[] = 'Not found next icon "timeoutwithlimit" or "timeout"';
|
|
$result[] = 'Goto next icon if exists...';
|
|
logIVRAddFgItem($fgItem,$result);
|
|
fgItemRunNextFrom($fgItem);
|
|
}
|
|
|
|
$run_next = false;
|
|
|
|
} else {
|
|
|
|
$cmd = 'SET VARIABLE AGIDIGITADO ' . $GLOBALS['digitado'];
|
|
$result[] = $cmd;
|
|
$response = agiRunCmd($cmd);
|
|
$result[] = $response;
|
|
|
|
$cmd = 'EXEC QUEUELOG NONE,' . $GLOBALS['uniqueid'] . ',NONE,INFO|IVRAPPEND|->' . $GLOBALS['digitado'];
|
|
$response = agiRunCmd($cmd);
|
|
|
|
}
|
|
|
|
if ($run_next) {
|
|
$fgItemChildren = fgItemGetChildrenFrom($fgItem);
|
|
foreach ($fgItemChildren as $fgItemChild) {
|
|
if ($run_next) {
|
|
if ($fgItemChild['cmd'] == 'digit') {
|
|
if ($fgItemChild['value'] == $GLOBALS['digitado']) {
|
|
logIVRAddFgItem($fgItem,$result);
|
|
fgItemRun($fgItemChild);
|
|
$run_next = false;
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
if ($run_next) {
|
|
$tamanho = strlen($GLOBALS['digitado']);
|
|
if (($tamanho >= 3) && ($tamanho <= 4)) {
|
|
$fgItemChildren = fgItemGetChildrenFrom($fgItem);
|
|
foreach ($fgItemChildren as $fgItemChild) {
|
|
if ($run_next) {
|
|
if ($fgItemChild['cmd'] == 'dialdigit') {
|
|
logIVRAddFgItem($fgItem,$result);
|
|
fgItemRun($fgItemChild);
|
|
$run_next = false;
|
|
}
|
|
}
|
|
}
|
|
} else {
|
|
$result[] = 'Digitado não validado como ramal para usar "dialdigit"';
|
|
}
|
|
}
|
|
|
|
if ($run_next) {
|
|
$fgItemChildren = fgItemGetChildrenFrom($fgItem);
|
|
foreach ($fgItemChildren as $fgItemChild) {
|
|
if ($run_next) {
|
|
if ($fgItemChild['cmd'] == 'digitinvalid') {
|
|
logIVRAddFgItem($fgItem,$result);
|
|
fgItemRun($fgItemChild);
|
|
$run_next = false;
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
if ($run_next) {
|
|
$result[] = 'Not found next icon "digit" or "dialdigit" or "digitinvalid"';
|
|
logIVRAddFgItem($fgItem,$result);
|
|
fgItemRunNextFrom($fgItem);
|
|
}
|
|
|
|
}
|
|
|
|
function fgItemRunQueue($fgItem = array()) {
|
|
|
|
logAdd("<hr>fgItemRunQueue<br><br>");
|
|
logAddFgItem($fgItem);
|
|
logAdd("<br>");
|
|
|
|
logIVRAddFgItemLast($fgItem);
|
|
|
|
$result = array();
|
|
|
|
$timeout = isset($fgItem['value2']) ? $fgItem['value2'] : '';
|
|
$timeout = is_numeric($timeout) ? $timeout : '';
|
|
|
|
/*
|
|
$id_queue_callback = isset($fgItem['value2']) ? $fgItem['value2'] : '';
|
|
$cmd = 'SET VARIABLE DIDCALLBACKQUEUEID ' . $id_queue_callback;
|
|
$result[] = $cmd;
|
|
$response = agiRunCmd($cmd);
|
|
$result[] = $response;
|
|
*/
|
|
|
|
$run_next = true;
|
|
|
|
$result[] = 'Queue id: ' . $fgItem['value'] . ' timeout: ' . $timeout;
|
|
|
|
// same => n,QueueLog(Q21,${UNIQUEID},NONE,INFO,IVRSTART)
|
|
// same => n,QueueLog(Q21,${UNIQUEID},NONE,INFO,IVRAPPEND|DDR-FILA-INSUMOS-TUPA)
|
|
|
|
/*
|
|
$cmd = 'EXEC QUEUELOG Q'.$fgItem['value'].',' . $GLOBALS['uniqueid'] . ',NONE,NONE,INFO|IVRAPPEND|' . $GLOBALS['digitado'];
|
|
$result[] = $cmd;
|
|
$response = agiRunCmd($cmd);
|
|
$result[] = $response;
|
|
*/
|
|
|
|
/*
|
|
$cmd = 'EXEC QUEUELOG Q'.$fgItem['value'].',' . $GLOBALS['uniqueid'] . ',NONE,INFO|IVRAPPEND|' . $GLOBALS['digitado'];
|
|
$result[] = $cmd;
|
|
$response = agiRunCmd($cmd);
|
|
$result[] = $response;
|
|
*/
|
|
|
|
// ...
|
|
|
|
$response = agiRunQueue(array('id' => $fgItem['value'],'timeout' => $timeout));
|
|
$result[] = $response;
|
|
if ($response == 'stopivr') {
|
|
$run_next = false;
|
|
}
|
|
|
|
if (($run_next) && ($response == 'timeout')) {
|
|
|
|
$fgItemChildren = fgItemGetChildrenFrom($fgItem);
|
|
foreach ($fgItemChildren as $fgItemChild) {
|
|
if ($run_next) {
|
|
if ($fgItemChild['cmd'] == 'timeoutwithlimit') {
|
|
logIVRAddFgItem($fgItem,$result);
|
|
fgItemRun($fgItemChild);
|
|
$run_next = false;
|
|
}
|
|
}
|
|
}
|
|
|
|
$fgItemChildren = fgItemGetChildrenFrom($fgItem);
|
|
foreach ($fgItemChildren as $fgItemChild) {
|
|
if ($run_next) {
|
|
if ($fgItemChild['cmd'] == 'timeout') {
|
|
logIVRAddFgItem($fgItem,$result);
|
|
fgItemRun($fgItemChild);
|
|
$run_next = false;
|
|
}
|
|
}
|
|
}
|
|
|
|
if ($run_next) {
|
|
$result[] = 'Not found next icon "timeoutwithlimit" or "timeout"';
|
|
logIVRAddFgItem($fgItem,$result);
|
|
}
|
|
|
|
$run_next = false;
|
|
|
|
}
|
|
|
|
if ($run_next) {
|
|
logIVRAddFgItem($fgItem,$result);
|
|
fgItemRunNextFrom($fgItem);
|
|
}
|
|
|
|
}
|
|
|
|
function fgItemRunQueueWaitingCount($fgItem = array()) {
|
|
|
|
logAdd("<hr>fgItemRunQueueWaitingCount<br><br>");
|
|
logAddFgItem($fgItem);
|
|
logAdd("<br>");
|
|
|
|
logIVRAddFgItemLast($fgItem);
|
|
|
|
$result = array();
|
|
|
|
$id_queue = is_numeric($fgItem['value']) ? 'Q'.$fgItem['value'] : $fgItem['value'];
|
|
|
|
$cmd = 'GET FULL VARIABLE ${QUEUE_WAITING_COUNT(' . $id_queue . ')}';
|
|
$result[] = $cmd;
|
|
$response = agiRunCmd($cmd);
|
|
if ($GLOBALS['isXampp']) {
|
|
$rnd = rand(0,20);
|
|
$response = '200 result=1 (' . $rnd . ')';
|
|
}
|
|
$result[] = $response;
|
|
|
|
$waiting_count = '';
|
|
if (substr($response,0,14) == '200 result=1 (') {
|
|
$explodido = explode('(',$response);
|
|
$waiting_count = substr($explodido[1],0,-1);
|
|
}
|
|
|
|
$run_next = true;
|
|
|
|
if ($waiting_count == '') {
|
|
$result[] = 'Coleta de waiting sem sucesso';
|
|
logIVRAddFgItem($fgItem,$result);
|
|
$run_next = false;
|
|
}
|
|
|
|
if ($run_next) {
|
|
$arr = array();
|
|
$fgItemChildren = fgItemGetChildrenFrom($fgItem);
|
|
foreach ($fgItemChildren as $fgItemChild) {
|
|
if ($fgItemChild['cmd'] == 'queue.waitingcount-greater') {
|
|
$arr[$fgItemChild['value']] = $fgItemChild['id'];
|
|
}
|
|
}
|
|
if (count($arr) > 0) {
|
|
ksort($arr);
|
|
$fgItemNextId = end($arr);
|
|
logIVRAddFgItem($fgItem,$result);
|
|
fgItemRun($GLOBALS['fgItens'][$fgItemNextId]);
|
|
$run_next = false;
|
|
}
|
|
}
|
|
|
|
if ($run_next) {
|
|
$result[] = 'No Match';
|
|
$fgItemChildren = fgItemGetChildrenFrom($fgItem);
|
|
foreach ($fgItemChildren as $fgItemChild) {
|
|
if ($run_next) {
|
|
if ($fgItemChild['cmd'] == 'nomatch') {
|
|
logIVRAddFgItem($fgItem,$result);
|
|
fgItemRun($fgItemChild);
|
|
$run_next = false;
|
|
}
|
|
}
|
|
}
|
|
if ($run_next) {
|
|
$result[] = 'No found next icon "nomatch"';
|
|
logIVRAddFgItem($fgItem,$result);
|
|
}
|
|
}
|
|
|
|
}
|
|
|
|
function fgItemRunQueueWaitingCountGreater($fgItem = array()) {
|
|
|
|
logAdd("<hr>fgItemRunQueueWaitingCountGreater<br><br>");
|
|
logAddFgItem($fgItem);
|
|
logAdd("<br>");
|
|
|
|
logIVRAddFgItemLast($fgItem);
|
|
logIVRAddFgItem($fgItem);
|
|
|
|
fgItemRunNextFrom($fgItem);
|
|
|
|
}
|
|
|
|
function fgItemRunQueueWithCallback($fgItem = array()) {
|
|
|
|
logAdd("<hr>fgItemRunQueueWithCallback<br><br>");
|
|
logAddFgItem($fgItem);
|
|
logAdd("<br>");
|
|
|
|
logIVRAddFgItemLast($fgItem);
|
|
|
|
$result = array();
|
|
|
|
$id_queue_callback = isset($fgItem['value2']) ? $fgItem['value2'] : '';
|
|
if ($id_queue_callback == '') {
|
|
$cmd = 'SET VARIABLE AGICALLBACKQUEUEID ""';
|
|
} else {
|
|
$cmd = 'SET VARIABLE AGICALLBACKQUEUEID ' . $id_queue_callback;
|
|
}
|
|
$result[] = $cmd;
|
|
$response = agiRunCmd($cmd);
|
|
$result[] = $response;
|
|
|
|
$timeout = isset($fgItem['value3']) ? $fgItem['value3'] : '';
|
|
$timeout = is_numeric($timeout) ? $timeout : '';
|
|
|
|
$result[] = 'Queue id: ' . $fgItem['value'] . ' timeout: ' . $timeout . ' Queue callback id: ' . $fgItem['value3'];
|
|
|
|
$run_next = true;
|
|
|
|
$queue_status = '';
|
|
|
|
$cmd = 'GET FULL VARIABLE ${QUEUE_MEMBER(Q' . $fgItem['value'] . ',ready)}';
|
|
$result[] = $cmd;
|
|
$response = agiRunCmd($cmd);
|
|
if ($GLOBALS['isXampp']) {
|
|
$rnd = rand(1,100);
|
|
if ($rnd >= 50) {
|
|
$response = '200 result=1 (0)';
|
|
}
|
|
}
|
|
$result[] = $response;
|
|
if (substr($response,0,14) == '200 result=1 (') {
|
|
$qtd = str_replace('200 result=1 (','',$response);
|
|
$qtd = substr($qtd,0,-1);
|
|
if ($qtd == '0') {
|
|
$queue_status = 'full';
|
|
}
|
|
}
|
|
|
|
if ($queue_status == 'full') {
|
|
|
|
$fgItemChildren = fgItemGetChildrenFrom($fgItem);
|
|
foreach ($fgItemChildren as $fgItemChild) {
|
|
if ($run_next) {
|
|
if ($fgItemChild['cmd'] == 'queue.withcallback-noready') {
|
|
logIVRAddFgItem($fgItem,$result);
|
|
fgItemRun($fgItemChild);
|
|
$run_next = false;
|
|
}
|
|
}
|
|
}
|
|
|
|
}
|
|
|
|
if ($run_next) {
|
|
|
|
// logAdd('===> agiRunQueue<br>');
|
|
$queue_status = agiRunQueue(array('id' => $fgItem['value'],'timeout' => $timeout));
|
|
$result[] = 'queue_status: ' . $queue_status;
|
|
if ($queue_status == 'stopivr') {
|
|
// logAdd('===> agiRunQueue stopivr<br>');
|
|
$run_next = false;
|
|
}
|
|
|
|
}
|
|
|
|
if (($run_next) && ($queue_status == 'timeout')) {
|
|
|
|
$fgItemChildren = fgItemGetChildrenFrom($fgItem);
|
|
foreach ($fgItemChildren as $fgItemChild) {
|
|
if ($run_next) {
|
|
if ($fgItemChild['cmd'] == 'timeoutwithlimit') {
|
|
logIVRAddFgItem($fgItem,$result);
|
|
fgItemRun($fgItemChild);
|
|
$run_next = false;
|
|
}
|
|
}
|
|
}
|
|
|
|
$fgItemChildren = fgItemGetChildrenFrom($fgItem);
|
|
foreach ($fgItemChildren as $fgItemChild) {
|
|
if ($run_next) {
|
|
if ($fgItemChild['cmd'] == 'timeout') {
|
|
logIVRAddFgItem($fgItem,$result);
|
|
fgItemRun($fgItemChild);
|
|
$run_next = false;
|
|
}
|
|
}
|
|
}
|
|
|
|
if ($run_next) {
|
|
$result[] = 'Not found next icon "timeoutwithlimit" or "timeout"';
|
|
logIVRAddFgItem($fgItem,$result);
|
|
}
|
|
|
|
$run_next = false;
|
|
|
|
}
|
|
|
|
if ($run_next) {
|
|
logIVRAddFgItem($fgItem,$result);
|
|
fgItemRunNextFrom($fgItem);
|
|
}
|
|
|
|
}
|
|
|
|
function fgItemRunQueueWithCallbackNoReady($fgItem = array()) {
|
|
|
|
logAdd("<hr>fgItemRunQueueWithCallbackNoReady<br><br>");
|
|
logAddFgItem($fgItem);
|
|
logAdd("<br>");
|
|
|
|
logIVRAddFgItemLast($fgItem);
|
|
logIVRAddFgItem($fgItem);
|
|
|
|
fgItemRunNextFrom($fgItem);
|
|
|
|
}
|
|
|
|
function fgItemRunRecord($fgItem = array()) {
|
|
|
|
logAdd("<hr>fgItemRunRecord<br><br>");
|
|
logAddFgItem($fgItem);
|
|
logAdd("<br>");
|
|
|
|
logIVRAddFgItemLast($fgItem);
|
|
|
|
$result = array();
|
|
|
|
$uniqueid = $GLOBALS['uniqueid'];
|
|
$callerid = $GLOBALS['callerid'];
|
|
$exten = $GLOBALS['fgId'];
|
|
|
|
//$cmd = 'EXEC MixMonitor IN_'.date("dmY").'_'.date("H-i-s").'_'.$uniqueid.'_'.$callerid.'_'.$exten.'.wav';
|
|
//$cmd = 'EXEC MixMonitor IN_2023-10-31_10-05-01_123456.78_2001_2221.wav';
|
|
//$cmd = 'EXEC MixMonitor IN_'.date("Y-m-d").'_'.date("H-i-s").'_'.$uniqueid.'_'.$callerid.'_'.$exten.'.wav';
|
|
$cmd = 'EXEC MixMonitor IN_'.date("Y-m-d").'_'.date("H-i-s").'_'.$uniqueid.'_'.$callerid.'_'.$exten.'.ogg';
|
|
$result[] = $cmd;
|
|
$response = agiRunCmd($cmd);
|
|
$result[] = $response;
|
|
|
|
logIVRAddFgItem($fgItem,$result);
|
|
fgItemRunNextFrom($fgItem);
|
|
|
|
}
|
|
|
|
function fgItemRunStart($fgItem = array()) {
|
|
|
|
logAdd("<hr>fgItemRunStart<br><br>");
|
|
logAddFgItem($fgItem);
|
|
logAdd("<br>");
|
|
|
|
logIVRAddFgItemLast($fgItem);
|
|
|
|
$result = array();
|
|
|
|
// queue_log
|
|
// 1353461650|1353461627.33271|NONE|NONE|INFO|IVRSTART|1234|5556777
|
|
// QueueLog(queuename,uniqueid,agent,event,[additionalinfo])
|
|
// $cmd = 'EXEC QUEUELOG NONE,' . $GLOBALS['uniqueid'] . ',NONE,NONE,INFO|IVRSTART|' . $GLOBALS['callerid'] . '|' . $GLOBALS['fgId'];
|
|
// ...
|
|
|
|
logIVRAddFgItem($fgItem,$result);
|
|
|
|
fgItemRunNextFrom($fgItem);
|
|
|
|
}
|
|
|
|
function fgItemRunTimeout($fgItem = array()) {
|
|
|
|
logAdd("<hr>fgItemRunTimeout<br><br>");
|
|
logAddFgItem($fgItem);
|
|
logAdd("<br>");
|
|
|
|
logIVRAddFgItemLast($fgItem);
|
|
|
|
$result = array();
|
|
|
|
$run_next = true;
|
|
|
|
$fgItemChildren = fgItemGetChildrenFrom($fgItem);
|
|
foreach ($fgItemChildren as $fgItemChild) {
|
|
if ($run_next) {
|
|
if ($fgItemChild['cmd'] == 'voicemail') {
|
|
$result[] = 'Found icon "voicemail"';
|
|
logIVRAddFgItem($fgItem,$result);
|
|
fgItemRun($fgItemChild);
|
|
$run_next = false;
|
|
}
|
|
}
|
|
}
|
|
|
|
if ($run_next) {
|
|
logIVRAddFgItem($fgItem,$result);
|
|
fgItemRunNextFrom($fgItem);
|
|
}
|
|
|
|
}
|
|
|
|
function fgItemRunTimeoutWithLimit($fgItem = array()) {
|
|
|
|
logAdd("<hr>fgItemRunTimeoutWithLimit<br><br>");
|
|
logAddFgItem($fgItem);
|
|
logAdd("<br>");
|
|
|
|
logIVRAddFgItemLast($fgItem);
|
|
|
|
$result = array();
|
|
|
|
$run_next = true;
|
|
|
|
if (!isset($GLOBALS['fgItemExecutedCount'][$fgItem['id']])) {
|
|
$GLOBALS['fgItemExecutedCount'][$fgItem['id']] = 0;
|
|
}
|
|
$GLOBALS['fgItemExecutedCount'][$fgItem['id']]++;
|
|
|
|
$result[] = "Execute Count: " . $GLOBALS['fgItemExecutedCount'][$fgItem['id']];
|
|
logAdd("fgItemExecutedCount: ".$GLOBALS['fgItemExecutedCount'][$fgItem['id']]."<br>");
|
|
|
|
if ($GLOBALS['fgItemExecutedCount'][$fgItem['id']] >= $fgItem['value']) {
|
|
|
|
$result[] = 'Execution limit reached';
|
|
|
|
$fgItemChildren = fgItemGetChildrenFrom($fgItem);
|
|
foreach ($fgItemChildren as $fgItemChild) {
|
|
if ($run_next) {
|
|
if ($fgItemChild['cmd'] == 'timeoutwithlimit.limit') {
|
|
$result[] = 'Found "timeoutwithlimit.limit"';
|
|
logIVRAddFgItem($fgItem,$result);
|
|
fgItemRun($fgItemChild);
|
|
$run_next = false;
|
|
}
|
|
}
|
|
}
|
|
|
|
if ($run_next) {
|
|
$result[] = 'Not found next icon "timeoutwithlimit.limit"';
|
|
logIVRAddFgItem($fgItem,$result);
|
|
}
|
|
|
|
$run_next = false;
|
|
}
|
|
|
|
if ($run_next) {
|
|
logIVRAddFgItem($fgItem,$result);
|
|
fgItemRunNextFrom($fgItem);
|
|
}
|
|
|
|
}
|
|
|
|
function fgItemRunTimeoutWithLimitLimit($fgItem = array()) {
|
|
|
|
logAdd("<hr>fgItemRunTimeoutWithLimitLimit<br><br>");
|
|
logAddFgItem($fgItem);
|
|
logAdd("<br>");
|
|
|
|
logIVRAddFgItemLast($fgItem);
|
|
logIVRAddFgItem($fgItem);
|
|
|
|
fgItemRunNextFrom($fgItem);
|
|
|
|
}
|
|
|
|
function fgItemRunVoicemail($fgItem = array()) {
|
|
|
|
logAdd("<hr>fgItemRunVoicemail<br><br>");
|
|
logAddFgItem($fgItem);
|
|
logAdd("<br>");
|
|
|
|
logIVRAddFgItemLast($fgItem);
|
|
|
|
$result = array();
|
|
|
|
if (isset($GLOBALS['numerodiscado'])) {
|
|
if ($GLOBALS['numerodiscado'] != '') {
|
|
$cmd = 'EXEC VOICEMAIL ' . $GLOBALS['numerodiscado'];
|
|
$result[] = $cmd;
|
|
$response = agiRunCmd($cmd);
|
|
$result[] = $response;
|
|
} else {
|
|
$result[] = 'Empty numerodiscado';
|
|
}
|
|
} else {
|
|
$result[] = 'Not found numerodiscao';
|
|
}
|
|
|
|
logIVRAddFgItem($fgItem,$result);
|
|
fgItemRunNextFrom($fgItem);
|
|
|
|
}
|
|
|
|
function fgItemRunWhitelistCheck($fgItem = array()) {
|
|
|
|
logAdd("<hr>fgItemRunWhitelistCheck<br><br>");
|
|
logAddFgItem($fgItem);
|
|
logAdd("<br>");
|
|
|
|
logIVRAddFgItemLast($fgItem);
|
|
|
|
$result = array();
|
|
|
|
$esta_na_lista = hitpbxCheckWhitelist($GLOBALS['callerid']);
|
|
|
|
if ($GLOBALS['isXampp']) {
|
|
$rnd = rand(1,100);
|
|
$esta_na_lista = ($rnd >= 50);
|
|
}
|
|
|
|
if ($esta_na_lista) {
|
|
$result[] = 'Is True';
|
|
} else {
|
|
$result[] = 'Is False';
|
|
}
|
|
$tmp = ($esta_na_lista) ? "Yes" : "No";
|
|
logAdd("Esta na whilelist: ".$tmp."<br>");
|
|
|
|
$run_next = true;
|
|
$fgItemChildren = fgItemGetChildrenFrom($fgItem);
|
|
$cmdTarget = $esta_na_lista ? 'whitelist.true' : 'whitelist.false';
|
|
foreach ($fgItemChildren as $fgItemChild) {
|
|
if ($run_next) {
|
|
if ($fgItemChild['cmd'] == $cmdTarget) {
|
|
logIVRAddFgItem($fgItem,$result);
|
|
fgItemRun($fgItemChild);
|
|
$run_next = false;
|
|
}
|
|
}
|
|
}
|
|
|
|
if ($run_next) {
|
|
$result[] = 'Not found icon "whitelist.true" or "whitelist.false"';
|
|
logIVRAddFgItem($fgItem,$result);
|
|
}
|
|
|
|
}
|
|
|
|
function fgItemRunWhitelistFalse($fgItem = array()) {
|
|
|
|
logAdd("<hr>fgItemRunWhitelistFalse<br><br>");
|
|
logAddFgItem($fgItem);
|
|
logAdd("<br>");
|
|
|
|
logIVRAddFgItemLast($fgItem);
|
|
logIVRAddFgItem($fgItem);
|
|
|
|
fgItemRunNextFrom($fgItem);
|
|
|
|
}
|
|
|
|
function fgItemRunWhitelistTrue($fgItem = array()) {
|
|
|
|
logAdd("<hr>fgItemRunWhitelistTrue<br><br>");
|
|
logAddFgItem($fgItem);
|
|
logAdd("<br>");
|
|
|
|
logIVRAddFgItemLast($fgItem);
|
|
logIVRAddFgItem($fgItem);
|
|
|
|
fgItemRunNextFrom($fgItem);
|
|
|
|
}
|
|
|
|
// --------------------------------------------------------------------------------------------------------------------------------
|
|
|
|
function hitpbxCheckAuditoria($args = array()) {
|
|
|
|
$args['ramal'] = isset($args['ramal']) ? $args['ramal'] : '';
|
|
$args['ramais'] = isset($args['ramais']) ? $args['ramais'] : array();
|
|
$args['idqueue'] = isset($args['idqueue']) ? $args['idqueue'] : '';
|
|
|
|
if ($args['ramal'] != '') {
|
|
$args['ramais'][] = $args['ramal'];
|
|
}
|
|
|
|
$ramal_ids = array();
|
|
|
|
foreach ($args['ramais'] as $ramal) {
|
|
|
|
$query = "SELECT id FROM tab_ramal WHERE ramal = '" . mysqli_real_escape_string($GLOBALS['db'],$ramal) . "'";
|
|
$query_result = mysqli_query($GLOBALS['db'],$query);
|
|
if (mysqli_num_rows($query_result)) {
|
|
$resultLinha = mysqli_fetch_assoc($query_result);
|
|
$ramal_ids[] = $resultLinha['id'];
|
|
}
|
|
}
|
|
|
|
$auditorias = array();
|
|
|
|
foreach ($ramal_ids as $idramal) {
|
|
$query = "SELECT * FROM tab_auditoria WHERE gravar = '1' AND id_origem_tab_ramal = '" . mysqli_real_escape_string($GLOBALS['db'],$idramal) . "'";
|
|
$query_result = mysqli_query($GLOBALS['db'],$query);
|
|
while ($resultLinha = mysqli_fetch_assoc($query_result)) {
|
|
$auditorias[] = $resultLinha;
|
|
}
|
|
}
|
|
|
|
$query = "SELECT * FROM tab_auditoria WHERE gravar = '1' AND id_origem_tab_queue = '" . mysqli_real_escape_string($GLOBALS['db'],$args['idqueue']) . "' ";
|
|
$query_result = mysqli_query($GLOBALS['db'],$query);
|
|
while ($resultLinha = mysqli_fetch_assoc($query_result)) {
|
|
$auditorias[] = $resultLinha;
|
|
}
|
|
|
|
$periodo_match = false;
|
|
foreach ($auditorias as $auditoria) {
|
|
$periodo_match = hitpbxCheckPeriodoMatch(array('id_periodo' => $auditoria['id_tab_condicao_tempo']));
|
|
}
|
|
|
|
return $periodo_match;
|
|
|
|
}
|
|
|
|
function hitpbxCheckBlacklist($callerid = '') {
|
|
|
|
$return = false;
|
|
//$query = "SELECT id FROM tab_blacklist WHERE telefone = '" . mysqli_real_escape_string($GLOBALS['db'],$callerid) . "'";
|
|
$query = "SELECT id FROM tab_blacklist WHERE CAST(REGEXP_REPLACE(telefone, '[^0-9]', '') AS SIGNED) = '" . mysqli_real_escape_string($GLOBALS['db'],$callerid) . "'";
|
|
|
|
if (($return != true) && ((strlen($callerid) == 12) || (strlen($callerid) == 13))) {
|
|
// Exemplos de callerid: 551133224455 ou 5511988887777
|
|
$tmp = '(' . substr($callerid,2,2) . ')' . substr($callerid,4);
|
|
$query = "SELECT id FROM tab_blacklist WHERE telefone = '" . mysqli_real_escape_string($GLOBALS['db'],$tmp) . "'";
|
|
$query_result = mysqli_query($GLOBALS['db'],$query);
|
|
if (mysqli_num_rows($query_result) > 0) {
|
|
$return = true;
|
|
}
|
|
}
|
|
|
|
if (($return != true) && ((strlen($callerid) == 10) || (strlen($callerid) == 11))) {
|
|
// Exemplos de callerid: 1133224455 ou 11988887777
|
|
$tmp = '55(' . substr($callerid,0,2) . ')' . substr($callerid,2);
|
|
$query = "SELECT id FROM tab_blacklist WHERE telefone = '" . mysqli_real_escape_string($GLOBALS['db'],$tmp) . "'";
|
|
$query_result = mysqli_query($GLOBALS['db'],$query);
|
|
if (mysqli_num_rows($query_result) > 0) {
|
|
$return = true;
|
|
}
|
|
}
|
|
|
|
$query_result = mysqli_query($GLOBALS['db'],$query);
|
|
if (mysqli_num_rows($query_result) > 0) {
|
|
$return = true;
|
|
}
|
|
return $return;
|
|
|
|
}
|
|
|
|
function hitpbxCheckPeriodoMatch($args = array()) {
|
|
|
|
$return = false;
|
|
|
|
$args['id_periodo'] = isset($args['id_periodo']) ? $args['id_periodo'] : '';
|
|
$args['weekday'] = isset($args['weekday']) ? $args['weekday'] : date('D');
|
|
$args['hhmmss'] = isset($args['hhmmss']) ? $args['hhmmss'] : date("H:i:s");
|
|
$args['day'] = isset($args['day']) ? $args['day'] : date("d");
|
|
$args['month'] = isset($args['month']) ? $args['month'] : date("m");
|
|
$args['year'] = isset($args['year']) ? $args['year'] : date("Y");
|
|
|
|
if ($args['id_periodo'] != '') {
|
|
|
|
$query = "SELECT id FROM tab_periodo ";
|
|
$query.= "WHERE id = '" . mysqli_real_escape_string($GLOBALS['db'],$args['id_periodo']) . "'";
|
|
if ($args['weekday'] == 'Mon') { $query.= "AND (monday = '1' OR (monday = '0' AND tuesday = '0' AND wednesday = '0' AND thursday = '0' AND friday = '0' AND saturday = '0' AND sunday = '0')) "; }
|
|
if ($args['weekday'] == 'Tue') { $query.= "AND (tuesday = '1' OR (monday = '0' AND tuesday = '0' AND wednesday = '0' AND thursday = '0' AND friday = '0' AND saturday = '0' AND sunday = '0')) "; }
|
|
if ($args['weekday'] == 'Wed') { $query.= "AND (wednesday = '1' OR (monday = '0' AND tuesday = '0' AND wednesday = '0' AND thursday = '0' AND friday = '0' AND saturday = '0' AND sunday = '0')) "; }
|
|
if ($args['weekday'] == 'Thu') { $query.= "AND (thursday = '1' OR (monday = '0' AND tuesday = '0' AND wednesday = '0' AND thursday = '0' AND friday = '0' AND saturday = '0' AND sunday = '0')) "; }
|
|
if ($args['weekday'] == 'Fri') { $query.= "AND (friday = '1' OR (monday = '0' AND tuesday = '0' AND wednesday = '0' AND thursday = '0' AND friday = '0' AND saturday = '0' AND sunday = '0')) "; }
|
|
if ($args['weekday'] == 'Sat') { $query.= "AND (saturday = '1' OR (monday = '0' AND tuesday = '0' AND wednesday = '0' AND thursday = '0' AND friday = '0' AND saturday = '0' AND sunday = '0')) "; }
|
|
if ($args['weekday'] == 'Sun') { $query.= "AND (sunday = '1' OR (monday = '0' AND tuesday = '0' AND wednesday = '0' AND thursday = '0' AND friday = '0' AND saturday = '0' AND sunday = '0')) "; }
|
|
$query.= "AND ((time_start <= '".$args['hhmmss']."' AND time_stop >= '".$args['hhmmss']."') OR (time_start = '00:00:00' AND time_stop = '00:00:00')) ";
|
|
$query.= "AND ((day_start <= '".$args['day']."' AND day_stop >= '".$args['day']."') OR (day_start = '0' AND day_stop = '0')) ";
|
|
$query.= "AND ((month_start <= '".$args['month']."' AND month_stop >= '".$args['month']."') OR (month_start = '0' AND month_stop = '0')) ";
|
|
$query.= "AND ((year_start <= '".$args['year']."' AND year_stop >= '".$args['year']."') OR (year_start = '0' AND year_stop = '0')) ";
|
|
$query_result = mysqli_query($GLOBALS['db'],$query);
|
|
if (mysqli_num_rows($query_result) > 0) {
|
|
$return = true;
|
|
}
|
|
|
|
}
|
|
|
|
return $return;
|
|
|
|
}
|
|
|
|
function hitpbxCheckWhitelist($callerid = '') {
|
|
|
|
$return = false;
|
|
//$query = "SELECT id FROM tab_whitelist WHERE telefone = '" . mysqli_real_escape_string($GLOBALS['db'],$callerid) . "'";
|
|
$query = "SELECT id FROM tab_whitelist WHERE CAST(REGEXP_REPLACE(telefone, '[^0-9]', '') AS SIGNED) = '" . mysqli_real_escape_string($GLOBALS['db'],$callerid) . "'";
|
|
$query_result = mysqli_query($GLOBALS['db'],$query);
|
|
if (mysqli_num_rows($query_result) > 0) {
|
|
$return = true;
|
|
}
|
|
|
|
if (($return != true) && ((strlen($callerid) == 12) || (strlen($callerid) == 13))) {
|
|
// Exemplos de callerid: 551133224455 ou 5511988887777
|
|
$tmp = '(' . substr($callerid,2,2) . ')' . substr($callerid,4);
|
|
$query = "SELECT id FROM tab_whitelist WHERE telefone = '" . mysqli_real_escape_string($GLOBALS['db'],$tmp) . "'";
|
|
$query_result = mysqli_query($GLOBALS['db'],$query);
|
|
if (mysqli_num_rows($query_result) > 0) {
|
|
$return = true;
|
|
}
|
|
}
|
|
|
|
if (($return != true) && ((strlen($callerid) == 10) || (strlen($callerid) == 11))) {
|
|
// Exemplos de callerid: 1133224455 ou 11988887777
|
|
$tmp = '55(' . substr($callerid,0,2) . ')' . substr($callerid,2);
|
|
$query = "SELECT id FROM tab_whitelist WHERE telefone = '" . mysqli_real_escape_string($GLOBALS['db'],$tmp) . "'";
|
|
$query_result = mysqli_query($GLOBALS['db'],$query);
|
|
if (mysqli_num_rows($query_result) > 0) {
|
|
$return = true;
|
|
}
|
|
}
|
|
|
|
return $return;
|
|
|
|
}
|
|
|
|
function hitpbxGetCallbackFromRamal($ramal = '') {
|
|
|
|
$return = '';
|
|
$query = "SELECT callback FROM tab_ramal WHERE ramal = '" . mysqli_real_escape_string($GLOBALS['db'],$ramal) . "'";
|
|
$query_result = mysqli_query($GLOBALS['db'],$query);
|
|
if (mysqli_num_rows($query_result) > 0) {
|
|
$resultLinha = mysqli_fetch_assoc($query_result);
|
|
$return = $resultLinha['callback'];
|
|
}
|
|
return $return;
|
|
|
|
}
|
|
|
|
function hitpbxGetDesvioFrom($args = array()) {
|
|
|
|
$return = array();
|
|
|
|
$args['tipo'] = $args['tipo'] ? $args['tipo'] : ''; // shortname
|
|
$args['value'] = $args['value'] ? $args['value'] : '';
|
|
|
|
$origem_tipo_id = '';
|
|
$query = "SELECT id FROM tab_desvio_origem_tipo WHERE shortname = '".mysqli_real_escape_string($GLOBALS['db'],$args['tipo'])."'";
|
|
$query_result = mysqli_query($GLOBALS['db'],$query);
|
|
while ($resultLinha = mysqli_fetch_assoc($query_result)) {
|
|
$origem_tipo_id = $resultLinha['id'];
|
|
}
|
|
|
|
$origem_id = $args['value'];
|
|
if ($args['tipo'] == 'ramal') {
|
|
$query = "SELECT id FROM tab_ramal WHERE ramal = '".mysqli_real_escape_string($GLOBALS['db'],$args['value'])."'";
|
|
$query_result = mysqli_query($GLOBALS['db'],$query);
|
|
while ($resultLinha = mysqli_fetch_assoc($query_result)) {
|
|
$origem_id = $resultLinha['id'];
|
|
}
|
|
}
|
|
|
|
$query = "SELECT tab_desvio.periodo_id, tab_desvio.destino_id, tab_desvio_destino_tipo.shortname ";
|
|
$query.= "FROM tab_desvio ";
|
|
$query.= "INNER JOIN tab_desvio_destino_tipo ON tab_desvio_destino_tipo.id = tab_desvio.destino_tipo_id ";
|
|
$query.= "WHERE tab_desvio.origem_tipo_id = '".mysqli_real_escape_string($GLOBALS['db'],$origem_tipo_id)."'";
|
|
$query.= "AND tab_desvio.origem_id = '".mysqli_real_escape_string($GLOBALS['db'],$origem_id)."'";
|
|
$query_result = mysqli_query($GLOBALS['db'],$query);
|
|
while ($resultLinha = mysqli_fetch_assoc($query_result)) {
|
|
|
|
$periodo_match = false;
|
|
|
|
if (empty($resultLinha['periodo_id'])) {
|
|
$periodo_match = true;
|
|
} else {
|
|
|
|
$query2 = "SELECT * FROM tab_periodo ";
|
|
$query2.= "WHERE id = '".mysqli_real_escape_string($GLOBALS['db'],$resultLinha['periodo_id'])."' ";
|
|
|
|
$weekday = date('D');
|
|
if ($weekday == 'Mon') { $query2.= "AND (monday = '1' OR (monday = '0' AND tuesday = '0' AND wednesday = '0' AND thursday = '0' AND friday = '0' AND saturday = '0' AND sunday = '0')) "; }
|
|
if ($weekday == 'Tue') { $query2.= "AND (tuesday = '1' OR (monday = '0' AND tuesday = '0' AND wednesday = '0' AND thursday = '0' AND friday = '0' AND saturday = '0' AND sunday = '0')) "; }
|
|
if ($weekday == 'Wed') { $query2.= "AND (wednesday = '1' OR (monday = '0' AND tuesday = '0' AND wednesday = '0' AND thursday = '0' AND friday = '0' AND saturday = '0' AND sunday = '0')) "; }
|
|
if ($weekday == 'Thu') { $query2.= "AND (thursday = '1' OR (monday = '0' AND tuesday = '0' AND wednesday = '0' AND thursday = '0' AND friday = '0' AND saturday = '0' AND sunday = '0')) "; }
|
|
if ($weekday == 'Fri') { $query2.= "AND (friday = '1' OR (monday = '0' AND tuesday = '0' AND wednesday = '0' AND thursday = '0' AND friday = '0' AND saturday = '0' AND sunday = '0')) "; }
|
|
if ($weekday == 'Sat') { $query2.= "AND (saturday = '1' OR (monday = '0' AND tuesday = '0' AND wednesday = '0' AND thursday = '0' AND friday = '0' AND saturday = '0' AND sunday = '0')) "; }
|
|
if ($weekday == 'Sun') { $query2.= "AND (sunday = '1' OR (monday = '0' AND tuesday = '0' AND wednesday = '0' AND thursday = '0' AND friday = '0' AND saturday = '0' AND sunday = '0')) "; }
|
|
|
|
$hhmmss = date("H:i:s");
|
|
$query2.= "AND ((time_start <= '".$hhmmss."' AND time_stop >= '".$hhmmss."') OR (time_start = '00:00:00' AND time_stop = '00:00:00')) ";
|
|
|
|
$day = date('d');
|
|
$query2.= "AND ((day_start <= '".$day."' AND day_stop >= '".$day."') OR (day_start = '0' AND day_stop = '0')) ";
|
|
|
|
$month = date('m');
|
|
$query2.= "AND ((month_start <= '".$month."' AND month_stop >= '".$month."') OR (month_start = '0' AND month_stop = '0')) ";
|
|
|
|
$year = date('Y');
|
|
$query2.= "AND ((year_start <= '".$year."' AND year_stop >= '".$year."') OR (year_start = '0' AND year_stop = '0')) ";
|
|
|
|
$result2 = mysqli_query($GLOBALS['db'],$query2);
|
|
if (mysqli_num_rows($result2) > 0) {
|
|
$periodo_match = true;
|
|
}
|
|
|
|
}
|
|
|
|
if ($periodo_match) {
|
|
|
|
if ($resultLinha['shortname'] == 'queue') {
|
|
$query2 = "SELECT id FROM tab_queue WHERE id = '".mysqli_real_escape_string($GLOBALS['db'],$resultLinha['destino_id'])."'";
|
|
$result2 = mysqli_query($GLOBALS['db'],$query2);
|
|
while ($resultLinha2 = mysqli_fetch_assoc($result2)) {
|
|
$return = array(
|
|
'shortname' => $resultLinha['shortname'],
|
|
'queue' => $resultLinha2['id']
|
|
);
|
|
}
|
|
}
|
|
|
|
if (($resultLinha['shortname'] == 'ramal') || ($resultLinha['shortname'] == 'voicemail')) {
|
|
$query2 = "SELECT ramal FROM tab_ramal WHERE id = '".mysqli_real_escape_string($GLOBALS['db'],$resultLinha['destino_id'])."'";
|
|
$result2 = mysqli_query($GLOBALS['db'],$query2);
|
|
while ($resultLinha2 = mysqli_fetch_assoc($result2)) {
|
|
$return = array(
|
|
'shortname' => $resultLinha['shortname'],
|
|
'ramal' => $resultLinha2['ramal']
|
|
);
|
|
}
|
|
}
|
|
|
|
if ($resultLinha['shortname'] == 'ramalgrupo') {
|
|
$query2 = "SELECT id FROM tab_group WHERE id = '".mysqli_real_escape_string($GLOBALS['db'],$resultLinha['destino_id'])."'";
|
|
$result2 = mysqli_query($GLOBALS['db'],$query2);
|
|
while ($resultLinha2 = mysqli_fetch_assoc($result2)) {
|
|
$return = array(
|
|
'shortname' => $resultLinha['shortname'],
|
|
'callgroup' => $resultLinha2['id']
|
|
);
|
|
}
|
|
}
|
|
|
|
if ($resultLinha['shortname'] == 'numeroexterno') {
|
|
$return = array(
|
|
'shortname' => $resultLinha['shortname'],
|
|
'numero' => $resultLinha['destino_id']
|
|
);
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
return $return;
|
|
|
|
}
|
|
|
|
function hitpbxGetQueuenomeFromId($queueid = '') {
|
|
|
|
$return = '';
|
|
$query = "SELECT nome FROM tab_queue WHERE id = '".mysqli_real_escape_string($GLOBALS['db'],$queueid)."'";
|
|
$query_result = mysqli_query($GLOBALS['db'],$query);
|
|
while ($resultLinha = mysqli_fetch_assoc($query_result)) {
|
|
$return = $resultLinha['nome'];
|
|
}
|
|
return $return;
|
|
|
|
}
|
|
|
|
function hitpbxGetQueueFromNumeroExterno($args = array()) {
|
|
|
|
$return = '';
|
|
$args['numero_externo'] = $args['numero_externo'] ? $args['numero_externo'] : '';
|
|
if ($args['numero_externo'] != '') {
|
|
$query = "SELECT * FROM tab_queue WHERE numero_externo = '".mysqli_real_escape_string($GLOBALS['db'],$args['numero_externo'])."'";
|
|
$query_result = mysqli_query($GLOBALS['db'],$query);
|
|
while ($resultLinha = mysqli_fetch_assoc($query_result)) {
|
|
$return = $resultLinha;
|
|
}
|
|
}
|
|
return $return;
|
|
|
|
}
|
|
|
|
function hitpbxGetRamais($args = array()) {
|
|
|
|
$return = array();
|
|
$query = "SELECT ramal FROM tab_ramal ";
|
|
$query.= "WHERE ramal IS NOT NULL ";
|
|
if (isset($args['callgroup'])) {
|
|
$query.= "AND callgroup = '".mysqli_real_escape_string($GLOBALS['db'],$args['callgroup'])."'";
|
|
}
|
|
$query_result = mysqli_query($GLOBALS['db'],$query);
|
|
while ($resultLinha = mysqli_fetch_assoc($query_result)) {
|
|
$return[] = $resultLinha['ramal'];
|
|
}
|
|
return $return;
|
|
|
|
}
|
|
|
|
function hitpbxGetRamaisSecretariaFromRamal($ramal = '') {
|
|
|
|
$return = array();
|
|
$query = "SELECT callgroup_secretaria FROM tab_ramal WHERE ramal = '" . mysqli_real_escape_string($GLOBALS['db'],$ramal) . "'";
|
|
$query_result = mysqli_query($GLOBALS['db'],$query);
|
|
if (mysqli_num_rows($query_result) > 0) {
|
|
$resultLinha = mysqli_fetch_assoc($query_result);
|
|
$callgroup_secretaria = $resultLinha['callgroup_secretaria'];
|
|
$query = "SELECT ramal FROM tab_ramal WHERE callgroup = '" . mysqli_real_escape_string($GLOBALS['db'],$callgroup_secretaria) . "'";
|
|
$query_result = mysqli_query($GLOBALS['db'],$query);
|
|
while ($resultLinha = mysqli_fetch_assoc($query_result)) {
|
|
$return[] = $resultLinha['ramal'];
|
|
}
|
|
}
|
|
return $return;
|
|
|
|
}
|
|
|
|
function hitpbxGetRingTimeoutFromRamal($ramal = '') {
|
|
|
|
$return = '';
|
|
$query = "SELECT ring_timeout FROM tab_ramal WHERE ramal = '" . mysqli_real_escape_string($GLOBALS['db'],$ramal) . "'";
|
|
$query_result = mysqli_query($GLOBALS['db'],$query);
|
|
if (mysqli_num_rows($query_result) > 0) {
|
|
$resultLinha = mysqli_fetch_assoc($query_result);
|
|
$return = $resultLinha['ring_timeout'];
|
|
}
|
|
return $return;
|
|
|
|
}
|
|
|
|
// --------------------------------------------------------------------------------------------------------------------------------
|
|
|
|
function extrairNumeros($string) {
|
|
|
|
preg_match_all('/\d+/', $string, $matches);
|
|
$numeros = implode('', $matches[0]);
|
|
return $numeros;
|
|
|
|
}
|
|
|
|
function validarCNPJ($cnpj = '') {
|
|
|
|
// Remover caracteres não numéricos
|
|
$cnpj = preg_replace('/[^0-9]/', '', $cnpj);
|
|
// Verificar se o CNPJ tem 14 dígitos
|
|
if (strlen($cnpj) !== 14) {
|
|
return false;
|
|
}
|
|
// Verificar CNPJs com dígitos repetidos (00.000.000/0000-00, 11.111.111/1111-11, etc.)
|
|
if (preg_match('/(\d)\1{13}/', $cnpj)) {
|
|
return false;
|
|
}
|
|
// Calcular o primeiro dígito verificador
|
|
$soma = 0;
|
|
for ($i = 0; $i < 12; $i++) {
|
|
$soma += $cnpj[$i] * (($i < 4) ? (5 - $i) : (13 - $i));
|
|
}
|
|
$resto = $soma % 11;
|
|
$dv1 = ($resto < 2) ? 0 : 11 - $resto;
|
|
// Calcular o segundo dígito verificador
|
|
$soma = 0;
|
|
for ($i = 0; $i < 13; $i++) {
|
|
$soma += $cnpj[$i] * (($i < 5) ? (6 - $i) : (14 - $i));
|
|
}
|
|
$resto = $soma % 11;
|
|
$dv2 = ($resto < 2) ? 0 : 11 - $resto;
|
|
// Verificar se os dígitos verificadores são válidos
|
|
if ($cnpj[12] == $dv1 && $cnpj[13] == $dv2) {
|
|
return true;
|
|
} else {
|
|
return false;
|
|
}
|
|
|
|
}
|
|
|
|
function validarCPF($cpf = '') {
|
|
|
|
// Remover caracteres não numéricos
|
|
$cpf = preg_replace('/[^0-9]/', '', $cpf);
|
|
// Verificar se o CPF tem 11 dígitos
|
|
if (strlen($cpf) !== 11) {
|
|
return false;
|
|
}
|
|
// Verificar CPFs com dígitos repetidos (111.111.111-11, 222.222.222-22, etc.)
|
|
if (preg_match('/(\d)\1{10}/', $cpf)) {
|
|
return false;
|
|
}
|
|
// Separar os dígitos
|
|
$digitos = str_split($cpf);
|
|
// Calcular o primeiro dígito verificador
|
|
$soma = 0;
|
|
for ($i = 0; $i < 9; $i++) {
|
|
$soma += $digitos[$i] * (10 - $i);
|
|
}
|
|
$resto = $soma % 11;
|
|
$dv1 = ($resto < 2) ? 0 : 11 - $resto;
|
|
// Calcular o segundo dígito verificador
|
|
$soma = 0;
|
|
for ($i = 0; $i < 10; $i++) {
|
|
$soma += $digitos[$i] * (11 - $i);
|
|
}
|
|
$resto = $soma % 11;
|
|
$dv2 = ($resto < 2) ? 0 : 11 - $resto;
|
|
// Verificar se os dígitos verificadores são válidos
|
|
if ($digitos[9] == $dv1 && $digitos[10] == $dv2) {
|
|
return true;
|
|
} else {
|
|
return false;
|
|
}
|
|
|
|
}
|
|
|
|
// --------------------------------------------------------------------------------------------------------------------------------
|
|
|
|
$stdin = fopen('php://stdin', 'r');
|
|
$stdout = fopen('php://stdout', 'w');
|
|
|
|
$isXampp = (file_exists('C:\xampp'));
|
|
|
|
$appdir = dirname(__FILE__);
|
|
chdir($appdir);
|
|
|
|
date_default_timezone_set('America/Bahia');
|
|
|
|
if ('A' == 'B') {
|
|
|
|
$response = agiRunCmd('EXEC NOOP HITAGI');
|
|
$response = agiRunCmd('ANSWER');
|
|
$response = agiRunCmd('EXEC WAIT 1');
|
|
$response = agiRunCmd('EXEC PLAYBACK beep');
|
|
$response = agiRunCmd('EXEC WAIT 1');
|
|
// $response = agiRunCmd('EXEC QueueStatus Q95');
|
|
// $response = agiRunCmd('EXEC NOOP ${QUEUE_EXISTS(Q95)}');
|
|
// $response = agiRunCmd('GET FULL VARIABLE ${QUEUE_MEMBER_LIST(Q95)}');
|
|
|
|
$response = agiRunCmd('GET FULL VARIABLE ${QUEUE_WAITING_COUNT(Q95)}');
|
|
// 200 result=1 (0)
|
|
|
|
|
|
} else {
|
|
|
|
$fgId = (isset($argv[1])) ? $argv[1] : '';
|
|
$fgItens = array();
|
|
$fgItemStart = array();
|
|
if ($fgId != '') {
|
|
// ...
|
|
if (file_exists('/etc/asterisk')) {
|
|
$target = '/var/www/html/fluxograma/data-json/' . $fgId . '.json';
|
|
} else {
|
|
$target = 'dial/' . $fgId . '.json';
|
|
}
|
|
if (file_exists($target)) {
|
|
$itens = file_get_contents($target);
|
|
$itens = json_decode($itens,true);
|
|
foreach ($itens as $item) {
|
|
$fgItens[$item['id']] = $item;
|
|
if ($item['cmd'] == 'start') {
|
|
$fgItemStart = $item;
|
|
}
|
|
}
|
|
unset($itens);
|
|
}
|
|
}
|
|
|
|
logStart();
|
|
logAdd("target: ".$target."<br>");
|
|
|
|
if (count($fgItemStart) > 0) {
|
|
|
|
$arrDtmf = array(
|
|
'35' => '#',
|
|
'42' => '*',
|
|
'48' => '0',
|
|
'49' => '1',
|
|
'50' => '2',
|
|
'51' => '3',
|
|
'52' => '4',
|
|
'53' => '5',
|
|
'54' => '6',
|
|
'55' => '7',
|
|
'56' => '8',
|
|
'57' => '9'
|
|
);
|
|
|
|
if ($isXampp) {
|
|
|
|
$callerid = '1138118400';
|
|
$uniqueid = date("Ymd") . "." . date("His");
|
|
$digitado = '';
|
|
|
|
$host = 'localhost';
|
|
$user = 'root';
|
|
$password = '';
|
|
$database = 'hitpbx_homologacao';
|
|
$port = '3306';
|
|
$db = mysqli_connect($host, $user, $password, $database, $port) or die('Erro de conexão com o banco de dados');
|
|
mysqli_set_charset($db, 'utf8');
|
|
|
|
fgItemRun($fgItemStart);
|
|
|
|
} else {
|
|
|
|
$host = '172.31.187.152';
|
|
$user = 'appuser';
|
|
$password = 'nmvP$x23Vzb@T%Su';
|
|
$hostname = gethostname();
|
|
$hostname = str_replace('hitpbx-','hitpbx_',$hostname);
|
|
$database = $hostname;
|
|
if ($hostname == 'hitpbx-001') {
|
|
$database = 'hitpbx-001';
|
|
}
|
|
$port = '6033';
|
|
$db = mysqli_connect($host, $user, $password, $database, $port) or die('Erro de conexão com o banco de dados');
|
|
mysqli_set_charset($db, 'utf8');
|
|
|
|
/*
|
|
logAdd("111<br>");
|
|
$query = "SELECT * FROM tab_ramal LIMIT 1";
|
|
$result = mysqli_query($db,$query);
|
|
logAdd($query."<br>");
|
|
$result = mysqli_query($GLOBALS['db'],$query);
|
|
logAdd($query."<br>");
|
|
*/
|
|
|
|
// ...
|
|
|
|
/*
|
|
$host = '172.31.187.150';
|
|
$dbcdr = mysqli_connect($host, $user, $password, $database, $port) or die('Erro de conexão com o banco de dados');
|
|
mysqli_set_charset($dbcdr, 'utf8');
|
|
$query = "
|
|
CREATE TABLE IF NOT EXISTS tab_ivr_log2 (
|
|
`id` INT NOT NULL AUTO_INCREMENT,
|
|
`uniqueid` VARCHAR(32) NOT NULL,
|
|
`did` TEXT NULL,
|
|
`quando` DATETIME NULL,
|
|
`fgitem_json` TEXT NULL,
|
|
`fgitem_result` TEXT NULL,
|
|
PRIMARY KEY (`id`))
|
|
ENGINE = InnoDB
|
|
DEFAULT CHARACTER SET = utf8;
|
|
";
|
|
$result = mysqli_query($dbcdr,$query);
|
|
*/
|
|
|
|
// ...
|
|
|
|
$response = agiRunCmd('EXEC NOOP HITAGI');
|
|
$response = agiRunCmd('ANSWER');
|
|
$response = agiRunCmd('EXEC WAIT 1');
|
|
$response = agiRunCmd('EXEC PLAYBACK beep');
|
|
$response = agiRunCmd('EXEC WAIT 1');
|
|
|
|
$digitado = '';
|
|
|
|
$callerid = agiVarGet('CALLERID');
|
|
$uniqueid = agiVarGet('UNIQUEID');
|
|
|
|
$response = agiVarSet('AGIDID',$fgId);
|
|
|
|
$cmd = 'EXEC QUEUELOG NONE,' . $GLOBALS['uniqueid'] . ',NONE,INFO|IVRSTART';
|
|
$response = agiRunCmd($cmd);
|
|
|
|
$cmd = 'EXEC QUEUELOG NONE,' . $GLOBALS['uniqueid'] . ',NONE,INFO|IVRAPPEND|->' . $fgId;
|
|
$response = agiRunCmd($cmd);
|
|
|
|
fgItemRun($fgItemStart);
|
|
|
|
// 1353461660|1353461627.33271|NONE|NONE|INFO|IVRHANGUP|
|
|
//$cmd = 'EXEC QUEUELOG NONE,' . $GLOBALS['uniqueid'] . ',NONE,NONE,INFO|IVRHANGUP';
|
|
//$response = agiRunCmd($cmd);
|
|
|
|
// $response = agiRunCmd('HANGUP');
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
fclose($stdin);
|
|
fclose($stdout);
|
|
exit();
|
|
?>
|