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