version 1.90, 2001/04/02 13:13:17
|
version 1.97, 2001/08/16 02:20:01
|
Line 1
|
Line 1
|
# The LearningOnline Network |
# The LearningOnline Network |
# Search Catalog |
# Search Catalog |
# |
# |
|
# YEAR=2001 |
# 03/08/2001 Scott Harrison |
# 03/08/2001 Scott Harrison |
# Scott Harrison: 03/12/2001, 03/13/2001, 03/14/2001, 03/15/2001, 03/19/2001 |
# Scott Harrison: 03/12/2001, 03/13/2001, 03/14/2001, 03/15/2001, 03/19/2001 |
# Scott Harrison: 03/20/2001 |
# Scott Harrison: 03/20/2001, 03/21/2001, 03/22/2001, 03/26/2001, 03/27/2001 |
|
# Scott Harrison: 04/02/2001, 08/15/2001 |
# |
# |
# Functions |
# Functions |
# |
# |
Line 181 END
|
Line 183 END
|
$scrout.=&searchphrasefield('Limit by URL','url', |
$scrout.=&searchphrasefield('Limit by URL','url', |
$ENV{'form.url'}); |
$ENV{'form.url'}); |
|
|
$scrout.=&searchphrasefield('Limit by version','version', |
# $scrout.=&searchphrasefield('Limit by version','version', |
$ENV{'form.version'}); |
# $ENV{'form.version'}); |
|
|
$scrout.=&searchphrasefield('Limit by notes','notes', |
$scrout.=&searchphrasefield('Limit by notes','notes', |
$ENV{'form.notes'}); |
$ENV{'form.notes'}); |
Line 300 ENDDOCUMENT
|
Line 302 ENDDOCUMENT
|
$r->print(' '); |
$r->print(' '); |
$r->print(&simplecheckbox('titleonly',$ENV{'form.titleonly'})); |
$r->print(&simplecheckbox('titleonly',$ENV{'form.titleonly'})); |
$r->print('<font color="#800000">Title only</font> '); |
$r->print('<font color="#800000">Title only</font> '); |
$r->print(&simplecheckbox('allversions',$ENV{'form.allversions'})); |
# $r->print(&simplecheckbox('allversions',$ENV{'form.allversions'})); |
|
# <font color="#800000">Search historic archives</font> |
$r->print(<<ENDDOCUMENT); |
$r->print(<<ENDDOCUMENT); |
<font color="#800000">Search historic archives</font> |
|
<br> |
<br> |
<input type="submit" name="basicsubmit" value='SEARCH' /> |
<input type="submit" name="basicsubmit" value='SEARCH' /> |
<input type="reset" name="reset" value='RESET' /> |
<input type="reset" name="reset" value='RESET' /> |
Line 622 sub advancedsearch {
|
Line 624 sub advancedsearch {
|
$customquery,$customshow); |
$customquery,$customshow); |
&output_results('Advanced',$r,$envhash,$customquery,$reply); |
&output_results('Advanced',$r,$envhash,$customquery,$reply); |
} |
} |
$r->print(' '); # just in case.. hrrmm.. |
# should not get to this point |
return OK; |
return 'Error. Should not have gone to this point.'; |
} |
} |
|
|
# ---------------------------------------------------- see if a field is filled |
# ---------------------------------------------------- see if a field is filled |
sub filled { |
sub filled { |
my ($field)=@_; |
my ($field)=@_; |
if ($field=~/\S/) { |
if ($field=~/\S/ && $field ne 'any') { |
return 1; |
return 1; |
} |
} |
else { |
else { |
Line 657 sub basicsearch {
|
Line 659 sub basicsearch {
|
my $query=''; |
my $query=''; |
my $concatarg=join('," ",', |
my $concatarg=join('," ",', |
('title', 'author', 'subject', 'notes', 'abstract')); |
('title', 'author', 'subject', 'notes', 'abstract')); |
$query='select * from metadata where concat(' . $concatarg . ') like %' . |
$concatarg='title' if $ENV{'form.titleonly'}; |
$ENV{'form.basicexp'} . '%'; |
|
|
$query=&build_SQL_query('concat('.$concatarg.')',$ENV{'form.'.'basicexp'}); |
|
|
|
|
# Get reply (either a hash reference to filehandles or bad connection) |
# Get reply (either a hash reference to filehandles or bad connection) |
my $reply=&Apache::lonnet::metadata_query($query); |
my $reply=&Apache::lonnet::metadata_query('select * from metadata where '.$query); |
|
|
# Output search results |
# Output search results |
&output_results('Basic',$r,$envhash,$query,$reply); |
&output_results('Basic',$r,$envhash,$query,$reply); |
Line 705 RESULTS
|
Line 709 RESULTS
|
|
|
# ----------------------------- format and output results based on a reply list |
# ----------------------------- format and output results based on a reply list |
sub output_results { |
sub output_results { |
my ($mode,$r,$envhash,$query,@replylist)=@_; |
my ($mode,$r,$envhash,$query,$replyref)=@_; |
my %ENV=%{$envhash}; |
my %ENV=%{$envhash}; |
|
my %rhash=%{$replyref}; |
my $compiledresult=''; |
my $compiledresult=''; |
|
my $timeremain=30; |
|
my $resultflag=0; |
|
my $tflag=1; |
|
|
foreach my $reply (@replylist) { |
# make query information persistent to allow for subsequent revision |
|
my $persistent=&make_persistent(); |
|
|
my @results; |
# output beginning of search page |
|
$r->print(<<BEGINNING); |
|
<html> |
|
<head> |
|
<title>The LearningOnline Network with CAPA</title> |
|
BEGINNING |
|
$r->print(<<SCRIPT) if $ENV{'form.catalogmode'} eq 'interactive'; |
|
<script> |
|
function select_data(title,url) { |
|
changeTitle(title); |
|
changeURL(url); |
|
self.close(); |
|
} |
|
function changeTitle(val) { |
|
if (opener.inf.document.forms.resinfo.elements.t) { |
|
opener.inf.document.forms.resinfo.elements.t.value=val; |
|
} |
|
} |
|
function changeURL(val) { |
|
if (opener.inf.document.forms.resinfo.elements.u) { |
|
opener.inf.document.forms.resinfo.elements.u.value=val; |
|
} |
|
} |
|
</script> |
|
SCRIPT |
|
$r->print(<<CATALOGBEGIN); |
|
</head> |
|
<body bgcolor="#ffffff"> |
|
<img align=right src=/adm/lonIcons/lonlogos.gif> |
|
<h1>Search Catalog</h1> |
|
CATALOGBEGIN |
|
$r->print(<<RESULTS); |
|
<form method="post" action="/adm/searchcat"> |
|
<input type='button' value='Revise search request' |
|
onClick='this.form.submit();'> |
|
$closebutton |
|
$persistent |
|
<hr> |
|
<h3>Search Query</h3> |
|
RESULTS |
|
if ($mode eq 'Basic') { |
|
$r->print(<<RESULTS); |
|
<p> |
|
<b>Basic search:</b> $ENV{'form.basicexp'} |
|
</p> |
|
RESULTS |
|
} |
|
elsif ($mode eq 'Advanced') { |
|
$r->print(<<RESULTS); |
|
<p> |
|
<b>Advanced search</b> |
|
$query |
|
</p> |
|
RESULTS |
|
} |
|
$r->print('<h3>Search Results</h3>'); |
|
$r->rflush(); |
|
$r->print(<<ENDPOP); |
|
<script> |
|
popwin=open('','popwin','width=400,height=200'); |
|
popwin.document.writeln('<html><body bgcolor="#FFFFFF">'+ |
|
'<h3>Search Results Progress</h3>'+ |
|
'<form name=popremain>'+ |
|
'<br />Server space <input type=text size=25 name=space value="">'+ |
|
'<br />Status <input type=text size=25 name=status value="">'+ |
|
'<br />Maximum remaining time <input type=text size=25 name=timeout value="30">'+ |
|
'</form>'+ |
|
'</body></html>'); |
|
popwin.document.close(); |
|
</script> |
|
ENDPOP |
|
$r->rflush(); |
|
|
|
my $servernum=(keys %rhash)+0; |
|
$r->print('<script>popwin.document.popremain.space.value="'. |
|
$servernum.', 0%, count=0/'.$servernum.'";</script>'); |
|
$r->rflush(); |
|
my $servercount=0; |
|
foreach my $rkey (keys %rhash) { |
|
$servercount++; |
|
$tflag=1; |
|
$compiledresult=''; |
|
my $hostname=$rkey; |
|
$r->print('<script>popwin.document.popremain.status.value="'. |
|
$rkey.', trying contact";</script>'); |
|
$r->rflush(); |
|
my $reply=$rhash{$rkey}; |
|
my @results; |
|
|
my $replyfile=''; |
my $replyfile=''; |
$reply=~/^([\.\w]+)$/; # must do since 'use strict' checks for tainting |
|
$replyfile=$r->dir_config('lonDaemons').'/tmp/'.$1; |
if ($reply eq 'con_lost') { |
$reply=~/(.*?)\_/; |
my $percent=sprintf('%3.0f',($servercount/$servernum*100)); |
my $hostname=$1; |
$r->print('<script>popwin.document.popremain.space.value="'. |
sleep 3; # temporary fix, need to check for completion and status |
$servernum.', '.$percent.'%, count='.$servercount. |
{ |
'/'.$servernum.'";</script>'); |
while (1) { |
} |
last if -e $replyfile; |
else { |
sleep 1; |
$reply=~/^([\.\w]+)$/; # must do since 'use strict' checks for tainting |
|
$replyfile=$r->dir_config('lonDaemons').'/tmp/'.$1; |
|
$reply=~/(.*?)\_/; |
|
{ |
|
while (1) { |
|
if (-e $replyfile && $tflag) { |
|
$r->print('<script>popwin.document.popremain.status.'. |
|
'value="'.$rkey.', transmitting";</script>'); |
|
$r->rflush(); |
|
$tflag=0; |
|
} |
|
last if -e "$replyfile.end"; |
|
last unless $timeremain; |
|
sleep 1; |
|
$timeremain--; |
|
$r->print('<script>popwin.document.popremain.timeout.value="'. |
|
$timeremain.'";</script>'); |
|
$r->rflush(); |
|
} |
|
# QUESTION: how should I handle this error condition.. |
|
# I'm sure there is syntax elsewhere I can use.. |
|
my $fh=Apache::File->new($replyfile) or |
|
($r->print('ERROR: file cannot be opened') and return OK); |
|
@results=<$fh>; |
} |
} |
# QUESTION: how should I handle this error condition.. |
|
# I'm sure there is syntax elsewhere I can use.. |
|
my $fh=Apache::File->new($replyfile) or |
|
($r->print('file cannot be opened') and return OK); |
|
@results=<$fh>; |
|
} |
} |
|
|
my $customshow=''; |
my $customshow=''; |
my $extrashow=''; |
my $extrashow=''; |
my @customfields; |
my @customfields; |
Line 738 sub output_results {
|
Line 851 sub output_results {
|
$customshow=$ENV{'form.customshow'}; |
$customshow=$ENV{'form.customshow'}; |
$customshow=~s/[^\w\s]//g; |
$customshow=~s/[^\w\s]//g; |
my @fields=map {"<font color=\"#008000\">$_:</font><!-- $_ -->"} |
my @fields=map {"<font color=\"#008000\">$_:</font><!-- $_ -->"} |
split(/\s+/,$customshow); |
split(/\s+/,$customshow); |
@customfields=split(/\s+/,$customshow); |
@customfields=split(/\s+/,$customshow); |
if ($customshow) { |
if ($customshow) { |
$extrashow="<ul><li>".join("</li><li>",@fields)."</li></ul>\n"; |
$extrashow="<ul><li>".join("</li><li>",@fields)."</li></ul>\n"; |
Line 760 sub output_results {
|
Line 873 sub output_results {
|
chomp $result; |
chomp $result; |
next unless $result; |
next unless $result; |
my @fields=map |
my @fields=map |
{&Apache::lonnet::unescape($_)} |
{&Apache::lonnet::unescape($_)} |
(split(/\,/,$result)); |
(split(/\,/,$result)); |
my ($title,$author,$subject,$url,$keywords,$version, |
my ($title,$author,$subject,$url,$keywords,$version, |
$notes,$abstract,$mime,$lang, |
$notes,$abstract,$mime,$lang, |
$creationdate,$lastrevisiondate,$owner,$copyright)=@fields; |
$creationdate,$lastrevisiondate,$owner,$copyright)=@fields; |
Line 773 sub output_results {
|
Line 886 sub output_results {
|
foreach my $field (@customfields) { |
foreach my $field (@customfields) { |
my $value=''; |
my $value=''; |
if ($customhash{$url}=~/\<${field}[^\>]*\>(.*?)\<\/${field}[^\>]*\>/s) { |
if ($customhash{$url}=~/\<${field}[^\>]*\>(.*?)\<\/${field}[^\>]*\>/s) { |
$value=$1; |
$value=$1; |
} |
} |
$extrashow2=~s/\<\!\-\- $field \-\-\>/ $value/g; |
$extrashow2=~s/\<\!\-\- $field \-\-\>/ $value/g; |
} |
} |
} |
} |
|
|
$compiledresult.=<<END if $compiledresult; |
$compiledresult.=<<END if $compiledresult; |
<hr align='left' width='200' noshade /> |
<hr align='left' width='200' noshade /> |
END |
END |
$compiledresult.=<<END; |
$compiledresult.=<<END; |
<p> |
<p> |
END |
END |
$compiledresult.=<<END if $ENV{'form.catalogmode'} eq 'interactive'; |
$compiledresult.=<<END if $ENV{'form.catalogmode'} eq 'interactive'; |
<font size='-1'><INPUT TYPE="button" NAME="returnvalues" VALUE="SELECT" |
<font size='-1'><INPUT TYPE="button" NAME="returnvalues" VALUE="SELECT" |
onClick="javascript:select_data('$title','$url')"> |
onClick="javascript:select_data('$title','$url')"> |
</font> |
</font> |
Line 793 onClick="javascript:select_data('$title'
|
Line 906 onClick="javascript:select_data('$title'
|
END |
END |
my $httphost=$ENV{'HTTP_HOST'}; |
my $httphost=$ENV{'HTTP_HOST'}; |
|
|
my $viewselect; |
my $viewselect; |
if ($mode eq 'Basic') { |
if ($mode eq 'Basic') { |
$viewselect=$ENV{'form.basicviewselect'}; |
$viewselect=$ENV{'form.basicviewselect'}; |
} |
} |
elsif ($mode eq 'Advanced') { |
elsif ($mode eq 'Advanced') { |
$viewselect=$ENV{'form.advancedviewselect'}; |
$viewselect=$ENV{'form.advancedviewselect'}; |
} |
} |
|
|
if ($viewselect eq 'Detailed Citation View') { |
if ($viewselect eq 'Detailed Citation View') { |
$compiledresult.=&detailed_citation_view(@fields, |
$compiledresult.=&detailed_citation_view(@fields, |
$hostname,$httphost, |
$hostname,$httphost, |
$extrashow2); |
$extrashow2); |
} |
} |
elsif ($viewselect eq 'Summary View') { |
elsif ($viewselect eq 'Summary View') { |
$compiledresult.=&summary_view(@fields,$hostname,$httphost, |
$compiledresult.=&summary_view(@fields,$hostname,$httphost, |
$extrashow2); |
$extrashow2); |
} |
} |
elsif ($viewselect eq 'Fielded Format') { |
elsif ($viewselect eq 'Fielded Format') { |
$compiledresult.=&fielded_format_view(@fields,$hostname, |
$compiledresult.=&fielded_format_view(@fields,$hostname, |
$httphost,$extrashow2); |
$httphost,$extrashow2); |
} |
} |
elsif ($viewselect eq 'XML/SGML') { |
elsif ($viewselect eq 'XML/SGML') { |
$compiledresult.=&xml_sgml_view(@fields,$hostname,$httphost, |
$compiledresult.=&xml_sgml_view(@fields,$hostname,$httphost, |
$extrashow2); |
$extrashow2); |
} |
} |
|
|
} |
} |
|
|
unless ($compiledresult) { |
if ($compiledresult) { |
$compiledresult="There were no results that matched your query"; |
$resultflag=1; |
} |
} |
|
|
# make query information persistent to allow for subsequent revision |
|
my $persistent=&make_persistent(); |
|
|
|
$r->print(<<BEGINNING); |
|
<html> |
|
<head> |
|
<title>The LearningOnline Network with CAPA</title> |
|
BEGINNING |
|
$r->print(<<SCRIPT) if $ENV{'form.catalogmode'} eq 'interactive'; |
|
<script> |
|
function select_data(title,url) { |
|
changeTitle(title); |
|
changeURL(url); |
|
} |
|
function changeTitle(val) { |
|
if (opener.inf.document.forms.resinfo.elements.t) { |
|
opener.inf.document.forms.resinfo.elements.t.value=val; |
|
} |
|
} |
|
function changeURL(val) { |
|
if (opener.inf.document.forms.resinfo.elements.u) { |
|
opener.inf.document.forms.resinfo.elements.u.value=val; |
|
} |
|
} |
|
</script> |
|
SCRIPT |
|
$r->print(<<RESULTS); |
|
</head> |
|
<body bgcolor="#ffffff"> |
|
<img align=right src=/adm/lonIcons/lonlogos.gif> |
|
<h1>Search Catalog</h1> |
|
<form method="post" action="/adm/searchcat"> |
|
$customdata |
|
<input type='button' value='Revise search request' |
|
onClick='this.form.submit();'> |
|
$closebutton |
|
$persistent |
|
<hr> |
|
<h3>Search Query</h3> |
|
RESULTS |
|
if ($mode eq 'Basic') { |
|
$r->print(<<RESULTS); |
$r->print(<<RESULTS); |
<p> |
$compiledresult |
<b>Basic search:</b> $ENV{'form.basicexp'} |
|
</p> |
|
RESULTS |
RESULTS |
|
my $percent=sprintf('%3.0f',($servercount/$servernum*100)); |
|
$r->print('<script>popwin.document.popremain.space.value="'. |
|
$servernum.', '.$percent.'%, count='.$servercount. |
|
'/'.$servernum.'";</script>'); |
} |
} |
elsif ($mode eq 'Advanced') { |
unless ($resultflag) { |
$r->print(<<RESULTS); |
$r->print("\nThere were no results that matched your query\n"); |
<p> |
|
<b>Advanced search</b> |
|
$query |
|
</p> |
|
RESULTS |
|
} |
} |
$r->print(<<RESULTS); |
$r->print('<script>popwin.close()</script>'); $r->rflush(); |
<h3>Search Results</h3> |
$r->print(<<RESULTS); |
$compiledresult |
|
</body> |
</body> |
</html> |
</html> |
RESULTS |
RESULTS |
} |
|
} |
} |
|
|
# ------------------------------------------------------------- build_SQL_query |
# ------------------------------------------------------------- build_SQL_query |
Line 928 sub recursive_SQL_query_build {
|
Line 995 sub recursive_SQL_query_build {
|
if ($key eq 'literal') { |
if ($key eq 'literal') { |
$replacement="($dkey like \"\%$value\%\")"; |
$replacement="($dkey like \"\%$value\%\")"; |
} |
} |
|
elsif ($key eq 'not') { |
|
$value=~s/like/not like/; |
|
# $replacement="($dkey not like $value)"; |
|
$replacement="$value"; |
|
} |
elsif ($key eq 'and') { |
elsif ($key eq 'and') { |
$value=~/(.*[\"|\)]) ([|\(|\^].*)/; |
$value=~/(.*[\"|\)]) ([|\(|\^].*)/; |
$replacement="($1 AND $2)"; |
$replacement="($1 AND $2)"; |