1: # The LearningOnline Network with CAPA
2: #
3: # Sequence Handler
4: #
5: # $Id: lonsequence.pm,v 1.6 2002/04/02 21:05:50 www Exp $
6: #
7: # Copyright Michigan State University Board of Trustees
8: #
9: # This file is part of the LearningOnline Network with CAPA (LON-CAPA).
10: #
11: # LON-CAPA is free software; you can redistribute it and/or modify
12: # it under the terms of the GNU General Public License as published by
13: # the Free Software Foundation; either version 2 of the License, or
14: # (at your option) any later version.
15: #
16: # LON-CAPA is distributed in the hope that it will be useful,
17: # but WITHOUT ANY WARRANTY; without even the implied warranty of
18: # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19: # GNU General Public License for more details.
20: #
21: # You should have received a copy of the GNU General Public License
22: # along with LON-CAPA; if not, write to the Free Software
23: # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
24: #
25: # /home/httpd/html/adm/gpl.txt
26: #
27: # http://www.lon-capa.org/
28: #
29: # (Handler to resolve ambiguous file locations
30: #
31: # (TeX Content Handler
32: #
33: # 05/29/00,05/30,10/11 Gerd Kortemeyer)
34: #
35: # 10/11,10/12 Gerd Kortemeyer)
36: #
37: # 10/16 Gerd Kortemeyer
38:
39: package Apache::lonsequence;
40:
41: use strict;
42: use Apache::lonnet;
43: use Apache::Constants qw(:common :http REDIRECT);
44: use GDBM_File;
45:
46:
47: # ----------------------------------------------------------- Could not resolve
48:
49: sub getlost {
50: my ($r,$errmsg)=@_;
51: $r->content_type('text/html');
52: $r->send_http_header;
53: $r->print(
54: '<head><title>Unknown Error</title></head><body bgcolor="#FFFFFF"><h1>'.
55: 'LON-CAPA</h1>Could not handle sequence resource reference.<p>'.$errmsg.
56: '</body></html>');
57: }
58:
59: # ================================================================ Main Handler
60:
61: sub handler {
62: my $r=shift;
63:
64: if ($r->header_only) {
65: $r->content_type('text/html');
66: $r->send_http_header;
67: return OK;
68: }
69:
70: my %hash;
71: my %bighash;
72: my $requrl=$r->uri;
73:
74: # ------------------------------------------------------------ Tie symb db file
75: if ($ENV{'request.course.fn'}) {
76: my $last;
77: if (tie(%hash,'GDBM_File',$ENV{'request.course.fn'}.'_symb.db',
78: &GDBM_READER,0640)) {
79: $last=$hash{'last_direction'};
80: untie(%hash);
81: }
82: my $direction='';
83: my $prevmap='';
84: if ($last) {
85: ($prevmap,$direction)=(split(/\_\_\_/,$last));
86: }
87: # ------------------------------------------------------------- Tie big db file
88: if (tie(%bighash,'GDBM_File',$ENV{'request.course.fn'}.'.db',
89: &GDBM_READER,0640)) {
90: my $disid='';
91: my $whatend='';
92: if ($direction eq 'back') {
93: $disid=$bighash{'map_finish_'.$requrl};
94: $whatend='End';
95: } else {
96: $disid=$bighash{'map_start_'.$requrl};
97: $whatend='Beginning';
98: }
99: my $disurl='';
100: my $dismapid='';
101: if ($disid) {
102: $disurl=$bighash{'src_'.$disid};
103: $dismapid=(split(/\./,$disid))[1];
104: }
105: my $symb='';
106: my $sequencetitle='';
107: unless($disurl) {
108: if ($symb=&Apache::lonnet::symbread()) {
109: my ($mapurl,$mapid)=split(/\_\_\_/,$symb);
110: $sequencetitle=$bighash{'title_'.
111: $bighash{'map_pc_/res/'.$mapurl}.'.'.
112: $mapid};
113: }
114: }
115: # --------------------------------------- Untie hash, make sure to come by here
116: untie(%bighash);
117: if ($disurl) {
118: # -------------------------------------------------- Has first or last resource
119: &Apache::lonnet::symblist($requrl,{$disurl => $dismapid,
120: 'last_known' => &Apache::lonnet::declutter($disurl)});
121: $r->content_type('text/html');
122: $r->header_out(Location => 'http://'.$ENV{'HTTP_HOST'}.$disurl);
123: return REDIRECT;
124: } else {
125: # ---------- Does not have first or last resource, try to find out where we are
126: unless ($symb) {
127: $r->internal_redirect('/adm/ambiguous');
128: }
129: $r->content_type('text/html');
130: $r->send_http_header;
131: $r->print(<<ENDSYMB);
132: <html><body bgcolor="#FFFFFF">
133: <h2>$whatend of</h2>
134: <h1>$sequencetitle</h1>
135: </body></html>
136: ENDSYMB
137: return OK
138: }
139: } else {
140: &getlost($r,'Could not access course structure.');
141: return OK;
142: }
143: } else {
144: $ENV{'user.error.msg'}="$requrl:bre:0:0:Course not initialized";
145: return HTTP_NOT_ACCEPTABLE;
146: }
147:
148: return OK;
149: }
150:
151: 1;
152: __END__
153:
154:
155:
156:
157:
158:
159:
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>