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