Annotation of rat/lonpageflip.pm, revision 1.17
1.1 www 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: #
1.13 www 13: # 10/03,10/05,10/06,10/07,10/09,10/10,10/11,10/16,10/17,
1.14 www 14: # 11/14,11/16,
1.17 ! www 15: # 10/01/01,05/01,05/28,07/05 Gerd Kortemeyer
1.1 www 16:
17: package Apache::lonpageflip;
18:
19: use strict;
1.4 www 20: use Apache::Constants qw(:common :http REDIRECT);
1.1 www 21: use Apache::lonnet();
22: use HTML::TokeParser;
23: use GDBM_File;
24:
1.3 www 25: # ========================================================== Module Global Hash
26:
1.1 www 27: my %hash;
28:
1.3 www 29: sub addrid {
1.4 www 30: my ($current,$new,$condid)=@_;
31: unless ($condid) { $condid=0; }
1.3 www 32: if (&Apache::lonnet::allowed('bre',$hash{'src_'.$new})) {
33: if ($current) {
1.5 www 34: $current.=','.$new;
1.3 www 35: } else {
1.5 www 36: $current=''.$new;
1.3 www 37: }
1.1 www 38: }
1.3 www 39: return $current;
1.1 www 40: }
41:
1.15 www 42: sub move {
43: my ($rid,$mapurl,$direction)=@_;
44:
45: my $next='';
46:
47: my $mincond=1;
48: my $posnext='';
49: if ($direction eq 'forward') {
50: # --------------------------------------------------------------------- Forward
51: if ($hash{'type_'.$rid} eq 'finish') {
52: $rid=$hash{'ids_/res/'.$mapurl};
53: }
54: map {
55: my $thiscond=
56: &Apache::lonnet::directcondval($hash{'condid_'.$hash{'undercond_'.$_}});
57: if ($thiscond>=$mincond) {
58: if ($posnext) {
59: $posnext.=','.$_.':'.$thiscond;
60: } else {
61: $posnext=$_.':'.$thiscond;
62: }
63: if ($thiscond>$mincond) { $mincond=$thiscond; }
64: }
65: } split(/\,/,$hash{'to_'.$rid});
66: map {
67: my ($linkid,$condval)=split(/\:/,$_);
68: if ($condval>=$mincond) {
69: $next=&addrid($next,$hash{'goesto_'.$linkid},
70: $hash{'condid_'.$hash{'undercond_'.$linkid}});
71: }
72: } split(/\,/,$posnext);
73: if ($hash{'is_map_'.$next}) {
74: if (
75: $hash{'map_type_'.$hash{'map_pc_'.$hash{'src_'.$next}}} eq 'sequence') {
76: $mapurl=$hash{'src_'.$next};
77: $next=$hash{'map_start_'.$hash{'src_'.$next}};
78: }
79: }
80: } elsif ($direction eq 'back') {
81: # ------------------------------------------------------------------- Backwards
82: if ($hash{'type_'.$rid} eq 'start') {
83: $rid=$hash{'ids_/res/'.$mapurl};
84: }
85: map {
86: my $thiscond=
87: &Apache::lonnet::directcondval($hash{'condid_'.$hash{'undercond_'.$_}});
88: if ($thiscond>=$mincond) {
89: if ($posnext) {
90: $posnext.=','.$_.':'.$thiscond;
91: } else {
92: $posnext=$_.':'.$thiscond;
93: }
94: if ($thiscond>$mincond) { $mincond=$thiscond; }
95: }
96: } split(/\,/,$hash{'from_'.$rid});
97: map {
98: my ($linkid,$condval)=split(/\:/,$_);
99: if ($condval>=$mincond) {
100: $next=&addrid($next,$hash{'comesfrom_'.$linkid},
101: $hash{'condid_'.$hash{'undercond_'.$linkid}});
102: }
103: } split(/\,/,$posnext);
104: if ($hash{'is_map_'.$next}) {
105: if (
106: $hash{'map_type_'.$hash{'map_pc_'.$hash{'src_'.$next}}} eq 'sequence') {
107: $mapurl=$hash{'src_'.$next};
108: $next=$hash{'map_finish_'.$hash{'src_'.$next}};
109: }
110: }
111: }
112:
113: return ($next,$mapurl);
114: }
115:
1.1 www 116: # ================================================================ Main Handler
117:
118: sub handler {
1.2 www 119: my $r=shift;
1.1 www 120:
121: # ------------------------------------------- Set document type for header only
122:
1.2 www 123: if ($r->header_only) {
1.1 www 124: $r->content_type('text/html');
125: $r->send_http_header;
1.2 www 126: return OK;
127: }
128:
1.5 www 129: my %cachehash=();
130: my $multichoice=0;
131: my %multichoicehash=();
1.4 www 132: my $redirecturl='';
133: my $next='';
134: my @possibilities=();
1.2 www 135:
136: if (($ENV{'form.postdata'})&&($ENV{'request.course.fn'})) {
137: $ENV{'form.postdata'}=~/(\w+)\:(.*)/;
138: my $direction=$1;
139: my $currenturl=$2;
1.10 www 140: if ($direction eq 'return') {
141: # -------------------------------------------------------- Return to last known
142: my $last;
143: if (tie(%hash,'GDBM_File',$ENV{'request.course.fn'}.'_symb.db',
144: &GDBM_READER,0640)) {
145: $last=$hash{'last_known'};
146: untie(%hash);
147: }
148: my $newloc;
149: if ($last) {
150: $newloc='/res/'.(split(/\_\_\_/,$last))[1];
151: } else {
152: $newloc='/adm/noidea.html';
153: }
154: $r->content_type('text/html');
155: $r->header_out(Location =>
156: 'http://'.$ENV{'HTTP_HOST'}.$newloc);
157:
158: return REDIRECT;
159: }
1.2 www 160: $currenturl=~s/^http\:\/\///;
161: $currenturl=~s/^[^\/]+//;
1.17 ! www 162: unless (($currenturl=~/^\/res\//) ||
! 163: ($currenturl=~/^\/adm\/wrapper\//)) {
1.7 www 164: my $last;
165: if (tie(%hash,'GDBM_File',$ENV{'request.course.fn'}.'_symb.db',
166: &GDBM_READER,0640)) {
167: $last=$hash{'last_known'};
168: untie(%hash);
169: }
170: if ($last) {
171: $currenturl='/res/'.(split(/\_\_\_/,$last))[1];
172: } else {
173: $r->content_type('text/html');
174: $r->header_out(Location =>
175: 'http://'.$ENV{'HTTP_HOST'}.'/adm/noidea.html');
1.9 www 176: return REDIRECT;
1.7 www 177: }
178: }
1.3 www 179: # ------------------------------------------- Do we have any idea where we are?
180: my $position;
181: if ($position=Apache::lonnet::symbread($currenturl)) {
182: # ------------------------------------------------------------------------- Yes
183: my ($mapurl,$mapnum,$thisurl)=split(/\_\_\_/,$position);
184: $cachehash{$thisurl}=$mapnum;
1.5 www 185: # ============================================================ Tie the big hash
1.3 www 186: if (tie(%hash,'GDBM_File',$ENV{'request.course.fn'}.'.db',
187: &GDBM_READER,0640)) {
188: my $rid=$hash{'map_pc_/res/'.$mapurl}.'.'.$mapnum;
1.14 www 189:
1.15 www 190: # ------------------------------------------------- Move forward, backward, etc
191:
192: ($next,$mapurl)=&move($rid,$mapurl,$direction);
193: # -------------------------------------- Do we have one and only one empty URL?
194: my $safecount=0;
195: while (($next) && ($next!~/\,/) && (!$hash{'src_'.$next})
196: && ($safecount<25)) {
197: ($next,$mapurl)=&move($next,$mapurl,$direction);
198: $safecount++;
199: }
1.4 www 200: # ----------------------------------------------------- Check out possibilities
201: if ($next) {
202: @possibilities=split(/\,/,$next);
203: if ($#possibilities==0) {
1.5 www 204: # ---------------------------------------------- Only one possibility, redirect
205: $redirecturl=$hash{'src_'.$next};
206: $cachehash{&Apache::lonnet::declutter($redirecturl)}
207: =(split(/\./,$next))[1];
1.4 www 208: } else {
1.5 www 209: # ------------------------ There are multiple possibilities for a next resource
210: $multichoice=1;
211: map {
212: $multichoicehash{'src_'.$_}=$hash{'src_'.$_};
213: $multichoicehash{'title_'.$_}=$hash{'title_'.$_};
1.6 www 214: $multichoicehash{'type_'.$_}=$hash{'type_'.$_};
1.5 www 215: $cachehash
216: {&Apache::lonnet::declutter(
217: $multichoicehash
218: {'src_'.$_}
219: )}
220: =(split(/\./,$_))[1];
221: } @possibilities;
1.4 www 222: }
1.5 www 223: } else {
224: # -------------------------------------------------------------- No place to go
225: $multichoice=-1;
1.4 www 226: }
1.5 www 227: # ----------------- The program must come past this point to untie the big hash
1.3 www 228: untie(%hash);
1.5 www 229: # --------------------------------------------------------- Store position info
230: $cachehash{'last_direction'}=$direction;
1.7 www 231: $cachehash{'last_known'}=&Apache::lonnet::declutter($currenturl);
1.5 www 232: &Apache::lonnet::symblist($mapurl,%cachehash);
233: # ============================================== Do not return before this line
1.4 www 234: if ($redirecturl) {
1.5 www 235: # ----------------------------------------------------- There is a URL to go to
1.4 www 236: $r->content_type('text/html');
237: $r->header_out(Location =>
238: 'http://'.$ENV{'HTTP_HOST'}.$redirecturl);
239: return REDIRECT;
1.5 www 240: } else {
241: # --------------------------------------------------------- There was a problem
1.8 www 242: $r->content_type('text/html');
243: $r->send_http_header;
244: if ($#possibilities>0) {
245: $r->print(<<ENDSTART);
246: <head><title>Choose Next Location</title></head>
247: <body bgcolor="#FFFFFF">
248: <h1>LON-CAPA</h1>
249: There are several possibilities of where to go next.
250: <p>
251: Please click on the the resource you intend to access:
252: <p>
253: <table border=2>
254: <tr><th>Title</th><th>Type</th></tr>
255: ENDSTART
256: map {
257: $r->print(
258: '<tr><td><a href="'.
259: $multichoicehash{'src_'.$_}.'">'.
260: $multichoicehash{'title_'.$_}.
261: '</a></td><td>'.$multichoicehash{'type_'.$_}.
262: '</td></tr>');
263: } @possibilities;
264: $r->print('</table></body></html>');
265: return OK;
266: } else {
267: $r->print(<<ENDNONE);
268: <head><title>Choose Next Location</title></head>
269: <body bgcolor="#FFFFFF">
1.17 ! www 270: <img src="/adm/lonIcons/lonlogos.gif" align=right>
1.8 www 271: <h1>Sorry!</h1>
272: <h2>Next resource could not be identified.</h2>
1.17 ! www 273: <h3>You probably are at the beginning or the end of the course.</h3>
1.8 www 274: </body>
275: </html>
276: ENDNONE
277: return OK;
278: }
279: }
1.5 www 280: } else {
281: # ------------------------------------------------- Problem, could not tie hash
282: $ENV{'user.error.msg'}="/adm/flip:bre:0:1:Course Data Missing";
283: return HTTP_NOT_ACCEPTABLE;
1.3 www 284: }
1.5 www 285: } else {
286: # ---------------------------------------- No, could not determine where we are
1.6 www 287: $r->internal_redirect('/adm/ambiguous');
1.2 www 288: }
1.5 www 289: } else {
1.2 www 290: # -------------------------- Class was not initialized or page fliped strangely
291: $ENV{'user.error.msg'}="/adm/flip:bre:0:0:Choose Course";
292: return HTTP_NOT_ACCEPTABLE;
293: }
1.1 www 294: }
295:
296: 1;
297: __END__
298:
299:
300:
301:
302:
303:
304:
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>