changes to track email addresses for email invoicing
[freeside.git] / htdocs / edit / process / cust_main.cgi
1 #!/usr/bin/perl -Tw
2 #
3 # $Id: cust_main.cgi,v 1.4 1999-01-18 09:22:32 ivan Exp $
4 #
5 # Usage: post form to:
6 #        http://server.name/path/cust_main.cgi
7 #
8 # Note: Should be run setuid root as user nobody.
9 #
10 # ivan@voicenet.com 96-dec-04
11 #
12 # added referral check
13 # ivan@voicenet.com 97-jun-4
14 #
15 # rewrote for new API
16 # ivan@voicenet.com 97-jul-28
17 #
18 # same as above (again) and clean up some stuff ivan@sisd.com 98-feb-23
19 #
20 # Changes to allow page to work at a relative position in server
21 # Changed 'day' to 'daytime' because Pg6.3 reserves the day word
22 #       bmccane@maxbaud.net     98-apr-3
23 #
24 # $Log: cust_main.cgi,v $
25 # Revision 1.4  1999-01-18 09:22:32  ivan
26 # changes to track email addresses for email invoicing
27 #
28 # Revision 1.3  1998/12/17 08:40:19  ivan
29 # s/CGI::Request/CGI.pm/; etc
30 #
31 # Revision 1.2  1998/11/18 08:57:36  ivan
32 # i18n, s/CGI-modules/CGI.pm/, FS::CGI::idiot instead of inline, FS::CGI::popurl
33 #
34
35 use strict;
36 #use CGI;
37 use CGI;
38 use CGI::Carp qw(fatalsToBrowser);
39 use FS::UID qw(cgisuidsetup getotaker);
40 use FS::CGI qw(eidiot popurl);
41 use FS::Record qw(qsearchs fields);
42 use FS::cust_main;
43
44 my($cgi)=new CGI;
45 &cgisuidsetup($cgi);
46
47 #unmunge stuff
48
49 $cgi->param('agentnum', (split(/:/, ($cgi->param('agentnum'))[0] ))[0] );
50
51 $cgi->param('tax','') unless defined($cgi->param('tax'));
52
53 $cgi->param('refnum', (split(/:/, ($cgi->param('refnum'))[0] ))[0] );
54
55 $cgi->param('state') =~ /^(\w+)( \((\w+)\))? \/ (\w+)$/;
56 $cgi->param('state', $1);
57 $cgi->param('county', $3 || '');
58 $cgi->param('country', $4);
59
60 my $payby = $cgi->param('payby');
61 $cgi->param('payinfo', $cgi->param( $payby. '_payinfo' ) );
62 $cgi->param('paydate',
63   $cgi->param( $payby. '_month' ). '-'. $cgi->param( $payby. '_year' ) );
64 $cgi->param('payname', $cgi->param( $payby. '_payname' ) );
65
66 $cgi->param('otaker', &getotaker );
67
68 my @invoicing_list = split( /\s*\,\s*/, $cgi->param('invoicing_list') );
69 push @invoicing_list, 'POST' if $cgi->param('invoicing_list_POST');
70
71 #create new record object
72
73 my($new) = new FS::cust_main ( {
74   map {
75     $_, scalar($cgi->param($_))
76 #  } qw(custnum agentnum last first ss company address1 address2 city county
77 #       state zip daytime night fax payby payinfo paydate payname tax
78 #       otaker refnum)
79   } fields('cust_main')
80 } );
81
82 #perhaps the invocing_list magic should move to cust_main.pm?
83 if ( $new->custnum eq '' ) {
84   my $error;
85   $error = $new->check_invoicing_list( \@invoicing_list );
86   &ediot($error) if $error;
87   $error = $new->insert;
88   &eidiot($error) if $error;
89   $new->invoicing_list( \@invoicing_list );
90 } else { #create old record object
91   my $error;
92   my $old = qsearchs( 'cust_main', { 'custnum' => $new->custnum } ); 
93   &eidiot("Old record not found!") unless $old;
94   $error = $new->check_invoicing_list( \@invoicing_list );
95   &eidiot($error) if $error;
96   $error = $new->replace($old);
97   &eidiot($error) if $error;
98   $new->invoicing_list( \@invoicing_list );
99 }
100
101 my $custnum = $new->custnum;
102 print $cgi->redirect(popurl(3). "view/cust_main.cgi?$custnum#cust_main");
103