This commit was generated by cvs2svn to compensate for changes in r4407,
[freeside.git] / httemplate / edit / process / rate_region.cgi
1 <%
2
3 my $regionnum = $cgi->param('regionnum');
4
5 my $old = qsearchs('rate_region', { 'regionnum' => $regionnum } ) if $regionnum;
6
7 my $new = new FS::rate_region ( {
8   map {
9     $_, scalar($cgi->param($_));
10   } ( fields('rate_region') )
11 } );
12
13 my $countrycode = $cgi->param('countrycode');
14 my @npa = split(/\s*,\s*/, $cgi->param('npa'));
15 $npa[0] = '' unless @npa;
16 my @rate_prefix = map {
17                         new FS::rate_prefix {
18                           'countrycode' => $countrycode,
19                           'npa'         => $_,
20                         }
21                       } @npa;
22
23 my @dest_detail = map {
24   my $ratenum = $_->ratenum;
25   new FS::rate_detail {
26     'ratenum'  => $ratenum,
27     map { $_ => $cgi->param("$_$ratenum") }
28         qw( min_included min_charge sec_granularity )
29   };
30 } qsearch('rate', {} );
31
32
33 my $error;
34 if ( $regionnum ) {
35   $error = $new->replace($old, 'rate_prefix' => \@rate_prefix,
36                                'dest_detail' => \@dest_detail, );
37 } else {
38   $error = $new->insert( 'rate_prefix' => \@rate_prefix,
39                          'dest_detail' => \@dest_detail, );
40   $regionnum = $new->getfield('regionnum');
41 }
42
43 if ( $error ) {
44   $cgi->param('error', $error);
45   print $cgi->redirect(popurl(2). "rate_region.cgi?". $cgi->query_string );
46 } else { 
47   #print $cgi->redirect(popurl(3). "browse/rate_region.cgi");
48   print $cgi->redirect(popurl(3). "browse/rate.cgi");
49 }
50
51 %>