version 1.213, 2004/04/21 15:48:34
|
version 1.214, 2004/04/21 18:04:55
|
Line 830 sub viewoptions {
|
Line 830 sub viewoptions {
|
\&viewoptiontext, |
\&viewoptiontext, |
sort(keys(%Views))); |
sort(keys(%Views))); |
$scrout.= ' '; |
$scrout.= ' '; |
$scrout.=&Apache::lonmeta::selectbox('show', |
my $countselect = &Apache::lonmeta::selectbox('show', |
$ENV{'form.show'}, |
$ENV{'form.show'}, |
undef, |
undef, |
(10,20,50,100,1000,10000)); |
(10,20,50,100,1000,10000)); |
$scrout .= (' 'x2).&mt('Records per Page').'</nobr>'.$/; |
$scrout .= (' 'x2).&mt('[_1] Records per Page',$countselect). |
|
'</nobr>'.$/; |
return $scrout; |
return $scrout; |
} |
} |
|
|
Line 1801 sub update_status {
|
Line 1802 sub update_status {
|
$r->rflush(); |
$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 { |
sub update_seconds { |
my ($r,$text) = @_; |
my ($r) = @_; |
$text =~ s/\'/\\\'/g; |
my $time = &time_left(); |
$r->print |
if (($last_time-$time) > 0) { |
("<script>document.statusform.seconds.value = ' $text'</script>\n"); |
&Apache::lonnet::logthis('time left = '.$time.' last time = '.$time); |
$r->rflush(); |
&Apache::lonnet::logthis('updating time'); |
|
$r->print("<script>". |
|
"document.statusform.seconds.value = '$time'". |
|
"</script>\n"); |
|
$r->rflush(); |
|
} |
|
$last_time = $time; |
|
} |
|
|
} |
} |
|
|
###################################################################### |
###################################################################### |
Line 1855 sub run_search {
|
Line 1883 sub run_search {
|
my $bodytag=&Apache::loncommon::bodytag(undef,undef,undef,1); |
my $bodytag=&Apache::loncommon::bodytag(undef,undef,undef,1); |
my $connection = $r->connection; |
my $connection = $r->connection; |
# |
# |
# Timing variables |
|
# |
|
my $starttime = time; |
|
my $max_time = 30; # seconds for the search to complete |
|
# |
|
# Print run_search header |
# Print run_search header |
# |
# |
$r->print(<<END); |
$r->print(<<END); |
Line 1876 END
|
Line 1899 END
|
if (@Lines > 2) { |
if (@Lines > 2) { |
$pretty_string = join '<br \>',(@Lines[0..2],'....<br />'); |
$pretty_string = join '<br \>',(@Lines[0..2],'....<br />'); |
} |
} |
$r->print(&mt("Search").": ".$pretty_string); |
$r->print(&mt("Search: [_1]",$pretty_string)); |
$r->rflush(); |
$r->rflush(); |
# |
# |
# Determine the servers we need to contact. |
# Determine the servers we need to contact. |
Line 1891 END
|
Line 1914 END
|
@Servers_to_contact = sort(keys(%Apache::lonnet::libserv)); |
@Servers_to_contact = sort(keys(%Apache::lonnet::libserv)); |
} |
} |
my %Server_status; |
my %Server_status; |
|
# |
|
# Check on the mysql table we will use to store results. |
my $table =$ENV{'form.table'}; |
my $table =$ENV{'form.table'}; |
if (! defined($table) || $table eq '' || $table =~ /\D/ ) { |
if (! defined($table) || $table eq '' || $table =~ /\D/ ) { |
$r->print("Unable to determine table id to store search results in.". |
$r->print("Unable to determine table id to store search results in.". |
Line 1935 END
|
Line 1960 END
|
</form> |
</form> |
END |
END |
$r->rflush(); |
$r->rflush(); |
my $time_remaining = $max_time - (time - $starttime) ; |
&reset_timing(); |
$time_remaining = 0 if ($time_remaining <0); |
&update_seconds($r); |
my $last_time = $time_remaining; |
&update_status($r,&mt('contacting [_1]',$Servers_to_contact[0])); |
&update_seconds($r,$time_remaining); |
while (&time_left() && |
&update_status($r,'contacting '.$Servers_to_contact[0]); |
|
while (($time_remaining > 0) && |
|
((@Servers_to_contact) || keys(%Server_status))) { |
((@Servers_to_contact) || keys(%Server_status))) { |
$time_remaining = $max_time - (time - $starttime) ; |
&update_seconds($r); |
&update_seconds($r,$time_remaining); |
# |
# Send out a search request if it needs to be done. |
# Send out a search request |
if (@Servers_to_contact) { |
if (@Servers_to_contact) { |
# Contact one server |
# Contact one server |
my $server = shift(@Servers_to_contact); |
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, |
my $reply=&Apache::lonnet::metadata_query($query,$customquery, |
$customshow,[$server]); |
$customshow,[$server]); |
($server) = keys(%$reply); |
($server) = keys(%$reply); |
Line 1960 END
|
Line 1983 END
|
# left to contact. |
# left to contact. |
if (scalar (keys(%Server_status))) { |
if (scalar (keys(%Server_status))) { |
&update_status($r, |
&update_status($r, |
&mt('waiting on').' '.(join(' ',keys(%Server_status)))); |
&mt('waiting on [_1]',join(' ',keys(%Server_status)))); |
} |
} |
sleep(1); |
sleep(1); |
} |
} |
Line 1969 END
|
Line 1992 END
|
# have results from yet, looking for results. |
# have results from yet, looking for results. |
while (my ($server,$status) = each(%Server_status)) { |
while (my ($server,$status) = each(%Server_status)) { |
last if ($connection->aborted()); |
last if ($connection->aborted()); |
$time_remaining = $max_time - (time - $starttime) ; |
&update_seconds($r); |
$time_remaining = 0 if ($time_remaining < 0); |
|
if ($last_time - $time_remaining > 0) { |
|
$last_time = $time_remaining; |
|
&update_seconds($r,$time_remaining); |
|
} |
|
if ($status eq 'con_lost') { |
if ($status eq 'con_lost') { |
delete ($Server_status{$server}); |
delete ($Server_status{$server}); |
next; |
next; |
Line 1982 END
|
Line 2000 END
|
$status=~/^([\.\w]+)$/; |
$status=~/^([\.\w]+)$/; |
my $datafile=$r->dir_config('lonDaemons').'/tmp/'.$1; |
my $datafile=$r->dir_config('lonDaemons').'/tmp/'.$1; |
if (-e $datafile && ! -e "$datafile.end") { |
if (-e $datafile && ! -e "$datafile.end") { |
&update_status($r,&mt('Receiving results from').' '.$server); |
&update_status($r,&mt('Receiving results from [_1]',$server)); |
next; |
next; |
} |
} |
last if ($connection->aborted()); |
last if ($connection->aborted()); |
if (-e "$datafile.end") { |
if (-e "$datafile.end") { |
&update_status($r,&mt('Reading results from').' '.$server); |
&update_status($r,&mt('Reading results from [_1]',$server)); |
if (-z "$datafile") { |
if (-z "$datafile") { |
delete($Server_status{$server}); |
delete($Server_status{$server}); |
next; |
next; |
Line 2002 END
|
Line 2020 END
|
# Read in the whole file. |
# Read in the whole file. |
while (my $result = <$fh>) { |
while (my $result = <$fh>) { |
last if ($connection->aborted()); |
last if ($connection->aborted()); |
# handle custom fields? Someday we will! |
# |
|
# Records are stored one per line |
chomp($result); |
chomp($result); |
next unless $result; |
next if (! $result); |
|
# |
# Parse the result. |
# Parse the result. |
my %Fields = &parse_raw_result($result,$server); |
my %Fields = &parse_raw_result($result,$server); |
$Fields{'hostname'} = $server; |
$Fields{'hostname'} = $server; |
|
# |
|
# Skip based on copyright |
next if (! ©right_check(\%Fields)); |
next if (! ©right_check(\%Fields)); |
|
# |
# Store the result in the mysql database |
# Store the result in the mysql database |
my $result = &Apache::lonmysql::store_row($table,\%Fields); |
my $result = &Apache::lonmysql::store_row($table,\%Fields); |
if (! defined($result)) { |
if (! defined($result)) { |
$r->print(&Apache::lonmysql::get_error()); |
$r->print(&Apache::lonmysql::get_error()); |
} |
} |
# $r->print(&Apache::lonmysql::get_debug()); |
# |
$hitcountsum ++; |
$hitcountsum ++; |
$time_remaining = $max_time - (time - $starttime) ; |
&update_seconds($r); |
$time_remaining = 0 if ($time_remaining < 0); |
|
if ($last_time - $time_remaining > 0) { |
|
&update_seconds($r,$time_remaining); |
|
$last_time = $time_remaining; |
|
} |
|
if ($hitcountsum % 50 == 0) { |
if ($hitcountsum % 50 == 0) { |
&update_count_status($r,$hitcountsum); |
&update_count_status($r,$hitcountsum); |
} |
} |
} # End of foreach (@results) |
} |
$fh->close(); |
$fh->close(); |
# $server is only deleted if the results file has been |
# $server is only deleted if the results file has been |
# found and (successfully) opened. This may be a bad idea. |
# found and (successfully) opened. This may be a bad idea. |
Line 2035 END
|
Line 2053 END
|
&update_count_status($r,$hitcountsum); |
&update_count_status($r,$hitcountsum); |
} |
} |
last if ($connection->aborted()); |
last if ($connection->aborted()); |
# Finished looping through the servers |
&update_seconds($r); |
$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_status($r,&mt('Search Complete').$server); |
&update_status($r,&mt('Search Complete [_1]',$server)); |
&update_seconds($r,0); |
&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 |
# 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("</body></html>"); |
$r->print("</body></html>"); |
if ($ENV{'form.catalogmode'} ne 'groupsearch') { |
if ($ENV{'form.catalogmode'} ne 'groupsearch') { |
$r->print("<script>". |
$r->print("<script>". |
Line 2077 Returns html for the previous and next b
|
Line 2090 Returns html for the previous and next b
|
sub prev_next_buttons { |
sub prev_next_buttons { |
my ($current_min,$show,$total,$parms) = @_; |
my ($current_min,$show,$total,$parms) = @_; |
return '' if ($show eq 'all'); # No links if you get them all at once. |
return '' if ($show eq 'all'); # No links if you get them all at once. |
my $links; |
# |
## |
# Create links |
## Prev |
|
my $prev_min = $current_min - $show; |
my $prev_min = $current_min - $show; |
$prev_min = 1 if $prev_min < 1; |
$prev_min = 1 if $prev_min < 1; |
if ($prev_min < $current_min) { |
my $prevlink = |
$links .= |
qq{<a href="/adm/searchcat?$parms&start=$prev_min&show=$show">}; |
qq{<a href="/adm/searchcat?$parms&start=$prev_min&show=$show">}. |
# |
&mt('prev').'</a>'; |
|
} else { |
|
$links .= &mt('prev'); |
|
} |
|
## |
|
## Pages.... Someday. |
|
## |
|
$links .= |
|
qq{ |
|
<a href="/adm/searchcat?$parms&start=$current_min&$show=$show">}. |
|
&mt('reload').'</a>'; |
|
## |
|
## Next |
|
my $next_min = $current_min + $show; |
my $next_min = $current_min + $show; |
$next_min = $current_min if ($next_min > $total); |
$next_min = $current_min if ($next_min > $total); |
if ($next_min != $current_min) { |
my $nextlink = |
$links .= |
qq{<a href="/adm/searchcat?$parms&start=$next_min&show=$show">}; |
qq{ |
my $reloadlink = |
<a href="/adm/searchcat?$parms&start=$next_min&show=$show">}. |
qq{<a href="/adm/searchcat?$parms&start=$current_min&$show=$show">}; |
&mt('next').'</a>'; |
# |
} else { |
# Determine which parameters to pass |
$links .= ' '.&mt('next'); |
my $String = '[_1]prev[_2] [_3]reload[_4] [_5]next[_6]'; |
} |
if ($prev_min == $current_min) { |
|
$String =~ s:\[_[12]\]::g; |
|
} |
|
if ($next_min == $current_min) { |
|
$String =~ s:\[_[56]\]::g; |
|
} |
|
my $links = &mt($String, |
|
$prevlink, '</a>', |
|
$reloadlink,'</a>', |
|
$nextlink, '</a>'); |
return $links; |
return $links; |
} |
} |
|
|
Line 2192 sub display_results {
|
Line 2200 sub display_results {
|
."</center>\n" |
."</center>\n" |
); |
); |
if ($total_results == 0) { |
if ($total_results == 0) { |
$r->print('<meta HTTP-EQUIV="Refresh" CONTENT="1">'. |
$r->print('<meta HTTP-EQUIV="Refresh" CONTENT="2">'. |
'<h3>'.&mt('There are currently no results').'.</h3>'. |
'<h3>'.&mt('There are currently no results').'.</h3>'. |
"</form></body></html>"); |
"</form></body></html>"); |
return; |
return; |
Line 2218 sub display_results {
|
Line 2226 sub display_results {
|
} |
} |
my $prefix=&catalogmode_output($Fields{'title'},$Fields{'url'}, |
my $prefix=&catalogmode_output($Fields{'title'},$Fields{'url'}, |
$Fields{'id'},$checkbox_num++); |
$Fields{'id'},$checkbox_num++); |
|
|
# Render the result into html |
# Render the result into html |
$output.= &$viewfunction($prefix,%Fields); |
$output.= &$viewfunction($prefix,%Fields); |
# Print them out as they come in. |
# Print them out as they come in. |