--- loncom/interface/lonsearchcat.pm 2002/09/16 20:09:45 1.157
+++ loncom/interface/lonsearchcat.pm 2003/02/03 04:02:17 1.164
@@ -1,7 +1,7 @@
# The LearningOnline Network with CAPA
# Search Catalog
#
-# $Id: lonsearchcat.pm,v 1.157 2002/09/16 20:09:45 www Exp $
+# $Id: lonsearchcat.pm,v 1.164 2003/02/03 04:02:17 harris41 Exp $
#
# Copyright Michigan State University Board of Trustees
#
@@ -79,7 +79,6 @@ use Apache::lonnet();
use Apache::File();
use CGI qw(:standard);
use Text::Query;
-use DBI;
use GDBM_File;
use Apache::loncommon();
use Apache::lonmysql();
@@ -191,7 +190,8 @@ sub handler {
##
&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']);
##
## 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
@@ -242,11 +242,13 @@ END
## Clear out old values from groupsearch database
##
untie %groupsearch_db if (tied(%groupsearch_db));
- if (($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'});
} else {
# This is a stupid error to give to the user.
# It really tells them nothing.
@@ -436,7 +438,9 @@ ENDDOCUMENT
' ';
my $checkbox = &simplecheckbox('related',$ENV{'form.related'});
$scrout.=<
\n";
$scrout.=&searchphrasefield('publisher owner','owner',
$ENV{'form.owner'});
$scrout.="\n";
- $ENV{'form.category'}='any' unless length($ENV{'form.category'});
+ $ENV{'form.category'}='any' if (! defined($ENV{'form.category'}));
$scrout.=&selectbox('File Category','category',
$ENV{'form.category'},
'any','Any category',
@@ -689,7 +693,7 @@ sub get_persistent_form_data {
&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)) {
@@ -1131,7 +1135,7 @@ sub parse_advanced_search {
'lastrevisiondatestart_month','lastrevisiondatestart_day',
'lastrevisiondatestart_year','lastrevisiondateend_month',
'lastrevisiondateend_day','lastrevisiondateend_year',
- 'notes','abstract','mime','language','owner',
+ 'notes','abstract','extension','language','owner',
'custommetadata','customshow','category') {
$ENV{"form.$field"}=~s/[^\w\/\s\(\)\=\-\"\']//g;
}
@@ -1142,16 +1146,13 @@ sub parse_advanced_search {
$ENV{"form.$_"}=~s/[^\w\/\s\(\)\=\-\"\']//g;
}
# Preprocess the category form element.
- $ENV{'form.category'} = 'any' if (ref($ENV{'form.category'}));
- if ($ENV{'form.category'} ne 'any') {
- my @extensions = &Apache::loncommon::filecategorytypes
- ($ENV{'form.category'});
- $ENV{'form.mime'} = join ' OR ',@extensions;
- }
+ $ENV{'form.category'} = 'any' if (! defined($ENV{'form.category'}) ||
+ ref($ENV{'form.category'}));
+ #
# Check to see if enough information was filled in
for my $field ('title','author','subject','keywords','url','version',
- 'notes','abstract','mime','language','owner',
- 'custommetadata') {
+ 'notes','abstract','category','extension','language',
+ 'owner','custommetadata') {
if (&filled($ENV{"form.$field"})) {
$fillflag++;
}
@@ -1166,7 +1167,7 @@ sub parse_advanced_search {
my $font = '';
# Evaluate logical expression AND/OR/NOT phrase fields.
foreach my $field ('title','author','subject','notes','abstract','url',
- 'keywords','version','owner','mime') {
+ 'keywords','version','owner') {
if ($ENV{'form.'.$field}) {
my $searchphrase = $ENV{'form.'.$field};
$pretty_search_string .= $font."$field contains ".
@@ -1185,10 +1186,30 @@ sub parse_advanced_search {
push @queries,&build_SQL_query($field,$searchphrase);
}
}
- # I dislike the hack below.
- if ($ENV{'form.category'}) {
- $ENV{'form.mime'}='';
+ #
+ # 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') {
+ my @extensions = &Apache::loncommon::filecategorytypes
+ ($ENV{'form.category'});
+ if (scalar(@extensions) > 0) {
+ $searchphrase = join(' OR ',@extensions);
+ }
+ }
+ if (exists($ENV{'form.extension'}) && $ENV{'form.extension'} !~ /^\s*$/) {
+ $searchphrase .= ' OR ' if (defined($searchphrase));
+ my @extensions = split(/,/,$ENV{'form.extension'});
+ $searchphrase .= join(' OR ',@extensions);
+ }
+ if (defined($searchphrase)) {
+ push @queries,&build_SQL_query('mime',$searchphrase);
+ $pretty_search_string .=$font.'mime contains '.
+ $searchphrase.' ';
}
+ #####
# Evaluate option lists
if ($ENV{'form.language'} and $ENV{'form.language'} ne 'any') {
push @queries,"(language like \"$ENV{'form.language'}\")";
@@ -1871,6 +1892,7 @@ sub revise_button {
$revise_phase = 'disp_adv' if ($ENV{'form.searchmode'} eq 'advanced');
my $newloc = '/adm/searchcat'.
'?persistent_db_id='.$ENV{'form.persistent_db_id'}.
+ '&cleargroupsort=1'.
'&phase='.$revise_phase;
my $result = qq{ };
@@ -1972,7 +1994,7 @@ END
my $time_remaining = $max_time - (time - $starttime) ;
my $last_time = $time_remaining;
&update_seconds($r,$time_remaining);
- while (($time_remaining > 0) &&
+ while (($time_remaining > 0) &&
((@Servers_to_contact) || keys(%Server_status))) {
# Send out a search request if it needs to be done.
if (@Servers_to_contact) {
@@ -1990,7 +2012,13 @@ END
# left to contact.
sleep(1);
}
- &update_status($r,'waiting on '.(join(' ',keys(%Server_status))));
+ #
+ if (scalar (keys(%Server_status))) {
+ &update_status($r,'waiting on '.(join(' ',keys(%Server_status))));
+ }
+ #
+ # Loop through the servers we have contacted but do not
+ # have results from yet, looking for results.
while (my ($server,$status) = each(%Server_status)) {
last if ($connection->aborted());
if ($status eq 'con_lost') {
@@ -2053,6 +2081,7 @@ END
}
last if ($connection->aborted());
# Finished looping through the servers
+ $starttime = time if (@Servers_to_contact);
$time_remaining = $max_time - (time - $starttime) ;
if ($last_time - $time_remaining > 0) {
$last_time = $time_remaining;
@@ -2144,6 +2173,10 @@ sub display_results {
return;
}
##
+ ## $checkbox_num is a count of the number of checkboxes output on the
+ ## page this is used only during catalogmode=groupsearch.
+ my $checkbox_num = 0;
+ ##
## Get the catalog controls setup
##
my $action = "/adm/searchcat?phase=results";
@@ -2216,13 +2249,13 @@ sub display_results {
##
foreach my $row (@Results) {
if ($connection->aborted()) {
- untie %groupsearch_db if (tied(%groupsearch_db));
- &Apache::lonmysql::disconnect_from_db();
+ &cleanup();
return;
}
my %Fields = %{&parse_row(@$row)};
my $output="
\n";
- my $prefix=&catalogmode_output($Fields{'title'},$Fields{'url'});
+ my $prefix=&catalogmode_output($Fields{'title'},$Fields{'url'},
+ $Fields{'id'},$checkbox_num++);
# Render the result into html
$output.= &$viewfunction($prefix,%Fields);
# Print them out as they come in.
@@ -2253,22 +2286,18 @@ sub display_results {
=pod
-=item &catalogmode_output($title,$url)
+=item &catalogmode_output($title,$url,$fnum,$checkbox_num)
Returns html needed for the various catalog modes. Gets inputs from
-$ENV{'form.catalogmode'}. Stores data in %groupsearch_db and $fnum
-(local variable).
+$ENV{'form.catalogmode'}. Stores data in %groupsearch_db.
=cut
######################################################################
######################################################################
-{
-my $fnum = 0;
-
sub catalogmode_output {
my $output = '';
- my ($title,$url) = @_;
+ my ($title,$url,$fnum,$checkbox_num) = @_;
if ($ENV{'form.catalogmode'} eq 'interactive') {
$title=~ s/\'/\\\'/g;
if ($ENV{'form.catalogmode'} eq 'interactive') {
@@ -2284,15 +2313,12 @@ END
$output.=<
+onClick="javascript:queue($checkbox_num,$fnum)" />
END
- $fnum++;
}
return $output;
}
-
-}
######################################################################
######################################################################
@@ -2540,8 +2566,8 @@ SCRIPT
}
$result.=<
LON-CAPA Digital Library Search Results
@@ -2934,6 +2961,16 @@ sub start_fresh_session {
1;
+sub cleanup {
+ if (tied(%groupsearch_db)) {
+ &Apache::lonnet::logthis('Cleanup searchcat: groupsearch_db');
+ unless (untie(%groupsearch_db)) {
+ &Apache::lonnet::logthis('Failed cleanup searchcat: groupsearch_db');
+ }
+ }
+ &Apache::lonmysql::disconnect_from_db();
+}
+
__END__
=pod