3 # $Id: signup.cgi,v 1.5 2000-02-02 07:44:00 ivan Exp $
6 use vars qw( @payby $cgi $locales $packages $pops $r $error
7 $last $first $ss $company $address1 $address2 $city $state $county
8 $country $zip $daytime $night $fax $invoicing_list $payby $payinfo
9 $paydate $payname $pkgpart $username $password $popnum
10 $ieak_file $ieak_template $ac $exch $loc
12 #$ieak_docroot $ieak_baseurl
13 use subs qw( print_form print_okay expselect );
16 use CGI::Carp qw(fatalsToBrowser);
17 use HTTP::Headers::UserAgent 2.00;
18 use FS::SignupClient qw( signup_info new_customer );
21 #acceptable payment methods
23 #@payby = qw( CARD BILL COMP );
24 #@payby = qw( CARD BILL );
26 @payby = qw( CARD PREPAY );
28 $ieak_file = '/usr/local/freeside/ieak.template';
30 if ( -e $ieak_file ) {
31 $ieak_template = new Text::Template ( TYPE => 'FILE', SOURCE => $ieak_file )
32 or die "Couldn't construct template: $Text::Template::ERROR";
37 # #to enable ieak signups, you need to specify a directory in the web server's
38 # #document space and the equivalent base URL
40 # $ieak_docroot = "/var/www/sisd.420.am/freeside/ieak";
41 # $ieak_baseurl = "http://sisd.420.am/freeside/ieak";
43 #srand (time ^ $$ ^ unpack "%L*", `ps axww | gzip`);
45 ( $locales, $packages, $pops ) = signup_info();
49 if ( defined $cgi->param('magic') ) {
50 if ( $cgi->param('magic') eq 'process' ) {
52 $cgi->param('state') =~ /^(\w*)( \(([\w ]+)\))? ?\/ ?(\w+)$/
53 or die "Oops, illegal \"state\" param: ". $cgi->param('state');
58 $payby = $cgi->param('payby');
59 $payinfo = $cgi->param( $payby. '_payinfo' );
61 $cgi->param( $payby. '_month' ). '-'. $cgi->param( $payby. '_year' );
62 $payname = $cgi->param( $payby. '_payname' );
64 if ( $invoicing_list = $cgi->param('invoicing_list') ) {
65 $invoicing_list .= ', POST' if $cgi->param('invoicing_list_POST');
67 $invoicing_list = 'POST';
70 ( $error = new_customer ( {
71 'last' => $last = $cgi->param('last'),
72 'first' => $first = $cgi->param('first'),
73 'ss' => $ss = $cgi->param('ss'),
74 'company' => $company = $cgi->param('company'),
75 'address1' => $address1 = $cgi->param('address1'),
76 'address2' => $address2 = $cgi->param('address2'),
77 'city' => $city = $cgi->param('city'),
80 'zip' => $zip = $cgi->param('zip'),
81 'country' => $country,
82 'daytime' => $daytime = $cgi->param('daytime'),
83 'night' => $night = $cgi->param('night'),
84 'fax' => $fax = $cgi->param('fax'),
86 'payinfo' => $payinfo,
87 'paydate' => $paydate,
88 'payname' => $payname,
89 'invoicing_list' => $invoicing_list,
90 'pkgpart' => $pkgpart = $cgi->param('pkgpart'),
91 'username' => $username = $cgi->param('username'),
92 '_password' => $password = $cgi->param('_password'),
93 'popnum' => $popnum = $cgi->param('popnum'),
98 die "unrecognized magic: ". $cgi->param('magic');
116 $invoicing_list = '';
131 my $r = qq!<font color="#ff0000">*</font>!;
132 my $self_url = $cgi->self_url;
134 print $cgi->header( '-expires' => 'now' ), <<END;
135 <HTML><HEAD><TITLE>ISP Signup form</TITLE></HEAD>
136 <BODY BGCOLOR="#e8e8e8"><FONT SIZE=7>ISP Signup form</FONT><BR><BR>
139 print qq!<FONT SIZE="+1" COLOR="#ff0000">Error: $error</FONT>! if $error;
142 <FORM ACTION="$self_url" METHOD=POST>
143 <INPUT TYPE="hidden" NAME="magic" VALUE="process">
145 <TABLE BGCOLOR="#c0c0c0" BORDER=0 CELLSPACING=0 WIDTH="100%">
147 <TH ALIGN="right">${r}Contact name<BR>(last, first)</TH>
148 <TD COLSPAN=3><INPUT TYPE="text" NAME="last" VALUE="$last">,
149 <INPUT TYPE="text" NAME="first" VALUE="$first"></TD>
150 <TD ALIGN="right">SS#</TD>
151 <TD><INPUT TYPE="text" NAME="ss" SIZE=11 VALUE="$ss"></TD>
154 <TD ALIGN="right">Company</TD>
155 <TD COLSPAN=5><INPUT TYPE="text" NAME="company" SIZE=70 VALUE="$company"></TD>
158 <TH ALIGN="right">${r}Address</TH>
159 <TD COLSPAN=5><INPUT TYPE="text" NAME="address1" SIZE=70 VALUE="$address1"></TD>
162 <TD ALIGN="right"> </TD>
163 <TD COLSPAN=5><INPUT TYPE="text" NAME="address2" SIZE=70 VALUE="$address2"></TD>
166 <TH ALIGN="right">${r}City</TH>
167 <TD><INPUT TYPE="text" NAME="city" VALUE="$city"></TD>
168 <TH ALIGN="right">${r}State/Country</TH>
169 <TD><SELECT NAME="state" SIZE="1">
172 foreach ( @{$locales} ) {
174 print " SELECTED" if ( $state eq $_->{'state'}
175 && $county eq $_->{'county'}
176 && $country eq $_->{'country'}
178 print ">", $_->{'state'};
179 print " (",$_->{'county'},")" if $_->{'county'};
180 print " / ", $_->{'country'};
186 <TD><INPUT TYPE="text" NAME="zip" SIZE=10 VALUE="$zip"></TD>
189 <TD ALIGN="right">Day Phone</TD>
190 <TD COLSPAN=5><INPUT TYPE="text" NAME="daytime" VALUE="$daytime" SIZE=18></TD>
193 <TD ALIGN="right">Night Phone</TD>
194 <TD COLSPAN=5><INPUT TYPE="text" NAME="night" VALUE="$night" SIZE=18></TD>
197 <TD ALIGN="right">Fax</TD>
198 <TD COLSPAN=5><INPUT TYPE="text" NAME="fax" VALUE="$fax" SIZE=12></TD>
200 </TABLE>$r required fields<BR>
201 <BR>Billing information<TABLE BGCOLOR="#c0c0c0" BORDER=0 CELLSPACING=0 WIDTH="100%">
205 print qq!<INPUT TYPE="checkbox" NAME="invoicing_list_POST" VALUE="POST"!;
206 my @invoicing_list = split(', ', $invoicing_list );
208 if ! @invoicing_list || grep { $_ eq 'POST' } @invoicing_list;
209 print '>Postal mail invoice</TD></TR><TR><TD>Email invoice ',
210 qq!<INPUT TYPE="text" NAME="invoicing_list" VALUE="!,
211 join(', ', grep { $_ ne 'POST' } @invoicing_list ),
215 <TR><TD>Billing type</TD></TR></TABLE>
216 <TABLE BGCOLOR="#c0c0c0" BORDER=1 WIDTH="100%">
221 'CARD' => qq!Credit card<BR>${r}<INPUT TYPE="text" NAME="CARD_payinfo" VALUE="" MAXLENGTH=19><BR>${r}Exp !. expselect("CARD"). qq!<BR>${r}Name on card<BR><INPUT TYPE="text" NAME="CARD_payname" VALUE="">!,
222 'BILL' => qq!Billing<BR>P.O. <INPUT TYPE="text" NAME="BILL_payinfo" VALUE=""><BR>${r}Exp !. expselect("BILL", "12-2037"). qq!<BR>${r}Attention<BR><INPUT TYPE="text" NAME="BILL_payname" VALUE="Accounts Payable">!,
223 'COMP' => qq!Complimentary<BR>${r}Approved by<INPUT TYPE="text" NAME="COMP_payinfo" VALUE=""><BR>${r}Exp !. expselect("COMP"),
224 'PREPAY' => qq!Prepaid card<BR>${r}<INPUT TYPE="text" NAME="PREPAY_payinfo" VALUE="" MAXLENGTH=80>!,
228 'CARD' => qq!Credit card<BR>${r}<INPUT TYPE="text" NAME="CARD_payinfo" VALUE="$payinfo" MAXLENGTH=19><BR>${r}Exp !. expselect("CARD", $paydate). qq!<BR>${r}Name on card<BR><INPUT TYPE="text" NAME="CARD_payname" VALUE="$payname">!,
229 'BILL' => qq!Billing<BR>P.O. <INPUT TYPE="text" NAME="BILL_payinfo" VALUE="$payinfo"><BR>${r}Exp !. expselect("BILL", $paydate). qq!<BR>${r}Attention<BR><INPUT TYPE="text" NAME="BILL_payname" VALUE="$payname">!,
230 'COMP' => qq!Complimentary<BR>${r}Approved by<INPUT TYPE="text" NAME="COMP_payinfo" VALUE="$payinfo"><BR>${r}Exp !. expselect("COMP", $paydate),
231 'PREPAY' => qq!Prepaid card<BR>${r}<INPUT TYPE="text" NAME="PREPAY_payinfo" VALUE="$payinfo" MAXLENGTH=80>!,
235 print qq!<TD VALIGN=TOP><INPUT TYPE="radio" NAME="payby" VALUE="$_"!;
237 print qq! CHECKED> $paybychecked{$_}</TD>!;
239 print qq!> $payby{$_}</TD>!;
244 </TR></TABLE>$r required fields for each billing type
245 <BR><BR>First package
246 <TABLE BGCOLOR="#c0c0c0" BORDER=0 CELLSPACING=0 WIDTH="100%">
248 <TD COLSPAN=2><SELECT NAME="pkgpart"><OPTION VALUE="">(none)
251 foreach my $package ( @{$packages} ) {
252 print qq!<OPTION VALUE="!, $package->{'pkgpart'}, '"';
253 print " SELECTED" if $pkgpart && ( $package->{'pkgpart'} == $pkgpart );
254 print ">", $package->{'pkg'};
261 <TD ALIGN="right">Username</TD>
262 <TD><INPUT TYPE="text" NAME="username" VALUE="$username"></TD>
265 <TD ALIGN="right">Password</TD>
266 <TD><INPUT TYPE="text" NAME="_password" VALUE="$password">
267 (blank to generate)</TD>
270 <TD ALIGN="right">POP</TD>
271 <TD><SELECT NAME="popnum" SIZE=1><OPTION>
274 foreach my $pop ( @{$pops} ) {
275 print qq!<OPTION VALUE="!, $pop->{'popnum'}, '"',
276 ( $popnum && $pop->{'popnum'} == $popnum ) ? ' SELECTED' : '', ">",
277 $pop->{'popnum'}, ": ",
278 $pop->{'city'}, ", ",
280 " (", $pop->{'ac'}, ")/",
288 <BR><BR><INPUT TYPE="submit" VALUE="Signup">
289 </FORM></BODY></HTML>
295 my $user_agent = new HTTP::Headers::UserAgent $ENV{HTTP_USER_AGENT};
297 && $user_agent->platform eq 'ia32'
298 && $user_agent->os =~ /^win/
299 && ($user_agent->browser)[0] eq 'IE'
301 { #send an IEAK config
302 my $username = $cgi->param('username');
303 my $password = $cgi->param('_password');
304 my $email_name = $cgi->param('first'). ' '. $cgi->param('last');
306 print $cgi->header('application/x-Internet-signup'),
307 $ieak_template->fill_in();
309 # my $ins_file = rand(4294967296). ".ins";
310 # open(INS_FILE, ">$ieak_docroot/$ins_file");
311 # print INS_FILE <<END;
313 # print $cgi->redirect("$ieak_docroot/$ins_file");
315 } else { #send a simple confirmation
316 print $cgi->header( '-expires' => 'now' ), <<END;
317 <HTML><HEAD><TITLE>Signup successful</TITLE></HEAD>
318 <BODY BGCOLOR="#e8e8e8"><FONT SIZE=7>Signup successful</FONT><BR><BR>
328 my $date = shift || '';
329 my( $m, $y ) = ( 0, 0 );
330 if ( $date =~ /^(\d{4})-(\d{2})-\d{2}$/ ) { #PostgreSQL date format
331 ( $m, $y ) = ( $2, $1 );
332 } elsif ( $date =~ /^(\d{1,2})-(\d{1,2}-)?(\d{4}$)/ ) {
333 ( $m, $y ) = ( $1, $3 );
335 my $return = qq!<SELECT NAME="$prefix!. qq!_month" SIZE="1">!;
337 $return .= "<OPTION";
338 $return .= " SELECTED" if $_ == $m;
341 $return .= qq!</SELECT>/<SELECT NAME="$prefix!. qq!_year" SIZE="1">!;
342 for ( 1999 .. 2037 ) {
343 $return .= "<OPTION";
344 $return .= " SELECTED" if $_ == $y;
347 $return .= "</SELECT>";