version 1.92, 2001/04/02 16:57:38
|
version 1.94, 2001/04/13 18:09:15
|
Line 658 sub basicsearch {
|
Line 658 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 %' . |
# $query='select * from metadata where concat(' . $concatarg . ') like "%' . |
$ENV{'form.basicexp'} . '%'; |
# $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 711 sub output_results {
|
Line 714 sub output_results {
|
my %rhash=%{$replyref}; |
my %rhash=%{$replyref}; |
my $compiledresult=''; |
my $compiledresult=''; |
my $timeremain=30; |
my $timeremain=30; |
|
my $resultflag=0; |
|
my $tflag=1; |
|
|
|
# make query information persistent to allow for subsequent revision |
|
my $persistent=&make_persistent(); |
|
|
|
# output beginning of search page |
$r->print(<<BEGINNING); |
$r->print(<<BEGINNING); |
<html> |
<html> |
<head> |
<head> |
Line 740 SCRIPT
|
Line 750 SCRIPT
|
<img align=right src=/adm/lonIcons/lonlogos.gif> |
<img align=right src=/adm/lonIcons/lonlogos.gif> |
<h1>Search Catalog</h1> |
<h1>Search Catalog</h1> |
CATALOGBEGIN |
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->rflush(); |
$r->print(<<ENDPOP); |
$r->print(<<ENDPOP); |
<script> |
<script> |
Line 759 ENDPOP
|
Line 794 ENDPOP
|
|
|
my $servernum=(keys %rhash)+0; |
my $servernum=(keys %rhash)+0; |
$r->print('<script>popwin.document.popremain.space.value="'. |
$r->print('<script>popwin.document.popremain.space.value="'. |
$servernum.', 0%, count=0/1";</script>'); |
$servernum.', 0%, count=0/'.$servernum.'";</script>'); |
$r->rflush(); |
$r->rflush(); |
|
my $servercount=0; |
foreach my $rkey (keys %rhash) { |
foreach my $rkey (keys %rhash) { |
|
$servercount++; |
|
$tflag=1; |
|
$compiledresult=''; |
|
my $hostname=$rkey; |
$r->print('<script>popwin.document.popremain.status.value="'. |
$r->print('<script>popwin.document.popremain.status.value="'. |
$rkey.', trying contact";</script>'); |
$rkey.', trying contact";</script>'); |
$r->rflush(); |
$r->rflush(); |
Line 769 ENDPOP
|
Line 809 ENDPOP
|
my @results; |
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="'. |
{ |
$servernum.', '.$percent.'%, count='.$servercount. |
while (1) { |
'/'.$servernum.'";</script>'); |
$r->print('<script>popwin.document.popremain.status.value="'. |
} |
$rkey.', contacted";</script>') if -e $replyfile; |
else { |
$r->rflush(); |
$reply=~/^([\.\w]+)$/; # must do since 'use strict' checks for tainting |
last if -e "$replyfile.end"; |
$replyfile=$r->dir_config('lonDaemons').'/tmp/'.$1; |
last unless $timeremain; |
$reply=~/(.*?)\_/; |
sleep 1; |
{ |
$timeremain--; |
while (1) { |
$r->print('<script>popwin.document.popremain.timeout.value="'. |
if (-e $replyfile && $tflag) { |
$timeremain.'";</script>'); |
$r->print('<script>popwin.document.popremain.status.'. |
$r->rflush(); |
'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 800 ENDPOP
|
Line 850 ENDPOP
|
$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 822 ENDPOP
|
Line 872 ENDPOP
|
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 835 ENDPOP
|
Line 885 ENDPOP
|
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 855 onClick="javascript:select_data('$title'
|
Line 905 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(<<RESULTS); |
|
<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 |
} |
|
$r->print('<script>popwin.close()</script>'); $r->rflush(); |
|
} |
} |
|
|
# ------------------------------------------------------------- build_SQL_query |
# ------------------------------------------------------------- build_SQL_query |
Line 964 sub recursive_SQL_query_build {
|
Line 994 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)"; |