--- loncom/interface/lonsearchcat.pm 2001/12/11 03:18:39 1.110 +++ loncom/interface/lonsearchcat.pm 2002/03/08 18:36:00 1.117 @@ -1,7 +1,7 @@ # The LearningOnline Network with CAPA # Search Catalog # -# $Id: lonsearchcat.pm,v 1.110 2001/12/11 03:18:39 harris41 Exp $ +# $Id: lonsearchcat.pm,v 1.117 2002/03/08 18:36:00 matthew Exp $ # # Copyright Michigan State University Board of Trustees # @@ -28,7 +28,9 @@ # YEAR=2001 # 3/8, 3/12, 3/13, 3/14, 3/15, 3/19 Scott Harrison # 3/20, 3/21, 3/22, 3/26, 3/27, 4/2, 8/15, 8/24, 8/25 Scott Harrison -# 10/12,10/14,10/15,10/16,11/28,11/29,12/10 Scott Harrison +# 10/12,10/14,10/15,10/16,11/28,11/29,12/10,12/12,12/16 Scott Harrison +# YEAR=2002 +# 1/17 Scott Harrison # ### @@ -54,13 +56,11 @@ use Apache::File(); use CGI qw(:standard); use Text::Query; use GDBM_File; +use Apache::loncommon(); # ---------------------------------------- variables used throughout the module # -- information holders -my %language; # holds contents of language.tab -my %cprtag; # holds contents of copyright.tab -my %mimetag; # holds contents of filetypes.tab my %hostdomains; # matches host name to host domain my %hostips; # matches host name to host ip my %hitcount; # stores number of hits per host @@ -97,37 +97,7 @@ my $advancedviewselect=<new($Apache::lonnet::perlvar{'lonTabDir'}. - '/language.tab'); - while (<$fh>) { - $_=~/(\w+)\s+([\w\s\-]+)/; chomp; - $language{$1}=$2; - } - } - $cprtag{'any'}='Any copyright/distribution'; - { - my $fh=Apache::File->new($Apache::lonnet::perlvar{'lonIncludes'}. - '/copyright.tab'); - while (<$fh>) { - $_=~/(\w+)\s+([\w\s\-]+)/; chomp; - $cprtag{$1}=$2; - } - } - $mimetag{'any'}='Any type'; - { - my $fh=Apache::File->new($Apache::lonnet::perlvar{'lonTabDir'}. - '/filetypes.tab'); - while (<$fh>) { - if (/^\S/ and !/^\#/) { - $_=~/(\S+)\s+(\S+)\s+([\S\s\-]+)/; chomp; - $mimetag{$1}=".$1 $3"; - } - } - } +BEGIN { { my $fh=Apache::File->new($Apache::lonnet::perlvar{'lonTabDir'}. '/hosts.tab'); @@ -141,6 +111,7 @@ sub BEGIN { } } +#------------------------------------------------------------- global variables my $diropendb = ""; my $domain = ""; @@ -148,16 +119,17 @@ my $domain = ""; sub handler { my $r = shift; untie %hash; - &get_unprocessed_cgi(); $r->content_type('text/html'); $r->send_http_header; return OK if $r->header_only; $domain = $r->dir_config('lonDefDomain'); - $diropendb= "/home/httpd/perl/tmp/$domain\_$ENV{'user.name'}_searchcat.db"; + &Apache::loncommon::get_unprocessed_cgi($ENV{'QUERY_STRING'}, + ['catalogmode','launch','acts','mode','form','element']); + if ($ENV{'form.launch'} eq '1') { if (tie(%hash,'GDBM_File',$diropendb,&GDBM_WRCREAT,0640)) { &start_fresh_session(); @@ -190,7 +162,12 @@ END onClick='javascript:select_group()'> END } - + $hidden .= < + + + +END # ------------------------------------------------------ Determine current user $yourself=$ENV{'user.name'}.'@'.$ENV{'user.domain'}; @@ -235,13 +212,18 @@ END $ENV{'form.mime'}='any' unless length($ENV{'form.mime'}); $scrout.=&selectbox('Limit by MIME type','mime', - $ENV{'form.mime'},%mimetag); + $ENV{'form.mime'}, + 'any','Any type', + \&{Apache::loncommon::filedescriptionex}, + (&Apache::loncommon::fileextensions)); $ENV{'form.language'}='any' unless length($ENV{'form.language'}); $scrout.=&selectbox('Limit by language','language', - $ENV{'form.language'},%language); - + $ENV{'form.language'},'any','Any Language', + \&{Apache::loncommon::languagedescription}, + (&Apache::loncommon::languageids), + ); # ------------------------------------------------ Compute date selection boxes $scrout.=< @@ -376,18 +362,6 @@ ENDDOCUMENT return OK; } -# ----------- grab unprocessed CGI variables that may have been appended to URL -sub get_unprocessed_cgi { - foreach (split(/&/,$ENV{'QUERY_STRING'})) { - my ($name, $value) = split(/=/,$_); - $value =~ tr/+/ /; - $value =~ s/%([a-fA-F0-9][a-fA-F0-9])/pack("C",hex($1))/eg; - if ($name eq 'catalogmode' or $name eq 'launch' or $name eq 'acts') { - $ENV{'form.'.$name}=$value; - } - } -} - # ------------------------------------------------------------- make persistent sub make_persistent { my $persistent=''; @@ -437,155 +411,60 @@ sub dateboxes { my ($name,$defaultmonth,$defaultday,$defaultyear, $currentmonth,$currentday,$currentyear)=@_; ($defaultmonth,$defaultday,$defaultyear)=('','',''); - my $month=< - - - - - - - - - - - - - - -END - $month=~s/(\"$currentmonth\")/$1 SELECTED/ if length($currentmonth); + # + # Day my $day=< - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - END + for (my $i = 1; $i<=31; $i++) { + $day.="\n"; + } + $day.="\n"; $day=~s/(\"$currentday\")/$1 SELECTED/ if length($currentday); + # + # Month + my $month=< + +END + my $i = 1; + foreach (qw/January February March April May June + July August September October November December /){ + $month .="\n"; + $i++; + } + $month.="\n"; + $month=~s/(\"$currentmonth\")/$1 SELECTED/ if length($currentmonth); + # + # Year (obviously) my $year=< - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - END + my $maxyear = 2051; + for (my $i = 1976; $i<=$maxyear; $i++) { + $year.="\n"; + } + $year.="\n"; $year=~s/(\"$currentyear\")/$1 SELECTED/ if length($currentyear); return "$month$day$year"; } sub selectbox { - my ($title,$name,$value,%options)=@_; + my ($title,$name,$value,$anyvalue,$anytag,$functionref,@idlist)=@_; my $uctitle=uc($title); my $selout="\n

$uctitle:". "
".''; } @@ -608,7 +487,12 @@ sub advancedsearch { 'custommetadata','customshow') { $ENV{"form.$field"}=~s/[^\w\/\s\(\)\=\-\"\']//g; } - + foreach ('mode','form','element') { + # is this required? Hmmm. + next unless (exists($ENV{"form.$_"})); + $ENV{"form.$_"}=&Apache::lonnet::unescape($ENV{"form.$_"}); + $ENV{"form.$_"}=~s/[^\w\/\s\(\)\=\-\"\']//g; + } # Check to see if enough information was filled in for my $field ('title','author','subject','keywords','url','version', 'notes','abstract','mime','language','owner', @@ -715,6 +599,12 @@ sub basicsearch { for my $field ('basicexp') { $ENV{"form.$field"}=~s/[^\w\s\(\)\-]//g; } + foreach ('mode','form','element') { + # is this required? Hmmm. + next unless (exists($ENV{"form.$_"})); + $ENV{"form.$_"}=&Apache::lonnet::unescape($ENV{"form.$_"}); + $ENV{"form.$_"}=~s/[^\w\/\s\(\)\=\-\"\']//g; + } # Check to see if enough is filled in unless (&filled($ENV{'form.basicexp'})) { @@ -878,7 +768,9 @@ BEGINNING # conditional output of script functions dependent on the mode in # which the search was invoked - $r->print(<print(< function select_data(title,url) { changeTitle(title); @@ -897,7 +789,30 @@ BEGINNING } SCRIPT - $r->print(<print(< +function select_data(title,url) { + changeURL(url); + self.close(); +} +function changeTitle(val) { +} +function changeURL(val) { + if (window.opener.document) { + window.opener.document.forms["$form"].elements["$element"].value=val; + } else { + var url = 'forms[\"$form\"].elements[\"$element\"].value'; + alert("Unable to transfer data to "+url); + } +} + +SCRIPT + } + } + $r->print(< function select_data(title,url) { // alert('DEBUG: Should be storing '+title+' and '+url); @@ -916,7 +831,7 @@ SCRIPT } SCRIPT - $r->print(<print(< function displayinfo(val) { popwin.document.forms.popremain.sdetails.value=val; @@ -927,9 +842,7 @@ SCRIPT openhelpwin.focus(); } function abortsearch(val) { - openhelpwin=open('/adm/help/searchcat.html','helpscreen', - 'scrollbars=1,width=400,height=300'); - openhelpwin.focus(); + popwin.close(); } SCRIPT @@ -987,7 +900,7 @@ RESULTS $grid.=$sk; my $hc; if ($rhash{$sk} eq 'con_lost') { - $hc="!!!BAD CONNECTION, CONTACT SYSTEM ADMINISTRATOR!!!"; + $hc="BAD CONNECTION, CONTACT SYSTEM ADMINISTRATOR "; } else { $hc="'+\"'\"+\"+hc['$sk']+\"+\"'\"+'"; @@ -1006,7 +919,7 @@ RESULTS } $r->print(< - popwin=open('','popwin','scrollbars=1,width=400,height=200'); + popwin=open('','popwin','scrollbars=1,width=400,height=220'); popwin.focus(); popwin.document.writeln('<'+'html>'); popwin.document.writeln('<'+'head>'); @@ -1034,11 +947,11 @@ RESULTS $grid '<'+'br />'+ 'Server details '+ - '<'+'input type="text" size="25" name="sdetails"'+ + '<'+'input type="text" size="35" name="sdetails"'+ ' value="" />'+ '<'+'br />'+ ' <'+'input type="button" name="button"'+ - ' value="abort search and view current results" '+ + ' value="close this window" '+ ' onClick="javascript:opener.abortsearch()" />'+ ' <'+'input type="button" name="button"'+ ' value="help" onClick="javascript:opener.openhelp()" />'+ @@ -1071,11 +984,7 @@ ENDPOP my $replyfile=''; if ($reply eq 'con_lost') { - $r->print(''. - "\n"); - $r->rflush(); + &popwin_imgupdate($r,$sn,"srvbad.gif"); $bloop--; $orkey{$rkey}=1; } @@ -1087,58 +996,31 @@ ENDPOP my $temp=0; WLOOP: while (1) { if (-e $replyfile && $tflag) { - $r->print(''. - "\n"); - $r->rflush(); - $r->print(''. - "\n"); - $r->rflush(); + &popwin_imgupdate($r,$sn,"srvhalf.gif"); + &popwin_js($r,'popwin.hc["'.$rkey.'"]='. + '"still transferring..."'.';'); $tflag=0; } if (-e "$replyfile.end") { $bloop--; $orkey{$rkey}=1; if (-s $replyfile) { - $r->print(''."\n"); - $r->rflush(); + &popwin_imgupdate($r,$sn,"srvgood.gif"); my $fh=Apache::File->new($replyfile) or ($r->print('ERROR: file '. $replyfile.' cannot be opened') and return OK); @results=<$fh> if $fh; $hitcount{$rkey}=@results+0; - $r->print(''. - "\n"); - $r->rflush(); + &popwin_js($r,'popwin.hc["'.$rkey.'"]='. + $hitcount{$rkey}.';'); $hitcountsum+=$hitcount{$rkey}; - $r->print(''. - "\n"); - $r->rflush(); + &popwin_js($r,'popwin.document.forms.popremain.'. + 'numhits.value='.$hitcountsum.';'); } else { - $r->print(''. - "\n"); - $r->rflush(); - $r->print(''. - "\n"); - $r->rflush(); + &popwin_imgupdate($r,$sn,"srvempty.gif"); + &popwin_js($r,'popwin.hc["'.$rkey.'"]=0;'); } last WLOOP; } @@ -1152,18 +1034,13 @@ ENDPOP sleep 1; $timeremain--; $elapsetime++; - $r->print(''."\n"); - $r->rflush(); + &popwin_js($r,"popwin.document.popremain.". + "elapsetime.value=$elapsetime;"); $temp++; } } - $r->print(''."\n"); - $r->rflush(); + &popwin_js($r,'popwin.document.whirly.'. + 'src="/adm/lonIcons/lonanimend.gif";'); } my $customshow=''; my $extrashow=''; @@ -1242,12 +1119,17 @@ END $compiledresult.=< END - $compiledresult.=< +onClick="javascript:select_data('$titleesc','$url')">
END + } if ($ENV{'form.catalogmode'} eq 'groupsearch') { $fnum+=0; $hash{"pre_${fnum}_link"}=$url; @@ -1333,9 +1215,21 @@ sub detailed_citation_view { Subject: $subject
Keyword(s): $keywords
Notes: $notes
-MIME Type: $mimetag{$mime}
-Language: $language{$lang}
-Copyright/Distribution: $cprtag{$copyright}
+MIME Type: +END + $result.=&Apache::loncommon::filedescription($mime); + $result.=< +Language: +END + $result.=&Apache::loncommon::languagedescription($lang); + $result.=< +Copyright/Distribution: +END + $result.=&Apache::loncommon::copyrightdescription($copyright); + $result.=<

$extrashow

@@ -1351,11 +1245,12 @@ sub summary_view { $notes,$shortabstract,$mime,$lang, $creationdate,$lastrevisiondate,$owner,$copyright, $hostname,$httphost,$extrashow)=@_; + my $cprtag=&Apache::loncommon::copyrightdescription($copyright); my $result=<$author
$title
$owner -- $lastrevisiondate
-$cprtag{$copyright}
+$cprtag
$extrashow

END @@ -1368,6 +1263,9 @@ sub fielded_format_view { $notes,$shortabstract,$mime,$lang, $creationdate,$lastrevisiondate,$owner,$copyright, $hostname,$httphost,$extrashow)=@_; + my $mimetag=&Apache::loncommon::filedescription($mime); + my $language=&Apache::loncommon::languagedescription($lang); + my $cprtag=&Apache::loncommon::copyrightdescription($copyright); my $result=<URL: $url
@@ -1376,12 +1274,12 @@ sub fielded_format_view { Subject: $subject
Keyword(s): $keywords
Notes: $notes
-MIME Type: $mimetag{$mime}
-Language: $language{$lang}
+MIME Type: $mimetag
+Language: $language
Creation Date: $creationdate
Last Revision Date: $lastrevisiondate
Publisher/Owner: $owner
-Copyright/Distribution: $cprtag{$copyright}
+Copyright/Distribution: $cprtag
Repository Location: $hostname
Abstract: $shortabstract
$extrashow @@ -1396,6 +1294,9 @@ sub xml_sgml_view { $notes,$shortabstract,$mime,$lang, $creationdate,$lastrevisiondate,$owner,$copyright, $hostname,$httphost,$extrashow)=@_; + my $cprtag=&Apache::loncommon::copyrightdescription($copyright); + my $mimetag=&Apache::loncommon::filedescription($mime); + my $language=&Apache::loncommon::languagedescription($lang); my $result=< <LonCapaResource> @@ -1407,18 +1308,18 @@ sub xml_sgml_view { <notes>$notes</notes> <mimeInfo> <mime>$mime</mime> -<mimetag>$mimetag{$mime}</mimetag> +<mimetag>$mimetag</mimetag> </mimeInfo> <languageInfo> <language>$lang</language> -<languagetag>$language{$lang}</languagetag> +<languagetag>$language</languagetag> </languageInfo> <creationdate>$creationdate</creationdate> <lastrevisiondate>$lastrevisiondate</lastrevisiondate> <owner>$owner</owner> <copyrightInfo> <copyright>$copyright</copyright> -<copyrighttag>$cprtag{$copyright}</copyrighttag> +<copyrighttag>$cprtag</copyrighttag> </copyrightInfo> <repositoryLocation>$hostname</repositoryLocation> <shortabstract>$shortabstract</shortabstract> @@ -1518,6 +1419,27 @@ sub start_fresh_session { } } +# ----------------------------------------------- send javascript to popwin +sub popwin_js { + # Print javascript out to popwin, but make sure we dont generate + # any javascript errors in doing so. + my ($r,$text) = @_; + $r->print(<<"END"); + +END + $r->rflush(); +} + +sub popwin_imgupdate { + my ($r,$imgnum,$icon) = @_; + &popwin_js($r,'popwin.document.img'.$imgnum.'.'. + 'src="/adm/lonIcons/'.$icon.'";'); +} + 1; __END__ @@ -1553,18 +1475,6 @@ This routine is only run once after comp =item * -Initializes %language hash table. - -=item * - -Initializes %cprtag hash table (for copyright.tab). - -=item * - -Initializes %mimetag hash table (for filetypes.tab). - -=item * - Initializes %hostdomains and hostips hash table (for hosts.tab). =back