Annotation of rat/lonsequence.pm, revision 1.4
1.1 www 1: # The LearningOnline Network with CAPA
2: #
3: # Sequence Handler
4: #
5: # (Handler to resolve ambiguous file locations
6: #
7: # (TeX Content Handler
8: #
9: # 05/29/00,05/30,10/11 Gerd Kortemeyer)
10: #
11: # 10/11,10/12 Gerd Kortemeyer)
12: #
13: # 10/16 Gerd Kortemeyer
14:
1.3 www 15: package Apache::lonsequence;
1.1 www 16:
17: use strict;
18: use Apache::lonnet;
1.3 www 19: use Apache::Constants qw(:common :http REDIRECT);
1.1 www 20: use GDBM_File;
21:
22:
23: # ----------------------------------------------------------- Could not resolve
24:
25: sub getlost {
26: my ($r,$errmsg)=@_;
27: $r->content_type('text/html');
28: $r->send_http_header;
29: $r->print(
30: '<head><title>Unknown Error</title></head><body bgcolor="#FFFFFF"><h1>'.
1.3 www 31: 'LON-CAPA</h1>Could not handle sequence resource reference.<p>'.$errmsg.
1.1 www 32: '</body></html>');
33: }
34:
35: # ================================================================ Main Handler
36:
37: sub handler {
38: my $r=shift;
39:
40: if ($r->header_only) {
41: $r->content_type('text/html');
42: $r->send_http_header;
43: return OK;
44: }
45:
1.2 www 46: my %hash;
1.1 www 47: my %bighash;
1.2 www 48: my $requrl=$r->uri;
49:
1.3 www 50: # ------------------------------------------------------------ Tie symb db file
1.1 www 51: if ($ENV{'request.course.fn'}) {
1.2 www 52: my $last;
53: if (tie(%hash,'GDBM_File',$ENV{'request.course.fn'}.'_symb.db',
54: &GDBM_READER,0640)) {
55: $last=$hash{'last_direction'};
56: untie(%hash);
57: }
1.3 www 58: my $direction='';
59: my $prevmap='';
60: if ($last) {
61: ($prevmap,$direction)=(split(/\_\_\_/,$last));
62: }
63: # ------------------------------------------------------------- Tie big db file
1.1 www 64: if (tie(%bighash,'GDBM_File',$ENV{'request.course.fn'}.'.db',
65: &GDBM_READER,0640)) {
1.3 www 66: my $disid='';
1.4 ! www 67: my $whatend='';
1.3 www 68: if ($direction eq 'back') {
69: $disid=$bighash{'map_finish_'.$requrl};
1.4 ! www 70: $whatend='End';
1.3 www 71: } else {
72: $disid=$bighash{'map_start_'.$requrl};
1.4 ! www 73: $whatend='Beginning';
1.3 www 74: }
75: my $disurl='';
1.4 ! www 76: my $dismapid='';
1.3 www 77: if ($disid) {
78: $disurl=$bighash{'src_'.$disid};
1.4 ! www 79: $dismapid=(split(/\./,$disid))[1];
1.3 www 80: }
81: my $symb='';
1.4 ! www 82: my $sequencetitle='';
1.3 www 83: unless($disurl) {
84: if ($symb=&Apache::lonnet::symbread()) {
1.4 ! www 85: my ($mapurl,$mapid)=split(/\_\_\_/,$symb);
! 86: $sequencetitle=$bighash{'title_'.
! 87: $bighash{'map_pc_/res/'.$mapurl}.'.'.
! 88: $mapid};
1.3 www 89: }
90: }
91: # --------------------------------------- Untie hash, make sure to come by here
92: untie(%bighash);
93: if ($disurl) {
94: # -------------------------------------------------- Has first or last resource
1.4 ! www 95: &Apache::lonnet::symblist($requrl,$disurl => $dismapid,
! 96: 'last_known' => &Apache::lonnet::declutter($disurl));
1.3 www 97: $r->content_type('text/html');
98: $r->header_out(Location => 'http://'.$ENV{'HTTP_HOST'}.$disurl);
99: return REDIRECT;
100: } else {
101: # ---------- Does not have first or last resource, try to find out where we are
102: unless ($symb) {
103: $r->internal_redirect('/adm/ambiguous');
104: }
105: $r->content_type('text/html');
106: $r->send_http_header;
107: $r->print(<<ENDSYMB);
1.4 ! www 108: <html><body bgcolor="#FFFFFF">
! 109: <h2>$whatend of</h2>
! 110: <h1>$sequencetitle</h1>
1.3 www 111: </body></html>
112: ENDSYMB
113: return OK
1.2 www 114: }
1.1 www 115: } else {
116: &getlost($r,'Could not access course structure.');
117: return OK;
118: }
119: } else {
120: $ENV{'user.error.msg'}="$requrl:bre:0:0:Course not initialized";
121: return HTTP_NOT_ACCEPTABLE;
122: }
123:
124: return OK;
125: }
126:
127: 1;
128: __END__
129:
130:
131:
132:
133:
134:
135:
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>