File:  [LON-CAPA] / loncom / interface / lonindexcourse.pm
Revision 1.7: download - view: text, annotated - select for diffs
Wed Feb 26 23:46:22 2025 UTC (4 months ago) by raeburn
Branches: MAIN
CVS tags: version_2_12_X, HEAD
- WCAG 2 compliance.

    1: # The LearningOnline Network with CAPA
    2: # Index Course
    3: #
    4: # $Id: lonindexcourse.pm,v 1.7 2025/02/26 23:46:22 raeburn Exp $
    5: #
    6: # Copyright Michigan State University Board of Trustees
    7: #
    8: # This file is part of the LearningOnline Network with CAPA (LON-CAPA).
    9: #
   10: # LON-CAPA is free software; you can redistribute it and/or modify
   11: # it under the terms of the GNU General Public License as published by
   12: # the Free Software Foundation; either version 2 of the License, or
   13: # (at your option) any later version.
   14: #
   15: # LON-CAPA is distributed in the hope that it will be useful,
   16: # but WITHOUT ANY WARRANTY; without even the implied warranty of
   17: # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
   18: # GNU General Public License for more details.
   19: #
   20: # You should have received a copy of the GNU General Public License
   21: # along with LON-CAPA; if not, write to the Free Software
   22: # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
   23: #
   24: # /home/httpd/html/adm/gpl.txt
   25: #
   26: # http://www.lon-capa.org/
   27: #
   28: ###############################################################################
   29: ###############################################################################
   30: 
   31: package Apache::lonindexcourse;
   32: 
   33: use strict;
   34: use Apache::Constants qw(:common :http);
   35: use Apache::lonnet;
   36: use GDBM_File;
   37: use Apache::loncommon();
   38: use Apache::lonmeta;
   39: use Apache::lonhtmlcommon;
   40: use Apache::lonlocal;
   41: use LONCAPA::lonmetadata();
   42: use HTML::Entities();
   43: use Apache::lonnavmaps;
   44: use Apache::lonnavdisplay();
   45: use Apache::lonindexer();
   46: use LONCAPA;
   47: 
   48: # Variables For course search
   49: my %alreadyseen;
   50: my %hash;
   51: my %indexhash=();
   52: my %indextitles=();
   53: 
   54: sub make_symb {
   55:     my ($id)=@_;
   56:     my ($mapid,$resid)=split(/\./,$id);
   57:     my $map=$hash{'map_id_'.$mapid};
   58:     my $res=$hash{'src_'.$id};
   59:     my $symb=&Apache::lonnet::encode_symb($map,$resid,$res);
   60:     return $symb;
   61: }
   62: 
   63: sub course_index {
   64:     my $r=shift;
   65:     $r->rflush();
   66: # ======================================================= Go through the course
   67:     my $c=$r->connection;
   68:     %indexhash=();
   69:     %indextitles=();
   70:     %alreadyseen=();
   71:     if (tie(%hash,'GDBM_File',$env{'request.course.fn'}.".db",
   72:             &GDBM_READER(),0640)) {
   73:         foreach my $key (sort(keys(%hash))) {
   74:             last if ($c->aborted());
   75:             if ($key =~ /^src\_(.+)$/) {
   76:                 my $rid = $1;
   77:                 unless ($env{'request.role.adv'}) {
   78:                     next if ($hash{'randomout_'.$rid} || $hash{'deeplinkout_'.$rid});
   79:                     if (!$env{'request.deeplink.login'} && $hash{'deeplinkonly_'.$rid}) {
   80:                         my ($value) = map { &unescape($_); } split(/:/,$hash{'deeplinkonly_'.$rid});
   81:                         my ($state,$others,$listed) = split(/,/,$value);
   82:                         next if (($state eq 'only') &&
   83:                                  (($listed eq 'absent') || ($listed eq 'grades')));
   84:                     }
   85:                 }
   86:                 my $symb=&make_symb($rid);
   87:                 my %newwords=&checkonthis($r,$rid,$hash{$key},0,&Apache::lonnet::gettitle($symb),
   88:                              $symb);
   89:             }
   90:         }
   91:         untie(%hash);
   92:     }
   93: # Output
   94:     $r->print(&Apache::loncommon::start_data_table());
   95:     my $currentchar='';
   96:     my $colheader = '<span class="LC_visually_hidden">'.&mt('Resource(s)').'</span>&nbsp;';
   97:     &Apache::loncommon::set_data_table_count(1);
   98:     foreach my $lword (sort(keys(%indexhash))) {
   99:        unless ($lword=~/\w/) { next; }
  100:        if ($lword=~/^\d+$/) { next; }
  101:        my $firstchar=substr($lword,0,1);
  102:        if ($currentchar ne $firstchar) {
  103:           $r->print(&Apache::loncommon::start_data_table_header_row().
  104:                     '<th>'.$firstchar.'</th><th>'.$colheader.'</th>'.
  105:                     &Apache::loncommon::end_data_table_header_row()."\n");
  106:           $currentchar=$firstchar;
  107:        }
  108:        $r->print("\n".&Apache::loncommon::continue_data_table_row()."<td>$lword</td><td>");
  109:        foreach my $href (split(/\,/,$indexhash{$lword})) {
  110:            unless ($href) { next; }
  111:            $r->print(' &nbsp; <a href="'.$href.'">'.$indextitles{$href}.'</a>');
  112:        }
  113:        $r->print('</td>'.&Apache::loncommon::end_data_table_row());
  114:     }
  115:     $r->print(&Apache::loncommon::end_data_table());
  116: }
  117: 
  118: # =============================== This pulls up a resource and its dependencies
  119: 
  120: sub checkonthis {
  121:     my ($r,$id,$url,$level,$title,$symb)=@_;
  122:     $alreadyseen{$id}=1;
  123:     if (&Apache::loncommon::connection_aborted($r)) { return; }
  124:     $r->rflush();
  125: 
  126:     my $result='';
  127:     if ($env{'request.role.adv'} || !$hash{'encrypted_'.$id}) {
  128:         $result=&Apache::lonnet::metadata($url,'subject').','.
  129:                 &Apache::lonnet::metadata($url,'keywords');
  130:     }
  131:     $result=~s/\s+/\,/gs;
  132:     my $href=$url;
  133:     if ($hash{'encrypted_'.$id} && !$env{'request.role.adv'}) {
  134:         $href=&Apache::lonenc::encrypted($href)
  135:                .'?symb='.&Apache::lonenc::encrypted($symb);
  136:     } else {
  137:         $href.='?symb='.&escape($symb);
  138:     }
  139:     foreach my $word (split(/\,/,$result)) {
  140:         unless ($word) { next; }
  141:         $indexhash{lc($word)}.=','.$href;
  142:         $indextitles{$href}=($title?substr($title,0,10):'').' ...';
  143:     }
  144:     
  145:     $r->rflush();
  146: # Check also the dependencies of this one
  147:     my $dependencies=
  148:                 &Apache::lonnet::metadata($url,'dependencies');
  149:     foreach my $item (split(/\,/,$dependencies)) {
  150:        if (($item =~ /^\/res\//) && (!$alreadyseen{$id})) {
  151:           &checkonthis($r,$id,$item,$level+1,'');
  152:        }
  153:     }
  154: }
  155: 
  156: sub untiehash {
  157:     if (tied(%hash)) {
  158:         untie(%hash);
  159:     }
  160: }
  161: 
  162: sub handler {
  163:     my $r = shift;
  164:     &Apache::loncommon::content_type($r,'text/html');
  165:     $r->send_http_header;
  166:     if ($r->header_only) { return OK; }
  167: 
  168:     my $crstype = &Apache::loncommon::course_type();
  169:     &Apache::loncommon::get_unprocessed_cgi($ENV{'QUERY_STRING'},['phase']);
  170:     $r->print(&Apache::loncommon::start_page("$crstype Index"));
  171:     &Apache::lonhtmlcommon::clear_breadcrumbs();
  172:     &Apache::lonhtmlcommon::add_breadcrumb(
  173:             {   href => '/adm/indexcourse',
  174:                 text => "$crstype Index"});
  175:     $r->print(&Apache::lonhtmlcommon::breadcrumbs("$crstype Index"));
  176:     &Apache::lonnavdisplay::startContentScreen($r,'courseindex');
  177:     my $cdom = $env{'course.'.$env{'request.course.id'}.'.domain'};
  178:     my $cnum = $env{'course.'.$env{'request.course.id'}.'.num'};
  179:     my $clientip = &Apache::lonnet::get_requestor_ip($r);
  180:     my ($blocked,$blocktext) =
  181:         &Apache::loncommon::blocking_status('index',$clientip,$cnum,$cdom);
  182:     if ($blocked) {
  183:         my $checkrole = "cm./$cdom/$cnum";
  184:         if ($env{'request.course.sec'} ne '') {
  185:             $checkrole .= "/$env{'request.course.sec'}";
  186:         }
  187:         if ((&Apache::lonnet::allowed('evb',undef,undef,$checkrole)) &&
  188:             ($env{'request.role'} !~ m{^st\./$cdom/$cnum})) {
  189:             undef($blocked);
  190:         }
  191:     }
  192:     if ($blocked) {
  193:         $r->print($blocktext);
  194:     } else {
  195:         &course_index($r);
  196:     }
  197:     &Apache::lonnavdisplay::endContentScreen($r);
  198:     $r->print(&Apache::loncommon::end_page());
  199:     return OK;
  200: }
  201: 
  202: 1;

FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>