1: # The LearningOnline Network with CAPA
2: #
3: # Page flip handler
4: #
5: # (Page Handler
6: #
7: # (TeX Content Handler
8: #
9: # 05/29/00,05/30 Gerd Kortemeyer)
10: # 08/30,08/31,09/06,09/14,09/15,09/16,09/19,09/20,09/21,09/23,
11: # 10/02 Gerd Kortemeyer)
12: #
13: # 10/03,10/05,10/06,10/07,10/09 Gerd Kortemeyer
14:
15: package Apache::lonpageflip;
16:
17: use strict;
18: use Apache::Constants qw(:common :http REDIRECT);
19: use Apache::lonnet();
20: use HTML::TokeParser;
21: use GDBM_File;
22:
23: # ========================================================== Module Global Hash
24:
25: my %hash;
26:
27: sub addrid {
28: my ($current,$new,$condid)=@_;
29: unless ($condid) { $condid=0; }
30: if (&Apache::lonnet::allowed('bre',$hash{'src_'.$new})) {
31: if ($current) {
32: $current.=','.$new.':'.$condid;
33: } else {
34: $current=''.$new.':'.$condid;
35: }
36: }
37: return $current;
38: }
39:
40: # ================================================================ Main Handler
41:
42: sub handler {
43: my $r=shift;
44:
45: # ------------------------------------------- Set document type for header only
46:
47: if ($r->header_only) {
48: $r->content_type('text/html');
49: $r->send_http_header;
50: return OK;
51: }
52:
53: my %cachehash=();
54: my $redirecturl='';
55: my $next='';
56: my @possibilities=();
57:
58: if (($ENV{'form.postdata'})&&($ENV{'request.course.fn'})) {
59: $ENV{'form.postdata'}=~/(\w+)\:(.*)/;
60: my $direction=$1;
61: my $currenturl=$2;
62: my $redirecturl=$currenturl;
63: $currenturl=~s/^http\:\/\///;
64: $currenturl=~s/^[^\/]+//;
65: # ------------------------------------------- Do we have any idea where we are?
66: my $position;
67: if ($position=Apache::lonnet::symbread($currenturl)) {
68: # ------------------------------------------------------------------------- Yes
69: my ($mapurl,$mapnum,$thisurl)=split(/\_\_\_/,$position);
70: $cachehash{$thisurl}=$mapnum;
71: if (tie(%hash,'GDBM_File',$ENV{'request.course.fn'}.'.db',
72: &GDBM_READER,0640)) {
73: my $rid=$hash{'map_pc_/res/'.$mapurl}.'.'.$mapnum;
74: my $next='';
75: if ($direction eq 'forward') {
76: map {
77: $next=&addrid($next,$hash{'goesto_'.$_},
78: $hash{'condid_'.$hash{'undercond_'.$_}});
79: } split(/\,/,$hash{'to_'.$rid});
80: } elsif ($direction eq 'back') {
81: map {
82: $next=&addrid($next,$hash{'comesfrom_'.$_},
83: $hash{'condid_'.$hash{'undercond_'.$_}});
84: } split(/\,/,$hash{'from_'.$rid});
85: } elsif ($direction eq 'up') {
86: } elsif ($direction eq 'down') {
87: }
88: my $redirectid='';
89: # ----------------------------------------------------- Check out possibilities
90: if ($next) {
91: @possibilities=split(/\,/,$next);
92: if ($#possibilities==0) {
93: $redirectid=(split(/\:/,$next))[0];
94: } else {
95: }
96: }
97: if ($redirectid) {
98: $redirecturl=$hash{'src_'.$redirectid};
99: }
100: untie(%hash);
101: if ($redirecturl) {
102: $r->content_type('text/html');
103: $r->header_out(Location =>
104: 'http://'.$ENV{'HTTP_HOST'}.$redirecturl);
105: return REDIRECT;
106: }
107: }
108: }
109: # -------------------------------------------------------- No, could not decide
110: }
111: $r->content_type('text/html');
112: $r->send_http_header;
113:
114: $r->print('<html><body>');
115:
116: # -------------------------- Class was not initialized or page fliped strangely
117: } else {
118: $ENV{'user.error.msg'}="/adm/flip:bre:0:0:Choose Course";
119: return HTTP_NOT_ACCEPTABLE;
120: }
121:
122:
123:
124:
125: # ------TRASH BELOW
126: # --------------------------- TRASH
127:
128: $r->print('</body></html>');
129: return OK;
130:
131:
132: # ========================================================= TOTAL TRASH
133:
134: # &Apache::lonnet::symblist($requrl,%symbhash);
135:
136: }
137:
138: 1;
139: __END__
140:
141:
142:
143:
144:
145:
146:
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>