[LON-CAPA-cvs] cvs: loncom(version_1_2_X) /interface lonsearchcat.pm
albertel
lon-capa-cvs@mail.lon-capa.org
Wed, 19 Jan 2005 20:22:36 -0000
albertel Wed Jan 19 15:22:36 2005 EDT
Modified files: (Branch: version_1_2_X)
/loncom/interface lonsearchcat.pm
Log:
- backport 1.235
Index: loncom/interface/lonsearchcat.pm
diff -u loncom/interface/lonsearchcat.pm:1.230 loncom/interface/lonsearchcat.pm:1.230.2.1
--- loncom/interface/lonsearchcat.pm:1.230 Mon Jun 28 11:55:09 2004
+++ loncom/interface/lonsearchcat.pm Wed Jan 19 15:22:36 2005
@@ -1,7 +1,7 @@
# The LearningOnline Network with CAPA
# Search Catalog
#
-# $Id: lonsearchcat.pm,v 1.230 2004/06/28 15:55:09 matthew Exp $
+# $Id: lonsearchcat.pm,v 1.230.2.1 2005/01/19 20:22:36 albertel Exp $
#
# Copyright Michigan State University Board of Trustees
#
@@ -444,10 +444,18 @@
{ # Scope the course search to avoid global variables
#
# Variables For course search
-my %alreadyseen;
my %hash;
my $totalfound;
+sub make_symb {
+ my ($id)=@_;
+ my ($mapid,$resid)=split(/\./,$id);
+ my $map=$hash{'map_id_'.$mapid};
+ my $res=$hash{'src_'.$id};
+ my $symb=&Apache::lonnet::encode_symb($map,$resid,$res);
+ return $symb;
+}
+
sub course_search {
my $r=shift;
my $bodytag=&Apache::loncommon::bodytag('Course Search');
@@ -469,16 +477,18 @@
$bodytag.'<hr /><center><font size="+2" face="arial">'.$pretty_search_string.'</font></center><hr />');
$r->rflush();
# ======================================================= Go through the course
- undef %alreadyseen;
- %alreadyseen=();
my $c=$r->connection;
if (tie(%hash,'GDBM_File',$ENV{'request.course.fn'}.".db",
&GDBM_READER(),0640)) {
- foreach (keys %hash) {
+ foreach (sort(keys(%hash))) {
if ($c->aborted()) { last; }
- if (($_=~/^src\_(.+)$/) && (!$alreadyseen{$hash{$_}})) {
- &checkonthis($r,$hash{$_},0,$hash{'title_'.$1},$fulltext,
- @allwords);
+ if (($_=~/^src\_(.+)$/)) {
+ if ($hash{'randomout_'.$1} & !$ENV{'request.role.adv'}) {
+ next;
+ }
+ my $symb=&make_symb($1);
+ &checkonthis($r,$1,$hash{$_},0,&Apache::lonnet::gettitle($symb),
+ $fulltext,$symb,@allwords);
}
}
untie(%hash);
@@ -493,15 +503,20 @@
# =============================== This pulls up a resource and its dependencies
sub checkonthis {
- my ($r,$url,$level,$title,$fulltext,@allwords)=@_;
- $alreadyseen{$url}=1;
+ my ($r,$id,$url,$level,$title,$fulltext,$symb,@allwords)=@_;
$r->rflush();
- my $result=&Apache::lonnet::metadata($url,'title').' '.
- &Apache::lonnet::metadata($url,'subject').' '.
- &Apache::lonnet::metadata($url,'abstract').' '.
- &Apache::lonnet::metadata($url,'keywords');
- if (($url) && ($fulltext)) {
- $result.=&Apache::lonnet::ssi_body($url);
+
+ my $result=$title.' ';
+ if ($ENV{'request.role.adv'} || !$hash{'encrypted_'.$id}) {
+ $result.=&Apache::lonnet::metadata($url,'title').' '.
+ &Apache::lonnet::metadata($url,'subject').' '.
+ &Apache::lonnet::metadata($url,'abstract').' '.
+ &Apache::lonnet::metadata($url,'keywords');
+ }
+ my ($extension)=($url=~/\.(\w+)$/);
+ if (&Apache::loncommon::fileembstyle($extension) eq 'ssi' &&
+ ($url) && ($fulltext)) {
+ $result.=&Apache::lonnet::ssi_body($url.'?symb='.&Apache::lonnet::escape($symb));
}
$result=~s/\s+/ /gs;
my $applies=0;
@@ -518,8 +533,15 @@
for (my $i=0;$i<=$level*5;$i++) {
$r->print(' ');
}
- $r->print('<a href="'.$url.'" target="cat">'.
- ($title?$title:$url).'</a><br />');
+ my $href=$url;
+ if ($hash{'encrypted_'.$id} && !$ENV{'request.role.adv'}) {
+ $href=&Apache::lonenc::encrypted($href)
+ .'?symb='.&Apache::lonenc::encrypted($symb);
+ } else {
+ $href.='?symb='.&Apache::lonnet::escape($symb);
+ }
+ $r->print('<a href="'.$href.'" target="cat">'.($title?$title:$url).
+ '</a><br />');
$totalfound++;
} elsif ($fulltext) {
$r->print(' .');
@@ -529,8 +551,8 @@
my $dependencies=
&Apache::lonnet::metadata($url,'dependencies');
foreach (split(/\,/,$dependencies)) {
- if (($_=~/^\/res\//) && (!$alreadyseen{$_})) {
- &checkonthis($r,$_,$level+1,'',$fulltext,@allwords);
+ if (($_=~/^\/res\//)) {
+ &checkonthis($r,$id,$_,$level+1,'',$fulltext,undef,@allwords);
}
}
}