X-Git-Url: http://git.freeside.biz/gitweb/?p=freeside.git;a=blobdiff_plain;f=httemplate%2Fedit%2Fprocess%2Frate_region.cgi;h=1b271028dd60eb33223978e3295f42db713bb93e;hp=7532245650a91033d5857ef1bcdc6b69c0ed9612;hb=HEAD;hpb=3ce7691203a7737406bf2d4442f7fd84b81f847e diff --git a/httemplate/edit/process/rate_region.cgi b/httemplate/edit/process/rate_region.cgi index 753224565..1b271028d 100755 --- a/httemplate/edit/process/rate_region.cgi +++ b/httemplate/edit/process/rate_region.cgi @@ -1,52 +1,50 @@ -% -% -%my $regionnum = $cgi->param('regionnum'); -% -%my $old = qsearchs('rate_region', { 'regionnum' => $regionnum } ) if $regionnum; -% -%my $new = new FS::rate_region ( { -% map { -% $_, scalar($cgi->param($_)); -% } ( fields('rate_region') ) -%} ); -% -%my $countrycode = $cgi->param('countrycode'); -%my @npa = split(/\s*,\s*/, $cgi->param('npa')); -%$npa[0] = '' unless @npa; -%my @rate_prefix = map { -% new FS::rate_prefix { -% 'countrycode' => $countrycode, -% 'npa' => $_, -% } -% } @npa; -% -%my @dest_detail = map { -% my $ratenum = $_->ratenum; -% new FS::rate_detail { -% 'ratenum' => $ratenum, -% map { $_ => $cgi->param("$_$ratenum") } -% qw( min_included min_charge sec_granularity ) -% }; -%} qsearch('rate', {} ); -% -% -%my $error; -%if ( $regionnum ) { -% $error = $new->replace($old, 'rate_prefix' => \@rate_prefix, -% 'dest_detail' => \@dest_detail, ); -%} else { -% $error = $new->insert( 'rate_prefix' => \@rate_prefix, -% 'dest_detail' => \@dest_detail, ); -% $regionnum = $new->getfield('regionnum'); -%} -% %if ( $error ) { % $cgi->param('error', $error); -% print $cgi->redirect(popurl(2). "rate_region.cgi?". $cgi->query_string ); +<% $cgi->redirect(popurl(2). "rate_region.cgi?". $cgi->query_string ) %> +%} elsif ( $action eq 'Add' ) { +<% $cgi->redirect(popurl(2). "rate_region.cgi?regionnum=$regionnum") %> %} else { -% #print $cgi->redirect(popurl(3). "browse/rate_region.cgi"); -% print $cgi->redirect(popurl(3). "browse/rate.cgi"); +<% $cgi->redirect(popurl(3). "browse/rate_region.html") %> %} -% -% +<%init> + +my $conf = new FS::Conf; +die "access denied" + unless $FS::CurrentUser::CurrentUser->access_right('Configuration'); + +my $regionnum = $cgi->param('regionnum'); +my $action = $regionnum ? 'Edit' : 'Add'; + +my $old = qsearchs('rate_region', { 'regionnum' => $regionnum } ) if $regionnum; + +my $new = new FS::rate_region ( { + map { + $_, scalar($cgi->param($_)); + } ( fields('rate_region') ) +} ); + +my $countrycode = $cgi->param('countrycode'); +my @npa = split(/\s*,\s*/, $cgi->param('npa')); +my %npa = map { $_, 1 } @npa; #removing duplicates +@npa = sort keys %npa; +$npa[0] = '' unless @npa; +my @rate_prefix = map { + #my($npa,$nxx) = split('-', $_); + s/\D//g; + new FS::rate_prefix { + 'countrycode' => $countrycode, + #'npa' => $npa, + #'nxx' => $nxx, + 'npa' => $_, + } + } @npa; +# we no longer process dest_detail records here +my $error; +if ( $regionnum ) { + $error = $new->replace($old, 'rate_prefix' => \@rate_prefix ); +} else { + $error = $new->insert( 'rate_prefix' => \@rate_prefix ); + $regionnum = $new->getfield('regionnum'); +} +