--- loncom/interface/lonsearchcat.pm 2001/12/11 02:18:13 1.109
+++ loncom/interface/lonsearchcat.pm 2003/01/06 13:54:25 1.162
@@ -1,7 +1,7 @@
# The LearningOnline Network with CAPA
# Search Catalog
#
-# $Id: lonsearchcat.pm,v 1.109 2001/12/11 02:18:13 harris41 Exp $
+# $Id: lonsearchcat.pm,v 1.162 2003/01/06 13:54:25 www Exp $
#
# Copyright Michigan State University Board of Trustees
#
@@ -25,22 +25,48 @@
#
# http://www.lon-capa.org/
#
-# YEAR=2001
-# 3/8, 3/12, 3/13, 3/14, 3/15, 3/19 Scott Harrison
-# 3/20, 3/21, 3/22, 3/26, 3/27, 4/2, 8/15, 8/24, 8/25 Scott Harrison
-# 10/12,10/14,10/15,10/16,11/28,11/29 Scott Harrison
-#
-###
+###############################################################################
+###############################################################################
+
+=pod
+
+=head1 NAME
+
+lonsearchcat - LONCAPA Search Interface
+
+=head1 SYNOPSIS
+
+Search interface to LON-CAPAs digital library
+
+=head1 DESCRIPTION
+
+This module enables searching for a distributed browseable catalog.
+
+This is part of the LearningOnline Network with CAPA project
+described at http://www.lon-capa.org.
+
+lonsearchcat presents the user with an interface to search the LON-CAPA
+digital library. lonsearchcat also initiates the execution of a search
+by sending the search parameters to LON-CAPA servers. The progress of
+search (on a server basis) is displayed to the user in a seperate window.
+
+=head1 Internals
+
+=over 4
+
+=cut
+
+###############################################################################
+###############################################################################
###############################################################################
## ##
## ORGANIZATION OF THIS PERL MODULE ##
## ##
## 1. Modules used by this module ##
-## 2. Choices for different output views (detailed, summary, xml, etc) ##
-## 3. BEGIN block (to be run once after compilation) ##
-## 4. Handling routine called via Apache and mod_perl ##
-## 5. Other subroutines ##
+## 2. Variables used throughout the module ##
+## 3. handler subroutine called via Apache and mod_perl ##
+## 4. Other subroutines ##
## ##
###############################################################################
@@ -53,194 +79,516 @@ use Apache::lonnet();
use Apache::File();
use CGI qw(:standard);
use Text::Query;
+use DBI;
use GDBM_File;
+use Apache::loncommon();
+use Apache::lonmysql();
# ---------------------------------------- variables used throughout the module
-# -- information holders
-my %language; # holds contents of language.tab
-my %cprtag; # holds contents of copyright.tab
-my %mimetag; # holds contents of filetypes.tab
-my %hostdomains; # matches host name to host domain
-my %hostips; # matches host name to host ip
-my %hitcount; # stores number of hits per host
+######################################################################
+######################################################################
+
+=pod
+
+=item Global variables
+
+=over 4
+
+=item $importbutton
+
+button to take the select results and go to group sorting
+
+=item %groupsearch_db
+
+Database hash used to save values for the groupsearch RAT interface.
+
+=item $diropendb
+
+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.
+
+=item $bodytag
+
+LON-CAPA standard body tag, gotten from &Apache::lonnet::bodytag.
+No title, no table, just a
tag.
+
+=back
+
+=cut
+
+######################################################################
+######################################################################
# -- dynamically rendered interface components
-my $closebutton; # button that closes the search window
my $importbutton; # button to take the selected results and go to group sorting
# -- miscellaneous variables
-my $scrout; # string that holds portions of the screen output
-my $yourself; # allows for quickly limiting to oneself
-my %hash;
-
-# ------------------------------------------ choices for different output views
-# Detailed Citation View ---> sub detailed_citation_view
-# Summary View ---> sub summary_view
-# Fielded Format ---> sub fielded_format_view
-# XML/SGML ---> sub xml_sgml_view
-my $basicviewselect=<
-
-
-
-
-
-END
-my $advancedviewselect=<
-
-
-
-
-
-END
-
-# ----------------------------------------------------------------------- BEGIN
-sub BEGIN {
-# --------------------------------- Compute various listings of metadata values
- $language{'any'}='Any language';
- {
- my $fh=Apache::File->new($Apache::lonnet::perlvar{'lonTabDir'}.
- '/language.tab');
- while (<$fh>) {
- $_=~/(\w+)\s+([\w\s\-]+)/; chomp;
- $language{$1}=$2;
- }
- }
- $cprtag{'any'}='Any copyright/distribution';
- {
- my $fh=Apache::File->new($Apache::lonnet::perlvar{'lonIncludes'}.
- '/copyright.tab');
- while (<$fh>) {
- $_=~/(\w+)\s+([\w\s\-]+)/; chomp;
- $cprtag{$1}=$2;
- }
- }
- $mimetag{'any'}='Any type';
- {
- my $fh=Apache::File->new($Apache::lonnet::perlvar{'lonTabDir'}.
- '/filetypes.tab');
- while (<$fh>) {
- $_=~/(\w+)\s+(\w+)\s+([\w\s\-]+)/; chomp;
- $mimetag{$1}=".$1 $3";
- }
- }
- {
- my $fh=Apache::File->new($Apache::lonnet::perlvar{'lonTabDir'}.
- '/hosts.tab');
- while (<$fh>) {
- $_=~/(\w+?)\:(\w+?)\:(\w+?)\:(.*)/; chomp;
- if ($3 eq 'library') {
- $hostdomains{$1}=$2;
- $hostips{$1}=$4;
- }
- }
- }
-}
+my %groupsearch_db; # 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,
+ "Compact View" => \&compact_view);
+my %persistent_db;
+my $hidden_fields;
+my $bodytag;
+
+######################################################################
+######################################################################
+
+=pod
-my $diropendb = "";
-my $domain = "";
+=item &handler() - main handler invoked by httpd child
+
+=item Variables
+
+=over 4
-# ----------------------------- Handling routine called via Apache and mod_perl
+=item $hidden
+
+holds 'hidden' html forms
+
+=item $scrout
+
+string that holds portions of the screen output
+
+=back
+
+=cut
+
+######################################################################
+######################################################################
sub handler {
my $r = shift;
- untie %hash;
- &get_unprocessed_cgi();
+ #
+ my $loaderror=&Apache::lonnet::overloaderror($r);
+ if ($loaderror) { return $loaderror; }
+
+ my $closebutton; # button that closes the search window
+ # This button is different for the RAT compared to
+ # normal invocation.
+ #
$r->content_type('text/html');
$r->send_http_header;
return OK if $r->header_only;
-
- $domain = $r->dir_config('lonDefDomain');
-
- $diropendb= "/home/httpd/perl/tmp/$domain\_$ENV{'user.name'}_searchcat.db";
-
- if ($ENV{'form.launch'} eq '1') {
- if (tie(%hash,'GDBM_File',$diropendb,&GDBM_WRCREAT,0640)) {
+ ##
+ ## Prevent caching of the search interface window. Hopefully this means
+ ## we will get the launch=1 passed in a little more.
+ &Apache::loncommon::no_cache($r);
+ ##
+ ## Pick up form fields passed in the links.
+ ##
+ &Apache::loncommon::get_unprocessed_cgi($ENV{'QUERY_STRING'},
+ ['catalogmode','launch','acts','mode','form','element','pause',
+ 'phase','persistent_db_id','table','start','show',
+ 'cleargroupsort']);
+ ##
+ ## The following is a trick - we wait a few seconds if asked to so
+ ## the daemon running the search can get ahead of the daemon
+ ## printing the results. We only need (theoretically) to do
+ ## this once, so the pause indicator is deleted
+ ##
+ if (exists($ENV{'form.pause'})) {
+ sleep(3);
+ delete($ENV{'form.pause'});
+ }
+ ##
+ ## Initialize global variables
+ ##
+ my $domain = $r->dir_config('lonDefDomain');
+ $diropendb= "/home/httpd/perl/tmp/".&Apache::lonnet::escape($domain).
+ "\_".&Apache::lonnet::escape($ENV{'user.name'})."_searchcat.db";
+ #
+ # set the name of the persistent database
+ # $ENV{'form.persistent_db_id'} can only have digits in it.
+ if (! exists($ENV{'form.persistent_db_id'}) ||
+ ($ENV{'form.persistent_db_id'} =~ /\D/) ||
+ ($ENV{'form.launch'} eq '1')) {
+ $ENV{'form.persistent_db_id'} = time;
+ }
+ $bodytag=&Apache::loncommon::bodytag(undef,undef,undef,1);
+ my $persistent_db_file = "/home/httpd/perl/tmp/".
+ &Apache::lonnet::escape($domain).
+ '_'.&Apache::lonnet::escape($ENV{'user.name'}).
+ '_'.$ENV{'form.persistent_db_id'}.'_persistent_search.db';
+ ##
+ if (! &get_persistent_form_data($persistent_db_file)) {
+ if ($ENV{'form.phase'} =~ /(run_search|results)/) {
+ &Apache::lonnet::logthis("lonsearchcat:Unable to recover data ".
+ "from $persistent_db_file");
+ $r->print(<
+LON-CAPA Search Error
+$bodytag
+We were unable to retrieve data describing your search. This is a serious
+error and has been logged. Please alert your LON-CAPA administrator.
+
+