File:  [LON-CAPA] / loncom / interface / lonindexcourse.pm
Revision 1.2: download - view: text, annotated - select for diffs
Sun Dec 25 20:41:53 2011 UTC (12 years, 3 months ago) by raeburn
Branches: MAIN
CVS tags: HEAD, BZ4492-merge, BZ4492-feature_horizontal_radioresponse
Changes to improve usability for Course Contents and Content Editor.
- Separate "editor" tabs (Content Editor && Supplemental Content Editor) from
  "display" tabs (Main Content, Supplemental Content, Content Search, Content Index).
- Replace "Edit Content" link on "Course Contents" page (used to jump directly
  to editing specific folder) with icon, to reduce clutter.
- "Back to Overview" link on editor pages to jump directly to corresponding
  location on "display" pages.
- CC and student roles have same tabs in "display" of Contents
- New URL: "/adm/supplemental" for supplemental contents when displaying
  (as CC or student).
- Supplemental Course Content breadcrumbs do not need link to course as first
  item.
- Functions menu in Supplemental Course Content includes "Folder Editor" link
  to jump to editor.
- Do not use style: "LC_current_location" when location is a folder.

# 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().
                    '<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::lonnavdisplay::startContentScreen($r,'courseindex');
    &course_index($r);
    &Apache::lonnavdisplay::endContentScreen($r);
    $r->print(&Apache::loncommon::end_page());
    return OK;
}

1;

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