--- loncom/interface/lonsearchcat.pm 2004/06/28 15:55:09 1.230
+++ loncom/interface/lonsearchcat.pm 2005/02/02 22:02:41 1.237
@@ -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.237 2005/02/02 22:02:41 albertel Exp $
#
# Copyright Michigan State University Board of Trustees
#
@@ -76,6 +76,7 @@ use Apache::lonlocal;
use LONCAPA::lonmetadata();
use HTML::Entities();
use Parse::RecDescent;
+use Apache::lonnavmaps;
######################################################################
######################################################################
@@ -448,12 +449,22 @@ 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');
my $pretty_search_string = ''.$ENV{'form.courseexp'}.'';
my $search_string = $ENV{'form.courseexp'};
my @New_Words;
+ undef(%alreadyseen);
if ($ENV{'form.crsrelated'}) {
($search_string,@New_Words) = &related_version($ENV{'form.courseexp'});
if (@New_Words) {
@@ -463,29 +474,107 @@ sub course_search {
}
}
my $fulltext=$ENV{'form.crsfulltext'};
+ my $discuss=$ENV{'form.crsdiscuss'};
my @allwords=($search_string,@New_Words);
$totalfound=0;
$r->print('
LON-CAPA Course Search'.
- $bodytag.'
'.$pretty_search_string.'
');
+ $bodytag.'
'.$pretty_search_string.'
'.&mt('Course content').':
');
$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);
}
unless ($totalfound) {
- $r->print(''.&mt('No resources found').'.
');
+ $r->print(''.&mt('No matches found in resources').'.
');
}
+
+# Check discussions if requested
+ if ($discuss) {
+ my $totaldiscussions = 0;
+ $r->print('
'.&mt('Discussion postings').':
');
+ my $navmap = Apache::lonnavmaps::navmap->new();
+ my @allres=$navmap->retrieveResources();
+ my %discussiontime = &Apache::lonnet::dump('discussiontimes',
+ $ENV{'course.'.$ENV{'request.course.id'}.'.domain'},
+ $ENV{'course.'.$ENV{'request.course.id'}.'.num'});
+ foreach my $resource (@allres) {
+ my $result = '';
+ my $applies = 0;
+ my $symb = $resource->symb();
+ my $ressymb = $symb;
+ if ($symb =~ m#(___adm/\w+/\w+)/(\d+)/bulletinboard$#) {
+ $ressymb = 'bulletin___'.$2.$1.'/'.$2.'/bulletinboard';
+ unless ($ressymb =~ m#bulletin___\d+___adm/wrapper#) {
+ $ressymb=~s#(bulletin___\d+___)#$1adm/wrapper/#;
+ }
+ }
+ if (defined($discussiontime{$ressymb})) {
+ my %contrib = &Apache::lonnet::restore($ressymb,$ENV{'request.course.id'},
+ $ENV{'course.'.$ENV{'request.course.id'}.'.domain'},
+ $ENV{'course.'.$ENV{'request.course.id'}.'.num'});
+ if ($contrib{'version'}) {
+ for (my $id=1;$id<=$contrib{'version'};$id++) {
+ unless (($contrib{'hidden'}=~/\.$id\./) || ($contrib{'deleted'}=~/\.$id\./)) {
+ if ($contrib{$id.':subject'}) {
+ $result .= $contrib{$id.':subject'};
+ }
+ if ($contrib{$id.':message'}) {
+ $result .= $contrib{$id.':message'};
+ }
+ if ($contrib{$id,':attachmenturl'}) {
+ if ($contrib{$id,':attachmenturl'} =~ m-/([^/]+)$-) {
+ $result .= $1;
+ }
+ }
+ $applies = &checkwords($result,$applies,@allwords);
+ }
+ }
+ }
+ }
+# Does this discussion apply?
+ if ($applies) {
+ my ($map,$ind,$url)=&Apache::lonnet::decode_symb($ressymb);
+ my $disctype = &mt('resource');
+ if ($url =~ m#/bulletinboard$#) {
+ if ($url =~m#^adm/wrapper/adm/.*/bulletinboard$#) {
+ $url =~s#^adm/wrapper##;
+ }
+ $disctype = &mt('bulletin board');
+ } else {
+ $url = '/res/'.$url;
+ }
+ if ($url =~ /\?/) {
+ $url .= '&symb=';
+ } else {
+ $url .= '?symb=';
+ }
+ $url .= &Apache::lonnet::escape($resource->symb());
+ my $title = $resource->compTitle();
+ $r->print('
'.
+ ($title?$title:$url).' - '.$disctype.'
');
+ $totaldiscussions++;
+ } else {
+ $r->print(' .');
+ }
+ }
+ unless ($totaldiscussions) {
+ $r->print(''.&mt('No matches found in postings').'.
');
+ }
+ }
+
# =================================================== Done going through course
$r->print('