Annotation of rat/lonpageflip.pm, revision 1.15
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.15 ! www 15: # 10/01/01,05/01 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: } elsif ($direction eq 'up') {
! 112: # -------------------------------------------------------------------------- Up
! 113: } elsif ($direction eq 'down') {
! 114: # ------------------------------------------------------------------------ Down
! 115: }
! 116:
! 117: return ($next,$mapurl);
! 118: }
! 119:
1.1 www 120: # ================================================================ Main Handler
121:
122: sub handler {
1.2 www 123: my $r=shift;
1.1 www 124:
125: # ------------------------------------------- Set document type for header only
126:
1.2 www 127: if ($r->header_only) {
1.1 www 128: $r->content_type('text/html');
129: $r->send_http_header;
1.2 www 130: return OK;
131: }
132:
1.5 www 133: my %cachehash=();
134: my $multichoice=0;
135: my %multichoicehash=();
1.4 www 136: my $redirecturl='';
137: my $next='';
138: my @possibilities=();
1.2 www 139:
140: if (($ENV{'form.postdata'})&&($ENV{'request.course.fn'})) {
141: $ENV{'form.postdata'}=~/(\w+)\:(.*)/;
142: my $direction=$1;
143: my $currenturl=$2;
1.10 www 144: if ($direction eq 'return') {
145: # -------------------------------------------------------- Return to last known
146: my $last;
147: if (tie(%hash,'GDBM_File',$ENV{'request.course.fn'}.'_symb.db',
148: &GDBM_READER,0640)) {
149: $last=$hash{'last_known'};
150: untie(%hash);
151: }
152: my $newloc;
153: if ($last) {
154: $newloc='/res/'.(split(/\_\_\_/,$last))[1];
155: } else {
156: $newloc='/adm/noidea.html';
157: }
158: $r->content_type('text/html');
159: $r->header_out(Location =>
160: 'http://'.$ENV{'HTTP_HOST'}.$newloc);
161:
162: return REDIRECT;
163: }
1.2 www 164: $currenturl=~s/^http\:\/\///;
165: $currenturl=~s/^[^\/]+//;
1.7 www 166: unless ($currenturl=~/\/res\//) {
167: my $last;
168: if (tie(%hash,'GDBM_File',$ENV{'request.course.fn'}.'_symb.db',
169: &GDBM_READER,0640)) {
170: $last=$hash{'last_known'};
171: untie(%hash);
172: }
173: if ($last) {
174: $currenturl='/res/'.(split(/\_\_\_/,$last))[1];
175: } else {
176: $r->content_type('text/html');
177: $r->header_out(Location =>
178: 'http://'.$ENV{'HTTP_HOST'}.'/adm/noidea.html');
1.9 www 179: return REDIRECT;
1.7 www 180: }
181: }
1.3 www 182: # ------------------------------------------- Do we have any idea where we are?
183: my $position;
184: if ($position=Apache::lonnet::symbread($currenturl)) {
185: # ------------------------------------------------------------------------- Yes
186: my ($mapurl,$mapnum,$thisurl)=split(/\_\_\_/,$position);
187: $cachehash{$thisurl}=$mapnum;
1.5 www 188: # ============================================================ Tie the big hash
1.3 www 189: if (tie(%hash,'GDBM_File',$ENV{'request.course.fn'}.'.db',
190: &GDBM_READER,0640)) {
191: my $rid=$hash{'map_pc_/res/'.$mapurl}.'.'.$mapnum;
1.14 www 192:
1.15 ! www 193: # ------------------------------------------------- Move forward, backward, etc
! 194:
! 195: ($next,$mapurl)=&move($rid,$mapurl,$direction);
! 196: # -------------------------------------- Do we have one and only one empty URL?
! 197: my $safecount=0;
! 198: while (($next) && ($next!~/\,/) && (!$hash{'src_'.$next})
! 199: && ($safecount<25)) {
! 200: ($next,$mapurl)=&move($next,$mapurl,$direction);
! 201: $safecount++;
! 202: }
1.4 www 203: # ----------------------------------------------------- Check out possibilities
204: if ($next) {
205: @possibilities=split(/\,/,$next);
206: if ($#possibilities==0) {
1.5 www 207: # ---------------------------------------------- Only one possibility, redirect
208: $redirecturl=$hash{'src_'.$next};
209: $cachehash{&Apache::lonnet::declutter($redirecturl)}
210: =(split(/\./,$next))[1];
1.4 www 211: } else {
1.5 www 212: # ------------------------ There are multiple possibilities for a next resource
213: $multichoice=1;
214: map {
215: $multichoicehash{'src_'.$_}=$hash{'src_'.$_};
216: $multichoicehash{'title_'.$_}=$hash{'title_'.$_};
1.6 www 217: $multichoicehash{'type_'.$_}=$hash{'type_'.$_};
1.5 www 218: $cachehash
219: {&Apache::lonnet::declutter(
220: $multichoicehash
221: {'src_'.$_}
222: )}
223: =(split(/\./,$_))[1];
224: } @possibilities;
1.4 www 225: }
1.5 www 226: } else {
227: # -------------------------------------------------------------- No place to go
228: $multichoice=-1;
1.4 www 229: }
1.5 www 230: # ----------------- The program must come past this point to untie the big hash
1.3 www 231: untie(%hash);
1.5 www 232: # --------------------------------------------------------- Store position info
233: $cachehash{'last_direction'}=$direction;
1.7 www 234: $cachehash{'last_known'}=&Apache::lonnet::declutter($currenturl);
1.5 www 235: &Apache::lonnet::symblist($mapurl,%cachehash);
236: # ============================================== Do not return before this line
1.4 www 237: if ($redirecturl) {
1.5 www 238: # ----------------------------------------------------- There is a URL to go to
1.4 www 239: $r->content_type('text/html');
240: $r->header_out(Location =>
241: 'http://'.$ENV{'HTTP_HOST'}.$redirecturl);
242: return REDIRECT;
1.5 www 243: } else {
244: # --------------------------------------------------------- There was a problem
1.8 www 245: $r->content_type('text/html');
246: $r->send_http_header;
247: if ($#possibilities>0) {
248: $r->print(<<ENDSTART);
249: <head><title>Choose Next Location</title></head>
250: <body bgcolor="#FFFFFF">
251: <h1>LON-CAPA</h1>
252: There are several possibilities of where to go next.
253: <p>
254: Please click on the the resource you intend to access:
255: <p>
256: <table border=2>
257: <tr><th>Title</th><th>Type</th></tr>
258: ENDSTART
259: map {
260: $r->print(
261: '<tr><td><a href="'.
262: $multichoicehash{'src_'.$_}.'">'.
263: $multichoicehash{'title_'.$_}.
264: '</a></td><td>'.$multichoicehash{'type_'.$_}.
265: '</td></tr>');
266: } @possibilities;
267: $r->print('</table></body></html>');
268: return OK;
269: } else {
270: $r->print(<<ENDNONE);
271: <head><title>Choose Next Location</title></head>
272: <body bgcolor="#FFFFFF">
273: <img src="/adm/lonKaputt/lonlogo_broken.gif" align=left>
274: <h1>Sorry!</h1>
275: <h2>Next resource could not be identified.</h2>
276: </body>
277: </html>
278: ENDNONE
279: return OK;
280: }
281: }
1.5 www 282: } else {
283: # ------------------------------------------------- Problem, could not tie hash
284: $ENV{'user.error.msg'}="/adm/flip:bre:0:1:Course Data Missing";
285: return HTTP_NOT_ACCEPTABLE;
1.3 www 286: }
1.5 www 287: } else {
288: # ---------------------------------------- No, could not determine where we are
1.6 www 289: $r->internal_redirect('/adm/ambiguous');
1.2 www 290: }
1.5 www 291: } else {
1.2 www 292: # -------------------------- Class was not initialized or page fliped strangely
293: $ENV{'user.error.msg'}="/adm/flip:bre:0:0:Choose Course";
294: return HTTP_NOT_ACCEPTABLE;
295: }
1.1 www 296: }
297:
298: 1;
299: __END__
300:
301:
302:
303:
304:
305:
306:
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>