64061deed8b9df8e114a83439479ecc9f618c6cc
[freeside.git] / httemplate / edit / process / cust_main_county-expand.cgi
1 <%
2
3 $cgi->param('taxnum') =~ /^(\d+)$/ or die "Illegal taxnum!";
4 my $taxnum = $1;
5 my $cust_main_county = qsearchs('cust_main_county',{'taxnum'=>$taxnum})
6   or die ("Unknown taxnum!");
7
8 my @expansion;
9 if ( $cgi->param('delim') eq 'n' ) {
10   @expansion=split(/\n/,$cgi->param('expansion'));
11 } elsif ( $cgi->param('delim') eq 's' ) {
12   @expansion=split(' ',$cgi->param('expansion'));
13 } else {
14   die "Illegal delim!";
15 }
16
17 @expansion=map {
18   unless ( /^\s*([\w\- ]+)\s*$/ ) {
19     $cgi->param('error', "Illegal item in expansion");
20     print $cgi->redirect(popurl(2). "cust_main_county-expand.cgi?". $cgi->query_string );
21     myexit();
22   }
23   $1;
24 } @expansion;
25
26 foreach ( @expansion) {
27   my(%hash)=$cust_main_county->hash;
28   my($new)=new FS::cust_main_county \%hash;
29   $new->setfield('taxnum','');
30   if ( ! $cust_main_county->state ) {
31     $new->setfield('state',$_);
32   } else {
33     $new->setfield('county',$_);
34   }
35   #if (datasrc =~ m/Pg/)
36   #{
37   #    $new->setfield('tax',0.0);
38   #}
39   my($error)=$new->insert;
40   die $error if $error;
41 }
42
43 unless ( qsearch( 'cust_main', {
44                                  'state'  => $cust_main_county->state,
45                                  'county' => $cust_main_county->county,
46                                  'country' =>  $cust_main_county->country,
47                                } )
48          || ! @expansion
49 ) {
50   my($error)=($cust_main_county->delete);
51   die $error if $error;
52 }
53
54 print $cgi->redirect(popurl(3). "browse/cust_main_county.cgi");
55
56 %>