b7c4547f695843d15afc473f67052600fccb3069
[freeside.git] / httemplate / edit / process / cust_main_county-expand.cgi
1 <%
2 #
3 # $Id: cust_main_county-expand.cgi,v 1.1 2001-07-30 07:36:04 ivan Exp $
4 #
5 # ivan@sisd.com 97-dec-16
6 #
7 # Changes to allow page to work at a relative position in server
8 # Added import of datasrc from UID.pm for Pg6.3
9 # Default tax to 0.0 if using Pg6.3
10 #       bmccane@maxbaud.net     98-apr-3
11 #
12 # lose background, FS::CGI
13 # undo default tax to 0.0 if using Pg6.3: comes from pre-expanded record
14 # for that state
15 # ivan@sisd.com 98-sep-2
16 #
17 # $Log: cust_main_county-expand.cgi,v $
18 # Revision 1.1  2001-07-30 07:36:04  ivan
19 # templates!!!
20 #
21 # Revision 1.7  2000/12/21 05:22:30  ivan
22 # perldoc -f split
23 #
24 # Revision 1.6  1999/01/25 12:19:07  ivan
25 # yet more mod_perl stuff
26 #
27 # Revision 1.5  1999/01/19 05:13:51  ivan
28 # for mod_perl: no more top-level my() variables; use vars instead
29 # also the last s/create/new/;
30 #
31 # Revision 1.4  1999/01/18 22:47:52  ivan
32 # s/create/new/g; and use fields('table_name')
33 #
34 # Revision 1.3  1998/12/17 08:40:20  ivan
35 # s/CGI::Request/CGI.pm/; etc
36 #
37 # Revision 1.2  1998/11/18 09:01:40  ivan
38 # i18n! i18n!
39 #
40
41 use strict;
42 use vars qw ( $cgi $taxnum $cust_main_county @expansion $expansion );
43 use CGI;
44 use CGI::Carp qw(fatalsToBrowser);
45 use FS::UID qw(cgisuidsetup datasrc);
46 use FS::Record qw(qsearch qsearchs);
47 use FS::CGI qw(popurl);
48 use FS::cust_main_county;
49 use FS::cust_main;
50
51 $cgi = new CGI;
52 &cgisuidsetup($cgi);
53
54 $cgi->param('taxnum') =~ /^(\d+)$/ or die "Illegal taxnum!";
55 $taxnum = $1;
56 $cust_main_county = qsearchs('cust_main_county',{'taxnum'=>$taxnum})
57   or die ("Unknown taxnum!");
58
59 if ( $cgi->param('delim') eq 'n' ) {
60   @expansion=split(/\n/,$cgi->param('expansion'));
61 } elsif ( $cgi->param('delim') eq 's' ) {
62   @expansion=split(' ',$cgi->param('expansion'));
63 } else {
64   die "Illegal delim!";
65 }
66
67 @expansion=map {
68   unless ( /^\s*([\w\- ]+)\s*$/ ) {
69     $cgi->param('error', "Illegal item in expansion");
70     print $cgi->redirect(popurl(2). "cust_main_county-expand.cgi?". $cgi->query_string );
71     exit;
72   }
73   $1;
74 } @expansion;
75
76 foreach ( @expansion) {
77   my(%hash)=$cust_main_county->hash;
78   my($new)=new FS::cust_main_county \%hash;
79   $new->setfield('taxnum','');
80   if ( ! $cust_main_county->state ) {
81     $new->setfield('state',$_);
82   } else {
83     $new->setfield('county',$_);
84   }
85   #if (datasrc =~ m/Pg/)
86   #{
87   #    $new->setfield('tax',0.0);
88   #}
89   my($error)=$new->insert;
90   die $error if $error;
91 }
92
93 unless ( qsearch('cust_main',{
94   'state'  => $cust_main_county->getfield('state'),
95   'county' => $cust_main_county->getfield('county'),
96   'country' =>  $cust_main_county->getfield('country'),
97 } ) ) {
98   my($error)=($cust_main_county->delete);
99   die $error if $error;
100 }
101
102 print $cgi->redirect(popurl(3). "edit/cust_main_county.cgi");
103
104 %>