File:
[LON-CAPA] /
rat /
lonambiguous.pm
Revision
1.16:
download - view:
text,
annotated -
select for diffs
Thu Apr 7 06:56:27 2005 UTC (19 years, 5 months ago) by
albertel
Branches:
MAIN
CVS tags:
version_2_1_2,
version_2_1_1,
version_2_1_0,
version_2_0_X,
version_2_0_99_1,
version_2_0_2,
version_2_0_1,
version_2_0_0,
version_1_99_3,
version_1_99_2,
version_1_99_1_tmcc,
version_1_99_1,
version_1_99_0_tmcc,
version_1_99_0,
HEAD
- ENV -> env
1: # The LearningOnline Network with CAPA
2: # Handler to resolve ambiguous file locations
3: #
4: # $Id: lonambiguous.pm,v 1.16 2005/04/07 06:56:27 albertel Exp $
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: package Apache::lonambiguous;
30:
31: use strict;
32: use Apache::lonnet;
33: use Apache::Constants qw(:common REDIRECT);
34: use GDBM_File;
35: use Apache::loncommon;
36: use Apache::lonlocal;
37:
38: my %bighash;
39:
40: sub cleanup {
41: if (tied(%bighash)){
42: &Apache::lonnet::logthis('Cleanup ambiguous: bighash');
43: unless (untie(%bighash)) {
44: &Apache::lonnet::logthis('Failed cleanup ambiguous: bighash');
45: }
46: }
47: }
48:
49: # ----------------------------------------------------------- Could not resolve
50:
51: sub getlost {
52: my ($r,$errmsg)=@_;
53: $errmsg=&mt($errmsg);
54: &Apache::loncommon::content_type($r,'text/html');
55: $r->send_http_header;
56: $r->print(
57: '<head><title>Unknown Error</title></head>'.
58: &Apache::loncommon::bodytag('Could not handle ambiguous resource reference').
59: $errmsg.
60: '</body></html>');
61: }
62:
63: # ================================================================ Main Handler
64:
65: sub make_symb {
66: my ($id)=@_;
67: my ($mapid,$resid)=split(/\./,$id);
68: my $map=$bighash{'map_id_'.$mapid};
69: my $res=$bighash{'src_'.$id};
70: my $symb=&Apache::lonnet::encode_symb($map,$resid,$res);
71: return $symb;
72: }
73:
74: sub handler {
75: my $r=shift;
76:
77: if ($r->header_only) {
78: &Apache::loncommon::content_type($r,'text/html');
79: $r->send_http_header;
80: return OK;
81: }
82:
83: # ---------------------------------------------------------- Is this selecting?
84:
85: if ($env{'form.selecturl'}) {
86: my $envkey;
87: if (tie(%bighash,'GDBM_File',$env{'request.course.fn'}.'.db',
88: &GDBM_READER(),0640)) {
89: foreach $envkey (keys %env) {
90: if ($envkey=~/^form\.(\d+)\.(\d+)$/) {
91: # ---------------------------------------------------- Update symb and redirect
92: my $mapid=$1;
93: my $resid=$2;
94: my $resurl=$bighash{'src_'.$mapid.'.'.$resid};
95: &Apache::lonnet::symblist($bighash{'map_id_'.$mapid},
96: $resurl => [$resurl,$resid]);
97: untie(%bighash);
98: $r->header_out(Location =>
99: 'http://'.$ENV{'HTTP_HOST'}.$resurl);
100: return REDIRECT;
101: }
102: }
103: untie(%bighash);
104: } else {
105: &getlost($r,'Could not access course structure.');
106: return OK;
107: }
108: }
109:
110: # ---------------------------------------------------------- Do we have a case?
111:
112: my $thisfn;
113: unless (($thisfn=$env{'request.ambiguous'})&&($env{'request.course.fn'})) {
114: &getlost($r,'Could not find information on resource.');
115: return OK;
116: }
117:
118: # ---------------------------------- Should this file have been part of a page?
119:
120: $thisfn=&Apache::lonnet::declutter($thisfn);
121: my %hash;
122: my $syval='';
123:
124: if (tie(%hash,'GDBM_File',$env{'request.course.fn'}.'_symb.db',
125: &GDBM_READER(),0640)) {
126: $syval=$hash{$thisfn};
127: untie(%hash);
128: }
129:
130: # ---------------------------------------------------------- There was an entry
131:
132: if ($syval) {
133: my ($page,undef,$res)=&Apache::lonnet::decode_symb($syval);
134: if ($res eq 'page') {
135: # ----------------------------------- Okay, this should have appeared on a page
136: &Apache::loncommon::content_type($r,'text/html');
137: $r->header_out(Location =>
138: 'http://'.$ENV{'HTTP_HOST'}.
139: &Apache::lonnet::clutter($page));
140: return REDIRECT;
141: } else {
142: # There is not really a problem (???), but cannot go back without endless loop
143: &getlost($r,'The nature of the problem is unclear');
144: return OK;
145: }
146: }
147: # ------------------------------------Encrypted requests go straight to navmaps
148: if ($env{'request.enc'}) {
149: &Apache::loncommon::content_type($r,'text/html');
150: $r->header_out(Location => 'http://'.$ENV{'HTTP_HOST'}.'/adm/navmaps');
151: return REDIRECT;
152: }
153: # ------------------------------------------------ Would be standalone resource
154:
155: if (tie(%bighash,'GDBM_File',$env{'request.course.fn'}.'.db',
156: &GDBM_READER(),0640)) {
157: # ---------------------------------------------- Get ID(s) for current resource
158: my $ids=$bighash{'ids_'.&Apache::lonnet::clutter($thisfn)};
159: if ($ids) {
160: # ------------------------------------------------------------------- Has ID(s)
161: my @possibilities=split(/\,/,$ids);
162: my $couldbe='';
163: foreach (@possibilities) {
164: if ($bighash{'encrypted_'.$_}) { next; }
165: my $symb=&make_symb($_);
166: if (&Apache::lonnet::allowed('bre',$bighash{'src_'.$_},$symb)) {
167: if ($couldbe) {
168: $couldbe.=','.$_;
169: } else {
170: $couldbe=$_;
171: }
172: }
173: }
174: if ($couldbe) {
175: @possibilities=split(/\,/,$couldbe);
176: if ($#possibilities==0) {
177: my $id=$possibilities[0];
178: my $resurl=$bighash{'src_'.$id};
179: my $mapurl=$bighash{'map_id_'.(split(/\./,$id))[0]};
180: my $symb=&make_symb($id);
181: &Apache::loncommon::content_type($r,'text/html');
182: &Apache::lonnet::logthis('http://'.$ENV{'HTTP_HOST'}.$resurl.'?symb='.$symb);
183: $r->header_out(Location =>
184: 'http://'.$ENV{'HTTP_HOST'}.$resurl.'?symb='.$symb);
185: return REDIRECT;
186: }
187: if ($#possibilities>0) {
188: # ----------------------------------------------- Okay, really multiple choices
189: &Apache::loncommon::content_type($r,'text/html');
190: $r->send_http_header;
191: my $bodytag=
192: &Apache::loncommon::bodytag('Pick Instance of Resource');
193: $r->print(<<ENDSTART);
194: <head><title>Choose Location</title></head>
195: $bodytag
196: The resource you had been accessing appears more than once in this course,
197: and LON-CAPA has insufficient session information to determine which instance
198: of the resource you meant.
199: <p>
200: Please click on the instance of the resource you intended to access:
201: </p>
202: <table border="2">
203: <tr><th>Title</th><th>Part of ...</th></tr>
204: ENDSTART
205: map {
206: my $resurl=$bighash{'src_'.$_};
207: my $mapurl=$bighash{'map_id_'.(split(/\./,$_))[0]};
208: my $symb=&make_symb($_);
209: $r->print('<tr><td><a href="'.$resurl.'?symb='.$symb.'">'.
210: &Apache::lonnet::gettitle($symb).
211: '</a></td><td>'.
212: &Apache::lonnet::gettitle($mapurl).' '.
213: '</td></tr>');
214: } @possibilities;
215: $r->print('</table></body></html>');
216: untie(%bighash);
217: return OK;
218: }
219: }
220: }
221: untie(%bighash);
222: }
223:
224: # ------------------------------------ This handler should not have been called
225: &getlost($r,'Invalid call of handler');
226: return OK;
227: }
228:
229: 1;
230: __END__
231:
232:
233:
234:
235:
236:
237:
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>