properly pass init_popstate to error pages
[freeside.git] / fs_signup / FS-SignupClient / cgi / signup.cgi
1 #!/usr/bin/perl -Tw
2 #
3 # $Id: signup.cgi,v 1.43 2003-07-04 03:21:42 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              $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
182     if ( $invoicing_list = $cgi->param('invoicing_list') ) {
183       $invoicing_list .= ', POST' if $cgi->param('invoicing_list_POST');
184     } else {
185       $invoicing_list = 'POST';
186     }
187
188     $error = '';
189
190     $last             = $cgi->param('last');
191     $first            = $cgi->param('first');
192     $ss               = $cgi->param('ss');
193     $company          = $cgi->param('company');
194     $address1         = $cgi->param('address1');
195     $address2         = $cgi->param('address2');
196     $city             = $cgi->param('city');
197     #$county,
198     #$state,
199     $zip              = $cgi->param('zip');
200     #$country,
201     $daytime          = $cgi->param('daytime');
202     $night            = $cgi->param('night');
203     $fax              = $cgi->param('fax');
204     #$payby,
205     #$payinfo,
206     #$paydate,
207     #$payname,
208     #$invoicing_list,
209     $referral_custnum = $cgi->param('ref');
210     $pkgpart          = $cgi->param('pkgpart');
211     $username         = $cgi->param('username');
212     $sec_phrase       = $cgi->param('sec_phrase');
213     $password         = $cgi->param('_password');
214     $popnum           = $cgi->param('popnum');
215     #$agentnum, #         = $cgi->param('agentnum'),
216     $init_popstate    = $cgi->param('init_popstate');
217
218     if ( $cgi->param('_password') ne $cgi->param('_password2') ) {
219       $error = $init_data->{msgcat}{passwords_dont_match}; #msgcat
220       $password  = '';
221       $password2 = '';
222     } else {
223       $password2 = $cgi->param('_password2');
224
225       if ( $payby =~ /^(CARD|DCRD)$/ && $cgi->param('CARD_type') ) {
226         $payinfo =~ s/\D//g;
227
228         $payinfo =~ /^(\d{13,16})$/
229           or $error ||= $init_data->{msgcat}{invalid_card}; #. $self->payinfo;
230         $payinfo = $1;
231         validate($payinfo)
232           or $error ||= $init_data->{msgcat}{invalid_card}; #. $self->payinfo;
233         cardtype($payinfo) eq $cgi->param('CARD_type')
234           or $error ||= $init_data->{msgcat}{not_a}. $cgi->param('CARD_type');
235       }
236
237       $error ||= new_customer ( {
238         'last'             => $last,
239         'first'            => $first,
240         'ss'               => $ss,
241         'company'          => $company,
242         'address1'         => $address1,
243         'address2'         => $address2,
244         'city'             => $city,
245         'county'           => $county,
246         'state'            => $state,
247         'zip'              => $zip,
248         'country'          => $country,
249         'daytime'          => $daytime,
250         'night'            => $night,
251         'fax'              => $fax,
252         'payby'            => $payby,
253         'payinfo'          => $payinfo,
254         'paydate'          => $paydate,
255         'payname'          => $payname,
256         'invoicing_list'   => $invoicing_list,
257         'referral_custnum' => $referral_custnum,
258         'pkgpart'          => $pkgpart,
259         'username'         => $username,
260         'sec_phrase'       => $sec_phrase,
261         '_password'        => $password,
262         'popnum'           => $popnum,
263         'agentnum'         => $agentnum,
264       } );
265
266     }
267     
268     if ( $error eq '_decline' ) {
269       print_decline();
270     } elsif ( $error ) {
271       print_form();
272     } else {
273       print_okay();
274     }
275
276   } else {
277     die "unrecognized magic: ". $cgi->param('magic');
278   }
279 } else {
280   $error = '';
281   $last = '';
282   $first = '';
283   $ss = '';
284   $company = '';
285   $address1 = '';
286   $address2 = '';
287   $city = '';
288   $state = $init_data->{statedefault};
289   $county = '';
290   $country = $init_data->{countrydefault};
291   $zip = '';
292   $daytime = '';
293   $night = '';
294   $fax = '';
295   $invoicing_list = '';
296   $payby = '';
297   $payinfo = '';
298   $paydate = '';
299   $payname = '';
300   $pkgpart = '';
301   $username = '';
302   $password = '';
303   $password2 = '';
304   $sec_phrase = '';
305   $popnum = '';
306   $referral_custnum = $cgi->param('ref') || '';
307   $init_popstate = $cgi->param('init_popstate') || '';
308   print_form;
309 }
310
311 sub print_form {
312
313   $cgi->delete('ref');
314   $cgi->delete('init_popstate');
315   $self_url = $cgi->self_url;
316
317   $error = "Error: $error" if $error;
318
319   print $cgi->header( '-expires' => 'now' ),
320         $signup_template->fill_in();
321
322 }
323
324 sub print_decline {
325   print $cgi->header( '-expires' => 'now' ),
326         $decline_template->fill_in();
327 }
328
329 sub print_okay {
330   my $user_agent = new HTTP::Headers::UserAgent $ENV{HTTP_USER_AGENT};
331
332   $cgi->param('username') =~ /^(.+)$/
333     or die "fatal: invalid username got past FS::SignupClient::new_customer";
334   my $username = $1;
335   $cgi->param('_password') =~ /^(.+)$/
336     or die "fatal: invalid password got past FS::SignupClient::new_customer";
337   my $password = $1;
338   ( $cgi->param('first'). ' '. $cgi->param('last') ) =~ /^(.*)$/
339     or die "fatal: invalid email_name got past FS::SignupClient::new_customer";
340   $email_name = $1; #global for template
341
342   my $pop = $popnum2pop{$cgi->param('popnum')};
343     #or die "fatal: invalid popnum got past FS::SignupClient::new_customer";
344   if ( $pop ) {
345     ( $ac, $exch, $loc ) = ( $pop->{'ac'}, $pop->{'exch'}, $pop->{'loc'} );
346   } else {
347     ( $ac, $exch, $loc ) = ( '', '', ''); #presumably you're not using them.
348   }
349
350   #global for template
351   $pkg = ( grep { $_->{'pkgpart'} eq $pkgpart } @$packages )[0]->{'pkg'};
352
353   if ( $ieak_template
354        && $user_agent->platform eq 'ia32'
355        && $user_agent->os =~ /^win/
356        && ($user_agent->browser)[0] eq 'IE'
357      )
358   { #send an IEAK config
359     print $cgi->header('application/x-Internet-signup'),
360           $ieak_template->fill_in();
361   } elsif ( $cck_template
362             && $user_agent->platform eq 'ia32'
363             && $user_agent->os =~ /^win/
364             && ($user_agent->browser)[0] eq 'Netscape'
365           )
366   { #send a Netscape config
367     my $cck_data = $cck_template->fill_in();
368     print $cgi->header('application/x-netscape-autoconfigure-dialer-v2'),
369           map {
370             m/(.*)\s+(.*)$/;
371             pack("N", length($1)). $1. pack("N", length($2)). $2;
372           } split(/\n/, $cck_data);
373
374   } else { #send a simple confirmation
375     print $cgi->header( '-expires' => 'now' ),
376           $success_template->fill_in();
377   }
378 }
379
380 #horrible false laziness with FS/FS/svc_acct_pop.pm::popselector
381 sub popselector {
382
383   my( $popnum ) = @_;
384
385   return '<INPUT TYPE="hidden" NAME="popnum" VALUE="">' unless @$pops;
386   return $pops->[0]{city}. ', '. $pops->[0]{state}.
387          ' ('. $pops->[0]{ac}. ')/'. $pops->[0]{exch}. '-'. $pops->[0]{loc}.
388          '<INPUT TYPE="hidden" NAME="popnum" VALUE="'. $pops->[0]{popnum}. '">'
389     if scalar(@$pops) == 1;
390
391   #my %pop = ();
392   #my %popnum2pop = ();
393   #foreach (@$pops) {
394   #  push @{ $pop{ $_->{state} }->{ $_->{ac} } }, $_;
395   #  $popnum2pop{$_->{popnum}} = $_;
396   #}
397
398   my $text = <<END;
399     <SCRIPT>
400     function opt(what,href,text) {
401       var optionName = new Option(text, href, false, false)
402       var length = what.length;
403       what.options[length] = optionName;
404     }
405 END
406
407   if ( $init_popstate ) {
408     $text .= '<INPUT TYPE="hidden" NAME="init_popstate" VALUE="'.
409              $init_popstate. '">';
410   } else {
411     $text .= <<END;
412       function acstate_changed(what) {
413         state = what.options[what.selectedIndex].text;
414         what.form.popac.options.length = 0
415         what.form.popac.options[0] = new Option("Area code", "-1", false, true);
416 END
417   } 
418
419   my @states = $init_popstate ? ( $init_popstate ) : keys %pop;
420   foreach my $state ( sort { $a cmp $b } @states ) {
421     $text .= "\nif ( state == \"$state\" ) {\n" unless $init_popstate;
422
423     foreach my $ac ( sort { $a cmp $b } keys %{ $pop{$state} }) {
424       $text .= "opt(what.form.popac, \"$ac\", \"$ac\");\n";
425       if ($ac eq $cgi->param('popac')) {
426         $text .= "what.form.popac.options[what.form.popac.length-1].selected = true;\n";
427       }
428     }
429     $text .= "}\n" unless $init_popstate;
430   }
431   $text .= "popac_changed(what.form.popac)}\n";
432
433   $text .= <<END;
434   function popac_changed(what) {
435     ac = what.options[what.selectedIndex].text;
436     what.form.popnum.options.length = 0;
437     what.form.popnum.options[0] = new Option("City", "-1", false, true);
438
439 END
440
441   foreach my $state ( @states ) {
442     foreach my $popac ( keys %{ $pop{$state} } ) {
443       $text .= "\nif ( ac == \"$popac\" ) {\n";
444
445       foreach my $pop ( @{$pop{$state}->{$popac}}) {
446         my $o_popnum = $pop->{popnum};
447         my $poptext =  $pop->{city}. ', '. $pop->{state}.
448                        ' ('. $pop->{ac}. ')/'. $pop->{exch}. '-'. $pop->{loc};
449
450         $text .= "opt(what.form.popnum, \"$o_popnum\", \"$poptext\");\n";
451         if ($popnum == $o_popnum) {
452           $text .= "what.form.popnum.options[what.form.popnum.length-1].selected = true;\n";
453         }
454       }
455       $text .= "}\n";
456     }
457   }
458
459
460   $text .= "}\n</SCRIPT>\n";
461
462   $text .=
463     qq!<TABLE CELLPADDING="0"><TR><TD><SELECT NAME="acstate"! .
464     qq!SIZE=1 onChange="acstate_changed(this)"><OPTION VALUE=-1>State!;
465   $text .= "<OPTION" . ($_ eq $cgi->param('acstate') ? " SELECTED" : "") .
466            ">$_" foreach sort { $a cmp $b } @states;
467   $text .= '</SELECT>'; #callback? return 3 html pieces?  #'</TD>';
468
469   $text .=
470     qq!<SELECT NAME="popac" SIZE=1 onChange="popac_changed(this)">!.
471     qq!<OPTION>Area code</SELECT></TR><TR VALIGN="top">!;
472
473   $text .= qq!<TR><TD><SELECT NAME="popnum" SIZE=1 STYLE="width: 20em"><OPTION>City!;
474
475
476   #comment this block to disable initial list polulation
477   my @initial_select = ();
478   if ( scalar( @$pops ) > 100 ) {
479     push @initial_select, $popnum2pop{$popnum} if $popnum2pop{$popnum};
480   } else {
481     @initial_select = @$pops;
482   }
483   foreach my $pop ( sort { $a->{state} cmp $b->{state} } @initial_select ) {
484     $text .= qq!<OPTION VALUE="!. $pop->{popnum}. '"'.
485              ( ( $popnum && $pop->{popnum} == $popnum ) ? ' SELECTED' : '' ). ">".
486              $pop->{city}. ', '. $pop->{state}.
487                ' ('. $pop->{ac}. ')/'. $pop->{exch}. '-'. $pop->{loc};
488   }
489
490   $text .= qq!</SELECT></TD></TR></TABLE>!;
491
492   $text;
493
494 }
495
496 sub expselect {
497   my $prefix = shift;
498   my $date = shift || '';
499   my( $m, $y ) = ( 0, 0 );
500   if ( $date  =~ /^(\d{4})-(\d{2})-\d{2}$/ ) { #PostgreSQL date format
501     ( $m, $y ) = ( $2, $1 );
502   } elsif ( $date =~ /^(\d{1,2})-(\d{1,2}-)?(\d{4}$)/ ) {
503     ( $m, $y ) = ( $1, $3 );
504   }
505   my $return = qq!<SELECT NAME="$prefix!. qq!_month" SIZE="1">!;
506   for ( 1 .. 12 ) {
507     $return .= "<OPTION";
508     $return .= " SELECTED" if $_ == $m;
509     $return .= ">$_";
510   }
511   $return .= qq!</SELECT>/<SELECT NAME="$prefix!. qq!_year" SIZE="1">!;
512   for ( 2001 .. 2037 ) {
513     $return .= "<OPTION";
514     $return .= " SELECTED" if $_ == $y;
515     $return .= ">$_";
516   }
517   $return .= "</SELECT>";
518
519   $return;
520 }
521
522 #false laziness w/FS::cust_main_county
523 sub regionselector {
524   my ( $selected_county, $selected_state, $selected_country,
525        $prefix, $onchange ) = @_;
526
527   my $prefix = '' unless defined $prefix;
528
529   my $countyflag = 0;
530
531   my %cust_main_county;
532
533 #  unless ( @cust_main_county ) { #cache 
534     #@cust_main_county = qsearch('cust_main_county', {} );
535     #foreach my $c ( @cust_main_county ) {
536     foreach my $c ( @$locales ) {
537       #$countyflag=1 if $c->county;
538       $countyflag=1 if $c->{county};
539       #push @{$cust_main_county{$c->country}{$c->state}}, $c->county;
540       #$cust_main_county{$c->country}{$c->state}{$c->county} = 1;
541       $cust_main_county{$c->{country}}{$c->{state}}{$c->{county}} = 1;
542     }
543 #  }
544   $countyflag=1 if $selected_county;
545
546   my $script_html = <<END;
547     <SCRIPT>
548     function opt(what,value,text) {
549       var optionName = new Option(text, value, false, false);
550       var length = what.length;
551       what.options[length] = optionName;
552     }
553     function ${prefix}country_changed(what) {
554       country = what.options[what.selectedIndex].text;
555       for ( var i = what.form.${prefix}state.length; i >= 0; i-- )
556           what.form.${prefix}state.options[i] = null;
557 END
558       #what.form.${prefix}state.options[0] = new Option('', '', false, true);
559
560   foreach my $country ( sort keys %cust_main_county ) {
561     $script_html .= "\nif ( country == \"$country\" ) {\n";
562     foreach my $state ( sort keys %{$cust_main_county{$country}} ) {
563       my $text = $state || '(n/a)';
564       $script_html .= qq!opt(what.form.${prefix}state, "$state", "$text");\n!;
565     }
566     $script_html .= "}\n";
567   }
568
569   $script_html .= <<END;
570     }
571     function ${prefix}state_changed(what) {
572 END
573
574   if ( $countyflag ) {
575     $script_html .= <<END;
576       state = what.options[what.selectedIndex].text;
577       country = what.form.${prefix}country.options[what.form.${prefix}country.selectedIndex].text;
578       for ( var i = what.form.${prefix}county.length; i >= 0; i-- )
579           what.form.${prefix}county.options[i] = null;
580 END
581
582     foreach my $country ( sort keys %cust_main_county ) {
583       $script_html .= "\nif ( country == \"$country\" ) {\n";
584       foreach my $state ( sort keys %{$cust_main_county{$country}} ) {
585         $script_html .= "\nif ( state == \"$state\" ) {\n";
586           #foreach my $county ( sort @{$cust_main_county{$country}{$state}} ) {
587           foreach my $county ( sort keys %{$cust_main_county{$country}{$state}} ) {
588             my $text = $county || '(n/a)';
589             $script_html .=
590               qq!opt(what.form.${prefix}county, "$county", "$text");\n!;
591           }
592         $script_html .= "}\n";
593       }
594       $script_html .= "}\n";
595     }
596   }
597
598   $script_html .= <<END;
599     }
600     </SCRIPT>
601 END
602
603   my $county_html = $script_html;
604   if ( $countyflag ) {
605     $county_html .= qq!<SELECT NAME="${prefix}county" onChange="$onchange">!;
606     $county_html .= '</SELECT>';
607   } else {
608     $county_html .=
609       qq!<INPUT TYPE="hidden" NAME="${prefix}county" VALUE="$selected_county">!;
610   }
611
612   my $state_html = qq!<SELECT NAME="${prefix}state" !.
613                    qq!onChange="${prefix}state_changed(this); $onchange">!;
614   foreach my $state ( sort keys %{ $cust_main_county{$selected_country} } ) {
615     my $text = $state || '(n/a)';
616     my $selected = $state eq $selected_state ? 'SELECTED' : '';
617     $state_html .= "\n<OPTION $selected VALUE=$state>$text</OPTION>"
618   }
619   $state_html .= '</SELECT>';
620
621   $state_html .= '</SELECT>';
622
623   my $country_html = qq!<SELECT NAME="${prefix}country" !.
624                      qq!onChange="${prefix}country_changed(this); $onchange">!;
625   my $countrydefault = $init_data->{countrydefault} || 'US';
626   foreach my $country (
627     sort { ($b eq $countrydefault) <=> ($a eq $countrydefault) or $a cmp $b }
628       keys %cust_main_county
629   ) {
630     my $selected = $country eq $selected_country ? ' SELECTED' : '';
631     $country_html .= "\n<OPTION$selected>$country</OPTION>"
632   }
633   $country_html .= '</SELECT>';
634
635   ($county_html, $state_html, $country_html);
636
637 }
638
639 sub success_default { #html to use if you don't specify a success file
640   <<'END';
641 <HTML><HEAD><TITLE>Signup successful</TITLE></HEAD>
642 <BODY BGCOLOR="#e8e8e8"><FONT SIZE=7>Signup successful</FONT><BR><BR>
643 Thanks for signing up!
644 <BR><BR>
645 Signup information for <%= $email_name %>:
646 <BR><BR>
647 Username: <%= $username %><BR>
648 Password: <%= $password %><BR>
649 Access number: (<%= $ac %>) / $exch - $local<BR>
650 Package: <%= $pkg %><BR>
651 </BODY></HTML>
652 END
653 }
654
655 sub decline_default { #html to use if there is a decline
656   <<'END';
657 <HTML><HEAD><TITLE>Processing error</TITLE></HEAD>
658 <BODY BGCOLOR="#e8e8e8"><FONT SIZE=7>Processing error</FONT><BR><BR>
659 There has been an error processing your account.  Please contact customer
660 support.
661 </BODY></HTML>
662 END
663 }
664