5ca93d2891d49b2c9d5a56f3b5a65fc8f1391e9f
[freeside.git] / fs_signup / FS-SignupClient / cgi / signup.cgi
1 #!/usr/bin/perl -Tw
2 #
3 # $Id: signup.cgi,v 1.48 2003-10-25 02:05:44 ivan Exp $
4
5 use strict;
6 use vars qw( @payby $cgi $locales $packages
7              $pops %pop %popnum2pop
8              $init_data $error
9              $last $first $ss $company $address1 $address2 $city $state $county
10              $country $zip $daytime $night $fax $invoicing_list $payby $payinfo
11              $paycvv $paydate $payname $referral_custnum $init_popstate
12              $pkgpart $username $password $password2 $sec_phrase $popnum
13              $agentnum
14              $ieak_file $ieak_template $cck_file $cck_template
15              $signup_html $signup_template
16              $success_html $success_template
17              $decline_html $decline_template
18              $ac $exch $loc
19              $email_name $pkg
20              $self_url
21            );
22 use subs qw( print_form print_okay print_decline
23              success_default decline_default
24              expselect );
25 use CGI;
26 #use CGI::Carp qw(fatalsToBrowser);
27 use Text::Template;
28 use Business::CreditCard;
29 use HTTP::Headers::UserAgent 2.00;
30 use FS::SignupClient 0.03 qw( signup_info new_customer );
31
32 #acceptable payment methods
33 #
34 #@payby = qw( CARD BILL COMP );
35 #@payby = qw( CARD BILL );
36 #@payby = qw( CARD );
37 @payby = qw( CARD PREPAY );
38
39 $ieak_file = '/usr/local/freeside/ieak.template';
40 $cck_file = '/usr/local/freeside/cck.template';
41 $signup_html = -e 'signup.html'
42                  ? 'signup.html'
43                  : '/usr/local/freeside/signup.html';
44 $success_html = -e 'success.html'
45                   ? 'success.html'
46                   : '/usr/local/freeside/success.html';
47 $decline_html = -e 'decline.html'
48                   ? 'decline.html'
49                   : '/usr/local/freeside/decline.html';
50
51
52 if ( -e $ieak_file ) {
53   my $ieak_txt = Text::Template::_load_text($ieak_file)
54     or die $Text::Template::ERROR;
55   $ieak_txt =~ /^(.*)$/s; #untaint the template source - it's trusted
56   $ieak_txt = $1;
57   $ieak_txt =~ s/\r//g; # don't double \r on old templates
58   $ieak_txt =~ s/\n/\r\n/g;
59   $ieak_template = new Text::Template ( TYPE => 'STRING', SOURCE => $ieak_txt )
60     or die $Text::Template::ERROR;
61 } else {
62   $ieak_template = '';
63 }
64
65 if ( -e $cck_file ) {
66   my $cck_txt = Text::Template::_load_text($cck_file)
67     or die $Text::Template::ERROR;
68   $cck_txt =~ /^(.*)$/s; #untaint the template source - it's trusted
69   $cck_txt = $1;
70   $cck_template = new Text::Template ( TYPE => 'STRING', SOURCE => $cck_txt )
71     or die $Text::Template::ERROR;
72 } else {
73   $cck_template = '';
74 }
75
76 $agentnum = '';
77 if ( -e $signup_html ) {
78   my $signup_txt = Text::Template::_load_text($signup_html)
79     or die $Text::Template::ERROR;
80   $signup_txt =~ /^(.*)$/s; #untaint the template source - it's trusted
81   $signup_txt = $1;
82   $signup_template = new Text::Template ( TYPE => 'STRING',
83                                           SOURCE => $signup_txt,
84                                           DELIMITERS => [ '<%=', '%>' ]
85                                         )
86     or die $Text::Template::ERROR;
87   if ( $signup_txt =~
88          /<\s*INPUT TYPE="?hidden"?\s+NAME="?agentnum"?\s+VALUE="?(\d+)"?\s*>/si
89   ) {
90     $agentnum = $1;
91   }
92 } else {
93   #too much maintenance hassle to keep in this file
94   die "can't find ./signup.html or /usr/local/freeside/signup.html";
95   #$signup_template = new Text::Template ( TYPE => 'STRING',
96   #                                        SOURCE => &signup_default,
97   #                                        DELIMITERS => [ '<%=', '%>' ]
98   #                                      )
99   #  or die $Text::Template::ERROR;
100 }
101
102 if ( -e $success_html ) {
103   my $success_txt = Text::Template::_load_text($success_html)
104     or die $Text::Template::ERROR;
105   $success_txt =~ /^(.*)$/s; #untaint the template source - it's trusted
106   $success_txt = $1;
107   $success_template = new Text::Template ( TYPE => 'STRING',
108                                            SOURCE => $success_txt,
109                                            DELIMITERS => [ '<%=', '%>' ],
110                                          )
111     or die $Text::Template::ERROR;
112 } else {
113   $success_template = new Text::Template ( TYPE => 'STRING',
114                                            SOURCE => &success_default,
115                                            DELIMITERS => [ '<%=', '%>' ],
116                                          )
117     or die $Text::Template::ERROR;
118 }
119
120 if ( -e $decline_html ) {
121   my $decline_txt = Text::Template::_load_text($decline_html)
122     or die $Text::Template::ERROR;
123   $decline_txt =~ /^(.*)$/s; #untaint the template source - it's trusted
124   $decline_txt = $1;
125   $decline_template = new Text::Template ( TYPE => 'STRING',
126                                            SOURCE => $decline_txt,
127                                            DELIMITERS => [ '<%=', '%>' ],
128                                          )
129     or die $Text::Template::ERROR;
130 } else {
131   $decline_template = new Text::Template ( TYPE => 'STRING',
132                                            SOURCE => &decline_default,
133                                            DELIMITERS => [ '<%=', '%>' ],
134                                          )
135     or die $Text::Template::ERROR;
136 }
137
138
139 ( $locales, $packages, $pops, $init_data ) = signup_info();
140 @payby = @{$init_data->{'payby'}} if @{$init_data->{'payby'}};
141 $packages = $init_data->{agentnum2part_pkg}{$agentnum} if $agentnum;
142 %pop = ();
143 %popnum2pop = ();
144 foreach (@$pops) {
145   push @{ $pop{ $_->{state} }->{ $_->{ac} } }, $_;
146   $popnum2pop{$_->{popnum}} = $_;
147 }
148
149 $cgi = new CGI;
150
151 if ( defined $cgi->param('magic') ) {
152   if ( $cgi->param('magic') eq 'process' ) {
153
154     if ( $cgi->param('state') =~ /^(\w*)( \(([\w ]+)\))? ?\/ ?(\w+)$/ ) {
155       $state = $1;
156       $county = $3 || '';
157       $country = $4;
158     } elsif ( $cgi->param('state') =~ /^(\w*)$/ ) {
159       $state = $1;
160       $cgi->param('county') =~ /^([\w ]*)$/
161         or die "illegal county: ". $cgi->param('county');
162       $county = $1;
163       $cgi->param('country') =~ /^(\w+)$/
164         or die "illegal country: ". $cgi->param('country');
165       $country = $1;
166     } else {
167       die "illegal state: ". $cgi->param('state');
168     }
169
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');
175     } else {
176       $payinfo = $cgi->param( $payby. '_payinfo' );
177     }
178     $paydate =
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' )
183                 : '';
184
185     if ( $invoicing_list = $cgi->param('invoicing_list') ) {
186       $invoicing_list .= ', POST' if $cgi->param('invoicing_list_POST');
187     } else {
188       $invoicing_list = 'POST';
189     }
190
191     $error = '';
192
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');
200     #$county,
201     #$state,
202     $zip              = $cgi->param('zip');
203     #$country,
204     $daytime          = $cgi->param('daytime');
205     $night            = $cgi->param('night');
206     $fax              = $cgi->param('fax');
207     #$payby,
208     #$payinfo,
209     #$paydate,
210     #$payname,
211     #$invoicing_list,
212     $referral_custnum = $cgi->param('ref');
213     $pkgpart          = $cgi->param('pkgpart');
214     $username         = $cgi->param('username');
215     $sec_phrase       = $cgi->param('sec_phrase');
216     $password         = $cgi->param('_password');
217     $popnum           = $cgi->param('popnum');
218     #$agentnum, #         = $cgi->param('agentnum'),
219     $agentnum         ||= $cgi->param('agentnum');
220     $init_popstate    = $cgi->param('init_popstate');
221
222     if ( $cgi->param('_password') ne $cgi->param('_password2') ) {
223       $error = $init_data->{msgcat}{passwords_dont_match}; #msgcat
224       $password  = '';
225       $password2 = '';
226     } else {
227       $password2 = $cgi->param('_password2');
228
229       if ( $payby =~ /^(CARD|DCRD)$/ && $cgi->param('CARD_type') ) {
230         $payinfo =~ s/\D//g;
231
232         $payinfo =~ /^(\d{13,16})$/
233           or $error ||= $init_data->{msgcat}{invalid_card}; #. $self->payinfo;
234         $payinfo = $1;
235         validate($payinfo)
236           or $error ||= $init_data->{msgcat}{invalid_card}; #. $self->payinfo;
237         cardtype($payinfo) eq $cgi->param('CARD_type')
238           or $error ||= $init_data->{msgcat}{not_a}. $cgi->param('CARD_type');
239       }
240
241       $error ||= new_customer ( {
242         'last'             => $last,
243         'first'            => $first,
244         'ss'               => $ss,
245         'company'          => $company,
246         'address1'         => $address1,
247         'address2'         => $address2,
248         'city'             => $city,
249         'county'           => $county,
250         'state'            => $state,
251         'zip'              => $zip,
252         'country'          => $country,
253         'daytime'          => $daytime,
254         'night'            => $night,
255         'fax'              => $fax,
256         'payby'            => $payby,
257         'payinfo'          => $payinfo,
258         'paycvv'           => $paycvv,
259         'paydate'          => $paydate,
260         'payname'          => $payname,
261         'invoicing_list'   => $invoicing_list,
262         'referral_custnum' => $referral_custnum,
263         'pkgpart'          => $pkgpart,
264         'username'         => $username,
265         'sec_phrase'       => $sec_phrase,
266         '_password'        => $password,
267         'popnum'           => $popnum,
268         'agentnum'         => $agentnum,
269         map { $_ => $cgi->param($_) } grep { /^snarf_/ } $cgi->param
270       } );
271
272     }
273     
274     if ( $error eq '_decline' ) {
275       print_decline();
276     } elsif ( $error ) {
277       #fudge the snarf info
278       no strict 'refs';
279       ${$_} = $cgi->param($_) foreach grep { /^snarf_/ } $cgi->param;
280       print_form();
281     } else {
282       print_okay();
283     }
284
285   } else {
286     die "unrecognized magic: ". $cgi->param('magic');
287   }
288 } else {
289   $error = '';
290   $last = '';
291   $first = '';
292   $ss = '';
293   $company = '';
294   $address1 = '';
295   $address2 = '';
296   $city = '';
297   $state = $init_data->{statedefault};
298   $county = '';
299   $country = $init_data->{countrydefault};
300   $zip = '';
301   $daytime = '';
302   $night = '';
303   $fax = '';
304   $invoicing_list = '';
305   $payby = '';
306   $payinfo = '';
307   $paydate = '';
308   $payname = '';
309   $pkgpart = '';
310   $username = '';
311   $password = '';
312   $password2 = '';
313   $sec_phrase = '';
314   $popnum = '';
315   $referral_custnum = $cgi->param('ref') || '';
316   $init_popstate = $cgi->param('init_popstate') || '';
317   print_form;
318 }
319
320 sub print_form {
321
322   $cgi->delete('ref');
323   $cgi->delete('init_popstate');
324   $self_url = $cgi->self_url;
325
326   $error = "Error: $error" if $error;
327
328   print $cgi->header( '-expires' => 'now' ),
329         $signup_template->fill_in();
330
331 }
332
333 sub print_decline {
334   print $cgi->header( '-expires' => 'now' ),
335         $decline_template->fill_in();
336 }
337
338 sub print_okay {
339   my $user_agent = new HTTP::Headers::UserAgent $ENV{HTTP_USER_AGENT};
340
341   $cgi->param('username') =~ /^(.+)$/
342     or die "fatal: invalid username got past FS::SignupClient::new_customer";
343   my $username = $1;
344   $cgi->param('_password') =~ /^(.+)$/
345     or die "fatal: invalid password got past FS::SignupClient::new_customer";
346   my $password = $1;
347   ( $cgi->param('first'). ' '. $cgi->param('last') ) =~ /^(.*)$/
348     or die "fatal: invalid email_name got past FS::SignupClient::new_customer";
349   $email_name = $1; #global for template
350
351   my $pop = $popnum2pop{$cgi->param('popnum')};
352     #or die "fatal: invalid popnum got past FS::SignupClient::new_customer";
353   if ( $pop ) {
354     ( $ac, $exch, $loc ) = ( $pop->{'ac'}, $pop->{'exch'}, $pop->{'loc'} );
355   } else {
356     ( $ac, $exch, $loc ) = ( '', '', ''); #presumably you're not using them.
357   }
358
359   #global for template
360   $pkg = ( grep { $_->{'pkgpart'} eq $pkgpart } @$packages )[0]->{'pkg'};
361
362   if ( $ieak_template
363        && $user_agent->platform eq 'ia32'
364        && $user_agent->os =~ /^win/
365        && ($user_agent->browser)[0] eq 'IE'
366      )
367   { #send an IEAK config
368     print $cgi->header('application/x-Internet-signup'),
369           $ieak_template->fill_in();
370   } elsif ( $cck_template
371             && $user_agent->platform eq 'ia32'
372             && $user_agent->os =~ /^win/
373             && ($user_agent->browser)[0] eq 'Netscape'
374           )
375   { #send a Netscape config
376     my $cck_data = $cck_template->fill_in();
377     print $cgi->header('application/x-netscape-autoconfigure-dialer-v2'),
378           map {
379             m/(.*)\s+(.*)$/;
380             pack("N", length($1)). $1. pack("N", length($2)). $2;
381           } split(/\n/, $cck_data);
382
383   } else { #send a simple confirmation
384     print $cgi->header( '-expires' => 'now' ),
385           $success_template->fill_in();
386   }
387 }
388
389 #horrible false laziness with FS/FS/svc_acct_pop.pm::popselector
390 sub popselector {
391
392   my( $popnum ) = @_;
393
394   return '<INPUT TYPE="hidden" NAME="popnum" VALUE="">' unless @$pops;
395   return $pops->[0]{city}. ', '. $pops->[0]{state}.
396          ' ('. $pops->[0]{ac}. ')/'. $pops->[0]{exch}. '-'. $pops->[0]{loc}.
397          '<INPUT TYPE="hidden" NAME="popnum" VALUE="'. $pops->[0]{popnum}. '">'
398     if scalar(@$pops) == 1;
399
400   #my %pop = ();
401   #my %popnum2pop = ();
402   #foreach (@$pops) {
403   #  push @{ $pop{ $_->{state} }->{ $_->{ac} } }, $_;
404   #  $popnum2pop{$_->{popnum}} = $_;
405   #}
406
407   my $text = <<END;
408     <SCRIPT>
409     function opt(what,href,text) {
410       var optionName = new Option(text, href, false, false)
411       var length = what.length;
412       what.options[length] = optionName;
413     }
414 END
415
416   if ( $init_popstate ) {
417     $text .= '<INPUT TYPE="hidden" NAME="init_popstate" VALUE="'.
418              $init_popstate. '">';
419   } else {
420     $text .= <<END;
421       function acstate_changed(what) {
422         state = what.options[what.selectedIndex].text;
423         what.form.popac.options.length = 0
424         what.form.popac.options[0] = new Option("Area code", "-1", false, true);
425 END
426   } 
427
428   my @states = $init_popstate ? ( $init_popstate ) : keys %pop;
429   foreach my $state ( sort { $a cmp $b } @states ) {
430     $text .= "\nif ( state == \"$state\" ) {\n" unless $init_popstate;
431
432     foreach my $ac ( sort { $a cmp $b } keys %{ $pop{$state} }) {
433       $text .= "opt(what.form.popac, \"$ac\", \"$ac\");\n";
434       if ($ac eq $cgi->param('popac')) {
435         $text .= "what.form.popac.options[what.form.popac.length-1].selected = true;\n";
436       }
437     }
438     $text .= "}\n" unless $init_popstate;
439   }
440   $text .= "popac_changed(what.form.popac)}\n";
441
442   $text .= <<END;
443   function popac_changed(what) {
444     ac = what.options[what.selectedIndex].text;
445     what.form.popnum.options.length = 0;
446     what.form.popnum.options[0] = new Option("City", "-1", false, true);
447
448 END
449
450   foreach my $state ( @states ) {
451     foreach my $popac ( keys %{ $pop{$state} } ) {
452       $text .= "\nif ( ac == \"$popac\" ) {\n";
453
454       foreach my $pop ( @{$pop{$state}->{$popac}}) {
455         my $o_popnum = $pop->{popnum};
456         my $poptext =  $pop->{city}. ', '. $pop->{state}.
457                        ' ('. $pop->{ac}. ')/'. $pop->{exch}. '-'. $pop->{loc};
458
459         $text .= "opt(what.form.popnum, \"$o_popnum\", \"$poptext\");\n";
460         if ($popnum == $o_popnum) {
461           $text .= "what.form.popnum.options[what.form.popnum.length-1].selected = true;\n";
462         }
463       }
464       $text .= "}\n";
465     }
466   }
467
468
469   $text .= "}\n</SCRIPT>\n";
470
471   $text .=
472     qq!<TABLE CELLPADDING="0"><TR><TD><SELECT NAME="acstate"! .
473     qq!SIZE=1 onChange="acstate_changed(this)"><OPTION VALUE=-1>State!;
474   $text .= "<OPTION" . ($_ eq $cgi->param('acstate') ? " SELECTED" : "") .
475            ">$_" foreach sort { $a cmp $b } @states;
476   $text .= '</SELECT>'; #callback? return 3 html pieces?  #'</TD>';
477
478   $text .=
479     qq!<SELECT NAME="popac" SIZE=1 onChange="popac_changed(this)">!.
480     qq!<OPTION>Area code</SELECT></TR><TR VALIGN="top">!;
481
482   $text .= qq!<TR><TD><SELECT NAME="popnum" SIZE=1 STYLE="width: 20em"><OPTION>City!;
483
484
485   #comment this block to disable initial list polulation
486   my @initial_select = ();
487   if ( scalar( @$pops ) > 100 ) {
488     push @initial_select, $popnum2pop{$popnum} if $popnum2pop{$popnum};
489   } else {
490     @initial_select = @$pops;
491   }
492   foreach my $pop ( sort { $a->{state} cmp $b->{state} } @initial_select ) {
493     $text .= qq!<OPTION VALUE="!. $pop->{popnum}. '"'.
494              ( ( $popnum && $pop->{popnum} == $popnum ) ? ' SELECTED' : '' ). ">".
495              $pop->{city}. ', '. $pop->{state}.
496                ' ('. $pop->{ac}. ')/'. $pop->{exch}. '-'. $pop->{loc};
497   }
498
499   $text .= qq!</SELECT></TD></TR></TABLE>!;
500
501   $text;
502
503 }
504
505 sub expselect {
506   my $prefix = shift;
507   my $date = shift || '';
508   my( $m, $y ) = ( 0, 0 );
509   if ( $date  =~ /^(\d{4})-(\d{2})-\d{2}$/ ) { #PostgreSQL date format
510     ( $m, $y ) = ( $2, $1 );
511   } elsif ( $date =~ /^(\d{1,2})-(\d{1,2}-)?(\d{4}$)/ ) {
512     ( $m, $y ) = ( $1, $3 );
513   }
514   my $return = qq!<SELECT NAME="$prefix!. qq!_month" SIZE="1">!;
515   for ( 1 .. 12 ) {
516     $return .= "<OPTION";
517     $return .= " SELECTED" if $_ == $m;
518     $return .= ">$_";
519   }
520   $return .= qq!</SELECT>/<SELECT NAME="$prefix!. qq!_year" SIZE="1">!;
521   for ( 2001 .. 2037 ) {
522     $return .= "<OPTION";
523     $return .= " SELECTED" if $_ == $y;
524     $return .= ">$_";
525   }
526   $return .= "</SELECT>";
527
528   $return;
529 }
530
531 #false laziness w/FS::cust_main_county
532 sub regionselector {
533   my ( $selected_county, $selected_state, $selected_country,
534        $prefix, $onchange ) = @_;
535
536   $prefix = '' unless defined $prefix;
537
538   my $countyflag = 0;
539
540   my %cust_main_county;
541
542 #  unless ( @cust_main_county ) { #cache 
543     #@cust_main_county = qsearch('cust_main_county', {} );
544     #foreach my $c ( @cust_main_county ) {
545     foreach my $c ( @$locales ) {
546       #$countyflag=1 if $c->county;
547       $countyflag=1 if $c->{county};
548       #push @{$cust_main_county{$c->country}{$c->state}}, $c->county;
549       #$cust_main_county{$c->country}{$c->state}{$c->county} = 1;
550       $cust_main_county{$c->{country}}{$c->{state}}{$c->{county}} = 1;
551     }
552 #  }
553   $countyflag=1 if $selected_county;
554
555   my $script_html = <<END;
556     <SCRIPT>
557     function opt(what,value,text) {
558       var optionName = new Option(text, value, false, false);
559       var length = what.length;
560       what.options[length] = optionName;
561     }
562     function ${prefix}country_changed(what) {
563       country = what.options[what.selectedIndex].text;
564       for ( var i = what.form.${prefix}state.length; i >= 0; i-- )
565           what.form.${prefix}state.options[i] = null;
566 END
567       #what.form.${prefix}state.options[0] = new Option('', '', false, true);
568
569   foreach my $country ( sort keys %cust_main_county ) {
570     $script_html .= "\nif ( country == \"$country\" ) {\n";
571     foreach my $state ( sort keys %{$cust_main_county{$country}} ) {
572       my $text = $state || '(n/a)';
573       $script_html .= qq!opt(what.form.${prefix}state, "$state", "$text");\n!;
574     }
575     $script_html .= "}\n";
576   }
577
578   $script_html .= <<END;
579     }
580     function ${prefix}state_changed(what) {
581 END
582
583   if ( $countyflag ) {
584     $script_html .= <<END;
585       state = what.options[what.selectedIndex].text;
586       country = what.form.${prefix}country.options[what.form.${prefix}country.selectedIndex].text;
587       for ( var i = what.form.${prefix}county.length; i >= 0; i-- )
588           what.form.${prefix}county.options[i] = null;
589 END
590
591     foreach my $country ( sort keys %cust_main_county ) {
592       $script_html .= "\nif ( country == \"$country\" ) {\n";
593       foreach my $state ( sort keys %{$cust_main_county{$country}} ) {
594         $script_html .= "\nif ( state == \"$state\" ) {\n";
595           #foreach my $county ( sort @{$cust_main_county{$country}{$state}} ) {
596           foreach my $county ( sort keys %{$cust_main_county{$country}{$state}} ) {
597             my $text = $county || '(n/a)';
598             $script_html .=
599               qq!opt(what.form.${prefix}county, "$county", "$text");\n!;
600           }
601         $script_html .= "}\n";
602       }
603       $script_html .= "}\n";
604     }
605   }
606
607   $script_html .= <<END;
608     }
609     </SCRIPT>
610 END
611
612   my $county_html = $script_html;
613   if ( $countyflag ) {
614     $county_html .= qq!<SELECT NAME="${prefix}county" onChange="$onchange">!;
615     $county_html .= '</SELECT>';
616   } else {
617     $county_html .=
618       qq!<INPUT TYPE="hidden" NAME="${prefix}county" VALUE="$selected_county">!;
619   }
620
621   my $state_html = qq!<SELECT NAME="${prefix}state" !.
622                    qq!onChange="${prefix}state_changed(this); $onchange">!;
623   foreach my $state ( sort keys %{ $cust_main_county{$selected_country} } ) {
624     my $text = $state || '(n/a)';
625     my $selected = $state eq $selected_state ? 'SELECTED' : '';
626     $state_html .= "\n<OPTION $selected VALUE=$state>$text</OPTION>"
627   }
628   $state_html .= '</SELECT>';
629
630   $state_html .= '</SELECT>';
631
632   my $country_html = qq!<SELECT NAME="${prefix}country" !.
633                      qq!onChange="${prefix}country_changed(this); $onchange">!;
634   my $countrydefault = $init_data->{countrydefault} || 'US';
635   foreach my $country (
636     sort { ($b eq $countrydefault) <=> ($a eq $countrydefault) or $a cmp $b }
637       keys %cust_main_county
638   ) {
639     my $selected = $country eq $selected_country ? ' SELECTED' : '';
640     $country_html .= "\n<OPTION$selected>$country</OPTION>"
641   }
642   $country_html .= '</SELECT>';
643
644   ($county_html, $state_html, $country_html);
645
646 }
647
648 sub success_default { #html to use if you don't specify a success file
649   <<'END';
650 <HTML><HEAD><TITLE>Signup successful</TITLE></HEAD>
651 <BODY BGCOLOR="#e8e8e8"><FONT SIZE=7>Signup successful</FONT><BR><BR>
652 Thanks for signing up!
653 <BR><BR>
654 Signup information for <%= $email_name %>:
655 <BR><BR>
656 Username: <%= $username %><BR>
657 Password: <%= $password %><BR>
658 Access number: (<%= $ac %>) / <%= $exch %> - <%= $local %><BR>
659 Package: <%= $pkg %><BR>
660 </BODY></HTML>
661 END
662 }
663
664 sub decline_default { #html to use if there is a decline
665   <<'END';
666 <HTML><HEAD><TITLE>Processing error</TITLE></HEAD>
667 <BODY BGCOLOR="#e8e8e8"><FONT SIZE=7>Processing error</FONT><BR><BR>
668 There has been an error processing your account.  Please contact customer
669 support.
670 </BODY></HTML>
671 END
672 }
673