--- loncom/interface/lonsearchcat.pm 2005/03/22 21:15:42 1.241
+++ loncom/interface/lonsearchcat.pm 2006/03/06 18:23:10 1.255
@@ -1,7 +1,7 @@
# The LearningOnline Network with CAPA
# Search Catalog
#
-# $Id: lonsearchcat.pm,v 1.241 2005/03/22 21:15:42 matthew Exp $
+# $Id: lonsearchcat.pm,v 1.255 2006/03/06 18:23:10 www Exp $
#
# Copyright Michigan State University Board of Trustees
#
@@ -63,7 +63,7 @@ package Apache::lonsearchcat;
use strict;
use Apache::Constants qw(:common :http);
-use Apache::lonnet();
+use Apache::lonnet;
use Apache::File();
use CGI qw(:standard);
use Text::Query;
@@ -77,6 +77,7 @@ use LONCAPA::lonmetadata();
use HTML::Entities();
use Parse::RecDescent;
use Apache::lonnavmaps;
+use Apache::lonindexer();
######################################################################
######################################################################
@@ -93,7 +94,9 @@ my %persistent_db; # gdbm hash which h
# 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);
@@ -144,54 +147,54 @@ sub handler {
## printing the results. We only need (theoretically) to do
## this once, so the pause indicator is deleted
##
- if (exists($ENV{'form.pause'})) {
+ if (exists($env{'form.pause'})) {
sleep(1);
- delete($ENV{'form.pause'});
+ 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";
+ "$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;
+ # $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::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 '') {
+ 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'},
+ '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'},
+ '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 ($env{'form.phase'} !~ m/(basic|adv|course)_search/) {
if (! &get_persistent_form_data($persistent_db_file)) {
- if ($ENV{'form.phase'} =~ /(run_search|results)/) {
+ if ($env{'form.phase'} =~ /(run_search|results)/) {
&Apache::lonnet::logthis('lonsearchcat:'.
'Unable to recover data from '.
$persistent_db_file);
@@ -216,13 +219,13 @@ END
## Clear out old values from groupsearch database
##
untie %groupsearch_db if (tied(%groupsearch_db));
- if (($ENV{'form.cleargroupsort'} eq '1') ||
- (($ENV{'form.launch'} eq '1') &&
- ($ENV{'form.catalogmode'} eq 'groupsearch'))) {
+ if (($env{'form.cleargroupsort'} eq '1') ||
+ (($env{'form.launch'} eq '1') &&
+ ($env{'form.catalogmode'} eq 'groupsearch'))) {
if (tie(%groupsearch_db,'GDBM_File',$diropendb,&GDBM_WRCREAT(),0640)) {
&start_fresh_session();
untie %groupsearch_db;
- delete($ENV{'form.cleargroupsort'});
+ delete($env{'form.cleargroupsort'});
} else {
# This is a stupid error to give to the user.
# It really tells them nothing.
@@ -236,36 +239,36 @@ END
## Configure hidden fields
##
$hidden_fields = ''."\n";
- if (exists($ENV{'form.catalogmode'})) {
+ $env{'form.persistent_db_id'}.'" />'."\n";
+ if (exists($env{'form.catalogmode'})) {
$hidden_fields .= &hidden_field('catalogmode');
}
- if (exists($ENV{'form.form'})) {
+ if (exists($env{'form.form'})) {
$hidden_fields .= &hidden_field('form');
}
- if (exists($ENV{'form.element'})) {
+ if (exists($env{'form.element'})) {
$hidden_fields .= &hidden_field('element');
}
- if (exists($ENV{'form.titleelement'})) {
+ if (exists($env{'form.titleelement'})) {
$hidden_fields .= &hidden_field('titleelement');
}
- if (exists($ENV{'form.mode'})) {
+ if (exists($env{'form.mode'})) {
$hidden_fields .= &hidden_field('mode');
}
##
## Configure dynamic components of interface
##
- if ($ENV{'form.catalogmode'} eq 'interactive') {
+ if ($env{'form.catalogmode'} eq 'interactive') {
$closebutton="'/adm/searchcat?phase=disp_adv&'.
- 'catalogmode='.$ENV{'form.catalogmode'}.
- '&launch='.$ENV{'form.launch'}.
- '&mode='.$ENV{'form.mode'},
+ 'catalogmode='.$env{'form.catalogmode'}.
+ '&launch='.$env{'form.launch'}.
+ '&mode='.$env{'form.mode'},
text=>"Advanced Search",
bug=>'Searching',});
- } elsif ($ENV{'form.searchmode'} eq 'course search') {
+ } 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'},
+ 'catalogmode='.$env{'form.catalogmode'}.
+ '&launch='.$env{'form.launch'}.
+ '&mode='.$env{'form.mode'},
text=>"Course Search",
bug=>'Searching',});
}
##
## Switch on the phase
##
- if ($ENV{'form.phase'} eq 'disp_basic') {
+ if ($env{'form.phase'} eq 'disp_basic') {
&print_basic_search_form($r,$closebutton,$hidden_fields);
- } elsif ($ENV{'form.phase'} eq 'disp_adv') {
+ } elsif ($env{'form.phase'} eq 'disp_adv') {
&print_advanced_search_form($r,$closebutton,$hidden_fields);
- } elsif ($ENV{'form.phase'} eq 'results') {
+ } elsif ($env{'form.phase'} eq 'results') {
&display_results($r,$importbutton,$closebutton,$diropendb);
- } elsif ($ENV{'form.phase'} =~ /^(sort|run_search)$/) {
+ } elsif ($env{'form.phase'} =~ /^(sort|run_search)$/) {
my ($query,$customquery,$customshow,$libraries,$pretty_string) =
&get_persistent_data($persistent_db_file,
['query','customquery','customshow',
'libraries','pretty_string']);
- if ($ENV{'form.phase'} eq 'sort') {
+ if ($env{'form.phase'} eq 'sort') {
&print_sort_form($r,$pretty_string);
- } elsif ($ENV{'form.phase'} eq 'run_search') {
+ } elsif ($env{'form.phase'} eq 'run_search') {
&run_search($r,$query,$customquery,$customshow,
$libraries,$pretty_string);
}
- } elsif ($ENV{'form.phase'} eq 'course_search') {
+ } elsif ($env{'form.phase'} eq 'course_search') {
&course_search($r);
- } elsif(($ENV{'form.phase'} eq 'basic_search') ||
- ($ENV{'form.phase'} eq 'adv_search')) {
+ } elsif(($env{'form.phase'} eq 'basic_search') ||
+ ($env{'form.phase'} eq 'adv_search')) {
#
# We are running a search, try to parse it
my ($query,$customquery,$customshow,$libraries) =
(undef,undef,undef,undef);
my $pretty_string;
- if ($ENV{'form.phase'} eq 'basic_search') {
+ if ($env{'form.phase'} eq 'basic_search') {
($query,$pretty_string,$libraries) =
&parse_basic_search($r,$closebutton,$hidden_fields);
return OK if (! defined($query));
- &make_persistent({ basicexp => $ENV{'form.basicexp'}},
+ &make_persistent({ basicexp => $env{'form.basicexp'}},
$persistent_db_file);
} else { # Advanced search
($query,$customquery,$customshow,$libraries,$pretty_string)
@@ -384,7 +382,7 @@ The search has been aborted.
END
return OK;
}
- delete($ENV{'form.launch'});
+ delete($env{'form.launch'});
if (! &make_form_data_persistent($r,$persistent_db_file)) {
my $html=&Apache::lonxml::xmlbegin();
$r->print(<'.$/;
}
@@ -470,20 +468,20 @@ sub make_symb {
sub course_search {
my $r=shift;
my $bodytag=&Apache::loncommon::bodytag('Course Search');
- my $pretty_search_string = ''.$ENV{'form.courseexp'}.'';
- my $search_string = $ENV{'form.courseexp'};
+ my $pretty_search_string = ''.$env{'form.courseexp'}.'';
+ my $search_string = $env{'form.courseexp'};
my @New_Words;
undef(%alreadyseen);
- if ($ENV{'form.crsrelated'}) {
- ($search_string,@New_Words) = &related_version($ENV{'form.courseexp'});
+ if ($env{'form.crsrelated'}) {
+ ($search_string,@New_Words) = &related_version($env{'form.courseexp'});
if (@New_Words) {
$pretty_search_string .= ' '.&mt("with related words").": @New_Words.";
} else {
$pretty_search_string .= ' '.&mt('with no related words').".";
}
}
- my $fulltext=$ENV{'form.crsfulltext'};
- my $discuss=$ENV{'form.crsdiscuss'};
+ my $fulltext=$env{'form.crsfulltext'};
+ my $discuss=$env{'form.crsdiscuss'};
my @allwords=($search_string,@New_Words);
$totalfound=0;
my $html=&Apache::lonxml::xmlbegin();
@@ -492,12 +490,12 @@ sub course_search {
$r->rflush();
# ======================================================= Go through the course
my $c=$r->connection;
- if (tie(%hash,'GDBM_File',$ENV{'request.course.fn'}.".db",
+ if (tie(%hash,'GDBM_File',$env{'request.course.fn'}.".db",
&GDBM_READER(),0640)) {
foreach (sort(keys(%hash))) {
if ($c->aborted()) { last; }
if (($_=~/^src\_(.+)$/)) {
- if ($hash{'randomout_'.$1} & !$ENV{'request.role.adv'}) {
+ if ($hash{'randomout_'.$1} & !$env{'request.role.adv'}) {
next;
}
my $symb=&make_symb($1);
@@ -518,8 +516,8 @@ sub course_search {
my $navmap = Apache::lonnavmaps::navmap->new();
my @allres=$navmap->retrieveResources();
my %discussiontime = &Apache::lonnet::dump('discussiontimes',
- $ENV{'course.'.$ENV{'request.course.id'}.'.domain'},
- $ENV{'course.'.$ENV{'request.course.id'}.'.num'});
+ $env{'course.'.$env{'request.course.id'}.'.domain'},
+ $env{'course.'.$env{'request.course.id'}.'.num'});
foreach my $resource (@allres) {
my $result = '';
my $applies = 0;
@@ -532,9 +530,9 @@ sub course_search {
}
}
if (defined($discussiontime{$ressymb})) {
- my %contrib = &Apache::lonnet::restore($ressymb,$ENV{'request.course.id'},
- $ENV{'course.'.$ENV{'request.course.id'}.'.domain'},
- $ENV{'course.'.$ENV{'request.course.id'}.'.num'});
+ my %contrib = &Apache::lonnet::restore($ressymb,$env{'request.course.id'},
+ $env{'course.'.$env{'request.course.id'}.'.domain'},
+ $env{'course.'.$env{'request.course.id'}.'.num'});
if ($contrib{'version'}) {
for (my $id=1;$id<=$contrib{'version'};$id++) {
unless (($contrib{'hidden'}=~/\.$id\./) || ($contrib{'deleted'}=~/\.$id\./)) {
@@ -598,7 +596,7 @@ sub checkonthis {
$r->rflush();
my $result=$title.' ';
- if ($ENV{'request.role.adv'} || !$hash{'encrypted_'.$id}) {
+ if ($env{'request.role.adv'} || !$hash{'encrypted_'.$id}) {
$result.=&Apache::lonnet::metadata($url,'title').' '.
&Apache::lonnet::metadata($url,'subject').' '.
&Apache::lonnet::metadata($url,'abstract').' '.
@@ -619,7 +617,7 @@ sub checkonthis {
$r->print(' ');
}
my $href=$url;
- if ($hash{'encrypted_'.$id} && !$ENV{'request.role.adv'}) {
+ if ($hash{'encrypted_'.$id} && !$env{'request.role.adv'}) {
$href=&Apache::lonenc::encrypted($href)
.'?symb='.&Apache::lonenc::encrypted($symb);
} else {
@@ -688,32 +686,36 @@ Prints the form for the basic search. S
######################################################################
sub print_basic_search_form {
my ($r,$closebutton,$hidden_fields) = @_;
- my $result = ($ENV{'form.catalogmode'} ne 'groupsearch');
+ my $result = ($env{'form.catalogmode'} ne 'groupsearch');
my $bodytag=&Apache::loncommon::bodytag('Search').
&Apache::lonhtmlcommon::breadcrumbs(undef,'Searching','Search_Basic',
undef,undef,
- $ENV{'form.catalogmode'} ne 'groupsearch');
+ $env{'form.catalogmode'} ne 'groupsearch');
my $scrout = &search_html_header().$bodytag;
- if (&Apache::lonnet::allowed('bre',$ENV{'request.role.domain'})) {
+ if (&Apache::lonnet::allowed('bre',$env{'request.role.domain'})) {
# Define interface components
my $userelatedwords= '';
+ ('related',$env{'form.related'},'related')).'';
my $onlysearchdomain='';
+ my $inclext= '';
my $adv_search_link =
''.&mt('Advanced Search').'';
#
$scrout.='
';
}
- if ($ENV{'request.course.id'}) {
+ if ($env{'request.course.id'}) {
my %lt=&Apache::lonlocal::texthash('srch' => 'Search',
'header' => 'Course Search',
'note' => 'Enter terms or phrases, then press "Search" below',
@@ -777,16 +780,16 @@ $lt{'note'}.
ENDCOURSESEARCH
$scrout.=' '.
&Apache::lonhtmlcommon::textbox('courseexp',
- $ENV{'form.courseexp'},40);
+ $env{'form.courseexp'},40);
my $crscheckbox =
&Apache::lonhtmlcommon::checkbox('crsfulltext',
- $ENV{'form.crsfulltext'});
+ $env{'form.crsfulltext'});
my $relcheckbox =
&Apache::lonhtmlcommon::checkbox('crsrelated',
- $ENV{'form.crsrelated'});
+ $env{'form.crsrelated'});
my $discheckbox =
&Apache::lonhtmlcommon::checkbox('crsdiscuss',
- $ENV{'form.crsrelated'});
+ $env{'form.crsrelated'});
$scrout.=(<
| |
@@ -825,7 +828,7 @@ sub print_advanced_search_form{
&Apache::lonhtmlcommon::breadcrumbs(undef,'Searching',
'Search_Advanced',
undef,undef,
- $ENV{'form.catalogmode'} ne 'groupsearch');
+ $env{'form.catalogmode'} ne 'groupsearch');
my %lt=&Apache::lonlocal::texthash('srch' => 'Search',
'reset' => 'Reset',
'help' => 'Help');
@@ -860,18 +863,20 @@ ENDHEADER
'abstract' => 1,
'standards'=> 1,
'mime' => 1,
+ 'subject' => 1,
);
#
- foreach my $field ('title','author','owner','authorspace','modifyinguser',
- 'keywords','notes','abstract','standards','mime') {
+ foreach my $field ('title','author','subject','owner','authorspace',
+ 'modifyinguser','keywords','notes','abstract',
+ 'standards','mime') {
$scrout.=''.&titlefield($fields{$field}).' | '.
&Apache::lonmeta::prettyinput($field,
- $ENV{'form.'.$field},
+ $env{'form.'.$field},
$field,
'advsearch',
$related_word_search{$field},
' | ',
- $ENV{'form.'.$field.'_related'},
+ $env{'form.'.$field.'_related'},
50);
if ($related_word_search{$field}) {
$scrout .= 'related words';
@@ -885,7 +890,7 @@ ENDHEADER
' | '.&titlefield($fields{$field}).' | '.
''.
&Apache::lonmeta::prettyinput($field,
- $ENV{'form.'.$field},
+ $env{'form.'.$field},
$field,
'advsearch',
0).
@@ -894,19 +899,22 @@ ENDHEADER
$scrout.=' |
'.
&titlefield(&mt('MIME Type Category')).' | '.
&Apache::loncommon::filecategoryselect('category',
- $ENV{'form.category'}).
+ $env{'form.category'}).
' |
'.$/;
$scrout.=''.
&titlefield(&mt('Domains')).' | '.
&Apache::loncommon::domain_select('domains',
- $ENV{'form.domains'},1).
- ' |
'.$/;
+ $env{'form.domains'},1).
+ '
'.$/;
#
# Misc metadata
$scrout.=''.
&titlefield(&mt('Copyright/Distribution')).' | '.
&Apache::lonmeta::selectbox('copyright',
- $ENV{'form.copyright'},
+ $env{'form.copyright'},
\&Apache::loncommon::copyrightdescription,
( undef,
&Apache::loncommon::copyrightids)
@@ -914,7 +922,7 @@ ENDHEADER
$scrout.=' |
'.
&titlefield(&mt('Language')).' | '.
&Apache::lonmeta::selectbox('language',
- $ENV{'form.language'},
+ $env{'form.language'},
\&Apache::loncommon::languagedescription,
('any',&Apache::loncommon::languageids)
).' |
';
@@ -1075,7 +1083,9 @@ sub viewoptiontext {
'xml' => 'XML/SGML',
'compact' => 'Compact View',
'fielded' => 'Fielded Format',
- 'summary' => 'Summary View');
+ 'summary' => 'Summary View',
+ 'summarypreview' => 'Summary Preview',
+ 'detailedpreview' => 'Detailed Citation Preview');
return $desc{$code};
}
@@ -1096,16 +1106,16 @@ Outputs: text for box with view options
######################################################################
sub viewoptions {
my $scrout;
- if (! defined($ENV{'form.viewselect'})) {
- $ENV{'form.viewselect'}='detailed';
+ if (! defined($env{'form.viewselect'})) {
+ $env{'form.viewselect'}='detailed';
}
$scrout.=&Apache::lonmeta::selectbox('viewselect',
- $ENV{'form.viewselect'},
+ $env{'form.viewselect'},
\&viewoptiontext,
sort(keys(%Views)));
$scrout.= ' ';
my $countselect = &Apache::lonmeta::selectbox('show',
- $ENV{'form.show'},
+ $env{'form.show'},
undef,
(10,20,50,100,1000,10000));
$scrout .= (' 'x2).&mt('[_1] Records per Page',$countselect).
@@ -1145,7 +1155,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.
@@ -1167,20 +1177,20 @@ sub get_persistent_form_data {
next if ($name !~ /^form./);
# Kludgification begins!
if ($name eq 'form.domains' &&
- $ENV{'form.searchmode'} eq 'basic' &&
- $ENV{'form.phase'} ne 'disp_basic') {
+ $env{'form.searchmode'} eq 'basic' &&
+ $env{'form.phase'} ne 'disp_basic') {
next;
}
# End kludge (hopefully)
- next if (exists($ENV{$name}));
+ next if (exists($env{$name}));
my @values = map {
&Apache::lonnet::unescape($_);
} split(',',$persistent_db{$name});
next if (@values <1);
if ($arrays_allowed{$name}) {
- $ENV{$name} = [@values];
+ $env{$name} = [@values];
} else {
- $ENV{$name} = $values[0] if ($values[0]);
+ $env{$name} = $values[0] if ($values[0]);
}
}
untie (%persistent_db);
@@ -1285,9 +1295,9 @@ sub make_form_data_persistent {
my $r = shift;
my $filename = shift;
my %save;
- foreach (keys(%ENV)) {
+ foreach (keys(%env)) {
next if (!/^form/ || /submit/);
- $save{$_} = $ENV{$_};
+ $save{$_} = $env{$_};
}
return &make_persistent(\%save,$filename);
}
@@ -1335,36 +1345,36 @@ sub parse_advanced_search {
'lastrevisiondatestart_month','lastrevisiondatestart_day',
'lastrevisiondatestart_year','lastrevisiondateend_month',
'lastrevisiondateend_day','lastrevisiondateend_year') {
- $ENV{'form.'.$field}=~s/[^\w\/\s\(\)\=\-\"\']//g;
+ $env{'form.'.$field}=~s/[^\w\/\s\(\)\=\-\"\']//g;
}
foreach ('mode','form','element') {
# is this required? Hmmm.
- next if (! exists($ENV{'form.'.$_}));
- $ENV{'form.'.$_}=&Apache::lonnet::unescape($ENV{'form.'.$_});
- $ENV{'form.'.$_}=~s/[^\w\/\s\(\)\=\-\"\']//g;
+ next if (! exists($env{'form.'.$_}));
+ $env{'form.'.$_}=&Apache::lonnet::unescape($env{'form.'.$_});
+ $env{'form.'.$_}=~s/[^\w\/\s\(\)\=\-\"\']//g;
}
# Preprocess the category form element.
- $ENV{'form.category'} = 'any' if (! defined($ENV{'form.category'}) ||
- ref($ENV{'form.category'}));
+ $env{'form.category'} = 'any' if (! defined($env{'form.category'}) ||
+ ref($env{'form.category'}));
#
# Check to see if enough information was filled in
foreach my $field (@BasicFields) {
- if (&filled($ENV{'form.'.$field})) {
+ if (&filled($env{'form.'.$field})) {
$fillflag++;
}
}
foreach my $field (@StatsFields,@EvalFields) {
- if (&filled($ENV{'form.'.$field.'_max'})) {
+ if (&filled($env{'form.'.$field.'_max'})) {
$fillflag++;
}
- if (&filled($ENV{'form.'.$field.'_min'})) {
+ if (&filled($env{'form.'.$field.'_min'})) {
$fillflag++;
}
}
for my $field ('lowestgradelevel','highestgradelevel') {
- if ( $ENV{'form.'.$field} =~ /^\d+$/ &&
- $ENV{'form.'.$field} > 0) {
+ if ( $env{'form.'.$field} =~ /^\d+$/ &&
+ $env{'form.'.$field} > 0) {
$fillflag++;
}
}
@@ -1379,21 +1389,21 @@ sub parse_advanced_search {
my $font = '';
# Evaluate logical expression AND/OR/NOT phrase fields.
foreach my $field (@BasicFields) {
- next if (!defined($ENV{'form.'.$field}) || $ENV{'form.'.$field} eq '');
+ next if (!defined($env{'form.'.$field}) || $env{'form.'.$field} eq '');
my ($error,$SQLQuery) =
- &process_phrase_input($ENV{'form.'.$field},
- $ENV{'form.'.$field.'_related'},$field);
+ &process_phrase_input($env{'form.'.$field},
+ $env{'form.'.$field.'_related'},$field);
if (defined($error)) {
&output_unparsed_phrase_error($r,$closebutton,'phase=disp_adv',
$hidden_fields,$field);
return;
} else {
$pretty_search_string .=
- $font.$field.': '.$ENV{'form.'.$field};
- if ($ENV{'form.'.$field.'_related'}) {
+ $font.$field.': '.$env{'form.'.$field};
+ if ($env{'form.'.$field.'_related'}) {
my @Words =
&Apache::loncommon::get_related_words
- ($ENV{'form.'.$field});
+ ($env{'form.'.$field});
if (@Words) {
$pretty_search_string.= ' with related words: '.
join(', ',@Words[0..4]);
@@ -1409,11 +1419,11 @@ sub parse_advanced_search {
# Make the 'mime' from 'form.category' and 'form.extension'
#
my $searchphrase;
- if (exists($ENV{'form.category'}) &&
- $ENV{'form.category'} !~ /^\s*$/ &&
- $ENV{'form.category'} ne 'any') {
+ if (exists($env{'form.category'}) &&
+ $env{'form.category'} !~ /^\s*$/ &&
+ $env{'form.category'} ne 'any') {
my @extensions = &Apache::loncommon::filecategorytypes
- ($ENV{'form.category'});
+ ($env{'form.category'});
if (scalar(@extensions) > 0) {
$searchphrase = join(' OR ',@extensions);
}
@@ -1426,45 +1436,45 @@ sub parse_advanced_search {
}
#
# Evaluate option lists
- if ($ENV{'form.lowestgradelevel'} &&
- $ENV{'form.lowestgradelevel'} ne '0' &&
- $ENV{'form.lowestgradelevel'} =~ /^\d+$/) {
+ if ($env{'form.lowestgradelevel'} &&
+ $env{'form.lowestgradelevel'} ne '0' &&
+ $env{'form.lowestgradelevel'} =~ /^\d+$/) {
push(@queries,
- '(lowestgradelevel>='.$ENV{'form.lowestgradelevel'}.')');
+ '(lowestgradelevel>='.$env{'form.lowestgradelevel'}.')');
$pretty_search_string.="lowestgradelevel>=".
- $ENV{'form.lowestgradelevel'}."
\n";
+ $env{'form.lowestgradelevel'}."
\n";
}
- if ($ENV{'form.highestgradelevel'} &&
- $ENV{'form.highestgradelevel'} ne '0' &&
- $ENV{'form.highestgradelevel'} =~ /^\d+$/) {
+ if ($env{'form.highestgradelevel'} &&
+ $env{'form.highestgradelevel'} ne '0' &&
+ $env{'form.highestgradelevel'} =~ /^\d+$/) {
push(@queries,
- '(highestgradelevel<='.$ENV{'form.highestgradelevel'}.')');
+ '(highestgradelevel<='.$env{'form.highestgradelevel'}.')');
$pretty_search_string.="highestgradelevel<=".
- $ENV{'form.highestgradelevel'}."
\n";
+ $env{'form.highestgradelevel'}."
\n";
}
- if ($ENV{'form.language'} and $ENV{'form.language'} ne 'any') {
- push @queries,"(language like \"$ENV{'form.language'}\")";
+ if ($env{'form.language'} and $env{'form.language'} ne 'any') {
+ push @queries,"(language like \"$env{'form.language'}\")";
$pretty_search_string.=$font."language= ".
- &Apache::loncommon::languagedescription($ENV{'form.language'}).
+ &Apache::loncommon::languagedescription($env{'form.language'}).
"
\n";
}
- if ($ENV{'form.copyright'} and $ENV{'form.copyright'} ne 'any') {
- push @queries,"(copyright like \"$ENV{'form.copyright'}\")";
+ if ($env{'form.copyright'} and $env{'form.copyright'} ne 'any') {
+ push @queries,"(copyright like \"$env{'form.copyright'}\")";
$pretty_search_string.=$font."copyright = ".
- &Apache::loncommon::copyrightdescription($ENV{'form.copyright'}).
+ &Apache::loncommon::copyrightdescription($env{'form.copyright'}).
"
\n";
}
#
# Statistics
foreach my $field (@StatsFields,@EvalFields) {
my ($min,$max);
- if (exists($ENV{'form.'.$field.'_min'}) &&
- $ENV{'form.'.$field.'_min'} ne '') {
- $min = $ENV{'form.'.$field.'_min'};
- }
- if (exists($ENV{'form.'.$field.'_max'}) &&
- $ENV{'form.'.$field.'_max'} ne '') {
- $max = $ENV{'form.'.$field.'_max'};
+ if (exists($env{'form.'.$field.'_min'}) &&
+ $env{'form.'.$field.'_min'} ne '') {
+ $min = $env{'form.'.$field.'_min'};
+ }
+ if (exists($env{'form.'.$field.'_max'}) &&
+ $env{'form.'.$field.'_max'} ne '') {
+ $max = $env{'form.'.$field.'_max'};
}
next if (! defined($max) && ! defined($min));
if (defined($min) && defined($max)) {
@@ -1517,17 +1527,17 @@ sub parse_advanced_search {
## because I was unable to figureout exactly how it worked and could
## not imagine people actually using it. MH
##
- # if ($ENV{'form.custommetadata'}) {
+ # if ($env{'form.custommetadata'}) {
# $pretty_search_string .=$font."Custom Metadata Search: ".
- # $ENV{'form.custommetadata'}."
\n";
+ # $env{'form.custommetadata'}."
\n";
# $customquery=&build_custommetadata_query('custommetadata',
- # $ENV{'form.custommetadata'});
+ # $env{'form.custommetadata'});
# }
my $customshow=undef;
- # if ($ENV{'form.customshow'}) {
+ # if ($env{'form.customshow'}) {
# $pretty_search_string .=$font."Custom Metadata Display: ".
- # $ENV{'form.customshow'}."
\n";
- # $customshow=$ENV{'form.customshow'};
+ # $env{'form.customshow'}."
\n";
+ # $customshow=$env{'form.customshow'};
# $customshow=~s/[^\w\s]//g;
# my @fields=split(/\s+/,$customshow);
# $customshow=join(" ",@fields);
@@ -1535,10 +1545,10 @@ sub parse_advanced_search {
##
## Deal with restrictions to given domains
##
- my ($libraries_to_query,$pretty_domains_string,$domain_sql_restriction) =
- &parse_domain_restrictions();
- push(@queries,$domain_sql_restriction);
- $pretty_search_string .= $pretty_domains_string."
\n";
+ my ($libraries_to_query,$pretty_domains_string) = &parse_domain_restrictions();
+ if ($pretty_domains_string) {
+ $pretty_search_string .= $pretty_domains_string."
\n";
+ }
#
if (@queries) {
$query="SELECT * FROM metadata WHERE (".join(") AND (",@queries).')';
@@ -1552,35 +1562,26 @@ sub parse_advanced_search {
sub parse_domain_restrictions {
my $libraries_to_query = undef;
- # $ENV{'form.domains'} can be either a scalar or an array reference.
+ # $env{'form.domains'} can be either a scalar or an array reference.
# We need an array.
- if (! exists($ENV{'form.domains'}) || $ENV{'form.domains'} eq '') {
+ if (! exists($env{'form.domains'}) || $env{'form.domains'} eq '') {
return (undef,'',undef);
}
- my @allowed_domains;
- if (ref($ENV{'form.domains'})) {
- @allowed_domains = @{$ENV{'form.domains'}};
- } else {
- @allowed_domains = ($ENV{'form.domains'});
- }
+ my @allowed_domains = &Apache::loncommon::get_env_multiple('form.domains');
#
my %domain_hash = ();
my $pretty_domains_string;
- my $domain_sql_restriction;
foreach (@allowed_domains) {
$domain_hash{$_}++;
}
if ($domain_hash{'any'}) {
$pretty_domains_string = "In all LON-CAPA domains.";
- $domain_sql_restriction = undef;
} else {
if (@allowed_domains > 1) {
$pretty_domains_string = "In LON-CAPA domains:";
} else {
$pretty_domains_string = "In LON-CAPA domain ";
}
- $domain_sql_restriction =
- '(domain="'.join('" OR domain="',@allowed_domains).'")';
foreach (sort @allowed_domains) {
$pretty_domains_string .= "".$_." ";
}
@@ -1591,8 +1592,7 @@ sub parse_domain_restrictions {
}
}
return ($libraries_to_query,
- $pretty_domains_string,
- $domain_sql_restriction);
+ $pretty_domains_string);
}
######################################################################
@@ -1613,19 +1613,18 @@ sub parse_basic_search {
#
# Clean up fields for safety
for my $field ('basicexp') {
- $ENV{"form.$field"}=~s/[^\w\s\'\"\!\(\)\-]//g;
+ $env{"form.$field"}=~s/[^\w\s\'\"\!\(\)\-]//g;
}
foreach ('mode','form','element') {
# is this required? Hmmm.
- next unless (exists($ENV{"form.$_"}));
- $ENV{"form.$_"}=&Apache::lonnet::unescape($ENV{"form.$_"});
- $ENV{"form.$_"}=~s/[^\w\/\s\(\)\=\-\"\']//g;
+ next unless (exists($env{"form.$_"}));
+ $env{"form.$_"}=&Apache::lonnet::unescape($env{"form.$_"});
+ $env{"form.$_"}=~s/[^\w\/\s\(\)\=\-\"\']//g;
}
- my ($libraries_to_query,$pretty_domains_string,$domain_sql_restriction) =
- &parse_domain_restrictions();
+ my ($libraries_to_query,$pretty_domains_string) = &parse_domain_restrictions();
#
# Check to see if enough of a query is filled in
- my $search_string = $ENV{'form.basicexp'};
+ my $search_string = $env{'form.basicexp'};
if (! &filled($search_string)) {
&output_blank_field_error($r,$closebutton,'phase=disp_basic');
return OK;
@@ -1637,7 +1636,7 @@ sub parse_basic_search {
'notes','abstract','keywords')
).')';
my ($error,$SQLQuery) = &process_phrase_input($search_string,
- $ENV{'form.related'},
+ $env{'form.related'},
$searchfield);
if ($error) {
&output_unparsed_phrase_error($r,$closebutton,'phase=disp_basic',
@@ -1645,9 +1644,6 @@ sub parse_basic_search {
return;
}
push(@Queries,$SQLQuery);
- if (defined($domain_sql_restriction) && $domain_sql_restriction ne '') {
- push(@Queries,$domain_sql_restriction);
- }
#foreach my $q (@Queries) {
# &Apache::lonnet::logthis(' '.$q);
#}
@@ -2012,13 +2008,13 @@ sub copyright_check {
$Metadata->{'url'});
# Check for priv
if (($Metadata->{'copyright'} eq 'priv') &&
- (($ENV{'user.name'} ne $resname) &&
- ($ENV{'user.domain'} ne $resdom))) {
+ (($env{'user.name'} ne $resname) &&
+ ($env{'user.domain'} ne $resdom))) {
return 0;
}
# Check for domain
if (($Metadata->{'copyright'} eq 'domain') &&
- ($ENV{'user.domain'} ne $resdom)) {
+ ($env{'user.domain'} ne $resdom)) {
return 0;
}
return 1;
@@ -2099,7 +2095,7 @@ sub print_sort_form {
my $bodytag=&Apache::loncommon::bodytag(undef,undef,undef,1).
&Apache::lonhtmlcommon::breadcrumbs
(undef,'Searching','Searching',undef,undef,
- $ENV{'form.catalogmode'} ne 'groupsearch');
+ $env{'form.catalogmode'} ne 'groupsearch');
##
my %SortableFields=&Apache::lonlocal::texthash(
@@ -2118,7 +2114,7 @@ sub print_sort_form {
lastrevisiondate => 'Revision Date'
);
##
- my $table = $ENV{'form.table'};
+ my $table = $env{'form.table'};
return if (! &ensure_db_and_table($r,$table));
##
## Get the number of results
@@ -2139,7 +2135,7 @@ $html
");
# }
return;
@@ -2619,7 +2618,7 @@ sub display_results {
##
## Set viewing function
##
- my $viewfunction = $Views{$ENV{'form.viewselect'}};
+ my $viewfunction = $Views{$env{'form.viewselect'}};
if (!defined($viewfunction)) {
$r->print("Internal Error - Bad view selected.\n");
$r->rflush();
@@ -2635,7 +2634,7 @@ sub display_results {
my $action = "/adm/searchcat?phase=results";
##
## Deal with groupsearch by opening the groupsearch db file.
- if ($ENV{'form.catalogmode'} eq 'groupsearch') {
+ if ($env{'form.catalogmode'} eq 'groupsearch') {
if (! tie(%groupsearch_db,'GDBM_File',$diropendb,
&GDBM_WRCREAT(),0640)) {
$r->print('Unable to store import results.