# The LearningOnline Network with CAPA # Index Course # # $Id: lonindexcourse.pm,v 1.2 2011/12/25 20:41:53 raeburn Exp $ # # Copyright Michigan State University Board of Trustees # # This file is part of the LearningOnline Network with CAPA (LON-CAPA). # # LON-CAPA is free software; you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by # the Free Software Foundation; either version 2 of the License, or # (at your option) any later version. # # LON-CAPA is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details. # # You should have received a copy of the GNU General Public License # along with LON-CAPA; if not, write to the Free Software # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA # # /home/httpd/html/adm/gpl.txt # # http://www.lon-capa.org/ # ############################################################################### ############################################################################### package Apache::lonindexcourse; use strict; use Apache::Constants qw(:common :http); use Apache::lonnet; use GDBM_File; use Apache::loncommon(); use Apache::lonmeta; use Apache::lonhtmlcommon; use Apache::lonlocal; use LONCAPA::lonmetadata(); use HTML::Entities(); use Apache::lonnavmaps; use Apache::lonnavdisplay(); use Apache::lonindexer(); use LONCAPA; # Variables For course search my %alreadyseen; my %hash; my %indexhash=(); my %indextitles=(); 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_index { my $r=shift; $r->rflush(); # ======================================================= Go through the course my $c=$r->connection; %indexhash=(); %indextitles=(); %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; } my $symb=&make_symb($1); my %newwords=&checkonthis($r,$1,$hash{$_},0,&Apache::lonnet::gettitle($symb), $symb); } } untie(%hash); } # Output $r->print(&Apache::loncommon::start_data_table()); my $currentchar=''; 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()); $currentchar=$firstchar; } $r->print("\n".&Apache::loncommon::start_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()); } # =============================== This pulls up a resource and its dependencies sub checkonthis { my ($r,$id,$url,$level,$title,$symb)=@_; $alreadyseen{$id}=1; if (&Apache::loncommon::connection_aborted($r)) { return; } $r->rflush(); my $result=''; if ($env{'request.role.adv'} || !$hash{'encrypted_'.$id}) { $result=&Apache::lonnet::metadata($url,'subject').','. &Apache::lonnet::metadata($url,'keywords'); } $result=~s/\s+/\,/gs; my $href=$url; if ($hash{'encrypted_'.$id} && !$env{'request.role.adv'}) { $href=&Apache::lonenc::encrypted($href) .'?symb='.&Apache::lonenc::encrypted($symb); } else { $href.='?symb='.&escape($symb); } foreach my $word (split(/\,/,$result)) { unless ($word) { next; } $indexhash{lc($word)}.=','.$href; $indextitles{$href}=($title?substr($title,0,10):'').' ...'; } $r->rflush(); # 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,''); } } } sub untiehash { if (tied(%hash)) { untie(%hash); } } sub handler { my $r = shift; &Apache::loncommon::content_type($r,'text/html'); $r->send_http_header; if ($r->header_only) { return OK; } my $crstype = &Apache::loncommon::course_type(); &Apache::loncommon::get_unprocessed_cgi($ENV{'QUERY_STRING'},['phase']); $r->print(&Apache::loncommon::start_page("$crstype Index")); &Apache::lonhtmlcommon::clear_breadcrumbs(); &Apache::lonhtmlcommon::add_breadcrumb( { href => '/adm/indexcourse', text => "$crstype Index"}); $r->print(&Apache::lonhtmlcommon::breadcrumbs("$crstype Index")); &Apache::lonnavdisplay::startContentScreen($r,'courseindex'); &course_index($r); &Apache::lonnavdisplay::endContentScreen($r); $r->print(&Apache::loncommon::end_page()); return OK; } 1;