customer-to-customer referrals in singup server
[freeside.git] / fs_signup / FS-SignupClient / cgi / signup.cgi
index 839ad33..5d024a8 100755 (executable)
@@ -1,12 +1,13 @@
 #!/usr/bin/perl -Tw
 #
-# $Id: signup.cgi,v 1.7 2000-05-10 23:57:57 ivan Exp $
+# $Id: signup.cgi,v 1.10 2001-08-28 16:58:08 ivan Exp $
 
 use strict;
 use vars qw( @payby $cgi $locales $packages $pops $r $error
              $last $first $ss $company $address1 $address2 $city $state $county
              $country $zip $daytime $night $fax $invoicing_list $payby $payinfo
-             $paydate $payname $pkgpart $username $password $popnum
+             $paydate $payname $referral_custnum
+             $pkgpart $username $password $popnum
              $ieak_file $ieak_template $cck_file $cck_template
              $ac $exch $loc
            );
@@ -15,7 +16,7 @@ use subs qw( print_form print_okay expselect );
 use CGI;
 use CGI::Carp qw(fatalsToBrowser);
 use HTTP::Headers::UserAgent 2.00;
-use FS::SignupClient qw( signup_info new_customer );
+use FS::SignupClient 0.02 qw( signup_info new_customer );
 use Text::Template;
 
 #acceptable payment methods
@@ -29,14 +30,22 @@ $ieak_file = '/usr/local/freeside/ieak.template';
 $cck_file = '/usr/local/freeside/cck.template';
 
 if ( -e $ieak_file ) {
-  $ieak_template = new Text::Template ( TYPE => 'FILE', SOURCE => $ieak_file )
-    or die "Couldn't construct template: $Text::Template::ERROR";
+  my $ieak_txt = Text::Template::_load_text($ieak_file)
+    or die $Text::Template::ERROR;
+  $ieak_txt =~ /^(.*)$/s; #untaint the template source - it's trusted
+  $ieak_txt = $1;
+  $ieak_template = new Text::Template ( TYPE => 'STRING', SOURCE => $ieak_txt )
+    or die $Text::Template::ERROR;
 } else {
   $ieak_template = '';
 }
 if ( -e $cck_file ) {
-  $cck_template = new Text::Template ( TYPE => 'FILE', SOURCE => $cck_file )
-    or die "Couldn't construct template: $Text::Template::ERROR";
+  my $cck_txt = Text::Template::_load_text($cck_file)
+    or die $Text::Template::ERROR;
+  $cck_txt =~ /^(.*)$/s; #untaint the template source - it's trusted
+  $cck_txt = $1;
+  $cck_template = new Text::Template ( TYPE => 'STRING', SOURCE => $cck_txt )
+    or die $Text::Template::ERROR;
 } else {
   $cck_template = '';
 }
@@ -67,29 +76,30 @@ if ( defined $cgi->param('magic') ) {
     }
 
     ( $error = new_customer ( {
-      'last'           => $last            = $cgi->param('last'),
-      'first'          => $first           = $cgi->param('first'),
-      'ss'             => $ss              = $cgi->param('ss'),
-      'company'        => $company         = $cgi->param('company'),
-      'address1'       => $address1        = $cgi->param('address1'),
-      'address2'       => $address2        = $cgi->param('address2'),
-      'city'           => $city            = $cgi->param('city'),
-      'county'         => $county,
-      'state'          => $state,
-      'zip'            => $zip             = $cgi->param('zip'),
-      'country'        => $country,
-      'daytime'        => $daytime         = $cgi->param('daytime'),
-      'night'          => $night           = $cgi->param('night'),
-      'fax'            => $fax             = $cgi->param('fax'),
-      'payby'          => $payby,
-      'payinfo'        => $payinfo,
-      'paydate'        => $paydate,
-      'payname'        => $payname,
-      'invoicing_list' => $invoicing_list,
-      'pkgpart'        => $pkgpart         = $cgi->param('pkgpart'),
-      'username'       => $username        = $cgi->param('username'),
-      '_password'      => $password        = $cgi->param('_password'),
-      'popnum'         => $popnum          = $cgi->param('popnum'),
+      'last'             => $last             = $cgi->param('last'),
+      'first'            => $first            = $cgi->param('first'),
+      'ss'               => $ss               = $cgi->param('ss'),
+      'company'          => $company          = $cgi->param('company'),
+      'address1'         => $address1         = $cgi->param('address1'),
+      'address2'         => $address2         = $cgi->param('address2'),
+      'city'             => $city             = $cgi->param('city'),
+      'county'           => $county,
+      'state'            => $state,
+      'zip'              => $zip              = $cgi->param('zip'),
+      'country'          => $country,
+      'daytime'          => $daytime          = $cgi->param('daytime'),
+      'night'            => $night            = $cgi->param('night'),
+      'fax'              => $fax              = $cgi->param('fax'),
+      'payby'            => $payby,
+      'payinfo'          => $payinfo,
+      'paydate'          => $paydate,
+      'payname'          => $payname,
+      'invoicing_list'   => $invoicing_list,
+      'referral_custnum' => $referral_custnum = $cgi->param('ref'),
+      'pkgpart'          => $pkgpart          = $cgi->param('pkgpart'),
+      'username'         => $username         = $cgi->param('username'),
+      '_password'        => $password         = $cgi->param('_password'),
+      'popnum'           => $popnum           = $cgi->param('popnum'),
     } ) )
       ? print_form()
       : print_okay();
@@ -121,13 +131,14 @@ if ( defined $cgi->param('magic') ) {
   $username = '';
   $password = '';
   $popnum = '';
-
+  $referral_custnum = $cgi->param('ref') || '';
   print_form;
 }
 
 sub print_form {
 
   my $r = qq!<font color="#ff0000">*</font>!;
+  $cgi->delete('ref');
   my $self_url = $cgi->self_url;
 
   print $cgi->header( '-expires' => 'now' ), <<END;
@@ -140,6 +151,7 @@ END
   print <<END;
 <FORM ACTION="$self_url" METHOD=POST>
 <INPUT TYPE="hidden" NAME="magic" VALUE="process">
+<INPUT TYPE="hidden" NAME="ref" VALUE="$referral_custnum">
 Contact Information
 <TABLE BGCOLOR="#c0c0c0" BORDER=0 CELLSPACING=0 WIDTH="100%">
 <TR>
@@ -305,7 +317,7 @@ sub print_okay {
 
   my $pop = pop_info($cgi->param('popnum'))
     or die "fatal: invalid popnum got past FS::SignupClient::new_customer";
-  my ( $ac, $exch, $loc ) = ( $pop->{'ac'}, $pop->{'exch'}, $pop->{'loc'} );
+  ( $ac, $exch, $loc ) = ( $pop->{'ac'}, $pop->{'exch'}, $pop->{'loc'} );
 
   if ( $ieak_template
        && $user_agent->platform eq 'ia32'