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