don't redirect to a GET with sensitive data, RT#26099
[freeside.git] / httemplate / edit / cust_main.cgi
1 <& /elements/header.html,
2       $title,
3       '',
4       ' onUnload="myclose()"' #hmm, in billing.html
5 &>
6
7 <& /elements/error.html &>
8
9 <FORM NAME   = "CustomerForm"
10       METHOD = "POST"
11       ACTION = "<% popurl(1) %>process/cust_main.cgi"
12 >
13
14 <INPUT TYPE="hidden" NAME="custnum"     VALUE="<% $custnum %>">
15 <INPUT TYPE="hidden" NAME="prospectnum" VALUE="<% $prospectnum %>">
16
17 % if ( $custnum ) { 
18   <% mt('Customer #') |h %><B><% $cust_main->display_custnum %></B> - 
19   <B><FONT COLOR="#<% $cust_main->statuscolor %>">
20     <% ucfirst($cust_main->status) %>
21   </FONT></B>
22   <BR><BR>
23 % } 
24
25 %# agent, agent_custid, refnum (advertising source), referral_custnum
26 <& cust_main/top_misc.html, $cust_main, 'custnum' => $custnum  &>
27
28 %# birthdate
29 % if (    $conf->config('national_id-country')
30 %      || $conf->exists('cust_main-enable_birthdate')
31 %      || $conf->exists('cust_main-enable_spouse_birthdate')
32 %      || $conf->exists('cust_main-enable_anniversary_date')
33 %    )
34 % {
35   <BR>
36   <& cust_main/birthdate.html, $cust_main &>
37 % }
38
39 %# contact info
40
41 %  my $same_checked = '';
42 %  my $ship_disabled = '';
43 %  my @ship_style = ();
44 %  unless ( $cust_main->ship_last && $same ne 'Y' ) {
45 %    $same_checked = 'CHECKED';
46 %    $ship_disabled = 'DISABLED';
47 %    push @ship_style, 'background-color:#dddddd';
48 %    foreach (
49 %      qw( last first company address1 address2 city county state zip country
50 %          latitude longitude coord_auto
51 %          daytime night fax mobile )
52 %    ) {
53 %      $cust_main->set("ship_$_", $cust_main->get($_) );
54 %    }
55 %  }
56
57 <BR>
58 <FONT SIZE="+1"><B><% mt('Billing address') |h %></B></FONT>
59
60 <& cust_main/contact.html,
61              'cust_main'    => $cust_main,
62              'pre'          => '',
63              'onchange'     => 'bill_changed(this)',
64              'disabled'     => '',
65              'ss'           => $ss,
66              'stateid'      => $stateid,
67              'same_checked' => $same_checked, #for address2 "Unit #" labeling
68 &>
69
70 <SCRIPT>
71 function bill_changed(what) {
72   if ( what.form.same.checked ) {
73 % for (qw( last first company address1 address2 city zip latitude longitude coord_auto daytime night fax mobile )) { 
74     what.form.ship_<%$_%>.value = what.form.<%$_%>.value;
75 % } 
76
77     what.form.ship_country.selectedIndex = what.form.country.selectedIndex;
78
79     function fix_ship_city() {
80       what.form.ship_city_select.selectedIndex = what.form.city_select.selectedIndex;
81       what.form.ship_city.style.display = what.form.city.style.display;
82       if ( what.form.ship_city_select ) {
83         what.form.ship_city_select.style.display = what.form.city_select.style.display;
84       }
85     }
86
87     function fix_ship_county() {
88       what.form.ship_county.selectedIndex = what.form.county.selectedIndex;
89       ship_county_changed(what.form.ship_county, fix_ship_city );
90     }
91
92     function fix_ship_state() {
93       what.form.ship_state.selectedIndex = what.form.state.selectedIndex;
94       ship_state_changed(what.form.ship_state, fix_ship_county );
95     }
96
97     ship_country_changed(what.form.ship_country, fix_ship_state );
98
99   }
100 }
101 function samechanged(what) {
102   if ( what.checked ) {
103     bill_changed(what);
104
105 %   my @fields = qw( last first company address1 address2 city county state zip country latitude longitude daytime night fax mobile );
106 %   for (@fields) { 
107       what.form.ship_<%$_%>.disabled = true;
108       what.form.ship_<%$_%>.style.backgroundColor = '#dddddd';
109 %   }
110     if ( what.form.ship_city_select ) {
111       what.form.ship_city_select.disabled = true;
112       what.form.ship_city_select.style.backgroundColor = '#dddddd';
113     }
114
115 %   if ( $conf->exists('cust_main-require_address2') ) {
116       document.getElementById('address2_required').style.visibility = '';
117       document.getElementById('address2_label').style.visibility = '';
118       document.getElementById('ship_address2_required').style.visibility = 'hidden';
119       document.getElementById('ship_address2_label').style.visibility = 'hidden';
120 %   }
121
122   } else {
123
124 %   for (@fields) { 
125       what.form.ship_<%$_%>.disabled = false;
126       what.form.ship_<%$_%>.style.backgroundColor = '#ffffff';
127 %   } 
128
129 %   if ( $conf->exists('cust_main-require_address2') ) {
130       document.getElementById('address2_required').style.visibility = 'hidden';
131       document.getElementById('address2_label').style.visibility = 'hidden';
132       document.getElementById('ship_address2_required').style.visibility = '';
133       document.getElementById('ship_address2_label').style.visibility = '';
134 %   }
135
136   }
137 }
138 </SCRIPT>
139
140 <BR>
141 <FONT SIZE="+1"><B><% mt('Service address') |h %></B></FONT>
142
143 (<INPUT TYPE="checkbox" ID="same" NAME="same" VALUE="Y" onClick="samechanged(this)" <%$same_checked%>><% mt('same as billing address') |h %>)
144 <& cust_main/contact.html,
145              'cust_main' => $cust_main,
146              'pre'       => 'ship_',
147              'onchange'  => '',
148              'disabled'  => $ship_disabled,
149              'style'     => \@ship_style
150 &>
151
152 %# billing info
153 <& cust_main/billing.html, $cust_main,
154                'payinfo'        => $payinfo,
155                'invoicing_list' => \@invoicing_list,
156 &>
157
158 % my $ro_comments = $conf->exists('cust_main-use_comments')?'':'readonly';
159 % if (!$ro_comments || $cust_main->comments) {
160
161     <BR><% mt('Comments') |h %> 
162     <% &ntable("#cccccc") %>
163       <TR>
164         <TD>
165           <TEXTAREA NAME = "comments"
166                     COLS = 80
167                     ROWS = 5
168                     WRAP = "HARD"
169                     <% $ro_comments %>
170           ><% $cust_main->comments %></TEXTAREA>
171         </TD>
172       </TR>
173     </TABLE>
174
175 % }
176
177 % unless ( $custnum ) {
178
179     <& cust_main/first_pkg.html, $cust_main,
180                  'pkgpart_svcpart' => $pkgpart_svcpart,
181                  'disable_empty'   =>
182                    scalar( $cgi->param('lock_pkgpart') =~ /^(\d+)$/ ),
183                  'username'        => $username,
184                  'password'        => $password,
185                  'popnum'          => $popnum,
186                  'saved_domsvc'    => $saved_domsvc,
187                  %svc_phone,
188                  %svc_dsl,
189     &>
190
191 % }
192
193 <INPUT TYPE="hidden" NAME="locationnum" VALUE="<% $locationnum %>">
194
195 <INPUT TYPE="hidden" NAME="usernum" VALUE="<% $cust_main->usernum %>">
196
197 %# cust_main/bottomfixup.js
198 % foreach my $hidden (
199 %    'payauto', 'billday',
200 %    'payinfo', 'payinfo1', 'payinfo2', 'payinfo3', 'paytype',
201 %    'payname', 'paystate', 'exp_month', 'exp_year', 'paycvv',
202 %    'paystart_month', 'paystart_year', 'payissue',
203 %    'payip',
204 %    'paid',
205 % ) {
206     <INPUT TYPE="hidden" NAME="<% $hidden %>" VALUE="">
207 % } 
208
209 <& cust_main/bottomfixup.html, 'custnum' => $custnum &>
210
211 <BR>
212 <INPUT TYPE    = "button"
213        NAME    = "submitButton"
214        ID      = "submitButton"
215        VALUE   = "<% $custnum ?  emt("Apply changes") : emt("Add Customer") %>"
216        onClick = "this.disabled=true; bottomfixup(this.form);"
217 >
218 </FORM>
219
220 <& /elements/footer.html &>
221
222 <%init>
223
224 my $curuser = $FS::CurrentUser::CurrentUser;
225
226 #probably redundant given the checks below...
227 die "access denied"
228   unless $curuser->access_right('New customer')
229      ||  $curuser->access_right('Edit customer');
230
231 my $conf = new FS::Conf;
232
233 #get record
234
235 my($custnum, $cust_main, $ss, $stateid, $payinfo, @invoicing_list);
236 my $same = '';
237 my $pkgpart_svcpart = ''; #first_pkg
238 my($username, $password, $popnum, $saved_domsvc) = ( '', '', 0, 0 ); #svc_acct
239 my %svc_phone = ();
240 my %svc_dsl = ();
241 my $prospectnum = '';
242 my $locationnum = '';
243
244 $m->comp('/elements/handle_uri_query', 'secure'=>1);
245
246 if ( $cgi->param('error') ) {
247
248   $cust_main = new FS::cust_main ( {
249     map { $_, scalar($cgi->param($_)) } fields('cust_main')
250   } );
251
252   $custnum = $cust_main->custnum;
253
254   die "access denied"
255     unless $curuser->access_right($custnum ? 'Edit customer' : 'New customer');
256
257   @invoicing_list = split( /\s*,\s*/, $cgi->param('invoicing_list') );
258   $same = $cgi->param('same');
259   $cust_main->setfield('paid' => $cgi->param('paid')) if $cgi->param('paid');
260   $ss = $cust_main->ss;           # don't mask an entered value on errors
261   $stateid = $cust_main->stateid; # don't mask an entered value on errors
262   $payinfo = $cust_main->payinfo; # don't mask an entered value on errors
263
264   $cust_main->national_id( $cgi->param('national_id1') || $cgi->param('national_id2') );
265
266   $prospectnum = $cgi->param('prospectnum') || '';
267
268   $pkgpart_svcpart = $cgi->param('pkgpart_svcpart') || '';
269
270   $locationnum = $cgi->param('locationnum') || '';
271
272   #svc_acct
273   $username = $cgi->param('username');
274   $password = $cgi->param('_password');
275   $popnum = $cgi->param('popnum');
276   $saved_domsvc = $cgi->param('domsvc') || '';
277   if ( $saved_domsvc =~ /^(\d+)$/ ) {
278     $saved_domsvc = $1;
279   } else {
280     $saved_domsvc = '';
281   }
282
283   #svc_phone
284   $svc_phone{$_} = $cgi->param($_)
285     foreach qw( countrycode phonenum sip_password pin phone_name );
286
287   #svc_dsl (phonenum came in with svc_phone)
288   $svc_phone{$_} = $cgi->param($_)
289     foreach qw( password isp_chg isp_prev vendor_qual_id );
290
291 } elsif ( $cgi->keywords ) { #editing
292
293   die "access denied"
294     unless $curuser->access_right('Edit customer');
295
296   my( $query ) = $cgi->keywords;
297   $query =~ /^(\d+)$/;
298   $custnum=$1;
299   $cust_main = qsearchs('cust_main', { 'custnum' => $custnum } )
300     or die "custnum $custnum not found";
301   if ( $cust_main->dbdef_table->column('paycvv')
302        && length($cust_main->paycvv)             ) {
303     my $paycvv = $cust_main->paycvv;
304     $paycvv =~ s/./*/g;
305     $cust_main->paycvv($paycvv);
306   }
307   @invoicing_list = $cust_main->invoicing_list;
308   $ss = $conf->exists('unmask_ss') ? $cust_main->ss : $cust_main->masked('ss');
309   $stateid = $cust_main->masked('stateid');
310   $payinfo = $cust_main->paymask;
311
312 } else { #new customer
313
314   die "access denied"
315     unless $curuser->access_right('New customer');
316
317   $custnum='';
318   $cust_main = new FS::cust_main ( {} );
319   $cust_main->agentnum( $conf->config('default_agentnum') )
320     if $conf->exists('default_agentnum');
321   $cust_main->otaker( &getotaker );
322   $cust_main->referral_custnum( $cgi->param('referral_custnum') );
323   @invoicing_list = ();
324   push @invoicing_list, 'POST'
325     unless $conf->exists('disablepostalinvoicedefault');
326   $ss = '';
327   $stateid = '';
328   $payinfo = '';
329
330   $cgi->param('tagnum', FS::part_tag->default_tags);
331
332   if ( $cgi->param('qualnum') =~ /^(\d+)$/ ) {
333     my $qualnum = $1;
334     my $qual = qsearchs('qual', { 'qualnum' => $qualnum } )
335       or die "unknown qualnum $qualnum";
336
337     my $prospect_main = $qual->cust_or_prospect;
338     $prospectnum = $prospect_main->prospectnum
339       or die "qualification not on a prospect";
340
341     $cust_main->agentnum( $prospect_main->agentnum );
342     $cust_main->company(  $prospect_main->company  );
343
344     #first contact? -> name
345     my @contacts = $prospect_main->contact;
346     my $contact = $contacts[0];
347     $cust_main->first( $contact->first );
348     $cust_main->set( 'last', $contact->get('last') );
349     #contact phone numbers?
350
351     #location -> address  (all prospect quals have location, right?)
352     my $cust_location = $qual->cust_location;
353     $cust_location->dealternize;
354     $cust_main->$_( $cust_location->$_ )
355       foreach qw( address1 address2 city county state zip country latitude longitude coord_auto geocode );
356
357     #locationnum -> package order
358     $locationnum = $qual->locationnum;
359
360     #pkgpart handled by lock_pkgpart below
361
362     #service telephone & vendor_qual_id -> svc_dsl
363     $svc_dsl{$_} = $qual->$_
364       foreach qw( phonenum vendor_qual_id );
365   }
366
367   if ( $cgi->param('lock_pkgpart') =~ /^(\d+)$/ ) {
368     my $pkgpart = $1;
369     my $part_pkg = qsearchs('part_pkg', { 'pkgpart' => $pkgpart } )
370       or die "unknown pkgpart $pkgpart";
371     my $svcpart = $part_pkg->svcpart;
372     $pkgpart_svcpart = $pkgpart.'_'.$svcpart;
373   }
374
375 }
376
377 my %keep = map { $_=>1 } qw( error tagnum lock_agentnum lock_pkgpart );
378 $cgi->delete( grep { !$keep{$_} && $_ !~ /^tax_/ } $cgi->param );
379
380 my $title = $custnum ? 'Edit Customer' : 'Add Customer';
381 $title = mt($title);
382 $title .= ": ". $cust_main->name if $custnum;
383
384 my $r = qq!<font color="#ff0000">*</font>&nbsp;!;
385
386 </%init>