4 # $Id: signup.cgi,v 1.53 2004-11-22 18:20:21 ivan Exp $
7 use vars qw( @payby $cgi $locales $packages
11 $last $first $ss $company $address1
12 $address2 $city $state $county
13 $country $zip $daytime $night $fax
15 $ship_last $ship_first $ship_ss $ship_company $ship_address1
16 $ship_address2 $ship_city $ship_state $ship_county
17 $ship_country $ship_zip $ship_daytime $ship_night $ship_fax
19 $invoicing_list $payby $payinfo
20 $paycvv $paydate $payname $referral_custnum $init_popstate
21 $pkgpart $username $password $password2 $sec_phrase $popnum
23 $ieak_file $ieak_template
24 $signup_html $signup_template
25 $success_html $success_template
26 $decline_html $decline_template
31 use subs qw( print_form print_okay print_decline
32 success_default decline_default
35 #use CGI::Carp qw(fatalsToBrowser);
37 use Business::CreditCard;
38 use HTTP::BrowserDetect;
39 use FS::SelfService qw( signup_info new_customer expselect );
41 #acceptable payment methods
43 #@payby = qw( CARD BILL COMP );
44 #@payby = qw( CARD BILL );
46 @payby = qw( CARD PREPAY );
48 $ieak_file = '/usr/local/freeside/ieak.template';
49 $signup_html = -e 'signup.html'
51 : '/usr/local/freeside/signup.html';
52 $success_html = -e 'success.html'
54 : '/usr/local/freeside/success.html';
55 $decline_html = -e 'decline.html'
57 : '/usr/local/freeside/decline.html';
60 if ( -e $ieak_file ) {
61 my $ieak_txt = Text::Template::_load_text($ieak_file)
62 or die $Text::Template::ERROR;
63 $ieak_txt =~ /^(.*)$/s; #untaint the template source - it's trusted
65 $ieak_txt =~ s/\r//g; # don't double \r on old templates
66 $ieak_txt =~ s/\n/\r\n/g;
67 $ieak_template = new Text::Template ( TYPE => 'STRING', SOURCE => $ieak_txt )
68 or die $Text::Template::ERROR;
74 if ( -e $signup_html ) {
75 my $signup_txt = Text::Template::_load_text($signup_html)
76 or die $Text::Template::ERROR;
77 $signup_txt =~ /^(.*)$/s; #untaint the template source - it's trusted
79 $signup_template = new Text::Template ( TYPE => 'STRING',
80 SOURCE => $signup_txt,
81 DELIMITERS => [ '<%=', '%>' ]
83 or die $Text::Template::ERROR;
85 /<\s*INPUT TYPE="?hidden"?\s+NAME="?agentnum"?\s+VALUE="?(\d+)"?\s*>/si
90 #too much maintenance hassle to keep in this file
91 die "can't find ./signup.html or /usr/local/freeside/signup.html";
92 #$signup_template = new Text::Template ( TYPE => 'STRING',
93 # SOURCE => &signup_default,
94 # DELIMITERS => [ '<%=', '%>' ]
96 # or die $Text::Template::ERROR;
99 if ( -e $success_html ) {
100 my $success_txt = Text::Template::_load_text($success_html)
101 or die $Text::Template::ERROR;
102 $success_txt =~ /^(.*)$/s; #untaint the template source - it's trusted
104 $success_template = new Text::Template ( TYPE => 'STRING',
105 SOURCE => $success_txt,
106 DELIMITERS => [ '<%=', '%>' ],
108 or die $Text::Template::ERROR;
110 $success_template = new Text::Template ( TYPE => 'STRING',
111 SOURCE => &success_default,
112 DELIMITERS => [ '<%=', '%>' ],
114 or die $Text::Template::ERROR;
117 if ( -e $decline_html ) {
118 my $decline_txt = Text::Template::_load_text($decline_html)
119 or die $Text::Template::ERROR;
120 $decline_txt =~ /^(.*)$/s; #untaint the template source - it's trusted
122 $decline_template = new Text::Template ( TYPE => 'STRING',
123 SOURCE => $decline_txt,
124 DELIMITERS => [ '<%=', '%>' ],
126 or die $Text::Template::ERROR;
128 $decline_template = new Text::Template ( TYPE => 'STRING',
129 SOURCE => &decline_default,
130 DELIMITERS => [ '<%=', '%>' ],
132 or die $Text::Template::ERROR;
137 $init_data = signup_info( 'promo_code' => $cgi->param('promo_code') );
138 $error = $init_data->{'error'};
139 $locales = $init_data->{'cust_main_county'};
140 $packages = $init_data->{'part_pkg'};
141 $pops = $init_data->{'svc_acct_pop'};
142 @payby = @{$init_data->{'payby'}} if @{$init_data->{'payby'}};
143 $packages = $init_data->{agentnum2part_pkg}{$agentnum} if $agentnum;
147 push @{ $pop{ $_->{state} }->{ $_->{ac} } }, $_;
148 $popnum2pop{$_->{popnum}} = $_;
151 if ( defined $cgi->param('magic') ) {
152 if ( $cgi->param('magic') eq 'process' ) {
154 if ( $cgi->param('state') =~ /^(\w*)( \(([\w ]+)\))? ?\/ ?(\w+)$/ ) {
158 } elsif ( $cgi->param('state') =~ /^(\w*)$/ ) {
160 $cgi->param('county') =~ /^([\w ]*)$/
161 or die "illegal county: ". $cgi->param('county');
163 $cgi->param('country') =~ /^(\w+)$/
164 or die "illegal country: ". $cgi->param('country');
167 die "illegal state: ". $cgi->param('state');
170 $payby = $cgi->param('payby');
171 if ( $payby eq 'CHEK' || $payby eq 'DCHK' ) {
172 #$payinfo = join('@', map { $cgi->param( $payby. "_payinfo$_" ) } (1,2) );
173 $payinfo = $cgi->param($payby. '_payinfo1'). '@'.
174 $cgi->param($payby. '_payinfo2');
176 $payinfo = $cgi->param( $payby. '_payinfo' );
179 $cgi->param( $payby. '_month' ). '-'. $cgi->param( $payby. '_year' );
180 $payname = $cgi->param( $payby. '_payname' );
181 $paycvv = defined $cgi->param( $payby. '_paycvv' )
182 ? $cgi->param( $payby. '_paycvv' )
185 if ( $invoicing_list = $cgi->param('invoicing_list') ) {
186 $invoicing_list .= ', POST' if $cgi->param('invoicing_list_POST');
188 $invoicing_list = 'POST';
193 $last = $cgi->param('last');
194 $first = $cgi->param('first');
195 $ss = $cgi->param('ss');
196 $company = $cgi->param('company');
197 $address1 = $cgi->param('address1');
198 $address2 = $cgi->param('address2');
199 $city = $cgi->param('city');
202 $zip = $cgi->param('zip');
204 $daytime = $cgi->param('daytime');
205 $night = $cgi->param('night');
206 $fax = $cgi->param('fax');
208 $ship_last = $cgi->param('ship_last');
209 $ship_first = $cgi->param('ship_first');
210 $ship_ss = $cgi->param('ship_ss');
211 $ship_company = $cgi->param('ship_company');
212 $ship_address1 = $cgi->param('ship_address1');
213 $ship_address2 = $cgi->param('ship_address2');
214 $ship_city = $cgi->param('ship_city');
217 $ship_zip = $cgi->param('ship_zip');
219 $ship_daytime = $cgi->param('ship_daytime');
220 $ship_night = $cgi->param('ship_night');
221 $ship_fax = $cgi->param('ship_fax');
228 $referral_custnum = $cgi->param('ref');
229 $pkgpart = $cgi->param('pkgpart');
230 $username = $cgi->param('username');
231 $sec_phrase = $cgi->param('sec_phrase');
232 $password = $cgi->param('_password');
233 $popnum = $cgi->param('popnum');
234 #$agentnum, # = $cgi->param('agentnum'),
235 $agentnum ||= $cgi->param('agentnum');
236 $init_popstate = $cgi->param('init_popstate');
237 $refnum = $cgi->param('refnum');
239 if ( $cgi->param('_password') ne $cgi->param('_password2') ) {
240 $error = $init_data->{msgcat}{passwords_dont_match}; #msgcat
244 $password2 = $cgi->param('_password2');
246 if ( $payby =~ /^(CARD|DCRD)$/ && $cgi->param('CARD_type') ) {
249 $payinfo =~ /^(\d{13,16})$/
250 or $error ||= $init_data->{msgcat}{invalid_card}; #. $self->payinfo;
253 or $error ||= $init_data->{msgcat}{invalid_card}; #. $self->payinfo;
254 cardtype($payinfo) eq $cgi->param('CARD_type')
255 or $error ||= $init_data->{msgcat}{not_a}. $cgi->param('CARD_type');
260 my $r = new_customer ( {
264 'company' => $company,
265 'address1' => $address1,
266 'address2' => $address2,
271 'country' => $country,
272 'daytime' => $daytime,
275 'ship_last' => $ship_last,
276 'ship_first' => $ship_first,
277 'ship_company' => $ship_company,
278 'ship_address1' => $ship_address1,
279 'ship_address2' => $ship_address2,
280 'ship_city' => $ship_city,
281 'ship_county' => $ship_county,
282 'ship_state' => $ship_state,
283 'ship_zip' => $ship_zip,
284 'ship_country' => $ship_country,
285 'ship_daytime' => $ship_daytime,
286 'ship_night' => $ship_night,
287 'ship_fax' => $ship_fax,
289 'payinfo' => $payinfo,
291 'paydate' => $paydate,
292 'payname' => $payname,
293 'invoicing_list' => $invoicing_list,
294 'referral_custnum' => $referral_custnum,
295 'promo_code' => $cgi->param('promo_code'),
296 'pkgpart' => $pkgpart,
297 'username' => $username,
298 'sec_phrase' => $sec_phrase,
299 '_password' => $password,
301 'agentnum' => $agentnum,
303 map { $_ => $cgi->param($_) } grep { /^snarf_/ } $cgi->param
305 $error ||= $r->{'error'};
311 if ( $error eq '_decline' ) {
314 #fudge the snarf info
316 ${$_} = $cgi->param($_) foreach grep { /^snarf_/ } $cgi->param;
323 die "unrecognized magic: ". $cgi->param('magic');
334 $state = $init_data->{statedefault};
336 $country = $init_data->{countrydefault};
347 $ship_state = $init_data->{statedefault};
349 $ship_country = $init_data->{countrydefault};
354 $invoicing_list = '';
365 $referral_custnum = $cgi->param('ref') || '';
366 $init_popstate = $cgi->param('init_popstate') || '';
367 $refnum = $init_data->{'refnum'};
374 $cgi->delete('init_popstate');
375 $self_url = $cgi->self_url;
377 $error = "Error: $error" if $error;
379 print $cgi->header( '-expires' => 'now' ),
380 $signup_template->fill_in();
385 print $cgi->header( '-expires' => 'now' ),
386 $decline_template->fill_in();
390 my $user_agent = new HTTP::BrowserDetect $ENV{HTTP_USER_AGENT};
392 $cgi->param('username') =~ /^(.+)$/
393 or die "fatal: invalid username got past FS::SelfService::new_customer";
395 $cgi->param('_password') =~ /^(.+)$/
396 or die "fatal: invalid password got past FS::SelfService::new_customer";
398 ( $cgi->param('first'). ' '. $cgi->param('last') ) =~ /^(.*)$/
399 or die "fatal: invalid email_name got past FS::SelfService::new_customer";
400 $email_name = $1; #global for template
402 my $pop = $popnum2pop{$cgi->param('popnum')};
403 #or die "fatal: invalid popnum got past FS::SelfService::new_customer";
405 ( $ac, $exch, $loc ) = ( $pop->{'ac'}, $pop->{'exch'}, $pop->{'loc'} );
407 ( $ac, $exch, $loc ) = ( '', '', ''); #presumably you're not using them.
411 $pkg = ( grep { $_->{'pkgpart'} eq $pkgpart } @$packages )[0]->{'pkg'};
413 if ( $ieak_template && $user_agent->windows && $user_agent->ie ) {
415 print $cgi->header('application/x-Internet-signup'),
416 $ieak_template->fill_in();
417 } else { #send a simple confirmation
418 print $cgi->header( '-expires' => 'now' ),
419 $success_template->fill_in();
423 sub success_default { #html to use if you don't specify a success file
425 <HTML><HEAD><TITLE>Signup successful</TITLE></HEAD>
426 <BODY BGCOLOR="#e8e8e8"><FONT SIZE=7>Signup successful</FONT><BR><BR>
427 Thanks for signing up!
429 Signup information for <%= $email_name %>:
431 Username: <%= $username %><BR>
432 Password: <%= $password %><BR>
433 Access number: (<%= $ac %>) / <%= $exch %> - <%= $local %><BR>
434 Package: <%= $pkg %><BR>
439 sub decline_default { #html to use if there is a decline
441 <HTML><HEAD><TITLE>Processing error</TITLE></HEAD>
442 <BODY BGCOLOR="#e8e8e8"><FONT SIZE=7>Processing error</FONT><BR><BR>
443 There has been an error processing your account. Please contact customer
449 # subs for the templates...
451 =item regionselector SELECTED_COUNTY, SELECTED_STATE, SELECTED_COUNTRY, PREFIX, ONCHANGE
456 my ( $selected_county, $selected_state, $selected_country,
457 $prefix, $onchange ) = @_;
458 signup_info() unless $init_data;
459 FS::SelfService::regionselector({
460 selected_county => $selected_county,
461 selected_state => $selected_state,
462 selected_country => $selected_country,
464 onchange => $onchange,
465 default_country => $init_data->{countrydefault},
466 locales => $init_data->{cust_main_county},
468 #default_state => $init_data->{statedefault},
477 signup_info() unless $init_data;
478 FS::SelfService::popselector({
480 pops => $init_data->{svc_acct_pop},