summaryrefslogtreecommitdiff
path: root/httemplate/misc/phonenums.cgi
diff options
context:
space:
mode:
Diffstat (limited to 'httemplate/misc/phonenums.cgi')
-rw-r--r--httemplate/misc/phonenums.cgi43
1 files changed, 43 insertions, 0 deletions
diff --git a/httemplate/misc/phonenums.cgi b/httemplate/misc/phonenums.cgi
new file mode 100644
index 000000000..fd5de2ae6
--- /dev/null
+++ b/httemplate/misc/phonenums.cgi
@@ -0,0 +1,43 @@
+<% objToJson(\@phonenums) %>
+<%init>
+
+my( $exchangestring, $svcpart ) = $cgi->param('arg');
+
+my $part_svc = qsearchs('part_svc', { 'svcpart'=>$svcpart } );
+die "unknown svcpart $svcpart" unless $part_svc;
+
+my @phonenums = ();
+
+if ( $exchangestring ) {
+
+ my @exports = $part_svc->part_export_did;
+ if ( scalar(@exports) > 1 ) {
+ die "more than one DID-providing export attached to svcpart $svcpart";
+ } elsif ( ! @exports ) {
+ die "no DID providing export attached to svcpart $svcpart";
+ }
+ my $export = $exports[0];
+
+ my %opts = ();
+ if ( $exchangestring eq 'tollfree' ) {
+ $opts{'tollfree'} = 1;
+ }
+ #elsif ( $exchangestring =~ /^([\w\s\:\,\(\)\-]+), ([A-Z][A-Z])$/ ) {
+ elsif ( $exchangestring =~ /^(.+), ([A-Z][A-Z])$/ ) {
+ $opts{'ratecenter'} = $1;
+ $opts{'state'} = $2;
+ }
+ else {
+ $exchangestring =~ /\((\d{3})-(\d{3})-XXXX\)\s*$/i
+ or die "unparsable exchange: $exchangestring";
+ my( $areacode, $exchange ) = ( $1, $2 );
+ $opts{'areacode'} = $areacode;
+ $opts{'exchange'} = $exchange;
+ }
+
+ my $something = $export->get_dids(%opts);
+ @phonenums = @{ $something };
+
+}
+
+</%init>