Annotation of rat/lonambiguous.pm, revision 1.9
1.1 www 1: # The LearningOnline Network with CAPA
2: # Handler to resolve ambiguous file locations
3: #
1.9 ! www 4: # $Id: lonambiguous.pm,v 1.8 2003/01/14 18:47:50 www Exp $
1.4 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: #
1.1 www 28: # (TeX Content Handler
29: #
30: # 05/29/00,05/30,10/11 Gerd Kortemeyer)
31: #
1.3 www 32: # 10/11,10/12,10/16 Gerd Kortemeyer
1.1 www 33:
34: package Apache::lonambiguous;
35:
36: use strict;
37: use Apache::lonnet;
38: use Apache::Constants qw(:common REDIRECT);
39: use GDBM_File;
1.9 ! www 40: use Apache::loncommon;
1.1 www 41:
1.8 www 42: my %bighash;
43:
44: sub cleanup {
45: if (tied(%bighash)){
46: &Apache::lonnet::logthis('Cleanup ambiguous: bighash');
47: unless (untie(%bighash)) {
48: &Apache::lonnet::logthis('Failed cleanup ambiguous: bighash');
49: }
50: }
51: }
1.1 www 52:
53: # ----------------------------------------------------------- Could not resolve
54:
55: sub getlost {
1.2 www 56: my ($r,$errmsg)=@_;
1.1 www 57: $r->content_type('text/html');
58: $r->send_http_header;
1.2 www 59: $r->print(
1.9 ! www 60: '<head><title>Unknown Error</title></head>'.
! 61: &Apache::loncommon::bodytag('Could not handle ambiguous resource reference').
! 62: $errmsg.
1.2 www 63: '</body></html>');
1.1 www 64: }
65:
66: # ================================================================ Main Handler
67:
68: sub handler {
69: my $r=shift;
70:
71: if ($r->header_only) {
72: $r->content_type('text/html');
73: $r->send_http_header;
74: return OK;
75: }
76:
1.2 www 77: # ---------------------------------------------------------- Is this selecting?
1.8 www 78:
1.2 www 79: if ($ENV{'form.selecturl'}) {
80: my $envkey;
81: if (tie(%bighash,'GDBM_File',$ENV{'request.course.fn'}.'.db',
1.5 albertel 82: &GDBM_READER(),0640)) {
1.2 www 83: foreach $envkey (keys %ENV) {
84: if ($envkey=~/^form\.(\d+)\.(\d+)$/) {
1.3 www 85: # ---------------------------------------------------- Update symb and redirect
1.2 www 86: my $mapid=$1;
87: my $resid=$2;
88: my $resurl=$bighash{'src_'.$mapid.'.'.$resid};
89: &Apache::lonnet::symblist($bighash{'map_id_'.$mapid},
90: $resurl => $resid);
1.3 www 91: untie(%bighash);
1.2 www 92: $r->header_out(Location =>
93: 'http://'.$ENV{'HTTP_HOST'}.$resurl);
94: return REDIRECT;
95: }
96: }
97: untie(%bighash);
98: } else {
99: &getlost($r,'Could not access course structure.');
100: return OK;
101: }
102: }
103:
1.1 www 104: # ---------------------------------------------------------- Do we have a case?
105:
106: my $thisfn;
107: unless (($thisfn=$ENV{'request.ambiguous'})&&($ENV{'request.course.fn'})) {
1.2 www 108: &getlost($r,'Could not find information on resource.');
1.1 www 109: return OK;
110: }
111:
112: # ---------------------------------- Should this file have been part of a page?
113:
114: $thisfn=&Apache::lonnet::declutter($thisfn);
115: my %hash;
116: my $syval='';
117:
118: if (tie(%hash,'GDBM_File',$ENV{'request.course.fn'}.'_symb.db',
1.5 albertel 119: &GDBM_READER(),0640)) {
1.1 www 120: $syval=$hash{$thisfn};
121: untie(%hash);
122: }
1.2 www 123:
1.1 www 124: # ---------------------------------------------------------- There was an entry
1.2 www 125:
1.1 www 126: if ($syval) {
1.2 www 127:
1.1 www 128: if ($syval=~/\_$/) {
129: # ----------------------------------- Okay, this should have appeared on a page
130: $syval=~s/\_\_\_$//;
131: $r->content_type('text/html');
132: $r->header_out(Location =>
133: 'http://'.$ENV{'HTTP_HOST'}.'/res/'.$syval);
134: return REDIRECT;
135: } else {
136: # There is not really a problem (???), but cannot go back without endless loop
1.2 www 137: &getlost($r,'The nature of the problem is unclear');
1.1 www 138: return OK;
139: }
140: }
141:
142: # ------------------------------------------------ Would be standalone resource
143:
144: if (tie(%bighash,'GDBM_File',$ENV{'request.course.fn'}.'.db',
1.5 albertel 145: &GDBM_READER(),0640)) {
1.1 www 146: # ---------------------------------------------- Get ID(s) for current resource
1.7 albertel 147: my $ids=$bighash{'ids_'.&Apache::lonnet::clutter($thisfn)};
1.1 www 148: if ($ids) {
149: # ------------------------------------------------------------------- Has ID(s)
150: my @possibilities=split(/\,/,$ids);
151: my $couldbe='';
152: map {
1.2 www 153: if (&Apache::lonnet::allowed('bre',$bighash{'src_'.$_})) {
1.1 www 154: if ($couldbe) {
155: $couldbe.=','.$_;
156: } else {
157: $couldbe=$_;
158: }
159: }
160: } @possibilities;
161: if ($couldbe) {
162: @possibilities=split(/\,/,$couldbe);
163: if ($#possibilities>0) {
164: # ----------------------------------------------- Okay, really multiple choices
165: $r->content_type('text/html');
166: $r->send_http_header;
1.9 ! www 167: my $bodytag=
! 168: &Apache::loncommon::bodytag('Pick Instance of Resource');
1.2 www 169: $r->print(<<ENDSTART);
170: <head><title>Choose Location</title></head>
1.9 ! www 171: $bodytag
1.2 www 172: The resource you had been accessing appears more than once in this course,
173: and LON-CAPA has insufficient session information to determine which instance
174: of the resource you meant.
175: <p>
176: Please click on the instance of the resource you intended to access:
177: <p>
178: <form action="/adm/ambiguous" method=post>
179: <input type=hidden name=orgurl value="$thisfn">
180: <input type=hidden name=selecturl value=1>
181: <table border=2>
182: <tr><th> </th><th>Title</th><th>Type</th><th>Part of ...</th></tr>
183: ENDSTART
184: map {
185: my $mapurl=$bighash{'map_id_'.(split(/\./,$_))[0]};
186: $r->print('<tr><td><input type=submit value=Select name="'.
187: $_.'"></td><td>'.$bighash{'title_'.$_}.
188: '</td><td>'.$bighash{'type_'.$_}.
1.9 ! www 189: '</td><td>'.
! 190: ($mapurl=~/^\/uploaded\//?'':'<a href="'.$mapurl.'">').
! 191: &Apache::lonnet::gettitle($mapurl).' '.
! 192: ($mapurl=~/^\/uploaded\//?'':'</a>').'</td></tr>');
1.2 www 193: } @possibilities;
194: $r->print('</table></form></body></html>');
1.1 www 195: untie(%bighash);
196: return OK;
197: }
198: }
199: }
200: untie(%bighash);
201: }
202:
203: # ------------------------------------ This handler should not have been called
1.2 www 204: &getlost($r,'Invalid call of handler');
1.1 www 205: return OK;
206: }
207:
208: 1;
209: __END__
210:
211:
212:
213:
214:
215:
216:
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>