make necessary stuff for success.html global
[freeside.git] / fs_signup / FS-SignupClient / cgi / signup.cgi
index f13dd43..e3d2d8c 100755 (executable)
@@ -1,6 +1,6 @@
 #!/usr/bin/perl -Tw
 #
-# $Id: signup.cgi,v 1.21 2002-04-16 00:02:26 ivan Exp $
+# $Id: signup.cgi,v 1.25 2002-04-19 23:50:37 ivan Exp $
 
 use strict;
 use vars qw( @payby $cgi $locales $packages $pops $init_data $error
@@ -12,6 +12,7 @@ use vars qw( @payby $cgi $locales $packages $pops $init_data $error
              $ieak_file $ieak_template $cck_file $cck_template
              $signup_html $signup_template $success_html $success_template
              $ac $exch $loc
+             $email_name $pkg
              $self_url
            );
 use subs qw( print_form print_okay expselect signup_default success_default );
@@ -31,8 +32,12 @@ use FS::SignupClient 0.03 qw( signup_info new_customer );
 
 $ieak_file = '/usr/local/freeside/ieak.template';
 $cck_file = '/usr/local/freeside/cck.template';
-$signup_html = '/usr/local/freeside/signup.html';
-$success_html = '/usr/local/freeside/success.html';
+$signup_html = -e 'signup.html'
+                 ? 'signup.html'
+                 : '/usr/local/freeside/signup.html';
+$success_html = -e 'success.html'
+                  ? 'success.html'
+                  : '/usr/local/freeside/success.html';
 
 if ( -e $ieak_file ) {
   my $ieak_txt = Text::Template::_load_text($ieak_file)
@@ -56,6 +61,7 @@ if ( -e $cck_file ) {
   $cck_template = '';
 }
 
+$agentnum = '';
 if ( -e $signup_html ) {
   my $signup_txt = Text::Template::_load_text($signup_html)
     or die $Text::Template::ERROR;
@@ -66,6 +72,11 @@ if ( -e $signup_html ) {
                                           DELIMITERS => [ '<%=', '%>' ]
                                         )
     or die $Text::Template::ERROR;
+  if ( $signup_txt =~
+         /<\s*INPUT TYPE="?hidden"?\s+NAME="?agentnum"?\s+VALUE="?(\d+)"?\s*>/si
+  ) {
+    $agentnum = $1;
+  }
 } else {
   $signup_template = new Text::Template ( TYPE => 'STRING',
                                           SOURCE => &signup_default,
@@ -92,8 +103,10 @@ if ( -e $success_html ) {
     or die $Text::Template::ERROR;
 }
 
+
 ( $locales, $packages, $pops, $init_data ) = signup_info();
 @payby = @{$init_data->{'payby'}} if @{$init_data->{'payby'}};
+$packages = $init_data->{agentnum2part_pkg}{$agentnum} if $agentnum;
 
 $cgi = new CGI;
 
@@ -165,7 +178,7 @@ if ( defined $cgi->param('magic') ) {
         'sec_phrase'       => $sec_phrase       = $cgi->param('sec_phrase'),
         '_password'        => $password         = $cgi->param('_password'),
         'popnum'           => $popnum           = $cgi->param('popnum'),
-        'agentnum'         => $agentnum         = $cgi->param('agentnum'),
+        'agentnum'         => $agentnum, #         = $cgi->param('agentnum'),
       } );
 
     }
@@ -233,13 +246,18 @@ sub print_okay {
   my $password = $1;
   ( $cgi->param('first'). ' '. $cgi->param('last') ) =~ /^(.*)$/
     or die "fatal: invalid email_name got past FS::SignupClient::new_customer";
-  my $email_name = $1;
+  $email_name = $1; #global for template
 
-  my $pop = pop_info($cgi->param('popnum'))
-    or die "fatal: invalid popnum got past FS::SignupClient::new_customer";
-  ( $ac, $exch, $loc ) = ( $pop->{'ac'}, $pop->{'exch'}, $pop->{'loc'} );
+  my $pop = pop_info($cgi->param('popnum'));
+    #or die "fatal: invalid popnum got past FS::SignupClient::new_customer";
+  if ( $pop ) {
+    ( $ac, $exch, $loc ) = ( $pop->{'ac'}, $pop->{'exch'}, $pop->{'loc'} );
+  } else {
+    ( $ac, $exch, $loc ) = ( '', '', ''); #presumably you're not using them.
+  }
 
-  my $pkg = ( grep { $_->{'pkgpart'} eq $pkgpart } @$packages )[0]->{'pkg'};
+  #global for template
+  $pkg = ( grep { $_->{'pkgpart'} eq $pkgpart } @$packages )[0]->{'pkg'};
 
   if ( $ieak_template
        && $user_agent->platform eq 'ia32'