--- loncom/interface/lonsearchcourse.pm 2020/09/22 12:19:15 1.6
+++ loncom/interface/lonsearchcourse.pm 2024/04/16 21:09:14 1.14
@@ -1,7 +1,7 @@
# The LearningOnline Network with CAPA
# Search Course
#
-# $Id: lonsearchcourse.pm,v 1.6 2020/09/22 12:19:15 raeburn Exp $
+# $Id: lonsearchcourse.pm,v 1.14 2024/04/16 21:09:14 raeburn Exp $
#
# Copyright Michigan State University Board of Trustees
#
@@ -123,6 +123,11 @@ sub course_search {
my $discuss=$env{'form.crsdiscuss'};
my @allwords=($search_string,@New_Words);
$totalfound=0;
+ my $target = 'cat';
+ if ((($env{'request.lti.login'}) && ($env{'request.lti.target'} eq 'iframe')) ||
+ (($env{'request.deeplink.login'}) && ($env{'request.deeplink.target'} eq '_self'))) {
+ $target = '_self';
+ }
$r->print(
'
'.
@@ -133,15 +138,22 @@ sub course_search {
my $c=$r->connection;
if (tie(%hash,'GDBM_File',$env{'request.course.fn'}.".db",
&GDBM_READER(),0640)) {
- foreach (sort(keys(%hash))) {
- if ($c->aborted()) { last; }
- if (($_=~/^src\_(.+)$/)) {
- if ($hash{'randomout_'.$1} & !$env{'request.role.adv'}) {
- next;
+ foreach my $key (sort(keys(%hash))) {
+ last if ($c->aborted());
+ if ($key =~ /^src\_(.+)$/) {
+ my $rid = $1;
+ unless ($env{'request.role.adv'}) {
+ next if ($hash{'randomout_'.$rid} || $hash{'deeplinkout_'.$rid});
+ if (!$env{'request.deeplink.login'} && $hash{'deeplinkonly_'.$rid}) {
+ my ($value) = map { &unescape($_); } split(/:/,$hash{'deeplinkonly_'.$rid});
+ my ($state,$others,$listed) = split(/,/,$value);
+ next if (($state eq 'only') &&
+ (($listed eq 'absent') || ($listed eq 'grades')));
+ }
}
- my $symb=&make_symb($1);
- &checkonthis($r,$1,$hash{$_},0,&Apache::lonnet::gettitle($symb),
- $fulltext,$symb,@allwords);
+ my $symb=&make_symb($rid);
+ &checkonthis($r,$rid,$hash{$key},0,&Apache::lonnet::gettitle($symb),
+ $fulltext,$symb,$target,@allwords);
}
}
untie(%hash);
@@ -213,7 +225,7 @@ sub course_search {
}
$url .= &escape($resource->symb());
my $title = $resource->compTitle();
- $r->print('
'.
+ $r->print('
'.
($title?$title:$url).' - '.
$disctype.'
');
$totaldiscussions++;
@@ -233,7 +245,7 @@ sub course_search {
# =============================== This pulls up a resource and its dependencies
sub checkonthis {
- my ($r,$id,$url,$level,$title,$fulltext,$symb,@allwords)=@_;
+ my ($r,$id,$url,$level,$title,$fulltext,$symb,$target,@allwords)=@_;
$alreadyseen{$id}=1;
if (&Apache::loncommon::connection_aborted($r)) { return; }
$r->rflush();
@@ -261,12 +273,20 @@ sub checkonthis {
}
my $href=$url;
if ($hash{'encrypted_'.$id} && !$env{'request.role.adv'}) {
- $href=&Apache::lonenc::encrypted($href)
- .'?symb='.&Apache::lonenc::encrypted($symb);
+ $href=&Apache::lonenc::encrypted($href);
+ if ($url =~ /\.sequence$/) {
+ $href .= '?navmap=1';
+ } else {
+ $href .= '?symb='.&Apache::lonenc::encrypted($symb);
+ }
} else {
- $href.='?symb='.&escape($symb);
+ if ($href =~ /\.sequence$/) {
+ $href .= '?navmap=1';
+ } else {
+ $href .= '?symb='.&escape($symb);
+ }
}
- $r->print(''.($title?$title:$url).
+ $r->print(''.($title?$title:$url).
'
');
$totalfound++;
} elsif ($fulltext) {
@@ -276,18 +296,18 @@ sub checkonthis {
# Check also the dependencies of this one
my $dependencies=
&Apache::lonnet::metadata($url,'dependencies');
- foreach (split(/\,/,$dependencies)) {
- if (($_=~/^\/res\//) && (!$alreadyseen{$id})) {
- &checkonthis($r,$id,$_,$level+1,'',$fulltext,undef,@allwords);
+ foreach my $item (split(/\,/,$dependencies)) {
+ if (($item =~ /^\/res\//) && (!$alreadyseen{$id})) {
+ &checkonthis($r,$id,$item,$level+1,'',$fulltext,undef,$target,@allwords);
}
}
}
sub checkwords {
my ($result,$applies,@allwords) = @_;
- foreach (@allwords) {
- if ($_=~/\w/) {
- if ($result=~/$_/si) {
+ foreach my $word (@allwords) {
+ if ($word =~ /\w/) {
+ if ($result =~ /$word/si) {
$applies++;
}
}
@@ -331,8 +351,9 @@ sub handler {
&Apache::lonnavdisplay::startContentScreen($r,'coursesearch');
my $cdom = $env{'course.'.$env{'request.course.id'}.'.domain'};
my $cnum = $env{'course.'.$env{'request.course.id'}.'.num'};
+ my $clientip = &Apache::lonnet::get_requestor_ip($r);
my ($blocked,$blocktext) =
- &Apache::loncommon::blocking_status('search',$cnum,$cdom);
+ &Apache::loncommon::blocking_status('search',$clientip,$cnum,$cdom);
if ($blocked) {
my $checkrole = "cm./$cdom/$cnum";
if ($env{'request.course.sec'} ne '') {