--- loncom/interface/lonsearchcat.pm 2002/06/24 16:45:22 1.128
+++ 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.128 2002/06/24 16:45:22 harris41 Exp $
+# $Id: lonsearchcat.pm,v 1.132 2002/06/27 14:46:00 matthew Exp $
#
# Copyright Michigan State University Board of Trustees
#
@@ -223,10 +223,10 @@ END
##
if ($ENV{'form.basicsubmit'} eq 'SEARCH') {
# Perform basic search and give results
- return &basicsearch($r,\%ENV,$hidden);
+ return &basicsearch($r,$hidden);
} elsif ($ENV{'form.advancedsubmit'} eq 'SEARCH') {
# Perform advanced search and give results
- return &advancedsearch($r,\%ENV,$hidden);
+ return &advancedsearch($r,$hidden);
} elsif ($ENV{'form.reqinterface'} eq 'advanced') {
# Output the advanced interface
$r->print(&advanced_search_form($closebutton,$hidden));
@@ -273,7 +273,8 @@ sub basic_search_form{
$hidden
Basic Search
-Enter terms or phrases separated by AND, OR, or NOT then press SEARCH below.
+Enter terms or phrases separated by AND, OR, or NOT
+then press SEARCH below.
@@ -289,15 +290,14 @@ ENDDOCUMENT
$closebutton
-
-
@@ -322,6 +322,14 @@ Returns a scalar which holds html for th
sub advanced_search_form{
my ($closebutton,$hidden) = @_;
+ my $advanced_buttons = <<"END";
+
+
+
+$closebutton
+
+
+END
my $scrout=<<"ENDHEADER";
@@ -336,35 +344,81 @@ sub advanced_search_form{
-
Search Catalog
+
Advanced Catalog Search
+
+Enter terms or phrases separated by search operators
+such as AND, OR, or NOT.
@@ -534,7 +572,46 @@ the day, month, and year.
=item &selectbox()
-Returns html selection form.
+Returns a scalar containing an html form.
+
+Inputs:
+
+=over 4
+
+=item $title
+
+Printed above the select box, in uppercase.
+
+=item $name
+
+The name element of the tag.
+
+=item $default
+
+The default value of the form. Can be $anyvalue or in @idlist.
+
+=item $anyvalue
+
+The ';
}
else {$selout.='>'.&{$functionref}($_).'';}
}
- return $selout.'';
+ return $selout.'';
}
######################################################################
@@ -644,8 +719,7 @@ Parse advanced search results.
######################################################################
######################################################################
sub advancedsearch {
- my ($r,$envhash,$hidden)=@_;
- my %ENV=%{$envhash};
+ my ($r,$hidden)=@_;
my $fillflag=0;
# Clean up fields for safety
for my $field ('title','author','subject','keywords','url','version',
@@ -656,7 +730,7 @@ sub advancedsearch {
'lastrevisiondatestart_year','lastrevisiondateend_month',
'lastrevisiondateend_day','lastrevisiondateend_year',
'notes','abstract','mime','language','owner',
- 'custommetadata','customshow') {
+ 'custommetadata','customshow','category') {
$ENV{"form.$field"}=~s/[^\w\/\s\(\)\=\-\"\']//g;
}
foreach ('mode','form','element') {
@@ -665,6 +739,12 @@ sub advancedsearch {
$ENV{"form.$_"}=&Apache::lonnet::unescape($ENV{"form.$_"});
$ENV{"form.$_"}=~s/[^\w\/\s\(\)\=\-\"\']//g;
}
+ # Preprocess the category form element.
+ if ($ENV{'form.category'} ne 'any') {
+ my @extensions = &Apache::loncommon::filecategorytypes
+ ($ENV{'form.category'});
+ $ENV{'form.mime'} = join ' OR ',@extensions;
+ }
# Check to see if enough information was filled in
for my $field ('title','author','subject','keywords','url','version',
'notes','abstract','mime','language','owner',
@@ -682,18 +762,15 @@ sub advancedsearch {
my @queries;
# Evaluate logical expression AND/OR/NOT phrase fields.
foreach my $field ('title','author','subject','notes','abstract','url',
- 'keywords','version','owner') {
+ 'keywords','version','owner','mime') {
if ($ENV{'form.'.$field}) {
push @queries,&build_SQL_query($field,$ENV{'form.'.$field});
- }
+ }
}
# Evaluate option lists
if ($ENV{'form.language'} and $ENV{'form.language'} ne 'any') {
push @queries,"(language like \"$ENV{'form.language'}\")";
}
- if ($ENV{'form.mime'} and $ENV{'form.mime'} ne 'any') {
- push @queries,"(mime like \"$ENV{'form.mime'}\")";
- }
if ($ENV{'form.copyright'} and $ENV{'form.copyright'} ne 'any') {
push @queries,"(copyright like \"$ENV{'form.copyright'}\")";
}
@@ -733,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).
@@ -741,19 +845,22 @@ 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,$envhash,$customquery,$reply,$hidden);
+ &output_results('Advanced',$r,$customquery,$reply,$hidden);
return OK;
} elsif ($customquery) {
my $reply; # reply hash reference
$reply=&Apache::lonnet::metadata_query('',
- $customquery,$customshow);
- &output_results('Advanced',$r,$envhash,$customquery,$reply,$hidden);
+ $customquery,$customshow,
+ $libraries_to_query);
+ &output_results('Advanced',$r,$customquery,$reply,$hidden);
return OK;
}
# should not get to this point
@@ -774,8 +881,7 @@ Parse basic search form.
######################################################################
######################################################################
sub basicsearch {
- my ($r,$envhash,$hidden)=@_;
- my %ENV=%{$envhash};
+ my ($r,$hidden)=@_;
# Clean up fields for safety
for my $field ('basicexp') {
$ENV{"form.$field"}=~s/[^\w\s\(\)\-]//g;
@@ -808,7 +914,7 @@ sub basicsearch {
# &Apache::lonnet::logthis("metadata query finished:".time);
# Output search results
- &output_results('Basic',$r,$envhash,$query,$reply,$hidden);
+ &output_results('Basic',$r,$query,$reply,$hidden);
return OK;
}
@@ -1000,29 +1106,29 @@ contacted, etc.)
sub output_results {
# &Apache::lonnet::logthis("output_results:".time);
my $fnum; # search result counter
- my ($mode,$r,$envhash,$query,$replyref,$hidden)=@_;
- my %ENV=%{$envhash};
+ my ($mode,$r,$query,$replyref,$hidden)=@_;
my %rhash=%{$replyref};
my $compiledresult='';
my $timeremain=300; # (seconds)
my $elapsetime=0;
my $resultflag=0;
my $tflag=1;
+ my $viewselect=$ENV{'form.viewselect'};
#
# make query information persistent to allow for subsequent revision
my $persistent=&make_persistent();
- # spit out the generic header
- $r->print(&search_results_header());
+ # spit out the results header
+ $r->print(&search_results_header($mode));
$r->rflush();
# begin showing the cataloged results
- $r->print(<
-
-
-
');
- $r->rflush();
- #
# make the pop-up window for status
#
$r->print(&make_popwin(%rhash));
@@ -1147,9 +1242,6 @@ CATALOGCONTROLS
$Fields{'extrashow'}=~s/\<\!\-\- $field \-\-\>/ $value/g;
}
}
- if ($compiledresult or $servercount!=$servernum) {
- $compiledresult.="";
- }
$compiledresult.="\n
\n";
if ($ENV{'form.catalogmode'} eq 'interactive') {
my $titleesc=$Fields{'title'};
@@ -1176,13 +1268,6 @@ END
#
$fnum++;
}
- my $viewselect;
- if ($mode eq 'Basic') {
- $viewselect=$ENV{'form.basicviewselect'};
- }
- elsif ($mode eq 'Advanced') {
- $viewselect=$ENV{'form.advancedviewselect'};
- }
if ($viewselect eq 'Detailed Citation View') {
$compiledresult.=&detailed_citation_view
(%Fields, hostname => $rkey );
@@ -1199,6 +1284,9 @@ END
$compiledresult.=&xml_sgml_view
(%Fields, hostname => $rkey );
}
+ if ($compiledresult or $servercount!=$servernum) {
+ $compiledresult.="
";
+ }
}
untie %hash;
}
@@ -1347,10 +1435,18 @@ sub handle_custom_fields {
=item &search_results_header
-Output the proper javascript code to deal with different calling modes.
+Output the proper html headers and javascript code to deal with different
+calling modes.
+
+Takes most inputs directly from %ENV, except $mode.
+
+=over 4
+
+=item $mode is either (at this writing) 'Basic' or 'Advanced'
+
+=back
-Takes inputs directly from from %ENV. The following environment variables
-are checked:
+The following environment variables are checked:
=over 4
@@ -1373,12 +1469,20 @@ Checked for existance & 'edit' mode.
######################################################################
######################################################################
sub search_results_header {
+ my ($mode) = @_;
+ $mode = lc($mode);
+ my $title;
+ if ($mode eq 'advanced') {
+ $title = "Advanced Search Results";
+ } elsif ($mode eq 'basic') {
+ $title = "Basic Search Results";
+ }
my $result = '';
# output beginning of search page
$result.=<
-The LearningOnline Network with CAPA
+$title
BEGINNING
# conditional output of script functions dependent on the mode in
# which the search was invoked
@@ -1461,6 +1565,12 @@ SCRIPT
}
SCRIPT
+ $result.=<
+
+
+
$title
+END
return $result;
}
@@ -1584,30 +1694,17 @@ extra custom metadata to show.
sub detailed_citation_view {
my %values = @_;
my $result=<$values{'owner'}, last revised $values{'lastrevisiondate'}