All pastes #911645 Raw Edit

Something

public text v1 · immutable
·published 2008-02-20 20:58 UTC
rendered paste body
#!/usr/bin/php -q
<?php
require('phpagi.php');
$result = '';
function connect_db() { 
$db_connection = mysql_connect ('localhost', '', '') or die (mysql_error()); 
$db_select = mysql_select_db('billing') or die (mysql_error()); 
} 
$agi = new AGI();
$agi->answer();
$cid = $agi->parse_callerid();
 $incoming_number = $cid['username'];

connect_db(); 

$query1 = "SELECT id,pinnum,credit FROM cardcustomer WHERE phone = '$incoming_number' "; 
$query_result1 = @mysql_query($query1);  
$row_count = mysql_num_rows($query_result1); 
$row1 = @mysql_fetch_array ($query_result1); 
	If ($row_count !=0 ) {  // caller is authenticated based on ANI  
	$pin = $row1[pin_no];
$credit = $row1['credit'];

		//* Get the destination they would like to dial
			$result = $agi->get_data('prepaid-enter-dest', 3000, 20); 
			$keys = $result['result'];
		//* End of get destination

			$code = substr("$keys", 0, 4);


		//* check codes and verifiy they are in the database

				$check = "select clientrate,clientfirst,clientsecond from rates where codes like '$code'";
				$rest = @mysql_query($check);
				$row2 = @mysql_fetch_array ($rest);
				$clientrate = $row2['clientrate'];
				$agi->set_variable("clientrate",$row2['clientrate']);
				$agi->set_variable("clientfirst",$row2['clientfirst']);
				$agi->set_variable("clientsecond",$row2['clientsecond']);
				$agi->set_variable("credit","$credit");
				$seconds3 = bcdiv($credit, $clientrate, 5 );
                                $seconds2 = bcmul($seconds3, 60);	
		//* end of code check 
		
	$agi->set_variable("TIMEOUT(absolute)", "$seconds2");
	$agi->set_variable("CALLERID","$incoming_number");

	$agi->exec_dial("SIP","$keys@did.voip.les.net|300|Ttr"); 
	$answeredtime = $agi->get_variable("ANSWEREDTIME");
}else{

		$result = $agi->get_data('prepaid-enter-pin-number', 3000, 30);
		$pinnum = $result['result'];

		echo $enterpin;
			$query = "select credit from cardcustomer where pinnum='$pinnum'";
			$query_result = @mysql_query($query);
			$row_count1 = mysql_num_rows($query_result);
			
        If ($row_count1 !=0 ) { 
	
	$result = $agi->get_data('prepaid-enter-dest', 3000, 20);
                        $keys = $result['result'];
                //* End of get destination

                        $code = substr("$keys", 0, 4);

		$check = "select clientrate from rates where codes like '$code'";
		$rest = @mysql_query($check);
		$row2 = @mysql_fetch_array ($rest);
		$clientrate = $row2['clientrate'];
		$seconds = bcdiv($credit, $clientrate, 5 );
//*			echo $credit;
//*			echo $clientrate;
//*        
	$agi->exec_set("TIMEOUT(absolute)='60'");
        $agi->exec_dial("SIP","$keys@did.voip.les.net|300|Ttr"); 
}}
 ?>