This commit was manufactured by cvs2svn to create branch 'freeside_import'.
[freeside.git] / htdocs / edit / process / cust_main.cgi
1 #!/usr/bin/perl -Tw
2 #
3 # process/cust_main.cgi: Edit a customer (process form)
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 use strict;
25 use CGI::Request;
26 use CGI::Carp qw(fatalsToBrowser);
27 use FS::UID qw(cgisuidsetup);
28 use FS::Record qw(qsearchs);
29 use FS::cust_main;
30
31 my($req)=new CGI::Request; # create form object
32
33 &cgisuidsetup($req->cgi);
34
35 #create new record object
36
37 #unmunge agentnum
38 $req->param('agentnum', 
39   (split(/:/, ($req->param('agentnum'))[0] ))[0]
40 );
41
42 #unmunge tax
43 $req->param('tax','') unless defined($req->param('tax'));
44
45 #unmunge refnum
46 $req->param('refnum',
47   (split(/:/, ($req->param('refnum'))[0] ))[0]
48 );
49
50 #unmunge state/county
51 $req->param('state') =~ /^(\w+)( \((\w+)\))?$/;
52 $req->param('state', $1);
53 $req->param('county', $3 || '');
54
55 my($new) = create FS::cust_main ( {
56   map {
57     $_, $req->param("$_") || ''
58   } qw(custnum agentnum last first ss company address1 address2 city county
59        state zip country daytime night fax payby payinfo paydate payname tax
60        otaker refnum)
61 } );
62
63 if ( $new->custnum eq '' ) {
64
65   my($error)=$new->insert;
66   &idiot($error) if $error;
67
68 } else { #create old record object
69
70   my($old) = qsearchs( 'cust_main', { 'custnum', $new->custnum } ); 
71   &idiot("Old record not found!") unless $old;
72   my($error)=$new->replace($old);
73   &idiot($error) if $error;
74
75 }
76
77 my($custnum)=$new->custnum;
78 $req->cgi->redirect("../../view/cust_main.cgi?$custnum#cust_main");
79
80 sub idiot {
81   my($error)=@_;
82   CGI::Base::SendHeaders(); # one guess
83   print <<END;
84 <HTML>
85   <HEAD>
86     <TITLE>Error updating customer information</TITLE>
87   </HEAD>
88   <BODY>
89     <CENTER>
90     <H4>Error updating customer information</H4>
91     </CENTER>
92     Your update did not occur because of the following error:
93     <P><B>$error</B>
94     <P>Hit the <I>Back</I> button in your web browser, correct this mistake, and submit the form again.
95   </BODY>
96 </HTML>
97 END
98
99   exit;
100
101 }
102