ACLs
[freeside.git] / httemplate / edit / process / cust_main_county-expand.cgi
1 <% include('/elements/header-popup.html', 'Addition successful' ) %>
2
3 <SCRIPT TYPE="text/javascript">
4   window.top.location.reload();
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 #warn scalar(@expansion);
21 #warn "$_: $expansion[$_]\n" foreach (0..$#expansion);
22
23 @expansion=map {
24   unless ( /^\s*([\w\- ]+)\s*$/ ) {
25     $cgi->param('error', "Illegal item in expansion: $_");
26     print $cgi->redirect(popurl(2). "cust_main_county-expand.cgi?". $cgi->query_string );
27     myexit();
28   }
29   $1;
30 } @expansion;
31
32 foreach ( @expansion) {
33   my(%hash)=$cust_main_county->hash;
34   my($new)=new FS::cust_main_county \%hash;
35   $new->setfield('taxnum','');
36   if ( $cgi->param('taxclass') ) {
37     $new->setfield('taxclass', $_);
38   } elsif ( ! $cust_main_county->state ) {
39     $new->setfield('state',$_);
40   } else {
41     $new->setfield('county',$_);
42   }
43   my $error = $new->insert;
44   die $error if $error;
45 }
46
47 unless ( qsearch( 'cust_main', {
48                                  'state'  => $cust_main_county->state,
49                                  'county' => $cust_main_county->county,
50                                  'country' =>  $cust_main_county->country,
51                                } )
52          || ! @expansion
53 ) {
54   my $error = $cust_main_county->delete;
55   die $error if $error;
56 }
57
58 </%init>