--- loncom/interface/lonsearchcat.pm 2002/07/26 16:37:58 1.144
+++ loncom/interface/lonsearchcat.pm 2002/07/28 20:02:14 1.145
@@ -1,7 +1,7 @@
# The LearningOnline Network with CAPA
# Search Catalog
#
-# $Id: lonsearchcat.pm,v 1.144 2002/07/26 16:37:58 matthew Exp $
+# $Id: lonsearchcat.pm,v 1.145 2002/07/28 20:02:14 matthew Exp $
#
# Copyright Michigan State University Board of Trustees
#
@@ -103,10 +103,6 @@ use Apache::lonmysql();
=over 4
-=item $closebutton
-
-button that closes the search window
-
=item $importbutton
button to take the select results and go to group sorting
@@ -127,10 +123,6 @@ that produces it. Adding a new view typ
adding a line to the definition of this hash and making sure the function
takes the proper parameters.
-=item $results_db
-
-The name of the database results from searches are put in.
-
=back
=cut
@@ -139,20 +131,19 @@ The name of the database results from se
######################################################################
# -- 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 %groupsearch_db; # database hash
my $diropendb = ""; # db file
-
-my $results_db = "";
# 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 );
-
+my $persistent_db_file;
+my %persistent_db;
+my $hidden_fields;
######################################################################
######################################################################
@@ -180,22 +171,50 @@ string that holds portions of the screen
######################################################################
sub handler {
my $r = shift;
- untie %groupsearch_db;
-
+ #
+ untie %groupsearch_db if (tied(%groupsearch_db));
+ #
+ 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;
+ ##
+ ## Pick up form fields passed in the links.
+ ##
+ &Apache::loncommon::get_unprocessed_cgi($ENV{'QUERY_STRING'},
+ ['catalogmode','launch','acts','mode','form','element',
+ 'reqinterface','persistent_db_id','table']);
##
## 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";
- $results_db = "/home/httpd/perl/tmp/".&Apache::lonnet::escape($domain).
- '_'.&Apache::lonnet::escape($ENV{'user.name'})."_searchresults.db";
- &Apache::loncommon::get_unprocessed_cgi($ENV{'QUERY_STRING'},
- ['catalogmode','launch','acts','mode','form','element',
- 'reqinterface']);
+ #
+ # 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.persistent_db_id'} = time;
+ }
+ $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';
+ #
+ # Read in the database. It should (hopefully) not be catastrophic to
+ # fail in this exercise.
+ if (-e $persistent_db_file) {
+ # Read in the previous values, if we can.
+ if (tie(%persistent_db,'GDBM_File',$persistent_db_file,
+ &GDBM_READER,0640)) {
+ &reconstruct_persistent_form_data($r);
+ untie (%persistent_db);
+ }
+ }
##
## Clear out old values from groupsearch database
##
@@ -210,23 +229,14 @@ sub handler {
}
}
##
- ## Produce some output, so people know it is working
- ##
- $r->print("\n");
- $r->rflush;
- ##
## Configure dynamic components of interface
##
- my $hidden; # Holds 'hidden' html forms
+ $hidden_fields = '';
if ($ENV{'form.catalogmode'} eq 'interactive') {
- $hidden="".
- "\n";
$closebutton=""."\n";
} elsif ($ENV{'form.catalogmode'} eq 'groupsearch') {
- $hidden=<
-END
$closebutton=<
END
@@ -235,26 +245,29 @@ END
onClick='javascript:select_group()'>
END
}
- $hidden .= &make_persistent({ "form.mode" => $ENV{'form.mode'},
- "form.form" => $ENV{'form.form'},
- "form.element" => $ENV{'form.element'},
- "form.date" => 2 });
##
- ## What are we doing?
+ ## Do a search, if needed.
##
my $searchtype;
$searchtype = 'Basic' if ($ENV{'form.basicsubmit'} eq 'SEARCH');
$searchtype = 'Advanced' if ($ENV{'form.advancedsubmit'} eq 'SEARCH');
if ($searchtype) {
+ ##
+ ## make query information persistent to allow for subsequent revision
+ ##
+ tie(%persistent_db,'GDBM_File',$persistent_db_file,&GDBM_WRCREAT,0640);
+ &make_persistent(\%ENV);
+ untie(%persistent_db);
+ #
# We are running a search
my ($query,$customquery,$customshow,$libraries) =
(undef,undef,undef,undef);
my $pretty_string;
if ($searchtype eq 'Basic') {
- ($query,$pretty_string) = &parse_basic_search($r);
+ ($query,$pretty_string) = &parse_basic_search($r,$closebutton);
} elsif ($ENV{'form.advancedsubmit'} eq 'SEARCH') {
($query,$customquery,$customshow,$libraries,$pretty_string)
- = &parse_advanced_search($r);
+ = &parse_advanced_search($r,$closebutton);
return OK if (! defined($query));
}
# Output some information to the user.
@@ -262,26 +275,38 @@ END
$r->print("Sending search request to LON-CAPA servers. \n");
$r->rflush();
&run_search($r,$query,$customquery,$customshow,$libraries);
- &display_results($r,$searchtype,$hidden,$importbutton,
- $closebutton);
-
+ ##
+ ## Display the results
+ ##
+ &display_results($r,$searchtype,$importbutton,$closebutton);
$r->rflush();
} 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
- if ($ENV{'form.reqinterface'} eq 'advanced') {
- $r->print(&advanced_search_form($closebutton,$hidden));
- } else {
+ #
+ # remove the requested interface from the environment.
+ my $interface;
+ if ($ENV{'form.reqinterface'}) {
+ $interface = lc($ENV{'form.reqinterface'});
+ } else {
+ $interface = 'basic';
+ }
+ ##
+ ## Determine course of action
+ ##
+ if ($interface eq 'display') {
+ # &display_results($closebutton));
+ } elsif ($interface eq 'advanced') {
+ $r->print(&advanced_search_form($closebutton));
+ } elsif ($interface eq 'basic') {
# Output normal search interface
- $r->print(&basic_search_form($closebutton,$hidden));
+ $r->print(&basic_search_form($closebutton));
}
}
+ untie (%persistent_db);
return OK;
}
@@ -300,7 +325,7 @@ Returns a scalar which holds html for th
######################################################################
sub basic_search_form{
- my ($closebutton,$hidden) = @_;
+ my ($closebutton) = @_;
my $scrout=<<"ENDDOCUMENT";
@@ -317,7 +342,7 @@ sub basic_search_form{