Annotation of loncom/interface/lonindexcourse.pm, revision 1.3

1.1       www         1: # The LearningOnline Network with CAPA
                      2: # Index Course
                      3: #
1.3     ! raeburn     4: # $Id: lonindexcourse.pm,v 1.2 2011/12/25 20:41:53 raeburn Exp $
1.1       www         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;
1.2       raeburn    44: use Apache::lonnavdisplay();
1.1       www        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)) {
1.3     ! raeburn    73:         foreach my $key (sort(keys(%hash))) {
        !            74:             last if ($c->aborted());
        !            75:             if ($key =~ /^src\_(.+)$/) {
        !            76:                 my $rid = $1;
        !            77:                 if ($hash{'randomout_'.$rid} & !$env{'request.role.adv'}) {
1.1       www        78:                     next;
                     79:                 }
1.3     ! raeburn    80:                 my $symb=&make_symb($rid);
        !            81:                 my %newwords=&checkonthis($r,$rid,$hash{$key},0,&Apache::lonnet::gettitle($symb),
1.1       www        82:                              $symb);
                     83:             }
                     84:         }
                     85:         untie(%hash);
                     86:     }
                     87: # Output
                     88:     $r->print(&Apache::loncommon::start_data_table());
                     89:     my $currentchar='';
                     90:     foreach my $lword (sort(keys(%indexhash))) {
                     91:        unless ($lword=~/\w/) { next; }
                     92:        if ($lword=~/^\d+$/) { next; }
                     93:        my $firstchar=substr($lword,0,1);
                     94:        if ($currentchar ne $firstchar) {
                     95:           $r->print(&Apache::loncommon::start_data_table_header_row().
                     96:                     '<th>'.$firstchar.'</th><th>&nbsp;</th>'.&Apache::loncommon::end_data_table_header_row());
                     97:           $currentchar=$firstchar;
                     98:        }
                     99:        $r->print("\n".&Apache::loncommon::start_data_table_row()."<td>$lword</td><td>");
                    100:        foreach my $href (split(/\,/,$indexhash{$lword})) {
                    101:            unless ($href) { next; }
                    102:            $r->print(' &nbsp; <a href="'.$href.'">'.$indextitles{$href}.'</a>');
                    103:        }
                    104:        $r->print("</td>".&Apache::loncommon::start_data_table_row());
                    105:     }
                    106:     $r->print(&Apache::loncommon::end_data_table());
                    107: }
                    108: 
                    109: # =============================== This pulls up a resource and its dependencies
                    110: 
                    111: sub checkonthis {
                    112:     my ($r,$id,$url,$level,$title,$symb)=@_;
                    113:     $alreadyseen{$id}=1;
                    114:     if (&Apache::loncommon::connection_aborted($r)) { return; }
                    115:     $r->rflush();
                    116: 
                    117:     my $result='';
                    118:     if ($env{'request.role.adv'} || !$hash{'encrypted_'.$id}) {
                    119:         $result=&Apache::lonnet::metadata($url,'subject').','.
                    120:                 &Apache::lonnet::metadata($url,'keywords');
                    121:     }
                    122:     $result=~s/\s+/\,/gs;
                    123:     my $href=$url;
                    124:     if ($hash{'encrypted_'.$id} && !$env{'request.role.adv'}) {
                    125:         $href=&Apache::lonenc::encrypted($href)
                    126:                .'?symb='.&Apache::lonenc::encrypted($symb);
                    127:     } else {
                    128:         $href.='?symb='.&escape($symb);
                    129:     }
                    130:     foreach my $word (split(/\,/,$result)) {
                    131:         unless ($word) { next; }
                    132:         $indexhash{lc($word)}.=','.$href;
                    133:         $indextitles{$href}=($title?substr($title,0,10):'').' ...';
                    134:     }
                    135:     
                    136:     $r->rflush();
                    137: # Check also the dependencies of this one
                    138:     my $dependencies=
                    139:                 &Apache::lonnet::metadata($url,'dependencies');
1.3     ! raeburn   140:     foreach my $item (split(/\,/,$dependencies)) {
        !           141:        if (($item =~ /^\/res\//) && (!$alreadyseen{$id})) {
        !           142:           &checkonthis($r,$id,$item,$level+1,'');
1.1       www       143:        }
                    144:     }
                    145: }
                    146: 
                    147: sub untiehash {
                    148:     if (tied(%hash)) {
                    149:         untie(%hash);
                    150:     }
                    151: }
                    152: 
                    153: sub handler {
                    154:     my $r = shift;
                    155:     &Apache::loncommon::content_type($r,'text/html');
                    156:     $r->send_http_header;
                    157:     if ($r->header_only) { return OK; }
                    158: 
                    159:     my $crstype = &Apache::loncommon::course_type();
                    160:     &Apache::loncommon::get_unprocessed_cgi($ENV{'QUERY_STRING'},['phase']);
                    161:     $r->print(&Apache::loncommon::start_page("$crstype Index"));
                    162:     &Apache::lonhtmlcommon::clear_breadcrumbs();
                    163:     &Apache::lonhtmlcommon::add_breadcrumb(
                    164:             {   href => '/adm/indexcourse',
                    165:                 text => "$crstype Index"});
                    166:     $r->print(&Apache::lonhtmlcommon::breadcrumbs("$crstype Index"));
1.2       raeburn   167:     &Apache::lonnavdisplay::startContentScreen($r,'courseindex');
1.1       www       168:     &course_index($r);
1.2       raeburn   169:     &Apache::lonnavdisplay::endContentScreen($r);
1.1       www       170:     $r->print(&Apache::loncommon::end_page());
                    171:     return OK;
                    172: }
                    173: 
                    174: 1;

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