--- loncom/interface/lonsearchcat.pm 2002/06/26 18:19:41 1.131 +++ loncom/interface/lonsearchcat.pm 2002/06/27 14:46:00 1.132 @@ -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.132 2002/06/27 14:46:00 matthew Exp $ # # Copyright Michigan State University Board of Trustees # @@ -389,12 +389,36 @@ 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'. + # + 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.=''. + 'DOMAINS
'. + '\n"; + } + # + # + # $scrout.=&selectbox('Limit by language','language', $ENV{'form.language'},'any','Any Language', \&{Apache::loncommon::languagedescription}, @@ -786,6 +810,33 @@ 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,$_; + } + } + 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 # metadata). @@ -794,18 +845,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; }