i18n, s/CGI-modules/CGI.pm/, FS::CGI::idiot instead of inline, FS::CGI::popurl
[freeside.git] / htdocs / edit / process / cust_main.cgi
1 #!/usr/bin/perl -Tw
2 #
3 # $Id: cust_main.cgi,v 1.2 1998-11-18 08:57:36 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.2  1998-11-18 08:57:36  ivan
26 # i18n, s/CGI-modules/CGI.pm/, FS::CGI::idiot instead of inline, FS::CGI::popurl
27 #
28
29 use strict;
30 use CGI;
31 use CGI::Carp qw(fatalsToBrowser);
32 use FS::UID qw(cgisuidsetup);
33 use FS::CGI qw(eidiot popurl);
34 use FS::Record qw(qsearchs);
35 use FS::cust_main;
36
37 my($req)=new CGI;
38
39 &cgisuidsetup($cgi);
40
41 #create new record object
42
43 #unmunge agentnum
44 $cgi->param('agentnum', 
45   (split(/:/, ($cgi->param('agentnum'))[0] ))[0]
46 );
47
48 #unmunge tax
49 $cgi->param('tax','') unless defined($cgi->param('tax'));
50
51 #unmunge refnum
52 $cgi->param('refnum',
53   (split(/:/, ($cgi->param('refnum'))[0] ))[0]
54 );
55
56 #unmunge state/county/country
57 $cgi->param('state') =~ /^(\w+)( \((\w+)\))? \/ (\w+)$/;
58 $cgi->param('state', $1);
59 $cgi->param('county', $3 || '');
60 $cgi->param('country', $4);
61
62 my($new) = create FS::cust_main ( {
63   map {
64     $_, $cgi->param("$_") || ''
65   } qw(custnum agentnum last first ss company address1 address2 city county
66        state zip daytime night fax payby payinfo paydate payname tax
67        otaker refnum)
68 } );
69
70 if ( $new->custnum eq '' ) {
71
72   my($error)=$new->insert;
73   &eidiot($error) if $error;
74
75 } else { #create old record object
76
77   my($old) = qsearchs( 'cust_main', { 'custnum', $new->custnum } ); 
78   &eidiot("Old record not found!") unless $old;
79   my($error)=$new->replace($old);
80   &eidiot($error) if $error;
81
82 }
83
84 my($custnum)=$new->custnum;
85 print $cgi->redirect(popurl(3). "/view/cust_main.cgi?$custnum#cust_main");
86