RT# 82949 - changes section name from fees to pricing, better opiton
[freeside.git] / httemplate / edit / process / rate_region.cgi
1 %if ( $error ) {
2 %  $cgi->param('error', $error);
3 <% $cgi->redirect(popurl(2). "rate_region.cgi?". $cgi->query_string ) %>
4 %} elsif ( $action eq 'Add' ) {
5 <% $cgi->redirect(popurl(2). "rate_region.cgi?regionnum=$regionnum") %>
6 %} else { 
7 <% $cgi->redirect(popurl(3). "browse/rate_region.html") %>
8 %}
9 <%init>
10
11 my $conf = new FS::Conf;
12 die "access denied"
13   unless $FS::CurrentUser::CurrentUser->access_right('Configuration');
14
15 my $regionnum = $cgi->param('regionnum');
16 my $action = $regionnum ? 'Edit' : 'Add';
17
18 my $old = qsearchs('rate_region', { 'regionnum' => $regionnum } ) if $regionnum;
19
20 my $new = new FS::rate_region ( {
21   map {
22     $_, scalar($cgi->param($_));
23   } ( fields('rate_region') )
24 } );
25
26 my $countrycode = $cgi->param('countrycode');
27 my @npa = split(/\s*,\s*/, $cgi->param('npa'));
28 my %npa = map { $_, 1 } @npa; #removing duplicates
29 @npa = sort keys %npa;
30 $npa[0] = '' unless @npa;
31 my @rate_prefix = map {
32                         #my($npa,$nxx) = split('-', $_);
33                         s/\D//g;
34                         new FS::rate_prefix {
35                           'countrycode' => $countrycode,
36                           #'npa'         => $npa,
37                           #'nxx'         => $nxx,
38                           'npa'         => $_,
39                         }
40                       } @npa;
41 # we no longer process dest_detail records here
42 my $error;
43 if ( $regionnum ) {
44   $error = $new->replace($old, 'rate_prefix' => \@rate_prefix );
45 } else {
46   $error = $new->insert( 'rate_prefix' => \@rate_prefix );
47   $regionnum = $new->getfield('regionnum');
48 }
49
50 </%init>