예제 #1
0
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
}
예제 #2
0
 function Request($security_key, $called, $calling, $callerid, $callback_time, $uniqueid)
 {
     global $A2B;
     /*
     $status = 'PENDING';
     $server_ip = 'localhost';
     $num_attempt = 0;
     $channel = 'SIP/'.$phone_number.'@mylittleIP';	
     $exten = $phone_number;
     $context = 'a2billing';
     $priority = 1;
     //$timeout	callerid
     $variable = "phonenumber=$phone_number|callerid=$callerid";
     */
     $phone_number = $called;
     $insert_id_callback = 'null';
     if (strlen($uniqueid) == 0) {
         $uniqueid = MDP_STRING(5) . '-' . MDP_NUMERIC(10);
     }
     $FG_regular[] = array("^([0-9]{4})-([0-9]{2})-([0-9]{2}) ([0-9]{2}):([0-9]{2}):([0-9]{2})\$", "(YYYY-MM-DD HH:MM:SS)");
     // The wrapper variables for security
     // $security_key = API_SECURITY_KEY;
     write_log(LOG_CALLBACK, " Service_Callback( security_key={$security_key}, called={$called}, calling={$calling}, callerid={$callerid}, uniqueid={$uniqueid}, callback_time={$callback_time})");
     $mysecurity_key = API_SECURITY_KEY;
     // CHECK CALLERID
     if (strlen($callerid) < 1) {
         write_log(LOG_CALLBACK, basename(__FILE__) . ' line:' . __LINE__ . "[" . date("Y/m/d G:i:s", mktime()) . "] " . " ERROR FORMAT CALLERID AT LEAST 1 DIGIT ");
         sleep(2);
         return array($insert_id_callback, 'result=Error', " ERROR - FORMAT CALLERID AT LEAST 1 DIGIT ");
     }
     // CHECK PHONE_NUMBER
     if (strlen($phone_number) < 10) {
         write_log(LOG_CALLBACK, basename(__FILE__) . ' line:' . __LINE__ . "[" . date("Y/m/d G:i:s", mktime()) . "] " . " ERROR FORMAT PHONENUMBER AT LEAST 10 DIGITS ");
         sleep(2);
         return array($insert_id_callback, 'result=Error', " ERROR - FORMAT PHONENUMBER AT LEAST 10 DIGITS ");
     }
     // CHECK CALLBACK TIME
     if (strlen($callback_time) > 1 && !ereg($FG_regular[0][0], $callback_time)) {
         write_log(LOG_CALLBACK, basename(__FILE__) . ' line:' . __LINE__ . "[" . date("Y/m/d G:i:s", mktime()) . "] " . " ERROR FORMAT CALLBACKTIME : " . $FG_regular[0][0]);
         sleep(2);
         return array($insert_id_callback, 'result=Error', " ERROR - FORMAT CALLBACKTIME : " . $FG_regular[0][0]);
     }
     // CHECK SECURITY KEY
     if (md5($mysecurity_key) !== $security_key || strlen($security_key) == 0) {
         write_log(LOG_CALLBACK, basename(__FILE__) . ' line:' . __LINE__ . "[" . date("Y/m/d G:i:s", mktime()) . "] " . " CODE_ERROR SECURITY_KEY");
         sleep(2);
         return array($insert_id_callback, 'result=Error', ' KEY - BAD PARAMETER ');
     }
     $DBHandle = DbConnect();
     if (!$DBHandle) {
         write_log(LOG_CALLBACK, basename(__FILE__) . ' line:' . __LINE__ . "[" . date("Y/m/d G:i:s", mktime()) . "] " . " ERROR CONNECT DB");
         sleep(2);
         return array($insert_id_callback, 'result=Error', ' ERROR - CONNECT DB ');
     }
     $A2B->DBHandle = $DBHandle;
     $instance_table = new Table();
     $A2B->set_instance_table($instance_table);
     $called = ereg_replace("^\\+", "011", $called);
     $calling = ereg_replace("^\\+", "011", $calling);
     $called = ereg_replace("[^0-9]", "", $called);
     $calling = ereg_replace("[^0-9]", "", $calling);
     $called = ereg_replace("^01100", "011", $called);
     $calling = ereg_replace("^01100", "011", $calling);
     $called = ereg_replace("^00", "011", $called);
     $calling = ereg_replace("^00", "011", $calling);
     $called = ereg_replace("^0111", "1", $called);
     $calling = ereg_replace("^0111", "1", $calling);
     $A2B->credit = 1000;
     $A2B->tariff = $A2B->config["callback"]['all_callback_tariff'];
     $RateEngine = new RateEngine();
     // $RateEngine -> webui = 0;
     // LOOKUP RATE : FIND A RATE FOR THIS DESTINATION
     $A2B->dnid = $A2B->destination = $caller_areacode . $calling;
     $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
             if ($RateEngine->ratecard_obj[0][34] != '-1') {
                 $usetrunk = 34;
                 $usetrunk_failover = 1;
                 $RateEngine->usedtrunk = $RateEngine->ratecard_obj[$k][34];
             } else {
                 $usetrunk = 29;
                 $RateEngine->usedtrunk = $RateEngine->ratecard_obj[$k][29];
                 $usetrunk_failover = 0;
             }
             $prefix = $RateEngine->ratecard_obj[0][$usetrunk + 1];
             $tech = $RateEngine->ratecard_obj[0][$usetrunk + 2];
             $ipaddress = $RateEngine->ratecard_obj[0][$usetrunk + 3];
             $removeprefix = $RateEngine->ratecard_obj[0][$usetrunk + 4];
             $timeout = $RateEngine->ratecard_obj[0]['timeout'];
             $failover_trunk = $RateEngine->ratecard_obj[0][40 + $usetrunk_failover];
             $addparameter = $RateEngine->ratecard_obj[0][42 + $usetrunk_failover];
             $destination = $A2B->destination;
             if (strncmp($destination, $removeprefix, strlen($removeprefix)) == 0) {
                 $destination = substr($destination, strlen($removeprefix));
             }
             $pos_dialingnumber = strpos($ipaddress, '%dialingnumber%');
             $ipaddress = str_replace("%cardnumber%", $A2B->cardnumber, $ipaddress);
             $ipaddress = str_replace("%dialingnumber%", $prefix . $destination, $ipaddress);
             if ($pos_dialingnumber !== false) {
                 $dialstr = "{$tech}/{$ipaddress}" . $dialparams;
             } else {
                 if ($A2B->agiconfig['switchdialcommand'] == 1) {
                     $dialstr = "{$tech}/{$prefix}{$destination}@{$ipaddress}" . $dialparams;
                 } else {
                     $dialstr = "{$tech}/{$ipaddress}/{$prefix}{$destination}" . $dialparams;
                 }
             }
             //ADDITIONAL PARAMETER 			%dialingnumber%,	%cardnumber%
             if (strlen($addparameter) > 0) {
                 $addparameter = str_replace("%cardnumber%", $A2B->cardnumber, $addparameter);
                 $addparameter = str_replace("%dialingnumber%", $prefix . $destination, $addparameter);
                 $dialstr .= $addparameter;
             }
             $channel = $dialstr;
             $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;
             $application = '';
             $status = 'PENDING';
             $server_ip = 'localhost';
             $num_attempt = 0;
             $variable = "MODE=CID|CALLED={$called}|CALLING={$calling}|CBID={$uniqueid}|TARIFF=" . $A2B->tariff;
             if (is_numeric($A2B->config["callback"]['sec_wait_before_callback']) && $A2B->config["callback"]['sec_wait_before_callback'] >= 1) {
                 $sec_wait_before_callback = $A2B->config["callback"]['sec_wait_before_callback'];
             } else {
                 $sec_wait_before_callback = 1;
             }
             // LIST FIELDS TO INSERT CALLBACK REQUEST
             $QUERY_FIELS = 'uniqueid, status, server_ip, num_attempt, channel, exten, context, priority, variable, id_server_group, callback_time, account, callerid, timeout';
             // DEFINE THE CORRECT VALUE FOR THE INSERT
             if (strlen($callback_time) > 1) {
                 $QUERY_VALUES = "'{$uniqueid}', '{$status}', '{$server_ip}', '{$num_attempt}', '{$channel}', '{$exten}', '{$context}', '{$priority}', '{$variable}', '{$id_server_group}', '{$callback_time}', '{$account}', '{$callerid}', '30000'";
             } else {
                 if ($A2B->config["database"]['dbtype'] != "postgres") {
                     // MYSQL
                     $QUERY_VALUES = "'{$uniqueid}', '{$status}', '{$server_ip}', '{$num_attempt}', '{$channel}', '{$exten}', '{$context}', '{$priority}', '{$variable}', '{$id_server_group}', ADDDATE( CURRENT_TIMESTAMP, INTERVAL {$sec_wait_before_callback} SECOND ), '{$account}', '{$callerid}', '30000'";
                 } else {
                     // POSTGRESQL
                     $QUERY_VALUES = "'{$uniqueid}', '{$status}', '{$server_ip}', '{$num_attempt}', '{$channel}', '{$exten}', '{$context}', '{$priority}', '{$variable}', '{$id_server_group}',  (CURRENT_TIMESTAMP + INTERVAL '{$sec_wait_before_callback} SECOND'), '{$account}', '{$callerid}', '30000'";
                 }
             }
             $insert_id_callback = $instance_table->Add_table($DBHandle, $QUERY_VALUES, $QUERY_FIELS, 'cc_callback_spool', 'id');
             if (!$insert_id_callback) {
                 // FAIL INSERT
                 write_log(LOG_CALLBACK, basename(__FILE__) . ' line:' . __LINE__ . "[" . date("Y/m/d G:i:s", mktime()) . "] " . " ERROR INSERT -> \n QUERY=" . $QUERY);
                 sleep(2);
                 return array($insert_id_callback, 'result=Error', ' ERROR - INSERT INTO DB');
             }
             // SUCCEED INSERT
             write_log(LOG_CALLBACK, basename(__FILE__) . ' line:' . __LINE__ . "[" . date("Y/m/d G:i:s", mktime()) . "] " . " CALLBACK INSERTED -> \n QUERY=" . $QUERY);
             return array($insert_id_callback, 'result=Success', " Success - Callback request has been accepted ");
         } else {
             $error_msg = 'Error : You don t have enough credit to call you back !!!';
         }
     } else {
         $error_msg = 'Error : There is no route to call back your phonenumber !!!';
     }
     // CALLBACK FAIL
     write_log(LOG_CALLBACK, "error_msg = {$error_msg}");
     return array($insert_id_callback, 'result=Error', " ERROR - {$error_msg}");
 }
     }
     if ($result_search_phonestatus[0][1] == 0) {
         if ($verbose_level >= 1) {
             echo "\n[  Can't send callback -> number {$phone['1']} is not in the frequency ]";
         }
         continue;
     }
 } else {
     $action = "insert";
 }
 // Search Road...
 $A2B->set_instance_table($instance_table);
 $A2B->cardnumber = $phone["username"];
 $error_msg = '';
 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'] = $phone["username"];
     $A2B->agiconfig['use_dnid'] = 1;
     $A2B->agiconfig['say_timetocall'] = 0;
     $A2B->dnid = $A2B->destination = $phone["number"];
     $resfindrate = $RateEngine->rate_engine_findrates($A2B, $phone["number"], $phone["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
             if ($RateEngine->ratecard_obj[0][34] != '-1') {
                 $usetrunk = 34;
                 $usetrunk_failover = 1;
예제 #4
0
 $num = 0;
 $result = $A2B->instance_table->SQLExec($A2B->DBHandle, "SELECT username, tariff FROM cc_card where id='{$customer_info['15']}'");
 if (!is_array($result) || count($result) == 0) {
     echo gettext("Error card !!!");
     exit;
 }
 $A2B->cardnumber = $result[0][0];
 $A2B->credit = $balance;
 if ($FG_DEBUG == 1) {
     echo "cardnumber = " . $result[0][0] . " - balance={$balance}<br>";
 }
 if ($A2B->callingcard_ivr_authenticate_light($error_msg)) {
     if ($FG_DEBUG == 1) {
         $RateEngine->debug_st = 1;
     }
     $RateEngine = new RateEngine();
     $RateEngine->webui = 1;
     $A2B->agiconfig['accountcode'] = $A2B->cardnumber;
     $A2B->agiconfig['use_dnid'] = 1;
     $A2B->agiconfig['say_timetocall'] = 0;
     $A2B->dnid = $A2B->destination = $calling;
     if ($A2B->removeinterprefix) {
         $A2B->destination = $A2B->apply_rules($A2B->destination);
     }
     $resfindrate = $RateEngine->rate_engine_findrates($A2B, $A2B->destination, $result[0][1]);
     if ($FG_DEBUG == 1) {
         echo "resfindrate={$resfindrate}";
     }
     // IF FIND RATE
     if ($resfindrate != 0) {
         $res_all_calcultimeout = $RateEngine->rate_engine_all_calcultimeout($A2B, $A2B->credit);
예제 #5
0
	$A2B ->credit = 1000;
	$A2B ->tariff = $A2B -> config["callback"]['all_callback_tariff'];

	// MAKE THE AUTHENTICATION ACCORDING TO THE CALLERID
	$A2B -> agiconfig['cid_enable']=0;
	$A2B -> agiconfig['cid_askpincode_ifnot_callerid']=0;
	$A2B -> agiconfig['say_balance_after_auth']=0;

	if (strlen($A2B->CallerID)>1 && is_numeric($A2B->CallerID)) {

		/* WE START ;) */
		$cia_res = $A2B -> callingcard_ivr_authenticate($agi,$cid_1st_leg_tariff_id); // variable $cid_1st_leg_tariff_id is using as accountcode
		$A2B -> debug( DEBUG, $agi, __FILE__, __LINE__, "[TRY : callingcard_ivr_authenticate]");
		if ($cia_res==0) {

			$RateEngine = new RateEngine();
			// $RateEngine -> webui = 0;
			// LOOKUP RATE : FIND A RATE FOR THIS DESTINATION

			$A2B -> agiconfig['use_dnid']=1;
			$A2B -> agiconfig['say_timetocall']=0;
			$A2B -> agiconfig['say_balance_after_auth']=0;
			$A2B -> extension = $A2B -> dnid = $A2B -> destination = $caller_areacode.$A2B -> apply_rules($A2B -> CallerID);
			
			$QUERY = "SELECT callback FROM cc_callerid WHERE cid=$A2B->destination AND (callback=0 OR activated='f')";
			$result = $A2B -> instance_table -> SQLExec ($A2B->DBHandle, $QUERY);

			$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);
예제 #6
0
    exit;
}
$customer_info = $resmax->fetchRow();
if ($customer_info[14] != "1" && $customer_info[14] != "8") {
    Header("HTTP/1.0 401 Unauthorized");
    Header("Location: PP_error.php?c=accessdenied");
    die;
}
if ($callback) {
    if (strlen($called) > 1 && strlen($calling) > 1 && is_numeric($called) && is_numeric($calling)) {
        $A2B->DBHandle = DbConnect();
        $instance_table = new Table();
        $A2B->set_instance_table($instance_table);
        $A2B->cardnumber = $_SESSION["pr_login"];
        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'] = $_SESSION["pr_login"];
            $A2B->agiconfig['use_dnid'] = 1;
            $A2B->agiconfig['say_timetocall'] = 0;
            $A2B->extension = $A2B->dnid = $A2B->destination = $called;
            $resfindrate = $RateEngine->rate_engine_findrates($A2B, $called, $_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
                    if ($RateEngine->ratecard_obj[0][34] != '-1') {
                        $usetrunk = 34;
                        $usetrunk_failover = 1;
예제 #7
0
    }
} elseif ($mode == 'all-callback') {
    $A2B->debug(DEBUG, $agi, __FILE__, __LINE__, '[MODE : ALL-CALLBACK - ' . $A2B->CallerID . ']');
    // END
    if ($A2B->agiconfig['answer_call'] == 1) {
        $A2B->debug(DEBUG, $agi, __FILE__, __LINE__, '[HANGUP ALL CALLBACK TRIGGER]');
        $agi->hangup();
    } else {
        $A2B->debug(DEBUG, $agi, __FILE__, __LINE__, '[ALL CALLBACK TRIGGER RINGING]');
    }
    $A2B->credit = 1000;
    $A2B->tariff = $A2B->config["callback"]['all_callback_tariff'];
    if (strlen($A2B->CallerID) > 1 && is_numeric($A2B->CallerID)) {
        /* WE START ;) */
        if ($cia_res == 0) {
            $RateEngine = new RateEngine();
            // $RateEngine->webui = 0;
            // LOOKUP RATE : FIND A RATE FOR THIS DESTINATION
            $A2B->agiconfig['use_dnid'] = 1;
            $A2B->agiconfig['say_timetocall'] = 0;
            $A2B->agiconfig['say_balance_after_auth'] = 0;
            $A2B->extension = $A2B->dnid = $A2B->destination = $caller_areacode . $A2B->CallerID;
            $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
                    if ($RateEngine->ratecard_obj[0][34] != '-1') {
                        $usetrunk = 34;
예제 #8
0
 public function Request($security_key, $called, $calling, $callerid, $callback_time, $uniqueid, $accountnumber)
 {
     // $called : PHONE NUMBER PERSON CALLING
     // $calling : DESTINATION PHONE NUMBER
     global $A2B;
     /*
     $status = 'PENDING';
     $server_ip = 'localhost';
     $num_attempt = 0;
     $channel = 'SIP/'.$phone_number.'@mylittleIP';
     $exten = $phone_number;
     $context = 'a2billing';
     $priority = 1;
     //$timeout	callerid
     $variable = "phonenumber=$phone_number|callerid=$callerid";
     */
     $phone_number = $called;
     $insert_id_callback = 'null';
     if (strlen($uniqueid) == 0) {
         $uniqueid = MDP_STRING(5) . '-' . MDP_NUMERIC(5) . MDP_STRING(10) . MDP_NUMERIC(5);
     }
     $FG_regular[] = array("^([0-9]{4})-([0-9]{2})-([0-9]{2}) ([0-9]{2}):([0-9]{2}):([0-9]{2})\$", "(YYYY-MM-DD HH:MM:SS)");
     // The wrapper variables for security
     // $security_key = API_SECURITY_KEY;
     write_log(LOG_CALLBACK, " Service_Callback( security_key={$security_key}, called={$called}, calling={$calling}, callerid={$callerid}, uniqueid={$uniqueid}, callback_time={$callback_time})");
     $mysecurity_key = API_SECURITY_KEY;
     // CHECK CALLERID
     if (strlen($callerid) < 1) {
         write_log(LOG_CALLBACK, basename(__FILE__) . ' line:' . __LINE__ . "[" . date("Y/m/d G:i:s", mktime()) . "] " . " ERROR FORMAT CALLERID AT LEAST 1 DIGIT ");
         return array($insert_id_callback, 'result=Error', " ERROR - FORMAT CALLERID AT LEAST 1 DIGIT ");
     }
     // CHECK PHONE_NUMBER
     if (strlen($phone_number) < 10) {
         write_log(LOG_CALLBACK, basename(__FILE__) . ' line:' . __LINE__ . "[" . date("Y/m/d G:i:s", mktime()) . "] " . " ERROR FORMAT PHONENUMBER AT LEAST 10 DIGITS ");
         return array($insert_id_callback, 'result=Error', " ERROR - FORMAT PHONENUMBER AT LEAST 10 DIGITS ");
     }
     // CHECK DESTINATION NUMBER
     if (strlen($calling) < 2) {
         write_log(LOG_CALLBACK, basename(__FILE__) . ' line:' . __LINE__ . "[" . date("Y/m/d G:i:s", mktime()) . "] " . " ERROR FORMAT DESTINATION NUMBER AT LEAST 2 DIGITS ");
         return array($insert_id_callback, 'result=Error', " ERROR - FORMAT DESTINATION NUMBER AT LEAST 2 DIGITS ");
     }
     // CHECK CALLBACK TIME
     if (strlen($callback_time) > 1 && !preg_match("/" . $FG_regular[0][0] . "/", $callback_time)) {
         write_log(LOG_CALLBACK, basename(__FILE__) . ' line:' . __LINE__ . "[" . date("Y/m/d G:i:s", mktime()) . "] " . " ERROR FORMAT CALLBACKTIME : " . $FG_regular[0][0]);
         return array($insert_id_callback, 'result=Error', " ERROR - FORMAT CALLBACKTIME : " . $FG_regular[0][0]);
     }
     // CHECK SECURITY KEY
     if (md5($mysecurity_key) !== $security_key || strlen($security_key) == 0) {
         write_log(LOG_CALLBACK, basename(__FILE__) . ' line:' . __LINE__ . "[" . date("Y/m/d G:i:s", mktime()) . "] " . " CODE_ERROR SECURITY_KEY");
         sleep(2);
         return array($insert_id_callback, 'result=Error', ' KEY - BAD PARAMETER ');
     }
     $DBHandle = DbConnect();
     if (!$DBHandle) {
         write_log(LOG_CALLBACK, basename(__FILE__) . ' line:' . __LINE__ . "[" . date("Y/m/d G:i:s", mktime()) . "] " . " ERROR CONNECT DB");
         sleep(2);
         return array($insert_id_callback, 'result=Error', ' ERROR - CONNECT DB ');
     }
     $A2B->DBHandle = $DBHandle;
     $instance_table = new Table();
     $A2B->set_instance_table($instance_table);
     $A2B->credit = 1000;
     $A2B->tariff = $A2B->config["callback"]['all_callback_tariff'];
     if (strlen($accountnumber) > 1) {
         // IF WE HAVE AN ACCOUNT NUMBER DEFINED
         $QUERY = "SELECT tariff, typepaid, credit, creditlimit FROM cc_card WHERE username='******'";
         $card_data = $instance_table->SQLExec($DBHandle, $QUERY);
         if (is_array($card_data)) {
             $A2B->credit = $card_data[0]['credit'];
             if ($card_data[0]['typepaid'] == 1) {
                 $A2B->credit = $A2B->credit + $card_data[0]['creditlimit'];
             }
             $A2B->tariff = $card_data[0]['tariff'];
         }
         //Else find accountnumber from caller's CallerID
     } else {
         $QUERY .= "SELECT cc_card.tariff, cc_card.typepaid, cc_card.credit, cc_card.creditlimit, cc_card.username" . " FROM cc_card " . " JOIN cc_callerid" . " ON cc_card.id=cc_callerid.id_cc_card " . " WHERE cc_callerid.cid='" . $phone_number . "'";
         $QUERY .= "ORDER BY 1";
         $card_data = $instance_table->SQLExec($DBHandle, $QUERY);
         if (!is_array($card_data)) {
             return array($insert_id_callback, 'result=Error', "CALLING'S PARTY CALLERID DOES NOT EXIST IN DATABASE");
         }
         $accountnumber = $card_data[0]['username'];
         if (is_array($card_data)) {
             $A2B->credit = $card_data[0]['credit'];
             if ($card_data[0]['typepaid'] == 1) {
                 $A2B->credit = $A2B->credit + $card_data[0]['creditlimit'];
             }
             $A2B->tariff = $card_data[0]['tariff'];
         }
     }
     $RateEngine = new RateEngine();
     $A2B->extension = $A2B->dnid = $A2B->destination = $called;
     // LOOKUP RATE : FIND A RATE FOR THIS DESTINATION
     $resfindrate = $RateEngine->rate_engine_findrates($A2B, $A2B->destination, $A2B->tariff);
     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
             if ($RateEngine->ratecard_obj[0][34] != '-1') {
                 $usetrunk = 34;
                 $usetrunk_failover = 1;
                 $RateEngine->usedtrunk = $RateEngine->ratecard_obj[0][34];
             } else {
                 $usetrunk = 29;
                 $RateEngine->usedtrunk = $RateEngine->ratecard_obj[0][29];
                 $usetrunk_failover = 0;
             }
             $prefix = $RateEngine->ratecard_obj[0][$usetrunk + 1];
             $tech = $RateEngine->ratecard_obj[0][$usetrunk + 2];
             $ipaddress = $RateEngine->ratecard_obj[0][$usetrunk + 3];
             $removeprefix = $RateEngine->ratecard_obj[0][$usetrunk + 4];
             $timeout = $RateEngine->ratecard_obj[0]['timeout'];
             $failover_trunk = $RateEngine->ratecard_obj[0][40 + $usetrunk_failover];
             $addparameter = $RateEngine->ratecard_obj[0][42 + $usetrunk_failover];
             $destination = $A2B->destination;
             if (strncmp($destination, $removeprefix, strlen($removeprefix)) == 0) {
                 $destination = substr($destination, strlen($removeprefix));
             }
             $pos_dialingnumber = strpos($ipaddress, '%dialingnumber%');
             $ipaddress = str_replace("%cardnumber%", $A2B->cardnumber, $ipaddress);
             $ipaddress = str_replace("%dialingnumber%", $prefix . $destination, $ipaddress);
             $dialparams = '';
             if ($pos_dialingnumber !== false) {
                 $dialstr = "{$tech}/{$ipaddress}" . $dialparams;
             } else {
                 if ($A2B->agiconfig['switchdialcommand'] == 1) {
                     $dialstr = "{$tech}/{$prefix}{$destination}@{$ipaddress}" . $dialparams;
                 } else {
                     $dialstr = "{$tech}/{$ipaddress}/{$prefix}{$destination}" . $dialparams;
                 }
             }
             //ADDITIONAL PARAMETER 			%dialingnumber%,	%cardnumber%
             if (strlen($addparameter) > 0) {
                 $addparameter = str_replace("%cardnumber%", $A2B->cardnumber, $addparameter);
                 $addparameter = str_replace("%dialingnumber%", $prefix . $destination, $addparameter);
                 $dialstr .= $addparameter;
             }
             $channel = $dialstr;
             $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;
             $application = '';
             $status = 'PENDING';
             $server_ip = 'localhost';
             $num_attempt = 0;
             $sep = $A2B->config['global']['asterisk_version'] == "1_2" || $A2B->config['global']['asterisk_version'] == "1_4" ? '|' : ',';
             $variable = "CALLED={$called}" . $sep . "CALLING={$calling}" . $sep . "CBID={$uniqueid}" . $sep . "TARIFF=" . $A2B->tariff;
             if (is_numeric($A2B->config["callback"]['sec_wait_before_callback']) && $A2B->config["callback"]['sec_wait_before_callback'] >= 1) {
                 $sec_wait_before_callback = $A2B->config["callback"]['sec_wait_before_callback'];
             } else {
                 $sec_wait_before_callback = 1;
             }
             // LIST FIELDS TO INSERT CALLBACK REQUEST
             $QUERY_FIELS = 'uniqueid, status, server_ip, num_attempt, channel, exten, context, priority, variable, id_server_group, callback_time, account, callerid, timeout';
             // DEFINE THE CORRECT VALUE FOR THE INSERT
             if (strlen($callback_time) > 1) {
                 $QUERY_VALUES = "'{$uniqueid}', '{$status}', '{$server_ip}', '{$num_attempt}', '{$channel}', '{$exten}', '{$context}', '{$priority}', '{$variable}', '{$id_server_group}', '{$callback_time}', '{$accountnumber}', '{$callerid}', '30000'";
             } else {
                 $QUERY_VALUES = "'{$uniqueid}', '{$status}', '{$server_ip}', '{$num_attempt}', '{$channel}', '{$exten}', '{$context}', '{$priority}', '{$variable}', '{$id_server_group}', ADDDATE( CURRENT_TIMESTAMP, INTERVAL {$sec_wait_before_callback} SECOND ), '{$accountnumber}', '{$callerid}', '30000'";
             }
             $insert_id_callback = $instance_table->Add_table($DBHandle, $QUERY_VALUES, $QUERY_FIELS, 'cc_callback_spool', 'id');
             if (!$insert_id_callback) {
                 // FAIL INSERT
                 write_log(LOG_CALLBACK, basename(__FILE__) . ' line:' . __LINE__ . "[" . date("Y/m/d G:i:s", mktime()) . "] " . " ERROR INSERT -> \n QUERY= {$QUERY_FIELS} :: {$QUERY_VALUES}");
                 sleep(2);
                 return array($insert_id_callback, 'result=Error', ' ERROR - INSERT INTO DB');
             }
             // SUCCEED INSERT
             write_log(LOG_CALLBACK, basename(__FILE__) . ' line:' . __LINE__ . "[" . date("Y/m/d G:i:s", mktime()) . "] " . " CALLBACK INSERTED -> \n QUERY= {$QUERY_FIELS} :: {$QUERY_VALUES}");
             return array($insert_id_callback, 'result=Success', " Success - Callback request has been accepted ");
         } else {
             $error_msg = 'Error : You don t have enough credit to call you back !!!';
         }
     } else {
         $error_msg = 'Error : There is no route to call back your phonenumber !!!';
     }
     // CALLBACK FAIL
     write_log(LOG_CALLBACK, "error_msg = {$error_msg}");
     return array($insert_id_callback, 'result=Error', " ERROR - {$error_msg}");
 }
예제 #9
0
	Header("Location: PP_error.php?c=accessdenied");
	die();
}

if ($callback) {
	
	if (strlen($called)>1 && strlen($calling)>1 && is_numeric($called) && is_numeric($calling)) {
		
		$A2B -> DBHandle = DbConnect();
		$instance_table = new Table();
		$A2B -> set_instance_table ($instance_table);
		$A2B -> cardnumber = $_SESSION["pr_login"];
			
		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']=$_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) {