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