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

matthew lon-capa-cvs@mail.lon-capa.org
Wed, 07 Aug 2002 12:37:16 -0000


This is a MIME encoded message

--matthew1028723836
Content-Type: text/plain

matthew		Wed Aug  7 08:37:16 2002 EDT

  Modified files:              
    /loncom/interface	lonsearchcat.pm 
  Log:
  Fixed bug in domain limited searches.  Cleaned up old debugging code.
  Commented out custom metadata input and output code, since it doesn't work 
  right now anyway.
  
  
--matthew1028723836
Content-Type: text/plain
Content-Disposition: attachment; filename="matthew-20020807083716.txt"

Index: loncom/interface/lonsearchcat.pm
diff -u loncom/interface/lonsearchcat.pm:1.151 loncom/interface/lonsearchcat.pm:1.152
--- loncom/interface/lonsearchcat.pm:1.151	Sun Aug  4 14:28:01 2002
+++ loncom/interface/lonsearchcat.pm	Wed Aug  7 08:37:16 2002
@@ -1,7 +1,7 @@
 # The LearningOnline Network with CAPA
 # Search Catalog
 #
-# $Id: lonsearchcat.pm,v 1.151 2002/08/04 18:28:01 matthew Exp $
+# $Id: lonsearchcat.pm,v 1.152 2002/08/07 12:37:16 matthew Exp $
 #
 # Copyright Michigan State University Board of Trustees
 #
@@ -206,7 +206,7 @@
             '_'.&Apache::lonnet::escape($ENV{'user.name'}).
                 '_'.$ENV{'form.persistent_db_id'}.'_persistent_search.db';
     ##
-    if (! &get_persistent_form_data($r,$persistent_db_file)) {
+    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");
@@ -360,8 +360,7 @@
                 = &parse_advanced_search($r,$closebutton);
             return OK if (! defined($query));
         }
-        &make_persistent($r,
-                         { query => $query,
+        &make_persistent({ query => $query,
                            customquery => $customquery,
                            customshow => $customshow,
                            libraries => $libraries,
@@ -620,25 +619,25 @@
 			 (&Apache::loncommon::copyrightids),
 			 );
 # ------------------------------------------- Compute customized metadata field
-    $scrout.=<<CUSTOMMETADATA;
-<p>
-<font color="#800000" face="helvetica"><b>LIMIT BY SPECIAL METADATA FIELDS:</b>
-</font>
-For resource-specific metadata, enter in an expression in the form of 
-<i>key</i>=<i>value</i> separated by operators such as AND, OR or NOT.<br />
-<b>Example:</b> grandmother=75 OR grandfather=85
-<br />
-CUSTOMMETADATA
-    $scrout.=&simpletextfield('custommetadata',$ENV{'form.custommetadata'});
-    $scrout.=<<CUSTOMSHOW;
-<p>
-<font color="#800000" face="helvetica"><b>SHOW SPECIAL METADATA FIELDS:</b>
-</font>
-Enter in a space-separated list of special metadata fields to show
-in a fielded listing for each record result.
-<br />
-CUSTOMSHOW
-    $scrout.=&simpletextfield('customshow',$ENV{'form.customshow'});
+#    $scrout.=<<CUSTOMMETADATA;
+#<p>
+#<font color="#800000" face="helvetica"><b>LIMIT BY SPECIAL METADATA FIELDS:</b>
+#</font>
+#For resource-specific metadata, enter in an expression in the form of 
+#<i>key</i>=<i>value</i> separated by operators such as AND, OR or NOT.<br />
+#<b>Example:</b> grandmother=75 OR grandfather=85
+#<br />
+#CUSTOMMETADATA
+#    $scrout.=&simpletextfield('custommetadata',$ENV{'form.custommetadata'});
+#    $scrout.=<<CUSTOMSHOW;
+#<p>
+#<font color="#800000" face="helvetica"><b>SHOW SPECIAL METADATA FIELDS:</b>
+#</font>
+#Enter in a space-separated list of special metadata fields to show
+#in a fielded listing for each record result.
+#<br />
+#CUSTOMSHOW
+#    $scrout.=&simpletextfield('customshow',$ENV{'form.customshow'});
     $scrout.=<<ENDDOCUMENT;
 $advanced_buttons
 </form>
@@ -671,7 +670,6 @@
 ######################################################################
 ######################################################################
 sub get_persistent_form_data {
-    my $r = shift;
     my $filename = shift;
     return 0 if (! -e $filename);
     return undef if (! tie(%persistent_db,'GDBM_File',$filename,
@@ -683,24 +681,15 @@
     # Loop through the keys, looking for 'form.'
     foreach my $name (keys(%persistent_db)) {
         next if ($name !~ /^form./);
+        next if (exists($ENV{$name}));
         my @values = map { 
             &Apache::lonnet::unescape($_);
         } split(',',$persistent_db{$name});
         next if (@values <1);
-        if (exists($ENV{$name})) {
-            if (ref($ENV{$name}) eq 'ARRAY') {
-                # If it is an array, tack @values on the end of it.
-                $ENV{$name} = [@$ENV{$name},@values];
-            } elsif (! ref($ENV{$name}) && $arrays_allowed{$name}) {
-                # if arrays are allowed, turn it into one and add @values
-                $ENV{$name} = [$ENV{$name},@values];
-            } # otherwise, assume the value in $ENV{$name} is better than ours.
+        if ($arrays_allowed{$name}) {
+            $ENV{$name} = [@values];
         } else {
-            if ($arrays_allowed{$name}) {
-                $ENV{$name} = [@values];
-            } else {
-                $ENV{$name} = $values[0] if ($values[0]);
-            }
+            $ENV{$name} = $values[0] if ($values[0]);
         }
     }
     untie (%persistent_db);
@@ -741,7 +730,7 @@
         my @values = map { 
             &Apache::lonnet::unescape($_);
         } split(',',$persistent_db{$name});
-        if (@values == 1) {
+        if (@values <= 1) {
             push @Values,$values[0];
         } else {
             push @Values,\@values;
@@ -769,14 +758,11 @@
 ######################################################################
 ######################################################################
 sub make_persistent {
-    my $r = shift;
     my %save = %{shift()};
     my $filename = shift;
     return undef if (! tie(%persistent_db,'GDBM_File',
                            $filename,&GDBM_WRCREAT(),0640));
     foreach my $name (keys(%save)) {
-        next if (! exists($save{$name}));
-        next if (! defined($save{$name}) || $save{$name} eq '');
         my @values = (ref($save{$name}) ? @{$save{$name}} : ($save{$name}));
         # We handle array references, but not recursively.
         my $store = join(',', map { &Apache::lonnet::escape($_); } @values );
@@ -811,7 +797,7 @@
         next if (!/^form/ || /submit/);
         $save{$_} = $ENV{$_};
     }
-    return &make_persistent($r,\%save,$filename);
+    return &make_persistent(\%save,$filename);
 }
 
 ######################################################################
@@ -1230,21 +1216,21 @@
     }
     # Process form information for custom metadata querying
     my $customquery=undef;
-    if ($ENV{'form.custommetadata'}) {
-        $pretty_search_string .=$font."Custom Metadata Search</font>: <b>".
-            $ENV{'form.custommetadata'}."</b><br />\n";
-	$customquery=&build_custommetadata_query('custommetadata',
-				      $ENV{'form.custommetadata'});
-    }
+#    if ($ENV{'form.custommetadata'}) {
+#        $pretty_search_string .=$font."Custom Metadata Search</font>: <b>".
+#            $ENV{'form.custommetadata'}."</b><br />\n";
+#	$customquery=&build_custommetadata_query('custommetadata',
+#				      $ENV{'form.custommetadata'});
+#    }
     my $customshow=undef;
-    if ($ENV{'form.customshow'}) {
-        $pretty_search_string .=$font."Custom Metadata Display</font>: <b>".
-            $ENV{'form.customshow'}."</b><br />\n";
-	$customshow=$ENV{'form.customshow'};
-	$customshow=~s/[^\w\s]//g;
-	my @fields=split(/\s+/,$customshow);
-	$customshow=join(" ",@fields);
-    }
+#    if ($ENV{'form.customshow'}) {
+#        $pretty_search_string .=$font."Custom Metadata Display</font>: <b>".
+#            $ENV{'form.customshow'}."</b><br />\n";
+#	$customshow=$ENV{'form.customshow'};
+#	$customshow=~s/[^\w\s]//g;
+#	my @fields=split(/\s+/,$customshow);
+#	$customshow=join(" ",@fields);
+#    }
     ## ---------------------------------------------------------------
     ## Deal with restrictions to given domains
     ## 
@@ -1259,15 +1245,15 @@
         $domain_hash{$_}++;
     }
     if ($domain_hash{'any'}) {
-        $pretty_domains_string = "Searching all domains.";
+        $pretty_domains_string = "In all LON-CAPA domains.";
     } else {
         if (@allowed_domains > 1) {
-            $pretty_domains_string = "Searching domains:";
+            $pretty_domains_string = "In LON-CAPA domains:";
         } else {
-            $pretty_domains_string = "Searching domain ";
+            $pretty_domains_string = "In LON-CAPA domain ";
         }
         foreach (sort @allowed_domains) {
-            $pretty_domains_string .= "<b>$_</b> ";
+            $pretty_domains_string .= "<b>".$_."</b> ";
         }
         foreach (keys(%Apache::lonnet::libserv)) {
             if (exists($domain_hash{$Apache::lonnet::hostdom{$_}})) {
@@ -1909,9 +1895,9 @@
     # Check to see if $pretty_string has more than one carriage return.
     # Assume \n s are following <br /> s and truncate the value.
     # (there is probably a better way)...
-    my @Lines = split /\n/,$pretty_string;
-    if (@Lines > 1) {
-        $pretty_string = join /\n/,(@Lines[0..1],'....<br />');
+    my @Lines = split /<br \/>/,$pretty_string;
+    if (@Lines > 2) {
+        $pretty_string = join '<br \>',(@Lines[0..2],'....<br />');
     }
     $r->print("Search: ".$pretty_string);
     $r->rflush();
@@ -1920,7 +1906,11 @@
     #
     my @Servers_to_contact;
     if (defined($serverlist)) {
-        @Servers_to_contact = @$serverlist;
+        if (ref($serverlist) eq 'ARRAY') {
+            @Servers_to_contact = @$serverlist;
+        } else {
+            @Servers_to_contact = ($serverlist);
+        }
     } else {
         @Servers_to_contact = sort(keys(%Apache::lonnet::libserv));
     }

--matthew1028723836--