function callback_engine(&$A2B, $server, $username, $secret, $AmiVars, $destination, $tariff) { $A2B -> cardnumber = $AmiVars[4]; if ($A2B -> callingcard_ivr_authenticate_light ($error_msg)) { $RateEngine = new RateEngine(); $RateEngine -> webui = 0; // LOOKUP RATE : FIND A RATE FOR THIS DESTINATION $A2B -> agiconfig['accountcode'] = $A2B -> cardnumber; $A2B -> agiconfig['use_dnid'] = 1; $A2B -> agiconfig['say_timetocall'] = 0; $A2B -> extension = $A2B -> dnid = $A2B -> destination = $destination; $resfindrate = $RateEngine->rate_engine_findrates($A2B, $destination, $tariff); // IF FIND RATE if ($resfindrate!=0) { $res_all_calcultimeout = $RateEngine->rate_engine_all_calcultimeout($A2B, $A2B->credit); if ($res_all_calcultimeout) { $ast = new AGI_AsteriskManager(); $res = $ast -> connect($server, $username, $secret); if (!$res) return -4; // MAKE THE CALL $res = $RateEngine->rate_engine_performcall(false, $destination, $A2B, 8, $AmiVars, $ast); $ast -> disconnect(); if ($res !== false) return $res; else return -2; // not enough free trunk for make call } else return -3; // not have enough credit to call you back } else return -1; // no route to call back your phonenumber } else return -1; // ERROR MESSAGE IS CONFIGURE BY THE callingcard_ivr_authenticate_light }
$instance_table = new Table("cc_callback_spool"); $FG_TABLE_CLAUSE = "callerid='{$A2B->config['callback']['callerid']}' and exten_leg_a='{$A2B->destination}' and timediff(now(),entry_time)<{$A2B->config['callback']['sec_avoid_repeate']}"; $FG_NB_RECORD = $instance_table -> Table_count ($A2B -> DBHandle, $FG_TABLE_CLAUSE); if (!is_array($result) && $FG_NB_RECORD == 0) { $resfindrate = $RateEngine->rate_engine_findrates($A2B, $A2B -> destination, $A2B -> tariff); // IF FIND RATE if ($resfindrate!=0) { //$RateEngine -> debug_st = 1; $res_all_calcultimeout = $RateEngine->rate_engine_all_calcultimeout($A2B, $A2B->credit); if ($res_all_calcultimeout){ // MAKE THE CALL $channeloutcid = $RateEngine->rate_engine_performcall($agi, $A2B->destination, $A2B, 9); if ($channeloutcid) { $channel = $channeloutcid[0]; $sep = ($A2B->config['global']['asterisk_version'] == "1_2" || $A2B->config['global']['asterisk_version'] == "1_4")?'|':','; if (isset($A2B -> cidphonenumber) && $A2B -> cidphonenumber) { $exten = $A2B -> cidphonenumber; $variable = ''; } else { $exten = $A2B -> config["callback"]['extension']; $variable = "IDCONF=$idconfig".$sep; } if ($argc > 4 && strlen($argv[4]) > 0) $exten = $argv[4]; $context = $A2B -> config["callback"]['context_callback']; $id_server_group = $A2B -> config["callback"]['id_server_group']; $priority = 1; $timeout = $A2B -> config["callback"]['timeout']*1000;
// LOOKUP RATE : FIND A RATE FOR THIS DESTINATION $A2B -> agiconfig['accountcode']=$_SESSION["pr_login"]; $A2B -> agiconfig['use_dnid']=1; $A2B -> agiconfig['say_timetocall']=0; $A2B -> extension = $A2B -> dnid = $A2B -> destination = $A2B -> apply_rules($called); $resfindrate = $RateEngine->rate_engine_findrates($A2B, $A2B -> dnid, $_SESSION["tariff"]); // IF FIND RATE if ($resfindrate!=0) { $res_all_calcultimeout = $RateEngine->rate_engine_all_calcultimeout($A2B, $A2B->credit); if ($res_all_calcultimeout) { // MAKE THE CALL $channeloutcid = $RateEngine->rate_engine_performcall(false, $A2B -> dnid, $A2B); if ($channeloutcid) { $channel = $channeloutcid[0]; $exten = $calling; $context = $A2B -> config["callback"]['context_callback']; $id_server_group = $A2B -> config["callback"]['id_server_group']; $priority=1; $timeout = $A2B -> config["callback"]['timeout']*1000; $timeoutbefore = $A2B -> config["callback"]['sec_wait_before_callback']; $application=''; if ($channeloutcid[1]) $callerid = $channeloutcid[1]; else $callerid = $A2B -> config["callback"]['callerid']; $account = $_SESSION["pr_login"]; $uniqueid = MDP_NUMERIC(5).'-'.MDP_STRING(7); $status = 'PENDING';