This commit was generated by cvs2svn to compensate for changes in r11022,
[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") %>
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 $npa[0] = '' unless @npa;
29 my @rate_prefix = map {
30                         #my($npa,$nxx) = split('-', $_);
31                         s/\D//g;
32                         new FS::rate_prefix {
33                           'countrycode' => $countrycode,
34                           #'npa'         => $npa,
35                           #'nxx'         => $nxx,
36                           'npa'         => $_,
37                         }
38                       } @npa;
39 # we no longer process dest_detail records here
40 my $error;
41 if ( $regionnum ) {
42   $error = $new->replace($old, 'rate_prefix' => \@rate_prefix );
43 } else {
44   $error = $new->insert( 'rate_prefix' => \@rate_prefix );
45   $regionnum = $new->getfield('regionnum');
46 }
47
48 </%init>