prevent reload loops on process pages, #71249
[freeside.git] / httemplate / edit / process / cust_main_county-add.cgi
1 <% include('/elements/header-popup.html', 'Addition successful' ) %>
2
3 <SCRIPT TYPE="text/javascript">
4   topreload();
5 </SCRIPT>
6
7 </BODY>
8 </HTML>
9 <%init>
10
11 die "access denied"
12   unless $FS::CurrentUser::CurrentUser->access_right('Configuration');
13
14 $cgi->param('taxnum') =~ /^(\d+)$/ or die "Illegal taxnum!";
15 my $taxnum = $1;
16 my $cust_main_county = qsearchs('cust_main_county',{'taxnum'=>$taxnum})
17   or die ("Unknown taxnum!");
18
19 my @expansion = split /[\n\r]{1,2}/, $cgi->param('expansion');
20
21 @expansion=map {
22   unless ( /^\s*([\w \!\@\#\$\%\&\(\)\-\+\;\:\'\"\,\.\?\/\=\[\]]+)\s*$/ ) {
23     $cgi->param('error', "Illegal item in expansion: $_");
24     print $cgi->redirect(popurl(2). "cust_main_county-expand.cgi?". $cgi->query_string );
25     myexit();
26   }
27   $1;
28 } @expansion;
29
30 foreach ( @expansion ) {
31   my(%hash)=$cust_main_county->hash;
32   my($new)=new FS::cust_main_county \%hash;
33   $new->setfield('taxnum','');
34   $new->setfield('taxclass', '');
35   if ( $cgi->param('what') eq 'state' ) { #??
36     $new->setfield('state',$_);
37     $new->setfield('county', '');
38     $new->setfield('city', '');
39   } elsif ( $cgi->param('what') eq 'county' ) {
40     $new->setfield('county',$_);
41     $new->setfield('city', '');
42   } elsif ( $cgi->param('what') eq 'city' ) {
43     #uppercase cities in the US to try and agree with USPS validation
44     $new->setfield('city', $new->country eq 'US' ? uc($_) : $_ );
45   } else { #???
46     die 'unknown what '. $cgi->param('what');
47   }
48   my $error = $new->insert;
49   die $error if $error;
50 }
51
52 </%init>