version 1.150, 2002/08/01 14:11:57
|
version 1.151, 2002/08/04 18:28:01
|
Line 298 END
|
Line 298 END
|
} |
} |
} |
} |
$ENV{'form.phase'} = 'disp_basic' if (! exists($ENV{'form.phase'})); |
$ENV{'form.phase'} = 'disp_basic' if (! exists($ENV{'form.phase'})); |
|
$ENV{'form.show'} = 20 if (! exists($ENV{'form.show'})); |
## |
## |
## Switch on the phase |
## Switch on the phase |
## |
## |
Line 307 END
|
Line 308 END
|
&print_advanced_search_form($r,$closebutton); |
&print_advanced_search_form($r,$closebutton); |
} elsif ($ENV{'form.phase'} eq 'results') { |
} elsif ($ENV{'form.phase'} eq 'results') { |
&display_results($r,$importbutton,$closebutton); |
&display_results($r,$importbutton,$closebutton); |
} elsif($ENV{'form.phase'} eq 'run_search') { |
} elsif ($ENV{'form.phase'} =~ /^(sort|run_search)$/) { |
my ($query,$customquery,$customshow,$libraries,$pretty_string) = |
my ($query,$customquery,$customshow,$libraries,$pretty_string) = |
&get_persistent_data($persistent_db_file, |
&get_persistent_data($persistent_db_file, |
['query','customquery','customshow', |
['query','customquery','customshow', |
'libraries','pretty_string']); |
'libraries','pretty_string']); |
&run_search($r,$query,$customquery,$customshow, |
if ($ENV{'form.phase'} eq 'sort') { |
$libraries,$pretty_string); |
&print_sort_form($r,$pretty_string); |
|
} elsif ($ENV{'form.phase'} eq 'run_search') { |
|
&run_search($r,$query,$customquery,$customshow, |
|
$libraries,$pretty_string); |
|
} |
} elsif(($ENV{'form.phase'} eq 'basic_search') || |
} elsif(($ENV{'form.phase'} eq 'basic_search') || |
($ENV{'form.phase'} eq 'adv_search')) { |
($ENV{'form.phase'} eq 'adv_search')) { |
|
$ENV{'form.searchmode'} = 'basic'; |
|
if ($ENV{'form.phase'} eq 'adv_search') { |
|
$ENV{'form.searchmode'} = 'advanced'; |
|
} |
# Set up table |
# Set up table |
if (! defined(&create_results_table())) { |
if (! defined(&create_results_table())) { |
$r->print(<<END); |
$r->print(<<END); |
Line 425 END
|
Line 434 END
|
$ENV{'form.viewselect'}, |
$ENV{'form.viewselect'}, |
undef,undef,undef, |
undef,undef,undef, |
sort(keys(%Views))); |
sort(keys(%Views))); |
|
$scrout.=&selectbox(undef,'show', |
|
$ENV{'form.show'}, |
|
undef,undef,undef, |
|
(10,20,50,100)); |
$scrout.=<<ENDDOCUMENT; |
$scrout.=<<ENDDOCUMENT; |
<input type="button" value="HELP" onClick="openhelp()" /> |
per page. |
</p> |
</p> |
</form> |
</form> |
</body> |
</body> |
Line 492 ENDHEADER
|
Line 505 ENDHEADER
|
$ENV{'form.viewselect'}, |
$ENV{'form.viewselect'}, |
undef,undef,undef, |
undef,undef,undef, |
sort(keys(%Views))); |
sort(keys(%Views))); |
|
$scrout.=' '; |
|
$scrout.=&selectbox(undef,'show', |
|
$ENV{'form.show'}, |
|
undef,undef,undef, |
|
(10,20,50,100)); |
|
$scrout.=' '. |
|
'<font color="#800000" face="helvetica">Per Page</font>'; |
$scrout.="</td><td>Related<br />Words</td></tr>\n"; |
$scrout.="</td><td>Related<br />Words</td></tr>\n"; |
$scrout.=&searchphrasefield_with_related('title', 'title' , |
$scrout.=&searchphrasefield_with_related('title', 'title' , |
$ENV{'form.title'}); |
$ENV{'form.title'}); |
Line 1123 sub parse_advanced_search {
|
Line 1143 sub parse_advanced_search {
|
$ENV{"form.$_"}=~s/[^\w\/\s\(\)\=\-\"\']//g; |
$ENV{"form.$_"}=~s/[^\w\/\s\(\)\=\-\"\']//g; |
} |
} |
# Preprocess the category form element. |
# Preprocess the category form element. |
|
$ENV{'form.category'} = 'any' if (ref($ENV{'form.category'})); |
if ($ENV{'form.category'} ne 'any') { |
if ($ENV{'form.category'} ne 'any') { |
my @extensions = &Apache::loncommon::filecategorytypes |
my @extensions = &Apache::loncommon::filecategorytypes |
($ENV{'form.category'}); |
($ENV{'form.category'}); |
Line 1137 sub parse_advanced_search {
|
Line 1158 sub parse_advanced_search {
|
} |
} |
} |
} |
unless ($fillflag) { |
unless ($fillflag) { |
&output_blank_field_error($r,$closebutton); |
&output_blank_field_error($r,$closebutton,'phase=disp_adv'); |
return ; |
return ; |
} |
} |
# Turn the form input into a SQL-based query |
# Turn the form input into a SQL-based query |
Line 1294 sub parse_basic_search {
|
Line 1315 sub parse_basic_search {
|
|
|
# Check to see if enough is filled in |
# Check to see if enough is filled in |
unless (&filled($ENV{'form.basicexp'})) { |
unless (&filled($ENV{'form.basicexp'})) { |
&output_blank_field_error($r,$closebutton); |
&output_blank_field_error($r,$closebutton,'phase=disp_basic'); |
return OK; |
return OK; |
} |
} |
my $pretty_search_string = '<b>'.$ENV{'form.basicexp'}.'</b>'; |
my $pretty_search_string = '<b>'.$ENV{'form.basicexp'}.'</b>'; |
Line 1530 sub build_date_queries {
|
Line 1551 sub build_date_queries {
|
|
|
###################################################################### |
###################################################################### |
###################################################################### |
###################################################################### |
|
|
sub copyright_check { |
sub copyright_check { |
my $Metadata = shift; |
my $Metadata = shift; |
# Check copyright tags and skip results the user cannot use |
# Check copyright tags and skip results the user cannot use |
Line 1550 sub copyright_check {
|
Line 1570 sub copyright_check {
|
return 1; |
return 1; |
} |
} |
|
|
|
|
|
###################################################################### |
|
###################################################################### |
|
|
|
=pod |
|
|
|
=item &ensure_db_and_table |
|
|
|
Ensure we can get lonmysql to connect to the database and the table we |
|
need exists. |
|
|
|
Inputs: $r, table id |
|
|
|
Returns: undef on error, 1 if the table exists. |
|
|
|
=cut |
|
|
|
###################################################################### |
|
###################################################################### |
|
sub ensure_db_and_table { |
|
my ($r,$table) = @_; |
|
## |
|
## Sanity check the table id. |
|
## |
|
if (! defined($table) || $table eq '' || $table =~ /\D/ ) { |
|
$r->print("Unable to retrieve search results. ". |
|
"Unable to determine the table results were stored in. ". |
|
"</body></html>"); |
|
return undef; |
|
} |
|
## |
|
## Make sure we can connect and the table exists. |
|
## |
|
my $connection_result = &Apache::lonmysql::connect_to_db(); |
|
if (!defined($connection_result)) { |
|
$r->print("Unable to connect to the MySQL database where your results". |
|
" are stored. </body></html>"); |
|
&Apache::lonnet::logthis("lonsearchcat: unable to get lonmysql to". |
|
" connect to database."); |
|
&Apache::lonnet::logthis(&Apache::lonmysql::get_error()); |
|
return undef; |
|
} |
|
my $table_check = &Apache::lonmysql::check_table($table); |
|
if (! defined($table_check)) { |
|
$r->print("A MySQL error has occurred.</form></body></html>"); |
|
&Apache::lonnet::logthis("lonmysql was unable to determine the status". |
|
" of table ".$table); |
|
return undef; |
|
} elsif (! $table_check) { |
|
$r->print("The table of results could not be found."); |
|
&Apache::lonnet::logthis("The user requested a table, ".$table. |
|
", that could not be found."); |
|
return undef; |
|
} |
|
return 1; |
|
} |
|
|
|
###################################################################### |
|
###################################################################### |
|
|
|
=pod |
|
|
|
=item &print_sort_form |
|
|
|
=cut |
|
|
|
###################################################################### |
|
###################################################################### |
|
sub print_sort_form { |
|
my ($r,$pretty_query_string) = @_; |
|
## |
|
my %SortableFields = |
|
(id => 'Default', |
|
title => 'Title', |
|
author => 'Author', |
|
subject => 'Subject', |
|
url => 'URL', |
|
version => 'Version Number', |
|
mime => 'Mime type', |
|
lang => 'Language', |
|
owner => 'Owner/Publisher', |
|
copyright => 'Copyright', |
|
hostname => 'Host', |
|
creationdate => 'Creation Date', |
|
lastrevisiondate => 'Revision Date', |
|
); |
|
## |
|
my $table = $ENV{'form.table'}; |
|
return if (! &ensure_db_and_table($r,$table)); |
|
## |
|
## Get the number of results |
|
## |
|
my $total_results = &Apache::lonmysql::number_of_rows($table); |
|
if (! defined($total_results)) { |
|
$r->print("A MySQL error has occurred.</form></body></html>"); |
|
&Apache::lonnet::logthis("lonmysql was unable to determine the number". |
|
" of rows in table ".$table); |
|
&Apache::lonnet::logthis(&Apache::lonmysql::get_error()); |
|
return; |
|
} |
|
my $result; |
|
$result.=<<END; |
|
<html> |
|
<head> |
|
<script> |
|
function change_sort() { |
|
var newloc = "/adm/searchcat?phase=results"; |
|
newloc += "&persistent_db_id=$ENV{'form.persistent_db_id'}"; |
|
newloc += "&sortby="; |
|
newloc += document.forms.statusform.elements.sortby.value; |
|
parent.resultsframe.location= newloc; |
|
} |
|
</script> |
|
<title>Results</title> |
|
</head> |
|
<body> |
|
<form name="statusform" action="" method="post"> |
|
END |
|
|
|
#<h2>Sort Results</h2> |
|
#Sort by: <select size="1" name="sortby" onchange="javascript:change_sort();"> |
|
# $ENV{'form.sortby'} = 'id' if (! defined($ENV{'form.sortby'})); |
|
# foreach (keys(%SortableFields)) { |
|
# $result.="<option name=\"$_\""; |
|
# if ($_ eq $ENV{'form.sortby'}) { |
|
# $result.=" selected "; |
|
# } |
|
# $result.=" >$SortableFields{$_}</option>\n"; |
|
# } |
|
# $result.="</select>\n"; |
|
my $revise = &revise_button(); |
|
$result.=<<END; |
|
<p> |
|
There are $total_results matches to your query. $revise |
|
</p><p> |
|
Search:$pretty_query_string |
|
</p> |
|
</form> |
|
</body> |
|
</html> |
|
END |
|
$r->print($result); |
|
return; |
|
} |
|
|
##################################################################### |
##################################################################### |
##################################################################### |
##################################################################### |
|
|
Line 1573 my @DataOrder = qw/id title author subje
|
Line 1738 my @DataOrder = qw/id title author subje
|
abstract mime lang owner copyright creationdate lastrevisiondate hostname/; |
abstract mime lang owner copyright creationdate lastrevisiondate hostname/; |
|
|
my %Datatypes = |
my %Datatypes = |
( id =>{ type => 'INT', |
( id =>{ type => 'MEDIUMINT', |
restrictions => 'NOT NULL', |
restrictions => 'UNSIGNED NOT NULL', |
primary_key => 'yes', |
primary_key => 'yes', |
auto_inc => 'yes' |
auto_inc => 'yes' |
}, |
}, |
Line 1599 my %Datatypes =
|
Line 1764 my %Datatypes =
|
); |
); |
|
|
my @Fullindicies = |
my @Fullindicies = |
qw/title author subject abstract mime language owner copyright/; |
qw/title/; |
|
# qw/title author subject abstract mime language owner copyright/; |
|
|
###################################################################### |
###################################################################### |
###################################################################### |
###################################################################### |
Line 1690 sub update_seconds {
|
Line 1856 sub update_seconds {
|
|
|
=pod |
=pod |
|
|
|
=item &revise_button |
|
|
|
Inputs: None |
|
|
|
Returns: html string for a 'revise search' button. |
|
|
|
=cut |
|
|
|
###################################################################### |
|
###################################################################### |
|
sub revise_button { |
|
my $revise_phase = 'disp_basic'; |
|
$revise_phase = 'disp_adv' if ($ENV{'form.searchmode'} eq 'advanced'); |
|
my $newloc = '/adm/searchcat'. |
|
'?persistent_db_id='.$ENV{'form.persistent_db_id'}. |
|
'&phase='.$revise_phase; |
|
my $result = qq{<input type="button" value="Revise search" name="revise"} . |
|
qq{ onClick="parent.location='$newloc';" /> }; |
|
return $result; |
|
} |
|
|
|
###################################################################### |
|
###################################################################### |
|
|
|
=pod |
|
|
=item &run_search |
=item &run_search |
|
|
=cut |
=cut |
Line 1703 sub run_search {
|
Line 1895 sub run_search {
|
# Timing variables |
# Timing variables |
# |
# |
my $starttime = time; |
my $starttime = time; |
my $max_time = 120; # seconds for the search to complete |
my $max_time = 30; # seconds for the search to complete |
# |
# |
# Print run_search header |
# Print run_search header |
# |
# |
$r->print("<html><head><title>Search Status</title></head><body>"); |
$r->print(<<END); |
$r->print("Search: ".$pretty_string."\n"); |
<html> |
|
<head><title>Search Status</title></head> |
|
<body> |
|
<form name="statusform" action="" method="post"> |
|
<input type="hidden" name="Queue" value="" /> |
|
END |
|
# Check to see if $pretty_string has more than one carriage return. |
|
# Assume \n s are following <br /> s and truncate the value. |
|
# (there is probably a better way)... |
|
my @Lines = split /\n/,$pretty_string; |
|
if (@Lines > 1) { |
|
$pretty_string = join /\n/,(@Lines[0..1],'....<br />'); |
|
} |
|
$r->print("Search: ".$pretty_string); |
$r->rflush(); |
$r->rflush(); |
# |
# |
# Determine the servers we need to contact. |
# Determine the servers we need to contact. |
Line 1746 sub run_search {
|
Line 1951 sub run_search {
|
my $hitcountsum; |
my $hitcountsum; |
my $server; |
my $server; |
my $status; |
my $status; |
|
my $revise = &revise_button(); |
$r->print(<<END); |
$r->print(<<END); |
<form name="statusform" action="" method="post"> |
|
<input type="hidden" name="Queue" value="" /> |
|
<table> |
<table> |
<tr><th>Status</th><th>Total Matches</th><th>Time Remaining</th></tr> |
<tr><th>Status</th><th>Total Matches</th><th>Time Remaining</th><th></th></tr> |
<tr> |
<tr> |
<td><input type="text" name="status" value="" size="30" /></td> |
<td><input type="text" name="status" value="" size="30" /></td> |
<td><input type="text" name="count" value="" size="10" /></td> |
<td><input type="text" name="count" value="" size="10" /></td> |
<td><input type="text" name="seconds" value="" size="8" /></td> |
<td><input type="text" name="seconds" value="" size="8" /></td> |
|
<td>$revise</td> |
</tr> |
</tr> |
</table> |
</table> |
</form> |
</form> |
Line 1851 END
|
Line 2056 END
|
} |
} |
} |
} |
&update_status($r,'Search Complete'.$server); |
&update_status($r,'Search Complete'.$server); |
|
&update_seconds($r,0); |
&Apache::lonmysql::disconnect_from_db(); |
&Apache::lonmysql::disconnect_from_db(); |
# Let the user know |
|
# |
|
# 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. |
$r->print("<b>Search Completed.</b> "); |
|
if ($hitcountsum) { |
|
$r->print($hitcountsum." matches were found."); |
|
} else { |
|
$r->print("There were no successful matches to your query."); |
|
} |
|
$r->print("</body></html>"); |
$r->print("</body></html>"); |
|
$r->print("<script>window.location='/adm/searchcat?phase=sort&persistent_db_id=$ENV{'form.persistent_db_id'}';</script>"); |
return; |
return; |
} |
} |
|
|
Line 1883 sub prev_next_buttons {
|
Line 2082 sub prev_next_buttons {
|
## |
## |
## Prev |
## Prev |
my $prev_min = $current_min - $show; |
my $prev_min = $current_min - $show; |
$prev_min = 0 if $prev_min < 0; |
$prev_min = 1 if $prev_min < 1; |
if ($prev_min < $current_min) { |
if ($prev_min < $current_min) { |
$links .= qq{ |
$links .= qq{ |
<a href="/adm/searchcat?$parms&start=$prev_min&show=$show">prev</a> |
<a href="/adm/searchcat?$parms&start=$prev_min&show=$show">prev</a> |
Line 1953 sub display_results {
|
Line 2152 sub display_results {
|
## 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(); |
return if (! &ensure_db_and_table($r,$table)); |
if (!defined($connection_result)) { |
|
$r->print(&Apache::lonmysql::get_error()); |
|
} |
|
my $table_check = &Apache::lonmysql::check_table($table); |
|
if (! defined($table_check)) { |
|
$r->print("A MySQL error has occurred.</form></body></html>"); |
|
&Apache::lonnet::logthis("lonmysql was unable to determine the status". |
|
" of table ".$table); |
|
return; |
|
} elsif (! $table_check) { |
|
$r->print("The table of results could not be found."); |
|
&Apache::lonnet::logthis("The user requested a table, ".$table. |
|
", that could not be found."); |
|
return; |
|
} |
|
## |
## |
## Get the number of results |
## Get the number of results |
## |
## |
Line 1978 sub display_results {
|
Line 2162 sub display_results {
|
&Apache::lonnet::logthis("lonmysql was unable to determine the number". |
&Apache::lonnet::logthis("lonmysql was unable to determine the number". |
" of rows in table ".$table); |
" of rows in table ".$table); |
&Apache::lonnet::logthis(&Apache::lonmysql::get_error()); |
&Apache::lonnet::logthis(&Apache::lonmysql::get_error()); |
&Apache::lonnet::logthis(&Apache::lonmysql::get_debug()); |
|
return; |
return; |
} |
} |
## |
## |
## Determine how many results we need to get |
## Determine how many results we need to get |
## |
## |
$ENV{'form.show'} = 20; |
$ENV{'form.start'} = 1 if (! exists($ENV{'form.start'})); |
$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.start'}; |
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'} - 1; |
$max = $total_results if ($max > $total_results); |
$max = $total_results if ($max > $total_results); |
} |
} |
## |
## |
Line 2018 sub display_results {
|
Line 2200 sub display_results {
|
## Get results from MySQL table |
## Get results from MySQL table |
## |
## |
my @Results = &Apache::lonmysql::get_rows($table, |
my @Results = &Apache::lonmysql::get_rows($table, |
'id>'.$min.' AND id<='.$max); |
'id>='.$min.' AND id<='.$max); |
## |
## |
## Loop through the results and output them. |
## Loop through the results and output them. |
## |
## |
Line 2386 sub results_link {
|
Line 2568 sub results_link {
|
my $basic_link = "/adm/searchcat?"."&table=".$ENV{'form.table'}. |
my $basic_link = "/adm/searchcat?"."&table=".$ENV{'form.table'}. |
"&persistent_db_id=".$ENV{'form.persistent_db_id'}; |
"&persistent_db_id=".$ENV{'form.persistent_db_id'}; |
my $results_link = $basic_link."&phase=results". |
my $results_link = $basic_link."&phase=results". |
"&pause=10"."&start=0"."&show=20"; |
"&pause=1"."&start=1"; |
return $results_link; |
return $results_link; |
} |
} |
|
|
Line 2625 sub filled {
|
Line 2807 sub filled {
|
|
|
=item &output_blank_field_error() |
=item &output_blank_field_error() |
|
|
|
Output a complete page that indicates the user has not filled in enough |
|
information to do a search. |
|
|
|
Inputs: $r (Apache request handle), $closebutton, $parms. |
|
|
|
Returns: nothing |
|
|
|
$parms is extra information to include in the 'Revise search request' link. |
|
|
=cut |
=cut |
|
|
###################################################################### |
###################################################################### |
###################################################################### |
###################################################################### |
sub output_blank_field_error { |
sub output_blank_field_error { |
my ($r,$closebutton)=@_; |
my ($r,$closebutton,$parms)=@_; |
# make query information persistent to allow for subsequent revision |
# make query information persistent to allow for subsequent revision |
$r->print(<<BEGINNING); |
$r->print(<<BEGINNING); |
<html> |
<html> |
Line 2644 BEGINNING
|
Line 2835 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 |
<a href="/adm/searchcat?persistent_db_id=$ENV{'form.persistent_db_id'}" |
<a href="/adm/searchcat?$parms&persistent_db_id=$ENV{'form.persistent_db_id'}" |
>Revise search request</a> |
>Revise search request</a> |
$closebutton |
$closebutton |
<hr /> |
<hr /> |
<h3>Helpful Message</h3> |
<h3>Unactionable search query.</h3> |
<p> |
<p> |
Incorrect search query due to blank entry fields. |
You did not fill in enough information for the search to be started. |
You need to fill in the relevant |
You need to fill in relevant fields on the search page in order |
fields on the search page in order for a query to be |
for a query to be processed. |
processed. |
|
</p> |
</p> |
</body> |
</body> |
</html> |
</html> |
Line 2696 $hidden_fields
|
Line 2886 $hidden_fields
|
onClick='this.form.submit();' /> |
onClick='this.form.submit();' /> |
$closebutton |
$closebutton |
<hr /> |
<hr /> |
<h3>Helpful Message</h3> |
<h3>Error</h3> |
<p> |
<p> |
$message |
$message |
</p> |
</p> |