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

matthew lon-capa-cvs@mail.lon-capa.org
Tue, 04 May 2004 15:20:17 -0000


matthew		Tue May  4 11:20:17 2004 EDT

  Modified files:              
    /loncom/interface	lonsearchcat.pm 
  Log:
  Fix bug 2537: Once you do a search with related words you always search 
  with related words, even if you uncheck the box.  Added 
  &clean_up_environment to set checkbox values to '' so they will overwrite the
  values in the persistent data cache.
  Modified &parse_domain_restrictions to not restrict the domain when passed
  a value of ''.
  Modified &handler to not load in saved parameters when we receive a new
  search request and instead call &clean_up_environment.
  
  
Index: loncom/interface/lonsearchcat.pm
diff -u loncom/interface/lonsearchcat.pm:1.220 loncom/interface/lonsearchcat.pm:1.221
--- loncom/interface/lonsearchcat.pm:1.220	Mon May  3 15:24:14 2004
+++ loncom/interface/lonsearchcat.pm	Tue May  4 11:20:17 2004
@@ -1,7 +1,7 @@
 # The LearningOnline Network with CAPA
 # Search Catalog
 #
-# $Id: lonsearchcat.pm,v 1.220 2004/05/03 19:24:14 matthew Exp $
+# $Id: lonsearchcat.pm,v 1.221 2004/05/04 15:20:17 matthew Exp $
 #
 # Copyright Michigan State University Board of Trustees
 #
@@ -117,7 +117,7 @@
 
     my $loaderror=&Apache::lonnet::overloaderror($r);
     if ($loaderror) { return $loaderror; }
-
+    #
     my $closebutton;  # button that closes the search window 
                       # This button is different for the RAT compared to
                       # normal invocation.
@@ -185,11 +185,13 @@
               bug=>'Searching',});
     }
     #
-    if (! &get_persistent_form_data($persistent_db_file)) {
-        if ($ENV{'form.phase'} =~ /(run_search|results)/) {
-            &Apache::lonnet::logthis("lonsearchcat:Unable to recover data ".
-                                     "from $persistent_db_file");
-            $r->print(<<END);
+    if ($ENV{'form.phase'} !~ m/(basic|adv|course)_search/) {
+        if (! &get_persistent_form_data($persistent_db_file)) {
+            if ($ENV{'form.phase'} =~ /(run_search|results)/) {
+                &Apache::lonnet::logthis('lonsearchcat:'.
+                                         'Unable to recover data from '.
+                                         $persistent_db_file);
+                $r->print(<<END);
 <html>
 <head><title>LON-CAPA Search Error</title></head>
 $bodytag
@@ -198,8 +200,11 @@
 </body>
 </html>
 END
-            return OK;
+                return OK;
+            }
         }
+    } else {
+        &clean_up_environment();
     }
     ##
     ## Clear out old values from groupsearch database
@@ -389,6 +394,34 @@
     return OK;
 } 
 
+#
+# The mechanism used to store values away and retrieve them does not
+# handle the case of missing environment variables being significant.
+#
+# This routine sets non existant checkbox form elements to ''.
+#
+sub clean_up_environment {
+    if ($ENV{'form.phase'} eq 'basic_search') {
+        if (! exists($ENV{'form.related'})) {
+            $ENV{'form.related'} = '';
+        }
+        if (! exists($ENV{'form.domains'})) {
+            $ENV{'form.domains'} = '';
+        }
+    } elsif ($ENV{'form.phase'} eq 'adv_search') {
+        foreach my $field ('title','keywords','notes',
+                           'abstract','standards','mime') {
+            if (! exists($ENV{'form.'.$field.'_related'})) {
+                $ENV{'form.'.$field.'_related'} = '';
+            }
+        }
+    } elsif ($ENV{'form.phase'} eq 'course_search') {
+        if (! exists($ENV{'form.crsrelated'})) {
+            $ENV{'form.crsrelated'} = '';
+        }
+    }
+}
+
 ######################################################################
 ######################################################################
 ##
@@ -532,12 +565,15 @@
         my $userelatedwords=
             &mt('[_1] use related words',
                 &Apache::lonhtmlcommon::checkbox
-                ('related',$ENV{'form.related'}));
+                ('related',$ENV{'form.related'},'related'));
         my $onlysearchdomain=
             &mt('[_1] only search domain [_2]',
-                &Apache::lonhtmlcommon::checkbox
-                ('domains',$ENV{'form.domains'}),
-                $r->dir_config('lonDefDomain'));
+                &Apache::lonhtmlcommon::checkbox('domains',
+                                                 $ENV{'form.domains'},
+                                                 $r->dir_config('lonDefDomain')
+                                                 ),
+                $r->dir_config('lonDefDomain')
+                );
         my $adv_search_link = 
             '<a href="/adm/searchcat?'.
             'phase=disp_adv&'.
@@ -1361,7 +1397,7 @@
     my $libraries_to_query = undef;
     # $ENV{'form.domains'} can be either a scalar or an array reference.
     # We need an array.
-    if (! exists($ENV{'form.domains'})) {
+    if (! exists($ENV{'form.domains'}) || $ENV{'form.domains'} eq '') {
         return (undef,'');
     }
     my @allowed_domains;