4 # $Id: signup.cgi,v 1.54 2004-12-01 18:38:22 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');
169 if ( $cgi->param('ship_state') =~ /^(\w*)( \(([\w ]+)\))? ?\/ ?(\w+)$/ ) {
171 $ship_county = $3 || '';
173 } elsif ( $cgi->param('ship_state') =~ /^(\w*)$/ ) {
175 $cgi->param('ship_county') =~ /^([\w ]*)$/
176 or die "illegal county: ". $cgi->param('ship_county');
178 $cgi->param('ship_country') =~ /^(\w+)$/
179 or die "illegal ship_country: ". $cgi->param('ship_country');
182 # die "illegal ship_state: ". $cgi->param('ship_state');
185 $payby = $cgi->param('payby');
186 if ( $payby eq 'CHEK' || $payby eq 'DCHK' ) {
187 #$payinfo = join('@', map { $cgi->param( $payby. "_payinfo$_" ) } (1,2) );
188 $payinfo = $cgi->param($payby. '_payinfo1'). '@'.
189 $cgi->param($payby. '_payinfo2');
191 $payinfo = $cgi->param( $payby. '_payinfo' );
194 $cgi->param( $payby. '_month' ). '-'. $cgi->param( $payby. '_year' );
195 $payname = $cgi->param( $payby. '_payname' );
196 $paycvv = defined $cgi->param( $payby. '_paycvv' )
197 ? $cgi->param( $payby. '_paycvv' )
200 if ( $invoicing_list = $cgi->param('invoicing_list') ) {
201 $invoicing_list .= ', POST' if $cgi->param('invoicing_list_POST');
203 $invoicing_list = 'POST';
208 $last = $cgi->param('last');
209 $first = $cgi->param('first');
210 $ss = $cgi->param('ss');
211 $company = $cgi->param('company');
212 $address1 = $cgi->param('address1');
213 $address2 = $cgi->param('address2');
214 $city = $cgi->param('city');
217 $zip = $cgi->param('zip');
219 $daytime = $cgi->param('daytime');
220 $night = $cgi->param('night');
221 $fax = $cgi->param('fax');
223 $ship_last = $cgi->param('ship_last');
224 $ship_first = $cgi->param('ship_first');
225 $ship_ss = $cgi->param('ship_ss');
226 $ship_company = $cgi->param('ship_company');
227 $ship_address1 = $cgi->param('ship_address1');
228 $ship_address2 = $cgi->param('ship_address2');
229 $ship_city = $cgi->param('ship_city');
232 $ship_zip = $cgi->param('ship_zip');
234 $ship_daytime = $cgi->param('ship_daytime');
235 $ship_night = $cgi->param('ship_night');
236 $ship_fax = $cgi->param('ship_fax');
243 $referral_custnum = $cgi->param('ref');
244 $pkgpart = $cgi->param('pkgpart');
245 $username = $cgi->param('username');
246 $sec_phrase = $cgi->param('sec_phrase');
247 $password = $cgi->param('_password');
248 $popnum = $cgi->param('popnum');
249 #$agentnum, # = $cgi->param('agentnum'),
250 $agentnum ||= $cgi->param('agentnum');
251 $init_popstate = $cgi->param('init_popstate');
252 $refnum = $cgi->param('refnum');
254 if ( $cgi->param('_password') ne $cgi->param('_password2') ) {
255 $error = $init_data->{msgcat}{passwords_dont_match}; #msgcat
259 $password2 = $cgi->param('_password2');
261 if ( $payby =~ /^(CARD|DCRD)$/ && $cgi->param('CARD_type') ) {
264 $payinfo =~ /^(\d{13,16})$/
265 or $error ||= $init_data->{msgcat}{invalid_card}; #. $self->payinfo;
268 or $error ||= $init_data->{msgcat}{invalid_card}; #. $self->payinfo;
269 cardtype($payinfo) eq $cgi->param('CARD_type')
270 or $error ||= $init_data->{msgcat}{not_a}. $cgi->param('CARD_type');
275 my $r = new_customer ( {
279 'company' => $company,
280 'address1' => $address1,
281 'address2' => $address2,
286 'country' => $country,
287 'daytime' => $daytime,
290 'ship_last' => $ship_last,
291 'ship_first' => $ship_first,
292 'ship_company' => $ship_company,
293 'ship_address1' => $ship_address1,
294 'ship_address2' => $ship_address2,
295 'ship_city' => $ship_city,
296 'ship_county' => $ship_county,
297 'ship_state' => $ship_state,
298 'ship_zip' => $ship_zip,
299 'ship_country' => $ship_country,
300 'ship_daytime' => $ship_daytime,
301 'ship_night' => $ship_night,
302 'ship_fax' => $ship_fax,
304 'payinfo' => $payinfo,
306 'paydate' => $paydate,
307 'payname' => $payname,
308 'invoicing_list' => $invoicing_list,
309 'referral_custnum' => $referral_custnum,
310 'promo_code' => $cgi->param('promo_code'),
311 'pkgpart' => $pkgpart,
312 'username' => $username,
313 'sec_phrase' => $sec_phrase,
314 '_password' => $password,
316 'agentnum' => $agentnum,
318 map { $_ => $cgi->param($_) } grep { /^snarf_/ } $cgi->param
320 $error ||= $r->{'error'};
326 if ( $error eq '_decline' ) {
329 #fudge the snarf info
331 ${$_} = $cgi->param($_) foreach grep { /^snarf_/ } $cgi->param;
338 die "unrecognized magic: ". $cgi->param('magic');
349 $state = $init_data->{statedefault};
351 $country = $init_data->{countrydefault};
362 $ship_state = $init_data->{statedefault};
364 $ship_country = $init_data->{countrydefault};
369 $invoicing_list = '';
380 $referral_custnum = $cgi->param('ref') || '';
381 $init_popstate = $cgi->param('init_popstate') || '';
382 $refnum = $init_data->{'refnum'};
389 $cgi->delete('init_popstate');
390 $self_url = $cgi->self_url;
392 $error = "Error: $error" if $error;
394 print $cgi->header( '-expires' => 'now' ),
395 $signup_template->fill_in();
400 print $cgi->header( '-expires' => 'now' ),
401 $decline_template->fill_in();
405 my $user_agent = new HTTP::BrowserDetect $ENV{HTTP_USER_AGENT};
407 $cgi->param('username') =~ /^(.+)$/
408 or die "fatal: invalid username got past FS::SelfService::new_customer";
410 $cgi->param('_password') =~ /^(.+)$/
411 or die "fatal: invalid password got past FS::SelfService::new_customer";
413 ( $cgi->param('first'). ' '. $cgi->param('last') ) =~ /^(.*)$/
414 or die "fatal: invalid email_name got past FS::SelfService::new_customer";
415 $email_name = $1; #global for template
417 my $pop = $popnum2pop{$cgi->param('popnum')};
418 #or die "fatal: invalid popnum got past FS::SelfService::new_customer";
420 ( $ac, $exch, $loc ) = ( $pop->{'ac'}, $pop->{'exch'}, $pop->{'loc'} );
422 ( $ac, $exch, $loc ) = ( '', '', ''); #presumably you're not using them.
426 $pkg = ( grep { $_->{'pkgpart'} eq $pkgpart } @$packages )[0]->{'pkg'};
428 if ( $ieak_template && $user_agent->windows && $user_agent->ie ) {
430 print $cgi->header('application/x-Internet-signup'),
431 $ieak_template->fill_in();
432 } else { #send a simple confirmation
433 print $cgi->header( '-expires' => 'now' ),
434 $success_template->fill_in();
438 sub success_default { #html to use if you don't specify a success file
440 <HTML><HEAD><TITLE>Signup successful</TITLE></HEAD>
441 <BODY BGCOLOR="#e8e8e8"><FONT SIZE=7>Signup successful</FONT><BR><BR>
442 Thanks for signing up!
444 Signup information for <%= $email_name %>:
446 Username: <%= $username %><BR>
447 Password: <%= $password %><BR>
448 Access number: (<%= $ac %>) / <%= $exch %> - <%= $local %><BR>
449 Package: <%= $pkg %><BR>
454 sub decline_default { #html to use if there is a decline
456 <HTML><HEAD><TITLE>Processing error</TITLE></HEAD>
457 <BODY BGCOLOR="#e8e8e8"><FONT SIZE=7>Processing error</FONT><BR><BR>
458 There has been an error processing your account. Please contact customer
464 # subs for the templates...
466 =item regionselector SELECTED_COUNTY, SELECTED_STATE, SELECTED_COUNTRY, PREFIX, ONCHANGE
471 my ( $selected_county, $selected_state, $selected_country,
472 $prefix, $onchange ) = @_;
473 signup_info() unless $init_data;
474 FS::SelfService::regionselector({
475 selected_county => $selected_county,
476 selected_state => $selected_state,
477 selected_country => $selected_country,
479 onchange => $onchange,
480 default_country => $init_data->{countrydefault},
481 locales => $init_data->{cust_main_county},
483 #default_state => $init_data->{statedefault},
492 signup_info() unless $init_data;
493 FS::SelfService::popselector({
495 pops => $init_data->{svc_acct_pop},