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