diff --git a/L b/L deleted file mode 100644 index 083b700..0000000 --- a/L +++ /dev/null @@ -1 +0,0 @@ -L \ No newline at end of file diff --git a/agi-antiga/hitagi-entrada-2.php b/agi-antiga/hitagi-entrada-2.php deleted file mode 100644 index 5da13e8..0000000 --- a/agi-antiga/hitagi-entrada-2.php +++ /dev/null @@ -1,32 +0,0 @@ -on("Connect", function ($server, $fd) { - echo "Cliente conectado: ID $fd\n"; -}); - -// Define o callback para o evento de recebimento de dados -$server->on("Receive", function ($server, $fd, $reactor_id, $data) { - // Processa o fgId recebido - $fgId = trim($data); - - if (empty($fgId)) { - $server->send($fd, "ERROR: fgId não fornecido\n"); - } else { - // Envia uma resposta para o cliente - $response = "fgId recebido: $fgId\n"; - echo $response; // Imprime no console do servidor - $server->send($fd, $response); // Envia resposta ao cliente - } -}); - -// Define o callback para o evento de desconexão -$server->on("Close", function ($server, $fd) { - echo "Cliente desconectado: ID $fd\n"; -}); - -// Inicia o servidor -$server->start(); diff --git a/agi-antiga/hitagi-entrada.php b/agi-antiga/hitagi-entrada.php deleted file mode 100644 index ffe98f3..0000000 --- a/agi-antiga/hitagi-entrada.php +++ /dev/null @@ -1,3638 +0,0 @@ -#!/usr/bin/php -q -'); - fwrite($fp,'idmaster: ' . $idmaster . '
'); - fwrite($fp,'idnext: ' . $idnext . '
'); - fwrite($fp,'cmd: ' . $cmd . '
'); - fwrite($fp,'variation: ' . $variation . '
'); - fwrite($fp,'value: ' . $value . '
'); - fwrite($fp,'value2: ' . $value2 . '
'); - fwrite($fp,'value3: ' . $value3 . '
'); - if (isset($fgItem['defaultvalues'])) { - foreach ($fgItem['defaultvalues'] as $rowkey => $rowvalue) { - fwrite($fp,$rowkey . ': ' . $rowvalue . '
'); - } - } - 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('
agiRunCmd

'); - logAdd('command: ' . $command . '
'); - - $return = ''; - - if (!$GLOBALS['isXampp']) { - - fwrite($GLOBALS['stdout'], $command . "\n"); - fflush($GLOBALS['stdout']); - - while ($line = fgets($GLOBALS['stdin'])) { - logAdd('line: ' . $line . "
"); - $return.= $line; - if (strpos($line, 'result=') !== false) { - - if (substr($line,0,22) != '100 result=0 Trying...') { - break; - } - - } - } - $return = trim($return); - logAdd('return: ' . $return . '

'); - - } - - 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('
agiRunDialRamal '.$ramal.'

'); - - $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)."
"); - $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.'
'); - - 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.'
'); - if ($agiivrstop == 'SIM') { - // logAdd('FOI SIM
'); - $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('
fgItemGetChildrenFrom

'); - // logAddFgItem($fgItemFrom); - // logAdd("
"); - - $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('
fgItemGetMasterFrom

'); - // 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("
fgItemRun

"); - // logAddFgItem($fgItem); - // logAdd("
"); - - 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("
fgItemRunNextFrom

"); - // logAddFgItem($fgItemFrom); - // logAdd("
"); - - $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("
fgItemRunAgiExec

"); - logAddFgItem($fgItem); - logAdd("
"); - - 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("
fgItemRunBlacklistCheck

"); - logAddFgItem($fgItem); - logAdd("
"); - - 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("
fgItemRunBlacklistFalse

"); - logAddFgItem($fgItem); - logAdd("
"); - - logIVRAddFgItemLast($fgItem); - logIVRAddFgItem($fgItem); - - fgItemRunNextFrom($fgItem); - -} - -function fgItemRunBlacklistTrue($fgItem = array()) { - - logAdd("
fgItemRunBlacklistTrue

"); - logAddFgItem($fgItem); - logAdd("
"); - - logIVRAddFgItemLast($fgItem); - logIVRAddFgItem($fgItem); - - fgItemRunNextFrom($fgItem); - -} - -function fgItemRunCalleridChange($fgItem = array()) { - - logAdd('
fgItemRunCalleridChange

'); - logAddFgItem($fgItem); - logAdd("
"); - - 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('
fgItemRunCNPJCheck

'); - logAddFgItem($fgItem); - logAdd("
"); - - 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("
fgItemRunCNPJCheckFalse

"); - logAddFgItem($fgItem); - logAdd("
"); - - logIVRAddFgItemLast($fgItem); - logIVRAddFgItem($fgItem); - - fgItemRunNextFrom($fgItem); - -} - -function fgItemRunCNPJCheckTrue($fgItem = array()) { - - logAdd("
fgItemRunCNPJCheckTrue

"); - logAddFgItem($fgItem); - logAdd("
"); - - logIVRAddFgItemLast($fgItem); - logIVRAddFgItem($fgItem); - - fgItemRunNextFrom($fgItem); - -} - -function fgItemRunCondTempoCheck($fgItem = array()) { - - logAdd('
fgItemRunCondTempoCheck

'); - logAddFgItem($fgItem); - logAdd("
"); - - 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("
fgItemRunCondTempoCheckFalse

"); - logAddFgItem($fgItem); - logAdd("
"); - - logIVRAddFgItemLast($fgItem); - logIVRAddFgItem($fgItem); - - fgItemRunNextFrom($fgItem); - -} - -function fgItemRunCondTempoCheckTrue($fgItem = array()) { - - logAdd("
fgItemRunCondTempoCheckTrue

"); - logAddFgItem($fgItem); - logAdd("
"); - - logIVRAddFgItemLast($fgItem); - logIVRAddFgItem($fgItem); - - fgItemRunNextFrom($fgItem); - -} - -function fgItemRunCPFCheck($fgItem = array()) { - - logAdd('
fgItemRunCPFCheck

'); - logAddFgItem($fgItem); - logAdd("
"); - - 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("
fgItemRunCPFCheckFalse

"); - logAddFgItem($fgItem); - logAdd("
"); - - logIVRAddFgItemLast($fgItem); - logIVRAddFgItem($fgItem); - - fgItemRunNextFrom($fgItem); - -} - -function fgItemRunCPFCheckTrue($fgItem = array()) { - - logAdd("
fgItemRunCPFCheckTrue

"); - logAddFgItem($fgItem); - logAdd("
"); - - logIVRAddFgItemLast($fgItem); - logIVRAddFgItem($fgItem); - - fgItemRunNextFrom($fgItem); - -} - -function fgItemRunDialdigit($fgItem = array()) { - - logAdd("
fgItemRunDialdigit

"); - logAddFgItem($fgItem); - logAdd("
"); - - 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
"); - 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."
"); - $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."
"); - $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("
fgItemRunDialplanCheckvar

"); - logAddFgItem($fgItem); - logAdd("
"); - - 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("
"); - logAdd("varvalue: ".$varvalue." => "); - logAdd("agiVarGet(".strtoupper($varname)."): ".$response."
"); - if ($response == $varvalue) { - - logAdd("
fgItemRunDialplanCheckvar

"); - logAddFgItem($fgItem); - logAdd("
"); - - $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("
fgItemRunDialExtension

"); - logAddFgItem($fgItem); - logAdd("
"); - - 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."
"); - - 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("
fgItemRunDialGroupExtension

"); - logAddFgItem($fgItem); - logAdd("
"); - - 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."
"); - - 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("
fgItemRunDialplanGosub

"); - logAddFgItem($fgItem); - logAdd("
"); - - 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("
fgItemRunDialplanSetvar

"); - logAddFgItem($fgItem); - logAdd("
"); - - 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('
fgItemRunDigit

'); - logAddFgItem($fgItem); - logAdd("
"); - - 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("
fgItemRunDigitInvalid

"); - logAddFgItem($fgItem); - logAdd("
"); - - logIVRAddFgItemLast($fgItem); - logIVRAddFgItem($fgItem); - - fgItemRunNextFrom($fgItem); - -} - -function fgItemRunExpedienteCheck($fgItem = array()) { - - logAdd("
fgItemRunExpedienteCheck

"); - logAddFgItem($fgItem); - logAdd("
"); - - 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
"; - logAdd("isTrue: Yes
"); - } else { - $result[] = "Is False"; - logAdd("isTrue: No
"); - } - - $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("
fgItemRunExpedienteFalse

"); - logAddFgItem($fgItem); - logAdd("
"); - - logIVRAddFgItemLast($fgItem); - logIVRAddFgItem($fgItem); - - fgItemRunNextFrom($fgItem); - -} - -function fgItemRunExpedienteTrue($fgItem = array()) { - - logAdd("
fgItemRunExpedienteTrue

"); - logAddFgItem($fgItem); - logAdd("
"); - - logIVRAddFgItemLast($fgItem); - logIVRAddFgItem($fgItem); - - fgItemRunNextFrom($fgItem); - -} - -function fgItemRunFeriadoCheck($fgItem = array()) { - - logAdd("
fgItemRunFeriadoCheck

"); - logAddFgItem($fgItem); - logAdd("
"); - - 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
"); - } else { - $result[] = 'Is False'; - logAdd("isTrue: No
"); - } - - $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("
fgItemRunFeriadoFalse

"); - logAddFgItem($fgItem); - logAdd("
"); - - logIVRAddFgItemLast($fgItem); - logIVRAddFgItem($fgItem); - - fgItemRunNextFrom($fgItem); - -} - -function fgItemRunFeriadoTrue($fgItem = array()) { - - logAdd("
fgItemRunFeriadoTrue

"); - logAddFgItem($fgItem); - logAdd("
"); - - logIVRAddFgItemLast($fgItem); - logIVRAddFgItem($fgItem); - - fgItemRunNextFrom($fgItem); - -} - -function fgItemRunIVRRedirect($fgItem = array()) { - - logAdd("
fgItemRunIVRRedirect

"); - logAddFgItem($fgItem); - logAdd("
"); - - 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."
"); - if (file_exists($target)) { - - logAdd("target exists
"); - $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
"); - $result[] = 'Target not found: ' . $target; - logIVRAddFgItem($fgItem,$result); - - } - - } else { - - $result[] = 'Empty value (DID) to redirect'; - logIVRAddFgItem($fgItem,$result); - - } - -} - -function fgItemRunNoMatch($fgItem = array()) { - - logAdd("
fgItemRunNoMatch

"); - logAddFgItem($fgItem); - logAdd("
"); - - logIVRAddFgItemLast($fgItem); - logIVRAddFgItem($fgItem); - - fgItemRunNextFrom($fgItem); - -} - -function fgItemRunPesqSat($fgItem = array()) { - - logAdd("
fgItemRunPesqSat ???

"); - logAddFgItem($fgItem); - logAdd("
"); - - 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("
fgItemRunPlayaudio

"); - logAddFgItem($fgItem); - logAdd("
"); - - 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'] . "
"); - $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("
fgItemRunQueue

"); - logAddFgItem($fgItem); - logAdd("
"); - - 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("
fgItemRunQueueWaitingCount

"); - logAddFgItem($fgItem); - logAdd("
"); - - 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("
fgItemRunQueueWaitingCountGreater

"); - logAddFgItem($fgItem); - logAdd("
"); - - logIVRAddFgItemLast($fgItem); - logIVRAddFgItem($fgItem); - - fgItemRunNextFrom($fgItem); - -} - -function fgItemRunQueueWithCallback($fgItem = array()) { - - logAdd("
fgItemRunQueueWithCallback

"); - logAddFgItem($fgItem); - logAdd("
"); - - 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
'); - $queue_status = agiRunQueue(array('id' => $fgItem['value'],'timeout' => $timeout)); - $result[] = 'queue_status: ' . $queue_status; - if ($queue_status == 'stopivr') { - // logAdd('===> agiRunQueue stopivr
'); - $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("
fgItemRunQueueWithCallbackNoReady

"); - logAddFgItem($fgItem); - logAdd("
"); - - logIVRAddFgItemLast($fgItem); - logIVRAddFgItem($fgItem); - - fgItemRunNextFrom($fgItem); - -} - -function fgItemRunRecord($fgItem = array()) { - - logAdd("
fgItemRunRecord

"); - logAddFgItem($fgItem); - logAdd("
"); - - 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("
fgItemRunStart

"); - logAddFgItem($fgItem); - logAdd("
"); - - 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("
fgItemRunTimeout

"); - logAddFgItem($fgItem); - logAdd("
"); - - 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("
fgItemRunTimeoutWithLimit

"); - logAddFgItem($fgItem); - logAdd("
"); - - 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']]."
"); - - 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("
fgItemRunTimeoutWithLimitLimit

"); - logAddFgItem($fgItem); - logAdd("
"); - - logIVRAddFgItemLast($fgItem); - logIVRAddFgItem($fgItem); - - fgItemRunNextFrom($fgItem); - -} - -function fgItemRunVoicemail($fgItem = array()) { - - logAdd("
fgItemRunVoicemail

"); - logAddFgItem($fgItem); - logAdd("
"); - - 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("
fgItemRunWhitelistCheck

"); - logAddFgItem($fgItem); - logAdd("
"); - - 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."
"); - - $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("
fgItemRunWhitelistFalse

"); - logAddFgItem($fgItem); - logAdd("
"); - - logIVRAddFgItemLast($fgItem); - logIVRAddFgItem($fgItem); - - fgItemRunNextFrom($fgItem); - -} - -function fgItemRunWhitelistTrue($fgItem = array()) { - - logAdd("
fgItemRunWhitelistTrue

"); - logAddFgItem($fgItem); - logAdd("
"); - - 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."
"); - - 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
"); - $query = "SELECT * FROM tab_ramal LIMIT 1"; - $result = mysqli_query($db,$query); - logAdd($query."
"); - $result = mysqli_query($GLOBALS['db'],$query); - logAdd($query."
"); - */ - - // ... - - /* - $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(); -?> \ No newline at end of file diff --git a/apagar/AGIEntrada-log.html b/apagar/AGIEntrada-log.html deleted file mode 100644 index 8c4c19f..0000000 --- a/apagar/AGIEntrada-log.html +++ /dev/null @@ -1,70 +0,0 @@ -2024-12-12 13:48:24
Array
-(
-    [fgId] => 7998
-    [logEnabled] => 1
-    [isXampp] => 1
-)
-

Array
-(
-    [fgId] => 7998
-    [logEnabled] => 1
-    [isXampp] => 1
-    [fgItens] => Array
-        (
-            [1] => Array
-                (
-                    [id] => 1
-                    [idmaster] => 0
-                    [cmd] => start
-                    [value] => 7999
-                )
-
-            [2] => Array
-                (
-                    [id] => 2
-                    [idmaster] => 1
-                    [cmd] => playaudio
-                    [value] => welcome.wav
-                    [value2] => 2
-                    [value3] => 1
-                    [value4] => false
-                )
-
-            [3] => Array
-                (
-                    [id] => 3
-                    [idmaster] => 2
-                    [cmd] => timeout
-                    [value] => 
-                )
-
-            [4] => Array
-                (
-                    [id] => 4
-                    [idmaster] => 3
-                    [cmd] => playaudio
-                    [value] => timeout.wav
-                    [value2] => 2
-                    [value3] => 1
-                    [value4] => false
-                )
-
-        )
-
-    [fgItemStart] => Array
-        (
-            [id] => 1
-            [idmaster] => 0
-            [cmd] => start
-            [value] => 7999
-        )
-
-)
-


fgItemRun

Array
-(
-    [id] => 1
-    [idmaster] => 0
-    [cmd] => start
-    [value] => 7999
-)
-

\ No newline at end of file diff --git a/apagar/AGIEntrada.php b/apagar/AGIEntrada.php deleted file mode 100644 index fb0b8c7..0000000 --- a/apagar/AGIEntrada.php +++ /dev/null @@ -1,482 +0,0 @@ -globais = $globais; - $this->injection = $injection; - } - - public function agiRunCmd($command) - { - return $this->injection['agiRunCmd']($command); - } - - public function agiLog($texto) - { - return $this->injection['agiLog']($texto); - } - - // -------------------------------------------------------------------------------------------------------------------------------- - - public function logStart() - { - if ($this->globais['logEnabled']) { - $texto = date("Y-m-d H:i:s") . "
"; - $fp = fopen('log.html', 'w'); - fwrite($fp, $texto); - fclose($fp); - } - } - - public function logAdd($texto) - { - if ($this->globais['logEnabled']) { - $fp = fopen('log.html', 'a'); - fwrite($fp, $texto); - fclose($fp); - } - } - - // -------------------------------------------------------------------------------------------------------------------------------- - - public function agiVarGet($varName = '') - { - - $return = ''; - - if ($this->globais['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 = $this->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; - } - - public function agiVarSet($varName = '', $varValue = '') - { - - if ($this->globais['isXampp']) { - - return ''; - } else { - - if ($varName == 'CALLERID') { - $varName = 'CALLERID(num)'; - } - $return = $this->agiRunCmd('SET VARIABLE ' . $varName . ' ' . $varValue); - return $return; - } - } - - // -------------------------------------------------------------------------------------------------------------------------------- - - public function fgItemRunPlayaudio($fgItem = array()) - { - - $this->logAdd("
fgItemRunPlayaudio

"); - $this->logAdd("
" . print_r($fgItem, true) . "

"); - } - - public function fgItemRun($fgItem = array()) - { - - $this->logAdd("
fgItemRun

"); - $this->logAdd("
" . print_r($fgItem, true) . "

"); - - 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') { - $this->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; - // } - // } - - } - } - - public function teste() - { - $this->agiLog($this->globais['fgId']); - } - - function tocarFila($queueId, $timeout) - { - return $this->agiRunCmd('EXEC Queue Q' . $queueId . ',ctT,,,' . $timeout); - } - - // -------------------------------------------------------------------------------------------------------------------------------- - - public function run() - { - $this->logStart(); - $this->logAdd("
".print_r($this->globais, true) . "

"); - // $this->agiLog(print_r($this->globais, true) . "\n"); - $this->globais['fgItens'] = array(); - $this->globais['fgItemStart'] = array(); - if ($this->globais['fgId'] != '') { - // ... - if (file_exists('/etc/asterisk')) { - $target = '/var/www/html/fluxograma/data-json/' . $this->globais['fgId'] . '.json'; - } else { - $target = 'dial/' . $this->globais['fgId'] . '.json'; - } - if (file_exists($target)) { - $itens = file_get_contents($target); - $itens = json_decode($itens, true); - foreach ($itens as $item) { - $this->globais['fgItens'][$item['id']] = $item; - if ($item['cmd'] == 'start') { - $this->globais['fgItemStart'] = $item; - } - } - unset($itens); - } - } - $this->logAdd("
".print_r($this->globais['fgItens'], true) . "

"); - $this->logAdd("
".print_r($this->globais['fgItemStart'], true) . "

"); - // $this->agiLog(print_r($this->globais['fgItens'], true) . "\n"); - - if (count($this->globais['fgItemStart']) > 0) { - - $this->globais['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 ($this->globais['isXampp']) { - - $this->globais['callerid'] = '1138118400'; - $this->globais['uniqueid'] = date("Ymd") . "." . date("His"); - $this->globais['digitado'] = ''; - - $host = 'localhost'; - $user = 'root'; - $password = ''; - $database = 'hitpbx_homologacao'; - $port = '3306'; - $this->globais['db'] = mysqli_connect($host, $user, $password, $database, $port) or die('Erro de conexão com o banco de dados'); - mysqli_set_charset($this->globais['db'], 'utf8'); - - $this->fgItemRun($this->globais['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'; - $this->globais['db'] = mysqli_connect($host, $user, $password, $database, $port) or die('Erro de conexão com o banco de dados'); - mysqli_set_charset($this->globais['db'], 'utf8'); - - /* - logAdd("111
"); - $query = "SELECT * FROM tab_ramal LIMIT 1"; - $result = mysqli_query($db,$query); - logAdd($query."
"); - $result = mysqli_query($GLOBALS['db'],$query); - logAdd($query."
"); - */ - - // ... - - /* - $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 = $this->agiRunCmd('EXEC NOOP HITAGI'); - $response = $this->agiRunCmd('ANSWER'); - $response = $this->agiRunCmd('EXEC WAIT 1'); - $response = $this->agiRunCmd('EXEC PLAYBACK beep'); - $response = $this->agiRunCmd('EXEC WAIT 1'); - - $this->globais['digitado'] = ''; - - $this->globais['callerid'] = $this->agiVarGet('CALLERID'); - $this->globais['uniqueid'] = $this->agiVarGet('UNIQUEID'); - - $response = $this->agiVarSet('AGIDID', $this->globais['fgId']); - - $cmd = 'EXEC QUEUELOG NONE,' . $this->globais['uniqueid'] . ',NONE,INFO|IVRSTART'; - $response = $this->agiRunCmd($cmd); - - $cmd = 'EXEC QUEUELOG NONE,' . $this->globais['uniqueid'] . ',NONE,INFO|IVRAPPEND|->' . $this->globais['fgId']; - $response = $this->agiRunCmd($cmd); - - $this->fgItemRun($this->globais['fgItemStart']); - - // 1353461660|1353461627.33271|NONE|NONE|INFO|IVRHANGUP| - //$cmd = 'EXEC QUEUELOG NONE,' . $GLOBALS['uniqueid'] . ',NONE,NONE,INFO|IVRHANGUP'; - //$response = agiRunCmd($cmd); - - // $response = agiRunCmd('HANGUP'); - - } - } - - /* - $this->teste(); - $this->globais['nomeFila'] = '10'; - $response = $this->tocarFila($this->globais['nomeFila'], 1); - echo "\n" . $response . "\n"; - */ - } -} diff --git a/apagar/dial/7998.json b/apagar/dial/7998.json deleted file mode 100644 index a2dfe5b..0000000 --- a/apagar/dial/7998.json +++ /dev/null @@ -1,32 +0,0 @@ -[ - { - "id": "1", - "idmaster": "0", - "cmd": "start", - "value": "7999" - }, - { - "id": "2", - "idmaster": "1", - "cmd": "playaudio", - "value": "welcome.wav", - "value2": "2", - "value3": "1", - "value4": "false" - }, - { - "id": "3", - "idmaster": "2", - "cmd": "timeout", - "value": "" - }, - { - "id": "4", - "idmaster": "3", - "cmd": "playaudio", - "value": "timeout.wav", - "value2": "2", - "value3": "1", - "value4": "false" - } -] \ No newline at end of file diff --git a/apagar/dial/7999.json b/apagar/dial/7999.json deleted file mode 100644 index 83ffb5b..0000000 --- a/apagar/dial/7999.json +++ /dev/null @@ -1,53 +0,0 @@ -[ - { - "id": "1", - "idmaster": "0", - "cmd": "start", - "value": "7999" - }, - { - "id": "2", - "idmaster": "1", - "cmd": "playaudio", - "value": "welcome.wav", - "value2": "2", - "value3": "1", - "value4": "false" - }, - { - "id": "3", - "idmaster": "2", - "cmd": "timeout", - "value": "" - }, - { - "id": "4", - "idmaster": "3", - "cmd": "playaudio", - "value": "timeout.wav", - "value2": "2", - "value3": "1", - "value4": "false" - }, - { - "id": "5", - "idmaster": "2", - "cmd": "dialdigit", - "value": "" - }, - { - "id": "6", - "idmaster": "2", - "cmd": "digit", - "value": "2" - }, - { - "id": "7", - "idmaster": "6", - "cmd": "playaudio", - "value": "digit-2.wav", - "value2": "2", - "value3": "1", - "value4": "false" - } -] \ No newline at end of file diff --git a/apagar/hitagi-entrada-log.txt b/apagar/hitagi-entrada-log.txt deleted file mode 100644 index 85f2da0..0000000 --- a/apagar/hitagi-entrada-log.txt +++ /dev/null @@ -1,100 +0,0 @@ -Array -( - [fgId] => 7998 - [logEnabled] => 1 - [isxampp] => 1 - [isXampp] => -) - -Array -( - [1] => Array - ( - [id] => 1 - [idmaster] => 0 - [cmd] => start - [value] => 7999 - ) - - [2] => Array - ( - [id] => 2 - [idmaster] => 1 - [cmd] => playaudio - [value] => welcome.wav - [value2] => 2 - [value3] => 1 - [value4] => false - ) - - [3] => Array - ( - [id] => 3 - [idmaster] => 2 - [cmd] => timeout - [value] => - ) - - [4] => Array - ( - [id] => 4 - [idmaster] => 3 - [cmd] => playaudio - [value] => timeout.wav - [value2] => 2 - [value3] => 1 - [value4] => false - ) - -) - -Array -( - [fgId] => 7998 - [logEnabled] => 1 - [isxampp] => 1 - [isXampp] => -) - -Array -( - [1] => Array - ( - [id] => 1 - [idmaster] => 0 - [cmd] => start - [value] => 7999 - ) - - [2] => Array - ( - [id] => 2 - [idmaster] => 1 - [cmd] => playaudio - [value] => welcome.wav - [value2] => 2 - [value3] => 1 - [value4] => false - ) - - [3] => Array - ( - [id] => 3 - [idmaster] => 2 - [cmd] => timeout - [value] => - ) - - [4] => Array - ( - [id] => 4 - [idmaster] => 3 - [cmd] => playaudio - [value] => timeout.wav - [value2] => 2 - [value3] => 1 - [value4] => false - ) - -) - diff --git a/apagar/hitagi-entrada.php b/apagar/hitagi-entrada.php deleted file mode 100644 index 98767b5..0000000 --- a/apagar/hitagi-entrada.php +++ /dev/null @@ -1,54 +0,0 @@ - EXECUTAR COMANDO $command"; - return $texto; - }; -} - -function agiLogWrapper($logEnabled) -{ - return function ($texto) use ($logEnabled) { - if ($logEnabled) { - $filename = str_replace('.php', '-log.txt', __FILE__); - $fp = fopen($filename, 'a'); - fwrite($fp, $texto); - fclose($fp); - } - }; -} - -// -------------------------------------------------------------------------------------------------------------------------------- - -$stdin = fopen('php://stdin', 'r'); -$stdout = fopen('php://stdout', 'w'); - -$fgId = (isset($argv[1])) ? $argv[1] : ''; // DID - -$logEnabled = true; -$isXampp = (file_exists('C:\xampp')); - -$appdir = dirname(__FILE__); -chdir($appdir); - -date_default_timezone_set('America/Bahia'); - -$agientrada = new AGIEntrada( - array( - 'agiRunCmd' => agiRunCmdWrapper($stdin, $stdout), - 'agiLog' => agiLogWrapper($logEnabled) - ), - array( - 'fgId' => $fgId, - 'logEnabled' => $logEnabled, - 'isXampp' => $isXampp - ) -); -$agientrada->run(); - -fclose($stdin); -fclose($stdout); -exit(); diff --git a/apagar/log.html b/apagar/log.html deleted file mode 100644 index 016a7e9..0000000 --- a/apagar/log.html +++ /dev/null @@ -1,62 +0,0 @@ -2024-12-12 13:50:55
Array
-(
-    [fgId] => 7998
-    [logEnabled] => 1
-    [isXampp] => 1
-)
-

Array
-(
-    [1] => Array
-        (
-            [id] => 1
-            [idmaster] => 0
-            [cmd] => start
-            [value] => 7999
-        )
-
-    [2] => Array
-        (
-            [id] => 2
-            [idmaster] => 1
-            [cmd] => playaudio
-            [value] => welcome.wav
-            [value2] => 2
-            [value3] => 1
-            [value4] => false
-        )
-
-    [3] => Array
-        (
-            [id] => 3
-            [idmaster] => 2
-            [cmd] => timeout
-            [value] => 
-        )
-
-    [4] => Array
-        (
-            [id] => 4
-            [idmaster] => 3
-            [cmd] => playaudio
-            [value] => timeout.wav
-            [value2] => 2
-            [value3] => 1
-            [value4] => false
-        )
-
-)
-

Array
-(
-    [id] => 1
-    [idmaster] => 0
-    [cmd] => start
-    [value] => 7999
-)
-


fgItemRun

Array
-(
-    [id] => 1
-    [idmaster] => 0
-    [cmd] => start
-    [value] => 7999
-)
-

\ No newline at end of file diff --git a/classes/AGIEntrada.php b/classes/AGIEntrada.php new file mode 100644 index 0000000..b8b8b82 --- /dev/null +++ b/classes/AGIEntrada.php @@ -0,0 +1,2983 @@ +globais = $globais; + $this->injection = $injection; + } + + public function agiRunCmd($command) + { + $this->agiLog("===> " . __FUNCTION__ . " <==="); + $this->agiLog($command); + $return = ''; + if ($this->globais['isXampp']) { + $return = '200 result=1 (isXampp)'; + } else { + $return = $this->injection['agiRunCmd']($command); + } + $this->agiLog($return); + return $return; + } + + public function agiLog($texto) + { + return $this->injection['agiLog']($texto); + } + + // -------------------------------------------------------------------------------------------------------------------------------- + + public function logStart() + { + if ($this->globais['logEnabled']) { + $texto = date("Y-m-d H:i:s") . "
"; + $target = $this->globais['appdir'] . DIRECTORY_SEPARATOR . 'log' . DIRECTORY_SEPARATOR . 'log.html'; + $fp = fopen($target, 'w'); + fwrite($fp, $texto); + fclose($fp); + } + } + + public function logAdd($texto) + { + if ($this->globais['logEnabled']) { + $target = $this->globais['appdir'] . DIRECTORY_SEPARATOR . 'log' . DIRECTORY_SEPARATOR . 'log.html'; + $fp = fopen($target, 'a'); + fwrite($fp, $texto); + fclose($fp); + } + } + + // -------------------------------------------------------------------------------------------------------------------------------- + + public function fgGet() + { + $this->globais['fgItens'] = array(); + $this->globais['fgItemStart'] = array(); + if ($this->globais['fgId'] != '') { + if ($this->globais['asteriskip'] != '') { + // http://177.107.205.248/fluxograma/data-json/8999.json + $target = 'http://' . $this->globais['asteriskip'] . '/fluxograma/data-json/' . $this->globais['fgId'] . '.json'; + } else { + if (file_exists('/etc/asterisk')) { + $target = '/var/www/html/fluxograma/data-json/' . $this->globais['fgId'] . '.json'; + } else { + $target = 'dial/' . $this->globais['fgId'] . '.json'; + } + } + $itens = file_get_contents($target); + if ($itens !== false) { + $itens = json_decode($itens, true); + foreach ($itens as $item) { + $this->globais['fgItens'][$item['id']] = $item; + if ($item['cmd'] == 'start') { + $this->globais['fgItemStart'] = $item; + } + } + unset($itens); + } + } + } + + // -------------------------------------------------------------------------------------------------------------------------------- + + public function agiAddCallback($args = array()) + { + // $this->agiLog("===> " . __FUNCTION__ . " <==="); + // $this->agiLog(print_r($args, true)); + + // 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); + } + } + + public function agiRecordFilaIfAuditoria($args = array()) + { + // $this->agiLog("===> " . __FUNCTION__ . " <==="); + // $this->agiLog(print_r($args, true)); + $return = ''; + $args['idqueue'] = isset($args['idqueue']) ? $args['idqueue'] : ''; + $gravar = $this->hitpbxCheckAuditoria(array('idqueue' => $args['idqueue'])); + if ($gravar) { + $response = $this->agiRunRecord(array('tipo' => 'auditoria_fila', 'idqueue' => $args['idqueue'])); + } + return $return; + } + + public function agiRecordRamaisIfAuditoria($args = array()) + { + // $this->agiLog("===> " . __FUNCTION__ . " <==="); + // $this->agiLog(print_r($args, true)); + $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 = $this->hitpbxCheckAuditoria(array('ramal' => $ramal)); + if ($gravar) { + //$response = agiRunCmd('EXEC NOOP SIM'.$ramal); + $response = $this->agiRunRecord(array('tipo' => 'auditoria_ramal', 'ramal' => $ramal)); + } else { + //$response = agiRunCmd('EXEC NOOP NAO'.$ramal); + } + } + return $return; + } + + public function agiRunDialNumeroExterno($numero = '') + { + // $this->agiLog("===> " . __FUNCTION__ . " <==="); + // $this->agiLog($numero); + $return = ''; + + //$cmd = 'EXEC Dial SIP/SER2105/'.$numero.',30,Tt ""'; + $cmd = 'EXEC Dial Local/' . $numero . '@checksaida,30,Tt ""'; + $response = $this->agiRunCmd($cmd); + + $cmd = 'GET VARIABLE DIALSTATUS'; + $response = $this->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 = $this->agiRunCmd($cmd); + } + } + + return $return; + } + + public function agiRunDialRamal($ramal = '') + { + // $this->agiLog("===> " . __FUNCTION__ . " <==="); + // $this->agiLog($ramal); + + $return = ''; + + $runNext = true; + + $desvio = $this->hitpbxGetDesvioFrom(array('tipo' => 'ramal', 'value' => $ramal)); + if (count($desvio)) { + $runNext = false; + if ($desvio['shortname'] == 'numeroexterno') { + $return = $this->agiRunDialNumeroExterno($desvio['numero']); + } + if ($desvio['shortname'] == 'queue') { + $queuestatus = $this->agiRunQueue(array('id' => $desvio['queue'])); + if ($queuestatus == '') { + $return = 'ANSWER'; + } + } + if ($desvio['shortname'] == 'ramal') { + $return = $this->agiRunDialRamal($desvio['ramal']); + } + if ($desvio['shortname'] == 'voicemail') { + $this->agiRunVoicemail($desvio['ramal']); + $return = 'ANSWER'; + } + if ($desvio['shortname'] == 'numeroexterno') { + $this->agiRunDialNumeroExterno($desvio['numero']); + } + } + + if ($runNext) { + + $ramais_vai_tocar = array(); + + $cmd = 'EXEC Dial '; + + $ramais_secretaria = $this->hitpbxGetRamaisSecretariaFromRamal($ramal); + if (count($ramais_secretaria)) { + foreach ($ramais_secretaria as $ramal) { + + $response = $this->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 = $this->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 = $this->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 = $this->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 = $this->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 = $this->agiRecordRamaisIfAuditoria(array('ramais' => $ramais_vai_tocar)); + $response = $this->agiRunCmd($cmd); + // ... + + //$argssend["operationStatus"] = "hangup"; + //crmSend($argssend); + + $cmd = 'GET VARIABLE DIALSTATUS'; + $response = $this->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 = $this->agiRunCmd($cmd); + $callback = $this->hitpbxGetCallbackFromRamal($ramal); + if ($callback == '1') { + $callerid = $this->agiVarGet('CALLERID'); + $arr = array( + 'ramal' => $ramal, + 'numero' => $callerid + ); + $this->agiAddCallback($arr); + } + } + } + } + + return $return; + } + + public function agiRunDialRamalGrupo($callgroup = '') + { + // $this->agiLog("===> " . __FUNCTION__ . " <==="); + // $this->agiLog($callgroup); + + $return = ''; + + $runNext = true; + + $desvio = $this->hitpbxGetDesvioFrom(array('tipo' => 'ramalgrupo', 'value' => $callgroup)); + if (count($desvio)) { + $runNext = false; + if ($desvio['shortname'] == 'queue') { + $queuestatus = $this->agiRunQueue(array('id' => $desvio['queue'])); + if ($queuestatus == '') { + $return = 'ANSWER'; + } + } + if ($desvio['shortname'] == 'ramal') { + $return = $this->agiRunDialRamal($desvio['ramal']); + } + if ($desvio['shortname'] == 'ramalgrupo') { + $return = $this->agiRunDialRamalGrupo($desvio['callgroup']); + } + if ($desvio['shortname'] == 'voicemail') { + $this->agiRunVoicemail($desvio['ramal']); + $return = 'ANSWER'; + } + if ($desvio['shortname'] == 'numeroexterno') { + $this->agiRunDialNumeroExterno($desvio['numero']); + } + } + + if ($runNext) { + + $ramais_vai_tocar = array(); + + $cmd = 'EXEC Dial '; + $query = "SELECT ramal FROM tab_ramal WHERE callgroup = '" . mysqli_real_escape_string($this->globais['db'], $callgroup) . "'"; + $query_result = mysqli_query($this->globais['db'], $query) or die(mysqli_error($this->globais['db'])); + while ($resultLinha = mysqli_fetch_assoc($query_result)) { + if ($cmd != 'EXEC Dial ') { + $cmd .= '&'; + } + $cmd .= 'PJSIP/' . $resultLinha['ramal']; + $ramais_vai_tocar[] = $resultLinha['ramal']; + } + $cmd .= ' ""'; + + $response = $this->agiRecordRamaisIfAuditoria(array('ramais' => $ramais_vai_tocar)); + $response = $this->agiRunCmd($cmd); + + $cmd = 'GET VARIABLE DIALSTATUS'; + $response = $this->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 = $this->agiRunCmd($cmd); + } + } + } + + return $return; + } + + public function agiRunQueue($args = array()) + { + // $this->agiLog("===> " . __FUNCTION__ . " <==="); + // $this->agiLog(print_r($args, true)); + + $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 = $this->agiRunCmd($cmd); + + $queuenome = $this->hitpbxGetQueuenomeFromId($args['id']); + $cmd = 'SET VARIABLE __AGIQUEUENOME "' . $queuenome . '"'; + $response = $this->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") . "_" . $this->globais['uniqueid'] . "_" . $this->globais['callerid'] . "_" . $this->globais['fgId']; + $response = $this->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") . "_" . $this->globais['uniqueid'] . "_" . $this->globais['callerid'] . "_" . $this->globais['fgId']; + $response = $this->agiRunCmd($cmd); + + $desvio = $this->hitpbxGetDesvioFrom(array('tipo' => 'queue', 'value' => $args['id'])); + + if ($this->globais['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', 'numero' => '551138118400'); + } + } + + if (count($desvio)) { + // logAdd("desvio: ".json_encode($desvio)."
"); + $runNext = false; + if ($desvio['shortname'] == 'queue') { + $return = $this->agiRunQueue(array('id' => $desvio['queue'])); + } + if ($desvio['shortname'] == 'ramal') { + $response = $this->agiRunDialRamal($desvio['ramal']); + if ($response == 'ANSWER') { + $return = ''; + } + } + if ($desvio['shortname'] == 'voicemail') { + $this->agiRunVoicemail($desvio['ramal']); + $return = ''; + } + if ($desvio['shortname'] == 'numeroexterno') { + $this->agiRunDialNumeroExterno($desvio['numero']); + } + } + + if ($runNext) { + + // $response = agiRunCmd('SET VARIABLE GLOBAL(AGIIVRSTOP) NAO'); + $response = $this->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 = $this->agiRecordFilaIfAuditoria(array('idqueue' => $args['id'])); + $response = $this->agiRunCmd($cmd); + + $cmd = 'GET VARIABLE QUEUESTATUS'; + $response = $this->agiRunCmd($cmd); + // $this->logAdd('GET VARIABLE QUEUESTATUS: ' . $response . '
'); + + if ($this->globais['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 = $this->agiVarGet("AGIIVRSTOP"); + $agiivrstop = str_replace('"', '', $agiivrstop); + // logAdd('AGIIVRSTOP: '.$agiivrstop.'
'); + if ($agiivrstop == 'SIM') { + // logAdd('FOI SIM
'); + $return = 'stopivr'; + } + // ... + + } + + return $return; + } + + public function agiRunRecord($args = array()) + { + // $this->agiLog("===> " . __FUNCTION__ . " <==="); + // $this->agiLog(print_r($args, true)); + + /* + 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 = $this->agiVarGet('UNIQUEID'); + $callerid = $this->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 = $this->agiRunCmd($cmd); + } + } + if ($args['tipo'] == 'auditoria_ramal') { + $args['ramal'] = isset($args['ramal']) ? $args['ramal'] : ''; + if (is_numeric($args['ramal'])) { + $uniqueid = $this->agiVarGet('UNIQUEID'); + $callerid = $this->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 = $this->agiRunCmd($cmd); + } + } + return $return; + } + + public function agiRunVoicemail($ramal = '') + { + // $this->agiLog("===> " . __FUNCTION__ . " <==="); + // $this->agiLog($ramal); + $return = $this->agiRunCmd('EXEC VOICEMAIL ' . $ramal); + return $return; + } + + public function agiVarGet($varName = '') + { + // $this->agiLog("===> " . __FUNCTION__ . " <==="); + // $this->agiLog($varName); + + $return = ''; + + if ($this->globais['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 = $this->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; + } + + public function agiVarSet($varName = '', $varValue = '') + { + // $this->agiLog("===> " . __FUNCTION__ . " <==="); + // $this->agiLog($varName); + // $this->agiLog($varValue); + if ($this->globais['isXampp']) { + return ''; + } else { + if ($varName == 'CALLERID') { + $varName = 'CALLERID(num)'; + } + $return = $this->agiRunCmd('SET VARIABLE ' . $varName . ' ' . $varValue); + return $return; + } + } + + // -------------------------------------------------------------------------------------------------------------------------------- + + public function fgItemGetChildrenFrom($fgItemFrom = array()) + { + // $this->agiLog("===> " . __FUNCTION__ . " <==="); + // $this->agiLog(print_r($fgItemFrom, true)); + $return = array(); + reset($this->globais['fgItens']); + foreach ($this->globais['fgItens'] as $fgItem) { + if ($fgItem['cmd'] != 'start') { + if ($fgItem['idmaster'] == $fgItemFrom['id']) { + $return[$fgItem['id']] = $fgItem; + } + } + } + return $return; + } + + public function fgItemGetMasterFrom($fgItemFrom = array()) + { + // $this->agiLog("===> " . __FUNCTION__ . " <==="); + // $this->agiLog(print_r($fgItemFrom, true)); + $return = array(); + if (isset($this->globais['fgItens'][$fgItemFrom['idmaster']])) { + $return = $this->globais['fgItens'][$fgItemFrom['idmaster']]; + } + return $return; + } + + public function fgItemIsDialplanCheckvar($fgItem = array()) + { + // $this->agiLog("===> " . __FUNCTION__ . " <==="); + // $this->agiLog(print_r($fgItem, true)); + if (isset($fgItem['defaultvalues']['cmd'])) { + if ($fgItem['defaultvalues']['cmd'] == 'dialplan.checkvar') { + return true; + } + } + if ($fgItem['cmd'] == 'dialplan.checkvar') { + return true; + } + return false; + } + + public function fgItemRun($fgItem = array()) + { + // $this->agiLog("===> " . __FUNCTION__ . " <==="); + // $this->agiLog(print_r($fgItem, true)); + + $this->logAdd("
fgItemRun
"); + $this->logAdd("
" . print_r($fgItem, true) . "

"); + + // teste arquivoremoto + // $content = file_get_contents('/var/www/html/hitmanager/agi-debug.html'); + // $argssend = array(); + // $argssend['filedir'] = '/var/www/html/apagar'; + // $argssend['filename'] = 'teste.html'; + // $argssend['filebase64'] = base64_encode($content); + // $arquivo_removo = new ArquivoRemoto(); + // $response = $arquivo_removo->salvar($argssend); + // ... + + if (count($fgItem) > 0) { + + if ($fgItem['cmd'] == 'agi.exec') { + $this->fgItemRunAgiExec($fgItem); + return; + } + if ($fgItem['cmd'] == 'blacklist.check') { + $this->fgItemRunBlacklistCheck($fgItem); + return; + } + if ($fgItem['cmd'] == 'blacklist.true') { + $this->fgItemRunBlacklistTrue($fgItem); + return; + } + if ($fgItem['cmd'] == 'blacklist.false') { + $this->fgItemRunBlacklistFalse($fgItem); + return; + } + if ($fgItem['cmd'] == 'callerid.change') { + $this->fgItemRunCalleridChange($fgItem); + return; + } + if ($fgItem['cmd'] == 'cnpj.check') { + $this->fgItemRunCNPJCheck($fgItem); + return; + } + if ($fgItem['cmd'] == 'cnpj.true') { + $this->fgItemRunCNPJCheckTrue($fgItem); + return; + } + if ($fgItem['cmd'] == 'cnpj.false') { + $this->fgItemRunCNPJCheckFalse($fgItem); + return; + } + if ($fgItem['cmd'] == 'condtempo.check') { + $this->fgItemRunCondTempoCheck($fgItem); + return; + } + if ($fgItem['cmd'] == 'condtempo.true') { + $this->fgItemRunCondTempoCheckTrue($fgItem); + return; + } + if ($fgItem['cmd'] == 'condtempo.false') { + $this->fgItemRunCondTempoCheckFalse($fgItem); + return; + } + if ($fgItem['cmd'] == 'cpf.check') { + $this->fgItemRunCPFCheck($fgItem); + return; + } + if ($fgItem['cmd'] == 'cpf.true') { + $this->fgItemRunCPFCheckTrue($fgItem); + return; + } + if ($fgItem['cmd'] == 'cpf.false') { + $this->fgItemRunCPFCheckFalse($fgItem); + return; + } + if ($fgItem['cmd'] == 'dialextension') { + $this->fgItemRunDialExtension($fgItem); + return; + } + if ($fgItem['cmd'] == 'dialgroupextension') { + $this->fgItemRunDialGroupExtension($fgItem); + return; + } + if ($fgItem['cmd'] == 'dialplan.checkvar') { + $this->fgItemRunDialplanCheckvar($fgItem); + return; + } + if ($fgItem['cmd'] == 'dialplan.gosub') { + $this->fgItemRunDialplanGosub($fgItem); + return; + } + if ($fgItem['cmd'] == 'dialplan.setvar') { + $this->fgItemRunDialplanSetvar($fgItem); + return; + } + if ($fgItem['cmd'] == 'dialdigit') { + $this->fgItemRunDialdigit($fgItem); + return; + } + if ($fgItem['cmd'] == 'digit') { + $this->fgItemRunDigit($fgItem); + return; + } + if ($fgItem['cmd'] == 'digitinvalid') { + $this->fgItemRunDigitInvalid($fgItem); + return; + } + if ($fgItem['cmd'] == 'expediente.check') { + $this->fgItemRunExpedienteCheck($fgItem); + return; + } + if ($fgItem['cmd'] == 'expediente.false') { + $this->fgItemRunExpedienteFalse($fgItem); + return; + } + if ($fgItem['cmd'] == 'expediente.true') { + $this->fgItemRunExpedienteTrue($fgItem); + return; + } + if ($fgItem['cmd'] == 'feriado.check') { + $this->fgItemRunFeriadoCheck($fgItem); + return; + } + if ($fgItem['cmd'] == 'feriado.false') { + $this->fgItemRunFeriadoFalse($fgItem); + return; + } + if ($fgItem['cmd'] == 'feriado.true') { + $this->fgItemRunFeriadoTrue($fgItem); + return; + } + if ($fgItem['cmd'] == 'ivr.redirect') { + $this->fgItemRunIVRRedirect($fgItem); + return; + } + if ($fgItem['cmd'] == 'nomatch') { + $this->fgItemRunNoMatch($fgItem); + return; + } + if ($fgItem['cmd'] == 'pesqsat') { + $this->fgItemRunPesqSat($fgItem); + return; + } + if ($fgItem['cmd'] == 'playaudio') { + $this->fgItemRunPlayaudio($fgItem); + return; + } + if ($fgItem['cmd'] == 'queue') { + $this->fgItemRunQueue($fgItem); + return; + } + if ($fgItem['cmd'] == 'queue.waitingcount') { + $this->fgItemRunQueueWaitingCount($fgItem); + return; + } + if ($fgItem['cmd'] == 'queue.waitingcount-greater') { + $this->fgItemRunQueueWaitingCountGreater($fgItem); + return; + } + if ($fgItem['cmd'] == 'queue.withcallback') { + $this->fgItemRunQueueWithCallback($fgItem); + return; + } + if ($fgItem['cmd'] == 'queue.withcallback-noready') { + $this->fgItemRunQueueWithCallbackNoReady($fgItem); + return; + } + if ($fgItem['cmd'] == 'record') { + $this->fgItemRunRecord($fgItem); + return; + } + if ($fgItem['cmd'] == 'start') { + $this->fgItemRunStart($fgItem); + return; + } + if ($fgItem['cmd'] == 'timeout') { + $this->fgItemRunTimeout($fgItem); + return; + } + if ($fgItem['cmd'] == 'timeoutwithlimit') { + $this->fgItemRunTimeoutWithLimit($fgItem); + return; + } + if ($fgItem['cmd'] == 'timeoutwithlimit.limit') { + $this->fgItemRunTimeoutWithLimitLimit($fgItem); + return; + } + if ($fgItem['cmd'] == 'voicemail') { + $this->fgItemRunVoicemail($fgItem); + return; + } + if ($fgItem['cmd'] == 'whitelist.check') { + $this->fgItemRunWhitelistCheck($fgItem); + return; + } + if ($fgItem['cmd'] == 'whitelist.false') { + $this->fgItemRunWhitelistFalse($fgItem); + return; + } + if ($fgItem['cmd'] == 'whitelist.true') { + $this->fgItemRunWhitelistTrue($fgItem); + return; + } + if (isset($fgItem['defaultvalues']['cmd'])) { + if ($fgItem['defaultvalues']['cmd'] == 'dialplan.checkvar') { + $this->fgItemRunDialplanCheckvar($fgItem); + return; + } + if ($fgItem['defaultvalues']['cmd'] == 'dialplan.gosub') { + $this->fgItemRunDialplanGosub($fgItem); + return; + } + if ($fgItem['defaultvalues']['cmd'] == 'dialplan.setvar') { + $this->fgItemRunDialplanSetvar($fgItem); + return; + } + } + } + } + + public function fgItemRunAgiExec($fgItem = array()) + { + $this->agiLog("===> " . __FUNCTION__ . " <==="); + $this->agiLog(print_r($fgItem, true)); + + $this->logAdd("
fgItemRunAgiExec

"); + + $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 . '"'; + $response = $this->agiRunCmd($cmd); + + $this->fgItemRunNextFrom($fgItem); + } + + public function fgItemRunBlacklistCheck($fgItem = array()) + { + $this->agiLog("===> " . __FUNCTION__ . " <==="); + $this->agiLog(print_r($fgItem, true)); + + $this->logAdd("
fgItemRunBlacklistCheck

"); + + if ($this->globais['isXampp']) { + $rnd = rand(1, 100); + $esta_na_lista = ($rnd > 50) ? true : false; + } else { + $esta_na_lista = $this->hitpbxCheckBlacklist($this->globais['callerid']); + } + + $run_next = true; + + $cmdTarget = $esta_na_lista ? 'blacklist.true' : 'blacklist.false'; + $fgItemChildren = $this->fgItemGetChildrenFrom($fgItem); + foreach ($fgItemChildren as $fgItemChild) { + if ($run_next) { + if ($fgItemChild['cmd'] == $cmdTarget) { + $this->fgItemRun($fgItemChild); + $run_next = false; + } + } + } + } + + public function fgItemRunBlacklistFalse($fgItem = array()) + { + $this->agiLog("===> " . __FUNCTION__ . " <==="); + $this->agiLog(print_r($fgItem, true)); + $this->logAdd("
fgItemRunBlacklistFalse

"); + $this->fgItemRunNextFrom($fgItem); + } + + public function fgItemRunBlacklistTrue($fgItem = array()) + { + $this->agiLog("===> " . __FUNCTION__ . " <==="); + $this->agiLog(print_r($fgItem, true)); + $this->logAdd("
fgItemRunBlacklistTrue

"); + $this->fgItemRunNextFrom($fgItem); + } + + public function fgItemRunCalleridChange($fgItem = array()) + { + $this->agiLog("===> " . __FUNCTION__ . " <==="); + $this->agiLog(print_r($fgItem, true)); + $this->logAdd('
fgItemRunCalleridChange

'); + + $varname = 'CALLERID(num)'; + if (isset($fgItem['value2'])) { + if (trim($fgItem['value2']) != '') { + $varname = 'CALLERID(' . $fgItem['value2'] . ')'; + } + } + $varvalue = $fgItem['value']; + + $cmd = 'SET VARIABLE ' . $varname . ' ' . $varvalue; + $response = $this->agiRunCmd($cmd); + + $this->fgItemRunNextFrom($fgItem); + } + + public function fgItemRunCNPJCheck($fgItem = array()) + { + $this->agiLog("===> " . __FUNCTION__ . " <==="); + $this->agiLog(print_r($fgItem, true)); + $this->logAdd('
fgItemRunCNPJCheck

'); + + if ($this->globais['isXampp']) { + $rnd = rand(1, 100); + $validado = ($rnd > 50) ? true : false; + } else { + $validado = $this->validarCNPJ($this->globais['digitado']); + } + + $run_next = true; + + $cmdTarget = $validado ? 'cnpj.true' : 'cnpj.false'; + $fgItemChildren = $this->fgItemGetChildrenFrom($fgItem); + foreach ($fgItemChildren as $fgItemChild) { + if ($run_next) { + if ($fgItemChild['cmd'] == $cmdTarget) { + $this->fgItemRun($fgItemChild); + $run_next = false; + } + } + } + } + + public function fgItemRunCNPJCheckFalse($fgItem = array()) + { + $this->agiLog("===> " . __FUNCTION__ . " <==="); + $this->agiLog(print_r($fgItem, true)); + $this->logAdd("
fgItemRunCNPJCheckFalse

"); + $this->fgItemRunNextFrom($fgItem); + } + + public function fgItemRunCNPJCheckTrue($fgItem = array()) + { + $this->agiLog("===> " . __FUNCTION__ . " <==="); + $this->agiLog(print_r($fgItem, true)); + $this->logAdd("
fgItemRunCNPJCheckTrue

"); + $this->fgItemRunNextFrom($fgItem); + } + + public function fgItemRunCondTempoCheck($fgItem = array()) + { + $this->agiLog("===> " . __FUNCTION__ . " <==="); + $this->agiLog(print_r($fgItem, true)); + $this->logAdd('
fgItemRunCondTempoCheck

'); + + if ($this->globais['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($this->globais['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($this->globais['db'], $query); + if (mysqli_num_rows($query_result) > 0) { + $periodo_match = true; + } + } + + $run_next = true; + + $cmdTarget = $periodo_match ? 'condtempo.true' : 'condtempo.false'; + $fgItemChildren = $this->fgItemGetChildrenFrom($fgItem); + foreach ($fgItemChildren as $fgItemChild) { + if ($run_next) { + if ($fgItemChild['cmd'] == $cmdTarget) { + $this->fgItemRun($fgItemChild); + $run_next = false; + } + } + } + } + + public function fgItemRunCondTempoCheckFalse($fgItem = array()) + { + $this->agiLog("===> " . __FUNCTION__ . " <==="); + $this->agiLog(print_r($fgItem, true)); + $this->logAdd("
fgItemRunCondTempoCheckFalse

"); + $this->fgItemRunNextFrom($fgItem); + } + + public function fgItemRunCondTempoCheckTrue($fgItem = array()) + { + $this->agiLog("===> " . __FUNCTION__ . " <==="); + $this->agiLog(print_r($fgItem, true)); + $this->logAdd("
fgItemRunCondTempoCheckTrue

"); + $this->fgItemRunNextFrom($fgItem); + } + + public function fgItemRunCPFCheck($fgItem = array()) + { + $this->agiLog("===> " . __FUNCTION__ . " <==="); + $this->agiLog(print_r($fgItem, true)); + $this->logAdd('
fgItemRunCPFCheck

'); + + if ($this->globais['isXampp']) { + $rnd = rand(1, 100); + $validado = ($rnd > 50) ? true : false; + } else { + $validado = $this->validarCPF($this->globais['digitado']); + } + + $run_next = true; + + $cmdTarget = $validado ? 'cpf.true' : 'cpf.false'; + $fgItemChildren = $this->fgItemGetChildrenFrom($fgItem); + foreach ($fgItemChildren as $fgItemChild) { + if ($run_next) { + if ($fgItemChild['cmd'] == $cmdTarget) { + $this->fgItemRun($fgItemChild); + $run_next = false; + } + } + } + } + + public function fgItemRunCPFCheckFalse($fgItem = array()) + { + $this->agiLog("===> " . __FUNCTION__ . " <==="); + $this->agiLog(print_r($fgItem, true)); + $this->logAdd("
fgItemRunCPFCheckFalse

"); + $this->fgItemRunNextFrom($fgItem); + } + + public function fgItemRunCPFCheckTrue($fgItem = array()) + { + $this->agiLog("===> " . __FUNCTION__ . " <==="); + $this->agiLog(print_r($fgItem, true)); + $this->logAdd("
fgItemRunCPFCheckTrue

"); + $this->fgItemRunNextFrom($fgItem); + } + + public function fgItemRunDialdigit($fgItem = array()) + { + $this->agiLog("===> " . __FUNCTION__ . " <==="); + $this->agiLog(print_r($fgItem, true)); + $this->logAdd("
fgItemRunDialdigit

"); + + $run_next = true; + + $tamanho = strlen($this->globais['digitado']); + if (($tamanho != 3) && ($tamanho != 4)) { + $this->fgItemRunNextFrom($fgItem); + $run_next = false; + } + + if ($run_next) { + + $queue = $this->hitpbxGetQueueFromNumeroExterno(array('numero_externo' => $this->globais['digitado'])); + if (count($queue) > 0) { + $response = $this->agiRunQueue(array('id' => $queue['id'])); + $this->fgItemRunNextFrom($fgItem); + $run_next = false; + } + } + + if ($run_next) { + + $dialcontacts = ''; + $ramais_secretaria = $this->hitpbxGetRamaisSecretariaFromRamal($this->globais['digitado']); + if (count($ramais_secretaria)) { + foreach ($ramais_secretaria as $ramal) { + $cmd = 'GET FULL VARIABLE ${PJSIP_DIAL_CONTACTS(' . $ramal . ')}'; + $response = $this->agiRunCmd($cmd); + if ($this->globais['isXampp']) { + $response = '200 result=1 (' . $ramal . ')'; + } + $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 . ')}'; + $response = $this->agiRunCmd($cmd); + if ($this->globais['isXampp']) { + $response = '200 result=1 (SIP' . $ramal . ')'; + } + $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(' . $this->globais['digitado'] . ')}'; + $response = $this->agiRunCmd($cmd); + if ($this->globais['isXampp']) { + $response = '200 result=1 (' . $this->globais['digitado'] . ')'; + } + $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' . $this->globais['digitado'] . ')}'; + $response = $this->agiRunCmd($cmd); + if ($this->globais['isXampp']) { + $response = '200 result=1 (SIP' . $this->globais['digitado'] . ')'; + } + $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^' . $this->globais['callerid'] . '^' . $this->globais['digitado'] . '^' . $this->globais['uniqueid'] . ') ""'; + $response = $this->agiRunCmd($cmd); + + $this->globais['numerodiscado'] = $dialcontacts; + + $cmd = 'GET VARIABLE DIALSTATUS'; + $response = $this->agiRunCmd($cmd); + if ($this->globais['isXampp']) { + $rnd = rand(1, 100); + if ($rnd >= 50) { + $response = '200 result=1 (ANSWER)'; + } else { + $response = '200 result=1 (NO ANSWER)'; + } + } + $explodido = explode("(", $response); + if (count($explodido) > 1) { + $dialstatus = substr($explodido[1], 0, -1); + } else { + $dialstatus = ''; + } + + $this->globais['dialstatus'] = $dialstatus; + + if ($dialstatus == 'ANSWER') { + $this->fgItemRunNextFrom($fgItem); + } else { + + $desvio = $this->hitpbxGetDesvioFrom(array('tipo' => 'ramal', 'value' => $this->globais['digitado'])); + if (count($desvio)) { + $run_next = false; + if ($desvio['shortname'] == 'numeroexterno') { + $return = $this->agiRunDialNumeroExterno($desvio['numero']); + } + if ($desvio['shortname'] == 'queue') { + $queuestatus = $this->agiRunQueue(array('id' => $desvio['queue'])); + if ($queuestatus == '') { + $return = 'ANSWER'; + } + } + if ($desvio['shortname'] == 'ramal') { + $return = $this->agiRunDialRamal($desvio['ramal']); + } + if ($desvio['shortname'] == 'voicemail') { + $this->agiRunVoicemail($desvio['ramal']); + $return = 'ANSWER'; + } + if ($desvio['shortname'] == 'numeroexterno') { + $this->agiRunDialNumeroExterno($desvio['numero']); + } + } + + if ($run_next) { + + $cmd = 'EXEC PLAYBACK /var/lib/asterisk/sounds/pt_BR/exten-unavail ""'; + $response = $this->agiRunCmd($cmd); + + $run_next = true; + + $fgItemChildren = $this->fgItemGetChildrenFrom($fgItem); + foreach ($fgItemChildren as $fgItemChild) { + if ($run_next) { + if ($fgItemChild['cmd'] == 'timeoutwithlimit') { + $this->fgItemRun($fgItemChild); + $run_next = false; + } + } + } + + $fgItemChildren = $this->fgItemGetChildrenFrom($fgItem); + foreach ($fgItemChildren as $fgItemChild) { + if ($run_next) { + if ($fgItemChild['cmd'] == 'timeout') { + $this->fgItemRun($fgItemChild); + $run_next = false; + } + } + } + + $fgItemChildren = $this->fgItemGetChildrenFrom($fgItem); + foreach ($fgItemChildren as $fgItemChild) { + if ($run_next) { + if ($fgItemChild['cmd'] == 'voicemail') { + $this->fgItemRun($fgItemChild); + $run_next = false; + } + } + } + + if ($run_next) { + $this->fgItemRunNextFrom($fgItem); + } + } + } + } + } + + public function fgItemRunDialplanCheckvar($fgItem = array()) + { + $this->agiLog("===> " . __FUNCTION__ . " <==="); + $this->agiLog(print_r($fgItem, true)); + $this->logAdd("
fgItemRunDialplanCheckvar

"); + + $nomatch = true; + $run_next = true; + $fgItemMaster = $this->fgItemGetMasterFrom($fgItem); + $fgItemChildren = $this->fgItemGetChildrenFrom($fgItemMaster); + foreach ($fgItemChildren as $fgItemChild) { + if (($run_next) && ($this->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']; + } + $response = $this->agiVarGet(strtoupper($varname)); + if ($this->globais['isXampp']) { + $rnd = rand(1, 100); + if ($rnd >= 50) { + $response = 'ABC'; + } else { + $response = 'XYZ'; + } + } + if ($response == $varvalue) { + $this->fgItemRunNextFrom($fgItemChild); + $nomatch = false; + $run_next = false; + } + } + } + if ($nomatch) { + $run_next = true; + $fgItemChildren = $this->fgItemGetChildrenFrom($fgItemMaster); + foreach ($fgItemChildren as $fgItemChild) { + if ($run_next) { + if ($fgItemChild['cmd'] == 'nomatch') { + $this->fgItemRun($fgItemChild); + $run_next = false; + } + } + } + } + } + + public function fgItemRunDialExtension($fgItem = array()) + { + $this->agiLog("===> " . __FUNCTION__ . " <==="); + $this->agiLog(print_r($fgItem, true)); + $this->logAdd("
fgItemRunDialExtension

"); + + $dialstatus = $this->agiRunDialRamal($fgItem['value']); + + if ($this->globais['isXampp']) { + $this->globais['numerodiscado'] = $fgItem['value']; + $rnd = rand(1, 100); + if ($rnd >= 50) { + $dialstatus = 'ANSWER'; + } else { + $dialstatus = 'NO ANSWER'; + } + } + + if ($dialstatus != 'ANSWER') { + + $run_next = true; + + $fgItemChildren = $this->fgItemGetChildrenFrom($fgItem); + foreach ($fgItemChildren as $fgItemChild) { + if ($run_next) { + if ($fgItemChild['cmd'] == 'timeoutwithlimit') { + $this->fgItemRun($fgItemChild); + $run_next = false; + } + } + } + + $fgItemChildren = $this->fgItemGetChildrenFrom($fgItem); + foreach ($fgItemChildren as $fgItemChild) { + if ($run_next) { + if ($fgItemChild['cmd'] == 'timeout') { + $this->fgItemRun($fgItemChild); + $run_next = false; + } + } + } + + $fgItemChildren = $this->fgItemGetChildrenFrom($fgItem); + foreach ($fgItemChildren as $fgItemChild) { + if ($run_next) { + if ($fgItemChild['cmd'] == 'voicemail') { + $this->fgItemRun($fgItemChild); + $run_next = false; + } + } + } + + if ($run_next) { + $this->fgItemRunNextFrom($fgItem); + } + } else { + + $this->fgItemRunNextFrom($fgItem); + } + } + + public function fgItemRunDialGroupExtension($fgItem = array()) + { + $this->agiLog("===> " . __FUNCTION__ . " <==="); + $this->agiLog(print_r($fgItem, true)); + $this->logAdd("
fgItemRunDialGroupExtension

"); + + $dialstatus = $this->agiRunDialRamalGrupo($fgItem['value']); + + if ($this->globais['isXampp']) { + $this->globais['numerodiscado'] = '1111'; + $rnd = rand(1, 100); + if ($rnd >= 50) { + $dialstatus = 'ANSWER'; + } else { + $dialstatus = 'NO ANSWER'; + } + } + + if ($dialstatus != 'ANSWER') { + + $run_next = true; + + $fgItemChildren = $this->fgItemGetChildrenFrom($fgItem); + foreach ($fgItemChildren as $fgItemChild) { + if ($run_next) { + if ($fgItemChild['cmd'] == 'timeoutwithlimit') { + $this->fgItemRun($fgItemChild); + $run_next = false; + } + } + } + + $fgItemChildren = $this->fgItemGetChildrenFrom($fgItem); + foreach ($fgItemChildren as $fgItemChild) { + if ($run_next) { + if ($fgItemChild['cmd'] == 'timeout') { + $this->fgItemRun($fgItemChild); + $run_next = false; + } + } + } + + $fgItemChildren = $this->fgItemGetChildrenFrom($fgItem); + foreach ($fgItemChildren as $fgItemChild) { + if ($run_next) { + if ($fgItemChild['cmd'] == 'voicemail') { + $this->fgItemRun($fgItemChild); + $run_next = false; + } + } + } + + if ($run_next) { + $this->fgItemRunNextFrom($fgItem); + } + } else { + $this->fgItemRunNextFrom($fgItem); + } + } + + public function fgItemRunDialplanGosub($fgItem = array()) + { + $this->agiLog("===> " . __FUNCTION__ . " <==="); + $this->agiLog(print_r($fgItem, true)); + $this->logAdd("
fgItemRunDialplanGosub

"); + + $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'; + $response = $this->agiRunCmd($cmd); + } + + $this->fgItemRunNextFrom($fgItem); + } + + public function fgItemRunDialplanSetvar($fgItem = array()) + { + $this->agiLog("===> " . __FUNCTION__ . " <==="); + $this->agiLog(print_r($fgItem, true)); + $this->logAdd("
fgItemRunDialplanSetvar

"); + + $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 != '') { + $varvalue = $this->agiVarGet(strtoupper($varnameget)); + if ($this->globais['isXampp']) { + $varvalue = 'ABC'; + } + } + } + + if ($varvalue != '') { + $response = $this->agiVarSet(strtoupper($varnameset), $varvalue); + } else { + $cmd = 'SET VARIABLE ' . strtoupper($varnameset) . ' ""'; + $response = $this->agiRunCmd($cmd); + } + + $this->fgItemRunNextFrom($fgItem); + } + + public function fgItemRunDigit($fgItem = array()) + { + $this->agiLog("===> " . __FUNCTION__ . " <==="); + $this->agiLog(print_r($fgItem, true)); + $this->logAdd('
fgItemRunDigit

'); + + // 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; + */ + // ... + + $this->fgItemRunNextFrom($fgItem); + } + + public function fgItemRunDigitInvalid($fgItem = array()) + { + $this->agiLog("===> " . __FUNCTION__ . " <==="); + $this->agiLog(print_r($fgItem, true)); + $this->logAdd("
fgItemRunDigitInvalid

"); + $this->fgItemRunNextFrom($fgItem); + } + + public function fgItemRunExpedienteCheck($fgItem = array()) + { + $this->agiLog("===> " . __FUNCTION__ . " <==="); + $this->agiLog(print_r($fgItem, true)); + $this->logAdd("
fgItemRunExpedienteCheck

"); + + $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($this->globais['db'], $fgItem['value']) . "'"; + } + } + $query_result = mysqli_query($this->globais['db'], $query); + if (mysqli_num_rows($query_result) > 0) { + $isTrue = true; + } else { + $isTrue = false; + } + + if ($this->globais['isXampp']) { + $rnd = rand(1, 100); + $isTrue = ($rnd >= 50); + } + + $run_next = true; + $fgItemChildren = $this->fgItemGetChildrenFrom($fgItem); + $cmdTarget = $isTrue ? 'expediente.true' : 'expediente.false'; + foreach ($fgItemChildren as $fgItemChild) { + if ($run_next) { + if ($fgItemChild['cmd'] == $cmdTarget) { + $this->fgItemRun($fgItemChild); + $run_next = false; + } + } + } + } + + public function fgItemRunExpedienteFalse($fgItem = array()) + { + $this->agiLog("===> " . __FUNCTION__ . " <==="); + $this->agiLog(print_r($fgItem, true)); + $this->logAdd("
fgItemRunExpedienteFalse

"); + $this->fgItemRunNextFrom($fgItem); + } + + public function fgItemRunExpedienteTrue($fgItem = array()) + { + $this->agiLog("===> " . __FUNCTION__ . " <==="); + $this->agiLog(print_r($fgItem, true)); + $this->logAdd("
fgItemRunExpedienteTrue

"); + $this->fgItemRunNextFrom($fgItem); + } + + public function fgItemRunFeriadoCheck($fgItem = array()) + { + $this->agiLog("===> " . __FUNCTION__ . " <==="); + $this->agiLog(print_r($fgItem, true)); + $this->logAdd("
fgItemRunFeriadoCheck

"); + + $hojeDia = date("d"); + $hojeMes = date("m"); + $query = "SELECT * FROM tab_feriado WHERE mes = '" . $hojeMes . "' AND dia = '" . $hojeDia . "'"; + $query_result = mysqli_query($this->globais['db'], $query); + $isTrue = (mysqli_num_rows($query_result) > 0); + + if ($this->globais['isXampp']) { + $rnd = rand(1, 100); + $isTrue = ($rnd >= 50); + } + + $run_next = true; + $fgItemChildren = $this->fgItemGetChildrenFrom($fgItem); + $cmdTarget = $isTrue ? 'feriado.true' : 'feriado.false'; + foreach ($fgItemChildren as $fgItemChild) { + if ($run_next) { + if ($fgItemChild['cmd'] == $cmdTarget) { + $this->fgItemRun($fgItemChild); + $run_next = false; + } + } + } + } + + public function fgItemRunFeriadoFalse($fgItem = array()) + { + $this->agiLog("===> " . __FUNCTION__ . " <==="); + $this->agiLog(print_r($fgItem, true)); + $this->logAdd("
fgItemRunFeriadoFalse

"); + $this->fgItemRunNextFrom($fgItem); + } + + public function fgItemRunFeriadoTrue($fgItem = array()) + { + $this->agiLog("===> " . __FUNCTION__ . " <==="); + $this->agiLog(print_r($fgItem, true)); + $this->logAdd("
fgItemRunFeriadoTrue

"); + $this->fgItemRunNextFrom($fgItem); + } + + public function fgItemRunIVRRedirect($fgItem = array()) + { + $this->agiLog("===> " . __FUNCTION__ . " <==="); + $this->agiLog(print_r($fgItem, true)); + $this->logAdd("
fgItemRunIVRRedirect

"); + $this->globais['fgId'] = $fgItem['value']; + $this->fgGet(); + if (count($this->globais['fgItemStart']) > 0) { + $this->fgItemRunNextFrom($this->globais['fgItemStart']); + } + } + + public function fgItemRunNextFrom($fgItemFrom = array()) + { + // $this->agiLog("===> " . __FUNCTION__ . " <==="); + // $this->agiLog(print_r($fgItemFrom, true)); + + $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($this->globais['fgItens'][$fgItemFrom['idnext']])) { + $this->fgItemRun($this->globais['fgItens'][$fgItemFrom['idnext']]); + $run_next = false; + } + } + + $fgItemChildren = $this->fgItemGetChildrenFrom($fgItemFrom); + foreach ($fgItemChildren as $fgItemChild) { + if (($run_next) && (!in_array($fgItemChild['cmd'], $cmds_nonext))) { + $this->fgItemRun($fgItemChild); + $run_next = false; + } + } + } + + public function fgItemRunNoMatch($fgItem = array()) + { + $this->agiLog("===> " . __FUNCTION__ . " <==="); + $this->agiLog(print_r($fgItem, true)); + $this->logAdd("
fgItemRunNoMatch

"); + $this->fgItemRunNextFrom($fgItem); + } + + public function fgItemRunPesqSat($fgItem = array()) + { + $this->agiLog("===> " . __FUNCTION__ . " <==="); + $this->agiLog(print_r($fgItem, true)); + $this->logAdd("
fgItemRunPesqSat ???

"); + + $id_pesqsat = is_numeric($fgItem['value']) ? $fgItem['value'] : ''; + $audiofile = ''; + + if ($this->globais['isXampp']) { + $audiofile = 'pesquisa'; + } else { + $query = "INSERT INTO tab_pesqsat_nota SET "; + $query .= "id_pesqsat = '" . mysqli_real_escape_string($this->globais['db'], $id_pesqsat) . "', "; + $query .= "uniqueid = '" . mysqli_real_escape_string($this->globais['db'], $this->globais['uniqueid']) . "', "; + $query .= "nota = '100'"; + $query_result = mysqli_query($this->globais['db'], $query); + + $query = "SELECT audio FROM tab_pesqsat WHERE id = '" . mysqli_real_escape_string($this->globais['db'], $id_pesqsat) . "'"; + $query_result = mysqli_query($this->globais['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 = '2000'; // milisegundos + $digito_qtd = '2'; + + $this->globais['digitado'] = ''; + + $cmd = 'SET VARIABLE AGIDIGITADO ""'; + $response = $this->agiRunCmd($cmd); + + $cmd = 'GET DATA /var/lib/asterisk/sounds/cliente/' . $audiofile . ' ' . $digito_timeout . ' ' . $digito_qtd; + $response = $this->agiRunCmd($cmd); + + /* + 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); + $this->globais['digitado'] = $explodido[1]; + } + + $run_next = true; + + if ($this->globais == '') { + + $fgItemChildren = $this->fgItemGetChildrenFrom($fgItem); + foreach ($fgItemChildren as $fgItemChild) { + if ($run_next) { + if ($fgItemChild['cmd'] == 'timeoutwithlimit') { + $this->fgItemRun($fgItemChild); + $run_next = false; + } + } + } + + $fgItemChildren = $this->fgItemGetChildrenFrom($fgItem); + foreach ($fgItemChildren as $fgItemChild) { + if ($run_next) { + if ($fgItemChild['cmd'] == 'timeout') { + $this->fgItemRun($fgItemChild); + $run_next = false; + } + } + } + + $run_next = false; + } + + if ($run_next) { + + if (!$this->globais['isXampp']) { + $query = "UPDATE tab_pesqsat_nota SET "; + $query .= "nota = '" . mysqli_real_escape_string($this->globais['db'], $this->globais['digitado']) . "' "; + $query .= "WHERE id_pesqsat = '" . mysqli_real_escape_string($this->globais['db'], $id_pesqsat) . "' "; + $query .= "AND uniqueid = '" . mysqli_real_escape_string($this->globais['db'], $this->globais['uniqueid']) . "'"; + $query_result = mysqli_query($this->globais['db'], $query); + } + $this->fgItemRunNextFrom($fgItem); + } + } else { + $this->fgItemRunNextFrom($fgItem); + } + } + + public function fgItemRunPlayaudio($fgItem = array()) + { + $this->agiLog("===> " . __FUNCTION__ . " <==="); + $this->agiLog(print_r($fgItem, true)); + + $this->globais['digitado'] = ''; + + $cmd = 'SET VARIABLE AGIDIGITADO ""'; + $response = $this->agiRunCmd($cmd); + + if ($this->globais['isXampp']) { + $rnd = rand(1, 100); + if ($rnd >= 60) { + $this->globais['digitado'] = rand(0, 9); + } else if ($rnd >= 40) { + $this->globais['digitado'] = 'A'; + } else if ($rnd >= 20) { + $this->globais['digitado'] = '1001'; + } else { + $this->globais['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; + $response = $this->agiRunCmd($cmd); + + // 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); + $this->globais['digitado'] = $explodido[1]; + } + } + + $run_next = true; + + if ($this->globais['digitado'] == '') { + + $fgItemChildren = $this->fgItemGetChildrenFrom($fgItem); + foreach ($fgItemChildren as $fgItemChild) { + if ($run_next) { + if ($fgItemChild['cmd'] == 'timeoutwithlimit') { + $this->fgItemRun($fgItemChild); + $run_next = false; + } + } + } + + $fgItemChildren = $this->fgItemGetChildrenFrom($fgItem); + foreach ($fgItemChildren as $fgItemChild) { + if ($run_next) { + if ($fgItemChild['cmd'] == 'timeout') { + $this->fgItemRun($fgItemChild); + $run_next = false; + } + } + } + + if ($run_next) { + $this->fgItemRunNextFrom($fgItem); + } + + $run_next = false; + } else { + + $cmd = 'SET VARIABLE AGIDIGITADO ' . $this->globais['digitado']; + $response = $this->agiRunCmd($cmd); + + $cmd = 'EXEC QUEUELOG NONE,' . $this->globais['uniqueid'] . ',NONE,INFO|IVRAPPEND|->' . $this->globais['digitado']; + $response = $this->agiRunCmd($cmd); + } + + if ($run_next) { + $fgItemChildren = $this->fgItemGetChildrenFrom($fgItem); + foreach ($fgItemChildren as $fgItemChild) { + if ($run_next) { + if ($fgItemChild['cmd'] == 'digit') { + if ($fgItemChild['value'] == $this->globais['digitado']) { + $this->fgItemRun($fgItemChild); + $run_next = false; + } + } + } + } + } + + if ($run_next) { + $tamanho = strlen($this->globais['digitado']); + if (($tamanho >= 3) && ($tamanho <= 4)) { + $fgItemChildren = $this->fgItemGetChildrenFrom($fgItem); + foreach ($fgItemChildren as $fgItemChild) { + if ($run_next) { + if ($fgItemChild['cmd'] == 'dialdigit') { + $this->fgItemRun($fgItemChild); + $run_next = false; + } + } + } + } + } + + if ($run_next) { + $fgItemChildren = $this->fgItemGetChildrenFrom($fgItem); + foreach ($fgItemChildren as $fgItemChild) { + if ($run_next) { + if ($fgItemChild['cmd'] == 'digitinvalid') { + $this->fgItemRun($fgItemChild); + $run_next = false; + } + } + } + } + + if ($run_next) { + $this->fgItemRunNextFrom($fgItem); + } + } + + public function fgItemRunQueue($fgItem = array()) + { + $this->agiLog("===> " . __FUNCTION__ . " <==="); + $this->agiLog(print_r($fgItem, true)); + $this->logAdd("
fgItemRunQueue

"); + + $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; + + // 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 = $this->agiRunQueue(array('id' => $fgItem['value'], 'timeout' => $timeout)); + if ($response == 'stopivr') { + $run_next = false; + } + + if (($run_next) && ($response == 'timeout')) { + + $fgItemChildren = $this->fgItemGetChildrenFrom($fgItem); + foreach ($fgItemChildren as $fgItemChild) { + if ($run_next) { + if ($fgItemChild['cmd'] == 'timeoutwithlimit') { + $this->fgItemRun($fgItemChild); + $run_next = false; + } + } + } + + $fgItemChildren = $this->fgItemGetChildrenFrom($fgItem); + foreach ($fgItemChildren as $fgItemChild) { + if ($run_next) { + if ($fgItemChild['cmd'] == 'timeout') { + $this->fgItemRun($fgItemChild); + $run_next = false; + } + } + } + + $run_next = false; + } + + if ($run_next) { + $this->fgItemRunNextFrom($fgItem); + } + } + + public function fgItemRunQueueWaitingCount($fgItem = array()) + { + $this->agiLog("===> " . __FUNCTION__ . " <==="); + $this->agiLog(print_r($fgItem, true)); + $this->logAdd("
fgItemRunQueueWaitingCount

"); + + $id_queue = is_numeric($fgItem['value']) ? 'Q' . $fgItem['value'] : $fgItem['value']; + + $cmd = 'GET FULL VARIABLE ${QUEUE_WAITING_COUNT(' . $id_queue . ')}'; + $response = $this->agiRunCmd($cmd); + if ($this->globais['isXampp']) { + $rnd = rand(0, 20); + $response = '200 result=1 (' . $rnd . ')'; + } + + $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 == '') { + $run_next = false; + } + + if ($run_next) { + $arr = array(); + $fgItemChildren = $this->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); + $this->fgItemRun($this->globais['fgItens'][$fgItemNextId]); + $run_next = false; + } + } + + if ($run_next) { + $fgItemChildren = $this->fgItemGetChildrenFrom($fgItem); + foreach ($fgItemChildren as $fgItemChild) { + if ($run_next) { + if ($fgItemChild['cmd'] == 'nomatch') { + $this->fgItemRun($fgItemChild); + $run_next = false; + } + } + } + } + } + + public function fgItemRunQueueWaitingCountGreater($fgItem = array()) + { + $this->agiLog("===> " . __FUNCTION__ . " <==="); + $this->agiLog(print_r($fgItem, true)); + $this->logAdd("
fgItemRunQueueWaitingCountGreater

"); + $this->fgItemRunNextFrom($fgItem); + } + + public function fgItemRunQueueWithCallback($fgItem = array()) + { + $this->agiLog("===> " . __FUNCTION__ . " <==="); + $this->agiLog(print_r($fgItem, true)); + + $id_queue_callback = isset($fgItem['value2']) ? $fgItem['value2'] : ''; + if ($id_queue_callback == '') { + $cmd = 'SET VARIABLE AGICALLBACKQUEUEID ""'; + } else { + $cmd = 'SET VARIABLE AGICALLBACKQUEUEID ' . $id_queue_callback; + } + $response = $this->agiRunCmd($cmd); + + $timeout = isset($fgItem['value3']) ? $fgItem['value3'] : ''; + $timeout = is_numeric($timeout) ? $timeout : ''; + + $run_next = true; + + $queue_status = ''; + + $cmd = 'GET FULL VARIABLE ${QUEUE_MEMBER(Q' . $fgItem['value'] . ',ready)}'; + $response = $this->agiRunCmd($cmd); + if ($this->globais['isXampp']) { + $rnd = rand(1, 100); + if ($rnd >= 50) { + $response = '200 result=1 (0)'; + } + } + 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 = $this->fgItemGetChildrenFrom($fgItem); + foreach ($fgItemChildren as $fgItemChild) { + if ($run_next) { + if ($fgItemChild['cmd'] == 'queue.withcallback-noready') { + $this->fgItemRun($fgItemChild); + $run_next = false; + } + } + } + } + + if ($run_next) { + // logAdd('===> agiRunQueue
'); + $queue_status = $this->agiRunQueue(array('id' => $fgItem['value'], 'timeout' => $timeout)); + if ($queue_status == 'stopivr') { + // logAdd('===> agiRunQueue stopivr
'); + $run_next = false; + } + } + + if (($run_next) && ($queue_status == 'timeout')) { + + $fgItemChildren = $this->fgItemGetChildrenFrom($fgItem); + foreach ($fgItemChildren as $fgItemChild) { + if ($run_next) { + if ($fgItemChild['cmd'] == 'timeoutwithlimit') { + $this->fgItemRun($fgItemChild); + $run_next = false; + } + } + } + + $fgItemChildren = $this->fgItemGetChildrenFrom($fgItem); + foreach ($fgItemChildren as $fgItemChild) { + if ($run_next) { + if ($fgItemChild['cmd'] == 'timeout') { + $this->fgItemRun($fgItemChild); + $run_next = false; + } + } + } + + $run_next = false; + } + + if ($run_next) { + $this->fgItemRunNextFrom($fgItem); + } + } + + public function fgItemRunQueueWithCallbackNoReady($fgItem = array()) + { + $this->agiLog("===> " . __FUNCTION__ . " <==="); + $this->agiLog(print_r($fgItem, true)); + $this->logAdd("
fgItemRunQueueWithCallbackNoReady

"); + $this->fgItemRunNextFrom($fgItem); + } + + public function fgItemRunRecord($fgItem = array()) + { + $this->agiLog("===> " . __FUNCTION__ . " <==="); + $this->agiLog(print_r($fgItem, true)); + $this->logAdd("
fgItemRunRecord

"); + + $uniqueid = $this->globais['uniqueid']; + $callerid = $this->globais['callerid']; + $exten = $this->globais['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'; + $response = $this->agiRunCmd($cmd); + + $this->fgItemRunNextFrom($fgItem); + } + + public function fgItemRunStart($fgItem = array()) + { + $this->agiLog("===> " . __FUNCTION__ . " <==="); + $this->agiLog(print_r($fgItem, true)); + + // 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']; + // ... + + $this->fgItemRunNextFrom($fgItem); + } + + public function fgItemRunTimeout($fgItem = array()) + { + $this->agiLog("===> " . __FUNCTION__ . " <==="); + $this->agiLog(print_r($fgItem, true)); + + $run_next = true; + + $fgItemChildren = $this->fgItemGetChildrenFrom($fgItem); + foreach ($fgItemChildren as $fgItemChild) { + if ($run_next) { + if ($fgItemChild['cmd'] == 'voicemail') { + $this->fgItemRun($fgItemChild); + $run_next = false; + } + } + } + + if ($run_next) { + $this->fgItemRunNextFrom($fgItem); + } + } + + public function fgItemRunTimeoutWithLimit($fgItem = array()) + { + $this->agiLog("===> " . __FUNCTION__ . " <==="); + $this->agiLog(print_r($fgItem, true)); + $this->logAdd("
fgItemRunTimeoutWithLimit

"); + + $run_next = true; + + if (!isset($this->globais['fgItemExecutedCount'][$fgItem['id']])) { + $this->globais['fgItemExecutedCount'][$fgItem['id']] = 0; + } + $this->globais['fgItemExecutedCount'][$fgItem['id']]++; + + if ($this->globais['fgItemExecutedCount'][$fgItem['id']] >= $fgItem['value']) { + + $fgItemChildren = $this->fgItemGetChildrenFrom($fgItem); + foreach ($fgItemChildren as $fgItemChild) { + if ($run_next) { + if ($fgItemChild['cmd'] == 'timeoutwithlimit.limit') { + $this->fgItemRun($fgItemChild); + $run_next = false; + } + } + } + + $run_next = false; + } + + if ($run_next) { + $this->fgItemRunNextFrom($fgItem); + } + } + + public function fgItemRunTimeoutWithLimitLimit($fgItem = array()) + { + $this->agiLog("===> " . __FUNCTION__ . " <==="); + $this->agiLog(print_r($fgItem, true)); + $this->logAdd("
fgItemRunTimeoutWithLimitLimit

"); + $this->fgItemRunNextFrom($fgItem); + } + + public function fgItemRunVoicemail($fgItem = array()) + { + $this->agiLog("===> " . __FUNCTION__ . " <==="); + $this->agiLog(print_r($fgItem, true)); + $this->logAdd("
fgItemRunVoicemail

"); + if (isset($this->globais['numerodiscado'])) { + if ($this->globais['numerodiscado'] != '') { + $cmd = 'EXEC VOICEMAIL ' . $this->globais['numerodiscado']; + $response = $this->agiRunCmd($cmd); + } + } + $this->fgItemRunNextFrom($fgItem); + } + + public function fgItemRunWhitelistCheck($fgItem = array()) + { + $this->agiLog("===> " . __FUNCTION__ . " <==="); + $this->agiLog(print_r($fgItem, true)); + $this->logAdd("
fgItemRunWhitelistCheck

"); + $esta_na_lista = $this->hitpbxCheckWhitelist($GLOBALS['callerid']); + + if ($this->globais['isXampp']) { + $rnd = rand(1, 100); + $esta_na_lista = ($rnd >= 50); + } + + $run_next = true; + $fgItemChildren = $this->fgItemGetChildrenFrom($fgItem); + $cmdTarget = $esta_na_lista ? 'whitelist.true' : 'whitelist.false'; + foreach ($fgItemChildren as $fgItemChild) { + if ($run_next) { + if ($fgItemChild['cmd'] == $cmdTarget) { + $this->fgItemRun($fgItemChild); + $run_next = false; + } + } + } + } + + public function fgItemRunWhitelistFalse($fgItem = array()) + { + $this->agiLog("===> " . __FUNCTION__ . " <==="); + $this->agiLog(print_r($fgItem, true)); + $this->logAdd("
fgItemRunWhitelistFalse

"); + $this->fgItemRunNextFrom($fgItem); + } + + public function fgItemRunWhitelistTrue($fgItem = array()) + { + $this->agiLog("===> " . __FUNCTION__ . " <==="); + $this->agiLog(print_r($fgItem, true)); + $this->logAdd("
fgItemRunWhitelistTrue

"); + $this->fgItemRunNextFrom($fgItem); + } + + // -------------------------------------------------------------------------------------------------------------------------------- + + public 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($this->globais['db'], $ramal) . "'"; + $query_result = mysqli_query($this->globais['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($this->globais['db'], $idramal) . "'"; + $query_result = mysqli_query($this->globais['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($this->globais['db'], $args['idqueue']) . "' "; + $query_result = mysqli_query($this->globais['db'], $query); + while ($resultLinha = mysqli_fetch_assoc($query_result)) { + $auditorias[] = $resultLinha; + } + + $periodo_match = false; + foreach ($auditorias as $auditoria) { + $periodo_match = $this->hitpbxCheckPeriodoMatch(array('id_periodo' => $auditoria['id_tab_condicao_tempo'])); + } + + return $periodo_match; + } + + public 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($this->globais['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($this->globais['db'], $tmp) . "'"; + $query_result = mysqli_query($this->globais['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($this->globais['db'], $tmp) . "'"; + $query_result = mysqli_query($this->globais['db'], $query); + if (mysqli_num_rows($query_result) > 0) { + $return = true; + } + } + + $query_result = mysqli_query($this->globais['db'], $query); + if (mysqli_num_rows($query_result) > 0) { + $return = true; + } + return $return; + } + + public 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($this->globais['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($this->globais['db'], $query); + if (mysqli_num_rows($query_result) > 0) { + $return = true; + } + } + + return $return; + } + + public 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($this->globais['db'], $callerid) . "'"; + $query_result = mysqli_query($this->globais['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($this->globais['db'], $tmp) . "'"; + $query_result = mysqli_query($this->globais['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($this->globais['db'], $tmp) . "'"; + $query_result = mysqli_query($this->globais['db'], $query); + if (mysqli_num_rows($query_result) > 0) { + $return = true; + } + } + + return $return; + } + + public function hitpbxGetCallbackFromRamal($ramal = '') + { + $return = ''; + $query = "SELECT callback FROM tab_ramal WHERE ramal = '" . mysqli_real_escape_string($this->globais['db'], $ramal) . "'"; + $query_result = mysqli_query($this->globais['db'], $query); + if (mysqli_num_rows($query_result) > 0) { + $resultLinha = mysqli_fetch_assoc($query_result); + $return = $resultLinha['callback']; + } + return $return; + } + + public 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($this->globais['db'], $args['tipo']) . "'"; + $query_result = mysqli_query($this->globais['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($this->globais['db'], $args['value']) . "'"; + $query_result = mysqli_query($this->globais['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($this->globais['db'], $origem_tipo_id) . "'"; + $query .= "AND tab_desvio.origem_id = '" . mysqli_real_escape_string($this->globais['db'], $origem_id) . "'"; + $query_result = mysqli_query($this->globais['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($this->globais['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($this->globais['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($this->globais['db'], $resultLinha['destino_id']) . "'"; + $result2 = mysqli_query($this->globais['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($this->globais['db'], $resultLinha['destino_id']) . "'"; + $result2 = mysqli_query($this->globais['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($this->globais['db'], $resultLinha['destino_id']) . "'"; + $result2 = mysqli_query($this->globais['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; + } + + public function hitpbxGetQueuenomeFromId($queueid = '') + { + $return = ''; + $query = "SELECT nome FROM tab_queue WHERE id = '" . mysqli_real_escape_string($this->globais['db'], $queueid) . "'"; + $query_result = mysqli_query($this->globais['db'], $query); + while ($resultLinha = mysqli_fetch_assoc($query_result)) { + $return = $resultLinha['nome']; + } + return $return; + } + + public function hitpbxGetQueueFromNumeroExterno($args = array()) + { + $return = array(); + $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($this->globais['db'], $args['numero_externo']) . "'"; + $query_result = mysqli_query($this->globais['db'], $query); + while ($resultLinha = mysqli_fetch_assoc($query_result)) { + $return = $resultLinha; + } + } + return $return; + } + + public 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($this->globais['db'], $args['callgroup']) . "'"; + } + $query_result = mysqli_query($this->globais['db'], $query); + while ($resultLinha = mysqli_fetch_assoc($query_result)) { + $return[] = $resultLinha['ramal']; + } + return $return; + } + + public function hitpbxGetRamaisSecretariaFromRamal($ramal = '') + { + $return = array(); + $query = "SELECT callgroup_secretaria FROM tab_ramal WHERE ramal = '" . mysqli_real_escape_string($this->globais['db'], $ramal) . "'"; + $query_result = mysqli_query($this->globais['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($this->globais['db'], $callgroup_secretaria) . "'"; + $query_result = mysqli_query($this->globais['db'], $query); + while ($resultLinha = mysqli_fetch_assoc($query_result)) { + $return[] = $resultLinha['ramal']; + } + } + return $return; + } + + public function hitpbxGetRingTimeoutFromRamal($ramal = '') + { + $return = ''; + $query = "SELECT ring_timeout FROM tab_ramal WHERE ramal = '" . mysqli_real_escape_string($this->globais['db'], $ramal) . "'"; + $query_result = mysqli_query($this->globais['db'], $query); + if (mysqli_num_rows($query_result) > 0) { + $resultLinha = mysqli_fetch_assoc($query_result); + $return = $resultLinha['ring_timeout']; + } + return $return; + } + + // -------------------------------------------------------------------------------------------------------------------------------- + + public function extrairNumeros($string) + { + preg_match_all('/\d+/', $string, $matches); + $numeros = implode('', $matches[0]); + return $numeros; + } + + public 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; + } + } + + public 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; + } + } + + // -------------------------------------------------------------------------------------------------------------------------------- + + public function teste() + { + $this->agiLog($this->globais['fgId']); + } + + function tocarFila($queueId, $timeout) + { + return $this->agiRunCmd('EXEC Queue Q' . $queueId . ',ctT,,,' . $timeout); + } + + // -------------------------------------------------------------------------------------------------------------------------------- + + public function run() + { + $this->logStart(); + $this->logAdd("
" . print_r($this->globais, true) . "

"); + + $this->fgGet(); + + if (count($this->globais['fgItemStart']) > 0) { + + $this->globais['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 ($this->globais['isXampp']) { + + $this->globais['callerid'] = '1138118400'; + $this->globais['uniqueid'] = date("Ymd") . "." . date("His"); + $this->globais['digitado'] = ''; + + $host = 'localhost'; + $user = 'root'; + $password = ''; + $database = 'hitpbx_homologacao'; + $port = '3306'; + $this->globais['db'] = mysqli_connect($host, $user, $password, $database, $port) or die('Erro de conexão com o banco de dados'); + mysqli_set_charset($this->globais['db'], 'utf8'); + + $this->fgItemRun($this->globais['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'; + $this->globais['db'] = mysqli_connect($host, $user, $password, $database, $port) or die('Erro de conexão com o banco de dados'); + mysqli_set_charset($this->globais['db'], 'utf8'); + + /* + logAdd("111
"); + $query = "SELECT * FROM tab_ramal LIMIT 1"; + $result = mysqli_query($db,$query); + logAdd($query."
"); + $result = mysqli_query($this->globais['db'],$query); + logAdd($query."
"); + */ + + // ... + + /* + $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 = $this->agiRunCmd('EXEC NOOP HITAGI'); + $response = $this->agiRunCmd('ANSWER'); + $response = $this->agiRunCmd('EXEC WAIT 1'); + $response = $this->agiRunCmd('EXEC PLAYBACK beep'); + $response = $this->agiRunCmd('EXEC WAIT 1'); + + $this->globais['digitado'] = ''; + + $this->globais['callerid'] = $this->agiVarGet('CALLERID'); + $this->globais['uniqueid'] = $this->agiVarGet('UNIQUEID'); + + $response = $this->agiVarSet('AGIDID', $this->globais['fgId']); + + $cmd = 'EXEC QUEUELOG NONE,' . $this->globais['uniqueid'] . ',NONE,INFO|IVRSTART'; + $response = $this->agiRunCmd($cmd); + + $cmd = 'EXEC QUEUELOG NONE,' . $this->globais['uniqueid'] . ',NONE,INFO|IVRAPPEND|->' . $this->globais['fgId']; + $response = $this->agiRunCmd($cmd); + + $this->fgItemRun($this->globais['fgItemStart']); + + // 1353461660|1353461627.33271|NONE|NONE|INFO|IVRHANGUP| + //$cmd = 'EXEC QUEUELOG NONE,' . $GLOBALS['uniqueid'] . ',NONE,NONE,INFO|IVRHANGUP'; + //$response = agiRunCmd($cmd); + + // $response = agiRunCmd('HANGUP'); + + } + } + + /* + $this->teste(); + $this->globais['nomeFila'] = '10'; + $response = $this->tocarFila($this->globais['nomeFila'], 1); + echo "\n" . $response . "\n"; + */ + } +} diff --git a/classes/ArquivoRemoto.php b/classes/ArquivoRemoto.php new file mode 100644 index 0000000..113da17 --- /dev/null +++ b/classes/ArquivoRemoto.php @@ -0,0 +1,109 @@ +ip = 'localhost'; + $this->port = '8083'; + } + + public function runCURL($args = array()) + { + + $arr['url'] = isset($args['url']) ? $args['url'] : ''; + $arr['port'] = isset($args['port']) ? $args['port'] : ''; + $arr['postfields'] = isset($args['postfields']) ? $args['postfields'] : ''; + + $curl = curl_init(); + curl_setopt_array($curl, array( + CURLOPT_PORT => $arr['port'], + CURLOPT_URL => $arr['url'], + CURLOPT_RETURNTRANSFER => true, + CURLOPT_ENCODING => "", + CURLOPT_MAXREDIRS => 10, + CURLOPT_TIMEOUT => 30, + CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1, + CURLOPT_CUSTOMREQUEST => "POST", + CURLOPT_POSTFIELDS => $arr['postfields'], + CURLOPT_HTTPHEADER => array( + "Content-Type: application/json", + "User-Agent: insomnia/2023.5.8" + ), + )); + $response = curl_exec($curl); + $err = curl_error($curl); + curl_close($curl); + + if ($err) { + return array('error' => "cURL Error #:" . $err); + } + + $arr = json_decode($response, true); + if (json_last_error() != JSON_ERROR_NONE) { + return array('error' => 'cURL response not JSON'); + } else { + return $arr; + } + } + + public function pegar($args = array()) + { + $url = 'http://' . $this->ip . ':' . $this->port . '/pegar'; + + $arr = array(); + $arr['auth'] = isset($args['auth']) ? $args['auth'] : '80889736666668f4e2b9008ec15f5ca5'; + $arr['filedir'] = isset($args['filedir']) ? $args['filedir'] : ''; + $arr['filename'] = isset($args['filename']) ? $args['filename'] : ''; + $postfields = json_encode($arr); + unset($arr); + + $argssend = array(); + $argssend['url'] = $url; + $argssend['port'] = $this->port; + $argssend['postfields'] = $postfields; + return $this->runCURL($argssend); + } + + public function salvar($args = array()) + { + $url = 'http://' . $this->ip . ':' . $this->port . '/salvar'; + + $arr = array(); + $arr['auth'] = isset($args['auth']) ? $args['auth'] : '80889736666668f4e2b9008ec15f5ca5'; + $arr['filedir'] = isset($args['filedir']) ? $args['filedir'] : ''; + $arr['filename'] = isset($args['filename']) ? $args['filename'] : ''; + $arr['filebase64'] = isset($args['filebase64']) ? $args['filebase64'] : ''; + $postfields = json_encode($arr); + unset($arr); + + $argssend = array(); + $argssend['url'] = $url; + $argssend['port'] = $this->port; + $argssend['postfields'] = $postfields; + return $this->runCURL($argssend); + } + + public function excluir($args = array()) + { + $url = 'http://' . $this->ip . ':' . $this->port . '/excluir'; + + $arr = array(); + $arr['auth'] = isset($args['auth']) ? $args['auth'] : '80889736666668f4e2b9008ec15f5ca5'; + $arr['filedir'] = isset($args['filedir']) ? $args['filedir'] : ''; + $arr['filename'] = isset($args['filename']) ? $args['filename'] : ''; + $postfields = json_encode($arr); + unset($arr); + + $argssend = array(); + $argssend['url'] = $url; + $argssend['port'] = $this->port; + $argssend['postfields'] = $postfields; + return $this->runCURL($argssend); + } +} diff --git a/composer.json b/composer.json index 34147d9..e701445 100644 --- a/composer.json +++ b/composer.json @@ -1,14 +1,20 @@ { - "name": "hit/ami", - "autoload": { - "psr-4": { - "Hit\\Ami\\": "src/" + "name": "hitlabs/hitagi", + "type": "project", + "autoload": { + "psr-4": { + "Hitlabs\\Hitagi\\": "classes/" + } + }, + "authors": [ + { + "name": "HIT" + } + ], + "require": { + "swoole/ide-helper": "~5.0.0", + "vlucas/phpdotenv": "^5.6", + "firebase/php-jwt": "^6.10", + "guzzlehttp/guzzle": "^7.9" } - }, - "require": { - "swoole/ide-helper": "~5.0.0", - "vlucas/phpdotenv": "^5.6", - "firebase/php-jwt": "^6.10", - "guzzlehttp/guzzle": "^7.8" - } -} \ No newline at end of file +} diff --git a/composer.lock b/composer.lock index f596894..41ed4b8 100644 --- a/composer.lock +++ b/composer.lock @@ -4,7 +4,7 @@ "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies", "This file is @generated automatically" ], - "content-hash": "7cccddac512163c6eaa2449701d7945d", + "content-hash": "f78189202e95f3ab065c8f4b6d13b25b", "packages": [ { "name": "firebase/php-jwt", diff --git a/dial/8999.json b/dial/8999.json index d1f6aaa..704db00 100644 --- a/dial/8999.json +++ b/dial/8999.json @@ -28,5 +28,12 @@ "value2": "2", "value3": "1", "value4": "false" - } + }, + { + "id": "5", + "idmaster": "4", + "cmd": "queue", + "value": "13", + "value2": "5" + } ] \ No newline at end of file diff --git a/docs/manual-json.txt b/docs/manual-json.txt new file mode 100644 index 0000000..ef99aa8 --- /dev/null +++ b/docs/manual-json.txt @@ -0,0 +1,1147 @@ +JSON Ligações de entrada + +-------------------------------------------------------------------------------------------------------------------------------- +CMDs +-------------------------------------------------------------------------------------------------------------------------------- + +start + + Determina o inicio do fluxograma, passando o numero do DID no atributo value. + + { + "id": "1", + "idmaster": "1", + "cmd": "start", + "value": "551138118400" + }, + +-------------------------------------------------------------------------------------------------------------------------------- + +blacklist.check + + Verifica se o callerid esta na blacklist. + Caso esteja na lista, a ligação é encaminhado para o CMD blacklist.true + Caso não esteja na lista, a ligação é encaminhado para o CMD blacklist.false + + [ + { + "id": "1", + "idmaster": "1", + "cmd": "start", + "value": "2000" + }, + { + "id": "2", + "idmaster": "1", + "cmd": "blacklist.check", + "value": "" + }, + { + "id": "3", + "idmaster": "2", + "cmd": "blacklist.true", + "value": "" + }, + { + "id": "4", + "idmaster": "3", + "cmd": "playaudio", + "value": "vm-goodbye.wav", + "value2": "2", + "value3": "1", + "value4": "false" + }, + { + "id": "5", + "idmaster": "2", + "cmd": "blacklist.false", + "value": "" + }, + { + "id": "6", + "idmaster": "5", + "cmd": "playaudio", + "value": "demo-echotest.wav", + "value2": "2", + "value3": "1", + "value4": "false" + } + ] + +-------------------------------------------------------------------------------------------------------------------------------- + +callerid.change + + Altera o callerid passado pelo atributo value + O parametro pode ser passado em value2 num, all, name, etc... Se não passar ele usa num + + [ + { + "id": "1", + "idmaster": "1", + "cmd": "start", + "value": "2000" + }, + { + "id": "2", + "idmaster": "1", + "cmd": "callerid.change", + "value": "5555555", + "value2": "num" + }, + { + "id": "3", + "idmaster": "2", + "cmd": "playaudio", + "value": "vm-goodbye.wav", + "value2": "2", + "value3": "1", + "value4": "false" + } + ] + +-------------------------------------------------------------------------------------------------------------------------------- + +digit + + Confere o valor digitado se igual ao passado no atributo value. + Caso ocorra um digito. Encaminha a ligação para o CMD seguintem referente ao valor do digito. + Caso não ocorra um digito em 10 segundos. Encaminha para o CMD "timeout" em paralelo ao CMD "digit". + + { + "id": "1", + "idmaster": "1", + "cmd": "start", + "value": "551138118400" + }, + { + "id": "2", + "idmaster": "1", + "cmd": "playaudio", + "value": "demo-echotest.wav" + }, + { + "id": "3", + "idmaster": "2", + "cmd": "digit", + "value": "1" + }, + { + "id": "4", + "idmaster": "3", + "cmd": "dialgroupextension", + "value": "7" + }, + { + "id": "5", + "idmaster": "2", + "cmd": "timeout", + "value": "" + } + +-------------------------------------------------------------------------------------------------------------------------------- + +dialdigit + + Toca o ramal digitado. + + { + "id": "1", + "idmaster": "1", + "cmd": "start", + "value": "551138118400" + }, + { + "id": "2", + "idmaster": "1", + "cmd": "playaudio", + "value": "demo-echotest.wav" + }, + { + "id": "3", + "idmaster": "2", + "cmd": "dialdigit", + "value": "" + } + +-------------------------------------------------------------------------------------------------------------------------------- + +dialgroupextension + + Toca todos os ramais que pertencem ao id de grupo passado no atributo value: + + { + "id": "1", + "idmaster": "1", + "cmd": "start", + "value": "551138118400" + }, + { + "id": "2", + "idmaster": "1", + "cmd": "dialgroupextension", + "value": "7" + } + +-------------------------------------------------------------------------------------------------------------------------------- + +dialplan.checkvar + + Coleta variável da memória do asterisk, verificando se "deu match". Para seguir um rota específica do IVR após o "match". + + { + "id": "1", + "idmaster": "1", + "cmd": "start", + "value": "551138118400" + }, + { + "id": "2", + "idmaster": "1", + "cmd": "playaudio", + "value": "bemvindo-digitecpf.wav" + }, + { + "id": "3", + "idmaster": "2", + "cmd": "custom", + "variation": "1", + "defaultvalues": { + "cmd": "dialplan.setvar", + "varname": "CPF" + } + }, + { + "id": "4", + "idmaster": "3", + "cmd": "custom", + "variation": "2", + "defaultvalues": { + "cmd": "dialplan.checkvar", + "varname": "CPF", + "varvalue": "123456" + } + }, + { + "id": "5", + "idmaster": "4", + "cmd": "playaudio", + "value": "cpfvalidado.wav" + } + +-------------------------------------------------------------------------------------------------------------------------------- + +dialplan.gosub + + Direciona a ligação para um trecho do dialplan do asterisk (A ligação volta ao IVR, caso não execute hangup no dialplan). + Atributo ctxname é o nome do contexto no dialplan. + Atributo ctxexten é o ${EXTEN} passado para o contexto do diaplan (Se não informado vai passar o valor 1001). + + { + "id": "1", + "idmaster": "1", + "cmd": "start", + "value": "551138118400" + }, + { + "id": "2", + "idmaster": "1", + "cmd": "playaudio", + "value": "bemvindo-digitecpf.wav" + }, + { + "id": "3", + "idmaster": "2", + "cmd": "custom", + "variation": "1", + "defaultvalues": { + "cmd": "dialplan.gosub", + "ctxname": "unimed", + "ctxexten": "1001" + } + } + +-------------------------------------------------------------------------------------------------------------------------------- + +dialplan.setvar + + Armazena na memória do asterisk, variável de nome passado no atributo "varname", o último valor digitado no IVR. + + { + "id": "1", + "idmaster": "1", + "cmd": "start", + "value": "551138118400" + }, + { + "id": "2", + "idmaster": "1", + "cmd": "playaudio", + "value": "bemvindo-digitecpf.wav" + }, + { + "id": "3", + "idmaster": "2", + "cmd": "custom", + "variation": "1", + "defaultvalues": { + "cmd": "dialplan.setvar", + "varname": "CPF" + } + } + +-------------------------------------------------------------------------------------------------------------------------------- + +digitinvalid + + Encaminha a ligação para o CMD seguinte, caso tenha sido digitado uma opção "inválida" de digito na URA. + + { + "id": "1", + "idmaster": "1", + "cmd": "start", + "value": "551138118400" + }, + { + "id": "2", + "idmaster": "1", + "cmd": "playaudio", + "value": "demo-echotest.wav" + }, + { + "id": "3", + "idmaster": "2", + "cmd": "digit", + "value": "1" + }, + { + "id": "4", + "idmaster": "3", + "cmd": "dialgroupextension", + "value": "7" + }, + { + "id": "5", + "idmaster": "2", + "cmd": "digitinvalid", + "value": "" + }, + { + "id": "6", + "idmaster": "5", + "cmd": "playaudio", + "value": "ddigito-invalido.wav" + } + +-------------------------------------------------------------------------------------------------------------------------------- + +dialextension + + Toca o ramal informado no atributo value. + + { + "id": "1", + "idmaster": "1", + "cmd": "start", + "value": "551138118400" + }, + { + "id": "2", + "idmaster": "1", + "cmd": "dialextension", + "value": "2601" + } + +-------------------------------------------------------------------------------------------------------------------------------- + +cnpj.check + + Verifica se o CNPJ digitado é válido. + No atributo value é passao o número máximo de tentativas (zero ou vazio para infinitas) + Caso seja válido. A ligação é encaminhado para o CMD cnpj.true + Caso não seja válido. A ligação é encaminhado para o CMD cnpj.false + Caso atinja o limite. A ligação é encaminhado para o CMD cnpj.limit + + { + "id": "1", + "idmaster": "1", + "cmd": "start", + "value": "551138118400" + }, + { + "id": "2", + "idmaster": "1", + "cmd": "playaudio", + "value": "demo-echotest.wav", + "value2": "3", + "value3": "11", + "value4": "true" + }, + { + "id": "3", + "idmaster": "2", + "cmd": "cnpj.check", + "value": "" + }, + { + "id": "4", + "idmaster": "3", + "cmd": "cnpj.true", + "value": "" + }, + { + "id": "5", + "idmaster": "3", + "cmd": "cnpj.false", + "value": "" + } + +-------------------------------------------------------------------------------------------------------------------------------- + +condtempo.check + + Verifica se esta em alguma condição de tempo. + Caso positivo. A ligação é encaminhado para o CMD condtempo.true + Caso negativo. A ligação é encaminhado para o CMD condtempo.false + O campo value é o id da tab_periodo + + { + "id": "1", + "idmaster": "1", + "cmd": "start", + "value": "551138118400" + }, + { + "id": "2", + "idmaster": "1", + "cmd": "condtempo.check", + "value": "12" + }, + { + "id": "3", + "idmaster": "2", + "cmd": "condtempo.true", + "value": "" + }, + { + "id": "4", + "idmaster": "2", + "cmd": "condtempo.false", + "value": "" + } + +-------------------------------------------------------------------------------------------------------------------------------- + +cpf.check + + Verifica se o CPF digitado é válido. + No atributo value é passao o número máximo de tentativas (zero ou vazio para infinitas) + Caso seja válido. A ligação é encaminhado para o CMD cpf.true + Caso não seja válido. A ligação é encaminhado para o CMD cpf.false + Caso atinja o limite. A ligação é encaminhado para o CMD cnpj.limit + + [ + { + "id": "1", + "idmaster": "1", + "cmd": "start", + "value": "2000" + }, + { + "id": "2", + "idmaster": "1", + "cmd": "playaudio", + "value": "demo-echotest.wav", + "value2": "3", + "value3": "11", + "value4": "false" + }, + { + "id": "3", + "idmaster": "2", + "cmd": "cpf.check", + "value": "2" + }, + { + "id": "4", + "idmaster": "3", + "cmd": "cpf.true", + "value": "" + }, + { + "id": "5", + "idmaster": "3", + "idnext": "2", + "cmd": "cpf.false", + "value": "" + }, + { + "id": "6", + "idmaster": "3", + "cmd": "cpf.limit", + "value": "" + }, + { + "id": "7", + "idmaster": "6", + "cmd": "playaudio", + "value": "vm-goodbye.wav", + "value2": "2", + "value3": "1", + "value4": "false" + }, + { + "id": "8", + "idmaster": "4", + "cmd": "playaudio", + "value": "vm-intro.wav", + "value2": "2", + "value3": "1", + "value4": "false" + } + ] + +-------------------------------------------------------------------------------------------------------------------------------- + +expediente.check + + Verifica se esta em horário de expediente. Não precisa passar nenhuma informação nos atributos value. + Caso estaja em horário de expediente. A ligação é encaminhado para o CMD expediente.true + Caso não estaja em horário de expediente. A ligação é encaminhado para o CMD expediente.false + + { + "id": "1", + "idmaster": "1", + "cmd": "start", + "value": "551138118400" + }, + { + "id": "2", + "idmaster": "1", + "cmd": "expediente.check", + "value": "" + }, + { + "id": "3", + "idmaster": "2", + "cmd": "expediente.true", + "value": "" + }, + { + "id": "4", + "idmaster": "2", + "cmd": "expediente.false", + "value": "" + } + +-------------------------------------------------------------------------------------------------------------------------------- + +feriado.check + + Verifica se é feriado cadastrado. + Não precisa passar nenhuma informação nos atributos value. + Caso seja feriado cadastrado. A ligação é encaminhado para o CMD feriado.true + Caso não seja feriado cadastrado. A ligação é encaminhado para o CMD feriado.false + + { + "id": "1", + "idmaster": "1", + "cmd": "start", + "value": "551138118400" + }, + { + "id": "2", + "idmaster": "1", + "cmd": "feriado.check", + "value": "" + }, + { + "id": "3", + "idmaster": "2", + "cmd": "feriado.true", + "value": "" + }, + { + "id": "4", + "idmaster": "2", + "cmd": "expediente.false", + "value": "" + } + +-------------------------------------------------------------------------------------------------------------------------------- + +ivr.redirect + + Encaminha a ligação para outro IVR (passado no atributo value). + + { + "id": "1", + "idmaster": "1", + "cmd": "start", + "value": "551138118400" + }, + { + "id": "2", + "idmaster": "1", + "cmd": "ivr.redirect", + "value": "080012344321" + } + +-------------------------------------------------------------------------------------------------------------------------------- + +pesqsat + + Executa o audio da pesquisa de satisfação e salva a nota digitada no id da pesquisa de satisfação passada no atributo value + + { + "id": "1", + "idmaster": "1", + "cmd": "start", + "value": "551138118400" + }, + { + "id": "2", + "idmaster": "1", + "cmd": "playaudio", + "value": "pesquisa.wav" + }, + { + "id": "3", + "idmaster": "2", + "cmd": "pesqsat", + "value": "1" + }, + +-------------------------------------------------------------------------------------------------------------------------------- + +playaudio + + Toca um arquivo de audio informando o arquivo no atributo value. + Atributo value2 => Timeout em segundos + Atributo value3 => Máximo de digitos esperado + Atributo value4 => Pronuncia os numeros digitados se passado o valor: true + + { + "id": "1", + "idmaster": "1", + "cmd": "start", + "value": "551138118400" + }, + { + "id": "2", + "idmaster": "1", + "cmd": "playaudio", + "value": "demo-echotest.wav", + "value2": "3", + "value3": "11", + "value4": "true" + } + +-------------------------------------------------------------------------------------------------------------------------------- + +playaudiotext + + Toca um audio a partir do texto passado no atributo value. + Atributo value2 => Timeout em segundos + Atributo value3 => Máximo de digitos esperado + Atributo value4 => Pronuncia os numeros digitados se passado o valor: true + + { + "id": "1", + "idmaster": "1", + "cmd": "start", + "value": "551138118400" + }, + { + "id": "2", + "idmaster": "1", + "cmd": "playaudiotext", + "value": "Testando 123" + "value2": "3", + "value3": "11", + "value4": "true" + } + +-------------------------------------------------------------------------------------------------------------------------------- + +queue + + Executa uma fila de antendimento. O id da fila é passado no atributo value. + + { + "id": "1", + "idmaster": "1", + "cmd": "start", + "value": "551138118400" + }, + { + "id": "2", + "idmaster": "1", + "cmd": "queue", + "value": "4" + } + +-------------------------------------------------------------------------------------------------------------------------------- + +queue.logadd + + Adiciona registro no queuelog. + value é o id da fila de atendimento + value2 pode ser IVRSTART ou IVRAPPEND + value3 é o texto digitado no IVR + + { + "id": "1", + "idmaster": "1", + "cmd": "start", + "value": "551138118400" + }, + { + "id": "2", + "idmaster": "1", + "cmd": "queue.logadd", + "value": "3", + "value2": "IVRSTART", + "value3": "AGUARDOU" + } + +-------------------------------------------------------------------------------------------------------------------------------- + +record + + Inicia a gravação da ligação. Não precisa passar nenhuma informação nos atributos value. + + { + "id": "1", + "idmaster": "1", + "cmd": "start", + "value": "551138118400" + }, + { + "id": "2", + "idmaster": "1", + "cmd": "record", + "value": "" + } + +-------------------------------------------------------------------------------------------------------------------------------- + +timeout + + Executa a partir de um evento "timeout" do CMD anterior ou em paralelo (ex.: CMD "digit"). Encaminhando a ligação para o CMD seguinte. + + { + "id": "1", + "idmaster": "1", + "cmd": "start", + "value": "551138118400" + }, + { + "id": "2", + "idmaster": "1", + "cmd": "playaudio", + "value": "demo-echotest.wav" + }, + { + "id": "3", + "idmaster": "2", + "cmd": "digit", + "value": "1" + }, + { + "id": "4", + "idmaster": "3", + "cmd": "dialgroupextension", + "value": "7" + }, + { + "id": "5", + "idmaster": "2", + "cmd": "timeout", + "value": "" + }, + { + "id": "6", + "idmaster": "5", + "cmd": "dialextension", + "value": "2601" + } + +-------------------------------------------------------------------------------------------------------------------------------- + +whitelist.check + + Verifica se o callerid esta na whitelist. + Caso esteja na lista, a ligação é encaminhado para o CMD whitelist.true + Caso não esteja na lista, a ligação é encaminhado para o CMD whitelist.false + + [ + { + "id": "1", + "idmaster": "1", + "cmd": "start", + "value": "2000" + }, + { + "id": "2", + "idmaster": "1", + "cmd": "whitelist.check", + "value": "" + }, + { + "id": "3", + "idmaster": "2", + "cmd": "whitelist.true", + "value": "" + }, + { + "id": "4", + "idmaster": "3", + "cmd": "playaudio", + "value": "demo-echotest.wav", + "value2": "2", + "value3": "1", + "value4": "false" + }, + { + "id": "5", + "idmaster": "2", + "cmd": "whitelist.false", + "value": "" + }, + { + "id": "6", + "idmaster": "5", + "cmd": "playaudio", + "value": "vm-goodbye.wav", + "value2": "2", + "value3": "1", + "value4": "false" + } + ] + +-------------------------------------------------------------------------------------------------------------------------------- +CMD que conecta com outro CMD +-------------------------------------------------------------------------------------------------------------------------------- + + Informe o "idnext" para após executar o comando, o fluxo seguir para o próximo item que esta no "idnext" + Abaixo, exemplo de loop infinito tocando o audio. + + { + "id": "1", + "idmaster": "1", + "cmd": "start", + "value": "551138118400" + }, + { + "id": "2", + "idmaster": "1", + "cmd": "playaudio", + "value": "demo-echotest.wav" + }, + { + "id": "3", + "idmaster": "2", + "idnext": "2", + "cmd": "timeout", + "value": "" + } + +-------------------------------------------------------------------------------------------------------------------------------- +Regras de negócio +-------------------------------------------------------------------------------------------------------------------------------- + +Conexões CMD "master" => "child" permitidas + +start => callerid.change +start => dialgroupextension +start => dialextention +start => cnpj.check +start => cpf.check +start => expediente.check +start => feriado.check +start => playaudio +start => playaudiotext +start => queue +start => record + +callerid.change => dialgroupextension +callerid.change => dialextention +callerid.change => cnpj.check +callerid.change => cpf.check +callerid.change => expediente.check +callerid.change => feriado.check +callerid.change => playaudio +callerid.change => playaudiotext +callerid.change => queue +callerid.change => record + +dialgroupextension => timeout + +dialextension => timeout + +digit => callerid.change +digit => dialgroupextension +digit => dialextention +digit => cnpj.check +digit => cpf.check +digit => expediente.check +digit => feriado.check +digit => playaudio +digit => playaudiotext +digit => queue +digit => record + +digitinvalid => callerid.change +digitinvalid => dialgroupextension +digitinvalid => dialextention +digitinvalid => cnpj.check +digitinvalid => cpf.check +digitinvalid => expediente.check +digitinvalid => feriado.check +digitinvalid => playaudio +digitinvalid => playaudiotext +digitinvalid => queue +digitinvalid => record + +blacklist.check => blacklist.false +blacklist.check => blacklist.true + +blacklist.false => callerid.change +blacklist.false => dialgroupextension +blacklist.false => dialextension +blacklist.false => expediente.check +blacklist.false => feriado.check +blacklist.false => playaudio +blacklist.false => playaudiotext +blacklist.false => queue +blacklist.false => record + +blacklist.true => callerid.change +blacklist.true => dialgroupextension +blacklist.true => dialextension +blacklist.true => feriado.check +blacklist.true => expediente.check +blacklist.true => playaudio +blacklist.true => playaudiotext +blacklist.true => queue +blacklist.true => record + +cnpj.check => cnpj.false +cnpj.check => cnpj.true +cnpj.check => cnpj.limit + +cnpj.false => callerid.change +cnpj.false => dialgroupextension +cnpj.false => dialextension +cnpj.false => expediente.check +cnpj.false => feriado.check +cnpj.false => playaudio +cnpj.false => playaudiotext +cnpj.false => queue +cnpj.false => record + +cnpj.true => callerid.change +cnpj.true => dialgroupextension +cnpj.true => dialextension +cnpj.true => feriado.check +cnpj.true => expediente.check +cnpj.true => playaudio +cnpj.true => playaudiotext +cnpj.true => queue +cnpj.true => record + +cnpj.limit => callerid.change +cnpj.limit => dialgroupextension +cnpj.limit => dialextension +cnpj.limit => feriado.check +cnpj.limit => expediente.check +cnpj.limit => playaudio +cnpj.limit => playaudiotext +cnpj.limit => queue +cnpj.limit => record + +cpf.check => cpf.false +cpf.check => cpf.true +cpf.check => cpf.limit + +cpf.false => callerid.change +cpf.false => dialgroupextension +cpf.false => dialextension +cpf.false => expediente.check +cpf.false => feriado.check +cpf.false => playaudio +cpf.false => playaudiotext +cpf.false => queue +cpf.false => record + +cpf.true => callerid.change +cpf.true => dialgroupextension +cpf.true => dialextension +cpf.true => feriado.check +cpf.true => expediente.check +cpf.true => playaudio +cpf.true => playaudiotext +cpf.true => queue +cpf.true => record + +cpf.limit => callerid.change +cpf.limit => dialgroupextension +cpf.limit => dialextension +cpf.limit => feriado.check +cpf.limit => expediente.check +cpf.limit => playaudio +cpf.limit => playaudiotext +cpf.limit => queue +cpf.limit => record + +expediente.check => expediente.false +expediente.check => expediente.true + +expediente.false => callerid.change +expediente.false => dialgroupextension +expediente.false => dialextention +expediente.false => feriado.check +expediente.false => playaudio +expediente.false => playaudiotext +expediente.false => queue +expediente.false => record + +expediente.true => callerid.change +expediente.true => dialgroupextension +expediente.true => dialextention +expediente.true => feriado.check +expediente.true => playaudio +expediente.true => playaudiotext +expediente.true => queue +expediente.true => record + +feriado.check => feriado.false +feriado.check => feriado.true + +feriado.false => callerid.change +feriado.false => dialgroupextension +feriado.false => dialextention +feriado.false => expediente.check +feriado.false => playaudio +feriado.false => playaudiotext +feriado.false => queue +feriado.false => record + +feriado.true => callerid.change +feriado.true => dialgroupextension +feriado.true => dialextention +feriado.true => expediente.check +feriado.true => playaudio +feriado.true => playaudiotext +feriado.true => queue +feriado.true => record + +playaudio => callerid.change +playaudio => dialgroupextension +playaudio => dialextention +playaudio => digit +playaudio => digitinvalid +playaudio => cnpj.check +playaudio => cpf.check +playaudio => expediente.check +playaudio => feriado.check +playaudio => playaudio +playaudio => playaudiotext +playaudio => queue +playaudio => record + +playaudiotext => callerid.change +playaudiotext => dialgroupextension +playaudiotext => dialextention +playaudiotext => digit +playaudiotext => digitinvalid +playaudiotext => cnpj.check +playaudiotext => cpf.check +playaudiotext => expediente.check +playaudiotext => feriado.check +playaudiotext => playaudio +playaudiotext => playaudiotext +playaudiotext => queue +playaudiotext => record + +record => callerid.change +record => dialgroupextension +record => dialextention +record => expediente.check +record => feriado.check +record => playaudio +record => playaudiotext +record => queue + +timeout => callerid.change +timeout => dialgroupextension +timeout => dialextention +timeout => expediente.check +timeout => feriado.check +timeout => playaudio +timeout => playaudiotext +timeout => queue +timeout => record + +whitelist.check => whitelist.false +whitelist.check => whitelist.true + +whitelist.false => callerid.change +whitelist.false => dialgroupextension +whitelist.false => dialextension +whitelist.false => expediente.check +whitelist.false => feriado.check +whitelist.false => playaudio +whitelist.false => playaudiotext +whitelist.false => queue +whitelist.false => record + +whitelist.true => callerid.change +whitelist.true => dialgroupextension +whitelist.true => dialextension +whitelist.true => feriado.check +whitelist.true => expediente.check +whitelist.true => playaudio +whitelist.true => playaudiotext +whitelist.true => queue +whitelist.true => record + +-------------------------------------------------------------------------------------------------------------------------------- + +Conexões CMD permitidas em paralelo + +blacklist.true => blacklist.false +blacklist.false => blacklist.true + +cnpj.true => cnpj.false +cnpj.true => cnpj.limit +cnpj.false => cnpj.limit +cnpj.false => cnpj.true +cnpj.limit => cnpj.false +cnpj.limit => cnpj.true + +cpf.true => cpf.false +cpf.true => cpf.limit +cpf.false => cpf.limit +cpf.false => cpf.true +cpf.limit => cpf.false +cpf.limit => cpf.true + +digit <=> digit +digit <=> digitinvalid +digit <=> timeout + +expediente.true <=> expediente.false +expediente.false <=> expediente.true + +feriado.true <=> feriado.false +feriado.false <=> feriado.true + +timeout <=> digit +timeout <=> digitinvalid + +whitelist.true <=> whitelist.false +whitelist.false <=> whitelist.true + +-------------------------------------------------------------------------------------------------------------------------------- \ No newline at end of file diff --git a/hitagi-entrada-swoole.php b/hitagi-entrada-swoole.php index c13371f..8704f13 100644 --- a/hitagi-entrada-swoole.php +++ b/hitagi-entrada-swoole.php @@ -2,6 +2,7 @@ require __DIR__ . 'vendor/autoload.php'; require __DIR__ . 'includes/wrapper-swoole.php'; +use Hitlabs\Hitagi\AGIEntrada; use Swoole\Runtime; use Swoole\Table; use Swoole\Server; @@ -37,7 +38,7 @@ $server->on("receive", function ($server, $fd, $reactor_id, $data) { 'agi' => 1, 'data' => '', )); - $agi = new \Hit\Ami\AGIEntrada( + $agi = new AGIEntrada( array( 'agiRunCmd' => agiRunCmdSwooleWrapper($fd, $server), 'agiLog' => function ($info) { diff --git a/hitagi-entrada.php b/hitagi-entrada.php index 63f42bb..2811c3b 100644 --- a/hitagi-entrada.php +++ b/hitagi-entrada.php @@ -3,27 +3,26 @@ require 'vendor/autoload.php'; require 'includes/wrapper-noswoole.php'; +use Hitlabs\Hitagi\AGIEntrada; + $stdin = fopen('php://stdin', 'r'); $stdout = fopen('php://stdout', 'w'); - $fgId = (isset($argv[1])) ? $argv[1] : ''; // DID - $logEnabled = true; -$isXampp = (file_exists('C:\xampp')); +$isXampp = file_exists('C:\xampp'); +$asteriskip = ''; // 177.107.205.248 $appdir = dirname(__FILE__); - chdir($appdir); - date_default_timezone_set('America/Bahia'); -$agientrada = new \Hit\Ami\AGIEntrada( +$agientrada = new AGIEntrada( array( 'agiRunCmd' => agiRunCmdWrapper($stdin, $stdout), - 'agiLog' => agiLogWrapper($logEnabled) + 'agiLog' => agiLogWrapper() ), array( 'fgId' => $fgId, - 'asteriskip' => '177.107.205.248', + 'asteriskip' => $asteriskip, 'logEnabled' => $logEnabled, 'appdir' => $appdir, 'isXampp' => $isXampp diff --git a/includes/wrapper-noswoole.php b/includes/wrapper-noswoole.php index 9ca4093..01cc752 100644 --- a/includes/wrapper-noswoole.php +++ b/includes/wrapper-noswoole.php @@ -7,33 +7,26 @@ function agiRunCmdWrapper($stdin, $stdout) // return $texto; $return = ''; - fwrite($stdout, $command . "\n"); - fflush($stdout); - while ($line = fgets($stdin)) { - $return.= $line; - if (strpos($line, 'result=') !== false) { - if (substr($line,0,22) != '100 result=0 Trying...') { - break; - } - } - } - $return = trim($return); - return $return; - - }; -} - -function agiLogWrapper($logEnabled) -{ - return function ($texto, $options = array()) use ($logEnabled) { - if ($logEnabled) { - $target = 'log' . DIRECTORY_SEPARATOR . 'log.txt'; - $texto .= PHP_EOL; - if (isset($options['new'])) { - file_put_contents($target, $texto); - } else { - file_put_contents($target, $texto, FILE_APPEND); + fwrite($stdout, $command . "\n"); + fflush($stdout); + while ($line = fgets($stdin)) { + $return .= $line; + if (strpos($line, 'result=') !== false) { + if (substr($line, 0, 22) != '100 result=0 Trying...') { + break; + } } } + $return = trim($return); + return $return; + }; +} + +function agiLogWrapper() +{ + return function ($texto) { + $target = 'log' . DIRECTORY_SEPARATOR . 'log.txt'; + $texto = trim($texto) . PHP_EOL; + file_put_contents($target, $texto, FILE_APPEND); }; } diff --git a/log/log.html b/log/log.html index 39aad01..e743e1a 100644 --- a/log/log.html +++ b/log/log.html @@ -1,73 +1,51 @@ -2024-12-12 15:38:34
Array
+2024-12-13 22:07:35
Array
 (
-    [fgId] => 7998
+    [fgId] => 8999
+    [asteriskip] => 
     [logEnabled] => 1
     [appdir] => C:\xampp\htdocs\hit\gitea\hitagi-entrada
     [isXampp] => 1
 )
-

Array
-(
-    [1] => Array
-        (
-            [id] => 1
-            [idmaster] => 0
-            [cmd] => start
-            [value] => 7999
-        )
-
-    [2] => Array
-        (
-            [id] => 2
-            [idmaster] => 1
-            [cmd] => playaudio
-            [value] => welcome.wav
-            [value2] => 2
-            [value3] => 1
-            [value4] => false
-        )
-
-    [3] => Array
-        (
-            [id] => 3
-            [idmaster] => 2
-            [cmd] => timeout
-            [value] => 
-        )
-
-    [4] => Array
-        (
-            [id] => 4
-            [idmaster] => 3
-            [cmd] => playaudio
-            [value] => timeout.wav
-            [value2] => 2
-            [value3] => 1
-            [value4] => false
-        )
-
-)
-

Array
+


fgItemRun
Array
 (
     [id] => 1
     [idmaster] => 0
     [cmd] => start
-    [value] => 7999
+    [value] => 8999
 )
-


fgItemRun

Array
-(
-    [id] => 1
-    [idmaster] => 0
-    [cmd] => start
-    [value] => 7999
-)
-


fgItemRun

Array
+


fgItemRun
Array
 (
     [id] => 2
     [idmaster] => 1
     [cmd] => playaudio
-    [value] => welcome.wav
+    [value] => 32021341DIGITEOCPF.mp3
+    [value2] => 5
+    [value3] => 1
+    [value4] => false
+)
+


fgItemRun
Array
+(
+    [id] => 3
+    [idmaster] => 2
+    [cmd] => timeout
+    [value] => 
+)
+


fgItemRun
Array
+(
+    [id] => 4
+    [idmaster] => 3
+    [cmd] => playaudio
+    [value] => Agradecimento.wav
     [value2] => 2
     [value3] => 1
     [value4] => false
 )
-

\ No newline at end of file +


fgItemRun
Array
+(
+    [id] => 5
+    [idmaster] => 4
+    [cmd] => queue
+    [value] => 13
+    [value2] => 5
+)
+


fgItemRunQueue

\ No newline at end of file diff --git a/log/log.txt b/log/log.txt index 1832964..75717d8 100644 --- a/log/log.txt +++ b/log/log.txt @@ -1,40 +1,80 @@ -2024-12-12 15:38:34 -fgItemRunStart - +===> fgItemRunStart <=== Array ( [id] => 1 [idmaster] => 0 [cmd] => start - [value] => 7999 + [value] => 8999 ) - - -fgItemRunPlayaudio - +===> fgItemRunPlayaudio <=== Array ( [id] => 2 [idmaster] => 1 [cmd] => playaudio - [value] => welcome.wav + [value] => 32021341DIGITEOCPF.mp3 + [value2] => 5 + [value3] => 1 + [value4] => false +) +===> agiRunCmd <=== +SET VARIABLE AGIDIGITADO "" +200 result=1 (isXampp) +===> fgItemRunTimeout <=== +Array +( + [id] => 3 + [idmaster] => 2 + [cmd] => timeout + [value] => +) +===> fgItemRunPlayaudio <=== +Array +( + [id] => 4 + [idmaster] => 3 + [cmd] => playaudio + [value] => Agradecimento.wav [value2] => 2 [value3] => 1 [value4] => false ) - - +===> agiRunCmd <=== SET VARIABLE AGIDIGITADO "" - ------> EXECUTAR COMANDO SET VARIABLE AGIDIGITADO "" - -digitado: 2 - -SET VARIABLE AGIDIGITADO 2 - ------> EXECUTAR COMANDO SET VARIABLE AGIDIGITADO 2 - -Digitado não validado como ramal para usar "dialdigit" - -Not found next icon "digit" or "dialdigit" or "digitinvalid" - +200 result=1 (isXampp) +===> fgItemRunQueue <=== +Array +( + [id] => 5 + [idmaster] => 4 + [cmd] => queue + [value] => 13 + [value2] => 5 +) +===> agiRunCmd <=== +SET VARIABLE __AGIQUEUEID "Q13" +200 result=1 (isXampp) +===> agiRunCmd <=== +SET VARIABLE __AGIQUEUENOME "SAC" +200 result=1 (isXampp) +===> agiRunCmd <=== +SET VARIABLE MONITOR_FILENAME QUEUE_2024-12-13_22-07-35_20241213.220735_1138118400_8999 +200 result=1 (isXampp) +===> agiRunCmd <=== +SET VARIABLE __AGIRECORDNAME QUEUE_2024-12-13_22-07-35_20241213.220735_1138118400_8999 +200 result=1 (isXampp) +===> agiRunCmd <=== +GET FULL VARIABLE ${PJSIP_DIAL_CONTACTS(1001)} +200 result=1 (isXampp) +===> agiRunCmd <=== +GET FULL VARIABLE ${PJSIP_DIAL_CONTACTS(SIP1001)} +200 result=1 (isXampp) +===> agiRunCmd <=== +EXEC Dial isXampp&isXampp,30,Tt "" +200 result=1 (isXampp) +===> agiRunCmd <=== +GET VARIABLE DIALSTATUS +200 result=1 (isXampp) +===> agiRunCmd <=== +EXEC PLAYBACK /var/lib/asterisk/sounds/pt_BR/exten-unavail "" +200 result=1 (isXampp) diff --git a/sonar-project.properties b/sonar-project.properties deleted file mode 100644 index cf40a0a..0000000 --- a/sonar-project.properties +++ /dev/null @@ -1,8 +0,0 @@ -sonar.projectKey=my_project_key -sonar.projectName=My Project -sonar.projectVersion=1.0 - -sonar.sources=hitagi-entrada.php -sonar.language=php -sonar.host.url=http://localhost:9000 - diff --git a/src/AGIEntrada-old.php b/src/AGIEntrada-old.php deleted file mode 100644 index eec2718..0000000 --- a/src/AGIEntrada-old.php +++ /dev/null @@ -1,43 +0,0 @@ -globais = array(); - $this->injection = $injection; - } - - public function agiRunCmd ($command) { - return $this->injection['agiRunCmd']($command); - } - - public function agiLog ($info) { - return $this->injection['agiLog']($info); - } - - function tocarFila($queueId, $timeout) { - $this->agiRunCmd('EXEC Queue Q' . $queueId . ',ctT,,,' . 1); - } - - public function run() { - $this->agiLog( - array( - 'filename' => 'log.txt', - 'txt' => "LOG ======> Iniciando o processamento da chamada", - ) - ); - // echo "LOG ======> Iniciando o processamento da chamada" . PHP_EOL; - // echo "LOG ======> Dados iniciais: " . $this->globais['initialData'] . PHP_EOL; - // $response = $this->agiRunCmd('EXEC NOOP HITAGI'); - // $response = $this->agiRunCmd('ANSWER'); - // $response = $this->agiRunCmd('EXEC PLAYBACK beep'); - $this->globais['nomeFila'] = '10'; - $response = $this->tocarFila($this->globais['nomeFila'], 1); - print_r("Retorno $response" . PHP_EOL); - } -} -?> \ No newline at end of file diff --git a/src/AGIEntrada.php b/src/AGIEntrada.php deleted file mode 100644 index a817c87..0000000 --- a/src/AGIEntrada.php +++ /dev/null @@ -1,750 +0,0 @@ -globais = $globais; - $this->injection = $injection; - } - - public function agiRunCmd($command) - { - return $this->injection['agiRunCmd']($command); - } - - public function agiLog($texto, $options = array()) - { - return $this->injection['agiLog']($texto, $options); - } - - // -------------------------------------------------------------------------------------------------------------------------------- - - public function logStart() - { - if ($this->globais['logEnabled']) { - $texto = date("Y-m-d H:i:s") . "
"; - $target = $this->globais['appdir'] . DIRECTORY_SEPARATOR . 'log' . DIRECTORY_SEPARATOR . 'log.html'; - $fp = fopen($target, 'w'); - fwrite($fp, $texto); - fclose($fp); - } - } - - public function logAdd($texto) - { - if ($this->globais['logEnabled']) { - $target = $this->globais['appdir'] . DIRECTORY_SEPARATOR . 'log' . DIRECTORY_SEPARATOR . 'log.html'; - $fp = fopen($target, 'a'); - fwrite($fp, $texto); - fclose($fp); - } - } - - // -------------------------------------------------------------------------------------------------------------------------------- - - public function ivrGet() - { - $this->globais['fgItens'] = array(); - $this->globais['fgItemStart'] = array(); - if ($this->globais['fgId'] != '') { - if ($this->globais['asteriskip'] != '') { - // http://177.107.205.248/fluxograma/data-json/8999.json - $target = 'http://' . $this->globais['asteriskip'] . '/fluxograma/data-json/' . $this->globais['fgId'] . '.json'; - } else { - if (file_exists('/etc/asterisk')) { - $target = '/var/www/html/fluxograma/data-json/' . $this->globais['fgId'] . '.json'; - } else { - $target = 'dial/' . $this->globais['fgId'] . '.json'; - } - } - $this->agiLog($target); - $itens = file_get_contents($target); - if ($itens !== false) { - $itens = json_decode($itens, true); - foreach ($itens as $item) { - $this->globais['fgItens'][$item['id']] = $item; - if ($item['cmd'] == 'start') { - $this->globais['fgItemStart'] = $item; - } - } - unset($itens); - } - } - } - - // -------------------------------------------------------------------------------------------------------------------------------- - - public function agiVarGet($varName = '') - { - - $return = ''; - - if ($this->globais['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 = $this->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; - } - - public function agiVarSet($varName = '', $varValue = '') - { - - if ($this->globais['isXampp']) { - - return ''; - } else { - - if ($varName == 'CALLERID') { - $varName = 'CALLERID(num)'; - } - $return = $this->agiRunCmd('SET VARIABLE ' . $varName . ' ' . $varValue); - return $return; - } - } - - // -------------------------------------------------------------------------------------------------------------------------------- - - function fgItemGetChildrenFrom($fgItemFrom = array()) - { - - // $this->agiLog('fgItemGetChildrenFrom'); - // $this->agiLog(print_r($fgItemFrom, true)); - - $return = array(); - reset($this->globais['fgItens']); - foreach ($this->globais['fgItens'] as $fgItem) { - if ($fgItem['cmd'] != 'start') { - if ($fgItem['idmaster'] == $fgItemFrom['id']) { - $return[$fgItem['id']] = $fgItem; - } - } - } - return $return; - } - - public function fgItemRun($fgItem = array()) - { - - // $this->agiLog('fgItemRun'); - // $this->agiLog(print_r($fgItem, true) . "\n"); - - $this->logAdd("
fgItemRun

"); - $this->logAdd("
" . print_r($fgItem, true) . "

"); - - 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') { - $this->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') { - $this->fgItemRunStart($fgItem); - return; - } - if ($fgItem['cmd'] == 'timeout') { - $this->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()) - { - - // $this->agiLog('fgItemRunNextFrom'); - // $this->agiLog(print_r($fgItemFrom, true)); - - $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($this->globais['fgItens'][$fgItemFrom['idnext']])) { - fgItemRun($this->globais['fgItens'][$fgItemFrom['idnext']]); - $run_next = false; - } - } - - $fgItemChildren = $this->fgItemGetChildrenFrom($fgItemFrom); - foreach ($fgItemChildren as $fgItemChild) { - if (($run_next) && (!in_array($fgItemChild['cmd'], $cmds_nonext))) { - $this->fgItemRun($fgItemChild); - $run_next = false; - } - } - } - - public function fgItemRunPlayaudio($fgItem = array()) - { - - $this->agiLog('===> fgItemRunPlayaudio'); - $this->agiLog(print_r($fgItem, true)); - - $this->globais['digitado'] = ''; - - $cmd = 'SET VARIABLE AGIDIGITADO ""'; - $this->agiLog($cmd); - $response = $this->agiRunCmd($cmd); - $this->agiLog($response); - - if ($this->globais['isXampp']) { - $rnd = rand(1, 100); - if ($rnd >= 60) { - $this->globais['digitado'] = rand(0, 9); - } else if ($rnd >= 40) { - $this->globais['digitado'] = 'A'; - } else if ($rnd >= 20) { - $this->globais['digitado'] = '1001'; - } else { - $this->globais['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; - $this->agiLog($cmd); - $response = $this->agiRunCmd($cmd); - $this->agiLog($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); - $this->globais['digitado'] = $explodido[1]; - } - } - - $this->agiLog("digitado: " . $this->globais['digitado']); - - $run_next = true; - - if ($this->globais['digitado'] == '') { - - $fgItemChildren = $this->fgItemGetChildrenFrom($fgItem); - foreach ($fgItemChildren as $fgItemChild) { - if ($run_next) { - if ($fgItemChild['cmd'] == 'timeoutwithlimit') { - $this->fgItemRun($fgItemChild); - $run_next = false; - } - } - } - - $fgItemChildren = $this->fgItemGetChildrenFrom($fgItem); - foreach ($fgItemChildren as $fgItemChild) { - if ($run_next) { - if ($fgItemChild['cmd'] == 'timeout') { - $this->fgItemRun($fgItemChild); - $run_next = false; - } - } - } - - if ($run_next) { - $this->agiLog('Not found next icon "timeoutwithlimit" or "timeout"'); - $this->agiLog('Goto next icon if exists...'); - $this->fgItemRunNextFrom($fgItem); - } - - $run_next = false; - } else { - - $cmd = 'SET VARIABLE AGIDIGITADO ' . $this->globais['digitado']; - $this->agiLog($cmd); - $response = $this->agiRunCmd($cmd); - $this->agiLog($response); - - $cmd = 'EXEC QUEUELOG NONE,' . $this->globais['uniqueid'] . ',NONE,INFO|IVRAPPEND|->' . $this->globais['digitado']; - $response = $this->agiRunCmd($cmd); - } - - if ($run_next) { - $fgItemChildren = $this->fgItemGetChildrenFrom($fgItem); - foreach ($fgItemChildren as $fgItemChild) { - if ($run_next) { - if ($fgItemChild['cmd'] == 'digit') { - if ($fgItemChild['value'] == $this->globais['digitado']) { - $this->fgItemRun($fgItemChild); - $run_next = false; - } - } - } - } - } - - if ($run_next) { - $tamanho = strlen($this->globais['digitado']); - if (($tamanho >= 3) && ($tamanho <= 4)) { - $fgItemChildren = $this->fgItemGetChildrenFrom($fgItem); - foreach ($fgItemChildren as $fgItemChild) { - if ($run_next) { - if ($fgItemChild['cmd'] == 'dialdigit') { - $this->fgItemRun($fgItemChild); - $run_next = false; - } - } - } - } else { - $this->agiLog('Digitado não validado como ramal para usar "dialdigit"'); - } - } - - if ($run_next) { - $fgItemChildren = $this->fgItemGetChildrenFrom($fgItem); - foreach ($fgItemChildren as $fgItemChild) { - if ($run_next) { - if ($fgItemChild['cmd'] == 'digitinvalid') { - $this->fgItemRun($fgItemChild); - $run_next = false; - } - } - } - } - - if ($run_next) { - $this->agiLog('Not found next icon "digit" or "dialdigit" or "digitinvalid"'); - $this->fgItemRunNextFrom($fgItem); - } - } - - function fgItemRunStart($fgItem = array()) - { - $this->agiLog('===> fgItemRunStart'); - $this->agiLog(print_r($fgItem, true)); - - // 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']; - // ... - - $this->fgItemRunNextFrom($fgItem); - } - - function fgItemRunTimeout($fgItem = array()) - { - $this->agiLog('===> fgItemRunTimeout'); - $this->agiLog(print_r($fgItem, true)); - - $run_next = true; - - $fgItemChildren = $this->fgItemGetChildrenFrom($fgItem); - foreach ($fgItemChildren as $fgItemChild) { - if ($run_next) { - if ($fgItemChild['cmd'] == 'voicemail') { - $this->agiLog('Found icon "voicemail"'); - $this->fgItemRun($fgItemChild); - $run_next = false; - } - } - } - - if ($run_next) { - $this->fgItemRunNextFrom($fgItem); - } - } - - public function teste() - { - $this->agiLog($this->globais['fgId']); - } - - function tocarFila($queueId, $timeout) - { - return $this->agiRunCmd('EXEC Queue Q' . $queueId . ',ctT,,,' . $timeout); - } - - // -------------------------------------------------------------------------------------------------------------------------------- - - public function run() - { - $this->agiLog(date("Y-m-d H:i:s"), array('new' => true)); - - $this->logStart(); - $this->logAdd("
" . print_r($this->globais, true) . "

"); - - - $this->ivrGet(); - - $this->logAdd("
" . print_r($this->globais['fgItens'], true) . "

"); - $this->logAdd("
" . print_r($this->globais['fgItemStart'], true) . "

"); - - if (count($this->globais['fgItemStart']) > 0) { - - $this->globais['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 ($this->globais['isXampp']) { - - $this->globais['callerid'] = '1138118400'; - $this->globais['uniqueid'] = date("Ymd") . "." . date("His"); - $this->globais['digitado'] = ''; - - $host = 'localhost'; - $user = 'root'; - $password = ''; - $database = 'hitpbx_homologacao'; - $port = '3306'; - $this->globais['db'] = mysqli_connect($host, $user, $password, $database, $port) or die('Erro de conexão com o banco de dados'); - mysqli_set_charset($this->globais['db'], 'utf8'); - - $this->fgItemRun($this->globais['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'; - $this->globais['db'] = mysqli_connect($host, $user, $password, $database, $port) or die('Erro de conexão com o banco de dados'); - mysqli_set_charset($this->globais['db'], 'utf8'); - - /* - logAdd("111
"); - $query = "SELECT * FROM tab_ramal LIMIT 1"; - $result = mysqli_query($db,$query); - logAdd($query."
"); - $result = mysqli_query($this->globais['db'],$query); - logAdd($query."
"); - */ - - // ... - - /* - $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 = $this->agiRunCmd('EXEC NOOP HITAGI'); - $response = $this->agiRunCmd('ANSWER'); - $response = $this->agiRunCmd('EXEC WAIT 1'); - $response = $this->agiRunCmd('EXEC PLAYBACK beep'); - $response = $this->agiRunCmd('EXEC WAIT 1'); - - $this->globais['digitado'] = ''; - - $this->globais['callerid'] = $this->agiVarGet('CALLERID'); - $this->globais['uniqueid'] = $this->agiVarGet('UNIQUEID'); - - $response = $this->agiVarSet('AGIDID', $this->globais['fgId']); - - $cmd = 'EXEC QUEUELOG NONE,' . $this->globais['uniqueid'] . ',NONE,INFO|IVRSTART'; - $response = $this->agiRunCmd($cmd); - - $cmd = 'EXEC QUEUELOG NONE,' . $this->globais['uniqueid'] . ',NONE,INFO|IVRAPPEND|->' . $this->globais['fgId']; - $response = $this->agiRunCmd($cmd); - - $this->fgItemRun($this->globais['fgItemStart']); - - // 1353461660|1353461627.33271|NONE|NONE|INFO|IVRHANGUP| - //$cmd = 'EXEC QUEUELOG NONE,' . $GLOBALS['uniqueid'] . ',NONE,NONE,INFO|IVRHANGUP'; - //$response = agiRunCmd($cmd); - - // $response = agiRunCmd('HANGUP'); - - } - } - - /* - $this->teste(); - $this->globais['nomeFila'] = '10'; - $response = $this->tocarFila($this->globais['nomeFila'], 1); - echo "\n" . $response . "\n"; - */ - } -} diff --git a/txt.txt b/txt.txt deleted file mode 100644 index ba9736d..0000000 --- a/txt.txt +++ /dev/null @@ -1 +0,0 @@ -=> \ No newline at end of file diff --git a/vendor/autoload.php b/vendor/autoload.php index b5c1cba..2ace7f3 100644 --- a/vendor/autoload.php +++ b/vendor/autoload.php @@ -4,4 +4,4 @@ require_once __DIR__ . '/composer/autoload_real.php'; -return ComposerAutoloaderInit7cccddac512163c6eaa2449701d7945d::getLoader(); +return ComposerAutoloaderInit6629c2e9a27a691df05b9e008a8437de::getLoader(); diff --git a/vendor/composer/autoload_psr4.php b/vendor/composer/autoload_psr4.php index 71adb5c..9a34a5a 100644 --- a/vendor/composer/autoload_psr4.php +++ b/vendor/composer/autoload_psr4.php @@ -12,7 +12,7 @@ return array( 'Psr\\Http\\Message\\' => array($vendorDir . '/psr/http-factory/src', $vendorDir . '/psr/http-message/src'), 'Psr\\Http\\Client\\' => array($vendorDir . '/psr/http-client/src'), 'PhpOption\\' => array($vendorDir . '/phpoption/phpoption/src/PhpOption'), - 'Hit\\Ami\\' => array($baseDir . '/src'), + 'Hitlabs\\Hitagi\\' => array($baseDir . '/classes'), 'GuzzleHttp\\Psr7\\' => array($vendorDir . '/guzzlehttp/psr7/src'), 'GuzzleHttp\\Promise\\' => array($vendorDir . '/guzzlehttp/promises/src'), 'GuzzleHttp\\' => array($vendorDir . '/guzzlehttp/guzzle/src'), diff --git a/vendor/composer/autoload_real.php b/vendor/composer/autoload_real.php index 42af59d..381ccbf 100644 --- a/vendor/composer/autoload_real.php +++ b/vendor/composer/autoload_real.php @@ -2,7 +2,7 @@ // autoload_real.php @generated by Composer -class ComposerAutoloaderInit7cccddac512163c6eaa2449701d7945d +class ComposerAutoloaderInit6629c2e9a27a691df05b9e008a8437de { private static $loader; @@ -24,15 +24,15 @@ class ComposerAutoloaderInit7cccddac512163c6eaa2449701d7945d require __DIR__ . '/platform_check.php'; - spl_autoload_register(array('ComposerAutoloaderInit7cccddac512163c6eaa2449701d7945d', 'loadClassLoader'), true, true); + spl_autoload_register(array('ComposerAutoloaderInit6629c2e9a27a691df05b9e008a8437de', 'loadClassLoader'), true, true); self::$loader = $loader = new \Composer\Autoload\ClassLoader(\dirname(\dirname(__FILE__))); - spl_autoload_unregister(array('ComposerAutoloaderInit7cccddac512163c6eaa2449701d7945d', 'loadClassLoader')); + spl_autoload_unregister(array('ComposerAutoloaderInit6629c2e9a27a691df05b9e008a8437de', 'loadClassLoader')); $useStaticLoader = PHP_VERSION_ID >= 50600 && !defined('HHVM_VERSION') && (!function_exists('zend_loader_file_encoded') || !zend_loader_file_encoded()); if ($useStaticLoader) { require __DIR__ . '/autoload_static.php'; - call_user_func(\Composer\Autoload\ComposerStaticInit7cccddac512163c6eaa2449701d7945d::getInitializer($loader)); + call_user_func(\Composer\Autoload\ComposerStaticInit6629c2e9a27a691df05b9e008a8437de::getInitializer($loader)); } else { $map = require __DIR__ . '/autoload_namespaces.php'; foreach ($map as $namespace => $path) { @@ -53,12 +53,12 @@ class ComposerAutoloaderInit7cccddac512163c6eaa2449701d7945d $loader->register(true); if ($useStaticLoader) { - $includeFiles = Composer\Autoload\ComposerStaticInit7cccddac512163c6eaa2449701d7945d::$files; + $includeFiles = Composer\Autoload\ComposerStaticInit6629c2e9a27a691df05b9e008a8437de::$files; } else { $includeFiles = require __DIR__ . '/autoload_files.php'; } foreach ($includeFiles as $fileIdentifier => $file) { - composerRequire7cccddac512163c6eaa2449701d7945d($fileIdentifier, $file); + composerRequire6629c2e9a27a691df05b9e008a8437de($fileIdentifier, $file); } return $loader; @@ -70,7 +70,7 @@ class ComposerAutoloaderInit7cccddac512163c6eaa2449701d7945d * @param string $file * @return void */ -function composerRequire7cccddac512163c6eaa2449701d7945d($fileIdentifier, $file) +function composerRequire6629c2e9a27a691df05b9e008a8437de($fileIdentifier, $file) { if (empty($GLOBALS['__composer_autoload_files'][$fileIdentifier])) { $GLOBALS['__composer_autoload_files'][$fileIdentifier] = true; diff --git a/vendor/composer/autoload_static.php b/vendor/composer/autoload_static.php index 7574158..885b0a4 100644 --- a/vendor/composer/autoload_static.php +++ b/vendor/composer/autoload_static.php @@ -4,7 +4,7 @@ namespace Composer\Autoload; -class ComposerStaticInit7cccddac512163c6eaa2449701d7945d +class ComposerStaticInit6629c2e9a27a691df05b9e008a8437de { public static $files = array ( '7b11c4dc42b3b3023073cb14e519683c' => __DIR__ . '/..' . '/ralouphie/getallheaders/src/getallheaders.php', @@ -30,7 +30,7 @@ class ComposerStaticInit7cccddac512163c6eaa2449701d7945d ), 'H' => array ( - 'Hit\\Ami\\' => 8, + 'Hitlabs\\Hitagi\\' => 15, ), 'G' => array ( @@ -75,9 +75,9 @@ class ComposerStaticInit7cccddac512163c6eaa2449701d7945d array ( 0 => __DIR__ . '/..' . '/phpoption/phpoption/src/PhpOption', ), - 'Hit\\Ami\\' => + 'Hitlabs\\Hitagi\\' => array ( - 0 => __DIR__ . '/../..' . '/src', + 0 => __DIR__ . '/../..' . '/classes', ), 'GuzzleHttp\\Psr7\\' => array ( @@ -117,9 +117,9 @@ class ComposerStaticInit7cccddac512163c6eaa2449701d7945d public static function getInitializer(ClassLoader $loader) { return \Closure::bind(function () use ($loader) { - $loader->prefixLengthsPsr4 = ComposerStaticInit7cccddac512163c6eaa2449701d7945d::$prefixLengthsPsr4; - $loader->prefixDirsPsr4 = ComposerStaticInit7cccddac512163c6eaa2449701d7945d::$prefixDirsPsr4; - $loader->classMap = ComposerStaticInit7cccddac512163c6eaa2449701d7945d::$classMap; + $loader->prefixLengthsPsr4 = ComposerStaticInit6629c2e9a27a691df05b9e008a8437de::$prefixLengthsPsr4; + $loader->prefixDirsPsr4 = ComposerStaticInit6629c2e9a27a691df05b9e008a8437de::$prefixDirsPsr4; + $loader->classMap = ComposerStaticInit6629c2e9a27a691df05b9e008a8437de::$classMap; }, null, ClassLoader::class); } diff --git a/vendor/composer/installed.php b/vendor/composer/installed.php index f8f1e0d..f2e0785 100644 --- a/vendor/composer/installed.php +++ b/vendor/composer/installed.php @@ -2,11 +2,11 @@ 'root' => array( 'pretty_version' => '1.0.0+no-version-set', 'version' => '1.0.0.0', - 'type' => 'library', + 'type' => 'project', 'install_path' => __DIR__ . '/../../', 'aliases' => array(), 'reference' => NULL, - 'name' => 'hit/ami', + 'name' => 'hitlabs/hitagi', 'dev' => true, ), 'versions' => array( @@ -55,10 +55,10 @@ 'reference' => 'a70f5c95fb43bc83f07c9c948baa0dc1829bf201', 'dev_requirement' => false, ), - 'hit/ami' => array( + 'hitlabs/hitagi' => array( 'pretty_version' => '1.0.0+no-version-set', 'version' => '1.0.0.0', - 'type' => 'library', + 'type' => 'project', 'install_path' => __DIR__ . '/../../', 'aliases' => array(), 'reference' => NULL,