--- loncom/interface/lonsearchcat.pm 2002/06/26 18:19:41 1.131 +++ loncom/interface/lonsearchcat.pm 2002/06/27 19:28:50 1.133 @@ -1,7 +1,7 @@ # The LearningOnline Network with CAPA # Search Catalog # -# $Id: lonsearchcat.pm,v 1.131 2002/06/26 18:19:41 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 @@ END onClick='javascript:select_group()'> END } - $hidden .= < - - - -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? ## @@ -389,12 +387,46 @@ ENDHEADER $ENV{'form.owner'}); $scrout.="\n"; $ENV{'form.category'}='any' unless length($ENV{'form.category'}); - $scrout.=&selectbox('Limit by file category','category', + $scrout.=&selectbox('File Category','category', $ENV{'form.category'}, 'any','Any category', 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; + my $size = (scalar @domains < ($size - 1) ? scalar @domains + 1 : $size); + # standalone machines do not get to choose a domain to search. + if ((scalar @domains) == 1) { + $scrout .=''."\n"; + } else { + $scrout.="\n".''. + 'DOMAINS
'. + '\n"; + } + #---------------------------------------------------------------- + # + # $scrout.=&selectbox('Limit by language','language', $ENV{'form.language'},'any','Any Language', \&{Apache::loncommon::languagedescription}, @@ -493,16 +525,19 @@ to be somewhat persistent. ###################################################################### 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.=< + foreach (@values) { + s/\"/\'/g; # do not mess with html field syntax + $persistent.=< END + } } } return $persistent; @@ -786,6 +821,29 @@ sub advancedsearch { my @fields=split(/\s+/,$customshow); $customshow=join(" ",@fields); } + ## --------------------------------------------------------------- + ## Deal with restrictions to given domains + ## + my $libraries_to_query = undef; + # $ENV{'form.domains'} can be either a scalar or an array reference. + # We need an array. + my @allowed_domains = (ref($ENV{'form.domains'}) ? @{$ENV{'form.domains'}} + : ($ENV{'form.domains'}) ); + my %domain_hash = (); + foreach (@allowed_domains) { + $domain_hash{$_}++; + } + foreach (keys(%Apache::lonnet::libserv)) { + if ($_ eq 'any') { + $libraries_to_query = undef; + last; + } + if (exists($domain_hash{$Apache::lonnet::hostdom{$_}})) { + push @$libraries_to_query,$_; + } + } + ## --------------------------------------------------------------- + # # Send query statements over the network to be processed by either the SQL # database or a recursive scheme of 'grep'-like actions (for custom # metadata). @@ -794,18 +852,21 @@ sub advancedsearch { $query="select * from metadata where $query"; my $reply; # reply hash reference unless ($customquery or $customshow) { - $reply=&Apache::lonnet::metadata_query($query); + $reply=&Apache::lonnet::metadata_query($query,undef,undef, + $libraries_to_query); } else { $reply=&Apache::lonnet::metadata_query($query, - $customquery,$customshow); + $customquery,$customshow, + $libraries_to_query); } &output_results('Advanced',$r,$customquery,$reply,$hidden); return OK; } elsif ($customquery) { my $reply; # reply hash reference $reply=&Apache::lonnet::metadata_query('', - $customquery,$customshow); + $customquery,$customshow, + $libraries_to_query); &output_results('Advanced',$r,$customquery,$reply,$hidden); return OK; } @@ -1062,7 +1123,7 @@ sub output_results { 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(); @@ -1804,7 +1865,7 @@ sub filled { 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(< @@ -1850,7 +1911,7 @@ Output a full html page with an error me 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(<