--- loncom/interface/lonsearchcat.pm 2002/06/20 14:31:31 1.124
+++ loncom/interface/lonsearchcat.pm 2002/06/20 19:43:50 1.125
@@ -1,7 +1,7 @@
# The LearningOnline Network with CAPA
# Search Catalog
#
-# $Id: lonsearchcat.pm,v 1.124 2002/06/20 14:31:31 matthew Exp $
+# $Id: lonsearchcat.pm,v 1.125 2002/06/20 19:43:50 matthew Exp $
#
# Copyright Michigan State University Board of Trustees
#
@@ -524,7 +524,6 @@ a 'hidden' html input tag.
sub make_persistent {
my $persistent='';
-
foreach (keys %ENV) {
if (/^form\./ && !/submit/) {
my $name=$_;
@@ -532,7 +531,7 @@ sub make_persistent {
$ENV{$key}=~s/\'//g; # do not mess with html field syntax
$name=~s/^form\.//;
$persistent.=<
+
END
}
}
@@ -1029,104 +1028,16 @@ sub output_results {
my %ENV=%{$envhash};
my %rhash=%{$replyref};
my $compiledresult='';
- my $timeremain=300;
+ my $timeremain=300; # (seconds)
my $elapsetime=0;
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(<
-
-The LearningOnline Network with CAPA
-BEGINNING
-
- # conditional output of script functions dependent on the mode in
- # which the search was invoked
- if ($ENV{'form.catalogmode'} eq 'interactive'){
- if (! exists($ENV{'form.mode'}) || $ENV{'form.mode'} ne 'edit') {
- $r->print(<
-SCRIPT
- } elsif ($ENV{'form.mode'} eq 'edit') {
- my $form = $ENV{'form.form'};
- my $element = $ENV{'form.element'};
- $r->print(<
-SCRIPT
- }
- }
- $r->print(<
-SCRIPT
- $r->print(<
-SCRIPT
+ # spit out the generic header
+ $r->print(&search_results_header());
$r->rflush();
-
# begin showing the cataloged results
$r->print(<
@@ -1146,146 +1057,66 @@ $persistent
Search Query
CATALOGCONTROLS
+ #
+ # Remind them what they searched for
+ #
if ($mode eq 'Basic') {
- $r->print(<
-Basic search: $ENV{'form.basicexp'}
-
-RESULTS
- }
- elsif ($mode eq 'Advanced') {
- $r->print(<
-Advanced search
-$query
-
-RESULTS
+ $r->print('Basic search: '.$ENV{'form.basicexp'}.'
');
+ } elsif ($mode eq 'Advanced') {
+ $r->print('Advanced search '.$query.'
');
}
$r->print('Search Results ');
$r->rflush();
- my $servernum=(keys %rhash)+0;
-
- # define server grid (shows status of multiple machines)
- my $hcinit;
- my $grid="' '+";
- $grid.="\n";
- my $sn=1;
- for my $sk (sort keys %rhash) {
- # ''+
- $grid.="'+\"'\"+')\">'+";
- $grid.="\n";
- $grid.="' '+\n";
- $grid.="' '+\n" unless $sn%10;
- $sn++;
- }
- $r->print(<
- popwin=open('','popwin','scrollbars=1,width=400,height=220');
- popwin.focus();
- popwin.document.writeln('<'+'html>');
- popwin.document.writeln('<'+'head>');
- popwin.document.writeln('<'+'script>');
- popwin.document.writeln('hc=new Array();$hcinit');
- popwin.document.writeln('<'+'/script>');
- popwin.document.writeln('<'+'/head>'+
- '<'+'body bgcolor="#FFFFFF">'+
- '<'+'image name="whirly" align="right" src="/adm/lonIcons/'+
- 'lonanim.gif" '+
- 'alt="animated logo" />'+
- '<'+'h3>Search Results Progress<'+'/h3>'+
- '<'+'form name="popremain">'+
- '<'+'tt>'+
- '<'+'br clear="all"/>PLEASE BE PATIENT '+
- '<'+'br />SCANNING $servernum SERVERS'+
- '<'+'br clear="all" />Number of record hits found '+
- '<'+'input type="text" size="10" name="numhits"'+
- ' value="0" />'+
- '<'+'br clear="all" />Time elapsed '+
- '<'+'input type="text" size="10" name="elapsetime"'+
- ' value="0" />'+
- '<'+'br />'+
- 'SERVER GRID (click on any cell for details)'+
- $grid
- '<'+'br />'+
- 'Server details '+
- '<'+'input type="text" size="35" name="sdetails"'+
- ' value="" />'+
- '<'+'br />'+
- ' <'+'input type="button" name="button"'+
- ' value="close this window" '+
- ' onClick="javascript:opener.abortsearch()" />'+
- ' <'+'input type="button" name="button"'+
- ' value="help" onClick="javascript:opener.openhelp()" />'+
- '<'+'/tt>'+
- '<'+'/form>'+
- '<'+'/body><'+'/html>');
- popwin.document.close();
-
-ENDPOP
+ #
+ # make the pop-up window for status
+ #
+ $r->print(&make_popwin(%rhash));
$r->rflush();
-
+ ##
+ ## Prepare for the main loop below
+ ##
my $servercount=0;
my $hitcountsum=0;
- my $bloop=$servernum;
- my %orkey;
- BLOOP: while(1) {
- my $sn=0;
- last BLOOP unless $bloop;
- last BLOOP unless $timeremain;
- RLOOP: foreach my $rkey (sort keys %rhash) {
- $sn++;
- next RLOOP if $orkey{$rkey};
+ my $servernum=(keys %rhash);
+ my $serversleft=$servernum;
+ ##
+ ## Run until we run out of time or we run out of servers
+ ##
+ while($serversleft && $timeremain) {
+ ##
+ ## %rhash has servers deleted from it as results come in
+ ## (within the foreach loop below).
+ ##
+ foreach my $rkey (sort keys %rhash) {
$servercount++;
$tflag=1;
$compiledresult='';
my $hostname=$rkey;
my $reply=$rhash{$rkey};
my @results;
-
- my $replyfile='';
-
if ($reply eq 'con_lost') {
- &popwin_imgupdate($r,$sn,"srvbad.gif");
- $bloop--;
- $orkey{$rkey}=1;
- }
- else {
- $reply=~/^([\.\w]+)$/; # must do since 'use strict' checks for tainting
- $replyfile=$r->dir_config('lonDaemons').'/tmp/'.$1;
+ &popwin_imgupdate($r,$rkey,"srvbad.gif");
+ $serversleft--;
+ delete $rhash{$rkey};
+ } else {
+ # must do since 'use strict' checks for tainting
+ $reply=~/^([\.\w]+)$/;
+ my $replyfile=$r->dir_config('lonDaemons').'/tmp/'.$1;
$reply=~/(.*?)\_/;
{
my $temp=0;
WLOOP: while (1) {
if (-e $replyfile && $tflag) {
- &popwin_imgupdate($r,$sn,"srvhalf.gif");
+ &popwin_imgupdate($r,$rkey,"srvhalf.gif");
&popwin_js($r,'popwin.hc["'.$rkey.'"]='.
'"still transferring..."'.';');
$tflag=0;
}
if (-e "$replyfile.end") {
- $bloop--;
- $orkey{$rkey}=1;
+ $serversleft--;
+ delete $rhash{$rkey};
if (-s $replyfile) {
- &popwin_imgupdate($r,$sn,"srvgood.gif");
+ &popwin_imgupdate($r,$rkey,"srvgood.gif");
my $fh=Apache::File->new($replyfile) or
($r->print('ERROR: file '.
$replyfile.' cannot be opened') and
@@ -1299,21 +1130,16 @@ ENDPOP
'numhits.value='.$hitcountsum.';');
}
else {
- &popwin_imgupdate($r,$sn,"srvempty.gif");
+ &popwin_imgupdate($r,$rkey,"srvempty.gif");
&popwin_js($r,'popwin.hc["'.$rkey.'"]=0;');
}
last WLOOP;
- }
- if ($temp>1) {
- sleep 1;
- $timeremain--;
- $elapsetime++;
- last WLOOP;
- }
+ } # end of if ( -e "$replyfile.end")
last WLOOP unless $timeremain;
- sleep 1;
+ sleep 1; # wait for daemons to write files?
$timeremain--;
$elapsetime++;
+ last WLOOP if ($temp>1);
&popwin_js($r,"popwin.document.popremain.".
"elapsetime.value=$elapsetime;");
$temp++;
@@ -1321,7 +1147,7 @@ ENDPOP
}
&popwin_js($r,'popwin.document.whirly.'.
'src="/adm/lonIcons/lonanimend.gif";');
- }
+ } # end of if ($reply eq 'con_lost') else statement
my $customshow='';
my $extrashow='';
my @customfields;
@@ -1484,6 +1310,204 @@ RESULTS
######################################################################
######################################################################
+=pod
+
+=item &search_results_header
+
+=cut
+
+######################################################################
+######################################################################
+sub search_results_header {
+ my $result = '';
+ # output beginning of search page
+ $result.=<
+
+The LearningOnline Network with CAPA
+BEGINNING
+ # conditional output of script functions dependent on the mode in
+ # which the search was invoked
+ if ($ENV{'form.catalogmode'} eq 'interactive'){
+ if (! exists($ENV{'form.mode'}) || $ENV{'form.mode'} ne 'edit') {
+ $result.=<
+SCRIPT
+ } elsif ($ENV{'form.mode'} eq 'edit') {
+ my $form = $ENV{'form.form'};
+ my $element = $ENV{'form.element'};
+ $result.=<
+SCRIPT
+ }
+ }
+ $result.=<
+SCRIPT
+ $result.=<
+SCRIPT
+ return $result;
+}
+
+######################################################################
+######################################################################
+
+=pod
+
+=item &make_popwin()
+
+Returns html with javascript in it to open up the status window.
+
+=cut
+
+######################################################################
+######################################################################
+sub make_popwin {
+ my %rhash = @_;
+ my $servernum=(keys %rhash);
+ my $hcinit;
+ my $grid="' '+\n";
+ # $sn is the server number, used ONLY to make sure we have
+ # rows of 10 each. No longer used to index images.
+ my $sn=1;
+ foreach my $sk (sort keys %rhash) {
+ # ''+
+ $grid.="'+\"'\"+')\">'+";
+ $grid.="\n";
+ $grid.="' '+\n";
+ $grid.="' '+\n" unless $sn%10;
+ $sn++;
+ }
+ my $result.=<
+ popwin=open('','popwin','scrollbars=1,width=400,height=220');
+ popwin.focus();
+ popwin.document.writeln('<'+'html>');
+ popwin.document.writeln('<'+'head>');
+ popwin.document.writeln('<'+'script>');
+ popwin.document.writeln('hc=new Array();$hcinit');
+ popwin.document.writeln('<'+'/script>');
+ popwin.document.writeln('<'+'/head>'+
+ '<'+'body bgcolor="#FFFFFF">'+
+ '<'+'image name="whirly" align="right" src="/adm/lonIcons/'+
+ 'lonanim.gif" '+
+ 'alt="animated logo" />'+
+ '<'+'h3>Search Results Progress<'+'/h3>'+
+ '<'+'form name="popremain">'+
+ '<'+'tt>'+
+ '<'+'br clear="all"/>PLEASE BE PATIENT '+
+ '<'+'br />SCANNING $servernum SERVERS'+
+ '<'+'br clear="all" />Number of record hits found '+
+ '<'+'input type="text" size="10" name="numhits"'+
+ ' value="0" />'+
+ '<'+'br clear="all" />Time elapsed '+
+ '<'+'input type="text" size="10" name="elapsetime"'+
+ ' value="0" />'+
+ '<'+'br />'+
+ 'SERVER GRID (click on any cell for details)'+
+ $grid
+ '<'+'br />'+
+ 'Server details '+
+ '<'+'input type="text" size="35" name="sdetails"'+
+ ' value="" />'+
+ '<'+'br />'+
+ ' <'+'input type="button" name="button"'+
+ ' value="close this window" '+
+ ' onClick="javascript:opener.abortsearch()" />'+
+ ' <'+'input type="button" name="button"'+
+ ' value="help" onClick="javascript:opener.openhelp()" />'+
+ '<'+'/tt>'+
+ '<'+'/form>'+
+ '<'+'/body><'+'/html>');
+ popwin.document.close();
+
+ENDPOP
+ return $result;
+}
+
+######################################################################
+######################################################################
+
=pod
=item Metadata Viewing Functions
@@ -1827,13 +1851,16 @@ END
=item &popwin_imgupdate()
+Send a given image (and its location) out to the browser. Takes as
+input $r, loncapa server id, and an icon URL.
+
=cut
######################################################################
######################################################################
sub popwin_imgupdate {
- my ($r,$imgnum,$icon) = @_;
- &popwin_js($r,'popwin.document.img'.$imgnum.'.'.
+ my ($r,$server,$icon) = @_;
+ &popwin_js($r,'popwin.document.img_'.$hostdomains{$server}.'_'.$server.'.'.
'src="/adm/lonIcons/'.$icon.'";');
}