--- loncom/interface/lonsearchcat.pm 2003/12/22 22:40:37 1.196
+++ loncom/interface/lonsearchcat.pm 2004/04/21 15:48:34 1.213
@@ -1,7 +1,7 @@
# The LearningOnline Network with CAPA
# Search Catalog
#
-# $Id: lonsearchcat.pm,v 1.196 2003/12/22 22:40:37 matthew Exp $
+# $Id: lonsearchcat.pm,v 1.213 2004/04/21 15:48:34 matthew Exp $
#
# Copyright Michigan State University Board of Trustees
#
@@ -48,7 +48,7 @@ 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
@@ -70,7 +70,11 @@ 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();
######################################################################
######################################################################
@@ -83,22 +87,20 @@ my %groupsearch_db; # Database hash use
# groupsearch RAT interface.
my %persistent_db; # gdbm hash which holds data which is supposed to
# persist across calls to lonsearchcat.pm
-## %Views:
-## Hash which associates an output view description with the function
-## that produces it.
-# View Description/Name 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);
+# 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_defaults();
#
# set form defaults
#
@@ -148,7 +150,8 @@ sub handler {
## Initialize global variables
##
my $domain = $r->dir_config('lonDefDomain');
- $diropendb= "/home/httpd/perl/tmp/$ENV{'user.domain'}_$ENV{'user.name'}_searchcat.db";
+ $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.
@@ -163,6 +166,25 @@ sub handler {
'_'.&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",
+ 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",
+ bug=>'Searching',});
+ }
+ #
if (! &get_persistent_form_data($persistent_db_file)) {
if ($ENV{'form.phase'} =~ /(run_search|results)/) {
&Apache::lonnet::logthis("lonsearchcat:Unable to recover data ".
@@ -263,6 +285,32 @@ END
}
$ENV{'form.phase'} = 'disp_basic' if (! exists($ENV{'form.phase'}));
$ENV{'form.show'} = 20 if (! exists($ENV{'form.show'}));
+ #
+ $ENV{'form.searchmode'} = 'basic';
+ if ($ENV{'form.phase'} eq 'adv_search' ||
+ $ENV{'form.phase'} eq 'disp_adv') {
+ $ENV{'form.searchmode'} = 'advanced';
+ } elsif ($ENV{'form.phase'} eq 'course_search') {
+ $ENV{'form.searchmode'} = 'course_search';
+ }
+ #
+ if ($ENV{'form.searchmode'} eq 'advanced') {
+ &Apache::lonhtmlcommon::add_breadcrumb
+ ({href=>'/adm/searchcat?phase=disp_adv&'.
+ 'catalogmode='.$ENV{'form.catalogmode'}.
+ '&launch='.$ENV{'form.launch'}.
+ '&mode='.$ENV{'form.mode'},
+ text=>"Advanced Search",
+ bug=>'Searching',});
+ } elsif ($ENV{'form.searchmode'} eq 'course search') {
+ &Apache::lonhtmlcommon::add_breadcrumb
+ ({href=>'/adm/searchcat?phase=disp_adv&'.
+ 'catalogmode='.$ENV{'form.catalogmode'}.
+ '&launch='.$ENV{'form.launch'}.
+ '&mode='.$ENV{'form.mode'},
+ text=>"Course Search",
+ bug=>'Searching',});
+ }
##
## Switch on the phase
##
@@ -287,12 +335,12 @@ END
&course_search($r);
} elsif(($ENV{'form.phase'} eq 'basic_search') ||
($ENV{'form.phase'} eq 'adv_search')) {
- $ENV{'form.searchmode'} = 'basic';
- if ($ENV{'form.phase'} eq 'adv_search') {
- $ENV{'form.searchmode'} = 'advanced';
- }
# Set up table
if (! defined(&create_results_table())) {
+ my $errorstring=&Apache::lonmysql::get_error();
+ &Apache::lonnet::logthis('lonsearchcat.pm: Unable to create '.
+ 'needed table. lonmysql error:'.
+ $errorstring);
$r->print(<Search Error
$bodytag
@@ -357,23 +405,24 @@ my $totalfound;
sub course_search {
my $r=shift;
- my $bodytag=&Apache::loncommon::bodytag('Course Search');
+ my $bodytag=&Apache::loncommon::bodytag('Course Search').
+ &Apache::loncommon::help_open_bug('Searching');
my $pretty_search_string = ''.$ENV{'form.courseexp'}.'';
my $search_string = $ENV{'form.courseexp'};
my @New_Words;
if ($ENV{'form.crsrelated'}) {
($search_string,@New_Words) = &related_version($ENV{'form.courseexp'});
if (@New_Words) {
- $pretty_search_string .= " with related words: @New_Words.";
+ $pretty_search_string .= ' '.&mt("with related words").": @New_Words.";
} else {
- $pretty_search_string .= " with no related words.";
+ $pretty_search_string .= ' '.&mt('with no related words').".";
}
}
my $fulltext=$ENV{'form.crsfulltext'};
my @allwords=($search_string,@New_Words);
$totalfound=0;
$r->print('LON-CAPA Course Search'.
- $bodytag.$pretty_search_string);
+ $bodytag.'
'.$pretty_search_string.'
');
$r->rflush();
# ======================================================= Go through the course
undef %alreadyseen;
@@ -450,6 +499,23 @@ sub untiehash {
} # End of course search scoping
+sub search_html_header {
+ my $Str = <
+
+The LearningOnline Network with CAPA
+
+
+ENDHEADER
+ return $Str;
+}
+
######################################################################
######################################################################
@@ -457,89 +523,88 @@ sub untiehash {
=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{
+sub print_basic_search_form {
my ($r,$closebutton,$hidden_fields) = @_;
- my $bodytag=&Apache::loncommon::bodytag('Search');
- my $scrout=<<"ENDDOCUMENT";
-
-
-The LearningOnline Network with CAPA
-
-
-$bodytag
-ENDDOCUMENT
-if (&Apache::lonnet::allowed('bre',$ENV{'request.role.domain'})) {
- my $CatalogSearch=&mt('Catalog Search');
- my $Statement=&mt('Enter terms or phrases separated by AND, OR, or NOT then press SEARCH below');
- $scrout.=(<$CatalogSearch
-
-
-
-$closebutton
-END
- $scrout.=&selectbox('View','viewselect',
- $ENV{'form.viewselect'},
- undef,undef,undef,
- sort(keys(%Views)));
- $scrout.=&selectbox('Per Page','show',
- $ENV{'form.show'},
- undef,undef,undef,
- (10,20,50,100));
- $scrout.=<
-
-ENDDOCUMENT
+ my $bodytag=&Apache::loncommon::bodytag('Search').
+ &Apache::lonhtmlcommon::breadcrumbs(undef,'Searching','Finding_Resources',
+ undef,undef,! $ENV{'form.launch'});
+ my $scrout = &search_html_header().$bodytag;
+ if (&Apache::lonnet::allowed('bre',$ENV{'request.role.domain'})) {
+ # Define interface components
+ my $userelatedwords=
+ &mt('[_1] use related words',
+ &Apache::lonhtmlcommon::checkbox
+ ('related',$ENV{'form.related'}));
+ my $onlysearchdomain=
+ &mt('[_1] only search domain [_2]',
+ &Apache::lonhtmlcommon::checkbox
+ ('domains',$ENV{'form.domains'}),
+ $r->dir_config('lonDefDomain'));
+ my $adv_search_link =
+ ''.&mt('Advanced Search').'';
+ #
+ $scrout.='';
}
if ($ENV{'request.course.id'}) {
- my %lt=&Apache::lonlocal::texthash(
- 'srch' => 'Search',
+ my %lt=&Apache::lonlocal::texthash('srch' => 'Search',
'header' => 'Course Search',
'note' => 'Enter terms or phrases, then press "Search" below',
+ 'use' => 'use related words',
+ 'full' =>'fulltext search (time consuming)'
);
$scrout.=(<
+
\n";
$scrout.=<
@@ -775,7 +764,105 @@ 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');
+ return $desc{$code};
+}
+
+######################################################################
+######################################################################
+
+=pod
+
+=item viewoptions()
+
+Inputs: none
+
+Outputs: text for box with view options
+
+=cut
+
+######################################################################
+######################################################################
+sub viewoptions {
+ my $scrout="\n".'';
+ if (! defined($ENV{'form.viewselect'})) {
+ $ENV{'form.viewselect'}='detailed';
+ }
+ $scrout.=&Apache::lonmeta::selectbox('viewselect',
+ $ENV{'form.viewselect'},
+ \&viewoptiontext,
+ sort(keys(%Views)));
+ $scrout.= ' ';
+ $scrout.=&Apache::lonmeta::selectbox('show',
+ $ENV{'form.show'},
+ undef,
+ (10,20,50,100,1000,10000));
+ $scrout .= (' 'x2).&mt('Records per Page').''.$/;
+ return $scrout;
+}
+
+######################################################################
+######################################################################
+
+=pod
+
+=item searchhelp()
+
+Inputs: none
+
+Outputs: return little blurb on how to enter searches
+
+=cut
+
+######################################################################
+######################################################################
+sub searchhelp {
+ return &mt('Enter terms or phrases separated by AND, OR, or NOT');
+}
+
+######################################################################
+######################################################################
+
+=pod
+
+=item &get_persistent_form_data()
Inputs: filename of database
@@ -830,7 +917,7 @@ sub get_persistent_form_data {
=pod
-=item &get_persistent_data
+=item &get_persistent_data()
Inputs: filename of database, ref to array of values to recover.
@@ -881,7 +968,7 @@ 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.
=cut
@@ -913,7 +1000,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
@@ -931,288 +1018,6 @@ sub make_form_data_persistent {
}
######################################################################
-# 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,$checked
-
-Returns a simple check box with the given $name.
-If $value eq 'on' the box is checked.
-
-=cut
-
-###############################################
-###############################################
-
-sub simplecheckbox{
- my ($name,$value,$checked)=@_;
- $checked="checked" if ($value eq $checked || $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(&mt(shift()));
- return ''.$title.
- ': ';
-}
-
-###############################################
-###############################################
-
-=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 '