[LON-CAPA-cvs] cvs: loncom /interface lonsearchcat.pm

matthew lon-capa-cvs@mail.lon-capa.org
Thu, 27 Jun 2002 19:28:50 -0000


matthew		Thu Jun 27 15:28:50 2002 EDT

  Modified files:              
    /loncom/interface	lonsearchcat.pm 
  Log:
  &handler:
      Changed setting of $hidden to be a call to the new version of 
          &make_persistent.
  &advanced_search_form:
      Handle 'revise search request' cleanly.
  &make_persistent
      Takes a parmater as input now.
      Correctly handles non-scalar values.  Previously it output references 
          into hidden html forms, which did not work for some reason.
  &output_results
      Removed debugging code.
  
  
Index: loncom/interface/lonsearchcat.pm
diff -u loncom/interface/lonsearchcat.pm:1.132 loncom/interface/lonsearchcat.pm:1.133
--- loncom/interface/lonsearchcat.pm:1.132	Thu Jun 27 10:46:00 2002
+++ loncom/interface/lonsearchcat.pm	Thu Jun 27 15:28:50 2002
@@ -1,7 +1,7 @@
 # The LearningOnline Network with CAPA
 # Search Catalog
 #
-# $Id: lonsearchcat.pm,v 1.132 2002/06/27 14:46:00 matthew Exp $
+# $Id: lonsearchcat.pm,v 1.133 2002/06/27 19:28:50 matthew Exp $
 #
 # Copyright Michigan State University Board of Trustees
 #
@@ -212,12 +212,10 @@
 onClick='javascript:select_group()'>
 END
     }
-    $hidden .= <<END;
-<input type='hidden' name='mode'    value='$ENV{'form.mode'}'>
-<input type='hidden' name='form'    value='$ENV{'form.form'}'>
-<input type='hidden' name='element' value='$ENV{'form.element'}'>
-<input type='hidden' name='date' value='2'>
-END
+    $hidden .= &make_persistent({ "form.mode"    => $ENV{'form.mode'},
+                                  "form.form"    => $ENV{'form.form'},
+                                  "form.element" => $ENV{'form.element'},
+                                  "form.date"    => 2 });
     ##
     ##  What are we doing?
     ##
@@ -395,10 +393,17 @@
 			undef,
 			(&Apache::loncommon::filecategories()));
     $ENV{'form.language'}='any' unless length($ENV{'form.language'});
-    #
+    #----------------------------------------------------------------
     # Allow restriction to multiple domains.
     #   I make the crazy assumption that there will never be a domain 'any'.
     #
+    $ENV{'form.domains'} = 'any' if (! exists($ENV{'form.domains'}));
+    my @allowed_domains = (ref($ENV{'form.domains'}) ? @{$ENV{'form.domains'}} 
+                           :  ($ENV{'form.domains'}) );
+    my %domain_hash = ();
+    foreach (@allowed_domains) {
+        $domain_hash{$_}++;
+    }
     my @domains =&Apache::loncommon::get_domains();
     # adjust the size of the select box
     my $size = 4;
@@ -407,16 +412,19 @@
     if ((scalar @domains) == 1) {
         $scrout .='<input type="hidden" name="domains" value="any" />'."\n";
     } else {
-        $scrout.='<font color="#800000" face="helvetica"><b>'.
+        $scrout.="\n".'<font color="#800000" face="helvetica"><b>'.
             'DOMAINS</b></font><br />'.
                 '<select name="domains" size="'.$size.'" multiple>'."\n".
-                    '<option name="any" selected>all domains</option>'."\n";
+                    '<option name="any" value="any" '.
+                        ($domain_hash{'any'}? 'selected ' :'').
+                        '>all domains</option>'."\n";
         foreach my $dom (sort @domains) {
-            $scrout.="<option name=\"$dom\">$dom</option>\n";
+            $scrout.="<option name=\"$dom\" ".
+                ($domain_hash{$dom} ? 'selected ' :'').">$dom</option>\n";
         }
         $scrout.="</select>\n";
     }
-    #
+    #----------------------------------------------------------------
     # 
     #
     $scrout.=&selectbox('Limit by language','language',
@@ -517,16 +525,19 @@
 ######################################################################
 
 sub make_persistent {
+    my %save = %{shift()};
     my $persistent='';
-    foreach (keys %ENV) {
+    foreach (keys %save) {
 	if (/^form\./ && !/submit/) {
 	    my $name=$_;
-	    my $key=$name;
-	    $ENV{$key}=~s/\'//g; # do not mess with html field syntax
+            my @values = (ref($save{$name}) ? @{$save{$name}} : ($save{$name}));
 	    $name=~s/^form\.//;
-	    $persistent.=<<END;
-<input type="hidden" name="$name" value="$ENV{$key}" />
+            foreach (@values) {
+                s/\"/\'/g; # do not mess with html field syntax
+                $persistent.=<<END;
+<input type="hidden" name="$name" value="$_" />
 END
+            }
         }
     }
     return $persistent;
@@ -810,7 +821,7 @@
 	my @fields=split(/\s+/,$customshow);
 	$customshow=join(" ",@fields);
     }
-    ##
+    ## ---------------------------------------------------------------
     ## Deal with restrictions to given domains
     ## 
     my $libraries_to_query = undef;
@@ -831,11 +842,7 @@
             push @$libraries_to_query,$_;
         }
     }
-    if (defined($libraries_to_query)) {
-        &Apache::lonnet::logthis("libraries: @$libraries_to_query");
-    } else {
-        &Apache::lonnet::logthis("libraries: undef");
-    }
+    ## ---------------------------------------------------------------
     #
     # Send query statements over the network to be processed by either the SQL
     # database or a recursive scheme of 'grep'-like actions (for custom
@@ -1116,7 +1123,7 @@
     my $viewselect=$ENV{'form.viewselect'};
     #
     # make query information persistent to allow for subsequent revision
-    my $persistent=&make_persistent();
+    my $persistent=&make_persistent(\%ENV);
     # spit out the results header
     $r->print(&search_results_header($mode));
     $r->rflush();
@@ -1858,7 +1865,7 @@
 sub output_blank_field_error {
     my ($r)=@_;
     # make query information persistent to allow for subsequent revision
-    my $persistent=&make_persistent();
+    my $persistent=&make_persistent(\%ENV);
 
     $r->print(<<BEGINNING);
 <html>
@@ -1904,7 +1911,7 @@
 sub output_date_error {
     my ($r,$message)=@_;
     # make query information persistent to allow for subsequent revision
-    my $persistent=&make_persistent();
+    my $persistent=&make_persistent(\%ENV);
 
     $r->print(<<RESULTS);
 <html>