Annotation of rat/lonpageflip.pm, revision 1.92
1.1 www 1: # The LearningOnline Network with CAPA
2: #
3: # Page flip handler
4: #
1.92 ! raeburn 5: # $Id: lonpageflip.pm,v 1.91 2016/05/30 02:52:42 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 });
1.92 ! raeburn 248: &check_for_syllabus(\$furl);
1.69 www 249: if ($hash{'encrypted_'.$newrid}) {
250: $furl=&Apache::lonenc::encrypted($furl);
251: }
252: }
253: untie(%hash);
254: return $furl;
255: } else {
256: return '/adm/navmaps';
257: }
258: }
259:
1.91 raeburn 260: sub first_answerable_ressymb {
261: my $navmap = Apache::lonnavmaps::navmap->new;
262: return unless (ref($navmap));
263: my $iterator = $navmap->getIterator(undef,undef,undef,1);
264: return unless (ref($iterator));
265: my ($curRes,$result);
266: while ($curRes = $iterator->next()) {
267: if (ref($curRes) && $curRes->is_problem()) {
268: foreach my $part (@{$curRes->parts()}) {
269: if ($curRes->tries($part) < $curRes->maxtries($part)) {
270: $result = $curRes->link().'?symb='.$curRes->shown_symb();
271: last;
272: }
273: }
274: }
275: }
276: if ($result) {
277: return $result;
278: } else {
279: return &first_accessible_resource();
280: }
281: }
282:
1.92 ! raeburn 283: sub check_for_syllabus {
! 284: my ($srcref) = @_;
! 285: return unless (ref($srcref) eq 'SCALAR');
! 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';
! 293: }
! 294: }
! 295: }
! 296:
1.1 www 297: # ================================================================ Main Handler
298:
299: sub handler {
1.2 www 300: my $r=shift;
1.1 www 301:
302: # ------------------------------------------- Set document type for header only
303:
1.2 www 304: if ($r->header_only) {
1.51 albertel 305: &Apache::loncommon::content_type($r,'text/html');
306: $r->send_http_header;
307: return OK;
1.2 www 308: }
309:
1.5 www 310: my %cachehash=();
311: my $multichoice=0;
312: my %multichoicehash=();
1.90 raeburn 313: my ($redirecturl,$redirectsymb,$enc,$anchor);
1.4 www 314: my $next='';
315: my @possibilities=();
1.37 www 316: &Apache::loncommon::get_unprocessed_cgi($ENV{'QUERY_STRING'},['postdata']);
1.53 albertel 317: if (($env{'form.postdata'})&&($env{'request.course.fn'})) {
1.88 raeburn 318: my ($direction,$currenturl) = ($env{'form.postdata'}=~/(\w+)\:(.*)/);
1.89 raeburn 319: if ($currenturl=~m|^/enc/|) {
320: $currenturl=&Apache::lonenc::unencrypted($currenturl);
321: }
322: $currenturl=~s/\.\d+\.(\w+)$/\.$1/;
323: $currenturl=~s/^https?\:\/\///;
324: $currenturl=~s/^[^\/]+//;
325: my ($preupdatepos,$last,$reinitcheck);
326: if ($direction eq 'return') {
327: if (tie(%hash,'GDBM_File',$env{'request.course.fn'}.'_symb.db',
328: &GDBM_READER(),0640)) {
329: $last=$hash{'last_known'};
330: untie(%hash);
331: }
1.91 raeburn 332: } elsif ($direction eq 'firstanswerable') {
333: my $furl = &first_answerable_ressymb();
334: &Apache::loncommon::content_type($r,'text/html');
335: $r->header_out(Location =>
336: &Apache::lonnet::absolute_url().$furl);
337: return REDIRECT;
338: } elsif ($direction eq 'endplacement') {
339: &Apache::loncommon::content_type($r,'text/html');
340: $r->send_http_header;
341: $r->print(&Apache::lonplacementtest::showresult());
342: return OK;
1.89 raeburn 343: }
1.87 raeburn 344: if ($env{'request.course.id'}) {
345: # Check if course needs to be re-initialized
346: my $loncaparev = $r->dir_config('lonVersion');
1.89 raeburn 347: ($reinitcheck,my @reinit) = &Apache::loncommon::needs_coursereinit($loncaparev);
348: if ($reinitcheck eq 'switch') {
1.87 raeburn 349: &Apache::loncommon::content_type($r,'text/html');
350: $r->send_http_header;
351: $r->print(&Apache::loncommon::check_release_result(@reinit));
352: return OK;
1.89 raeburn 353: } elsif ($reinitcheck eq 'update') {
1.87 raeburn 354: my $cnum = $env{'course.'.$env{'request.course.id'}.'.num'};
355: my $cdom = $env{'course.'.$env{'request.course.id'}.'.domain'};
1.89 raeburn 356: $preupdatepos = &Apache::lonnet::symbread($currenturl);
357: unless ($direction eq 'return') {
358: if (tie(%hash,'GDBM_File',$env{'request.course.fn'}.'_symb.db',
359: &GDBM_READER(),0640)) {
360: $last=$hash{'last_known'};
361: untie(%hash);
362: }
363: }
1.87 raeburn 364: my ($furl,$ferr) = &Apache::lonuserstate::readmap("$cdom/$cnum");
365: if ($ferr) {
366: my $requrl = $r->uri;
367: $env{'user.error.msg'}="$requrl:bre:0:0:Course not initialized";
368: $env{'user.reinit'} = 1;
369: return HTTP_NOT_ACCEPTABLE;
1.89 raeburn 370: } else {
371: if ($last) {
372: my ($murl,$id,$fn)=&Apache::lonnet::decode_symb($last);
373: unless (&Apache::lonnet::symbverify($last,$fn)) {
374: undef($last);
375: }
376: }
1.87 raeburn 377: }
378: }
379: }
1.54 albertel 380: if ($direction eq 'firstres') {
1.69 www 381: my $furl=&first_accessible_resource();
1.54 albertel 382: &Apache::loncommon::content_type($r,'text/html');
383: $r->header_out(Location =>
1.71 albertel 384: &Apache::lonnet::absolute_url().$furl);
1.54 albertel 385:
386: return REDIRECT;
387: }
1.89 raeburn 388: if ($direction eq 'return') {
1.10 www 389: # -------------------------------------------------------- Return to last known
390: my $newloc;
1.53 albertel 391: if (($last) && (tie(%hash,'GDBM_File',$env{'request.course.fn'}.'.db',
1.36 www 392: &GDBM_READER(),0640))) {
1.52 albertel 393: my ($murl,$id,$fn)=&Apache::lonnet::decode_symb($last);
1.50 albertel 394: $id=$hash{'map_pc_'.&Apache::lonnet::clutter($murl)}.'.'.$id;
395: $newloc=$hash{'src_'.$id};
396: if ($newloc) {
1.92 ! raeburn 397: &check_for_syllabus(\$newloc);
! 398: if ($hash{'encrypted_'.$id}) {
! 399: $newloc=&Apache::lonenc::encrypted($newloc);
! 400: } elsif ($newloc =~ m{^(/adm/wrapper/ext/[^\#]+)\#([^\#]+)$}) {
! 401: $newloc = $1.&escape('#').$2;
! 402: }
1.50 albertel 403: } else {
1.57 www 404: $newloc='/adm/navmaps';
1.50 albertel 405: }
1.36 www 406: untie %hash;
1.10 www 407: } else {
1.57 www 408: $newloc='/adm/navmaps';
1.89 raeburn 409: }
410: &Apache::loncommon::content_type($r,'text/html');
411: $r->header_out(Location =>
412: &Apache::lonnet::absolute_url().$newloc);
1.54 albertel 413:
1.89 raeburn 414: return REDIRECT;
1.10 www 415: }
1.35 www 416: #
417: # Is the current URL on the map? If not, start with last known URL
418: #
1.89 raeburn 419:
1.35 www 420: unless (&Apache::lonnet::is_on_map($currenturl)) {
1.89 raeburn 421: if ($preupdatepos) {
422: undef($preupdatepos);
423: } elsif (tie(%hash,'GDBM_File',$env{'request.course.fn'}.'_symb.db',
424: &GDBM_READER(),0640)) {
425: $last=$hash{'last_known'};
1.7 www 426: untie(%hash);
427: }
1.89 raeburn 428: my $newloc;
1.7 www 429: if ($last) {
1.52 albertel 430: $currenturl=&Apache::lonnet::clutter((&Apache::lonnet::decode_symb($last))[2]);
1.7 www 431: } else {
1.89 raeburn 432: &Apache::loncommon::content_type($r,'text/html');
433: $r->header_out(Location =>
434: &Apache::lonnet::absolute_url().
435: '/adm/navmaps');
436: return REDIRECT;
1.7 www 437: }
438: }
1.3 www 439: # ------------------------------------------- Do we have any idea where we are?
440: my $position;
1.89 raeburn 441: if ($preupdatepos) {
442: $position = $preupdatepos;
443: } else {
444: $position=Apache::lonnet::symbread($currenturl);
445: }
446: if ($position) {
1.3 www 447: # ------------------------------------------------------------------------- Yes
1.41 www 448: my ($startoutmap,$mapnum,$thisurl)=&Apache::lonnet::decode_symb($position);
1.52 albertel 449: $cachehash{$startoutmap}{$thisurl}=[$thisurl,$mapnum];
1.23 www 450: $cachehash{$startoutmap}{'last_known'}=
1.52 albertel 451: [&Apache::lonnet::declutter($currenturl),$mapnum];
1.20 albertel 452:
1.5 www 453: # ============================================================ Tie the big hash
1.53 albertel 454: if (tie(%hash,'GDBM_File',$env{'request.course.fn'}.'.db',
1.28 albertel 455: &GDBM_READER(),0640)) {
1.29 www 456: my $rid=$hash{'map_pc_'.&Apache::lonnet::clutter($startoutmap)}.
457: '.'.$mapnum;
1.14 www 458:
1.15 www 459: # ------------------------------------------------- Move forward, backward, etc
1.22 www 460: my $endupmap;
461: ($next,$endupmap)=&move($rid,$startoutmap,$direction);
1.15 www 462: # -------------------------------------- Do we have one and only one empty URL?
1.22 www 463: # We are now at at least one non-empty URL
1.4 www 464: # ----------------------------------------------------- Check out possibilities
465: if ($next) {
466: @possibilities=split(/\,/,$next);
467: if ($#possibilities==0) {
1.5 www 468: # ---------------------------------------------- Only one possibility, redirect
1.90 raeburn 469: ($redirecturl,$redirectsymb,$enc,$anchor)=&hash_src($next);
1.52 albertel 470: $cachehash{$endupmap}{$redirecturl}=
471: [$redirecturl,(split(/\./,$next))[1]];
1.4 www 472: } else {
1.5 www 473: # ------------------------ There are multiple possibilities for a next resource
474: $multichoice=1;
1.62 albertel 475: foreach my $id (@possibilities) {
476: $multichoicehash{'src_'.$id}=$hash{'src_'.$id};
477: $multichoicehash{'title_'.$id}=$hash{'title_'.$id};
478: $multichoicehash{'type_'.$id}=$hash{'type_'.$id};
479: (my $first, my $second) = $id =~ /(\d+).(\d+)/;
480: my $symbSrc = Apache::lonnet::declutter($hash{'src_'.$id});
481: $multichoicehash{'symb_'.$id} =
1.32 bowersj2 482: Apache::lonnet::declutter($hash{'map_id_'.$first}.'___'.
483: $second.'___'.$symbSrc);
484:
1.62 albertel 485: my ($choicemap,$choiceres)=split(/\./,$id);
1.52 albertel 486: my $map=&Apache::lonnet::declutter($hash{'src_'.$choicemap});
1.62 albertel 487: my $url=$multichoicehash{'src_'.$id};
1.52 albertel 488: $cachehash{$map}{$url}=[$url,$choiceres];
1.62 albertel 489: }
1.4 www 490: }
1.5 www 491: } else {
492: # -------------------------------------------------------------- No place to go
493: $multichoice=-1;
1.4 www 494: }
1.5 www 495: # ----------------- The program must come past this point to untie the big hash
1.3 www 496: untie(%hash);
1.5 www 497: # --------------------------------------------------------- Store position info
1.52 albertel 498: $cachehash{$startoutmap}{'last_direction'}=[$direction,'notasymb'];
1.86 raeburn 499: foreach my $thismap (keys(%cachehash)) {
1.52 albertel 500: my $mapnum=$cachehash{$thismap}->{'mapnum'};
501: delete($cachehash{$thismap}->{'mapnum'});
502: &Apache::lonnet::symblist($thismap,
503: %{$cachehash{$thismap}});
1.19 www 504: }
1.5 www 505: # ============================================== Do not return before this line
1.4 www 506: if ($redirecturl) {
1.5 www 507: # ----------------------------------------------------- There is a URL to go to
1.38 www 508: if ($direction eq 'forward') {
509: &Apache::lonnet::linklog($currenturl,$redirecturl);
510: }
511: if ($direction eq 'back') {
512: &Apache::lonnet::linklog($redirecturl,$currenturl);
513: }
1.85 musolffc 514: # ------------------------------------- Check for and display critical messages
515: my ($redirect, $url) = &Apache::loncommon::critical_redirect(300);
1.89 raeburn 516: unless ($redirect) {
1.92 ! raeburn 517: &check_for_syllabus(\$redirecturl);
1.85 musolffc 518: $url=&Apache::lonnet::absolute_url().$redirecturl;
1.90 raeburn 519: my $addanchor;
520: if (($anchor ne '') && (!$enc || $env{'request.role.adv'})) {
521: $addanchor = 1;
522: $url =~ s/\#.+$//;
523: }
1.89 raeburn 524: $url = &add_get_param($url, { 'symb' => $redirectsymb});
1.90 raeburn 525: if ($addanchor) {
526: $url .= $anchor;
527: }
1.85 musolffc 528: }
1.89 raeburn 529: &Apache::loncommon::content_type($r,'text/html');
1.56 albertel 530: $r->header_out(Location => $url);
1.4 www 531: return REDIRECT;
1.5 www 532: } else {
533: # --------------------------------------------------------- There was a problem
1.51 albertel 534: &Apache::loncommon::content_type($r,'text/html');
1.8 www 535: $r->send_http_header;
1.59 www 536: my %lt=&Apache::lonlocal::texthash('title' => 'End of Sequence',
537: 'explain' =>
538: 'You have reached the end of the sequence of materials.',
539: 'back' => 'Go Back',
1.83 raeburn 540: 'nav' => 'Course Contents',
1.59 www 541: 'wherenext' =>
542: 'There are several possibilities of where to go next',
543: 'pick' =>
544: 'Please click on the the resource you intend to access',
545: 'titleheader' => 'Title',
1.89 raeburn 546: 'type' => 'Type',
547: 'update' => 'Content updated',
548: '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 549: 'gonav' => 'Go to the Contents page to select a resource to display.',
550: );
1.83 raeburn 551: if (&Apache::loncommon::course_type() eq 'Community') {
552: $lt{'nav'} = &mt('Community Contents');
553: }
1.8 www 554: if ($#possibilities>0) {
1.67 albertel 555: my $start_page=
556: &Apache::loncommon::start_page('Multiple Resources');
1.8 www 557: $r->print(<<ENDSTART);
1.67 albertel 558: $start_page
1.59 www 559: <h3>$lt{'wherenext'}</h3>
1.8 www 560: <p>
1.59 www 561: $lt{'pick'}:
1.8 www 562: <p>
1.79 bisitz 563: <table border="2">
1.59 www 564: <tr><th>$lt{'titleheader'}</th><th>$lt{'type'}</th></tr>
1.8 www 565: ENDSTART
1.62 albertel 566: foreach my $id (@possibilities) {
1.92 ! raeburn 567: my $src = $multichoicehash{'src_'.$id};
! 568: &check_for_syllabus(\$src);
1.8 www 569: $r->print(
570: '<tr><td><a href="'.
1.92 ! raeburn 571: &add_get_param($src,
1.66 albertel 572: {'symb' =>
573: $multichoicehash{'symb_'.$id},
574: }).'">'.
1.62 albertel 575: $multichoicehash{'title_'.$id}.
576: '</a></td><td>'.$multichoicehash{'type_'.$id}.
1.8 www 577: '</td></tr>');
1.26 www 578: }
1.59 www 579: $r->print('</table>');
1.8 www 580: } else {
1.89 raeburn 581: if ($reinitcheck) {
582: if (&Apache::loncommon::course_type() eq 'Community') {
583: $r->print(
584: &Apache::loncommon::start_page('Community Contents Updated'));
585: } else {
586: $r->print(
587: &Apache::loncommon::start_page('Course Contents Updated'));
588: }
589: $r->print('<h2>'.$lt{'update'}.'</h2>'
590: .'<p>'.$lt{'expupdate'}.'<br />'
591: .$lt{'gonav'}.'</p>');
592: } else {
1.91 raeburn 593: if (($env{'course.'.$env{'request.course.id'}.'.type'} eq 'Placement') &&
594: (!$env{'request.role.adv'})) {
595: my ($score,$incomplete) = &Apache::lonplacementtest::check_completion(undef,undef,1);
596: if ($incomplete) {
597: $r->print(&Apache::lonplacementtest::showincomplete($incomplete));
598: } else {
599: $r->print(&Apache::lonplacementtest::showresult(1));
600: }
601: } else {
602: $r->print(
603: &Apache::loncommon::start_page('No Resource')
604: .'<h2>'.$lt{'title'}.'</h2>'
605: .'<p>'.$lt{'explain'}.'</p>');
606: }
607: }
608: }
609: unless (($env{'course.'.$env{'request.course.id'}.'.type'} eq 'Placement') ||
610: ($env{'request.role.adv'})) {
611: if ((!@possibilities) && ($reinitcheck)) {
612: $r->print(
613: &Apache::lonhtmlcommon::actionbox(
614: ['<a href="/adm/navmaps">'.$lt{'nav'}.'</a></li>'
615: ]));
616: } else {
1.89 raeburn 617: $r->print(
1.91 raeburn 618: &Apache::lonhtmlcommon::actionbox(
619: ['<a href="/adm/flip?postdata=return:">'.$lt{'back'}.'</a></li>',
620: '<a href="/adm/navmaps">'.$lt{'nav'}.'</a></li>'
621: ]));
1.89 raeburn 622: }
1.91 raeburn 623:
1.82 bisitz 624: }
1.89 raeburn 625: $r->print(&Apache::loncommon::end_page());
626:
1.59 www 627: return OK;
628: }
1.5 www 629: } else {
630: # ------------------------------------------------- Problem, could not tie hash
1.53 albertel 631: $env{'user.error.msg'}="/adm/flip:bre:0:1:Course Data Missing";
1.5 www 632: return HTTP_NOT_ACCEPTABLE;
1.3 www 633: }
1.5 www 634: } else {
635: # ---------------------------------------- No, could not determine where we are
1.42 albertel 636: $r->internal_redirect('/adm/ambiguous');
1.81 raeburn 637: return OK;
1.2 www 638: }
1.5 www 639: } else {
1.2 www 640: # -------------------------- Class was not initialized or page fliped strangely
1.53 albertel 641: $env{'user.error.msg'}="/adm/flip:bre:0:0:Choose Course";
1.2 www 642: return HTTP_NOT_ACCEPTABLE;
643: }
1.1 www 644: }
645:
646: 1;
647: __END__
648:
1.77 jms 649: =pod
650:
651: =head1 NAME
652:
653: Apache::lonpageflip
654:
655: =head1 SYNOPSIS
656:
657: Deals with forward, backward, and other page flips.
658:
659: This is part of the LearningOnline Network with CAPA project
660: described at http://www.lon-capa.org.
661:
662: =head1 OVERVIEW
663:
664: (empty)
665:
666: =head1 SUBROUTINES
667:
668: =over cleanup()
669:
670: =item addrid()
671:
672: =item fullmove()
673:
674: =item hash_src()
675:
676: =item move()
677:
678: =item get_next_possible_move()
679:
680: =item first_accessible_resource()
681:
682: =item handler()
683:
684: =back
685:
686: =cut
1.1 www 687:
688:
689:
690:
691:
692:
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>