--- loncom/interface/lonsearchcat.pm 2001/04/02 13:15:26 1.91
+++ loncom/interface/lonsearchcat.pm 2001/08/16 02:20:01 1.97
@@ -1,10 +1,11 @@
# The LearningOnline Network
# Search Catalog
#
+# YEAR=2001
# 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/20/2001, 03/21/2001, 03/22/2001, 03/26/2001, 03/27/2001
-# Scott Harrison: 04/02/2001
+# Scott Harrison: 04/02/2001, 08/15/2001
#
# Functions
#
@@ -182,8 +183,8 @@ END
$scrout.=&searchphrasefield('Limit by URL','url',
$ENV{'form.url'});
- $scrout.=&searchphrasefield('Limit by version','version',
- $ENV{'form.version'});
+# $scrout.=&searchphrasefield('Limit by version','version',
+# $ENV{'form.version'});
$scrout.=&searchphrasefield('Limit by notes','notes',
$ENV{'form.notes'});
@@ -301,9 +302,9 @@ ENDDOCUMENT
$r->print(' ');
$r->print(&simplecheckbox('titleonly',$ENV{'form.titleonly'}));
$r->print('Title only ');
- $r->print(&simplecheckbox('allversions',$ENV{'form.allversions'}));
+# $r->print(&simplecheckbox('allversions',$ENV{'form.allversions'}));
+# Search historic archives
$r->print(<Search historic archives
@@ -623,14 +624,14 @@ sub advancedsearch {
$customquery,$customshow);
&output_results('Advanced',$r,$envhash,$customquery,$reply);
}
- $r->print(' '); # just in case.. hrrmm..
- return OK;
+ # should not get to this point
+ return 'Error. Should not have gone to this point.';
}
# ---------------------------------------------------- see if a field is filled
sub filled {
my ($field)=@_;
- if ($field=~/\S/) {
+ if ($field=~/\S/ && $field ne 'any') {
return 1;
}
else {
@@ -658,11 +659,13 @@ sub basicsearch {
my $query='';
my $concatarg=join('," ",',
('title', 'author', 'subject', 'notes', 'abstract'));
- $query='select * from metadata where concat(' . $concatarg . ') like %' .
- $ENV{'form.basicexp'} . '%';
+ $concatarg='title' if $ENV{'form.titleonly'};
+
+ $query=&build_SQL_query('concat('.$concatarg.')',$ENV{'form.'.'basicexp'});
+
# 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_results('Basic',$r,$envhash,$query,$reply);
@@ -706,32 +709,141 @@ RESULTS
# ----------------------------- format and output results based on a reply list
sub output_results {
- my ($mode,$r,$envhash,$query,@replylist)=@_;
+ my ($mode,$r,$envhash,$query,$replyref)=@_;
my %ENV=%{$envhash};
+ my %rhash=%{$replyref};
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(<
+
+The LearningOnline Network with CAPA
+BEGINNING
+ $r->print(<
+SCRIPT
+ $r->print(<
+
+
+
'+
+ ''+
+ '');
+ popwin.document.close();
+
+ENDPOP
+ $r->rflush();
+ my $servernum=(keys %rhash)+0;
+ $r->print('');
+ $r->rflush();
+ my $servercount=0;
+ foreach my $rkey (keys %rhash) {
+ $servercount++;
+ $tflag=1;
+ $compiledresult='';
+ my $hostname=$rkey;
+ $r->print('');
+ $r->rflush();
+ my $reply=$rhash{$rkey};
+ my @results;
+
my $replyfile='';
- $reply=~/^([\.\w]+)$/; # must do since 'use strict' checks for tainting
- $replyfile=$r->dir_config('lonDaemons').'/tmp/'.$1;
- $reply=~/(.*?)\_/;
- my $hostname=$1;
- sleep 3; # temporary fix, need to check for completion and status
- {
- while (1) {
- last if -e $replyfile;
- sleep 1;
+
+ if ($reply eq 'con_lost') {
+ my $percent=sprintf('%3.0f',($servercount/$servernum*100));
+ $r->print('');
+ }
+ else {
+ $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('');
+ $r->rflush();
+ $tflag=0;
+ }
+ last if -e "$replyfile.end";
+ last unless $timeremain;
+ sleep 1;
+ $timeremain--;
+ $r->print('');
+ $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 $extrashow='';
my @customfields;
@@ -739,7 +851,7 @@ sub output_results {
$customshow=$ENV{'form.customshow'};
$customshow=~s/[^\w\s]//g;
my @fields=map {"$_:"}
- split(/\s+/,$customshow);
+ split(/\s+/,$customshow);
@customfields=split(/\s+/,$customshow);
if ($customshow) {
$extrashow="
".join("
",@fields)."
\n";
@@ -761,8 +873,8 @@ sub output_results {
chomp $result;
next unless $result;
my @fields=map
- {&Apache::lonnet::unescape($_)}
- (split(/\,/,$result));
+ {&Apache::lonnet::unescape($_)}
+ (split(/\,/,$result));
my ($title,$author,$subject,$url,$keywords,$version,
$notes,$abstract,$mime,$lang,
$creationdate,$lastrevisiondate,$owner,$copyright)=@fields;
@@ -774,19 +886,19 @@ sub output_results {
foreach my $field (@customfields) {
my $value='';
if ($customhash{$url}=~/\<${field}[^\>]*\>(.*?)\<\/${field}[^\>]*\>/s) {
- $value=$1;
+ $value=$1;
}
- $extrashow2=~s/\<\!\-\- $field \-\-\>/ $value/g;
- }
- }
-
- $compiledresult.=</ $value/g;
+ }
+ }
+
+ $compiledresult.=<
END
- $compiledresult.=<
END
- $compiledresult.=<
@@ -794,100 +906,54 @@ onClick="javascript:select_data('$title'
END
my $httphost=$ENV{'HTTP_HOST'};
- my $viewselect;
- if ($mode eq 'Basic') {
+ my $viewselect;
+ if ($mode eq 'Basic') {
$viewselect=$ENV{'form.basicviewselect'};
}
- elsif ($mode eq 'Advanced') {
- $viewselect=$ENV{'form.advancedviewselect'};
- }
+ elsif ($mode eq 'Advanced') {
+ $viewselect=$ENV{'form.advancedviewselect'};
+ }
if ($viewselect eq 'Detailed Citation View') {
- $compiledresult.=&detailed_citation_view(@fields,
- $hostname,$httphost,
- $extrashow2);
+ $compiledresult.=&detailed_citation_view(@fields,
+ $hostname,$httphost,
+ $extrashow2);
}
elsif ($viewselect eq 'Summary View') {
$compiledresult.=&summary_view(@fields,$hostname,$httphost,
- $extrashow2);
+ $extrashow2);
}
elsif ($viewselect eq 'Fielded Format') {
$compiledresult.=&fielded_format_view(@fields,$hostname,
- $httphost,$extrashow2);
+ $httphost,$extrashow2);
}
elsif ($viewselect eq 'XML/SGML') {
$compiledresult.=&xml_sgml_view(@fields,$hostname,$httphost,
- $extrashow2);
+ $extrashow2);
}
-
+
}
- unless ($compiledresult) {
- $compiledresult="There were no results that matched your query";
+ if ($compiledresult) {
+ $resultflag=1;
}
- # make query information persistent to allow for subsequent revision
- my $persistent=&make_persistent();
-
- $r->print(<
-
-The LearningOnline Network with CAPA
-BEGINNING
- $r->print(<
-SCRIPT
- $r->print(<
-
-
-