[LON-CAPA-cvs] cvs: loncom / loncapa_apache.conf /interface londocs.pm lonindexcourse.pm doc/loncapafiles loncapafiles.lpml

www www@source.lon-capa.org
Tue, 18 Jan 2011 00:22:02 -0000


This is a MIME encoded message

--www1295310122
Content-Type: text/plain

www		Tue Jan 18 00:22:02 2011 EDT

  Added files:                 
    /loncom/interface	lonindexcourse.pm 

  Modified files:              
    /doc/loncapafiles	loncapafiles.lpml 
    /loncom	loncapa_apache.conf 
    /loncom/interface	londocs.pm 
  Log:
  Bug #3120: NAV through indexing
  
  
--www1295310122
Content-Type: text/plain
Content-Disposition: attachment; filename="www-20110118002202.txt"

Index: doc/loncapafiles/loncapafiles.lpml
diff -u doc/loncapafiles/loncapafiles.lpml:1.724 doc/loncapafiles/loncapafiles.lpml:1.725
--- doc/loncapafiles/loncapafiles.lpml:1.724	Mon Jan 17 20:17:55 2011
+++ doc/loncapafiles/loncapafiles.lpml	Tue Jan 18 00:21:52 2011
@@ -2,7 +2,7 @@
  "http://lpml.sourceforge.net/DTD/lpml.dtd">
 <!-- loncapafiles.lpml -->
 
-<!-- $Id: loncapafiles.lpml,v 1.724 2011/01/17 20:17:55 www Exp $ -->
+<!-- $Id: loncapafiles.lpml,v 1.725 2011/01/18 00:21:52 www Exp $ -->
 
 <!--
 
@@ -4652,6 +4652,15 @@
 <status>works/unverified</status>
 </file>
 <file>
+<source>loncom/interface/lonindexcourse.pm</source>
+<target dist='default'>home/httpd/lib/perl/Apache/lonindexcourse.pm</target>
+<categoryname>handler</categoryname>
+<description>
+Course/community Indexer
+</description>
+<status>works/unverified</status>
+</file>
+<file>
 <source>loncom/interface/lonmysql.pm</source>
 <target dist='default'>home/httpd/lib/perl/Apache/lonmysql.pm</target>
 <categoryname>handler</categoryname>
Index: loncom/loncapa_apache.conf
diff -u loncom/loncapa_apache.conf:1.200 loncom/loncapa_apache.conf:1.201
--- loncom/loncapa_apache.conf:1.200	Mon Jan 17 20:17:58 2011
+++ loncom/loncapa_apache.conf	Tue Jan 18 00:21:57 2011
@@ -1,7 +1,7 @@
 ##
 ## loncapa_apache.conf -- Apache HTTP LON-CAPA configuration file
 ##
-## $Id: loncapa_apache.conf,v 1.200 2011/01/17 20:17:58 www Exp $
+## $Id: loncapa_apache.conf,v 1.201 2011/01/18 00:21:57 www Exp $
 ##
 
 #
@@ -478,6 +478,15 @@
 ErrorDocument     500 /adm/errorhandler
 </Location>
 
+<Location /adm/indexcourse>
+AuthType LONCAPA
+Require valid-user
+PerlAuthzHandler       Apache::lonacc
+SetHandler perl-script
+PerlHandler Apache::lonindexcourse
+ErrorDocument     403 /adm/login
+ErrorDocument     500 /adm/errorhandler
+</Location>
 
 <Location /adm/statistics>
 AuthType LONCAPA
Index: loncom/interface/londocs.pm
diff -u loncom/interface/londocs.pm:1.449 loncom/interface/londocs.pm:1.450
--- loncom/interface/londocs.pm:1.449	Mon Jan 17 20:18:02 2011
+++ loncom/interface/londocs.pm	Tue Jan 18 00:22:02 2011
@@ -1,7 +1,7 @@
 # The LearningOnline Network
 # Documents
 #
-# $Id: londocs.pm,v 1.449 2011/01/17 20:18:02 www Exp $
+# $Id: londocs.pm,v 1.450 2011/01/18 00:22:02 www Exp $
 #
 # Copyright Michigan State University Board of Trustees
 #
@@ -2648,6 +2648,7 @@
                '><a href="/adm/coursedocs?forcestandard=1"><b>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;'.&mt('Content Editor').'&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</b></a></li>');
     }
     $r->print('<li'.(($mode eq 'coursesearch')?' class="active"':'').'><a href="/adm/searchcourse"><b>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;'.&mt('Content Search').'&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</b></a></li>');
+    $r->print('<li'.(($mode eq 'courseindex')?' class="active"':'').'><a href="/adm/indexcourse"><b>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;'.&mt('Content Index').'&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</b></a></li>');
     $r->print('<li '.(($mode eq 'supdocs')?' class="active"':'').
            '><a href="/adm/coursedocs?forcesupplement=1"><b>'.&mt('Supplemental Documents').'</b></a></li>');
     $r->print('</ul>');

Index: loncom/interface/lonindexcourse.pm
+++ loncom/interface/lonindexcourse.pm
# The LearningOnline Network with CAPA
# Index Course
#
# $Id: lonindexcourse.pm,v 1.1 2011/01/18 00:22:02 www 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::londocs();
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().
                    '<th>'.$firstchar.'</th><th>&nbsp;</th>'.&Apache::loncommon::end_data_table_header_row());
          $currentchar=$firstchar;
       }
       $r->print("\n".&Apache::loncommon::start_data_table_row()."<td>$lword</td><td>");
       foreach my $href (split(/\,/,$indexhash{$lword})) {
           unless ($href) { next; }
           $r->print(' &nbsp; <a href="'.$href.'">'.$indextitles{$href}.'</a>');
       }
       $r->print("</td>".&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::londocs::startContentScreen($r,'courseindex');
    &course_index($r);
    &Apache::londocs::endContentScreen($r);
    $r->print(&Apache::loncommon::end_page());
    return OK;
}

1;

--www1295310122--