--- loncom/interface/lonsearchcat.pm 2002/07/29 21:53:57 1.146
+++ loncom/interface/lonsearchcat.pm 2023/12/22 20:11:55 1.358
@@ -1,7 +1,7 @@
# The LearningOnline Network with CAPA
# Search Catalog
#
-# $Id: lonsearchcat.pm,v 1.146 2002/07/29 21:53:57 matthew Exp $
+# $Id: lonsearchcat.pm,v 1.358 2023/12/22 20:11:55 raeburn Exp $
#
# Copyright Michigan State University Board of Trustees
#
@@ -25,14 +25,6 @@
#
# 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,12/10,12/12,12/16 Scott Harrison
-# YEAR=2002
-# 1/17 Scott Harrison
-# 6/17 Matthew Hall
-#
###############################################################################
###############################################################################
@@ -56,193 +48,245 @@ 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.
+search (on a server basis) is displayed to the user in a separate window.
=head1 Internals
-=over 4
-
=cut
###############################################################################
###############################################################################
-###############################################################################
-## ##
-## ORGANIZATION OF THIS PERL MODULE ##
-## ##
-## 1. Modules used by this module ##
-## 2. Variables used throughout the module ##
-## 3. handler subroutine called via Apache and mod_perl ##
-## 4. Other subroutines ##
-## ##
-###############################################################################
-
package Apache::lonsearchcat;
-# ------------------------------------------------- modules used by this module
use strict;
-use Apache::Constants qw(:common);
-use Apache::lonnet();
+use Apache::Constants qw(:common :http);
+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
+use Apache::lonmeta;
+use Apache::lonhtmlcommon;
+use Apache::lonlocal;
+use LONCAPA::lonmetadata();
+use HTML::Entities();
+use Parse::RecDescent;
+use Apache::lonnavmaps;
+use Apache::lonindexer();
+use Apache::lonwishlist();
+use LONCAPA;
+use Time::HiRes qw(sleep);
######################################################################
######################################################################
-
-=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.
-
-=back
-
-=cut
-
-######################################################################
-######################################################################
-
-# -- dynamically rendered interface components
-my $importbutton; # button to take the selected results and go to group sorting
-
-# -- miscellaneous variables
-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 );
-my %persistent_db;
-my $hidden_fields;
+##
+## Global variables
+##
######################################################################
######################################################################
-
-=pod
-
-=item &handler() - main handler invoked by httpd child
-
-=item Variables
-
-=over 4
-
-=item $hidden
-
-holds 'hidden' html forms
-
-=item $scrout
-
-string that holds portions of the screen output
-
-=back
-
-=cut
+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,
+ "detailedpreview" => \&detailed_citation_preview,
+ "summary" => \&summary_view,
+ "summarypreview" => \&summary_preview,
+ "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 $closebutton; # button that closes the search window
# This button is different for the RAT compared to
# normal invocation.
#
- $r->content_type('text/html');
+ &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']);
+ 'phase','persistent_db_id','table','start','show',
+ 'cleargroupsort','titleelement','area','inhibitmenu']);
##
## 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(5);
- delete($ENV{'form.pause'});
+ if (exists($env{'form.pause'})) {
+ sleep(0.1);
+ 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";
+ my $temp_file_dir = LONCAPA::tempdir();
+ $diropendb= $temp_file_dir .
+ "$env{'user.domain'}_$env{'user.name'}_sel_res.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.persistent_db_id'} = time;
- }
- 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';
- ##
- &get_persistent_form_data($r,$persistent_db_file);
+ # $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;
+ }
+
+ my $persistent_db_file = $temp_file_dir .
+ &escape($domain).
+ '_'.&escape($env{'user.name'}).
+ '_'.$env{'form.persistent_db_id'}.'_persistent_search.db';
+ ##
+ &Apache::lonhtmlcommon::clear_breadcrumbs();
+
+ my @allowed_searches = ('portfolio');
+ if (&Apache::lonnet::allowed('bre',$env{'request.role.domain'}) eq 'F') {
+ push(@allowed_searches,'res');
+ }
+ my $crumb_text = 'Portfolio Search';
+ if (@allowed_searches ==2) {
+ $crumb_text = 'Portfolio and Content Library Search';
+ }
+ my $target = '_top';
+ if ((($env{'request.lti.login'}) && ($env{'request.lti.target'} eq 'iframe')) ||
+ (($env{'request.deeplink.login'}) && ($env{'request.deeplink.target'} eq '_self'))) {
+ if ($env{'form.phase'} =~ /^(sort|run_search)$/) {
+ $target = '_parent';
+ } else {
+ $target = '_self';
+ }
+ }
+ &Apache::lonhtmlcommon::add_breadcrumb
+ ({href=>'/adm/searchcat?'.
+ &Apache::loncommon::inhibit_menu_check().
+ '&catalogmode='.$env{'form.catalogmode'}.
+ '&launch='.$env{'form.launch'}.
+ '&mode='.$env{'form.mode'},
+ text=>"$crumb_text",
+ target=>$target,
+ 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 $msg =
+ &mt('We were unable to retrieve data describing your search.').
+ ' '.&mt('This is a serious error and has been logged.').
+ ' '.
+ &mt('Please alert your LON-CAPA administrator.');
+ &Apache::loncommon::simple_error_page(
+ $r,'Search Error',
+ $msg,
+ {'no_auto_mt_msg' => 1});
+ return OK;
+ }
+ }
+ } else {
+ &clean_up_environment();
+ }
##
## Clear out old values from groupsearch database
##
untie %groupsearch_db if (tied(%groupsearch_db));
- if ($ENV{'form.launch'} eq '1') {
- if (tie(%groupsearch_db,'GDBM_File',$diropendb,&GDBM_WRCREAT,0640)) {
+ if (($env{'form.cleargroupsort'} eq '1') ||
+ (($env{'form.launch'} eq '1') &&
+ ($env{'form.catalogmode'} eq 'import'))) {
+ if (tie(%groupsearch_db,'GDBM_File',$diropendb,&GDBM_WRCREAT(),0640)) {
&start_fresh_session();
untie %groupsearch_db;
+ delete($env{'form.cleargroupsort'});
} else {
- $r->print('
Unable to tie hash to db '.
- 'file');
+ # This is a stupid error to give to the user.
+ # It really tells them nothing.
+ my $msg = 'Unable to tie hash to db file.';
+ &Apache::loncommon::simple_error_page($r,'Search Error',
+ $msg);
return OK;
}
}
##
- ## Configure dynamic components of interface
+ ## Configure hidden fields
##
$hidden_fields = '';
+ $env{'form.persistent_db_id'}.'" />'."\n";
+ if (exists($env{'form.catalogmode'})) {
+ $hidden_fields .= &hidden_field('catalogmode');
+ }
+ if (exists($env{'form.form'})) {
+ $hidden_fields .= &hidden_field('form');
+ }
+ if (exists($env{'form.element'})) {
+ $hidden_fields .= &hidden_field('element');
+ }
+ if (exists($env{'form.titleelement'})) {
+ $hidden_fields .= &hidden_field('titleelement');
+ }
+ if (exists($env{'form.mode'})) {
+ $hidden_fields .= &hidden_field('mode');
+ }
+ if (exists($env{'form.area'})) {
+ $hidden_fields .= &hidden_field('area');
+ }
+ if (exists($env{'form.inhibitmenu'})) {
+ $hidden_fields .= &hidden_field('inhibitmenu');
+ }
##
- if ($ENV{'form.catalogmode'} eq 'interactive') {
- $closebutton=""."\n";
- } elsif ($ENV{'form.catalogmode'} eq 'groupsearch') {
- $closebutton=<
-END
+ ## Configure dynamic components of interface
+ ##
+ if ($env{'form.catalogmode'} eq 'interactive') {
+ $closebutton="
+
END
} else {
$closebutton = '';
@@ -251,145 +295,282 @@ END
##
## Sanity checks on form elements
##
- if (!defined($ENV{'form.viewselect'})) {
- $ENV{'form.viewselect'} ="Detailed Citation View";
+ if (!defined($env{'form.viewselect'})) {
+ $env{'form.viewselect'} ="summary";
}
- $ENV{'form.phase'} = 'displaybasic' if (! exists($ENV{'form.phase'}));
+ $env{'form.phase'} = 'disp_basic' if (! exists($env{'form.phase'}));
+ $env{'form.show'} = 20 if (! exists($env{'form.show'}));
+ #
+ $env{'form.searchmode'} = 'basic' if (! exists($env{'form.searchmode'}));
+ if ($env{'form.phase'} eq 'adv_search' ||
+ $env{'form.phase'} eq 'disp_adv') {
+ $env{'form.searchmode'} = 'advanced';
+ }
+ #
+ if ($env{'form.searchmode'} eq 'advanced') {
+ my $srchtype = 'Catalog';
+ if ($env{'form.area'} eq 'portfolio') {
+ $srchtype = 'Portfolio';
+ }
+ &Apache::lonhtmlcommon::add_breadcrumb
+ ({href=>'/adm/searchcat?'.&Apache::loncommon::inhibit_menu_check().
+ '&phase=disp_adv'.
+ '&catalogmode='.$env{'form.catalogmode'}.
+ '&launch='.$env{'form.launch'}.
+ '&mode='.$env{'form.mode'},
+ text=>"Advanced $srchtype Search",
+ bug=>'Searching',});
+ }
##
## Switch on the phase
##
- if ($ENV{'form.phase'} eq 'disp_basic') {
- &print_basic_search_form($r,$closebutton);
- } elsif ($ENV{'form.phase'} eq 'disp_adv') {
- &print_advanced_search_form($r,$closebutton);
- } elsif ($ENV{'form.phase'} eq 'results') {
- &display_results($r,$importbutton,$closebutton);
- } elsif($ENV{'form.phase'} eq 'run_search') {
- my ($query,$customquery,$customshow,$libraries,$pretty_string) =
+ if ($env{'form.phase'} eq 'disp_basic') {
+ &print_basic_search_form($r,$closebutton,$hidden_fields);
+ } elsif ($env{'form.phase'} eq 'disp_adv') {
+ &print_advanced_search_form($r,$closebutton,$hidden_fields);
+ } elsif ($env{'form.phase'} eq 'results') {
+ &display_results($r,$importbutton,$closebutton,$diropendb,
+ $env{'form.area'});
+ } elsif ($env{'form.phase'} =~ /^(sort|run_search)$/) {
+ my ($query,$customquery,$customshow,$libraries,$pretty_string,$domainsref) =
&get_persistent_data($persistent_db_file,
['query','customquery','customshow',
- 'libraries','pretty_string']);
- &write_status($r,"query = $query");
- &write_status($r,"customquery = $customquery");
- &write_status($r,"customshow = $customshow");
- &write_status($r,"libraries = $libraries");
- &write_status($r,"pretty_string = $pretty_string");
- &run_search($r,$query,$customquery,$customshow,
- $libraries,$pretty_string);
- } elsif(($ENV{'form.phase'} eq 'basic_search') ||
- ($ENV{'form.phase'} eq 'adv_search')) {
- # Set up table
- if (! defined(&create_results_table())) {
- # Unable to make table to store results in.
- # Definately abort search.
- }
- if (! &make_form_data_persistent($r,$persistent_db_file)) {
- # Unable to store persistent data.
- # Probably should bail out.
+ 'libraries','pretty_string','domains']);
+ if ($env{'form.phase'} eq 'sort') {
+ &print_sort_form($r,$pretty_string,$target);
+ } elsif ($env{'form.phase'} eq 'run_search') {
+ &run_search($r,$query,$customquery,$customshow,
+ $libraries,$pretty_string,$env{'form.area'},$domainsref,$target);
}
+ } elsif(($env{'form.phase'} eq 'basic_search') ||
+ ($env{'form.phase'} eq 'adv_search')) {
#
- # We are running a search
- my ($query,$customquery,$customshow,$libraries) =
- (undef,undef,undef,undef);
+ # We are running a search, try to parse it
+ my ($query,$customquery,$customshow,$libraries,$domains) =
+ (undef,undef,undef,undef,undef);
my $pretty_string;
- if ($ENV{'form.phase'} eq 'basic_search') {
- ($query,$pretty_string) = &parse_basic_search($r,$closebutton);
+ if ($env{'form.phase'} eq 'basic_search') {
+ ($query,$pretty_string,$libraries,$domains) =
+ &parse_basic_search($r,$closebutton,$hidden_fields);
+ return OK if (! defined($query));
+ &make_persistent({ basicexp => $env{'form.basicexp'}},
+ $persistent_db_file);
} else { # Advanced search
- ($query,$customquery,$customshow,$libraries,$pretty_string)
- = &parse_advanced_search($r,$closebutton);
+ ($query,$customquery,$customshow,$libraries,$pretty_string,$domains)
+ = &parse_advanced_search($r,$closebutton,$hidden_fields);
return OK if (! defined($query));
}
- &write_status($r,"query = $query");
- &write_status($r,"customquery = $customquery");
- &write_status($r,"customshow = $customshow");
- &write_status($r,"libraries = $libraries");
- &write_status($r,"pretty_string = $pretty_string");
- &make_persistent($r,
- { query => $query,
+ &make_persistent({ query => $query,
customquery => $customquery,
customshow => $customshow,
libraries => $libraries,
- pretty_string => $pretty_string },
+ pretty_string => $pretty_string,
+ domains => $domains },
$persistent_db_file);
+ #
+ # Set up table
+ if (! defined(&create_results_table($env{'form.area'}))) {
+ my $errorstring=&Apache::lonmysql::get_error();
+ &Apache::lonnet::logthis('lonsearchcat.pm: Unable to create '.
+ 'needed table. lonmysql error:'.
+ $errorstring);
+
+ my $msg =
+ 'Unable to create table in which to save search results. '.
+ 'The search has been aborted.';
+ &Apache::loncommon::simple_error_page($r,'Search Error',
+ $msg);
+ return OK;
+ }
+ delete($env{'form.launch'});
+ if (! &make_form_data_persistent($r,$persistent_db_file)) {
+ my $msg=
+ 'Unable to properly save search information. '.
+ 'The search has been aborted.';
+ &Apache::loncommon::simple_error_page($r,'Search Error',
+ $msg);
+ return OK;
+ }
##
## Print out the frames interface
##
- &print_frames_interface($r);
+ if (defined($query)) {
+ &print_frames_interface($r);
+ }
}
return OK;
}
-######################################################################
+#
+# The mechanism used to store values away and retrieve them does not
+# handle the case of missing environment variables being significant.
+#
+# This routine sets non existant checkbox form elements to ''.
+#
+sub clean_up_environment {
+ if ($env{'form.phase'} eq 'basic_search') {
+ if (! exists($env{'form.related'})) {
+ $env{'form.related'} = '';
+ }
+ if (! exists($env{'form.domains'})) {
+ $env{'form.domains'} = '';
+ }
+ } elsif ($env{'form.phase'} eq 'adv_search') {
+ foreach my $field ('title','keywords','notes',
+ 'abstract','standards','mime') {
+ if (! exists($env{'form.'.$field.'_related'})) {
+ $env{'form.'.$field.'_related'} = '';
+ }
+ }
+ } elsif ($env{'form.phase'} eq 'course_search') {
+ if (! exists($env{'form.crsrelated'})) {
+ $env{'form.crsrelated'} = '';
+ }
+ }
+}
+
+sub hidden_field {
+ my ($name,$value) = @_;
+ if (! defined($value)) {
+ $value = $env{'form.'.$name};
+ }
+ return ''.$/;
+}
+
######################################################################
-=pod
+=pod
+=over 4
+
=item &print_basic_search_form()
-Returns a scalar which holds html for the basic search form.
+Prints the form for the basic search. Sorry the name is so cryptic.
=cut
######################################################################
######################################################################
-
-sub print_basic_search_form{
- my ($r,$closebutton) = @_;
- my $scrout=<<"ENDDOCUMENT";
-
-
-The LearningOnline Network with CAPA
-
-
-
-
-
Search Catalog
-
-
-
-ENDDOCUMENT
+# Search form for accessible portfolio files
+ $scrout.= &setup_basic_search($r,'portfolio',$hidden_fields,$closebutton);
+ $scrout .= &Apache::loncommon::end_page();
$r->print($scrout);
return;
}
+
+sub setup_basic_search {
+ my ($r,$area,$hidden_fields,$closebutton) = @_;
+ # Define interface components
+ my %lt = &Apache::lonlocal::texthash (
+ res => 'Content Library Search',
+ portfolio => 'Portfolio Search',
+ );
+ my ($userelatedwords,$onlysearchdomain,$inclext,$adv_search_link,$scrout);
+
+ $userelatedwords = '';
+
+ my $anydom = 1;
+ if ($area eq 'res') {
+ unless (&Apache::lonnet::allowed('bre','/res/') eq 'F') {
+ $anydom = 0;
+ }
+ }
+ my $singledom;
+ my ($disabled,$checked);
+ if ($anydom) {
+ $singledom = $r->dir_config('lonDefDomain');
+ if ($env{'form.domains'} eq $singledom) {
+ $checked = 1;
+ }
+ } else {
+ $singledom = $env{'user.domain'};
+ $disabled = ' disabled="disabled"';
+ $checked = 1;
+ }
+ $onlysearchdomain = '';
+
+ $adv_search_link = ''.&mt('Advanced Search').'';
+ #
+ $scrout.='';
+ return $scrout;
+}
+
######################################################################
######################################################################
@@ -397,189 +578,309 @@ ENDDOCUMENT
=item &advanced_search_form()
-Returns a scalar which holds html for the advanced search form.
+Prints the advanced search form.
=cut
######################################################################
######################################################################
-
sub print_advanced_search_form{
- my ($r,$closebutton) = @_;
- my $advanced_buttons = <<"END";
+ my ($r,$closebutton,$hidden_fields) = @_;
+ my $bread_crumb =
+ &Apache::lonhtmlcommon::breadcrumbs('Searching','Search_Advanced',
+ $env{'form.catalogmode'} ne 'import');
+ my %lt=&Apache::lonlocal::texthash('srch' => 'Search',
+ 'reset' => 'Reset',
+ 'help' => 'Help');
+ my $advanced_buttons=<<"END";
-
-
+
+
$closebutton
-
END
- if (!defined($ENV{'form.viewselect'})) {
- $ENV{'form.viewselect'} ="Detailed Citation View";
+ my $srchtype = 'Catalog';
+ my $jscript;
+ if ($env{'form.area'} eq 'portfolio') {
+ $srchtype = 'Portfolio';
+ $jscript = '';
+ }
+ my $scrout= &Apache::loncommon::start_page("Advanced $srchtype Search",
+ $jscript);
+ $scrout .= $bread_crumb;
+
+ $scrout .= '';
+
+ $scrout .= &Apache::loncommon::end_page();
$r->print($scrout);
return;
}
@@ -589,7 +890,111 @@ ENDDOCUMENT
=pod
-=item &get_persistent_form_data
+=item &titlefield()
+
+Inputs: title text
+
+Outputs: titletext with font wrapper
+
+=cut
+
+######################################################################
+######################################################################
+sub titlefield {
+ my $title=shift;
+ return $title;
+}
+
+######################################################################
+######################################################################
+
+=pod
+
+=item viewoptiontext()
+
+Inputs: codename for view option
+
+Outputs: displayed text
+
+=cut
+
+######################################################################
+######################################################################
+sub viewoptiontext {
+ my $code=shift;
+ my %desc=&Apache::lonlocal::texthash
+ ('detailed' => "Detailed Citation View",
+ 'xml' => 'XML/SGML',
+ 'compact' => 'Compact View',
+ 'fielded' => 'Fielded Format',
+ 'summary' => 'Summary View',
+ 'summarypreview' => 'Summary Preview',
+ 'detailedpreview' => 'Detailed Citation Preview');
+ return $desc{$code};
+}
+
+######################################################################
+######################################################################
+
+=pod
+
+=item viewoptions()
+
+Inputs: none
+
+Outputs: text for box with view options
+
+=cut
+
+######################################################################
+######################################################################
+sub viewoptions {
+ my $scrout;
+ if (! defined($env{'form.viewselect'})) {
+ $env{'form.viewselect'}='detailed';
+ }
+ $scrout .= ''
+ .&mt('Type:').' '
+ .&Apache::lonmeta::selectbox('viewselect',
+ $env{'form.viewselect'},'',
+ \&viewoptiontext,
+ sort(keys(%Views)))
+ .'';
+ my $countselect = &Apache::lonmeta::selectbox('show',
+ $env{'form.show'},'',
+ undef,
+ (10,20,50,100,1000,10000));
+ $scrout .= ' '
+ .&mt('Records per Page:').' '.$countselect
+ .''.$/;
+ return $scrout;
+}
+
+######################################################################
+######################################################################
+
+=pod
+
+=item searchhelp()
+
+Inputs: none
+
+Outputs: return little blurb on how to enter searches
+
+=cut
+
+######################################################################
+######################################################################
+sub searchhelp {
+ return &mt('Enter words and quoted phrases');
+}
+
+######################################################################
+######################################################################
+
+=pod
+
+=item &get_persistent_form_data()
Inputs: filename of database
@@ -597,7 +1002,7 @@ Outputs: returns undef on database error
This function is the reverse of &make_persistent() for form data.
Retrieve persistent data from %persistent_db. Retrieved items will have their
-values unescaped. If a form value already exists in $ENV, it will not be
+values unescaped. If a form value already exists in $env, it will not be
overwritten. Form values that are array references may have values appended
to them.
@@ -606,48 +1011,45 @@ to them.
######################################################################
######################################################################
sub get_persistent_form_data {
- my $r = shift;
my $filename = shift;
- return undef if (! -e $filename);
+ return 0 if (! -e $filename);
return undef if (! tie(%persistent_db,'GDBM_File',$filename,
- &GDBM_READER,0640));
+ &GDBM_READER(),0640));
#
# These make sure we do not get array references printed out as 'values'.
- my %arrays_allowed = ('form.category'=>1,'form.domains'=>1);
+ my %arrays_allowed = ('form.domains'=>1);
#
# Loop through the keys, looking for 'form.'
foreach my $name (keys(%persistent_db)) {
next if ($name !~ /^form./);
+ # Kludgification begins!
+ if ($name eq 'form.domains' &&
+ $env{'form.searchmode'} eq 'basic' &&
+ $env{'form.phase'} ne 'disp_basic') {
+ next;
+ }
+ # End kludge (hopefully)
+ next if (exists($env{$name}));
my @values = map {
- &Apache::lonnet::unescape($_);
+ &unescape($_);
} split(',',$persistent_db{$name});
next if (@values <1);
- if (exists($ENV{$name})) {
- if (ref($ENV{$name}) eq 'ARRAY') {
- # If it is an array, tack @values on the end of it.
- $ENV{$name} = [@$ENV{$name},@values];
- } elsif (! ref($ENV{$name}) && $arrays_allowed{$name}) {
- # if arrays are allowed, turn it into one and add @values
- $ENV{$name} = [$ENV{$name},@values];
- } # otherwise, assume the value in $ENV{$name} is better than ours.
+ if ($arrays_allowed{$name}) {
+ $env{$name} = [@values];
} else {
- if ($arrays_allowed{$name}) {
- $ENV{$name} = [@values];
- } else {
- $ENV{$name} = $values[0] if ($values[0]);
- }
+ $env{$name} = $values[0] if ($values[0]);
}
- &write_status($r,"Reconstructed $name = $ENV{$name}");
}
untie (%persistent_db);
return 1;
}
+
######################################################################
######################################################################
=pod
-=item &get_persistent_data
+=item &get_persistent_data()
Inputs: filename of database, ref to array of values to recover.
@@ -655,8 +1057,9 @@ Outputs: array of values. Returns undef
This function is the reverse of &make_persistent();
Retrieve persistent data from %persistent_db. Retrieved items will have their
-values unescaped. If the item contains commas (before unescaping), the
-returned value will be an array pointer.
+values unescaped. If the item is 'domains; then the returned
+value will be a hash pointer. Otherwise, if the item contains
+commas (before unescaping), the returned value will be an array pointer.
=cut
@@ -668,19 +1071,31 @@ sub get_persistent_data {
my @Values; # Return array
return undef if (! -e $filename);
return undef if (! tie(%persistent_db,'GDBM_File',$filename,
- &GDBM_READER,0640));
+ &GDBM_READER(),0640));
foreach my $name (@Vars) {
if (! exists($persistent_db{$name})) {
push @Values, undef;
next;
}
- my @values = map {
- &Apache::lonnet::unescape($_);
- } split(',',$persistent_db{$name});
- if (@values == 1) {
- push @Values,$values[0];
+ if ($name eq 'domains') {
+ my %valueshash;
+ my @items= map { &unescape($_); } split(',',$persistent_db{$name});
+ foreach my $item (@items) {
+ if ($item =~ /=/) {
+ my ($key,$val) = map { &unescape($_); } split(/=/,$item);
+ $valueshash{$key} = $val;
+ }
+ }
+ push(@Values,\%valueshash);
} else {
- push @Values,\@values;
+ my @values = map {
+ &unescape($_);
+ } split(',',$persistent_db{$name});
+ if (@values <= 1) {
+ push @Values,$values[0];
+ } else {
+ push @Values,\@values;
+ }
}
}
untie (%persistent_db);
@@ -698,26 +1113,33 @@ Inputs: Hash of values to save, filename
Store variables away to the %persistent_db.
Values will be escaped. Values that are array pointers will have their
-elements escaped and concatenated in a comma seperated string.
+elements escaped and concatenated in a comma separated string. Values
+that are hash pointers will have their keys and values escaped and
+concatenated in a comma separated string.
=cut
######################################################################
######################################################################
sub make_persistent {
- my $r = shift;
my %save = %{shift()};
my $filename = shift;
return undef if (! tie(%persistent_db,'GDBM_File',
- $filename,&GDBM_WRCREAT,0640));
+ $filename,&GDBM_WRCREAT(),0640));
foreach my $name (keys(%save)) {
- next if (! exists($save{$name}));
- next if (! defined($save{$name}) || $save{$name} eq '');
- my @values = (ref($save{$name}) ? @{$save{$name}} : ($save{$name}));
- # We handle array references, but not recursively.
- my $store = join(',', map { &Apache::lonnet::escape($_); } @values );
+ my @values=();
+ if (ref($save{$name}) eq 'ARRAY') {
+ @values = @{$save{$name}};
+ } elsif (ref($save{$name}) eq 'HASH') {
+ foreach my $key (%{$save{$name}}) {
+ push(@values,&escape($key).'='.&escape($save{$name}{$key}));
+ }
+ } else {
+ @values = $save{$name};
+ }
+ # We handle array and hash references, but not recursively.
+ my $store = join(',', map { &escape($_); } @values );
$persistent_db{$name} = $store;
- &write_status($r,"Stored $name = $store");
}
untie(%persistent_db);
return 1;
@@ -734,7 +1156,7 @@ Inputs: filename of persistent database.
Store most form variables away to the %persistent_db.
Values will be escaped. Values that are array pointers will have their
-elements escaped and concatenated in a comma seperated string.
+elements escaped and concatenated in a comma separated string.
=cut
@@ -744,294 +1166,13 @@ sub make_form_data_persistent {
my $r = shift;
my $filename = shift;
my %save;
- foreach (keys(%ENV)) {
- next if (! /^form/ || /submit/);
- $save{$_} = $ENV{$_};
+ foreach (keys(%env)) {
+ next if (!/^form/ || /submit/);
+ $save{$_} = $env{$_};
}
- return &make_persistent($r,\%save,$filename);
-}
-
-######################################################################
-# HTML form building functions #
-######################################################################
-
-=pod
-
-=item HTML form building functions
-
-=over 4
-
-=cut
-
-###############################################
-###############################################
-
-=pod
-
-=item &simpletextfield()
-
-Inputs: $name,$value,$size
-
-Returns a text input field with the given name, value, and size.
-If size is not specified, a value of 20 is used.
-
-=cut
-
-###############################################
-###############################################
-
-sub simpletextfield {
- my ($name,$value,$size)=@_;
- $size = 20 if (! defined($size));
- return '';
-}
-
-###############################################
-###############################################
-
-=pod
-
-=item &simplecheckbox()
-
-Inputs: $name,$value
-
-Returns a simple check box with the given $name.
-If $value eq 'on' the box is checked.
-
-=cut
-
-###############################################
-###############################################
-
-sub simplecheckbox {
- my ($name,$value)=@_;
- my $checked='';
- $checked="checked" if $value eq 'on';
- return '';
-}
-
-###############################################
-###############################################
-
-=pod
-
-=item &fieldtitle()
-
-Input: $title
-
-Returns a scalar with html which will display $title as a search
-field heading.
-
-=cut
-
-###############################################
-###############################################
-
-sub fieldtitle {
- my $title = uc(shift());
- return ''.$title.
- ': ';
+ return &make_persistent(\%save,$filename);
}
-###############################################
-###############################################
-
-=pod
-
-=item &searchphrasefield()
-
-Inputs: $title,$name,$value
-
-Returns html for a title line and an input field for entering search terms.
-The entry field (which is where the $name and $value are used) is a 50 column
-simpletextfield. The html returned is for a row in a three column table.
-
-=cut
-
-###############################################
-###############################################
-
-sub searchphrasefield {
- my ($title,$name,$value)=@_;
- return '
'.&fieldtitle($title).'
'.
- &simpletextfield($name,$value,50)."
\n";
-}
-
-###############################################
-###############################################
-
-=pod
-
-=item &searchphrasefield_with_related()
-
-Inputs: $title,$name,$value
-
-Returns html for a title line and an input field for entering search terms
-and a check box for 'related words'. The entry field (which is where the
-$name and $value are used) is a 50 column simpletextfield. The name of
-the related words checkbox is "$name_related".
-
-=cut
-
-###############################################
-###############################################
-
-sub searchphrasefield_with_related {
- my ($title,$name,$value)=@_;
- return '