# The LearningOnline Network with CAPA # Search Catalog # # $Id: lonsearchcat.pm,v 1.249 2005/11/29 20:37:06 www Exp $ # # Copyright Michigan State University Board of Trustees # # This file is part of the LearningOnline Network with CAPA (LON-CAPA). # # LON-CAPA is free software; you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by # the Free Software Foundation; either version 2 of the License, or # (at your option) any later version. # # LON-CAPA is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details. # # You should have received a copy of the GNU General Public License # along with LON-CAPA; if not, write to the Free Software # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA # # /home/httpd/html/adm/gpl.txt # # http://www.lon-capa.org/ # ############################################################################### ############################################################################### =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 separate window. =head1 Internals =over 4 =cut ############################################################################### ############################################################################### package Apache::lonsearchcat; use strict; use Apache::Constants qw(:common :http); use Apache::lonnet; use Apache::File(); use CGI qw(:standard); use Text::Query; use GDBM_File; use Apache::loncommon(); use Apache::lonmysql(); use Apache::lonmeta; use Apache::lonhtmlcommon; use Apache::lonlocal; use LONCAPA::lonmetadata(); use HTML::Entities(); use Parse::RecDescent; use Apache::lonnavmaps; ###################################################################### ###################################################################### ## ## Global variables ## ###################################################################### ###################################################################### my %groupsearch_db; # Database hash used to save values for the # groupsearch RAT interface. my %persistent_db; # gdbm hash which holds data which is supposed to # persist across calls to lonsearchcat.pm # The different view modes and associated functions my %Views = ("detailed" => \&detailed_citation_view, "summary" => \&summary_view, "fielded" => \&fielded_format_view, "xml" => \&xml_sgml_view, "compact" => \&compact_view); ###################################################################### ###################################################################### sub handler { my $r = shift; # &set_defaults(); # # set form defaults # my $hidden_fields;# Hold all the hidden fields used to keep track # of the search system state my $importbutton; # button to take the selected results and go to group # sorting my $diropendb; # The full path to the (temporary) search database file. # This is set and used in &handler() and is also used in # &output_results(). my $bodytag; # LON-CAPA standard body tag, gotten from # &Apache::lonnet::bodytag. # No title, no table, just a
tag. 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. # &Apache::loncommon::content_type($r,'text/html'); $r->send_http_header; return OK if $r->header_only; ## ## 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','titleelement']); ## ## 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(1); delete($env{'form.pause'}); } ## ## Initialize global variables ## my $domain = $r->dir_config('lonDefDomain'); $diropendb= "/home/httpd/perl/tmp/". "$env{'user.domain'}_$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'; ## &Apache::lonhtmlcommon::clear_breadcrumbs(); if (exists($env{'request.course.id'}) && $env{'request.course.id'} ne '') { &Apache::lonhtmlcommon::add_breadcrumb ({href=>'/adm/searchcat?'. 'catalogmode='.$env{'form.catalogmode'}. '&launch='.$env{'form.launch'}. '&mode='.$env{'form.mode'}, text=>"Course and Catalog Search", target=>'_top', bug=>'Searching',}); } else { &Apache::lonhtmlcommon::add_breadcrumb ({href=>'/adm/searchcat?'. 'catalogmode='.$env{'form.catalogmode'}. '&launch='.$env{'form.launch'}. '&mode='.$env{'form.mode'}, text=>"Catalog Search", target=>'_top', bug=>'Searching',}); } # if ($env{'form.phase'} !~ m/(basic|adv|course)_search/) { 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); my $html=&Apache::lonxml::xmlbegin(); $r->print(<