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