[LON-CAPA-cvs] cvs: loncom /interface lonsearchcat.pm
matthew
lon-capa-cvs@mail.lon-capa.org
Thu, 27 Jun 2002 14:46:00 -0000
matthew Thu Jun 27 10:46:00 2002 EDT
Modified files:
/loncom/interface lonsearchcat.pm
Log:
Added domain restricted search interface to &advanced_search_form.
Support added in &advancedsearch.
NOTES:
Assumes no domain will be named 'any'.
Standalone machines do not get to choose - the dialog box does not appear.
Selections are not currently restored on 'revise search request'.
This is my next priority.
Selecting none of the domains is the same as selecting 'any'.
Selecting 'any domain' and other domains as well will search all domains.
There are no plans for machine-level restrictions at this time.
Index: loncom/interface/lonsearchcat.pm
diff -u loncom/interface/lonsearchcat.pm:1.131 loncom/interface/lonsearchcat.pm:1.132
--- loncom/interface/lonsearchcat.pm:1.131 Wed Jun 26 14:19:41 2002
+++ loncom/interface/lonsearchcat.pm Thu Jun 27 10:46:00 2002
@@ -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 @@
$ENV{'form.owner'});
$scrout.="</table>\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 .='<input type="hidden" name="domains" value="any" />'."\n";
+ } else {
+ $scrout.='<font color="#800000" face="helvetica"><b>'.
+ 'DOMAINS</b></font><br />'.
+ '<select name="domains" size="'.$size.'" multiple>'."\n".
+ '<option name="any" selected>all domains</option>'."\n";
+ foreach my $dom (sort @domains) {
+ $scrout.="<option name=\"$dom\">$dom</option>\n";
+ }
+ $scrout.="</select>\n";
+ }
+ #
+ #
+ #
$scrout.=&selectbox('Limit by language','language',
$ENV{'form.language'},'any','Any Language',
\&{Apache::loncommon::languagedescription},
@@ -786,6 +810,33 @@
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 @@
$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;
}