--- loncom/interface/lonsearchcat.pm 2004/04/21 15:48:34 1.213
+++ loncom/interface/lonsearchcat.pm 2004/04/22 20:05:18 1.215
@@ -1,7 +1,7 @@
# The LearningOnline Network with CAPA
# Search Catalog
#
-# $Id: lonsearchcat.pm,v 1.213 2004/04/21 15:48:34 matthew Exp $
+# $Id: lonsearchcat.pm,v 1.215 2004/04/22 20:05:18 matthew Exp $
#
# Copyright Michigan State University Board of Trustees
#
@@ -830,11 +830,12 @@ sub viewoptions {
\&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').''.$/;
+ my $countselect = &Apache::lonmeta::selectbox('show',
+ $ENV{'form.show'},
+ undef,
+ (10,20,50,100,1000,10000));
+ $scrout .= (' 'x2).&mt('[_1] Records per Page',$countselect).
+ ''.$/;
return $scrout;
}
@@ -1801,12 +1802,37 @@ sub update_status {
$r->rflush();
}
+{
+ my $max_time = 40; # seconds for the search to complete
+ my $start_time = 0;
+ my $last_time = 0;
+
+sub reset_timing {
+ $start_time = 0;
+ $last_time = 0;
+}
+
+sub time_left {
+ if ($start_time == 0) {
+ $start_time = time;
+ }
+ my $time_left = $max_time - (time - $start_time);
+ $time_left = 0 if ($time_left < 0);
+ return $time_left;
+}
+
sub update_seconds {
- my ($r,$text) = @_;
- $text =~ s/\'/\\\'/g;
- $r->print
- ("\n");
- $r->rflush();
+ my ($r) = @_;
+ my $time = &time_left();
+ if (($last_time-$time) > 0) {
+ $r->print("\n");
+ $r->rflush();
+ }
+ $last_time = $time;
+}
+
}
######################################################################
@@ -1855,11 +1881,6 @@ sub run_search {
my $bodytag=&Apache::loncommon::bodytag(undef,undef,undef,1);
my $connection = $r->connection;
#
- # Timing variables
- #
- my $starttime = time;
- my $max_time = 30; # seconds for the search to complete
- #
# Print run_search header
#
$r->print(< 2) {
$pretty_string = join '
',(@Lines[0..2],'....
');
}
- $r->print(&mt("Search").": ".$pretty_string);
+ $r->print(&mt("Search: [_1]",$pretty_string));
$r->rflush();
#
# Determine the servers we need to contact.
@@ -1891,6 +1912,8 @@ END
@Servers_to_contact = sort(keys(%Apache::lonnet::libserv));
}
my %Server_status;
+ #
+ # Check on the mysql table we will use to store results.
my $table =$ENV{'form.table'};
if (! defined($table) || $table eq '' || $table =~ /\D/ ) {
$r->print("Unable to determine table id to store search results in.".
@@ -1935,20 +1958,18 @@ END
END
$r->rflush();
- my $time_remaining = $max_time - (time - $starttime) ;
- $time_remaining = 0 if ($time_remaining <0);
- my $last_time = $time_remaining;
- &update_seconds($r,$time_remaining);
- &update_status($r,'contacting '.$Servers_to_contact[0]);
- while (($time_remaining > 0) &&
+ &reset_timing();
+ &update_seconds($r);
+ &update_status($r,&mt('contacting [_1]',$Servers_to_contact[0]));
+ while (&time_left() &&
((@Servers_to_contact) || keys(%Server_status))) {
- $time_remaining = $max_time - (time - $starttime) ;
- &update_seconds($r,$time_remaining);
- # Send out a search request if it needs to be done.
+ &update_seconds($r);
+ #
+ # Send out a search request
if (@Servers_to_contact) {
# Contact one server
my $server = shift(@Servers_to_contact);
- &update_status($r,&mt('contacting').' '.$server);
+ &update_status($r,&mt('contacting [_1]',$server));
my $reply=&Apache::lonnet::metadata_query($query,$customquery,
$customshow,[$server]);
($server) = keys(%$reply);
@@ -1960,7 +1981,7 @@ END
# left to contact.
if (scalar (keys(%Server_status))) {
&update_status($r,
- &mt('waiting on').' '.(join(' ',keys(%Server_status))));
+ &mt('waiting on [_1]',join(' ',keys(%Server_status))));
}
sleep(1);
}
@@ -1969,12 +1990,7 @@ END
# have results from yet, looking for results.
while (my ($server,$status) = each(%Server_status)) {
last if ($connection->aborted());
- $time_remaining = $max_time - (time - $starttime) ;
- $time_remaining = 0 if ($time_remaining < 0);
- if ($last_time - $time_remaining > 0) {
- $last_time = $time_remaining;
- &update_seconds($r,$time_remaining);
- }
+ &update_seconds($r);
if ($status eq 'con_lost') {
delete ($Server_status{$server});
next;
@@ -1982,12 +1998,12 @@ END
$status=~/^([\.\w]+)$/;
my $datafile=$r->dir_config('lonDaemons').'/tmp/'.$1;
if (-e $datafile && ! -e "$datafile.end") {
- &update_status($r,&mt('Receiving results from').' '.$server);
+ &update_status($r,&mt('Receiving results from [_1]',$server));
next;
}
last if ($connection->aborted());
if (-e "$datafile.end") {
- &update_status($r,&mt('Reading results from').' '.$server);
+ &update_status($r,&mt('Reading results from [_1]',$server));
if (-z "$datafile") {
delete($Server_status{$server});
next;
@@ -2002,30 +2018,30 @@ END
# Read in the whole file.
while (my $result = <$fh>) {
last if ($connection->aborted());
- # handle custom fields? Someday we will!
+ #
+ # Records are stored one per line
chomp($result);
- next unless $result;
+ next if (! $result);
+ #
# Parse the result.
my %Fields = &parse_raw_result($result,$server);
$Fields{'hostname'} = $server;
+ #
+ # Skip based on copyright
next if (! ©right_check(\%Fields));
+ #
# Store the result in the mysql database
my $result = &Apache::lonmysql::store_row($table,\%Fields);
if (! defined($result)) {
$r->print(&Apache::lonmysql::get_error());
}
- # $r->print(&Apache::lonmysql::get_debug());
+ #
$hitcountsum ++;
- $time_remaining = $max_time - (time - $starttime) ;
- $time_remaining = 0 if ($time_remaining < 0);
- if ($last_time - $time_remaining > 0) {
- &update_seconds($r,$time_remaining);
- $last_time = $time_remaining;
- }
+ &update_seconds($r);
if ($hitcountsum % 50 == 0) {
&update_count_status($r,$hitcountsum);
}
- } # End of foreach (@results)
+ }
$fh->close();
# $server is only deleted if the results file has been
# found and (successfully) opened. This may be a bad idea.
@@ -2035,21 +2051,16 @@ END
&update_count_status($r,$hitcountsum);
}
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;
- &update_seconds($r,$time_remaining);
- }
+ &update_seconds($r);
}
- &update_status($r,&mt('Search Complete').$server);
- &update_seconds($r,0);
+ &update_status($r,&mt('Search Complete [_1]',$server));
+ &update_seconds($r);
#
- &Apache::lonmysql::disconnect_from_db();
+ &Apache::lonmysql::disconnect_from_db(); # This is unneccessary
#
# We have run out of time or run out of servers to talk to and
- # results to get.
+ # results to get, so let the client know the top frame needs to be
+ # loaded from /adm/searchcat
$r->print("