[Astpp-commit] SF.net SVN: astpp:[2246] trunk/freeswitch/astpp-callingcards.pl
Brought to you by:
darrenkw
From: <dar...@us...> - 2009-04-18 17:25:18
|
Revision: 2246 http://astpp.svn.sourceforge.net/astpp/?rev=2246&view=rev Author: darrenkw Date: 2009-04-18 17:25:14 +0000 (Sat, 18 Apr 2009) Log Message: ----------- This is the correct version of the callingcards file. Modified Paths: -------------- trunk/freeswitch/astpp-callingcards.pl Modified: trunk/freeswitch/astpp-callingcards.pl =================================================================== --- trunk/freeswitch/astpp-callingcards.pl 2009-04-18 17:11:43 UTC (rev 2245) +++ trunk/freeswitch/astpp-callingcards.pl 2009-04-18 17:25:14 UTC (rev 2246) @@ -20,679 +20,658 @@ use vars qw(@output $verbosity $config $astpp_db $cdr_db $ASTPP %stats %input $cc $pricelistinfo $brandinfo $sound @resellerlist $brand); $stats{start_time} = [gettimeofday]; -$cc = 0; -$verbosity = 1; +$cc = 0; +$verbosity = 1; require "/usr/local/astpp/astpp-common.pl"; $ASTPP = ASTPP->new; -$ASTPP->set_verbosity($verbosity); #Tell ASTPP debugging how verbose we want to be. +$ASTPP->set_verbosity($verbosity) + ; #Tell ASTPP debugging how verbose we want to be. sub initialize() { - $SIG{HUP} = 'ignore_hup'; # We ignore the HUP command that Asterisk sends on a call hangup. - $config = &load_config(); # Load /var/lib/astpp/astpp-config.conf - $astpp_db = &connect_db( $config, @output ); - $ASTPP->set_astpp_db($astpp_db); - $config = &load_config_db($astpp_db,$config); - $brand = "brand"; #$AGI->get_variable("BRAND"); - if ($brand && $brand ne "") { - my $brandinfo = &get_cc_brand($astpp_db, $brand); - if ($brandinfo->{reseller}) { - $config = &load_config_db_reseller($astpp_db,$config,$brandinfo->{reseller}); - } - $config = &load_config_db_brand($astpp_db,$config,$brand); + $SIG{HUP} = 'ignore_hup' + ; # We ignore the HUP command that Asterisk sends on a call hangup. + $config = &load_config(); # Load /var/lib/astpp/astpp-config.conf + $astpp_db = &connect_db( $config, @output ); + $ASTPP->set_astpp_db($astpp_db); + $config = &load_config_db( $astpp_db, $config ); + $brand = "brand"; #$AGI->get_variable("BRAND"); + if ( $brand && $brand ne "" ) { + my $brandinfo = &get_cc_brand( $astpp_db, $brand ); + if ( $brandinfo->{reseller} ) { + $config = + &load_config_db_reseller( $astpp_db, $config, + $brandinfo->{reseller} ); } - $cdr_db = &cdr_connect_db( $config, @output ); - $ASTPP->set_cdr_db($cdr_db); - $sound = &define_sounds($astpp_db); + $config = &load_config_db_brand( $astpp_db, $config, $brand ); + } + $cdr_db = &cdr_connect_db( $config, @output ); + $ASTPP->set_cdr_db($cdr_db); + $sound = &define_sounds($astpp_db); } -sub set_in_use() { # Set the "inuse" flag on the calling cards. This prevents multiple people from -# using the same card. - my ( $cardinfo, $status ) = @_; - my $sql; - $sql = - "UPDATE callingcards SET inuse = " - . $astpp_db->quote($status) - . " WHERE cardnumber = " - . $astpp_db->quote( $cardinfo->{cardnumber} ); - $astpp_db->do($sql); +sub set_in_use() +{ # Set the "inuse" flag on the calling cards. This prevents multiple people from + + # using the same card. + my ( $cardinfo, $status ) = @_; + my $sql; + $sql = + "UPDATE callingcards SET inuse = " + . $astpp_db->quote($status) + . " WHERE cardnumber = " + . $astpp_db->quote( $cardinfo->{cardnumber} ); + $astpp_db->do($sql); } -sub check_card() { # Check a few things before saying the card is ok. - my ($cardinfo) = @_; - my $now = $astpp_db->selectall_arrayref("SELECT NOW() + 0")->[0][0]; - $ASTPP->debug( debug => "Present Time: $now", - verbosity => $verbosity ); - $ASTPP->debug( debug => "Expiration Date: $cardinfo->{expiry}", - verbosity => $verbosity ); - $ASTPP->debug( debug => "Valid for Days: $cardinfo->{validfordays}", - verbosity => $verbosity ); - $ASTPP->debug( debug => "First Use: $cardinfo->{firstused}", - verbosity => $verbosity ); - if ( $cardinfo->{inuse} != 0 ) { # If the card is in use then say so and leave. - $session->streamFile($sound->{card_inuse}); - $session->streamFile($sound->{goodbye}); - &leave($cardinfo); +sub check_card() { # Check a few things before saying the card is ok. + my ($cardinfo) = @_; + my $now = $astpp_db->selectall_arrayref("SELECT NOW() + 0")->[0][0]; + $ASTPP->debug( + debug => "Present Time: $now", + verbosity => $verbosity + ); + $ASTPP->debug( + debug => "Expiration Date: $cardinfo->{expiry}", + verbosity => $verbosity + ); + $ASTPP->debug( + debug => "Valid for Days: $cardinfo->{validfordays}", + verbosity => $verbosity + ); + $ASTPP->debug( + debug => "First Use: $cardinfo->{firstused}", + verbosity => $verbosity + ); + if ( $cardinfo->{inuse} != 0 ) + { # If the card is in use then say so and leave. + $session->streamFile( $sound->{card_inuse} ); + $session->streamFile( $sound->{goodbye} ); + &leave($cardinfo); + } + &set_in_use( $cardinfo, 1 ) + ; # Now the card is in use and nobody else can use it. + if ( $cardinfo->{firstused} eq "00000000000000" + || $cardinfo->{firstused} eq "0000-00-00 00:00:00" ) + { # If "firstused" has not been set, we will set it now. + # At the same time we will update the "maint_day" field. + my $sql = + "UPDATE callingcards SET firstused = NOW() WHERE cardnumber = " + . $astpp_db->quote( $cardinfo->{cardnumber} ); + $ASTPP->debug( + debug => $sql, + verbosity => $verbosity + ); + $astpp_db->do($sql); + $sql = + "UPDATE callingcards SET maint_day = DATE_ADD(NOW(), INTERVAL " + . "$cardinfo->{maint_fee_days} day) WHERE cardnumber = " + . $astpp_db->quote( $cardinfo->{cardnumber} ); + $ASTPP->debug( + debug => $sql, + verbosity => $verbosity + ); + if ( $cardinfo->{maint_fee_days} > 0 ) { + $astpp_db->do($sql); } - &set_in_use( $cardinfo, 1 ); # Now the card is in use and nobody else can use it. - if ( $cardinfo->{firstused} eq "00000000000000" || $cardinfo->{firstused} eq "0000-00-00 00:00:00" ) { # If "firstused" has not been set, we will set it now. - # At the same time we will update the "maint_day" field. - my $sql = - "UPDATE callingcards SET firstused = NOW() WHERE cardnumber = " - . $astpp_db->quote( $cardinfo->{cardnumber} ); - $ASTPP->debug( debug => $sql, - verbosity => $verbosity ); - $astpp_db->do($sql); - $sql = - "UPDATE callingcards SET maint_day = DATE_ADD(NOW(), INTERVAL " - . "$cardinfo->{maint_fee_days} day) WHERE cardnumber = " - . $astpp_db->quote( $cardinfo->{cardnumber} ); - $ASTPP->debug( debug => $sql, - verbosity => $verbosity ); - if ( $cardinfo->{maint_fee_days} > 0 ) { - $astpp_db->do($sql); - } + # $cardinfo = &get_callingcard( $astpp_db, $cardinfo->{cardnumber} ); - if ( $cardinfo->{validfordays} > 0 ) { #Check if the card is set to expire and deal with that as appropriate. - my $sql = -"UPDATE callingcards SET expiry = DATE_ADD(NOW(), INTERVAL " - . " $cardinfo->{validfordays} day) WHERE cardnumber = " - . $astpp_db->quote( $cardinfo->{cardnumber} ); - $ASTPP->debug( debug => $sql, - verbosity => $verbosity ); - $astpp_db->do($sql); - $cardinfo = &get_callingcard( $astpp_db, $cardinfo->{cardnumber}, $config ); - } + if ( $cardinfo->{validfordays} > 0 ) + { #Check if the card is set to expire and deal with that as appropriate. + my $sql = + "UPDATE callingcards SET expiry = DATE_ADD(NOW(), INTERVAL " + . " $cardinfo->{validfordays} day) WHERE cardnumber = " + . $astpp_db->quote( $cardinfo->{cardnumber} ); + $ASTPP->debug( + debug => $sql, + verbosity => $verbosity + ); + $astpp_db->do($sql); + $cardinfo = + &get_callingcard( $astpp_db, $cardinfo->{cardnumber}, $config ); } - elsif ( $cardinfo->{validfordays} > 0 ) { - my $now = $astpp_db->selectall_arrayref("SELECT NOW() + 0")->[0][0]; - $cardinfo->{expiry} = $astpp_db->selectall_arrayref("SELECT DATE_FORMAT('$cardinfo->{expiry}' , '\%Y\%m\%d\%H\%i\%s')")->[0][0]; - if ( $now >= $cardinfo->{expiry} ) { - my $sql = - "UPDATE callingcards SET status = 2 WHERE cardnumber = " - . $astpp_db->quote( $cardinfo->{cardnumber} ); - $ASTPP->debug( debug => $sql, - verbosity => $verbosity ); - $astpp_db->do($sql); - $sql = - "DELETE FROM ani_map WHERE account = " - . $astpp_db->quote( $cardinfo->{cardnumber} ); - $ASTPP->debug( debug => $sql, - verbosity => $verbosity ); - $astpp_db->do($sql); - $session->streamFile($sound->{card_has_expired}); - $session->streamFile($sound->{goodbye}); - &leave($cardinfo); - } + } + elsif ( $cardinfo->{validfordays} > 0 ) { + my $now = $astpp_db->selectall_arrayref("SELECT NOW() + 0")->[0][0]; + $cardinfo->{expiry} = $astpp_db->selectall_arrayref( + "SELECT DATE_FORMAT('$cardinfo->{expiry}' , '\%Y\%m\%d\%H\%i\%s')") + ->[0][0]; + if ( $now >= $cardinfo->{expiry} ) { + my $sql = "UPDATE callingcards SET status = 2 WHERE cardnumber = " + . $astpp_db->quote( $cardinfo->{cardnumber} ); + $ASTPP->debug( + debug => $sql, + verbosity => $verbosity + ); + $astpp_db->do($sql); + $sql = "DELETE FROM ani_map WHERE account = " + . $astpp_db->quote( $cardinfo->{cardnumber} ); + $ASTPP->debug( + debug => $sql, + verbosity => $verbosity + ); + $astpp_db->do($sql); + $session->streamFile( $sound->{card_has_expired} ); + $session->streamFile( $sound->{goodbye} ); + &leave($cardinfo); } - $ASTPP->debug( debug => "Present Time: $now", - verbosity => $verbosity ); - $ASTPP->debug( debug => "Expiration Date: $cardinfo->{expiry}", - verbosity => $verbosity ); - $ASTPP->debug( debug => "Valid for Days: $cardinfo->{validfordays}", - verbosity => $verbosity ); - $ASTPP->debug( debug => "First Use: $cardinfo->{firstused}", - verbosity => $verbosity ); + } + $ASTPP->debug( + debug => "Present Time: $now", + verbosity => $verbosity + ); + $ASTPP->debug( + debug => "Expiration Date: $cardinfo->{expiry}", + verbosity => $verbosity + ); + $ASTPP->debug( + debug => "Valid for Days: $cardinfo->{validfordays}", + verbosity => $verbosity + ); + $ASTPP->debug( + debug => "First Use: $cardinfo->{firstused}", + verbosity => $verbosity + ); } -sub tell_cost() { #Say how much the call will cost. - my ( $numberinfo, $pricelistinfo, $cardinfo ) = @_; - if ( $pricelistinfo->{markup} ne "" && $pricelistinfo->{markup} != 0 ) { - $ASTPP->debug( debug => "Adding Markup of $pricelistinfo->{markup}", - verbosity => $verbosity); - $numberinfo->{connectcost} = - $numberinfo->{connectcost} * - ( ( $pricelistinfo->{markup} / 10000 ) + 1 ); - $numberinfo->{cost} = - $numberinfo->{cost} * ( ( $pricelistinfo->{markup} / 10000 ) + 1 ); - } - if ($config->{calling_cards_rate_announce} == 1) { +sub tell_cost() { #Say how much the call will cost. + my ( $numberinfo, $pricelistinfo, $cardinfo ) = @_; + if ( $pricelistinfo->{markup} ne "" && $pricelistinfo->{markup} != 0 ) { + $ASTPP->debug( + debug => "Adding Markup of $pricelistinfo->{markup}", + verbosity => $verbosity + ); + $numberinfo->{connectcost} = + $numberinfo->{connectcost} * + ( ( $pricelistinfo->{markup} / 10000 ) + 1 ); + $numberinfo->{cost} = + $numberinfo->{cost} * ( ( $pricelistinfo->{markup} / 10000 ) + 1 ); + } + if ( $config->{calling_cards_rate_announce} == 1 ) { if ( $numberinfo->{cost} > 0 ) { - $session->streamFile($sound->{call_will_cost}); - $session->execute("phrase","spell," . ceil($numberinfo->{cost}/100)); - $session->streamFile($sound->{currency}); - my @call_cost = split(/\./, ($numberinfo->{cost} / 100)); - $session->execute("phrase","spell," . @call_cost[0]); - if (@call_cost[1]) { - $session->streamFile($sound->{point}); - $session->execute("phrase","spell," . @call_cost[1]); - $session->streamFile($sound->{sub_currency}); - } - $session->streamFile($sound->{per}); - $session->streamFile($sound->{minute}); + $session->streamFile( $sound->{call_will_cost} ); + $session->execute( "phrase", + "spell," . ceil( $numberinfo->{cost} / 100 ) ); + $session->streamFile( $sound->{currency} ); + my @call_cost = split( /\./, ( $numberinfo->{cost} / 100 ) ); + $session->execute( "phrase", "spell," . @call_cost[0] ); + if ( @call_cost[1] ) { + $session->streamFile( $sound->{point} ); + $session->execute( "phrase", "spell," . @call_cost[1] ); + $session->streamFile( $sound->{sub_currency} ); + } + $session->streamFile( $sound->{per} ); + $session->streamFile( $sound->{minute} ); } if ( $numberinfo->{connectcost} > 0 ) { - $session->streamFile($sound->{a_connect_charge}); - $session->execute("phrase","spell," . ceil($numberinfo->{connectcost}/100)); - $session->streamFile($sound->{sub_currency}); - $session->streamFile($sound->{will_apply}); + $session->streamFile( $sound->{a_connect_charge} ); + $session->execute( "phrase", + "spell," . ceil( $numberinfo->{connectcost} / 100 ) ); + $session->streamFile( $sound->{sub_currency} ); + $session->streamFile( $sound->{will_apply} ); } - } + } } -sub timelimit() { #Calculate and say the time limit. - my ( $numberinfo, $pricelistinfo, $cardinfo, $phoneno ) = @_; - my ( $connectfee, $cost, $timelimit, $available, $maxtime, $balance ); - # Timelimit is in seconds - if ($cc == 0) { +sub timelimit() { #Calculate and say the time limit. + my ( $numberinfo, $pricelistinfo, $cardinfo, $phoneno ) = @_; + my ( $connectfee, $cost, $timelimit, $available, $maxtime, $balance ); + + # Timelimit is in seconds + if ( $cc == 0 ) { $available = - ( $cardinfo->{value} - $cardinfo->{used} ) - $numberinfo->{connectfee}; - $ASTPP->debug( debug => "FUNDS AVAILABLE: $available", - verbosity => $verbosity); - } elsif ( $cc == 1 ) { - $balance = &accountbalance( $astpp_db, $cardinfo->{number} ); - $balance = ($balance * -1) + ( $cardinfo->{credit_limit}); - $available = ($balance - $numberinfo->{connectfee}) / 100; - } - if ( $available > 0 && $numberinfo->{cost} > 0 ) { - $timelimit = ( ( $available / $numberinfo->{cost} ) * 60 ); - } - elsif ( $available >= 0 && $numberinfo->{cost} <= 0 ) { - $timelimit = $config->{callingcards_max_length}; - } - if ( $timelimit > $config->{callingcards_max_length} ) { - $timelimit = $config->{callingcards_max_length}; - } - $ASTPP->debug( debug => "TIMELIMIT: $timelimit", - verbosity => $verbosity); - if ($brandinfo->{reseller} ne "") { - ASTPP->debug( debug => "THIS BRAND BELONGS TO $brandinfo->{reseller}!", - verbosity => $verbosity); - my $carddata = &get_account( $astpp_db, $brandinfo->{reseller} ); + ( $cardinfo->{value} - $cardinfo->{used} ) - + $numberinfo->{connectfee}; + $ASTPP->debug( + debug => "FUNDS AVAILABLE: $available", + verbosity => $verbosity + ); + } + elsif ( $cc == 1 ) { + $balance = &accountbalance( $astpp_db, $cardinfo->{number} ); + $balance = ( $balance * -1 ) + ( $cardinfo->{credit_limit} ); + $available = ( $balance - $numberinfo->{connectfee} ) / 100; + } + if ( $available > 0 && $numberinfo->{cost} > 0 ) { + $timelimit = ( ( $available / $numberinfo->{cost} ) * 60 ); + } + elsif ( $available >= 0 && $numberinfo->{cost} <= 0 ) { + $timelimit = $config->{callingcards_max_length}; + } + if ( $timelimit > $config->{callingcards_max_length} ) { + $timelimit = $config->{callingcards_max_length}; + } + $ASTPP->debug( + debug => "TIMELIMIT: $timelimit", + verbosity => $verbosity + ); + if ( $brandinfo->{reseller} ne "" ) { + ASTPP->debug( + debug => "THIS BRAND BELONGS TO $brandinfo->{reseller}!", + verbosity => $verbosity + ); + my $carddata = &get_account( $astpp_db, $brandinfo->{reseller} ); + # ($callstatus, $maxlength) = &max_length($astpp_db, $config, $carddata, $phoneno); # my $routeinfo = &get_route( $astpp_db, $config, $phoneno, $carddata->{pricelist},$carddata ); - my $minimumcharge = $numberinfo->{cost}; - my $belongs_to_reseller = 1; - while ( $belongs_to_reseller == 1 ) { - $ASTPP->debug( debug => "FINDING LIMIT FOR: $carddata->{reseller}", - verbosity => $verbosity); - push @resellerlist, $carddata->{number}; - $ASTPP->debug( debug => "PUSHING $carddata->{number} ONTO THE LIST OF RESELLERS", - verbosity => $verbosity); - my ($resellercallstatus, $resellermaxlength) = &max_length($astpp_db, $config, $carddata, $phoneno); - my $routeinfo = &get_route( $astpp_db, $config, $phoneno, $carddata->{pricelist}, $carddata, "CC" ); - if ($resellercallstatus != 1) { - $carddata->{reseller} = ""; - $timelimit = 0; - } elsif ($resellermaxlength < $timelimit / 60) { - $timelimit = $resellermaxlength * 60; - } - if ($resellermaxlength < 1 || $routeinfo->{cost} > $minimumcharge ) { - $carddata->{reseller} = ""; - $timelimit = 0; - } - $ASTPP->debug( debug => "RESELLER Max Length: $resellermaxlength", - verbosity => $verbosity); - $ASTPP->debug( debug => "RESELLER Call Status: $resellercallstatus", - verbosity => $verbosity); - if ($carddata->{reseller} && $carddata->{reseller} ne "") { - $carddata = &get_account( $astpp_db, $carddata->{reseller} ); - } else { - $belongs_to_reseller = 0; - } - } - } else { - $ASTPP->debug( debug => "THIS BRAND DOES NOT BELONG TO A RESELLER!", - verbosity => $verbosity); + my $minimumcharge = $numberinfo->{cost}; + my $belongs_to_reseller = 1; + while ( $belongs_to_reseller == 1 ) { + $ASTPP->debug( + debug => "FINDING LIMIT FOR: $carddata->{reseller}", + verbosity => $verbosity + ); + push @resellerlist, $carddata->{number}; + $ASTPP->debug( + debug => + "PUSHING $carddata->{number} ONTO THE LIST OF RESELLERS", + verbosity => $verbosity + ); + my ( $resellercallstatus, $resellermaxlength ) = + &max_length( $astpp_db, $config, $carddata, $phoneno ); + my $routeinfo = + &get_route( $astpp_db, $config, $phoneno, $carddata->{pricelist}, + $carddata, "CC" ); + if ( $resellercallstatus != 1 ) { + $carddata->{reseller} = ""; + $timelimit = 0; + } + elsif ( $resellermaxlength < $timelimit / 60 ) { + $timelimit = $resellermaxlength * 60; + } + if ( $resellermaxlength < 1 || $routeinfo->{cost} > $minimumcharge ) + { + $carddata->{reseller} = ""; + $timelimit = 0; + } + $ASTPP->debug( + debug => "RESELLER Max Length: $resellermaxlength", + verbosity => $verbosity + ); + $ASTPP->debug( + debug => "RESELLER Call Status: $resellercallstatus", + verbosity => $verbosity + ); + if ( $carddata->{reseller} && $carddata->{reseller} ne "" ) { + $carddata = &get_account( $astpp_db, $carddata->{reseller} ); + } + else { + $belongs_to_reseller = 0; + } } - $ASTPP->debug( debug =>"TIMELIMIT: $timelimit", verbosity => $verbosity); + } + else { + $ASTPP->debug( + debug => "THIS BRAND DOES NOT BELONG TO A RESELLER!", + verbosity => $verbosity + ); + } + $ASTPP->debug( debug => "TIMELIMIT: $timelimit", verbosity => $verbosity ); + my $minutes = $timelimit / 60; + $ASTPP->debug( debug => "MINUTES: $minutes", verbosity => $verbosity ); + if ( $minutes > 0 && $config->{calling_cards_timelimit_announce} == 1 ) { my $minutes = $timelimit / 60; - $ASTPP->debug( debug => "MINUTES: $minutes", verbosity => $verbosity); - if ($minutes > 0 && $config->{calling_cards_timelimit_announce} == 1) { - my $minutes = $timelimit / 60; - $minutes = sprintf( "%.0f", $minutes ); - $session->streamFile($sound->{call_will_last}); - if ( $minutes == 1 ) { - $session->execute("phrase","spell," . $minutes); - $session->streamFile($sound->{minute}); - } - elsif ( $minutes > 1 ) { - $session->execute("phrase","spell," . $minutes); - $session->streamFile($sound->{minutes}); - } + $minutes = sprintf( "%.0f", $minutes ); + $session->streamFile( $sound->{call_will_last} ); + if ( $minutes == 1 ) { + $session->execute( "phrase", "spell," . $minutes ); + $session->streamFile( $sound->{minute} ); } - elsif ($minutes < 1) { - $session->streamFile($sound->{not_enough_credit}); - $session->streamFile($sound->{goodbye}); - &leave($cardinfo); + elsif ( $minutes > 1 ) { + $session->execute( "phrase", "spell," . $minutes ); + $session->streamFile( $sound->{minutes} ); } - $ASTPP->debug( debug => "Available: $available", - verbosity => $verbosity ); - $ASTPP->debug( debug => "Balance: $balance", verbosity => $verbosity ); - $ASTPP->debug( debug => "Max Time: $maxtime", verbosity => $verbosity ); - return $timelimit; + } + elsif ( $minutes < 1 ) { + $session->streamFile( $sound->{not_enough_credit} ); + $session->streamFile( $sound->{goodbye} ); + &leave($cardinfo); + } + $ASTPP->debug( + debug => "Available: $available", + verbosity => $verbosity + ); + $ASTPP->debug( debug => "Balance: $balance", verbosity => $verbosity ); + $ASTPP->debug( debug => "Max Time: $maxtime", verbosity => $verbosity ); + return $timelimit; } -sub say_balance() { #Calculate and say the card balance. - my ($cardinfo) = @_; - my ( $connectfee, $cost, $included, $sub_balance, $balance, $main_balance ); - if ($cc == 0 ) { +sub say_balance() { #Calculate and say the card balance. + my ($cardinfo) = @_; + my ( $connectfee, $cost, $included, $sub_balance, $balance, $main_balance ); + if ( $cc == 0 ) { $balance = $cardinfo->{value} - $cardinfo->{used}; - } elsif ($cc ==1) { + } + elsif ( $cc == 1 ) { $balance = &accountbalance( $astpp_db, $cardinfo->{number} ); - $balance = ($balance * -1) + ( $cardinfo->{credit_limit} ); + $balance = ( $balance * -1 ) + ( $cardinfo->{credit_limit} ); + } + if ( $balance > 0 ) { + $balance = $balance / 10000; + $balance = sprintf( "%.2f", $balance ); + $sub_balance = substr( $balance, -2, 2 ); + $main_balance = substr( $balance, 0, -2 ); + $session->streamFile( $sound->{card_has_balance_of} ); + if ( $main_balance == 1 ) { + $session->execute( "phrase", "spell," . $main_balance ); + $session->streamFile( $sound->{main_currency} ); } - if ( $balance > 0 ) { - $balance = $balance / 10000; - $balance = sprintf( "%.2f", $balance ); - $sub_balance = substr( $balance, -2, 2 ); - $main_balance = substr( $balance, 0, -2 ); - my $interrupt = $session->playAndGetDigits(1,1,1,0,"#*","$sound->{card_has_balance_of}","$sound->{card_has_balance_of}",'^[0-9]+$'); - if (!$interrupt || $interrupt eq "" || $interrupt == 0) { - if ( $main_balance == 1 ) { -$session->execute("phrase","spell," . $main_balance); - $session->streamFile($sound->{main_currency}); - } - elsif ( $main_balance > 1 ) { -$session->execute("phrase","spell," . $main_balance); - $session->streamFile($sound->{main_currency_plural}); - } - if ( $sub_balance == 1 ) { -$session->execute("phrase","spell," . $sub_balance); - $session->streamFile($sound->{sub_currency}); - } - elsif ( $sub_balance > 1 ) { -$session->execute("phrase","spell," . $sub_balance); - $session->streamFile($sound->{sub_currency_plural}); - } - } + elsif ( $main_balance > 1 ) { + $session->execute( "phrase", "spell," . $main_balance ); + $session->streamFile( $sound->{main_currency_plural} ); } - else { - $session->streamFile($sound->{card_is_empty}); - $session->streamFile($sound->{goodbye}); - &leave($cardinfo); + if ( $sub_balance == 1 ) { + $session->execute( "phrase", "spell," . $sub_balance ); + $session->streamFile( $sound->{sub_currency} ); } - return $balance; + elsif ( $sub_balance > 1 ) { + $session->execute( "phrase", "spell," . $sub_balance ); + $session->streamFile( $sound->{sub_currency_plural} ); + } + } + else { + $session->streamFile( $sound->{card_is_empty} ); + $session->streamFile( $sound->{goodbye} ); + &leave($cardinfo); + } + return $balance; } -sub update_balance() { #Update the available credit on the calling card. - my ( $cardinfo, $charge ) = @_; - my $sql = - "UPDATE callingcards SET used = " - . $astpp_db->quote( ($charge) + $cardinfo->{used} ) - . " WHERE cardnumber = " - . $astpp_db->quote( $cardinfo->{cardnumber} ); - $astpp_db->do($sql); +sub update_balance() { #Update the available credit on the calling card. + my ( $cardinfo, $charge ) = @_; + my $sql = + "UPDATE callingcards SET used = " + . $astpp_db->quote( ($charge) + $cardinfo->{used} ) + . " WHERE cardnumber = " + . $astpp_db->quote( $cardinfo->{cardnumber} ); + $astpp_db->do($sql); } -sub write_asterisk_cdr() { #Write the cdr record to the asterisk cdr db. This is done so we get a record of the call the callingcard user placed. - # This is especially important for resellers and calling cards. - my ( - $reseller, $clid, $destination, $status, - $callstart, $answeredtime, $dstchannel, $lastapp, $dialedtime, $uniqueid, $asterisk_time, $cdr_db - ) - = @_; - my ($sql); - if (!$status) {$status = gettext("N/A"); } - $sql = "INSERT INTO cdr (calldate,dst,clid,dstchannel,lastapp,duration,billsec,disposition,accountcode,uniqueid) VALUES(" - . $astpp_db->quote($asterisk_time) . ", " - . $astpp_db->quote($destination) . ", " - . $astpp_db->quote($clid) . ", " - . $astpp_db->quote($dstchannel) . ", " - . $astpp_db->quote($lastapp) . ", " - . $astpp_db->quote($dialedtime) . ", " - . $astpp_db->quote($answeredtime) . ", " - . $astpp_db->quote($status) . ", " - . $astpp_db->quote( $reseller ) . ", " - . $astpp_db->quote( $uniqueid ) . ")"; - $cdr_db->do($sql); - $session->execute("set", "ANSWEREDTIME=0" ); - $session->execute("set", "DIALEDTIME=0" ); - $session->execute("set", "DIALSTATUS=NO ANSWER" ); -} -sub write_cdr() { # Write the callingcardcdr record if this is a calling card. - my ( - $cardinfo, $clid, $destination, $status, - $callstart, $charge, $answeredtime - ) - = @_; - my ($sql); - if (!$status) {$status = gettext("N/A"); } - $sql = -"INSERT INTO callingcardcdrs (cardnumber,clid,destination,disposition,callstart,seconds," - . "debit) VALUES (" - . $astpp_db->quote( $cardinfo->{cardnumber} ) . ", " - . $astpp_db->quote($clid) . ", " - . $astpp_db->quote($destination) . ", " - . $astpp_db->quote($status) . ", " - . $astpp_db->quote($callstart) . ", " - . $astpp_db->quote($answeredtime) . ", " - . $astpp_db->quote($charge) . ")"; - $astpp_db->do($sql); - $ASTPP->debug( debug => "$sql", verbosity => $verbosity ); - $ASTPP->debug( debug => "Resetting CDR Variables", verbosity => $verbosity ); - $session->execute("set", "ANSWEREDTIME=0" ); - $session->execute("set", "DIALEDTIME=0" ); - $session->execute("set", "DIALSTATUS=NO ANSWER" ); +sub dialout() { # Rig up the LCR stuff and do the outbound dialing. + # If a call does not go through we give the user the option + # of trying again. + my ( + $destination, $timelimit, $numberinfo, + $pricelistinfo, $cardinfo, $brandinfo + ) = @_; + my ( $status, $count, $increment ); + $ASTPP->debug( + debug => "Looking for outbound Route", + verbosity => $verbosity + ); + my @outboundroutes = + &get_outbound_routes( $astpp_db, $destination, $cardinfo, $numberinfo, + @resellerlist ); + $count = @outboundroutes; + if ( $count == 0 ) { + $ASTPP->debug( + debug => "NO OUTBOUND ROUTES FOUND!", + verbosity => $verbosity + ); + my $order = + $session->playAndGetDigits( 1, 1, 1, + $config->{calling_cards_general_input_timeout}, + "#*", "$sound->{noanswer}", "", '^[0-9]+$' ); + if ( $order != 1 ) { + &leave($cardinfo); + } + } + $count = 0; + foreach my $route (@outboundroutes) { + my $callstart = localtime(); + my ($accountcode); + $callstart = &prettytimestamp if $cc == 1; + $session->execute( "sched_hangup", "+" . $timelimit * 60 ); + my ( $xml_string, $data_string ) = $ASTPP->fs_dialplan_xml_bridge( + destination_number => $destination, + route_prepend => $route->{prepend}, + trunk_name => $route->{trunk} + ); + my ( $dialedtime, $uniqueid, $answeredtime, $clid ); + $session->execute( "export", "CALLINGCARDS=1" ); + if ( $cc == 1 ) { + $session->execute( "export", "ACCOUNTCODE=CC:$cardinfo->{number}" ); + } + else { + $session->execute( "export", + "ACCOUNTCODE=CC:$cardinfo->{cardnumber}" ); + } + $session->execute( "bridge", "$data_string" ); + return 1; + } } -sub dialout() { # Rig up the LCR stuff and do the outbound dialing. - # If a call does not go through we give the user the option - # of trying again. - my ( $destination, $timelimit, $numberinfo, $pricelistinfo, $cardinfo, $brandinfo ) = - @_; - my ( $status, $count, $increment ); - $ASTPP->debug( debug => "Looking for outbound Route", verbosity => $verbosity ); - my @outboundroutes = &get_outbound_routes( $astpp_db, $destination,$cardinfo,$numberinfo, @resellerlist ); - $count = @outboundroutes; - if ( $count == 0 ) { - $ASTPP->debug(debug => "NO OUTBOUND ROUTES FOUND!", verbosity => $verbosity ); - my $order = $session->playAndGetDigits(1,1,1,$config->{calling_cards_general_input_timeout},"#*","$sound->{noanswer}","$sound->{noanswer}",'^[0-9]+$'); - if ( $order != 1 ) { - &write_cdr( $cardinfo, "", $destination, gettext("NO Route Found"), "", 0, 0 ); - &leave($cardinfo); - } - } - $count = 0; - foreach my $route (@outboundroutes) { - my $callstart = localtime(); - my ($accountcode); - $callstart = &prettytimestamp if $cc == 1; - $session->execute("sched_hangup","+" . $timelimit/1000*60); - my ($xml_string,$data_string) = $ASTPP->fs_dialplan_xml_bridge( - destination_number => $destination, - route_prepend => $route->{prepend}, - trunk_name => $route->{trunk} - ); - my ($dialedtime,$uniqueid,$answeredtime,$clid); - my $vars = $session->execute("bridge","$data_string"); - - $ASTPP->debug( debug => "Vars: " . $vars); -# return 1 if (! $session->ready()); -# $VARS{destination_number} = $num_dial; -# UPDATEV(); -# return 1; - my $asterisk_time = &prettytimestamp; - $ASTPP->debug( debug => "CALL STATUS $status", verbosity => 1); - $ASTPP->debug( debug => "ANSWERED TIME $answeredtime", verbosity => $verbosity); - $ASTPP->debug( debug => "Account CC?: $cc", verbosity => $verbosity); - - if ( ( $status != ~/CHANUNAVAIL/ ) && ( $status != ~/CONGESTION/ ) ) { - if ( $status =~ /BUSY/ ) { - $ASTPP->debug( debug => "CALL BUSY", verbosity => $verbosity ); - my $order = $session->playAndGetDigits(1,1,1,$config->{calling_cards_general_input_timeout},"#*","$sound->{busy}","$sound->{busy}",'^[0-9]+$'); - if ( $order != 1 ) { - &write_cdr( $cardinfo, $clid, $destination, $status, - $callstart, 0, 0, $uniqueid ) - if $cc == 0; - &write_account_cdr( $astpp_db, $cardinfo->{number}, 0, - $destination, $callstart, 0, $uniqueid, $clid ) - if $cc == 1; - &write_asterisk_cdr( $accountcode, $clid, $destination, $status, - $callstart, $answeredtime, $route->{trunk}, "CallingCards", $dialedtime, $uniqueid . "a", $asterisk_time, $cdr_db); - &leave($cardinfo); - } else { - push @outboundroutes, $route; - } - } - elsif ( $status =~ /NOANSWER/ ) { - $ASTPP->debug(debug=> "NO ANSWER", verbosity => $verbosity ); - my $order = $session->playAndGetDigits(1,1,1,$config->{calling_cards_general_input_timeout},"#*","$sound->{noanswer}","$sound->{noanswer}",'^[0-9]+$'); - if ( $order != 1 ) { - &write_cdr( $cardinfo, $clid, $destination, $status, - $callstart, 0, 0, $uniqueid ) - if $cc == 0; - &write_account_cdr( $astpp_db, $cardinfo->{number}, 0, - $destination, $callstart, 0, $uniqueid, $clid ) - if $cc == 1; - &write_asterisk_cdr( $accountcode, $clid, $destination, $status, - $callstart, $answeredtime, $route->{trunk}, "CallingCards", $dialedtime, $uniqueid . "a", $asterisk_time, $cdr_db); - &leave($cardinfo); - } else { - push @outboundroutes, $route; - } - } - elsif ( $status =~ /ANSWER/ || $answeredtime > 0) { - $ASTPP->debug( debug => "CALL ANSWERED", verbosity => $verbosity ); - my $increment; - if ( $numberinfo->{inc} > 0 ) { - $increment = $numberinfo->{inc}; - } - else { - $increment = $pricelistinfo->{inc}; - } - $ASTPP->debug( debug => "$numberinfo->{connectcost}, $numberinfo->{cost}, $answeredtime, $increment, $numberinfo->{includedseconds}", - verbosity => $verbosity); - my $charge = &calc_call_cost( - $numberinfo->{connectcost}, $numberinfo->{cost}, - $answeredtime, $increment, - $numberinfo->{includedseconds} - ); - $ASTPP->debug( debug => "Cost $charge ", verbosity => $verbosity ); - if ($cardinfo->{minute_fee_pennies} > 0) { - $charge = (($cardinfo->{minute_fee_pennies} * 100) + $charge) if $cardinfo->{timeused} + $answeredtime => $cardinfo->{minute_fee_minutes}; - } - if ($cardinfo->{min_length_pennies} > 0 && ($cardinfo->{min_length_minutes}*60) > $answeredtime) { - $charge = (($cardinfo->{min_length_pennies} * 100) + $charge); - } - if ( $cc == 0 ) { - &write_cdr( - $cardinfo, $clid, $destination, $status, - $callstart, $charge, $answeredtime, $uniqueid - ); - &write_asterisk_cdr( $accountcode, $clid, $destination, "ANSWERED", - $callstart, $answeredtime, $route->{trunk}, "CallingCards", $dialedtime, $uniqueid . "a", $asterisk_time, $cdr_db); - &update_balance( $cardinfo, $charge ); - $astpp_db->do("UPDATE callingcards SET timeused = " - . $astpp_db->quote($cardinfo->{timeused} + $answeredtime) - . " WHERE cardnumber = " - . $astpp_db->quote($cardinfo->{cardnumber})); - } - elsif ( $cc == 1 ) { - my $status = - &write_account_cdr( $astpp_db, $cardinfo->{number}, - $charge, $destination, $callstart, $answeredtime, $uniqueid, $clid ); - &write_asterisk_cdr( $accountcode, $clid, $destination, $status, - $callstart, $answeredtime, $route->{trunk}, "CallingCards", $dialedtime, $uniqueid . "a", $asterisk_time, $cdr_db); - $ASTPP->debug( debug => $status, verbosity => $verbosity ); - } - $session->streamFile($sound->{call_completed}); - &leave($cardinfo); - } - elsif ( $status =~ /CANCEL/ ) { - $ASTPP->debug( debug => "CALL CANCELLED", verbosity => $verbosity ); - $session->streamFile($sound->{cancelled}) if $config->{calling_cards_cancelled_prompt} == 1; - &write_cdr( $cardinfo, $clid, $destination, $status, $callstart, 0, - 0, $uniqueid ) - if $cc == 0; - &write_account_cdr( $astpp_db, $cardinfo->{number}, 0, - $destination, $callstart, 0, $uniqueid, $clid ) - if $cc == 1; - &write_asterisk_cdr( $accountcode, $clid, $destination, $status, - $callstart, $answeredtime, $route->{trunk}, "CallingCards", $dialedtime, $uniqueid . "a", $asterisk_time, $cdr_db); - &leave($cardinfo); - } - else { - $ASTPP->debug( debug => "ERROR - ERROR - ERROR", verbosity => $verbosity ); - my $order = $session->playAndGetDigits(1,1,1,$config->{calling_cards_general_input_timeout},"#*","$sound->{noanswer}","$sound->{noanswer}",'^[0-9]+$'); - if ( $order != 1 ) { - &write_cdr( $cardinfo, $clid, $destination, $status, - $callstart, 0, 0, $uniqueid ) - if $cc == 0; - &write_account_cdr( $astpp_db, $cardinfo->{number}, 0, - $destination, $callstart, 0, $uniqueid, $clid ) - if $cc == 1; - &write_asterisk_cdr( $accountcode, $clid, $destination, $status, - $callstart, $answeredtime, $route->{trunk}, "CallingCards", $dialedtime, $uniqueid . "a", $asterisk_time, $cdr_db); - &leave($cardinfo); - } - } - } - } -} - - -sub leave() { # Prepare everything and then leave the calling card app. - my ($cardinfo) = @_; - my ($whatnow); - my $retries = 0; - &set_in_use( $cardinfo, 0 ) if $cc == 0; - while ($retries < 3) { - $whatnow = $session->playAndGetDigits(1,1,1,$config->{calling_cards_general_input_timeout},"#*","$sound->{astpp_callingcard_menu}","$sound->{astpp_callingcard_menu}",'^[0-9]+$'); - $ASTPP->debug( debug => "WHAT NEXT = $whatnow ", verbosity => $verbosity ); - if ($cc == 1) { - $session->execute("set", "CARDNUMBER=$cardinfo->{number}" ); - } else { - $session->execute("set", "CARDNUMBER=$cardinfo->{cardnumber}" ); - } - $session->execute("set", "PIN=$cardinfo->{pin}" ); - if ( $whatnow == 1 ) { - $session->execute("set", "NEWCALL=1" ); - $session->execute("set", "DESTINATION=$stats{destination}" ); - &exit_program(); - } - elsif ( $whatnow == 2 ) { - $session->execute("set", "NEWCALL=1" ); - $session->execute("set", "DESTINATION=" ); - &exit_program(); - } - elsif ( $whatnow == 3 ) { - $session->streamFile($sound->{goodbye}); - $session->hangup; - } else { - $retries++; - } +sub leave() { # Prepare everything and then leave the calling card app. + my ($cardinfo) = @_; + my ($whatnow); + my $retries = 0; + &set_in_use( $cardinfo, 0 ) if $cc == 0; + while ( $retries < 3 ) { + $whatnow = $session->playAndGetDigits( + 1, + 1, + 1, + $config->{calling_cards_general_input_timeout}, + "#*", + "$sound->{astpp_callingcard_menu}", + "", + '^[0-9]+$' + ); + $ASTPP->debug( + debug => "WHAT NEXT = $whatnow ", + verbosity => $verbosity + ); + if ( $cc == 1 ) { + $session->execute( "export", "CARDNUMBER=$cardinfo->{number}" ); } - if ($retries == 3) { - $session->streamFile($sound->{goodbye}); - $session->hangup; + else { + $session->execute( "export", "CARDNUMBER=$cardinfo->{cardnumber}" ); } + $session->execute( "export", "PIN=$cardinfo->{pin}" ); + if ( $whatnow == 1 ) { + $session->execute( "export", "NEWCALL=1" ); + $session->execute( "export", "DESTINATION=$stats{destination}" ); + &exit_program(); + } + elsif ( $whatnow == 2 ) { + $session->execute( "export", "NEWCALL=1" ); + $session->execute( "export", "DESTINATION=" ); + &exit_program(); + } + elsif ( $whatnow == 3 ) { + $session->streamFile( $sound->{goodbye} ); + } + else { + $retries++; + } + } + if ( $retries == 3 ) { + $session->streamFile( $sound->{goodbye} ); + } } sub exit_program() { - $stats{total_time} = tv_interval ($stats{start_time}); - $astpp_db->do("INSERT INTO callingcard_stats(uniqueid,total_time,billable_time) VALUES (" - . $astpp_db->quote($stats{uniqueid}) . "," - . $astpp_db->quote($stats{total_time}) . "," - . $astpp_db->quote($stats{answered_time}) . ")"); - $stats{total_time} = tv_interval ($stats{start_time}); - exit(0); + $stats{total_time} = tv_interval( $stats{start_time} ); + $astpp_db->do( +"INSERT INTO callingcard_stats(uniqueid,total_time,billable_time) VALUES (" + . $astpp_db->quote( $stats{uniqueid} ) . "," + . $astpp_db->quote( $stats{total_time} ) . "," + . $astpp_db->quote( $stats{answered_time} ) + . ")" ); + $stats{total_time} = tv_interval( $stats{start_time} ); + exit(1); } -sub print_console() #Dump string to the console +sub print_console() #Dump string to the console { - my ($output) = @_; - freeswitch::consoleLog("ASTPP",$output . "\n"); + my ($output) = @_; + freeswitch::consoleLog( "ASTPP", $output . "\n" ); } -sub say() -{ - my($phrase,$say) = @_; - $session->execute("phrase", $phrase ."," . $say ); +sub say() { + my ( $phrase, $say ) = @_; + $session->execute( "phrase", $phrase . "," . $say ); } - - ################# Program Starts Here ################################# -my ( $cardnum, $pin, $destination, $connectsurcharge, $perminsurcharge, $brand ) = - @ARGV; +my ( $cardnum, $pin, $destination, $connectsurcharge, $perminsurcharge, $brand ) + = @ARGV; my ( $retries, $cardinfo, $numberinfo, $pricelistinfo, @outboundroutes, - $callstart ); + $callstart ); $session->answer(); &initialize; -return 1 if (! $session->ready()); +my $vars = $session->getVariable("answered_time"); +$vars .= " : "; +$vars .= $session->getVariable("hangup_time"); +$ASTPP->debug( debug => "Vars: " . $vars ); +return 1 if ( !$session->ready() ); -if ($cardnum && $cardnum ne "") { - $ASTPP->debug( debug => "We recieved a cardnumber from the dialplan",verbosity => $verbosity); - $cardinfo = &get_callingcard( $astpp_db, $cardnum, $config ); - if ( !$cardinfo ) { - $cardinfo = &get_account_cc( $astpp_db, $cardnum ); - $cc = 1 if $cardinfo; - } -} else { #We won't play the welcome file when we already have card numbers. - $session->streamFile($config->{calling_cards_welcome_file}); +if ( $cardnum && $cardnum ne "" ) { + $ASTPP->debug( + debug => "We recieved a cardnumber from the dialplan", + verbosity => $verbosity + ); + $cardinfo = &get_callingcard( $astpp_db, $cardnum, $config ); + if ( !$cardinfo ) { + $cardinfo = &get_account_cc( $astpp_db, $cardnum ); + $cc = 1 if $cardinfo; + } } +else { #We won't play the welcome file when we already have card numbers. + $session->streamFile( $config->{calling_cards_welcome_file} ); +} + # If $cc == 1 means that we are using an ASTPP account instead of an actual # calling card. -if ( $cardinfo->{status} != 1 || !$cardinfo->{status}) { - $retries = 0; - while ( $cardinfo->{status} != 1 && $retries < $config->{card_retries} ) { - $cardnum = $session->playAndGetDigits($config->{cardlength},$config->{cardlength},1,$config->{calling_cards_number_input_timeout},"#","$sound->{cardnumber}","$sound->{cardnumber}",'^[0-9]+$'); - $cardinfo = &get_callingcard( $astpp_db, $cardnum, $config ); - if ( !$cardinfo ) { - $cardinfo = &get_account_cc( $astpp_db, $cardnum ); - $cc = 1 if $cardinfo; - } - $ASTPP->debug(debug => "CARD BRAND: $cardinfo->{brand} SPECIFIED BRAND: $brand", verbosity => $verbosity); - if ($brand && $brand ne "") { - $cardinfo = "" if $cardinfo->{brand} ne $brand; - } - $ASTPP->debug( debug => "ASTPP Number: $cardnum ", verbosity => $verbosity ); - $ASTPP->debug( debug => "ASTPP Number Status: $cardinfo->{status}", verbosity => $verbosity ); - if ( $cardinfo->{status} != 1 ) { - $session->streamFile($sound->{cardnumber_incorrect}); - } - $retries++; +if ( $cardinfo->{status} != 1 || !$cardinfo->{status} ) { + $retries = 0; + while ( $cardinfo->{status} != 1 && $retries < $config->{card_retries} ) { + $cardnum = $session->playAndGetDigits( + $config->{cardlength}, + $config->{cardlength}, + 1, + $config->{calling_cards_number_input_timeout}, + "#", + "$sound->{cardnumber}", + "", + '^[0-9]+$' + ); + $cardinfo = &get_callingcard( $astpp_db, $cardnum, $config ); + if ( !$cardinfo ) { + $cardinfo = &get_account_cc( $astpp_db, $cardnum ); + $cc = 1 if $cardinfo; } + $ASTPP->debug( + debug => "CARD BRAND: $cardinfo->{brand} SPECIFIED BRAND: $brand", + verbosity => $verbosity + ); + if ( $brand && $brand ne "" ) { + $cardinfo = "" if $cardinfo->{brand} ne $brand; + } + $ASTPP->debug( + debug => "ASTPP Number: $cardnum ", + verbosity => $verbosity + ); + $ASTPP->debug( + debug => "ASTPP Number Status: $cardinfo->{status}", + verbosity => $verbosity + ); if ( $cardinfo->{status} != 1 ) { - $session->streamFile($sound->{goodbye}); - exit(1); + $session->streamFile( $sound->{cardnumber_incorrect} ); } + $retries++; + } + if ( $cardinfo->{status} != 1 ) { + $session->streamFile( $sound->{goodbye} ); + $session->hangup(); + exit(1); + } } if ( $pin != $cardinfo->{pin} ) { - $retries = 0; - while ( $cardinfo->{pin} != $pin && $retries < $config->{pin_retries} ) { - $pin = $session->playAndGetDigits($config->{pinlength},$config->{pinlength},1,$config->{calling_cards_pin_input_timeout},"#","$sound->{pin}","$sound->{pin}",'^[0-9]+$'); - if ( $cardinfo->{pin} != $pin ) { - $session->streamFile($sound->{pin_incorrect}); - } - $retries++; + $retries = 0; + while ( $cardinfo->{pin} != $pin && $retries < $config->{pin_retries} ) { + $pin = $session->playAndGetDigits( + $config->{pinlength}, $config->{pinlength}, + 1, $config->{calling_cards_pin_input_timeout}, + "#", "$sound->{pin}", + "", '^[0-9]+$' + ); + if ( $cardinfo->{pin} != $pin ) { + $session->streamFile( $sound->{pin_incorrect} ); } - if ( $pin != $cardinfo->{pin} ) { - $session->streamFile($sound->{pin_incorrect}); - $session->streamFile($sound->{goodbye}); - exit(0); - } + $retries++; + } + if ( $pin != $cardinfo->{pin} ) { + $session->streamFile( $sound->{pin_incorrect} ); + $session->streamFile( $sound->{goodbye} ); + exit(0); + } } &check_card($cardinfo) if $cc == 0; my $balance = &say_balance($cardinfo); # Getting this far means we have a valid card and pin. $brandinfo = &get_cc_brand( $astpp_db, $cardinfo->{brand} ) if $cc == 0; -if ($brandinfo->{reseller}) { - $config = &load_config_db_reseller($astpp_db,$config,$brandinfo->{reseller}); +if ( $brandinfo->{reseller} ) { + $config = + &load_config_db_reseller( $astpp_db, $config, $brandinfo->{reseller} ); } -$config = &load_config_db_brand($astpp_db,$config,$cardinfo->{brand}); +$config = &load_config_db_brand( $astpp_db, $config, $cardinfo->{brand} ); $pricelistinfo = &get_pricelist( $astpp_db, $brandinfo->{pricelist} ) if $cc == 0; $pricelistinfo = &get_pricelist( $astpp_db, $cardinfo->{pricelist} ) if $cc == 1; -if ($destination && $destination ne "" ) { - $numberinfo = - &get_route( $astpp_db, $config, $destination, $brandinfo->{pricelist}, $cardinfo ) - if $cc == 0; - $numberinfo = - &get_route( $astpp_db, $config, $destination, $cardinfo->{pricelist}, $cardinfo ) - if $cc == 1; +if ( $destination && $destination ne "" ) { + $numberinfo = + &get_route( $astpp_db, $config, $destination, $brandinfo->{pricelist}, + $cardinfo ) + if $cc == 0; + $numberinfo = + &get_route( $astpp_db, $config, $destination, $cardinfo->{pricelist}, + $cardinfo ) + if $cc == 1; } $retries = 0; while ( !$numberinfo->{pattern} && $retries < $config->{number_retries} ) { - $destination = $session->playAndGetDigits(4,35,1,$config->{calling_cards_dial_input_timeout},"#","$sound->{destination}","$sound->{destination}",'^[0-9]+$'); - $numberinfo = - &get_route( $astpp_db, $config, $destination, $brandinfo->{pricelist}, $cardinfo ); - if ( !$numberinfo->{pattern} ) { - $session->streamFile($sound->{destination_incorrect}); - } else { - $numberinfo->{cost} = $numberinfo->{cost} + $perminsurcharge if $perminsurcharge ne ""; - $numberinfo->{connectcost} = $numberinfo->{connectcost} + $connectsurcharge if $connectsurcharge ne ""; - } - $retries++; + $destination = + $session->playAndGetDigits( 4, 35, 1, + $config->{calling_cards_dial_input_timeout}, + "#", "$sound->{destination}", "", '^[0-9]+$' ); + $numberinfo = + &get_route( $astpp_db, $config, $destination, $brandinfo->{pricelist}, + $cardinfo ); + if ( !$numberinfo->{pattern} ) { + $session->streamFile( $sound->{destination_incorrect} ); + } + else { + $numberinfo->{cost} = $numberinfo->{cost} + $perminsurcharge + if $perminsurcharge ne ""; + $numberinfo->{connectcost} = + $numberinfo->{connectcost} + $connectsurcharge + if $connectsurcharge ne ""; + } + $retries++; } if ( !$numberinfo->{pattern} ) { - $session->streamFile($sound->{destination_incorrect}); - $session->streamFile($sound->{goodbye}); - $session->hangup(); - &leave($cardinfo); + $session->streamFile( $sound->{destination_incorrect} ); + $session->streamFile( $sound->{goodbye} ); + $session->hangup(); + &leave($cardinfo); } # Congratulations, we now have a working card,pin, and phone number. $stats{destination} = $destination; -&tell_cost( $numberinfo, $pricelistinfo, $cardinfo ); -my $timelimit = &timelimit( $numberinfo, $pricelistinfo, $cardinfo, $destination ); -$session->streamFile($sound->{please_wait_will_connect}) if $config->{calling_cards_connection_prompt} == 1; -&dialout( $destination, $timelimit, $numberinfo, $pricelistinfo, $cardinfo, $brandinfo ); +&tell_cost( $numberinfo, $pricelistinfo, $cardinfo ); +my $timelimit = + &timelimit( $numberinfo, $pricelistinfo, $cardinfo, $destination ); +$session->streamFile( $sound->{please_wait_will_connect} ) + if $config->{calling_cards_connection_prompt} == 1; +&dialout( + $destination, $timelimit, $numberinfo, + $pricelistinfo, $cardinfo, $brandinfo +); 1; This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |