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