don't populate the whole initial list if there are tons of POPs
authorivan <ivan>
Fri, 4 Jul 2003 01:37:46 +0000 (01:37 +0000)
committerivan <ivan>
Fri, 4 Jul 2003 01:37:46 +0000 (01:37 +0000)
FS/FS/svc_acct_pop.pm
fs_signup/FS-SignupClient/cgi/signup.cgi

index 404816b..196ab7e 100644 (file)
@@ -166,7 +166,13 @@ END
   $text .= '</SELECT>'; #callback? return 3 html pieces?  #'</TD><TD>';
 
   $text .= qq!<SELECT NAME="popnum" SIZE=1><OPTION> !;
-  foreach my $pop ( @svc_acct_pop ) {
+  my @initial_select;
+  if ( scalar(@svc_acct_pop) > 100 ) {
+    @initial_select = qsearchs( 'svc_acct_pop', { 'popnum' => $popnum } );
+  } else {
+    @initial_select = @svc_acct_pop;
+  }
+  foreach my $pop ( @initial_select ) {
     $text .= qq!<OPTION VALUE="!. $pop->popnum. '"'.
              ( ( $popnum && $pop->popnum == $popnum ) ? ' SELECTED' : '' ). ">".
              $pop->text;
@@ -181,7 +187,7 @@ END
 
 =head1 VERSION
 
-$Id: svc_acct_pop.pm,v 1.8 2003-07-04 00:51:29 ivan Exp $
+$Id: svc_acct_pop.pm,v 1.9 2003-07-04 01:37:46 ivan Exp $
 
 =head1 BUGS
 
index 09bdd43..b400685 100755 (executable)
@@ -1,9 +1,11 @@
 #!/usr/bin/perl -Tw
 #
-# $Id: signup.cgi,v 1.38 2003-07-04 00:51:29 ivan Exp $
+# $Id: signup.cgi,v 1.39 2003-07-04 01:37:46 ivan Exp $
 
 use strict;
-use vars qw( @payby $cgi $locales $packages $pops $init_data $error
+use vars qw( @payby $cgi $locales $packages
+             $pops %pop %popnum2pop
+             $init_data $error
              $last $first $ss $company $address1 $address2 $city $state $county
              $country $zip $daytime $night $fax $invoicing_list $payby $payinfo
              $paydate $payname $referral_custnum
@@ -137,6 +139,12 @@ if ( -e $decline_html ) {
 ( $locales, $packages, $pops, $init_data ) = signup_info();
 @payby = @{$init_data->{'payby'}} if @{$init_data->{'payby'}};
 $packages = $init_data->{agentnum2part_pkg}{$agentnum} if $agentnum;
+%pop = ();
+%popnum2pop = ();
+foreach (@$pops) {
+  push @{ $pop{ $_->{state} }->{ $_->{ac} } }, $_;
+  $popnum2pop{$_->{popnum}} = $_;
+}
 
 $cgi = new CGI;
 
@@ -328,7 +336,7 @@ sub print_okay {
     or die "fatal: invalid email_name got past FS::SignupClient::new_customer";
   $email_name = $1; #global for template
 
-  my $pop = pop_info($cgi->param('popnum'));
+  my $pop = $popnum2pop{$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'} );
@@ -366,15 +374,6 @@ sub print_okay {
   }
 }
 
-sub pop_info {
-  my $popnum = shift;
-  my $pop;
-  foreach $pop ( @{$pops} ) {
-    if ( $pop->{'popnum'} == $popnum ) { return $pop; }
-  }
-  '';
-}
-
 #horrible false laziness with FS/FS/svc_acct_pop.pm::popselector
 sub popselector {
 
@@ -386,10 +385,12 @@ sub popselector {
          '<INPUT TYPE="hidden" NAME="popnum" VALUE="'. $pops->[0]{popnum}. '">'
     if scalar(@$pops) == 1;
 
-  my %pop = ();
-  foreach (@$pops) {
-    push @{ $pop{ $_->{state} }->{ $_->{ac} } }, $_;
-  }
+  #my %pop = ();
+  #my %popnum2pop = ();
+  #foreach (@$pops) {
+  #  push @{ $pop{ $_->{state} }->{ $_->{ac} } }, $_;
+  #  $popnum2pop{$_->{popnum}} = $_;
+  #}
 
   my $text = <<END;
     <SCRIPT>
@@ -460,8 +461,14 @@ END
 
   $text .= qq!<TR><TD><SELECT NAME="popnum" SIZE=1 STYLE="width: 20em"><OPTION>City!;
 
+
   #comment this block to disable initial list polulation
-  foreach my $pop ( sort { $a->{state} cmp $b->{state} } @$pops ) {
+  if ( scalar( @$pops ) > 100 ) {
+    @initial_select = ( $popnum2pop{$popnum} );
+  } else {
+    @initial_select = $@pops;
+  }
+  foreach my $pop ( sort { $a->{state} cmp $b->{state} } @initial_select ) {
     $text .= qq!<OPTION VALUE="!. $pop->{popnum}. '"'.
              ( ( $popnum && $pop->{popnum} == $popnum ) ? ' SELECTED' : '' ). ">".
              $pop->{city}. ', '. $pop->{state}.