summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorlevinse <levinse>2011-01-10 19:46:13 +0000
committerlevinse <levinse>2011-01-10 19:46:13 +0000
commit3aae44e96b429d182a7e36cf0ebb0d4bfef842d9 (patch)
treede0cc61e48ff0973c13c8e4dbe2380994d4a4135
parent9a46dd94e70887c5365c4b10d9db0d1b7f1b71ab (diff)
vitelity API improvements for toll-free and fax, RT11009
-rw-r--r--FS/FS/Schema.pm2
-rw-r--r--FS/FS/part_export/vitelity.pm114
-rw-r--r--FS/FS/svc_phone.pm16
-rw-r--r--httemplate/edit/process/svc_phone.html3
-rw-r--r--httemplate/edit/svc_phone.cgi2
-rw-r--r--httemplate/elements/select-did.html16
-rw-r--r--httemplate/elements/select-phonenum.html39
-rw-r--r--httemplate/misc/phonenums.cgi21
-rw-r--r--httemplate/view/svc_phone.cgi2
9 files changed, 189 insertions, 26 deletions
diff --git a/FS/FS/Schema.pm b/FS/FS/Schema.pm
index 9d8338fbf..979a5f7cf 100644
--- a/FS/FS/Schema.pm
+++ b/FS/FS/Schema.pm
@@ -2774,6 +2774,8 @@ sub tables_hashref {
'domsvc', 'int', 'NULL', '', '', '',
'locationnum', 'int', 'NULL', '', '', '',
'route', 'varchar', 'NULL', $char_d, '', '',
+ 'forwarddst', 'varchar', 'NULL', 15, '', '',
+ 'email', 'varchar', 'NULL', 255, '', '',
'lnp_status', 'varchar', 'NULL', $char_d, '', '',
'portable', 'char', 'NULL', 1, '', '',
'lrn', 'char', 'NULL', 10, '', '',
diff --git a/FS/FS/part_export/vitelity.pm b/FS/FS/part_export/vitelity.pm
index 1aa71fa96..d44335b65 100644
--- a/FS/FS/part_export/vitelity.pm
+++ b/FS/FS/part_export/vitelity.pm
@@ -14,6 +14,7 @@ tie my %options, 'Tie::IxHash',
'dry_run' => { label=>"Test mode - don't actually provision" },
'routesip' => { label=>'routesip (optional sub-account)' },
'type' => { label=>'type (optional DID type to order)' },
+ 'fax' => { label=>'vfax service', type=>'checkbox' },
;
%info = (
@@ -36,14 +37,56 @@ sub get_dids {
my $self = shift;
my %opt = ref($_[0]) ? %{$_[0]} : @_;
-# currently one of three cases: areacode+exchange, areacode, state
-# name == ratecenter
+ if ( $opt{'tollfree'} ) {
+ # XXX: no caching for now
+ # XXX: limit option
+
+ my $command = 'listtollfree';
+ $command = 'listdids' if $self->option('fax');
+ my @tollfree = $self->vitelity_command($command);
+ my @ret = ();
+
+ if (scalar(@tollfree)) {
+ local $SIG{HUP} = 'IGNORE';
+ local $SIG{INT} = 'IGNORE';
+ local $SIG{QUIT} = 'IGNORE';
+ local $SIG{TERM} = 'IGNORE';
+ local $SIG{TSTP} = 'IGNORE';
+ local $SIG{PIPE} = 'IGNORE';
+
+ my $oldAutoCommit = $FS::UID::AutoCommit;
+ local $FS::UID::AutoCommit = 0;
+ my $dbh = dbh;
+
+ my $errmsg = 'WARNING: error populating phone availability cache: ';
+
+ foreach my $did ( @tollfree ) {
+ $did =~ /^(\d{3})(\d{3})(\d{4})/ or die "unparsable did $did\n";
+ my($npa, $nxx, $station) = ($1, $2, $3);
+ push @ret, $did;
+
+ my $phone_avail = new FS::phone_avail {
+ 'exportnum' => $self->exportnum,
+ 'countrycode' => '1', # vitelity is US/CA only now
+ 'npa' => $npa,
+ 'nxx' => $nxx,
+ 'station' => $station,
+ };
+
+ $error = $phone_avail->insert();
+ if ( $error ) {
+ $dbh->rollback if $oldAutoCommit;
+ die $errmsg.$error;
+ }
+ }
+ $dbh->commit or warn $errmsg.$dbh->errstr if $oldAutoCommit;
- my %search = ();
+ }
- my $method = '';
+ my @sorted_ret = sort @ret;
+ return \@sorted_ret;
- if ( $opt{'areacode'} && $opt{'exchange'} ) { #return numbers in format NPA-NXX-XXXX
+ } elsif ( $opt{'areacode'} && $opt{'exchange'} ) { #return numbers in format NPA-NXX-XXXX
return [
map { join('-', $_->npa, $_->nxx, $_->station ) }
@@ -94,12 +137,14 @@ sub get_dids {
#otherwise, search for em
- my @ratecenters = $self->vitelity_command( 'listavailratecenters',
+ my $command = 'listavailratecenters';
+ $command = 'listratecenters' if $self->option('fax');
+ my @ratecenters = $self->vitelity_command( $command,
'state' => $opt{'state'},
);
# XXX: Options: type=unlimited OR type=pri
- if ( $ratecenters[0] eq 'unavailable' ) {
+ if ( $ratecenters[0] eq 'unavailable' || $ratecenters[0] eq 'none' ) {
return [];
} elsif ( $ratecenters[0] eq 'missingdata' ) {
die "missingdata error running Vitelity API"; #die?
@@ -121,20 +166,22 @@ sub get_dids {
my %npa = ();
foreach my $ratecenter (@ratecenters) {
- my @dids = $self->vitelity_command( 'listlocal',
+ my $command = 'listlocal';
+ $command = 'listdids' if $self->option('fax');
+ my @dids = $self->vitelity_command( $command,
'state' => $opt{'state'},
'ratecenter' => $ratecenter,
);
# XXX: Options: type=unlimited OR type=pri
- if ( $dids[0] eq 'unavailable' ) {
+ if ( $dids[0] eq 'unavailable' || $dids[0] eq 'noneavailable' ) {
next;
} elsif ( $dids[0] eq 'missingdata' ) {
die "missingdata error running Vitelity API"; #die?
}
foreach my $did ( @dids ) {
- $did =~ /^(\d{3})(\d{3})(\d{4}),/ or die "unparsable did $did\n";
+ $did =~ /^(\d{3})(\d{3})(\d{4})/ or die "unparsable did $did\n";
my($npa, $nxx, $station) = ($1, $2, $3);
$npa{$npa}++;
@@ -180,6 +227,7 @@ sub vitelity_command {
my $vitelity = Net::Vitelity->new(
'login' => $self->option('login'),
'pass' => $self->option('pass'),
+ 'apitype' => $self->option('fax') ? 'fax' : 'api',
#'debug' => $debug,
);
@@ -199,10 +247,23 @@ sub _export_insert {
$vparams{'type'} = $self->option('type')
if defined $self->option('type');
- my $result = $self->vitelity_command('getlocaldid',%vparams);
- if ( $result ne 'success' ) {
- return "Error running Vitelity getlocaldid: $result";
+ $command = 'getlocaldid';
+ $success = 'success';
+
+ # this is OK as Vitelity for now is US/CA only; it's not a hack
+ $command = 'gettollfree' if $vparams{'did'} =~ /^800|^88[8765]/;
+
+ if($self->option('fax')) {
+ # supposedly should work for toll-free fax too
+ $command = 'getdid';
+ $success = 'ok';
+ }
+
+ my $result = $self->vitelity_command($command,%vparams);
+
+ if ( $result ne $success ) {
+ return "Error running Vitelity $command: $result";
}
'';
@@ -211,7 +272,28 @@ sub _export_insert {
sub _export_replace {
my( $self, $new, $old ) = (shift, shift, shift);
- #hmm, what's to change?
+ # Call Forwarding
+ if( $old->forwarddst ne $new->forwarddst ) {
+ my $result = $self->vitelity_command('callfw',
+ 'did' => $old->phonenum,
+ 'forward' => $new->forwarddst ? $new->forwarddst : 'none',
+ );
+ if ( $result ne 'ok' ) {
+ return "Error running Vitelity callfw: $result";
+ }
+ }
+
+ # vfax forwarding emails
+ if( $old->email ne $new->email && $self->option('fax') ) {
+ my $result = $self->vitelity_command('changeemail',
+ 'did' => $old->phonenum,
+ 'emails' => $new->email ? $new->email : '',
+ );
+ if ( $result ne 'ok' ) {
+ return "Error running Vitelity changeemail: $result";
+ }
+ }
+
'';
}
@@ -223,12 +305,14 @@ sub _export_delete {
#probably okay to queue the deletion...?
#but hell, let's do it inline anyway, who wants phone numbers hanging around
+ return 'Deleting vfax DIDs is unsupported by Vitelity API' if $self->option('fax');
+
my $result = $self->vitelity_command('removedid',
'did' => $svc_phone->phonenum,
);
if ( $result ne 'success' ) {
- return "Error running Vitelity getlocaldid: $result";
+ return "Error running Vitelity removedid: $result";
}
'';
diff --git a/FS/FS/svc_phone.pm b/FS/FS/svc_phone.pm
index 0b001d706..cffe1e3f6 100644
--- a/FS/FS/svc_phone.pm
+++ b/FS/FS/svc_phone.pm
@@ -83,6 +83,14 @@ Optional svcnum from svc_pbx
Route id/number
+=item forwarddst
+
+Forwarding destination
+
+=item email
+
+Email address for virtual fax (fax-to-email) services
+
=item lnp_status
LNP Status (can be null, native, portedin, portingin, portin-reject,
@@ -170,6 +178,12 @@ sub table_info {
'route' => { label => 'Route',
%dis2,
},
+ 'forwarddst' => { label => 'Forward Destination',
+ %dis2,
+ },
+ 'email' => { label => 'Email',
+ %dis2,
+ },
'lnp_status' => { label => 'LNP Status',
type => 'select-lnp_status.html',
%dis2,
@@ -464,6 +478,8 @@ sub check {
|| $self->ut_foreign_keyn('domsvc', 'svc_domain', 'svcnum' )
|| $self->ut_foreign_keyn('locationnum', 'cust_location', 'locationnum')
|| $self->ut_textn('route')
+ || $self->ut_numbern('forwarddst')
+ || $self->ut_textn('email')
|| $self->ut_numbern('lrn')
|| $self->ut_numbern('lnp_desired_due_date')
|| $self->ut_numbern('lnp_due_date')
diff --git a/httemplate/edit/process/svc_phone.html b/httemplate/edit/process/svc_phone.html
index ddc938216..9dd1226cc 100644
--- a/httemplate/edit/process/svc_phone.html
+++ b/httemplate/edit/process/svc_phone.html
@@ -9,6 +9,9 @@
die "access denied"
unless $FS::CurrentUser::CurrentUser->access_right('Provision customer service'); #something else more specific?
+my $tollfreephonenum = $cgi->param('tollfreephonenum');
+$cgi->param('phonenum',$tollfreephonenum) if $tollfreephonenum =~ /^\d+$/;
+
my $args_callback = sub {
my( $cgi, $object ) = @_;
diff --git a/httemplate/edit/svc_phone.cgi b/httemplate/edit/svc_phone.cgi
index 8dd58d7ed..1623ed38a 100644
--- a/httemplate/edit/svc_phone.cgi
+++ b/httemplate/edit/svc_phone.cgi
@@ -38,6 +38,8 @@ push @fields, { field => 'pbxsvc',
maxlength => $conf->config('svc_phone-phone_name-max_length'),
},
'route',
+ 'forwarddst',
+ 'email',
{ value => 'E911 Information',
type => 'tablebreak-tr-title',
diff --git a/httemplate/elements/select-did.html b/httemplate/elements/select-did.html
index 062c98a80..546d90e8d 100644
--- a/httemplate/elements/select-did.html
+++ b/httemplate/elements/select-did.html
@@ -58,6 +58,19 @@ Example:
</TR>
</TABLE>
+
+% if ( $tollfree ) {
+ or toll-free
+ <% include('/elements/select-phonenum.html',
+ 'svcpart' => $svcpart,
+ 'empty' => 'Select phone number',
+ 'tollfree' => 1,
+ 'prefix' => 'tollfree',
+ 'bulknum' => 0,
+ )
+ %>
+% }
+
% if ( $bulknum ) {
<div id="bulkdid" style="padding-top: 11px">
% my $i;
@@ -100,6 +113,9 @@ if ( scalar(@exports) > 1 ) {
my $use_selector = scalar(@exports) ? 1 : 0;
+my $tollfree = 0;
+$tollfree = 1 if (scalar(@exports) && $exports[0]->exporttype eq 'vitelity');
+
my $bulknum = $opt{'bulknum'} || 0;
#my $field = $opt{'field'} || 'phonenum';
diff --git a/httemplate/elements/select-phonenum.html b/httemplate/elements/select-phonenum.html
index 986329043..25a885a39 100644
--- a/httemplate/elements/select-phonenum.html
+++ b/httemplate/elements/select-phonenum.html
@@ -86,13 +86,50 @@
}
+% if ( $opt{'tollfree'} ) {
+ function <% $opt{'prefix'} %>update_phonenums(phonenums) {
+ // lame hack so I can copy the code from above
+ what = document.getElementById('<% $opt{prefix} %>phonenum');
+
+ // blank the current phonenum
+ for ( var i = what.form.<% $opt{'prefix'} %>phonenum.length; i >= 0; i-- )
+ what.form.<% $opt{'prefix'} %>phonenum.options[i] = null;
+
+% if ($opt{empty}) {
+ opt(what.form.<% $opt{'prefix'} %>phonenum, '', '<% $opt{empty} %>');
+% }
+
+ // add the new phonenums
+ var phonenumArray = eval('(' + phonenums + ')' );
+ for ( var s = 0; s < phonenumArray.length; s++ ) {
+ var phonenumLabel = phonenumArray[s];
+ if ( phonenumLabel == "" )
+ phonenumLabel = '(n/a)';
+ opt(what.form.<% $opt{'prefix'} %>phonenum, phonenumArray[s], phonenumLabel);
+ }
+
+ what.form.<% $opt{'prefix'} %>phonenum.disabled = '';
+
+ if ( phonenumArray.length >= 1 ) {
+ what.form.<% $opt{'prefix'} %>phonenum.disabled = '';
+ what.form.<% $opt{'prefix'} %>phonenum.style.display = '';
+ }
+
+ }
+ <% $opt{'prefix'} %>get_phonenums( 'tollfree', <% $opt{'svcpart'} %>, <% $opt{'prefix'} %>update_phonenums );
+% }
+
</SCRIPT>
+% unless ( $opt{'tollfree'} ) {
<DIV ID="phonenumwait" STYLE="display:none"><IMG SRC="<%$fsurl%>images/wait-orange.gif"> <B>Finding phone numbers</B></DIV>
<DIV ID="phonenumerror" STYLE="display:none"><IMG SRC="<%$fsurl%>images/cross.png"> <B>Select a different city/exchange</B></DIV>
+% }
-<SELECT NAME="<% $opt{'prefix'} %>phonenum" notonChange="<% $opt{'prefix'} %>phonenum_changed(this); <% $opt{'onchange'} %>" <% $opt{'disabled'} %>>
+<SELECT ID="<% $opt{'prefix'} %>phonenum" NAME="<% $opt{'prefix'} %>phonenum"
+ notonChange="<% $opt{'prefix'} %>phonenum_changed(this); <% $opt{'onchange'} %>"
+ <% $opt{'disabled'} %>>
<OPTION VALUE="">Select phone number</OPTION>
</SELECT>
diff --git a/httemplate/misc/phonenums.cgi b/httemplate/misc/phonenums.cgi
index 2ed0f617d..b86d03f5d 100644
--- a/httemplate/misc/phonenums.cgi
+++ b/httemplate/misc/phonenums.cgi
@@ -1,12 +1,8 @@
-%# [ <% join(', ', map { qq("$_") } @exchanges) %> ]
<% objToJson(\@exchanges) %>
<%init>
my( $exchangestring, $svcpart ) = $cgi->param('arg');
-$exchangestring =~ /\((\d{3})-(\d{3})-XXXX\)\s*$/i
- or die "unparsable exchange: $exchangestring";
-my( $areacode, $exchange ) = ( $1, $2 );
my $part_svc = qsearchs('part_svc', { 'svcpart'=>$svcpart } );
die "unknown svcpart $svcpart" unless $part_svc;
@@ -18,12 +14,19 @@ if ( scalar(@exports) > 1 ) {
}
my $export = $exports[0];
-my $something = $export->get_dids('areacode'=>$areacode,
- 'exchange'=>$exchange,
- );
-
-#warn Dumper($something);
+my %opts = ();
+if ( $exchangestring eq 'tollfree' ) {
+ $opts{'tollfree'} = 1;
+}
+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);
my @exchanges = @{ $something };
</%init>
diff --git a/httemplate/view/svc_phone.cgi b/httemplate/view/svc_phone.cgi
index c2379a079..7b0ea7071 100644
--- a/httemplate/view/svc_phone.cgi
+++ b/httemplate/view/svc_phone.cgi
@@ -19,7 +19,7 @@ my %labels = map { $_ => ( ref($fields->{$_})
my @fields = qw( countrycode phonenum );
push @fields, 'domain' if $conf->exists('svc_phone-domain');
-push @fields, qw( pbx_title sip_password pin phone_name route );
+push @fields, qw( pbx_title sip_password pin phone_name route forwarddst email );
if ( $conf->exists('svc_phone-lnp') ) {
push @fields, 'lnp_status',