850f2add4b92fb7917f0edd3b8cac0aec783540e
[freeside.git] / htdocs / edit / process / cust_main.cgi
1 #!/usr/bin/perl -Tw
2 #
3 # $Id: cust_main.cgi,v 1.5 1999-01-19 05:13:50 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.5  1999-01-19 05:13:50  ivan
26 # for mod_perl: no more top-level my() variables; use vars instead
27 # also the last s/create/new/;
28 #
29 # Revision 1.4  1999/01/18 09:22:32  ivan
30 # changes to track email addresses for email invoicing
31 #
32 # Revision 1.3  1998/12/17 08:40:19  ivan
33 # s/CGI::Request/CGI.pm/; etc
34 #
35 # Revision 1.2  1998/11/18 08:57:36  ivan
36 # i18n, s/CGI-modules/CGI.pm/, FS::CGI::idiot instead of inline, FS::CGI::popurl
37 #
38
39 use strict;
40 use vars qw( $cgi $payby @invoicing_list $new $custnum );
41 use CGI;
42 use CGI::Carp qw(fatalsToBrowser);
43 use FS::UID qw(cgisuidsetup getotaker);
44 use FS::CGI qw(eidiot popurl);
45 use FS::Record qw(qsearchs fields);
46 use FS::cust_main;
47
48 $cgi = new CGI;
49 &cgisuidsetup($cgi);
50
51 #unmunge stuff
52
53 $cgi->param('agentnum', (split(/:/, ($cgi->param('agentnum'))[0] ))[0] );
54
55 $cgi->param('tax','') unless defined($cgi->param('tax'));
56
57 $cgi->param('refnum', (split(/:/, ($cgi->param('refnum'))[0] ))[0] );
58
59 $cgi->param('state') =~ /^(\w+)( \((\w+)\))? \/ (\w+)$/;
60 $cgi->param('state', $1);
61 $cgi->param('county', $3 || '');
62 $cgi->param('country', $4);
63
64 $payby = $cgi->param('payby');
65 $cgi->param('payinfo', $cgi->param( $payby. '_payinfo' ) );
66 $cgi->param('paydate',
67   $cgi->param( $payby. '_month' ). '-'. $cgi->param( $payby. '_year' ) );
68 $cgi->param('payname', $cgi->param( $payby. '_payname' ) );
69
70 $cgi->param('otaker', &getotaker );
71
72 @invoicing_list = split( /\s*\,\s*/, $cgi->param('invoicing_list') );
73 push @invoicing_list, 'POST' if $cgi->param('invoicing_list_POST');
74
75 #create new record object
76
77 $new = new FS::cust_main ( {
78   map {
79     $_, scalar($cgi->param($_))
80 #  } qw(custnum agentnum last first ss company address1 address2 city county
81 #       state zip daytime night fax payby payinfo paydate payname tax
82 #       otaker refnum)
83   } fields('cust_main')
84 } );
85
86 #perhaps the invocing_list magic should move to cust_main.pm?
87 if ( $new->custnum eq '' ) {
88   my $error;
89   $error = $new->check_invoicing_list( \@invoicing_list );
90   &ediot($error) if $error;
91   $error = $new->insert;
92   &eidiot($error) if $error;
93   $new->invoicing_list( \@invoicing_list );
94 } else { #create old record object
95   my $error;
96   my $old = qsearchs( 'cust_main', { 'custnum' => $new->custnum } ); 
97   &eidiot("Old record not found!") unless $old;
98   $error = $new->check_invoicing_list( \@invoicing_list );
99   &eidiot($error) if $error;
100   $error = $new->replace($old);
101   &eidiot($error) if $error;
102   $new->invoicing_list( \@invoicing_list );
103 }
104
105 $custnum = $new->custnum;
106 print $cgi->redirect(popurl(3). "view/cust_main.cgi?$custnum#cust_main");
107