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