Annotation of rat/lonpageflip.pm, revision 1.96
1.1 www 1: # The LearningOnline Network with CAPA
2: #
3: # Page flip handler
4: #
1.96 ! raeburn 5: # $Id: lonpageflip.pm,v 1.95 2017/03/08 02:51:18 raeburn 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:
1.76 jms 30:
31:
1.1 www 32: package Apache::lonpageflip;
33:
34: use strict;
1.68 albertel 35: use LONCAPA;
1.4 www 36: use Apache::Constants qw(:common :http REDIRECT);
1.53 albertel 37: use Apache::lonnet;
1.70 albertel 38: use Apache::loncommon();
1.91 raeburn 39: use Apache::lonnavmaps();
1.87 raeburn 40: use Apache::lonuserstate;
1.84 raeburn 41: use Apache::lonlocal;
1.1 www 42: use HTML::TokeParser;
43: use GDBM_File;
44:
1.3 www 45: # ========================================================== Module Global Hash
46:
1.1 www 47: my %hash;
1.34 www 48:
49: sub cleanup {
50: if (tied(%hash)){
51: &Apache::lonnet::logthis('Cleanup pageflip: hash');
52: unless (untie(%hash)) {
53: &Apache::lonnet::logthis('Failed cleanup pageflip: hash');
54: }
55: }
1.63 albertel 56: return OK;
1.34 www 57: }
1.1 www 58:
1.3 www 59: sub addrid {
1.4 www 60: my ($current,$new,$condid)=@_;
61: unless ($condid) { $condid=0; }
1.27 www 62:
1.3 www 63: if ($current) {
1.5 www 64: $current.=','.$new;
1.3 www 65: } else {
1.5 www 66: $current=''.$new;
1.3 www 67: }
1.27 www 68:
1.3 www 69: return $current;
1.25 www 70: }
71:
72: sub fullmove {
73: my ($rid,$mapurl,$direction)=@_;
1.53 albertel 74: if (tie(%hash,'GDBM_File',$env{'request.course.fn'}.'.db',
1.28 albertel 75: &GDBM_READER(),0640)) {
1.25 www 76: ($rid,$mapurl)=&move($rid,$mapurl,$direction);
77: untie(%hash);
78: }
79: return($rid,$mapurl);
1.1 www 80: }
81:
1.50 albertel 82: sub hash_src {
83: my ($id)=@_;
1.56 albertel 84: my ($mapid,$resid)=split(/\./,$id);
85: my $symb=&Apache::lonnet::encode_symb($hash{'map_id_'.$mapid},
86: $resid,$hash{'src_'.$id});
1.90 raeburn 87: my $anchor;
88: if ($hash{'ext_'.$id} eq 'true:') {
89: if ($hash{'src_'.$id} =~ /(\#.+)$/) {
90: $anchor = $1;
91: }
92: }
1.50 albertel 93: if ($hash{'encrypted_'.$id}) {
1.56 albertel 94: return (&Apache::lonenc::encrypted($hash{'src_'.$id}),
1.90 raeburn 95: &Apache::lonenc::encrypted($symb),
96: $hash{'encrypted_'.$id},$anchor);
1.50 albertel 97: }
1.90 raeburn 98: return ($hash{'src_'.$id},$symb,$hash{'encrypted_'.$id},$anchor);
1.50 albertel 99: }
100:
1.15 www 101: sub move {
1.72 albertel 102: my ($next,$endupmap,$direction) = @_;
103: my $safecount=0;
104: my $allowed=0;
105: do {
106: ($next,$endupmap)=&get_next_possible_move($next,$endupmap,$direction);
107:
108: my $url = $hash{'src_'.$next};
109: my ($mapid,$resid)=split(/\./,$next);
110: my $symb = &Apache::lonnet::encode_symb($hash{'map_id_'.$mapid},
111: $resid,$url);
112: if ($url eq '' || $symb eq '') {
113: $allowed = 0;
114: } else {
115: my $priv = &Apache::lonnet::allowed('bre',$url,$symb);
116: $allowed = (($priv eq 'F') || ($priv eq '2'));
117: }
118: $safecount++;
119: } while ( ($next)
120: && ($next!~/\,/)
121: && (
122: (!$hash{'src_'.$next})
123: || (
124: (!$env{'request.role.adv'})
125: && $hash{'randomout_'.$next}
126: )
127: || (!$allowed)
128: )
129: && ($safecount<10000));
130:
131: return ($next,$endupmap);
132: }
133:
134: sub get_next_possible_move {
1.15 www 135: my ($rid,$mapurl,$direction)=@_;
1.23 www 136: my $startoutrid=$rid;
1.15 www 137:
138: my $next='';
139:
140: my $mincond=1;
141: my $posnext='';
142: if ($direction eq 'forward') {
143: # --------------------------------------------------------------------- Forward
1.33 www 144: while ($hash{'type_'.$rid} eq 'finish') {
145: $rid=$hash{'ids_'.$hash{'map_id_'.(split(/\./,$rid))[0]}};
1.15 www 146: }
1.61 albertel 147: foreach my $id (split(/\,/,$hash{'to_'.$rid})) {
1.64 albertel 148: my $condition= $hash{'conditions_'.$hash{'goesto_'.$id}};
149: my $rescond = &Apache::lonnet::docondval($condition);
150: my $linkcond = &Apache::lonnet::directcondval($hash{'condid_'.$hash{'undercond_'.$id}});
151: my $thiscond = ($rescond<$linkcond)?$rescond:$linkcond;
152: if ($thiscond>=$mincond) {
1.15 www 153: if ($posnext) {
1.61 albertel 154: $posnext.=','.$id.':'.$thiscond;
1.15 www 155: } else {
1.61 albertel 156: $posnext=$id.':'.$thiscond;
1.15 www 157: }
158: if ($thiscond>$mincond) { $mincond=$thiscond; }
159: }
1.61 albertel 160: }
161: foreach my $id (split(/\,/,$posnext)) {
162: my ($linkid,$condval)=split(/\:/,$id);
1.15 www 163: if ($condval>=$mincond) {
164: $next=&addrid($next,$hash{'goesto_'.$linkid},
165: $hash{'condid_'.$hash{'undercond_'.$linkid}});
166: }
1.61 albertel 167: }
1.15 www 168: if ($hash{'is_map_'.$next}) {
1.23 www 169: # This jumps to the beginning of a new map (going down level)
1.15 www 170: if (
171: $hash{'map_type_'.$hash{'map_pc_'.$hash{'src_'.$next}}} eq 'sequence') {
172: $mapurl=$hash{'src_'.$next};
173: $next=$hash{'map_start_'.$hash{'src_'.$next}};
1.47 raeburn 174: } elsif (
175: # This jumps back up from an empty sequence, to a page up one level
176: $hash{'map_type_'.$hash{'map_pc_'.$hash{'src_'.$next}}} eq 'page') {
177: $mapurl=$hash{'map_id_'.(split(/\./,$next))[0]};
1.15 www 178: }
1.23 www 179: } elsif
180: ((split(/\./,$startoutrid))[0]!=(split(/\./,$next))[0]) {
181: # This comes up from a map (coming up one level);
182: $mapurl=$hash{'map_id_'.(split(/\./,$next))[0]};
1.61 albertel 183: }
1.15 www 184: } elsif ($direction eq 'back') {
185: # ------------------------------------------------------------------- Backwards
1.33 www 186: while ($hash{'type_'.$rid} eq 'start') {
187: $rid=$hash{'ids_'.$hash{'map_id_'.(split(/\./,$rid))[0]}};
188: }
1.62 albertel 189: foreach my $id (split(/\,/,$hash{'from_'.$rid})) {
1.64 albertel 190: my $condition= $hash{'conditions_'.$hash{'comesfrom_'.$id}};
191: my $rescond = &Apache::lonnet::docondval($condition);
192: my $linkcond = &Apache::lonnet::directcondval($hash{'condid_'.$hash{'undercond_'.$id}});
193: my $thiscond = ($rescond<$linkcond)?$rescond:$linkcond;
1.62 albertel 194: if ($thiscond>=$mincond) {
195: if ($posnext) {
196: $posnext.=','.$id.':'.$thiscond;
197: } else {
198: $posnext=$id.':'.$thiscond;
199: }
200: if ($thiscond>$mincond) { $mincond=$thiscond; }
201: }
202: }
203: foreach my $id (split(/\,/,$posnext)) {
204: my ($linkid,$condval)=split(/\:/,$id);
205: if ($condval>=$mincond) {
206: $next=&addrid($next,$hash{'comesfrom_'.$linkid},
207: $hash{'condid_'.$hash{'undercond_'.$linkid}});
208: }
209: }
1.15 www 210: if ($hash{'is_map_'.$next}) {
1.24 www 211: # This jumps to the end of a new map (going down one level)
1.15 www 212: if (
213: $hash{'map_type_'.$hash{'map_pc_'.$hash{'src_'.$next}}} eq 'sequence') {
214: $mapurl=$hash{'src_'.$next};
215: $next=$hash{'map_finish_'.$hash{'src_'.$next}};
1.47 raeburn 216: } elsif (
217: $hash{'map_type_'.$hash{'map_pc_'.$hash{'src_'.$next}}} eq 'page') {
218: # This jumps back up from an empty sequence, to a page up one level
219: $mapurl=$hash{'map_id_'.(split(/\./,$next))[0]};
220: }
1.24 www 221: } elsif
222: ((split(/\./,$startoutrid))[0]!=(split(/\./,$next))[0]) {
223: # This comes back up from a map (going up one level);
224: $mapurl=$hash{'map_id_'.(split(/\./,$next))[0]};
1.15 www 225: }
226: }
227: return ($next,$mapurl);
228: }
229:
1.69 www 230: sub first_accessible_resource {
231: my $furl;
232: if (tie(%hash,'GDBM_File',$env{'request.course.fn'}.'.db',
233: &GDBM_READER(),0640)) {
234: $furl=$hash{'first_url'};
1.74 albertel 235: my %args;
236: my ($url,$args) = split(/\?/,$furl);
237: foreach my $pair (split(/\&/,$args)) {
238: my ($name,$value) = split(/=/,$pair);
239: $args{&unescape($name)} = &unescape($value);
240: }
241: if (!&Apache::lonnet::allowed('bre',$url,$args{'symb'})) {
1.69 www 242: # Wow, we cannot see this ... move forward to the next one that we can see
243: my ($newrid,$newmap)=&move($hash{'first_rid'},$hash{'first_mapurl'},'forward');
244: # Build the new URL
1.73 albertel 245: my ($newmapid,$newresid)=split(/\./,$newrid);
1.69 www 246: my $symb=&Apache::lonnet::encode_symb($newmap,$newresid,$hash{'src_'.$newrid});
247: $furl=&add_get_param($hash{'src_'.$newrid},{ 'symb' => $symb });
248: if ($hash{'encrypted_'.$newrid}) {
249: $furl=&Apache::lonenc::encrypted($furl);
250: }
251: }
252: untie(%hash);
253: return $furl;
254: } else {
255: return '/adm/navmaps';
256: }
257: }
258:
1.91 raeburn 259: sub first_answerable_ressymb {
260: my $navmap = Apache::lonnavmaps::navmap->new;
261: return unless (ref($navmap));
262: my $iterator = $navmap->getIterator(undef,undef,undef,1);
263: return unless (ref($iterator));
264: my ($curRes,$result);
265: while ($curRes = $iterator->next()) {
266: if (ref($curRes) && $curRes->is_problem()) {
267: foreach my $part (@{$curRes->parts()}) {
268: if ($curRes->tries($part) < $curRes->maxtries($part)) {
269: $result = $curRes->link().'?symb='.$curRes->shown_symb();
270: last;
271: }
272: }
273: }
274: }
275: if ($result) {
276: return $result;
277: } else {
278: return &first_accessible_resource();
279: }
280: }
281:
1.95 raeburn 282: sub check_http_req {
1.92 raeburn 283: my ($srcref) = @_;
284: return unless (ref($srcref) eq 'SCALAR');
1.93 raeburn 285: my $usehttp;
1.92 raeburn 286: if ($env{'request.course.id'}) {
287: my $cnum = $env{'course.'.$env{'request.course.id'}.'.num'};
288: my $cdom = $env{'course.'.$env{'request.course.id'}.'.domain'};
289: if (($$srcref =~ m{^\Q/public/$cdom/$cnum/syllabus\E($|\?)}) &&
290: ($ENV{'SERVER_PORT'} == 443) &&
291: ($env{'course.'.$env{'request.course.id'}.'.externalsyllabus'} =~ m{^http://})) {
292: $$srcref .= (($$srcref =~/\?/)? '&':'?') . 'usehttp=1';
1.93 raeburn 293: $usehttp = 1;
1.95 raeburn 294: } elsif (($$srcref =~ m{^\Q/adm/wrapper/ext/\E(?!https:)}) &&
295: ($ENV{'SERVER_PORT'} == 443)) {
296: $usehttp = 1;
1.92 raeburn 297: }
298: }
1.93 raeburn 299: return $usehttp;
1.92 raeburn 300: }
301:
1.1 www 302: # ================================================================ Main Handler
303:
304: sub handler {
1.2 www 305: my $r=shift;
1.1 www 306:
307: # ------------------------------------------- Set document type for header only
308:
1.2 www 309: if ($r->header_only) {
1.51 albertel 310: &Apache::loncommon::content_type($r,'text/html');
311: $r->send_http_header;
312: return OK;
1.2 www 313: }
314:
1.5 www 315: my %cachehash=();
316: my $multichoice=0;
317: my %multichoicehash=();
1.90 raeburn 318: my ($redirecturl,$redirectsymb,$enc,$anchor);
1.4 www 319: my $next='';
1.94 raeburn 320: my $hostname = $r->hostname();
1.4 www 321: my @possibilities=();
1.37 www 322: &Apache::loncommon::get_unprocessed_cgi($ENV{'QUERY_STRING'},['postdata']);
1.53 albertel 323: if (($env{'form.postdata'})&&($env{'request.course.fn'})) {
1.88 raeburn 324: my ($direction,$currenturl) = ($env{'form.postdata'}=~/(\w+)\:(.*)/);
1.89 raeburn 325: if ($currenturl=~m|^/enc/|) {
326: $currenturl=&Apache::lonenc::unencrypted($currenturl);
327: }
328: $currenturl=~s/\.\d+\.(\w+)$/\.$1/;
329: $currenturl=~s/^https?\:\/\///;
330: $currenturl=~s/^[^\/]+//;
331: my ($preupdatepos,$last,$reinitcheck);
332: if ($direction eq 'return') {
333: if (tie(%hash,'GDBM_File',$env{'request.course.fn'}.'_symb.db',
334: &GDBM_READER(),0640)) {
335: $last=$hash{'last_known'};
336: untie(%hash);
337: }
1.91 raeburn 338: } elsif ($direction eq 'firstanswerable') {
339: my $furl = &first_answerable_ressymb();
1.95 raeburn 340: my $usehttp = &check_http_req(\$furl);
1.94 raeburn 341: if (($usehttp) && ($hostname ne '')) {
342: $furl='http://'.$hostname.$furl;
1.93 raeburn 343: } else {
344: $furl=&Apache::lonnet::absolute_url().$furl;
345: }
1.91 raeburn 346: &Apache::loncommon::content_type($r,'text/html');
1.93 raeburn 347: $r->header_out(Location => $furl);
1.91 raeburn 348: return REDIRECT;
349: } elsif ($direction eq 'endplacement') {
350: &Apache::loncommon::content_type($r,'text/html');
351: $r->send_http_header;
352: $r->print(&Apache::lonplacementtest::showresult());
353: return OK;
1.89 raeburn 354: }
1.87 raeburn 355: if ($env{'request.course.id'}) {
356: # Check if course needs to be re-initialized
357: my $loncaparev = $r->dir_config('lonVersion');
1.89 raeburn 358: ($reinitcheck,my @reinit) = &Apache::loncommon::needs_coursereinit($loncaparev);
359: if ($reinitcheck eq 'switch') {
1.87 raeburn 360: &Apache::loncommon::content_type($r,'text/html');
361: $r->send_http_header;
362: $r->print(&Apache::loncommon::check_release_result(@reinit));
363: return OK;
1.89 raeburn 364: } elsif ($reinitcheck eq 'update') {
1.87 raeburn 365: my $cnum = $env{'course.'.$env{'request.course.id'}.'.num'};
366: my $cdom = $env{'course.'.$env{'request.course.id'}.'.domain'};
1.89 raeburn 367: $preupdatepos = &Apache::lonnet::symbread($currenturl);
368: unless ($direction eq 'return') {
369: if (tie(%hash,'GDBM_File',$env{'request.course.fn'}.'_symb.db',
370: &GDBM_READER(),0640)) {
371: $last=$hash{'last_known'};
372: untie(%hash);
373: }
374: }
1.87 raeburn 375: my ($furl,$ferr) = &Apache::lonuserstate::readmap("$cdom/$cnum");
376: if ($ferr) {
377: my $requrl = $r->uri;
378: $env{'user.error.msg'}="$requrl:bre:0:0:Course not initialized";
379: $env{'user.reinit'} = 1;
380: return HTTP_NOT_ACCEPTABLE;
1.89 raeburn 381: } else {
382: if ($last) {
383: my ($murl,$id,$fn)=&Apache::lonnet::decode_symb($last);
384: unless (&Apache::lonnet::symbverify($last,$fn)) {
385: undef($last);
386: }
387: }
1.87 raeburn 388: }
389: }
390: }
1.54 albertel 391: if ($direction eq 'firstres') {
1.69 www 392: my $furl=&first_accessible_resource();
1.95 raeburn 393: my $usehttp = &check_http_req(\$furl);
1.94 raeburn 394: if (($usehttp) && ($hostname ne '')) {
395: $furl='http://'.$hostname.$furl;
1.93 raeburn 396: } else {
397: $furl=&Apache::lonnet::absolute_url().$furl;
398: }
1.54 albertel 399: &Apache::loncommon::content_type($r,'text/html');
1.93 raeburn 400: $r->header_out(Location => $furl);
1.54 albertel 401: return REDIRECT;
402: }
1.89 raeburn 403: if ($direction eq 'return') {
1.10 www 404: # -------------------------------------------------------- Return to last known
1.93 raeburn 405: my ($newloc,$usehttp);
1.53 albertel 406: if (($last) && (tie(%hash,'GDBM_File',$env{'request.course.fn'}.'.db',
1.36 www 407: &GDBM_READER(),0640))) {
1.52 albertel 408: my ($murl,$id,$fn)=&Apache::lonnet::decode_symb($last);
1.50 albertel 409: $id=$hash{'map_pc_'.&Apache::lonnet::clutter($murl)}.'.'.$id;
410: $newloc=$hash{'src_'.$id};
411: if ($newloc) {
1.95 raeburn 412: $usehttp = &check_http_req(\$newloc);
1.92 raeburn 413: if ($hash{'encrypted_'.$id}) {
414: $newloc=&Apache::lonenc::encrypted($newloc);
415: } elsif ($newloc =~ m{^(/adm/wrapper/ext/[^\#]+)\#([^\#]+)$}) {
416: $newloc = $1.&escape('#').$2;
417: }
1.50 albertel 418: } else {
1.57 www 419: $newloc='/adm/navmaps';
1.50 albertel 420: }
1.36 www 421: untie %hash;
1.10 www 422: } else {
1.57 www 423: $newloc='/adm/navmaps';
1.89 raeburn 424: }
1.94 raeburn 425: if (($usehttp) && ($hostname ne '')) {
426: $newloc='http://'.$hostname.$newloc;
1.93 raeburn 427: } else {
428: $newloc=&Apache::lonnet::absolute_url().$newloc
429: }
1.89 raeburn 430: &Apache::loncommon::content_type($r,'text/html');
1.93 raeburn 431: $r->header_out(Location => $newloc);
1.89 raeburn 432: return REDIRECT;
1.10 www 433: }
1.35 www 434: #
435: # Is the current URL on the map? If not, start with last known URL
436: #
1.89 raeburn 437:
1.35 www 438: unless (&Apache::lonnet::is_on_map($currenturl)) {
1.89 raeburn 439: if ($preupdatepos) {
440: undef($preupdatepos);
441: } elsif (tie(%hash,'GDBM_File',$env{'request.course.fn'}.'_symb.db',
442: &GDBM_READER(),0640)) {
443: $last=$hash{'last_known'};
1.7 www 444: untie(%hash);
445: }
1.89 raeburn 446: my $newloc;
1.7 www 447: if ($last) {
1.52 albertel 448: $currenturl=&Apache::lonnet::clutter((&Apache::lonnet::decode_symb($last))[2]);
1.7 www 449: } else {
1.89 raeburn 450: &Apache::loncommon::content_type($r,'text/html');
451: $r->header_out(Location =>
452: &Apache::lonnet::absolute_url().
453: '/adm/navmaps');
454: return REDIRECT;
1.7 www 455: }
456: }
1.3 www 457: # ------------------------------------------- Do we have any idea where we are?
458: my $position;
1.89 raeburn 459: if ($preupdatepos) {
460: $position = $preupdatepos;
461: } else {
462: $position=Apache::lonnet::symbread($currenturl);
463: }
464: if ($position) {
1.3 www 465: # ------------------------------------------------------------------------- Yes
1.41 www 466: my ($startoutmap,$mapnum,$thisurl)=&Apache::lonnet::decode_symb($position);
1.52 albertel 467: $cachehash{$startoutmap}{$thisurl}=[$thisurl,$mapnum];
1.23 www 468: $cachehash{$startoutmap}{'last_known'}=
1.52 albertel 469: [&Apache::lonnet::declutter($currenturl),$mapnum];
1.20 albertel 470:
1.5 www 471: # ============================================================ Tie the big hash
1.53 albertel 472: if (tie(%hash,'GDBM_File',$env{'request.course.fn'}.'.db',
1.28 albertel 473: &GDBM_READER(),0640)) {
1.29 www 474: my $rid=$hash{'map_pc_'.&Apache::lonnet::clutter($startoutmap)}.
475: '.'.$mapnum;
1.14 www 476:
1.15 www 477: # ------------------------------------------------- Move forward, backward, etc
1.22 www 478: my $endupmap;
479: ($next,$endupmap)=&move($rid,$startoutmap,$direction);
1.15 www 480: # -------------------------------------- Do we have one and only one empty URL?
1.22 www 481: # We are now at at least one non-empty URL
1.4 www 482: # ----------------------------------------------------- Check out possibilities
483: if ($next) {
484: @possibilities=split(/\,/,$next);
485: if ($#possibilities==0) {
1.5 www 486: # ---------------------------------------------- Only one possibility, redirect
1.90 raeburn 487: ($redirecturl,$redirectsymb,$enc,$anchor)=&hash_src($next);
1.52 albertel 488: $cachehash{$endupmap}{$redirecturl}=
489: [$redirecturl,(split(/\./,$next))[1]];
1.4 www 490: } else {
1.5 www 491: # ------------------------ There are multiple possibilities for a next resource
492: $multichoice=1;
1.62 albertel 493: foreach my $id (@possibilities) {
494: $multichoicehash{'src_'.$id}=$hash{'src_'.$id};
495: $multichoicehash{'title_'.$id}=$hash{'title_'.$id};
496: $multichoicehash{'type_'.$id}=$hash{'type_'.$id};
497: (my $first, my $second) = $id =~ /(\d+).(\d+)/;
498: my $symbSrc = Apache::lonnet::declutter($hash{'src_'.$id});
499: $multichoicehash{'symb_'.$id} =
1.32 bowersj2 500: Apache::lonnet::declutter($hash{'map_id_'.$first}.'___'.
501: $second.'___'.$symbSrc);
502:
1.62 albertel 503: my ($choicemap,$choiceres)=split(/\./,$id);
1.52 albertel 504: my $map=&Apache::lonnet::declutter($hash{'src_'.$choicemap});
1.62 albertel 505: my $url=$multichoicehash{'src_'.$id};
1.52 albertel 506: $cachehash{$map}{$url}=[$url,$choiceres];
1.62 albertel 507: }
1.4 www 508: }
1.5 www 509: } else {
510: # -------------------------------------------------------------- No place to go
511: $multichoice=-1;
1.4 www 512: }
1.5 www 513: # ----------------- The program must come past this point to untie the big hash
1.3 www 514: untie(%hash);
1.5 www 515: # --------------------------------------------------------- Store position info
1.52 albertel 516: $cachehash{$startoutmap}{'last_direction'}=[$direction,'notasymb'];
1.86 raeburn 517: foreach my $thismap (keys(%cachehash)) {
1.52 albertel 518: my $mapnum=$cachehash{$thismap}->{'mapnum'};
519: delete($cachehash{$thismap}->{'mapnum'});
520: &Apache::lonnet::symblist($thismap,
521: %{$cachehash{$thismap}});
1.19 www 522: }
1.5 www 523: # ============================================== Do not return before this line
1.4 www 524: if ($redirecturl) {
1.5 www 525: # ----------------------------------------------------- There is a URL to go to
1.38 www 526: if ($direction eq 'forward') {
527: &Apache::lonnet::linklog($currenturl,$redirecturl);
528: }
529: if ($direction eq 'back') {
530: &Apache::lonnet::linklog($redirecturl,$currenturl);
531: }
1.85 musolffc 532: # ------------------------------------- Check for and display critical messages
1.96 ! raeburn 533: my ($redirect, $url) = &Apache::loncommon::critical_redirect(300,'flip');
1.89 raeburn 534: unless ($redirect) {
1.95 raeburn 535: my $usehttp = &check_http_req(\$redirecturl);
1.94 raeburn 536: if (($usehttp) && ($hostname ne '')) {
537: $url='http://'.$hostname.$redirecturl;
1.93 raeburn 538: } else {
539: $url=&Apache::lonnet::absolute_url().$redirecturl;
540: }
1.90 raeburn 541: my $addanchor;
542: if (($anchor ne '') && (!$enc || $env{'request.role.adv'})) {
543: $addanchor = 1;
544: $url =~ s/\#.+$//;
545: }
1.89 raeburn 546: $url = &add_get_param($url, { 'symb' => $redirectsymb});
1.90 raeburn 547: if ($addanchor) {
548: $url .= $anchor;
549: }
1.85 musolffc 550: }
1.89 raeburn 551: &Apache::loncommon::content_type($r,'text/html');
1.56 albertel 552: $r->header_out(Location => $url);
1.4 www 553: return REDIRECT;
1.5 www 554: } else {
555: # --------------------------------------------------------- There was a problem
1.51 albertel 556: &Apache::loncommon::content_type($r,'text/html');
1.8 www 557: $r->send_http_header;
1.59 www 558: my %lt=&Apache::lonlocal::texthash('title' => 'End of Sequence',
559: 'explain' =>
560: 'You have reached the end of the sequence of materials.',
561: 'back' => 'Go Back',
1.83 raeburn 562: 'nav' => 'Course Contents',
1.59 www 563: 'wherenext' =>
564: 'There are several possibilities of where to go next',
565: 'pick' =>
566: 'Please click on the the resource you intend to access',
567: 'titleheader' => 'Title',
1.89 raeburn 568: 'type' => 'Type',
569: 'update' => 'Content updated',
570: 'expupdate' => 'As a result of a recent update to the sequence of materials, it is not possible to complete the page flip.',
1.91 raeburn 571: 'gonav' => 'Go to the Contents page to select a resource to display.',
572: );
1.83 raeburn 573: if (&Apache::loncommon::course_type() eq 'Community') {
574: $lt{'nav'} = &mt('Community Contents');
575: }
1.8 www 576: if ($#possibilities>0) {
1.67 albertel 577: my $start_page=
578: &Apache::loncommon::start_page('Multiple Resources');
1.8 www 579: $r->print(<<ENDSTART);
1.67 albertel 580: $start_page
1.59 www 581: <h3>$lt{'wherenext'}</h3>
1.8 www 582: <p>
1.59 www 583: $lt{'pick'}:
1.8 www 584: <p>
1.79 bisitz 585: <table border="2">
1.59 www 586: <tr><th>$lt{'titleheader'}</th><th>$lt{'type'}</th></tr>
1.8 www 587: ENDSTART
1.62 albertel 588: foreach my $id (@possibilities) {
1.92 raeburn 589: my $src = $multichoicehash{'src_'.$id};
1.95 raeburn 590: my $usehttp = &check_http_req(\$src);
1.94 raeburn 591: if (($usehttp) && ($hostname ne '')) {
592: $src = 'http://'.$hostname.$src;
1.93 raeburn 593: }
1.8 www 594: $r->print(
595: '<tr><td><a href="'.
1.92 raeburn 596: &add_get_param($src,
1.66 albertel 597: {'symb' =>
598: $multichoicehash{'symb_'.$id},
599: }).'">'.
1.62 albertel 600: $multichoicehash{'title_'.$id}.
601: '</a></td><td>'.$multichoicehash{'type_'.$id}.
1.8 www 602: '</td></tr>');
1.26 www 603: }
1.59 www 604: $r->print('</table>');
1.8 www 605: } else {
1.89 raeburn 606: if ($reinitcheck) {
607: if (&Apache::loncommon::course_type() eq 'Community') {
608: $r->print(
609: &Apache::loncommon::start_page('Community Contents Updated'));
610: } else {
611: $r->print(
612: &Apache::loncommon::start_page('Course Contents Updated'));
613: }
614: $r->print('<h2>'.$lt{'update'}.'</h2>'
615: .'<p>'.$lt{'expupdate'}.'<br />'
616: .$lt{'gonav'}.'</p>');
617: } else {
1.91 raeburn 618: if (($env{'course.'.$env{'request.course.id'}.'.type'} eq 'Placement') &&
619: (!$env{'request.role.adv'})) {
620: my ($score,$incomplete) = &Apache::lonplacementtest::check_completion(undef,undef,1);
621: if ($incomplete) {
622: $r->print(&Apache::lonplacementtest::showincomplete($incomplete));
623: } else {
624: $r->print(&Apache::lonplacementtest::showresult(1));
625: }
626: } else {
627: $r->print(
628: &Apache::loncommon::start_page('No Resource')
629: .'<h2>'.$lt{'title'}.'</h2>'
630: .'<p>'.$lt{'explain'}.'</p>');
631: }
632: }
633: }
634: unless (($env{'course.'.$env{'request.course.id'}.'.type'} eq 'Placement') ||
635: ($env{'request.role.adv'})) {
636: if ((!@possibilities) && ($reinitcheck)) {
637: $r->print(
638: &Apache::lonhtmlcommon::actionbox(
639: ['<a href="/adm/navmaps">'.$lt{'nav'}.'</a></li>'
640: ]));
641: } else {
1.89 raeburn 642: $r->print(
1.91 raeburn 643: &Apache::lonhtmlcommon::actionbox(
644: ['<a href="/adm/flip?postdata=return:">'.$lt{'back'}.'</a></li>',
645: '<a href="/adm/navmaps">'.$lt{'nav'}.'</a></li>'
646: ]));
1.89 raeburn 647: }
1.91 raeburn 648:
1.82 bisitz 649: }
1.89 raeburn 650: $r->print(&Apache::loncommon::end_page());
651:
1.59 www 652: return OK;
653: }
1.5 www 654: } else {
655: # ------------------------------------------------- Problem, could not tie hash
1.53 albertel 656: $env{'user.error.msg'}="/adm/flip:bre:0:1:Course Data Missing";
1.5 www 657: return HTTP_NOT_ACCEPTABLE;
1.3 www 658: }
1.5 www 659: } else {
660: # ---------------------------------------- No, could not determine where we are
1.42 albertel 661: $r->internal_redirect('/adm/ambiguous');
1.81 raeburn 662: return OK;
1.2 www 663: }
1.5 www 664: } else {
1.2 www 665: # -------------------------- Class was not initialized or page fliped strangely
1.53 albertel 666: $env{'user.error.msg'}="/adm/flip:bre:0:0:Choose Course";
1.2 www 667: return HTTP_NOT_ACCEPTABLE;
668: }
1.1 www 669: }
670:
671: 1;
672: __END__
673:
1.77 jms 674: =pod
675:
676: =head1 NAME
677:
678: Apache::lonpageflip
679:
680: =head1 SYNOPSIS
681:
682: Deals with forward, backward, and other page flips.
683:
684: This is part of the LearningOnline Network with CAPA project
685: described at http://www.lon-capa.org.
686:
687: =head1 OVERVIEW
688:
689: (empty)
690:
691: =head1 SUBROUTINES
692:
693: =over cleanup()
694:
695: =item addrid()
696:
697: =item fullmove()
698:
699: =item hash_src()
700:
701: =item move()
702:
703: =item get_next_possible_move()
704:
705: =item first_accessible_resource()
706:
707: =item handler()
708:
709: =back
710:
711: =cut
1.1 www 712:
713:
714:
715:
716:
717:
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>