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