Annotation of rat/lonpageflip.pm, revision 1.98
1.1 www 1: # The LearningOnline Network with CAPA
2: #
3: # Page flip handler
4: #
1.98 ! raeburn 5: # $Id: lonpageflip.pm,v 1.97 2017/11/16 13:42:01 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;
1.98 ! raeburn 105: my $deeplinkonly=0;
! 106: my $prev=$next;
! 107: my ($prevmapid)=split(/\./,$next);
1.72 albertel 108: do {
109: ($next,$endupmap)=&get_next_possible_move($next,$endupmap,$direction);
110:
111: my $url = $hash{'src_'.$next};
112: my ($mapid,$resid)=split(/\./,$next);
113: my $symb = &Apache::lonnet::encode_symb($hash{'map_id_'.$mapid},
114: $resid,$url);
115: if ($url eq '' || $symb eq '') {
116: $allowed = 0;
117: } else {
118: my $priv = &Apache::lonnet::allowed('bre',$url,$symb);
119: $allowed = (($priv eq 'F') || ($priv eq '2'));
120: }
1.98 ! raeburn 121: $deeplinkonly = 0;
! 122: if ($hash{'deeplinkonly_'.$next}) {
! 123: my ($value,$level) = split(/:/,$hash{'deeplinkonly_'.$next});
! 124: if ($level eq 'resource') {
! 125: $deeplinkonly = 1;
! 126: } elsif ($level eq 'map') {
! 127: if ($mapid != $prevmapid) {
! 128: $deeplinkonly = 1;
! 129: }
! 130: }
! 131: } elsif ($hash{'deeplinkonly_'.$prev}) {
! 132: my ($value,$level) = split(/:/,$hash{'deeplinkonly_'.$prev});
! 133: if ($level eq 'resource') {
! 134: $deeplinkonly = 1;
! 135: } elsif ($level eq 'map') {
! 136: if ($mapid != $prevmapid) {
! 137: $deeplinkonly = 1;
! 138: }
! 139: }
! 140: }
1.72 albertel 141: $safecount++;
142: } while ( ($next)
143: && ($next!~/\,/)
144: && (
145: (!$hash{'src_'.$next})
146: || (
1.98 ! raeburn 147: (!$env{'request.role.adv'})
! 148: && (($hash{'randomout_'.$next})
! 149: || ($deeplinkonly))
1.72 albertel 150: )
151: || (!$allowed)
152: )
153: && ($safecount<10000));
154:
155: return ($next,$endupmap);
156: }
157:
158: sub get_next_possible_move {
1.15 www 159: my ($rid,$mapurl,$direction)=@_;
1.23 www 160: my $startoutrid=$rid;
1.15 www 161:
162: my $next='';
163:
164: my $mincond=1;
165: my $posnext='';
166: if ($direction eq 'forward') {
167: # --------------------------------------------------------------------- Forward
1.33 www 168: while ($hash{'type_'.$rid} eq 'finish') {
169: $rid=$hash{'ids_'.$hash{'map_id_'.(split(/\./,$rid))[0]}};
1.15 www 170: }
1.61 albertel 171: foreach my $id (split(/\,/,$hash{'to_'.$rid})) {
1.64 albertel 172: my $condition= $hash{'conditions_'.$hash{'goesto_'.$id}};
173: my $rescond = &Apache::lonnet::docondval($condition);
174: my $linkcond = &Apache::lonnet::directcondval($hash{'condid_'.$hash{'undercond_'.$id}});
175: my $thiscond = ($rescond<$linkcond)?$rescond:$linkcond;
176: if ($thiscond>=$mincond) {
1.15 www 177: if ($posnext) {
1.61 albertel 178: $posnext.=','.$id.':'.$thiscond;
1.15 www 179: } else {
1.61 albertel 180: $posnext=$id.':'.$thiscond;
1.15 www 181: }
182: if ($thiscond>$mincond) { $mincond=$thiscond; }
183: }
1.61 albertel 184: }
185: foreach my $id (split(/\,/,$posnext)) {
186: my ($linkid,$condval)=split(/\:/,$id);
1.15 www 187: if ($condval>=$mincond) {
188: $next=&addrid($next,$hash{'goesto_'.$linkid},
189: $hash{'condid_'.$hash{'undercond_'.$linkid}});
190: }
1.61 albertel 191: }
1.15 www 192: if ($hash{'is_map_'.$next}) {
1.23 www 193: # This jumps to the beginning of a new map (going down level)
1.15 www 194: if (
195: $hash{'map_type_'.$hash{'map_pc_'.$hash{'src_'.$next}}} eq 'sequence') {
196: $mapurl=$hash{'src_'.$next};
197: $next=$hash{'map_start_'.$hash{'src_'.$next}};
1.47 raeburn 198: } elsif (
199: # This jumps back up from an empty sequence, to a page up one level
200: $hash{'map_type_'.$hash{'map_pc_'.$hash{'src_'.$next}}} eq 'page') {
201: $mapurl=$hash{'map_id_'.(split(/\./,$next))[0]};
1.15 www 202: }
1.23 www 203: } elsif
204: ((split(/\./,$startoutrid))[0]!=(split(/\./,$next))[0]) {
205: # This comes up from a map (coming up one level);
206: $mapurl=$hash{'map_id_'.(split(/\./,$next))[0]};
1.61 albertel 207: }
1.15 www 208: } elsif ($direction eq 'back') {
209: # ------------------------------------------------------------------- Backwards
1.33 www 210: while ($hash{'type_'.$rid} eq 'start') {
211: $rid=$hash{'ids_'.$hash{'map_id_'.(split(/\./,$rid))[0]}};
212: }
1.62 albertel 213: foreach my $id (split(/\,/,$hash{'from_'.$rid})) {
1.64 albertel 214: my $condition= $hash{'conditions_'.$hash{'comesfrom_'.$id}};
215: my $rescond = &Apache::lonnet::docondval($condition);
216: my $linkcond = &Apache::lonnet::directcondval($hash{'condid_'.$hash{'undercond_'.$id}});
217: my $thiscond = ($rescond<$linkcond)?$rescond:$linkcond;
1.62 albertel 218: if ($thiscond>=$mincond) {
219: if ($posnext) {
220: $posnext.=','.$id.':'.$thiscond;
221: } else {
222: $posnext=$id.':'.$thiscond;
223: }
224: if ($thiscond>$mincond) { $mincond=$thiscond; }
225: }
226: }
227: foreach my $id (split(/\,/,$posnext)) {
228: my ($linkid,$condval)=split(/\:/,$id);
229: if ($condval>=$mincond) {
230: $next=&addrid($next,$hash{'comesfrom_'.$linkid},
231: $hash{'condid_'.$hash{'undercond_'.$linkid}});
232: }
233: }
1.15 www 234: if ($hash{'is_map_'.$next}) {
1.24 www 235: # This jumps to the end of a new map (going down one level)
1.15 www 236: if (
237: $hash{'map_type_'.$hash{'map_pc_'.$hash{'src_'.$next}}} eq 'sequence') {
238: $mapurl=$hash{'src_'.$next};
239: $next=$hash{'map_finish_'.$hash{'src_'.$next}};
1.47 raeburn 240: } elsif (
241: $hash{'map_type_'.$hash{'map_pc_'.$hash{'src_'.$next}}} eq 'page') {
242: # This jumps back up from an empty sequence, to a page up one level
243: $mapurl=$hash{'map_id_'.(split(/\./,$next))[0]};
244: }
1.24 www 245: } elsif
246: ((split(/\./,$startoutrid))[0]!=(split(/\./,$next))[0]) {
247: # This comes back up from a map (going up one level);
248: $mapurl=$hash{'map_id_'.(split(/\./,$next))[0]};
1.15 www 249: }
250: }
251: return ($next,$mapurl);
252: }
253:
1.69 www 254: sub first_accessible_resource {
255: my $furl;
256: if (tie(%hash,'GDBM_File',$env{'request.course.fn'}.'.db',
257: &GDBM_READER(),0640)) {
258: $furl=$hash{'first_url'};
1.74 albertel 259: my %args;
260: my ($url,$args) = split(/\?/,$furl);
261: foreach my $pair (split(/\&/,$args)) {
262: my ($name,$value) = split(/=/,$pair);
263: $args{&unescape($name)} = &unescape($value);
264: }
265: if (!&Apache::lonnet::allowed('bre',$url,$args{'symb'})) {
1.69 www 266: # Wow, we cannot see this ... move forward to the next one that we can see
267: my ($newrid,$newmap)=&move($hash{'first_rid'},$hash{'first_mapurl'},'forward');
268: # Build the new URL
1.73 albertel 269: my ($newmapid,$newresid)=split(/\./,$newrid);
1.69 www 270: my $symb=&Apache::lonnet::encode_symb($newmap,$newresid,$hash{'src_'.$newrid});
271: $furl=&add_get_param($hash{'src_'.$newrid},{ 'symb' => $symb });
272: if ($hash{'encrypted_'.$newrid}) {
273: $furl=&Apache::lonenc::encrypted($furl);
274: }
275: }
276: untie(%hash);
277: return $furl;
278: } else {
279: return '/adm/navmaps';
280: }
281: }
282:
1.91 raeburn 283: sub first_answerable_ressymb {
284: my $navmap = Apache::lonnavmaps::navmap->new;
285: return unless (ref($navmap));
286: my $iterator = $navmap->getIterator(undef,undef,undef,1);
287: return unless (ref($iterator));
288: my ($curRes,$result);
289: while ($curRes = $iterator->next()) {
290: if (ref($curRes) && $curRes->is_problem()) {
291: foreach my $part (@{$curRes->parts()}) {
292: if ($curRes->tries($part) < $curRes->maxtries($part)) {
293: $result = $curRes->link().'?symb='.$curRes->shown_symb();
294: last;
295: }
296: }
297: }
298: }
299: if ($result) {
300: return $result;
301: } else {
302: return &first_accessible_resource();
303: }
304: }
305:
1.95 raeburn 306: sub check_http_req {
1.92 raeburn 307: my ($srcref) = @_;
308: return unless (ref($srcref) eq 'SCALAR');
1.93 raeburn 309: my $usehttp;
1.92 raeburn 310: if ($env{'request.course.id'}) {
311: my $cnum = $env{'course.'.$env{'request.course.id'}.'.num'};
312: my $cdom = $env{'course.'.$env{'request.course.id'}.'.domain'};
313: if (($$srcref =~ m{^\Q/public/$cdom/$cnum/syllabus\E($|\?)}) &&
314: ($ENV{'SERVER_PORT'} == 443) &&
315: ($env{'course.'.$env{'request.course.id'}.'.externalsyllabus'} =~ m{^http://})) {
316: $$srcref .= (($$srcref =~/\?/)? '&':'?') . 'usehttp=1';
1.93 raeburn 317: $usehttp = 1;
1.95 raeburn 318: } elsif (($$srcref =~ m{^\Q/adm/wrapper/ext/\E(?!https:)}) &&
319: ($ENV{'SERVER_PORT'} == 443)) {
320: $usehttp = 1;
1.92 raeburn 321: }
322: }
1.93 raeburn 323: return $usehttp;
1.92 raeburn 324: }
325:
1.97 raeburn 326: sub reinited_js {
327: my ($url,$cid,$timeout) = @_;
328: if (!$timeout) {
329: $timeout = 0;
330: }
331: return <<"END";
332: <script type="text/javascript">
333: // <![CDATA[
334: setTimeout(function() {
335: var newurl = '$url';
336: if (document.getElementById('LC_update_$cid')) {
337: document.getElementById('LC_update_$cid').style.display = 'none';
338: }
339: if ((newurl !== null) && (newurl !== '') && (newurl !== 'undefined')) {
340: window.location.href = "$url";
341: }
342: }, $timeout);
343: // ]]>
344: </script>
345: END
346: }
347:
1.1 www 348: # ================================================================ Main Handler
349:
350: sub handler {
1.2 www 351: my $r=shift;
1.1 www 352:
353: # ------------------------------------------- Set document type for header only
354:
1.2 www 355: if ($r->header_only) {
1.51 albertel 356: &Apache::loncommon::content_type($r,'text/html');
357: $r->send_http_header;
358: return OK;
1.2 www 359: }
360:
1.5 www 361: my %cachehash=();
362: my $multichoice=0;
363: my %multichoicehash=();
1.97 raeburn 364: my %prog_state=();
1.98 ! raeburn 365: my ($redirecturl,$redirectsymb,$enc,$anchor,$deeplinklevel);
1.4 www 366: my $next='';
1.94 raeburn 367: my $hostname = $r->hostname();
1.4 www 368: my @possibilities=();
1.37 www 369: &Apache::loncommon::get_unprocessed_cgi($ENV{'QUERY_STRING'},['postdata']);
1.53 albertel 370: if (($env{'form.postdata'})&&($env{'request.course.fn'})) {
1.88 raeburn 371: my ($direction,$currenturl) = ($env{'form.postdata'}=~/(\w+)\:(.*)/);
1.89 raeburn 372: if ($currenturl=~m|^/enc/|) {
373: $currenturl=&Apache::lonenc::unencrypted($currenturl);
374: }
375: $currenturl=~s/\.\d+\.(\w+)$/\.$1/;
376: $currenturl=~s/^https?\:\/\///;
377: $currenturl=~s/^[^\/]+//;
378: my ($preupdatepos,$last,$reinitcheck);
379: if ($direction eq 'return') {
380: if (tie(%hash,'GDBM_File',$env{'request.course.fn'}.'_symb.db',
381: &GDBM_READER(),0640)) {
382: $last=$hash{'last_known'};
383: untie(%hash);
384: }
1.91 raeburn 385: } elsif ($direction eq 'firstanswerable') {
386: my $furl = &first_answerable_ressymb();
1.95 raeburn 387: my $usehttp = &check_http_req(\$furl);
1.94 raeburn 388: if (($usehttp) && ($hostname ne '')) {
389: $furl='http://'.$hostname.$furl;
1.93 raeburn 390: } else {
391: $furl=&Apache::lonnet::absolute_url().$furl;
392: }
1.91 raeburn 393: &Apache::loncommon::content_type($r,'text/html');
1.93 raeburn 394: $r->header_out(Location => $furl);
1.91 raeburn 395: return REDIRECT;
396: } elsif ($direction eq 'endplacement') {
397: &Apache::loncommon::content_type($r,'text/html');
398: $r->send_http_header;
399: $r->print(&Apache::lonplacementtest::showresult());
400: return OK;
1.89 raeburn 401: }
1.87 raeburn 402: if ($env{'request.course.id'}) {
403: # Check if course needs to be re-initialized
404: my $loncaparev = $r->dir_config('lonVersion');
1.89 raeburn 405: ($reinitcheck,my @reinit) = &Apache::loncommon::needs_coursereinit($loncaparev);
406: if ($reinitcheck eq 'switch') {
1.87 raeburn 407: &Apache::loncommon::content_type($r,'text/html');
408: $r->send_http_header;
409: $r->print(&Apache::loncommon::check_release_result(@reinit));
410: return OK;
1.89 raeburn 411: } elsif ($reinitcheck eq 'update') {
1.87 raeburn 412: my $cnum = $env{'course.'.$env{'request.course.id'}.'.num'};
413: my $cdom = $env{'course.'.$env{'request.course.id'}.'.domain'};
1.89 raeburn 414: $preupdatepos = &Apache::lonnet::symbread($currenturl);
415: unless ($direction eq 'return') {
416: if (tie(%hash,'GDBM_File',$env{'request.course.fn'}.'_symb.db',
417: &GDBM_READER(),0640)) {
418: $last=$hash{'last_known'};
419: untie(%hash);
420: }
421: }
1.97 raeburn 422: &Apache::loncommon::content_type($r,'text/html');
423: $r->send_http_header;
424: $r->print(&Apache::loncommon::start_page('Content Changed'));
425: my $preamble = '<div id="LC_update_'.$env{'request.course.id'}.'" class="LC_info">'.
426: '<br />'.
427: &mt('Your course session is being updated because of recent changes by course personnel.').
428: ' '.&mt('Please be patient.').'<br /></div>'.
429: '<div style="padding:0;clear:both;margin:0;border:0"></div>';
430: %prog_state = &Apache::lonhtmlcommon::Create_PrgWin($r,undef,$preamble);
431: &Apache::lonhtmlcommon::Update_PrgWin($r,\%prog_state,&mt('Updating course'));
1.87 raeburn 432: my ($furl,$ferr) = &Apache::lonuserstate::readmap("$cdom/$cnum");
1.97 raeburn 433: &Apache::lonhtmlcommon::Update_PrgWin($r,\%prog_state,&mt('Finished'));
1.87 raeburn 434: if ($ferr) {
1.97 raeburn 435: &Apache::lonhtmlcommon::Close_PrgWin($r,\%prog_state);
1.87 raeburn 436: my $requrl = $r->uri;
437: $env{'user.error.msg'}="$requrl:bre:0:0:Course not initialized";
438: $env{'user.reinit'} = 1;
439: return HTTP_NOT_ACCEPTABLE;
1.89 raeburn 440: } else {
441: if ($last) {
442: my ($murl,$id,$fn)=&Apache::lonnet::decode_symb($last);
443: unless (&Apache::lonnet::symbverify($last,$fn)) {
444: undef($last);
445: }
446: }
1.87 raeburn 447: }
448: }
449: }
1.54 albertel 450: if ($direction eq 'firstres') {
1.69 www 451: my $furl=&first_accessible_resource();
1.95 raeburn 452: my $usehttp = &check_http_req(\$furl);
1.94 raeburn 453: if (($usehttp) && ($hostname ne '')) {
454: $furl='http://'.$hostname.$furl;
1.93 raeburn 455: } else {
456: $furl=&Apache::lonnet::absolute_url().$furl;
457: }
1.97 raeburn 458: if ($reinitcheck eq 'update') {
459: &Apache::lonhtmlcommon::Close_PrgWin($r,\%prog_state);
460: $r->print(&reinited_js($furl,$env{'request.course.id'},100));
461: $r->print(&Apache::loncommon::end_page());
462: return OK;
463: } else {
464: &Apache::loncommon::content_type($r,'text/html');
465: $r->header_out(Location => $furl);
466: return REDIRECT;
467: }
1.54 albertel 468: }
1.89 raeburn 469: if ($direction eq 'return') {
1.10 www 470: # -------------------------------------------------------- Return to last known
1.93 raeburn 471: my ($newloc,$usehttp);
1.53 albertel 472: if (($last) && (tie(%hash,'GDBM_File',$env{'request.course.fn'}.'.db',
1.36 www 473: &GDBM_READER(),0640))) {
1.52 albertel 474: my ($murl,$id,$fn)=&Apache::lonnet::decode_symb($last);
1.50 albertel 475: $id=$hash{'map_pc_'.&Apache::lonnet::clutter($murl)}.'.'.$id;
476: $newloc=$hash{'src_'.$id};
477: if ($newloc) {
1.95 raeburn 478: $usehttp = &check_http_req(\$newloc);
1.92 raeburn 479: if ($hash{'encrypted_'.$id}) {
480: $newloc=&Apache::lonenc::encrypted($newloc);
481: } elsif ($newloc =~ m{^(/adm/wrapper/ext/[^\#]+)\#([^\#]+)$}) {
482: $newloc = $1.&escape('#').$2;
483: }
1.50 albertel 484: } else {
1.57 www 485: $newloc='/adm/navmaps';
1.50 albertel 486: }
1.36 www 487: untie %hash;
1.10 www 488: } else {
1.57 www 489: $newloc='/adm/navmaps';
1.89 raeburn 490: }
1.94 raeburn 491: if (($usehttp) && ($hostname ne '')) {
492: $newloc='http://'.$hostname.$newloc;
1.93 raeburn 493: } else {
494: $newloc=&Apache::lonnet::absolute_url().$newloc
495: }
1.97 raeburn 496: if ($reinitcheck eq 'update') {
497: $r->print(&reinited_js($newloc,$env{'request.course.id'},100));
498: $r->print(&Apache::loncommon::end_page());
499: return OK;
500: } else {
501: &Apache::loncommon::content_type($r,'text/html');
502: $r->header_out(Location => $newloc);
503: return REDIRECT;
504: }
1.10 www 505: }
1.35 www 506: #
507: # Is the current URL on the map? If not, start with last known URL
508: #
1.89 raeburn 509:
1.35 www 510: unless (&Apache::lonnet::is_on_map($currenturl)) {
1.89 raeburn 511: if ($preupdatepos) {
512: undef($preupdatepos);
513: } elsif (tie(%hash,'GDBM_File',$env{'request.course.fn'}.'_symb.db',
514: &GDBM_READER(),0640)) {
515: $last=$hash{'last_known'};
1.7 www 516: untie(%hash);
517: }
1.89 raeburn 518: my $newloc;
1.7 www 519: if ($last) {
1.52 albertel 520: $currenturl=&Apache::lonnet::clutter((&Apache::lonnet::decode_symb($last))[2]);
1.7 www 521: } else {
1.97 raeburn 522: my $newloc = &Apache::lonnet::absolute_url().
523: '/adm/navmaps';
524: if ($reinitcheck eq 'update') {
525: &Apache::lonhtmlcommon::Close_PrgWin($r,\%prog_state);
526: $r->print(&reinited_js($newloc,$env{'request.course.id'},100));
527: $r->print(&Apache::loncommon::end_page());
528: return OK;
529: } else {
530: &Apache::loncommon::content_type($r,'text/html');
531: $r->header_out(Location => $newloc);
532: return REDIRECT;
533: }
1.7 www 534: }
535: }
1.3 www 536: # ------------------------------------------- Do we have any idea where we are?
537: my $position;
1.89 raeburn 538: if ($preupdatepos) {
539: $position = $preupdatepos;
540: } else {
541: $position=Apache::lonnet::symbread($currenturl);
542: }
543: if ($position) {
1.3 www 544: # ------------------------------------------------------------------------- Yes
1.41 www 545: my ($startoutmap,$mapnum,$thisurl)=&Apache::lonnet::decode_symb($position);
1.52 albertel 546: $cachehash{$startoutmap}{$thisurl}=[$thisurl,$mapnum];
1.23 www 547: $cachehash{$startoutmap}{'last_known'}=
1.52 albertel 548: [&Apache::lonnet::declutter($currenturl),$mapnum];
1.20 albertel 549:
1.5 www 550: # ============================================================ Tie the big hash
1.53 albertel 551: if (tie(%hash,'GDBM_File',$env{'request.course.fn'}.'.db',
1.28 albertel 552: &GDBM_READER(),0640)) {
1.29 www 553: my $rid=$hash{'map_pc_'.&Apache::lonnet::clutter($startoutmap)}.
554: '.'.$mapnum;
1.14 www 555:
1.15 www 556: # ------------------------------------------------- Move forward, backward, etc
1.22 www 557: my $endupmap;
558: ($next,$endupmap)=&move($rid,$startoutmap,$direction);
1.15 www 559: # -------------------------------------- Do we have one and only one empty URL?
1.22 www 560: # We are now at at least one non-empty URL
1.4 www 561: # ----------------------------------------------------- Check out possibilities
562: if ($next) {
563: @possibilities=split(/\,/,$next);
564: if ($#possibilities==0) {
1.5 www 565: # ---------------------------------------------- Only one possibility, redirect
1.90 raeburn 566: ($redirecturl,$redirectsymb,$enc,$anchor)=&hash_src($next);
1.52 albertel 567: $cachehash{$endupmap}{$redirecturl}=
568: [$redirecturl,(split(/\./,$next))[1]];
1.4 www 569: } else {
1.5 www 570: # ------------------------ There are multiple possibilities for a next resource
571: $multichoice=1;
1.62 albertel 572: foreach my $id (@possibilities) {
573: $multichoicehash{'src_'.$id}=$hash{'src_'.$id};
574: $multichoicehash{'title_'.$id}=$hash{'title_'.$id};
575: $multichoicehash{'type_'.$id}=$hash{'type_'.$id};
576: (my $first, my $second) = $id =~ /(\d+).(\d+)/;
577: my $symbSrc = Apache::lonnet::declutter($hash{'src_'.$id});
578: $multichoicehash{'symb_'.$id} =
1.32 bowersj2 579: Apache::lonnet::declutter($hash{'map_id_'.$first}.'___'.
580: $second.'___'.$symbSrc);
581:
1.62 albertel 582: my ($choicemap,$choiceres)=split(/\./,$id);
1.52 albertel 583: my $map=&Apache::lonnet::declutter($hash{'src_'.$choicemap});
1.62 albertel 584: my $url=$multichoicehash{'src_'.$id};
1.52 albertel 585: $cachehash{$map}{$url}=[$url,$choiceres];
1.62 albertel 586: }
1.4 www 587: }
1.5 www 588: } else {
589: # -------------------------------------------------------------- No place to go
590: $multichoice=-1;
1.98 ! raeburn 591: if ($hash{'deeplinkonly_'.$rid}) {
! 592: (my $value,$deeplinklevel) = split(/:/,$hash{'deeplinkonly_'.$rid});
! 593: }
1.4 www 594: }
1.5 www 595: # ----------------- The program must come past this point to untie the big hash
1.3 www 596: untie(%hash);
1.5 www 597: # --------------------------------------------------------- Store position info
1.52 albertel 598: $cachehash{$startoutmap}{'last_direction'}=[$direction,'notasymb'];
1.86 raeburn 599: foreach my $thismap (keys(%cachehash)) {
1.52 albertel 600: my $mapnum=$cachehash{$thismap}->{'mapnum'};
601: delete($cachehash{$thismap}->{'mapnum'});
602: &Apache::lonnet::symblist($thismap,
603: %{$cachehash{$thismap}});
1.19 www 604: }
1.5 www 605: # ============================================== Do not return before this line
1.4 www 606: if ($redirecturl) {
1.5 www 607: # ----------------------------------------------------- There is a URL to go to
1.38 www 608: if ($direction eq 'forward') {
609: &Apache::lonnet::linklog($currenturl,$redirecturl);
610: }
611: if ($direction eq 'back') {
612: &Apache::lonnet::linklog($redirecturl,$currenturl);
613: }
1.85 musolffc 614: # ------------------------------------- Check for and display critical messages
1.96 raeburn 615: my ($redirect, $url) = &Apache::loncommon::critical_redirect(300,'flip');
1.89 raeburn 616: unless ($redirect) {
1.95 raeburn 617: my $usehttp = &check_http_req(\$redirecturl);
1.94 raeburn 618: if (($usehttp) && ($hostname ne '')) {
619: $url='http://'.$hostname.$redirecturl;
1.93 raeburn 620: } else {
621: $url=&Apache::lonnet::absolute_url().$redirecturl;
622: }
1.90 raeburn 623: my $addanchor;
624: if (($anchor ne '') && (!$enc || $env{'request.role.adv'})) {
625: $addanchor = 1;
626: $url =~ s/\#.+$//;
627: }
1.89 raeburn 628: $url = &add_get_param($url, { 'symb' => $redirectsymb});
1.90 raeburn 629: if ($addanchor) {
630: $url .= $anchor;
631: }
1.85 musolffc 632: }
1.97 raeburn 633: if ($reinitcheck eq 'update') {
634: &Apache::lonhtmlcommon::Close_PrgWin($r,\%prog_state);
635: $r->print(&reinited_js($url,$env{'request.course.id'},100));
636: $r->print(&Apache::loncommon::end_page());
637: return OK;
638: } else {
639: &Apache::loncommon::content_type($r,'text/html');
640: $r->header_out(Location => $url);
641: return REDIRECT;
642: }
1.5 www 643: } else {
644: # --------------------------------------------------------- There was a problem
1.51 albertel 645: &Apache::loncommon::content_type($r,'text/html');
1.8 www 646: $r->send_http_header;
1.59 www 647: my %lt=&Apache::lonlocal::texthash('title' => 'End of Sequence',
1.98 ! raeburn 648: 'deeplink' => 'No link available',
! 649: 'deeplinkres' =>
! 650: 'Navigation to other content is unavailable when accessing content via deep-linking',
! 651: 'deeplinkmap' =>
! 652: 'You have reached the end of the sequence of available materials for access via deep-linking',
1.59 www 653: 'explain' =>
654: 'You have reached the end of the sequence of materials.',
655: 'back' => 'Go Back',
1.83 raeburn 656: 'nav' => 'Course Contents',
1.59 www 657: 'wherenext' =>
658: 'There are several possibilities of where to go next',
659: 'pick' =>
660: 'Please click on the the resource you intend to access',
661: 'titleheader' => 'Title',
1.89 raeburn 662: 'type' => 'Type',
663: 'update' => 'Content updated',
664: '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 665: 'gonav' => 'Go to the Contents page to select a resource to display.',
666: );
1.83 raeburn 667: if (&Apache::loncommon::course_type() eq 'Community') {
668: $lt{'nav'} = &mt('Community Contents');
669: }
1.8 www 670: if ($#possibilities>0) {
1.67 albertel 671: my $start_page=
672: &Apache::loncommon::start_page('Multiple Resources');
1.8 www 673: $r->print(<<ENDSTART);
1.67 albertel 674: $start_page
1.59 www 675: <h3>$lt{'wherenext'}</h3>
1.8 www 676: <p>
1.59 www 677: $lt{'pick'}:
1.8 www 678: <p>
1.79 bisitz 679: <table border="2">
1.59 www 680: <tr><th>$lt{'titleheader'}</th><th>$lt{'type'}</th></tr>
1.8 www 681: ENDSTART
1.62 albertel 682: foreach my $id (@possibilities) {
1.92 raeburn 683: my $src = $multichoicehash{'src_'.$id};
1.95 raeburn 684: my $usehttp = &check_http_req(\$src);
1.94 raeburn 685: if (($usehttp) && ($hostname ne '')) {
686: $src = 'http://'.$hostname.$src;
1.93 raeburn 687: }
1.8 www 688: $r->print(
689: '<tr><td><a href="'.
1.92 raeburn 690: &add_get_param($src,
1.66 albertel 691: {'symb' =>
692: $multichoicehash{'symb_'.$id},
693: }).'">'.
1.62 albertel 694: $multichoicehash{'title_'.$id}.
695: '</a></td><td>'.$multichoicehash{'type_'.$id}.
1.8 www 696: '</td></tr>');
1.26 www 697: }
1.59 www 698: $r->print('</table>');
1.8 www 699: } else {
1.89 raeburn 700: if ($reinitcheck) {
701: if (&Apache::loncommon::course_type() eq 'Community') {
702: $r->print(
703: &Apache::loncommon::start_page('Community Contents Updated'));
704: } else {
705: $r->print(
706: &Apache::loncommon::start_page('Course Contents Updated'));
707: }
708: $r->print('<h2>'.$lt{'update'}.'</h2>'
709: .'<p>'.$lt{'expupdate'}.'<br />'
710: .$lt{'gonav'}.'</p>');
711: } else {
1.91 raeburn 712: if (($env{'course.'.$env{'request.course.id'}.'.type'} eq 'Placement') &&
713: (!$env{'request.role.adv'})) {
714: my ($score,$incomplete) = &Apache::lonplacementtest::check_completion(undef,undef,1);
715: if ($incomplete) {
716: $r->print(&Apache::lonplacementtest::showincomplete($incomplete));
717: } else {
718: $r->print(&Apache::lonplacementtest::showresult(1));
719: }
1.98 ! raeburn 720: } else {
1.91 raeburn 721: $r->print(
1.98 ! raeburn 722: &Apache::loncommon::start_page('No Resource'));
! 723: if ($deeplinklevel eq 'resource') {
! 724: $r->print('<h2>'.$lt{'deeplink'}.'</h2>'
! 725: .'<p>'.$lt{'deeplinkres'}.'</p>');
! 726: } elsif ($deeplinklevel eq 'map') {
! 727: $r->print('<h2>'.$lt{'title'}.'</h2>'
! 728: .'<p>'.$lt{'deeplinkmap'}.'</p>');
! 729: } else {
! 730: $r->print('<h2>'.$lt{'title'}.'</h2>'
! 731: .'<p>'.$lt{'explain'}.'</p>');
! 732: }
1.91 raeburn 733: }
734: }
735: }
736: unless (($env{'course.'.$env{'request.course.id'}.'.type'} eq 'Placement') ||
737: ($env{'request.role.adv'})) {
1.98 ! raeburn 738: if ($deeplinklevel) {
! 739: $r->print(
! 740: &Apache::lonhtmlcommon::actionbox(
! 741: ['<a href="/adm/flip?postdata=return:">'.$lt{'back'}.'</a>']));
! 742: } elsif ((!@possibilities) && ($reinitcheck)) {
1.91 raeburn 743: $r->print(
744: &Apache::lonhtmlcommon::actionbox(
745: ['<a href="/adm/navmaps">'.$lt{'nav'}.'</a></li>'
746: ]));
747: } else {
1.89 raeburn 748: $r->print(
1.91 raeburn 749: &Apache::lonhtmlcommon::actionbox(
750: ['<a href="/adm/flip?postdata=return:">'.$lt{'back'}.'</a></li>',
751: '<a href="/adm/navmaps">'.$lt{'nav'}.'</a></li>'
752: ]));
1.89 raeburn 753: }
1.91 raeburn 754:
1.82 bisitz 755: }
1.89 raeburn 756: $r->print(&Apache::loncommon::end_page());
757:
1.59 www 758: return OK;
759: }
1.5 www 760: } else {
761: # ------------------------------------------------- Problem, could not tie hash
1.97 raeburn 762: if ($reinitcheck eq 'update') {
763: &Apache::lonhtmlcommon::Close_PrgWin($r,\%prog_state);
764: $r->print(&Apache::loncommon::end_page());
765: }
1.53 albertel 766: $env{'user.error.msg'}="/adm/flip:bre:0:1:Course Data Missing";
1.5 www 767: return HTTP_NOT_ACCEPTABLE;
1.3 www 768: }
1.5 www 769: } else {
770: # ---------------------------------------- No, could not determine where we are
1.97 raeburn 771: my $newloc = '/adm/ambiguous';
772: if ($reinitcheck eq 'update') {
773: &Apache::lonhtmlcommon::Close_PrgWin($r,\%prog_state);
774: $r->print(&reinited_js($newloc,$env{'request.course.id'},100));
775: $r->print(&Apache::loncommon::end_page());
776: } else {
777: $r->internal_redirect($newloc);
778: }
1.81 raeburn 779: return OK;
1.2 www 780: }
1.5 www 781: } else {
1.2 www 782: # -------------------------- Class was not initialized or page fliped strangely
1.53 albertel 783: $env{'user.error.msg'}="/adm/flip:bre:0:0:Choose Course";
1.2 www 784: return HTTP_NOT_ACCEPTABLE;
785: }
1.1 www 786: }
787:
788: 1;
789: __END__
790:
1.77 jms 791: =pod
792:
793: =head1 NAME
794:
795: Apache::lonpageflip
796:
797: =head1 SYNOPSIS
798:
799: Deals with forward, backward, and other page flips.
800:
801: This is part of the LearningOnline Network with CAPA project
802: described at http://www.lon-capa.org.
803:
804: =head1 OVERVIEW
805:
806: (empty)
807:
808: =head1 SUBROUTINES
809:
810: =over cleanup()
811:
812: =item addrid()
813:
814: =item fullmove()
815:
816: =item hash_src()
817:
818: =item move()
819:
820: =item get_next_possible_move()
821:
822: =item first_accessible_resource()
823:
824: =item handler()
825:
826: =back
827:
828: =cut
1.1 www 829:
830:
831:
832:
833:
834:
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>