--- astcc-original.agi 2005-03-20 20:42:36.897058729 +0800 +++ astcc.agi 2005-04-07 08:16:30.271583845 +0800 @@ -19,7 +19,7 @@ # ; Call script with the card-number as first arg and the number # ; to dial as the second arg. # ; -# exten => _00XXXXXXXXX,1,DeadAGI(astcc.agi,${CALLERIDNUM},${EXTEN}) +# exten => _00XXXXXXXXX,1,DeadAGI(astcc.agi,${CALLERIDNUM},${TARIFF},${EXTEN}) # exten => _00XXXXXXXXX,2,Hangup # # ; @@ -32,7 +32,7 @@ # ; If you call it with an extension of "BALANCE" and a calleridnumber, # ; it will read your balance to you and then exit. # -# exten => _00XXXXXXXXX,1,DeadAGI(astcc.agi,${CALLERIDNUM},BALANCE,1) +# exten => _00XXXXXXXXX,1,DeadAGI(astcc.agi,${CALLERIDNUM},BALANCE,'',1) # exten => _00XXXXXXXXX,2,Hangup # # I have added a few different quiet to this program. They can @@ -270,11 +270,14 @@ } sub getphone() { - my ($number) = @_; - my $sth = $dbh->prepare("SELECT * FROM routes WHERE " . $dbh->quote($number) . " RLIKE pattern ORDER BY LENGTH(pattern) DESC"); + my ($number, $tariff1) = @_; + print STDERR "3. Phone number is $number\nTariff is $tariff1\n"; + my $sth = $dbh->prepare("SELECT * FROM " . $tariff1 . " WHERE " . $dbh->quote($number) . " RLIKE pattern ORDER BY LENGTH(pattern) DESC"); + print STDERR "sth = $sth\n"; $sth->execute; $res = $sth->fetchrow_hashref; $sth->finish; + print STDERR "res = $res\n"; return $res; } @@ -290,7 +293,8 @@ $callstart = localtime(); return "CHANUNAVAIL" unless $res; if ($res->{tech} eq "Local") { - $dialstr = "Local/$phone/$res->{path}|30|HL(" . ($maxtime * 60 * 1000) . ":60000:30000)"; +; $dialstr = "Local/$phone/$res->{path}|30|HL(" . ($maxtime * 60 * 1000) . ":60000:30000)"; + $dialstr = "Local/" . '9' . "$phone" . '@' . "$res->{path}|30|HL(" . ($maxtime * 60 * 1000) . ":60000:30000)"; $res = $AGI->exec("DIAL $dialstr"); $answeredtime = $AGI->get_variable("ANSWEREDTIME"); $dialstatus = $AGI->get_variable("DIALSTATUS"); @@ -410,7 +414,7 @@ # # Answer the line right away # -($calleridnum, $phoneno, $quiet) = @ARGV; +($calleridnum, $phoneno, $tariff, $quiet) = @ARGV; $AGI->answer(); # # Play a nice tone @@ -518,12 +522,12 @@ } $phoneno = $res . $phoneno; - print STDERR "Phone number is $phoneno\n"; + print STDERR "1. Phone number is $phoneno\nTariff is $tariff\n"; if ($phoneno < 0) { &setinuse($carddata->{number}, 0); exit(0); } - $numdata = &getphone($phoneno); + $numdata = &getphone($phoneno, $tariff); if (!$numdata->{pattern}) { if ($quiet < 5 ) { $res = &mystreamfile("astcc-badphone"); @@ -551,9 +555,14 @@ &setinuse($carddata->{number}, 0); exit(0); } - $numdata = &getphone($phoneno); + print STDERR "2. Phone number is $phoneno\nTariff is $tariff\n"; + $numdata = &getphone($phoneno, $tariff); + print STDERR "2.a numdata = $numdata\n"; + print STDERR "2.b Matching pattern is $numdata->{pattern}\n"; if (!$numdata->{pattern}) { + print STDERR "2.c numdata = $numdata\n"; if ($quiet < 5 ) { + print STDERR "2.d quiet = $quiet\n"; $res = &mystreamfile("astcc-badphone"); $AGI->stream_file("vm-goodbye"); } @@ -577,8 +586,12 @@ exit(0); } - +if ($adjcost > 0) { $maxmins = int(($credit - $adjconn) / $adjcost); +} else { +$maxmins = 9999; +} + if ($maxmins <= 0.1) { if ($quiet < 5 ) { $res = &mystreamfile("astcc-notenough");