--- loncom/interface/lonsearchcat.pm 2002/08/04 18:28:01 1.151 +++ loncom/interface/lonsearchcat.pm 2002/08/07 12:37:16 1.152 @@ -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 @@ sub handler { '_'.&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 @@ END = &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 @@ LASTREVISIONDATEEND (&Apache::loncommon::copyrightids), ); # ------------------------------------------- Compute customized metadata field - $scrout.=< -LIMIT BY SPECIAL METADATA FIELDS: - -For resource-specific metadata, enter in an expression in the form of -key=value separated by operators such as AND, OR or NOT.
-Example: grandmother=75 OR grandfather=85 -
-CUSTOMMETADATA - $scrout.=&simpletextfield('custommetadata',$ENV{'form.custommetadata'}); - $scrout.=< -SHOW SPECIAL METADATA FIELDS: - -Enter in a space-separated list of special metadata fields to show -in a fielded listing for each record result. -
-CUSTOMSHOW - $scrout.=&simpletextfield('customshow',$ENV{'form.customshow'}); +# $scrout.=< +#LIMIT BY SPECIAL METADATA FIELDS: +# +#For resource-specific metadata, enter in an expression in the form of +#key=value separated by operators such as AND, OR or NOT.
+#Example: grandmother=75 OR grandfather=85 +#
+#CUSTOMMETADATA +# $scrout.=&simpletextfield('custommetadata',$ENV{'form.custommetadata'}); +# $scrout.=< +#SHOW SPECIAL METADATA FIELDS: +# +#Enter in a space-separated list of special metadata fields to show +#in a fielded listing for each record result. +#
+#CUSTOMSHOW +# $scrout.=&simpletextfield('customshow',$ENV{'form.customshow'}); $scrout.=< @@ -671,7 +670,6 @@ to them. ###################################################################### ###################################################################### 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 @@ sub get_persistent_form_data { # 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 @@ sub get_persistent_data { 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 @@ elements escaped and concatenated in a c ###################################################################### ###################################################################### 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 @@ sub make_form_data_persistent { next if (!/^form/ || /submit/); $save{$_} = $ENV{$_}; } - return &make_persistent($r,\%save,$filename); + return &make_persistent(\%save,$filename); } ###################################################################### @@ -1230,21 +1216,21 @@ sub parse_advanced_search { } # Process form information for custom metadata querying my $customquery=undef; - if ($ENV{'form.custommetadata'}) { - $pretty_search_string .=$font."Custom Metadata Search: ". - $ENV{'form.custommetadata'}."
\n"; - $customquery=&build_custommetadata_query('custommetadata', - $ENV{'form.custommetadata'}); - } +# if ($ENV{'form.custommetadata'}) { +# $pretty_search_string .=$font."Custom Metadata Search: ". +# $ENV{'form.custommetadata'}."
\n"; +# $customquery=&build_custommetadata_query('custommetadata', +# $ENV{'form.custommetadata'}); +# } my $customshow=undef; - if ($ENV{'form.customshow'}) { - $pretty_search_string .=$font."Custom Metadata Display: ". - $ENV{'form.customshow'}."
\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: ". +# $ENV{'form.customshow'}."
\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 @@ sub parse_advanced_search { $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 .= "$_ "; + $pretty_domains_string .= "".$_." "; } foreach (keys(%Apache::lonnet::libserv)) { if (exists($domain_hash{$Apache::lonnet::hostdom{$_}})) { @@ -1909,9 +1895,9 @@ END # Check to see if $pretty_string has more than one carriage return. # Assume \n s are following
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],'....
'); + my @Lines = split /
/,$pretty_string; + if (@Lines > 2) { + $pretty_string = join '
',(@Lines[0..2],'....
'); } $r->print("Search: ".$pretty_string); $r->rflush(); @@ -1920,7 +1906,11 @@ END # 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)); }