--- loncom/interface/lonsearchcat.pm 2002/07/03 19:11:09 1.134
+++ loncom/interface/lonsearchcat.pm 2002/07/09 17:27:11 1.140
@@ -1,7 +1,7 @@
# The LearningOnline Network with CAPA
# Search Catalog
#
-# $Id: lonsearchcat.pm,v 1.134 2002/07/03 19:11:09 matthew Exp $
+# $Id: lonsearchcat.pm,v 1.140 2002/07/09 17:27:11 matthew Exp $
#
# Copyright Michigan State University Board of Trustees
#
@@ -40,7 +40,7 @@
=head1 NAME
-lonsearchcat
+lonsearchcat - LONCAPA Search Interface
=head1 SYNOPSIS
@@ -118,6 +118,13 @@ The ubiquitous database hash
The full path to the (temporary) search database file. This is set and
used in &handler() and is also used in &output_results().
+=item %Views
+
+Hash which associates an output view description with the function
+that produces it. Adding a new view type should be as easy as
+adding a line to the definition of this hash and making sure the function
+takes the proper parameters.
+
=back
=cut
@@ -133,6 +140,12 @@ my $importbutton; # button to take the s
my %hash; # database hash
my $diropendb = ""; # db file
+# View Description Function Pointer
+my %Views = ("Detailed Citation View" => \&detailed_citation_view,
+ "Summary View" => \&summary_view,
+ "Fielded Format" => \&fielded_format_view,
+ "XML/SGML" => \&xml_sgml_view );
+
######################################################################
######################################################################
@@ -223,6 +236,7 @@ END
$searchtype = 'Basic' if ($ENV{'form.basicsubmit'} eq 'SEARCH');
$searchtype = 'Advanced' if ($ENV{'form.advancedsubmit'} eq 'SEARCH');
if ($searchtype) {
+ # We are running a search
my ($query,$customquery,$customshow,$libraries) =
(undef,undef,undef,undef);
if ($searchtype eq 'Basic') {
@@ -239,12 +253,21 @@ END
my $reply=&Apache::lonnet::metadata_query($query,$customquery,
$customshow,$libraries);
&output_results($searchtype,$r,$reply,$hidden);
- } elsif ($ENV{'form.reqinterface'} eq 'advanced') {
+ } else {
+ #
+ # We need to get information to search on
+ #
+ # Set the default view if it is not already set.
+ if (!defined($ENV{'form.viewselect'})) {
+ $ENV{'form.viewselect'} ="Detailed Citation View";
+ }
# Output the advanced interface
- $r->print(&advanced_search_form($closebutton,$hidden));
- } else {
- # Output normal search interface
- $r->print(&basic_search_form($closebutton,$hidden));
+ if ($ENV{'form.reqinterface'} eq 'advanced') {
+ $r->print(&advanced_search_form($closebutton,$hidden));
+ } else {
+ # Output normal search interface
+ $r->print(&basic_search_form($closebutton,$hidden));
+ }
}
return OK;
}
@@ -295,20 +318,18 @@ ENDDOCUMENT
' ';
# $scrout.=&simplecheckbox('allversions',$ENV{'form.allversions'});
# $scrout.='Search historic archives';
- $scrout.=<
\n";
$scrout.=&searchphrasefield('file extension','mime',
@@ -438,8 +449,6 @@ ENDHEADER
$scrout.="\n";
}
#----------------------------------------------------------------
- #
- #
$scrout.=&selectbox('Limit by language','language',
$ENV{'form.language'},'any','Any Language',
\&{Apache::loncommon::languagedescription},
@@ -604,7 +613,8 @@ Inputs:
=item $title
-Printed above the select box, in uppercase.
+Printed above the select box, in uppercase. If undefined, only a select
+box will be returned, with no additional html.
=item $name
@@ -612,12 +622,12 @@ The name element of the ';
+ return $selout.''.(defined($title)?'':' ');
}
######################################################################
@@ -803,6 +818,10 @@ sub parse_advanced_search {
push @queries,&build_SQL_query($field,$ENV{'form.'.$field});
}
}
+ # I dislike the hack below.
+ if ($ENV{'form.category'}) {
+ $ENV{'form.mime'}='';
+ }
# Evaluate option lists
if ($ENV{'form.language'} and $ENV{'form.language'} ne 'any') {
push @queries,"(language like \"$ENV{'form.language'}\")";
@@ -1114,13 +1133,23 @@ sub output_results {
my $elapsetime=0;
my $resultflag=0;
my $tflag=1;
- my $viewselect=$ENV{'form.viewselect'};
+ ##
+ ## Set viewing function
+ ##
+ my $viewfunction = $Views{$ENV{'form.viewselect'}};
+ if (!defined($viewfunction)) {
+ $r->print("Internal Error - Bad view selected.\n");
+ $r->rflush();
+ return;
+ }
#
# make query information persistent to allow for subsequent revision
my $persistent=&make_persistent(\%ENV);
- # spit out the results header
+ #
+ # Begin producing output
$r->print(&search_results_header($mode));
$r->rflush();
+ #
# begin showing the cataloged results
my $action = "/adm/searchcat";
if ($mode eq 'Basic') {
@@ -1141,7 +1170,6 @@ $persistent
CATALOGCONTROLS
#
# make the pop-up window for status
- #
$r->print(&make_popwin(%rhash));
$r->rflush();
##
@@ -1218,7 +1246,8 @@ CATALOGCONTROLS
} # end of if ($reply eq 'con_lost') else statement
my %Fields = undef; # Holds the data to be sent to the various
# *_view routines.
- my ($extrashow,$customfields,$customhash) = &handle_custom_fields(\@results);
+ my ($extrashow,$customfields,$customhash) =
+ &handle_custom_fields(\@results);
my @customfields = @$customfields;
my %customhash = %$customhash;
untie %hash if (keys %hash);
@@ -1235,6 +1264,21 @@ CATALOGCONTROLS
chomp $result;
next unless $result;
%Fields = &parse_raw_result($result,$rkey);
+ #
+ # Check copyright tags and skip results the user cannot use
+ my (undef,undef,$resdom,$resname) = split('/',$Fields{'url'});
+ # Check for priv
+ if (($Fields{'copyright'} eq 'priv') &&
+ (($ENV{'user.name'} ne $resname) &&
+ ($ENV{'user.domain'} ne $resdom))) {
+ next;
+ }
+ # Check for domain
+ if (($Fields{'copyright'} eq 'domain') &&
+ ($ENV{'user.domain'} ne $resdom)) {
+ next;
+ }
+ #
$Fields{'extrashow'}=$extrashow;
if ($extrashow) {
foreach my $field (@customfields) {
@@ -1269,22 +1313,8 @@ END
#
$fnum++;
}
- if ($viewselect eq 'Detailed Citation View') {
- $compiledresult.=&detailed_citation_view
- (%Fields, hostname => $rkey );
- }
- elsif ($viewselect eq 'Summary View') {
- $compiledresult.=&summary_view
- (%Fields, hostname => $rkey );
- }
- elsif ($viewselect eq 'Fielded Format') {
- $compiledresult.=&fielded_format_view
- (%Fields, hostname => $rkey );
- }
- elsif ($viewselect eq 'XML/SGML') {
- $compiledresult.=&xml_sgml_view
- (%Fields, hostname => $rkey );
- }
+ # Render the result into html
+ $compiledresult.= &$viewfunction(%Fields, hostname => $rkey );
if ($compiledresult or $servercount!=$servernum) {
$compiledresult.="";
}
@@ -1295,14 +1325,15 @@ END
$resultflag=1;
$r->print($compiledresult);
}
- my $percent=sprintf('%3.0f',($servercount/$servernum*100));
} # End of foreach loop over servers remaining
} # End of big loop - while($serversleft && $timeremain)
unless ($resultflag) {
$r->print("\nThere were no results that matched your query\n");
}
-# $r->print(''."\n"); $r->rflush();
+ $r->print(''.
+ "\n");
$r->print("\n\n");
+ $r->rflush();
return;
}
@@ -1600,16 +1631,13 @@ sub make_popwin {
# rows of 10 each. No longer used to index images.
my $sn=1;
foreach my $sk (sort keys %rhash) {
- # '