version 1.145, 2002/07/28 20:02:14
|
version 1.146, 2002/07/29 21:53:57
|
Line 141 my %Views = ("Detailed Citation View" =>
|
Line 141 my %Views = ("Detailed Citation View" =>
|
"Summary View" => \&summary_view, |
"Summary View" => \&summary_view, |
"Fielded Format" => \&fielded_format_view, |
"Fielded Format" => \&fielded_format_view, |
"XML/SGML" => \&xml_sgml_view ); |
"XML/SGML" => \&xml_sgml_view ); |
my $persistent_db_file; |
|
my %persistent_db; |
my %persistent_db; |
my $hidden_fields; |
my $hidden_fields; |
###################################################################### |
###################################################################### |
Line 172 string that holds portions of the screen
|
Line 171 string that holds portions of the screen
|
sub handler { |
sub handler { |
my $r = shift; |
my $r = shift; |
# |
# |
untie %groupsearch_db if (tied(%groupsearch_db)); |
|
# |
|
my $closebutton; # button that closes the search window |
my $closebutton; # button that closes the search window |
# This button is different for the RAT compared to |
# This button is different for the RAT compared to |
# normal invocation. |
# normal invocation. |
Line 185 sub handler {
|
Line 182 sub handler {
|
## Pick up form fields passed in the links. |
## Pick up form fields passed in the links. |
## |
## |
&Apache::loncommon::get_unprocessed_cgi($ENV{'QUERY_STRING'}, |
&Apache::loncommon::get_unprocessed_cgi($ENV{'QUERY_STRING'}, |
['catalogmode','launch','acts','mode','form','element', |
['catalogmode','launch','acts','mode','form','element','pause', |
'reqinterface','persistent_db_id','table']); |
'phase','persistent_db_id','table','start','show']); |
|
## |
|
## 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 |
|
## printing the results. We only need (theoretically) to do |
|
## this once, so the pause indicator is deleted |
|
## |
|
if (exists($ENV{'form.pause'})) { |
|
sleep(5); |
|
delete($ENV{'form.pause'}); |
|
} |
## |
## |
## Initialize global variables |
## Initialize global variables |
## |
## |
Line 195 sub handler {
|
Line 202 sub handler {
|
"\_".&Apache::lonnet::escape($ENV{'user.name'})."_searchcat.db"; |
"\_".&Apache::lonnet::escape($ENV{'user.name'})."_searchcat.db"; |
# |
# |
# set the name of the persistent database |
# set the name of the persistent database |
# $ENV{'form.persistent_db_id'} can only have digits in it. |
# $ENV{'form.persistent_db_id'} can only have digits in it. |
if (! exists($ENV{'form.persistent_db_id'}) || |
if (! exists($ENV{'form.persistent_db_id'}) || |
$ENV{'form.persistent_db_id'} =~ /\D/ ) { |
$ENV{'form.persistent_db_id'} =~ /\D/ ) { |
$ENV{'form.persistent_db_id'} = time; |
$ENV{'form.persistent_db_id'} = time; |
} |
} |
$persistent_db_file = "/home/httpd/perl/tmp/". |
my $persistent_db_file = "/home/httpd/perl/tmp/". |
&Apache::lonnet::escape($domain). |
&Apache::lonnet::escape($domain). |
'_'.&Apache::lonnet::escape($ENV{'user.name'}). |
'_'.&Apache::lonnet::escape($ENV{'user.name'}). |
'_'.$ENV{'form.persistent_db_id'}.'_persistent_search.db'; |
'_'.$ENV{'form.persistent_db_id'}.'_persistent_search.db'; |
# |
## |
# Read in the database. It should (hopefully) not be catastrophic to |
&get_persistent_form_data($r,$persistent_db_file); |
# fail in this exercise. |
|
if (-e $persistent_db_file) { |
|
# Read in the previous values, if we can. |
|
if (tie(%persistent_db,'GDBM_File',$persistent_db_file, |
|
&GDBM_READER,0640)) { |
|
&reconstruct_persistent_form_data($r); |
|
untie (%persistent_db); |
|
} |
|
} |
|
## |
## |
## Clear out old values from groupsearch database |
## Clear out old values from groupsearch database |
## |
## |
|
untie %groupsearch_db if (tied(%groupsearch_db)); |
if ($ENV{'form.launch'} eq '1') { |
if ($ENV{'form.launch'} eq '1') { |
if (tie(%groupsearch_db,'GDBM_File',$diropendb,&GDBM_WRCREAT,0640)) { |
if (tie(%groupsearch_db,'GDBM_File',$diropendb,&GDBM_WRCREAT,0640)) { |
&start_fresh_session(); |
&start_fresh_session(); |
Line 233 sub handler {
|
Line 232 sub handler {
|
## |
## |
$hidden_fields = '<input type="hidden" name="persistent_db_id" value="'. |
$hidden_fields = '<input type="hidden" name="persistent_db_id" value="'. |
$ENV{'form.persistent_db_id'}.'" />'; |
$ENV{'form.persistent_db_id'}.'" />'; |
|
## |
if ($ENV{'form.catalogmode'} eq 'interactive') { |
if ($ENV{'form.catalogmode'} eq 'interactive') { |
$closebutton="<input type='button' name='close' value='CLOSE' ". |
$closebutton="<input type='button' name='close' value='CLOSE' ". |
"onClick='self.close()'>"."\n"; |
"onClick='self.close()'>"."\n"; |
Line 244 END
|
Line 244 END
|
<input type='button' name='import' value='IMPORT' |
<input type='button' name='import' value='IMPORT' |
onClick='javascript:select_group()'> |
onClick='javascript:select_group()'> |
END |
END |
|
} else { |
|
$closebutton = ''; |
|
$importbutton = ''; |
} |
} |
## |
## |
## Do a search, if needed. |
## Sanity checks on form elements |
## |
## |
my $searchtype; |
if (!defined($ENV{'form.viewselect'})) { |
$searchtype = 'Basic' if ($ENV{'form.basicsubmit'} eq 'SEARCH'); |
$ENV{'form.viewselect'} ="Detailed Citation View"; |
$searchtype = 'Advanced' if ($ENV{'form.advancedsubmit'} eq 'SEARCH'); |
} |
if ($searchtype) { |
$ENV{'form.phase'} = 'displaybasic' if (! exists($ENV{'form.phase'})); |
## |
## |
## make query information persistent to allow for subsequent revision |
## Switch on the phase |
## |
## |
tie(%persistent_db,'GDBM_File',$persistent_db_file,&GDBM_WRCREAT,0640); |
if ($ENV{'form.phase'} eq 'disp_basic') { |
&make_persistent(\%ENV); |
&print_basic_search_form($r,$closebutton); |
untie(%persistent_db); |
} elsif ($ENV{'form.phase'} eq 'disp_adv') { |
|
&print_advanced_search_form($r,$closebutton); |
|
} elsif ($ENV{'form.phase'} eq 'results') { |
|
&display_results($r,$importbutton,$closebutton); |
|
} elsif($ENV{'form.phase'} eq 'run_search') { |
|
my ($query,$customquery,$customshow,$libraries,$pretty_string) = |
|
&get_persistent_data($persistent_db_file, |
|
['query','customquery','customshow', |
|
'libraries','pretty_string']); |
|
&write_status($r,"query = $query"); |
|
&write_status($r,"customquery = $customquery"); |
|
&write_status($r,"customshow = $customshow"); |
|
&write_status($r,"libraries = $libraries"); |
|
&write_status($r,"pretty_string = $pretty_string"); |
|
&run_search($r,$query,$customquery,$customshow, |
|
$libraries,$pretty_string); |
|
} elsif(($ENV{'form.phase'} eq 'basic_search') || |
|
($ENV{'form.phase'} eq 'adv_search')) { |
|
# Set up table |
|
if (! defined(&create_results_table())) { |
|
# Unable to make table to store results in. |
|
# Definately abort search. |
|
} |
|
if (! &make_form_data_persistent($r,$persistent_db_file)) { |
|
# Unable to store persistent data. |
|
# Probably should bail out. |
|
} |
# |
# |
# We are running a search |
# We are running a search |
my ($query,$customquery,$customshow,$libraries) = |
my ($query,$customquery,$customshow,$libraries) = |
(undef,undef,undef,undef); |
(undef,undef,undef,undef); |
my $pretty_string; |
my $pretty_string; |
if ($searchtype eq 'Basic') { |
if ($ENV{'form.phase'} eq 'basic_search') { |
($query,$pretty_string) = &parse_basic_search($r,$closebutton); |
($query,$pretty_string) = &parse_basic_search($r,$closebutton); |
} elsif ($ENV{'form.advancedsubmit'} eq 'SEARCH') { |
} else { # Advanced search |
($query,$customquery,$customshow,$libraries,$pretty_string) |
($query,$customquery,$customshow,$libraries,$pretty_string) |
= &parse_advanced_search($r,$closebutton); |
= &parse_advanced_search($r,$closebutton); |
return OK if (! defined($query)); |
return OK if (! defined($query)); |
} |
} |
# Output some information to the user. |
&write_status($r,"query = $query"); |
$r->print(&search_results_header($searchtype,$pretty_string)); |
&write_status($r,"customquery = $customquery"); |
$r->print("Sending search request to LON-CAPA servers.<br />\n"); |
&write_status($r,"customshow = $customshow"); |
$r->rflush(); |
&write_status($r,"libraries = $libraries"); |
&run_search($r,$query,$customquery,$customshow,$libraries); |
&write_status($r,"pretty_string = $pretty_string"); |
|
&make_persistent($r, |
|
{ query => $query, |
|
customquery => $customquery, |
|
customshow => $customshow, |
|
libraries => $libraries, |
|
pretty_string => $pretty_string }, |
|
$persistent_db_file); |
## |
## |
## Display the results |
## Print out the frames interface |
## |
## |
&display_results($r,$searchtype,$importbutton,$closebutton); |
&print_frames_interface($r); |
$r->rflush(); |
|
} else { |
|
# |
|
# Set the default view if it is not already set. |
|
if (!defined($ENV{'form.viewselect'})) { |
|
$ENV{'form.viewselect'} ="Detailed Citation View"; |
|
} |
|
# |
|
# remove the requested interface from the environment. |
|
my $interface; |
|
if ($ENV{'form.reqinterface'}) { |
|
$interface = lc($ENV{'form.reqinterface'}); |
|
} else { |
|
$interface = 'basic'; |
|
} |
|
## |
|
## Determine course of action |
|
## |
|
if ($interface eq 'display') { |
|
# &display_results($closebutton)); |
|
} elsif ($interface eq 'advanced') { |
|
$r->print(&advanced_search_form($closebutton)); |
|
} elsif ($interface eq 'basic') { |
|
# Output normal search interface |
|
$r->print(&basic_search_form($closebutton)); |
|
} |
|
} |
} |
untie (%persistent_db); |
|
return OK; |
return OK; |
} |
} |
|
|
Line 315 END
|
Line 324 END
|
|
|
=pod |
=pod |
|
|
=item &basic_search_form() |
=item &print_basic_search_form() |
|
|
Returns a scalar which holds html for the basic search form. |
Returns a scalar which holds html for the basic search form. |
|
|
Line 324 Returns a scalar which holds html for th
|
Line 333 Returns a scalar which holds html for th
|
###################################################################### |
###################################################################### |
###################################################################### |
###################################################################### |
|
|
sub basic_search_form{ |
sub print_basic_search_form{ |
my ($closebutton) = @_; |
my ($r,$closebutton) = @_; |
my $scrout=<<"ENDDOCUMENT"; |
my $scrout=<<"ENDDOCUMENT"; |
<html> |
<html> |
<head> |
<head> |
Line 342 sub basic_search_form{
|
Line 351 sub basic_search_form{
|
<img align='right' src='/adm/lonIcons/lonlogos.gif' /> |
<img align='right' src='/adm/lonIcons/lonlogos.gif' /> |
<h1>Search Catalog</h1> |
<h1>Search Catalog</h1> |
<form method="post" action="/adm/searchcat"> |
<form method="post" action="/adm/searchcat"> |
|
<input type="hidden" name="phase" value="basic_search" /> |
$hidden_fields |
$hidden_fields |
<h3>Basic Search</h3> |
<h3>Basic Search</h3> |
<p> |
<p> |
Line 358 ENDDOCUMENT
|
Line 368 ENDDOCUMENT
|
# $scrout.='<font color="#800000">Search historic archives</font>'; |
# $scrout.='<font color="#800000">Search historic archives</font>'; |
my $checkbox = &simplecheckbox('related',$ENV{'form.related'}); |
my $checkbox = &simplecheckbox('related',$ENV{'form.related'}); |
$scrout.=<<END; |
$scrout.=<<END; |
</td><td><a href="/adm/searchcat?reqinterface=advanced">Advanced Search</a></td></tr> |
</td><td><a href="/adm/searchcat?phase=disp_adv">Advanced Search</a></td></tr> |
<tr><td>$checkbox use related words</td><td></td></tr> |
<tr><td>$checkbox use related words</td><td></td></tr> |
</table> |
</table> |
</p> |
</p> |
Line 377 END
|
Line 387 END
|
</body> |
</body> |
</html> |
</html> |
ENDDOCUMENT |
ENDDOCUMENT |
return $scrout; |
$r->print($scrout); |
|
return; |
} |
} |
###################################################################### |
###################################################################### |
###################################################################### |
###################################################################### |
Line 393 Returns a scalar which holds html for th
|
Line 404 Returns a scalar which holds html for th
|
###################################################################### |
###################################################################### |
###################################################################### |
###################################################################### |
|
|
sub advanced_search_form{ |
sub print_advanced_search_form{ |
my ($closebutton) = @_; |
my ($r,$closebutton) = @_; |
my $advanced_buttons = <<"END"; |
my $advanced_buttons = <<"END"; |
<p> |
<p> |
<input type="submit" name="advancedsubmit" value='SEARCH' /> |
<input type="submit" name="advancedsubmit" value='SEARCH' /> |
Line 427 such as AND, OR, or NOT.<br />
|
Line 438 such as AND, OR, or NOT.<br />
|
<form method="post" action="/adm/searchcat"> |
<form method="post" action="/adm/searchcat"> |
$advanced_buttons |
$advanced_buttons |
$hidden_fields |
$hidden_fields |
|
<input type="hidden" name="phase" value="adv_search" /> |
<table> |
<table> |
<tr><td><font color="#800000" face="helvetica"><b>VIEW:</b></font></td> |
<tr><td><font color="#800000" face="helvetica"><b>VIEW:</b></font></td> |
<td> |
<td> |
Line 568 $advanced_buttons
|
Line 580 $advanced_buttons
|
</body> |
</body> |
</html> |
</html> |
ENDDOCUMENT |
ENDDOCUMENT |
return $scrout; |
$r->print($scrout); |
|
return; |
} |
} |
|
|
###################################################################### |
###################################################################### |
Line 576 ENDDOCUMENT
|
Line 589 ENDDOCUMENT
|
|
|
=pod |
=pod |
|
|
=item &reconstruct_persistent_form_data |
=item &get_persistent_form_data |
|
|
This function is the reverse of &make_persistent(); |
Inputs: filename of database |
|
|
|
Outputs: returns undef on database errors. |
|
|
|
This function is the reverse of &make_persistent() for form data. |
Retrieve persistent data from %persistent_db. Retrieved items will have their |
Retrieve persistent data from %persistent_db. Retrieved items will have their |
values unescaped. If the item contains commas (before unescaping), the |
values unescaped. If a form value already exists in $ENV, it will not be |
returned value will be an array pointer. Items will be returned in the |
overwritten. Form values that are array references may have values appended |
environment in $ENV{"form.$name"}. |
to them. |
|
|
=cut |
=cut |
|
|
###################################################################### |
###################################################################### |
###################################################################### |
###################################################################### |
sub reconstruct_persistent_form_data { |
sub get_persistent_form_data { |
foreach my $name (keys %persistent_db) { |
my $r = shift; |
# &Apache::lonnet::logthis("Reconstructing $name = $persistent_db{$name}"); |
my $filename = shift; |
my @Values = split(',',$persistent_db{$name}); |
return undef if (! -e $filename); |
my @value = map { &Apache::lonnet::unescape($_) } @Values; |
return undef if (! tie(%persistent_db,'GDBM_File',$filename, |
$name = 'form.'.$name; |
&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); |
|
# |
|
# Loop through the keys, looking for 'form.' |
|
foreach my $name (keys(%persistent_db)) { |
|
next if ($name !~ /^form./); |
|
my @values = map { |
|
&Apache::lonnet::unescape($_); |
|
} split(',',$persistent_db{$name}); |
|
next if (@values <1); |
if (exists($ENV{$name})) { |
if (exists($ENV{$name})) { |
if (ref($ENV{$name})) { |
if (ref($ENV{$name}) eq 'ARRAY') { |
# Assume it is an array reference |
# If it is an array, tack @values on the end of it. |
$ENV{$name} = [@{$ENV{$name}},@value]; |
$ENV{$name} = [@$ENV{$name},@values]; |
} else { |
} elsif (! ref($ENV{$name}) && $arrays_allowed{$name}) { |
$ENV{$name} = [$ENV{$name},@value]; |
# if arrays are allowed, turn it into one and add @values |
} |
$ENV{$name} = [$ENV{$name},@values]; |
|
} # otherwise, assume the value in $ENV{$name} is better than ours. |
} else { |
} else { |
if (@value > 1) { |
if ($arrays_allowed{$name}) { |
$ENV{$name} = [@value]; |
$ENV{$name} = [@values]; |
} else { |
} else { |
$ENV{$name} = $value[0]; |
$ENV{$name} = $values[0] if ($values[0]); |
} |
} |
} |
} |
|
&write_status($r,"Reconstructed $name = $ENV{$name}"); |
} |
} |
return; |
untie (%persistent_db); |
|
return 1; |
|
} |
|
###################################################################### |
|
###################################################################### |
|
|
|
=pod |
|
|
|
=item &get_persistent_data |
|
|
|
Inputs: filename of database, ref to array of values to recover. |
|
|
|
Outputs: array of values. Returns undef on error. |
|
|
|
This function is the reverse of &make_persistent(); |
|
Retrieve persistent data from %persistent_db. Retrieved items will have their |
|
values unescaped. If the item contains commas (before unescaping), the |
|
returned value will be an array pointer. |
|
|
|
=cut |
|
|
|
###################################################################### |
|
###################################################################### |
|
sub get_persistent_data { |
|
my $filename = shift; |
|
my @Vars = @{shift()}; |
|
my @Values; # Return array |
|
return undef if (! -e $filename); |
|
return undef if (! tie(%persistent_db,'GDBM_File',$filename, |
|
&GDBM_READER,0640)); |
|
foreach my $name (@Vars) { |
|
if (! exists($persistent_db{$name})) { |
|
push @Values, undef; |
|
next; |
|
} |
|
my @values = map { |
|
&Apache::lonnet::unescape($_); |
|
} split(',',$persistent_db{$name}); |
|
if (@values == 1) { |
|
push @Values,$values[0]; |
|
} else { |
|
push @Values,\@values; |
|
} |
|
} |
|
untie (%persistent_db); |
|
return @Values; |
} |
} |
|
|
###################################################################### |
###################################################################### |
Line 619 sub reconstruct_persistent_form_data {
|
Line 694 sub reconstruct_persistent_form_data {
|
|
|
=item &make_persistent() |
=item &make_persistent() |
|
|
Store (environment) variables away to the %persistent_db. |
Inputs: Hash of values to save, filename of persistent database. |
|
|
|
Store variables away to the %persistent_db. |
Values will be escaped. Values that are array pointers will have their |
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 seperated string. |
|
|
Line 628 elements escaped and concatenated in a c
|
Line 705 elements escaped and concatenated in a c
|
###################################################################### |
###################################################################### |
###################################################################### |
###################################################################### |
sub make_persistent { |
sub make_persistent { |
|
my $r = shift; |
my %save = %{shift()}; |
my %save = %{shift()}; |
foreach my $name (keys %save) { |
my $filename = shift; |
next if ($name !~ /^form\./ || $name =~ /submit/); |
return undef if (! tie(%persistent_db,'GDBM_File', |
|
$filename,&GDBM_WRCREAT,0640)); |
|
foreach my $name (keys(%save)) { |
|
next if (! exists($save{$name})); |
|
next if (! defined($save{$name}) || $save{$name} eq ''); |
my @values = (ref($save{$name}) ? @{$save{$name}} : ($save{$name})); |
my @values = (ref($save{$name}) ? @{$save{$name}} : ($save{$name})); |
# We handle array references, but not recursively. |
# We handle array references, but not recursively. |
my $store = join(',', map { &Apache::lonnet::escape($_); } @values ); |
my $store = join(',', map { &Apache::lonnet::escape($_); } @values ); |
$name=~s/^form\.//; |
|
$persistent_db{$name} = $store; |
$persistent_db{$name} = $store; |
|
&write_status($r,"Stored $name = $store"); |
} |
} |
return ''; |
untie(%persistent_db); |
|
return 1; |
|
} |
|
|
|
###################################################################### |
|
###################################################################### |
|
|
|
=pod |
|
|
|
=item &make_form_data_persistent() |
|
|
|
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. |
|
|
|
=cut |
|
|
|
###################################################################### |
|
###################################################################### |
|
sub make_form_data_persistent { |
|
my $r = shift; |
|
my $filename = shift; |
|
my %save; |
|
foreach (keys(%ENV)) { |
|
next if (! /^form/ || /submit/); |
|
$save{$_} = $ENV{$_}; |
|
} |
|
return &make_persistent($r,\%save,$filename); |
} |
} |
|
|
###################################################################### |
###################################################################### |
Line 1459 my %Datatypes =
|
Line 1570 my %Datatypes =
|
|
|
=pod |
=pod |
|
|
|
=item &create_results_table() |
|
|
|
Creates the table of search results by calling lonmysql. Stores the |
|
table id in $ENV{'form.table'} |
|
|
|
Inputs: none. |
|
|
|
Returns: the identifier of the table on success, undef on error. |
|
|
|
=cut |
|
|
|
###################################################################### |
|
###################################################################### |
|
sub create_results_table { |
|
my $table = &Apache::lonmysql::create_table |
|
( { columns => \%Datatypes, |
|
column_order => \@DataOrder, |
|
} ); |
|
if (defined($table)) { |
|
$ENV{'form.table'} = $table; |
|
return $table; |
|
} |
|
return undef; # Error... |
|
} |
|
###################################################################### |
|
###################################################################### |
|
|
|
=pod |
|
|
=item &write_status() |
=item &write_status() |
|
|
=cut |
=cut |
Line 1467 my %Datatypes =
|
Line 1607 my %Datatypes =
|
###################################################################### |
###################################################################### |
sub write_status { |
sub write_status { |
my ($r,$string) = @_; |
my ($r,$string) = @_; |
$r->print("<pre>".$string."</pre>\n"); |
$string =~ s/(\')/\$1/g; |
$r->rflush(); |
$string =~ s/\n//sg; |
|
# $r->print("<script>alert('$string');</script>\n"); |
|
# $r->rflush(); |
return; |
return; |
} |
} |
|
|
Line 1484 sub write_status {
|
Line 1626 sub write_status {
|
###################################################################### |
###################################################################### |
###################################################################### |
###################################################################### |
sub run_search { |
sub run_search { |
my ($r,$query,$customquery,$customshow,$serverlist) = @_; |
my ($r,$query,$customquery,$customshow,$serverlist,$pretty_string) = @_; |
# |
# |
# Timing variables |
# Timing variables |
# |
# |
my $starttime = time; |
my $starttime = time; |
my $max_time = 120; # seconds for the search to complete |
my $max_time = 120; # seconds for the search to complete |
# |
# |
|
# Print run_search header |
|
# |
|
$r->print("<html><head><title>Search Status</title></head><body>"); |
|
$r->print("Search: ".$pretty_string."<br />\n"); |
|
$r->rflush(); |
|
# |
# Determine the servers we need to contact. |
# Determine the servers we need to contact. |
# |
# |
my @Servers_to_contact; |
my @Servers_to_contact; |
Line 1500 sub run_search {
|
Line 1648 sub run_search {
|
@Servers_to_contact = sort(keys(%Apache::lonnet::libserv)); |
@Servers_to_contact = sort(keys(%Apache::lonnet::libserv)); |
} |
} |
my %Server_status; |
my %Server_status; |
# |
my $table =$ENV{'form.table'}; |
# Create Table |
|
# |
|
my $table = &Apache::lonmysql::create_table |
|
( { columns => \%Datatypes, |
|
column_order => \@DataOrder, |
|
} ); |
|
if (! defined($table)) { |
if (! defined($table)) { |
# What do I do now? Print out an error page. |
# What do I do now? Print out an error page. |
&Apache::lonnet::logthis("lonmysql attempted to create a table ". |
&Apache::lonnet::logthis("lonmysql attempted to create a table ". |
Line 1518 sub run_search {
|
Line 1660 sub run_search {
|
return; |
return; |
} |
} |
## |
## |
## form.table needs to be stored in the persistent database... |
## Prepare for the big loop. |
## |
## |
$ENV{'form.table'}=$table; |
|
# |
|
# Prepare for the big loop. |
|
# |
|
my $hitcountsum; |
my $hitcountsum; |
my $server; |
my $server; |
my $status; |
my $status; |
Line 1537 sub run_search {
|
Line 1675 sub run_search {
|
$customshow,[$server]); |
$customshow,[$server]); |
($server) = keys(%$reply); |
($server) = keys(%$reply); |
$Server_status{$server} = $reply->{$server}; |
$Server_status{$server} = $reply->{$server}; |
# &write_status($r,"Contacted:$server:reply:". |
# $r->print("Contacted:$server:reply:$Server_status{$server}"); |
# $Server_status{$server}); |
|
if ($max_time - (time - $starttime) < 20) { |
if ($max_time - (time - $starttime) < 20) { |
# If there are less than 20 seconds to go in the search, |
# If there are less than 20 seconds to go in the search, |
# give the newly contacted servers 20 more seconds to |
# give the newly contacted servers 20 more seconds to |
Line 1551 sub run_search {
|
Line 1688 sub run_search {
|
while (my ($server,$status) = each(%Server_status)) { |
while (my ($server,$status) = each(%Server_status)) { |
if ($status eq 'con_lost') { |
if ($status eq 'con_lost') { |
delete ($Server_status{$server}); |
delete ($Server_status{$server}); |
# &write_status($r,"server $server is not responding."); |
# $r->print("server $server is not responding."); |
next; |
next; |
} |
} |
$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") { |
# Let the user know we are receiving data from the server |
# Let the user know we are receiving data from the server |
# &write_status($r,"$server:Receiving file"); |
# $r->print("$server:Receiving file"); |
next; |
next; |
} |
} |
if (-e "$datafile.end") { |
if (-e "$datafile.end") { |
Line 1571 sub run_search {
|
Line 1708 sub run_search {
|
# Error opening file... |
# Error opening file... |
# Tell the user and exit...? |
# Tell the user and exit...? |
# Should I give up on opening it? |
# Should I give up on opening it? |
&write_status("Unable to open search results file for ". |
$r->print("Unable to open search results file for ". |
"server $server. Omitting from search"); |
"server $server. Omitting from search"); |
next; |
next; |
} |
} |
Line 1587 sub run_search {
|
Line 1724 sub run_search {
|
# 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)) { |
&write_status($r,&Apache::lonmysql::get_error()); |
$r->print(&Apache::lonmysql::get_error()); |
} |
} |
# &write_status($r,&Apache::lonmysql::get_debug()); |
# $r->print(&Apache::lonmysql::get_debug()); |
$hitcountsum ++; |
$hitcountsum ++; |
} # End of foreach (@results) |
} # 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. |
delete($Server_status{$server}); |
delete($Server_status{$server}); |
#&write_status($r,"Received $new_count more results from ". |
# $r->print("Received $new_count more results from ". |
# $server."."); |
# $server."."); |
} |
} |
} |
} |
Line 1607 sub run_search {
|
Line 1744 sub run_search {
|
# |
# |
# 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. |
&write_status($r,"Search completed."); |
$r->print("<h1>Search completed.</h1>"); |
if ($hitcountsum) { |
if ($hitcountsum) { |
&write_status($r,$hitcountsum." successful matches to your query."); |
$r->print($hitcountsum." successful matches to your query.<br />"); |
} else { |
} else { |
&write_status($r,"There were no successful matches to your query."); |
$r->print("There were no successful matches to your query.<br />"); |
} |
} |
|
$r->print("</body></html>"); |
return; |
return; |
} |
} |
|
|
Line 1620 sub run_search {
|
Line 1758 sub run_search {
|
###################################################################### |
###################################################################### |
=pod |
=pod |
|
|
=item &display_buttons |
=item &prev_next_buttons |
|
|
=cut |
=cut |
|
|
###################################################################### |
###################################################################### |
###################################################################### |
###################################################################### |
sub display_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; |
my $links; |
Line 1636 sub display_buttons {
|
Line 1774 sub display_buttons {
|
$prev_min = 0 if $prev_min < 0; |
$prev_min = 0 if $prev_min < 0; |
if ($prev_min < $current_min) { |
if ($prev_min < $current_min) { |
$links .= qq{ |
$links .= qq{ |
<a href="/adm/searchcat?$parms&startwith=$prev_min&show=$show">prev</a> |
<a href="/adm/searchcat?$parms&start=$prev_min&show=$show">prev</a> |
}; |
}; |
|
} else { |
|
$links .= 'prev'; |
} |
} |
## |
## |
## Pages.... Someday. |
## Pages.... Someday. |
## |
## |
|
$links .= qq{ |
|
<a href="/adm/searchcat?$parms&start=$current_min&$show=$show">reload</a> |
|
}; |
## |
## |
## Next |
## Next |
my $next_min = $current_min + $show; |
my $next_min = $current_min + $show; |
my $next_min = $current_min if ($next_min > $total); |
$next_min = $current_min if ($next_min > $total); |
if ($next_min != $current_min) { |
if ($next_min != $current_min) { |
$links .= qq{ |
$links .= qq{ |
<a href="/adm/searchcat?$parms&startwith=$next_min&show=$show">next</a> |
<a href="/adm/searchcat?$parms&start=$next_min&show=$show">next</a> |
}; |
}; |
|
} else { |
|
$links .= ' next'; |
} |
} |
return $links; |
return $links; |
} |
} |
Line 1667 sub display_buttons {
|
Line 1811 sub display_buttons {
|
###################################################################### |
###################################################################### |
sub display_results { |
sub display_results { |
my ($r,$mode,$importbutton,$closebutton) = @_; |
my ($r,$mode,$importbutton,$closebutton) = @_; |
|
$r->print(&search_results_header()); |
## |
## |
## Set viewing function |
## Set viewing function |
## |
## |
Line 1679 sub display_results {
|
Line 1824 sub display_results {
|
## |
## |
## Get the catalog controls setup |
## Get the catalog controls setup |
## |
## |
my $action = "/adm/searchcat"; |
my $action = "/adm/searchcat?phase=results"; |
if ($mode eq 'Basic') { |
## |
$action .= "?reqinterface=basic"; |
## |
} elsif ($mode eq 'Advanced') { |
## |
$action .= "?reqinterface=advanced"; |
if ($ENV{'form.catalogmode'} eq 'groupsearch') { |
|
if (! tie(%groupsearch_db,'GDBM_File',$diropendb, |
|
&GDBM_WRCREAT,0640)) { |
|
$r->print('Unable to tie hash to db file</body></html>'); |
|
$r->rflush(); |
|
return; |
|
} |
} |
} |
$r->print(<<CATALOGCONTROLS); |
|
<form name='results' method="post" action="$action"> |
|
$hidden_fields |
|
<input type='hidden' name='acts' value='' /> |
|
<input type='button' value='Revise search request' |
|
onClick='this.form.submit();' /> |
|
$importbutton |
|
$closebutton |
|
<hr /> |
|
CATALOGCONTROLS |
|
if (! tie(%groupsearch_db,'GDBM_File',$diropendb,&GDBM_WRCREAT,0640)) { |
|
$r->print('Unable to tie hash to db file</body></html>'); |
|
$r->rflush(); |
|
return; |
|
} |
|
## |
## |
## Prepare the table for querying |
## Prepare the table for querying |
## |
## |
my $table = $ENV{'form.table'}; |
my $table = $ENV{'form.table'}; |
my $connection_result = &Apache::lonmysql::connect_to_db(); |
my $connection_result = &Apache::lonmysql::connect_to_db(); |
if (!defined($connection_result)) { |
if (!defined($connection_result)) { |
&write_status($r,&Apache::lonmysql::get_error()); |
$r->print(&Apache::lonmysql::get_error()); |
} |
} |
my $table_check = &Apache::lonmysql::check_table($table); |
my $table_check = &Apache::lonmysql::check_table($table); |
if (! defined($table_check)) { |
if (! defined($table_check)) { |
Line 1740 CATALOGCONTROLS
|
Line 1876 CATALOGCONTROLS
|
## |
## |
## Determine how many results we need to get |
## Determine how many results we need to get |
## |
## |
$ENV{'form.startwith'} = 0 if (! exists($ENV{'form.startwith'})); |
$ENV{'form.show'} = 20; |
|
$ENV{'form.start'} = 0 if (! exists($ENV{'form.start'})); |
$ENV{'form.show'} = 'all' if (! exists($ENV{'form.show'})); |
$ENV{'form.show'} = 'all' if (! exists($ENV{'form.show'})); |
my $min = $ENV{'form.startwith'}; |
my $min = $ENV{'form.start'}; |
my $max; |
my $max; |
if ($ENV{'form.show'} eq 'all') { |
if ($ENV{'form.show'} eq 'all') { |
$max = $total_results ; |
$max = $total_results ; |
} else { |
} else { |
$max = $min + $ENV{'form.show'}; |
$max = $min + $ENV{'form.show'}; |
|
$max = $total_results if ($max > $total_results); |
} |
} |
## |
## |
## Output links (if necessary) for 'prev' and 'next' pages. |
## Output links (if necessary) for 'prev' and 'next' pages. |
## |
## |
|
$r->print("<center>Results $min to $max out of $total_results</center>\n"); |
|
$r->print |
|
('<br /><center>'. |
|
&prev_next_buttons($min,$ENV{'form.show'},$total_results, |
|
"table=".$ENV{'form.table'}. |
|
"&phase=results". |
|
"&persistent_db_id=".$ENV{'form.persistent_db_id'}) |
|
."</center><br />\n" |
|
); |
## |
## |
## Get results from MySQL table |
## Get results from MySQL table |
## |
## |
Line 2024 Checked for existance & 'edit' mode.
|
Line 2170 Checked for existance & 'edit' mode.
|
###################################################################### |
###################################################################### |
###################################################################### |
###################################################################### |
sub search_results_header { |
sub search_results_header { |
my ($mode,$pretty_query) = @_; |
|
$mode = lc($mode); |
|
my $title; |
|
if ($mode eq 'advanced') { |
|
$title = "Advanced Search Results"; |
|
} elsif ($mode eq 'basic') { |
|
$title = "Basic Search Results"; |
|
} |
|
my $result = ''; |
my $result = ''; |
# output beginning of search page |
# output beginning of search page |
$result.=<<BEGINNING; |
|
<html> |
|
<head> |
|
<title>$title</title> |
|
BEGINNING |
|
# conditional output of script functions dependent on the mode in |
# conditional output of script functions dependent on the mode in |
# which the search was invoked |
# which the search was invoked |
if ($ENV{'form.catalogmode'} eq 'interactive'){ |
if ($ENV{'form.catalogmode'} eq 'interactive'){ |
Line 2105 SCRIPT
|
Line 2238 SCRIPT
|
} |
} |
</script> |
</script> |
SCRIPT |
SCRIPT |
$result.=<<SCRIPT; |
|
<script type="text/javascript"> |
|
function displayinfo(val) { |
|
popwin.document.forms.popremain.sdetails.value=val; |
|
} |
|
function openhelp(val) { |
|
openhelpwin=open('/adm/help/searchcat.html','helpscreen', |
|
'scrollbars=1,width=400,height=300'); |
|
openhelpwin.focus(); |
|
} |
|
function abortsearch(val) { |
|
popwin.close(); |
|
} |
|
</script> |
|
SCRIPT |
|
$result.=<<END; |
$result.=<<END; |
</head> |
</head> |
<body bgcolor="#ffffff"> |
|
<img align=right src=/adm/lonIcons/lonlogos.gif> |
|
<h1>$title</h1> |
|
END |
END |
if ($pretty_query) { |
|
$result .= "<p>Search query: $pretty_query</p>"; |
|
} |
|
return $result; |
return $result; |
} |
} |
|
|
###################################################################### |
###################################################################### |
###################################################################### |
###################################################################### |
|
sub search_status_header { |
|
return <<ENDSTATUS; |
|
<html><head><title>Search Status</title></head> |
|
<body> |
|
<h3>Search Status</h3> |
|
Sending search request to LON-CAPA servers.<br /> |
|
ENDSTATUS |
|
} |
|
|
|
###################################################################### |
|
###################################################################### |
|
sub print_frames_interface { |
|
my $r = shift; |
|
my $basic_link = "/adm/searchcat?"."&table=".$ENV{'form.table'}. |
|
"&persistent_db_id=".$ENV{'form.persistent_db_id'}; |
|
my $run_search_link = $basic_link."&phase=run_search"; |
|
my $results_link = $basic_link."&phase=results". |
|
"&pause=10"."&start=0"."&show=20"; |
|
my $result = <<"ENDFRAMES"; |
|
<html> |
|
<head> |
|
<title>LON-CAPA Digital Library Search Results</title> |
|
</head> |
|
<frameset rows="150,*"> |
|
<frame name="statusframe" src="$run_search_link"> |
|
<frame name="resultsframe" src="$results_link"> |
|
</frameset> |
|
</html> |
|
ENDFRAMES |
|
|
|
$r->print($result); |
|
return; |
|
} |
|
|
|
###################################################################### |
|
###################################################################### |
|
|
=pod |
=pod |
|
|
Line 2184 END
|
Line 2332 END
|
=item &summary_view() |
=item &summary_view() |
|
|
=cut |
=cut |
|
|
###################################################################### |
###################################################################### |
###################################################################### |
###################################################################### |
sub summary_view { |
sub summary_view { |
Line 2332 BEGINNING
|
Line 2479 BEGINNING
|
<h1>Search Catalog</h1> |
<h1>Search Catalog</h1> |
<form method="post" action="/adm/searchcat"> |
<form method="post" action="/adm/searchcat"> |
$hidden_fields |
$hidden_fields |
<input type='button' value='Revise search request' |
<a href="/adm/searchcat?persistent_db_id=$ENV{'form.persistent_db_id'}" |
onClick='this.form.submit();' /> |
>Revise search request</a> |
$closebutton |
$closebutton |
<hr /> |
<hr /> |
<h3>Helpful Message</h3> |
<h3>Helpful Message</h3> |