--- loncom/interface/lonindexcourse.pm 2011/12/25 20:41:53 1.2
+++ loncom/interface/lonindexcourse.pm 2025/02/26 23:46:22 1.7
@@ -1,7 +1,7 @@
# The LearningOnline Network with CAPA
# Index Course
#
-# $Id: lonindexcourse.pm,v 1.2 2011/12/25 20:41:53 raeburn Exp $
+# $Id: lonindexcourse.pm,v 1.7 2025/02/26 23:46:22 raeburn Exp $
#
# Copyright Michigan State University Board of Trustees
#
@@ -70,14 +70,21 @@ sub course_index {
%alreadyseen=();
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);
- my %newwords=&checkonthis($r,$1,$hash{$_},0,&Apache::lonnet::gettitle($symb),
+ my $symb=&make_symb($rid);
+ my %newwords=&checkonthis($r,$rid,$hash{$key},0,&Apache::lonnet::gettitle($symb),
$symb);
}
}
@@ -86,21 +93,24 @@ sub course_index {
# Output
$r->print(&Apache::loncommon::start_data_table());
my $currentchar='';
+ my $colheader = ''.&mt('Resource(s)').' ';
+ &Apache::loncommon::set_data_table_count(1);
foreach my $lword (sort(keys(%indexhash))) {
unless ($lword=~/\w/) { next; }
if ($lword=~/^\d+$/) { next; }
my $firstchar=substr($lword,0,1);
if ($currentchar ne $firstchar) {
$r->print(&Apache::loncommon::start_data_table_header_row().
- '
'.$firstchar.' | | '.&Apache::loncommon::end_data_table_header_row());
+ ''.$firstchar.' | '.$colheader.' | '.
+ &Apache::loncommon::end_data_table_header_row()."\n");
$currentchar=$firstchar;
}
- $r->print("\n".&Apache::loncommon::start_data_table_row()."$lword | ");
+ $r->print("\n".&Apache::loncommon::continue_data_table_row()." | $lword | ");
foreach my $href (split(/\,/,$indexhash{$lword})) {
unless ($href) { next; }
$r->print(' '.$indextitles{$href}.'');
}
- $r->print(" | ".&Apache::loncommon::start_data_table_row());
+ $r->print(''.&Apache::loncommon::end_data_table_row());
}
$r->print(&Apache::loncommon::end_data_table());
}
@@ -136,9 +146,9 @@ 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,'');
+ foreach my $item (split(/\,/,$dependencies)) {
+ if (($item =~ /^\/res\//) && (!$alreadyseen{$id})) {
+ &checkonthis($r,$id,$item,$level+1,'');
}
}
}
@@ -164,7 +174,26 @@ sub handler {
text => "$crstype Index"});
$r->print(&Apache::lonhtmlcommon::breadcrumbs("$crstype Index"));
&Apache::lonnavdisplay::startContentScreen($r,'courseindex');
- &course_index($r);
+ 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('index',$clientip,$cnum,$cdom);
+ if ($blocked) {
+ my $checkrole = "cm./$cdom/$cnum";
+ if ($env{'request.course.sec'} ne '') {
+ $checkrole .= "/$env{'request.course.sec'}";
+ }
+ if ((&Apache::lonnet::allowed('evb',undef,undef,$checkrole)) &&
+ ($env{'request.role'} !~ m{^st\./$cdom/$cnum})) {
+ undef($blocked);
+ }
+ }
+ if ($blocked) {
+ $r->print($blocktext);
+ } else {
+ &course_index($r);
+ }
&Apache::lonnavdisplay::endContentScreen($r);
$r->print(&Apache::loncommon::end_page());
return OK;