summaryrefslogtreecommitdiff
path: root/httemplate/misc/phonenums.cgi
blob: a048280bbc066a7aa69963feb43617fc3fb57397 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
<% encode_json(\@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 =~ /^_REGION (.*)$/ ) {
      $opts{'region'} = $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>