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