Annotation of rat/lonpageflip.pm, revision 1.80.8.13.2.3
1.1 www 1: # The LearningOnline Network with CAPA
2: #
3: # Page flip handler
4: #
1.80.8.13.2.3! (raeburn 5:: # $Id: lonpageflip.pm,v 1.80.8.13.2.2 2022/01/05 00:54: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.13.2.3! (raeburn 466:: }
! 467:: my ($cnum,$cdom);
! 468:: if ($reinitcheck) {
! 469:: $cnum = $env{'course.'.$env{'request.course.id'}.'.num'};
! 470:: $cdom = $env{'course.'.$env{'request.course.id'}.'.domain'};
! 471:: }
! 472:: if (($reinitcheck eq 'main') || ($reinitcheck eq 'both')) {
1.80.8.8 raeburn 473: $preupdatepos = &Apache::lonnet::symbread($currenturl);
474: unless ($direction eq 'return') {
475: if (tie(%hash,'GDBM_File',$env{'request.course.fn'}.'_symb.db',
476: &GDBM_READER(),0640)) {
477: $last=$hash{'last_known'};
478: untie(%hash);
479: }
480: }
1.80.8.10 raeburn 481: &Apache::loncommon::content_type($r,'text/html');
482: $r->send_http_header;
483: $r->print(&Apache::loncommon::start_page('Content Changed'));
484: my $preamble = '<div id="LC_update_'.$env{'request.course.id'}.'" class="LC_info">'.
485: '<br />'.
486: &mt('Your course session is being updated because of recent changes by course personnel.').
1.80.8.12 raeburn 487: ' '.&mt('Please be patient').'.<br /></div>'.
1.80.8.10 raeburn 488: '<div style="padding:0;clear:both;margin:0;border:0"></div>';
489: %prog_state = &Apache::lonhtmlcommon::Create_PrgWin($r,undef,$preamble);
490: &Apache::lonhtmlcommon::Update_PrgWin($r,\%prog_state,&mt('Updating course'));
1.80.8.7 raeburn 491: my ($furl,$ferr) = &Apache::lonuserstate::readmap("$cdom/$cnum");
1.80.8.12 raeburn 492: &Apache::lonhtmlcommon::Update_PrgWin($r,\%prog_state,&mt('Finished!'));
1.80.8.7 raeburn 493: if ($ferr) {
1.80.8.10 raeburn 494: &Apache::lonhtmlcommon::Close_PrgWin($r,\%prog_state);
1.80.8.7 raeburn 495: my $requrl = $r->uri;
496: $env{'user.error.msg'}="$requrl:bre:0:0:Course not initialized";
497: $env{'user.reinit'} = 1;
498: return HTTP_NOT_ACCEPTABLE;
1.80.8.8 raeburn 499: } else {
500: if ($last) {
501: my ($murl,$id,$fn)=&Apache::lonnet::decode_symb($last);
502: unless (&Apache::lonnet::symbverify($last,$fn)) {
503: undef($last);
504: }
505: }
1.80.8.7 raeburn 506: }
507: }
1.80.8.13.2.3! (raeburn 508:: if (($reinitcheck eq 'both') || ($reinitcheck eq 'supp')) {
! 509:: my $possdel;
! 510:: if ($reinitcheck eq 'supp') {
! 511:: $possdel = 1;
! 512:: }
! 513:: my ($supplemental,$refs_updated) = &Apache::loncommon::get_supplemental($cnum,$cdom,'',$possdel);
! 514:: unless ($refs_updated) {
! 515:: &Apache::loncommon::set_supp_httprefs($cnum,$cdom,$supplemental);
! 516:: }
! 517:: }
1.80.8.7 raeburn 518: }
1.54 albertel 519: if ($direction eq 'firstres') {
1.69 www 520: my $furl=&first_accessible_resource();
1.80.8.13 raeburn 521: my $usehttp = &check_http_req(\$furl,$hostname);
1.80.8.11 raeburn 522: if (($usehttp) && ($hostname ne '')) {
523: $furl='http://'.$hostname.$furl;
524: } else {
525: $furl=&Apache::lonnet::absolute_url().$furl;
526: }
1.80.8.10 raeburn 527: if ($reinitcheck eq 'update') {
528: &Apache::lonhtmlcommon::Close_PrgWin($r,\%prog_state);
529: $r->print(&reinited_js($furl,$env{'request.course.id'},100));
530: $r->print(&Apache::loncommon::end_page());
531: return OK;
532: } else {
533: &Apache::loncommon::content_type($r,'text/html');
534: $r->header_out(Location => $furl);
535: return REDIRECT;
536: }
1.54 albertel 537: }
1.80.8.11 raeburn 538: if ($direction eq 'return') {
1.10 www 539: # -------------------------------------------------------- Return to last known
1.80.8.11 raeburn 540: my ($newloc,$usehttp);
1.53 albertel 541: if (($last) && (tie(%hash,'GDBM_File',$env{'request.course.fn'}.'.db',
1.36 www 542: &GDBM_READER(),0640))) {
1.52 albertel 543: my ($murl,$id,$fn)=&Apache::lonnet::decode_symb($last);
1.50 albertel 544: $id=$hash{'map_pc_'.&Apache::lonnet::clutter($murl)}.'.'.$id;
545: $newloc=$hash{'src_'.$id};
546: if ($newloc) {
1.80.8.13 raeburn 547: $usehttp = &check_http_req(\$newloc,$hostname);
1.80.8.11 raeburn 548: if ($hash{'encrypted_'.$id}) {
549: $newloc=&Apache::lonenc::encrypted($newloc);
550: }
551: if ($newloc =~ m{^(/adm/wrapper/ext/[^\#]+)(?:|(\#[^\#]+))$}) {
552: my ($url,$anchor) = ($1,$2);
553: if ($anchor) {
554: $newloc = $url.(($url=~/\?/)?'&':'?').'symb='.&escape($last).$anchor;
555: }
556: }
1.50 albertel 557: } else {
1.57 www 558: $newloc='/adm/navmaps';
1.50 albertel 559: }
1.36 www 560: untie %hash;
1.10 www 561: } else {
1.57 www 562: $newloc='/adm/navmaps';
1.80.8.1 raeburn 563: }
1.80.8.11 raeburn 564: if (($usehttp) && ($hostname ne '')) {
565: $newloc='http://'.$hostname.$newloc;
566: } else {
567: $newloc=&Apache::lonnet::absolute_url().$newloc
568: }
1.80.8.10 raeburn 569: if ($reinitcheck eq 'update') {
570: $r->print(&reinited_js($newloc,$env{'request.course.id'},100));
571: $r->print(&Apache::loncommon::end_page());
572: return OK;
573: } else {
574: &Apache::loncommon::content_type($r,'text/html');
575: $r->header_out(Location => $newloc);
576: return REDIRECT;
577: }
1.10 www 578: }
1.35 www 579: #
580: # Is the current URL on the map? If not, start with last known URL
581: #
1.80.8.8 raeburn 582:
1.35 www 583: unless (&Apache::lonnet::is_on_map($currenturl)) {
1.80.8.8 raeburn 584: if ($preupdatepos) {
585: undef($preupdatepos);
586: } elsif (tie(%hash,'GDBM_File',$env{'request.course.fn'}.'_symb.db',
587: &GDBM_READER(),0640)) {
588: $last=$hash{'last_known'};
1.7 www 589: untie(%hash);
590: }
591: if ($last) {
1.52 albertel 592: $currenturl=&Apache::lonnet::clutter((&Apache::lonnet::decode_symb($last))[2]);
1.7 www 593: } else {
1.80.8.10 raeburn 594: my $newloc = &Apache::lonnet::absolute_url().
595: '/adm/navmaps';
596: if ($reinitcheck eq 'update') {
597: &Apache::lonhtmlcommon::Close_PrgWin($r,\%prog_state);
598: $r->print(&reinited_js($newloc,$env{'request.course.id'},100));
599: $r->print(&Apache::loncommon::end_page());
600: return OK;
601: } else {
602: &Apache::loncommon::content_type($r,'text/html');
603: $r->header_out(Location => $newloc);
604: return REDIRECT;
605: }
1.7 www 606: }
607: }
1.3 www 608: # ------------------------------------------- Do we have any idea where we are?
609: my $position;
1.80.8.8 raeburn 610: if ($preupdatepos) {
611: $position = $preupdatepos;
612: } else {
613: $position=Apache::lonnet::symbread($currenturl);
614: }
615: if ($position) {
1.3 www 616: # ------------------------------------------------------------------------- Yes
1.41 www 617: my ($startoutmap,$mapnum,$thisurl)=&Apache::lonnet::decode_symb($position);
1.52 albertel 618: $cachehash{$startoutmap}{$thisurl}=[$thisurl,$mapnum];
1.23 www 619: $cachehash{$startoutmap}{'last_known'}=
1.52 albertel 620: [&Apache::lonnet::declutter($currenturl),$mapnum];
1.20 albertel 621:
1.5 www 622: # ============================================================ Tie the big hash
1.53 albertel 623: if (tie(%hash,'GDBM_File',$env{'request.course.fn'}.'.db',
1.28 albertel 624: &GDBM_READER(),0640)) {
1.29 www 625: my $rid=$hash{'map_pc_'.&Apache::lonnet::clutter($startoutmap)}.
626: '.'.$mapnum;
1.14 www 627:
1.15 www 628: # ------------------------------------------------- Move forward, backward, etc
1.22 www 629: my $endupmap;
630: ($next,$endupmap)=&move($rid,$startoutmap,$direction);
1.15 www 631: # -------------------------------------- Do we have one and only one empty URL?
1.22 www 632: # We are now at at least one non-empty URL
1.4 www 633: # ----------------------------------------------------- Check out possibilities
634: if ($next) {
635: @possibilities=split(/\,/,$next);
636: if ($#possibilities==0) {
1.5 www 637: # ---------------------------------------------- Only one possibility, redirect
1.80.8.9 raeburn 638: ($redirecturl,$redirectsymb,$enc,$anchor)=&hash_src($next);
1.52 albertel 639: $cachehash{$endupmap}{$redirecturl}=
640: [$redirecturl,(split(/\./,$next))[1]];
1.4 www 641: } else {
1.5 www 642: # ------------------------ There are multiple possibilities for a next resource
643: $multichoice=1;
1.62 albertel 644: foreach my $id (@possibilities) {
645: $multichoicehash{'src_'.$id}=$hash{'src_'.$id};
646: $multichoicehash{'title_'.$id}=$hash{'title_'.$id};
647: $multichoicehash{'type_'.$id}=$hash{'type_'.$id};
648: (my $first, my $second) = $id =~ /(\d+).(\d+)/;
649: my $symbSrc = Apache::lonnet::declutter($hash{'src_'.$id});
650: $multichoicehash{'symb_'.$id} =
1.32 bowersj2 651: Apache::lonnet::declutter($hash{'map_id_'.$first}.'___'.
652: $second.'___'.$symbSrc);
653:
1.62 albertel 654: my ($choicemap,$choiceres)=split(/\./,$id);
1.52 albertel 655: my $map=&Apache::lonnet::declutter($hash{'src_'.$choicemap});
1.62 albertel 656: my $url=$multichoicehash{'src_'.$id};
1.52 albertel 657: $cachehash{$map}{$url}=[$url,$choiceres];
1.62 albertel 658: }
1.4 www 659: }
1.5 www 660: } else {
661: # -------------------------------------------------------------- No place to go
662: $multichoice=-1;
1.80.8.13.2.1 (raeburn 663:: if ($position && $env{'request.deeplink.login'}) {
664:: my ($map,$resid,$url) = &Apache::lonnet::decode_symb($position);
665:: my $mapid = $hash{'map_pc_'.&Apache::lonnet::clutter($map)};
666:: my $position_deeplink = $hash{'deeplinkonly_'.$mapid.'.'.$resid};
667:: if ($position_deeplink) {
668:: (my $value,$deeplinklevel) = map { &unescape($_); }
669:: split(/:/,$position_deeplink);
670:: }
671:: }
1.4 www 672: }
1.5 www 673: # ----------------- The program must come past this point to untie the big hash
1.3 www 674: untie(%hash);
1.5 www 675: # --------------------------------------------------------- Store position info
1.52 albertel 676: $cachehash{$startoutmap}{'last_direction'}=[$direction,'notasymb'];
1.80.8.7 raeburn 677: foreach my $thismap (keys(%cachehash)) {
1.52 albertel 678: my $mapnum=$cachehash{$thismap}->{'mapnum'};
679: delete($cachehash{$thismap}->{'mapnum'});
680: &Apache::lonnet::symblist($thismap,
681: %{$cachehash{$thismap}});
1.19 www 682: }
1.5 www 683: # ============================================== Do not return before this line
1.4 www 684: if ($redirecturl) {
1.5 www 685: # ----------------------------------------------------- There is a URL to go to
1.38 www 686: if ($direction eq 'forward') {
687: &Apache::lonnet::linklog($currenturl,$redirecturl);
688: }
689: if ($direction eq 'back') {
690: &Apache::lonnet::linklog($redirecturl,$currenturl);
691: }
1.80.8.5 raeburn 692: # ------------------------------------- Check for and display critical messages
1.80.8.13.2.2 (raeburn 693:: my ($redirect, $url) = &Apache::loncommon::critical_redirect(300,'flip');
1.80.8.5 raeburn 694: unless ($redirect) {
1.80.8.13 raeburn 695: my $usehttp = &check_http_req(\$redirecturl,$hostname);
1.80.8.11 raeburn 696: if (($usehttp) && ($hostname ne '')) {
697: $url='http://'.$hostname.$redirecturl;
698: } else {
699: $url=&Apache::lonnet::absolute_url().$redirecturl;
700: }
1.80.8.9 raeburn 701: my $addanchor;
702: if (($anchor ne '') && (!$enc || $env{'request.role.adv'})) {
703: $addanchor = 1;
704: $url =~ s/\#.+$//;
705: }
1.80.8.5 raeburn 706: $url = &add_get_param($url, { 'symb' => $redirectsymb});
1.80.8.9 raeburn 707: if ($addanchor) {
708: $url .= $anchor;
709: }
1.80.8.1 raeburn 710: }
1.80.8.10 raeburn 711: if ($reinitcheck eq 'update') {
712: &Apache::lonhtmlcommon::Close_PrgWin($r,\%prog_state);
713: $r->print(&reinited_js($url,$env{'request.course.id'},100));
714: $r->print(&Apache::loncommon::end_page());
715: return OK;
716: } else {
717: &Apache::loncommon::content_type($r,'text/html');
718: $r->header_out(Location => $url);
719: return REDIRECT;
720: }
1.5 www 721: } else {
722: # --------------------------------------------------------- There was a problem
1.51 albertel 723: &Apache::loncommon::content_type($r,'text/html');
1.8 www 724: $r->send_http_header;
1.59 www 725: my %lt=&Apache::lonlocal::texthash('title' => 'End of Sequence',
1.80.8.13.2.1 (raeburn 726:: 'deeplink' => 'No link available',
727:: 'deeplinkres' =>
728:: 'Navigation to other content is unavailable when accessing content via deep-linking',
729:: 'deeplinkmap' =>
730:: 'You have reached the end of the sequence of available materials for access via deep-linking',
1.59 www 731: 'explain' =>
732: 'You have reached the end of the sequence of materials.',
733: 'back' => 'Go Back',
1.80.8.3 raeburn 734: 'nav' => 'Course Contents',
1.59 www 735: 'wherenext' =>
736: 'There are several possibilities of where to go next',
737: 'pick' =>
738: 'Please click on the the resource you intend to access',
739: 'titleheader' => 'Title',
1.80.8.8 raeburn 740: 'type' => 'Type',
741: 'update' => 'Content updated',
742: 'expupdate' => 'As a result of a recent update to the sequence of materials, it is not possible to complete the page flip.',
743: 'gonav' => 'Go to the Contents page to select a resource to display.');
1.80.8.3 raeburn 744: if (&Apache::loncommon::course_type() eq 'Community') {
745: $lt{'nav'} = &mt('Community Contents');
746: }
1.8 www 747: if ($#possibilities>0) {
1.67 albertel 748: my $start_page=
749: &Apache::loncommon::start_page('Multiple Resources');
1.8 www 750: $r->print(<<ENDSTART);
1.67 albertel 751: $start_page
1.59 www 752: <h3>$lt{'wherenext'}</h3>
1.8 www 753: <p>
1.59 www 754: $lt{'pick'}:
1.8 www 755: <p>
1.79 bisitz 756: <table border="2">
1.59 www 757: <tr><th>$lt{'titleheader'}</th><th>$lt{'type'}</th></tr>
1.8 www 758: ENDSTART
1.62 albertel 759: foreach my $id (@possibilities) {
1.80.8.11 raeburn 760: my $src = $multichoicehash{'src_'.$id};
1.80.8.13 raeburn 761: my $usehttp = &check_http_req(\$src,$hostname);
1.80.8.11 raeburn 762: if (($usehttp) && ($hostname ne '')) {
763: $src = 'http://'.$hostname.$src;
764: }
1.8 www 765: $r->print(
766: '<tr><td><a href="'.
1.80.8.11 raeburn 767: &add_get_param($src,
1.66 albertel 768: {'symb' =>
769: $multichoicehash{'symb_'.$id},
770: }).'">'.
1.62 albertel 771: $multichoicehash{'title_'.$id}.
772: '</a></td><td>'.$multichoicehash{'type_'.$id}.
1.8 www 773: '</td></tr>');
1.26 www 774: }
1.59 www 775: $r->print('</table>');
1.8 www 776: } else {
1.80.8.8 raeburn 777: if ($reinitcheck) {
778: if (&Apache::loncommon::course_type() eq 'Community') {
779: $r->print(
780: &Apache::loncommon::start_page('Community Contents Updated'));
781: } else {
782: $r->print(
783: &Apache::loncommon::start_page('Course Contents Updated'));
784: }
785: $r->print('<h2>'.$lt{'update'}.'</h2>'
786: .'<p>'.$lt{'expupdate'}.'<br />'
787: .$lt{'gonav'}.'</p>');
788: } else {
789: $r->print(
1.80.8.13.2.1 (raeburn 790:: &Apache::loncommon::start_page('No Resource'));
791:: if ($deeplinklevel eq 'resource') {
792:: $r->print('<h2>'.$lt{'deeplink'}.'</h2>'
793:: .'<p>'.$lt{'deeplinkres'}.'</p>');
794:: } elsif ($deeplinklevel eq 'map') {
795:: $r->print('<h2>'.$lt{'title'}.'</h2>'
796:: .'<p>'.$lt{'deeplinkmap'}.'</p>');
797:: } else {
798:: $r->print('<h2>'.$lt{'title'}.'</h2>'
799:: .'<p>'.$lt{'explain'}.'</p>');
800:: }
1.80.8.8 raeburn 801: }
1.59 www 802: }
1.80.8.13.2.1 (raeburn 803:: if ($deeplinklevel) {
804:: $r->print(
805:: &Apache::lonhtmlcommon::actionbox(
806:: ['<a href="/adm/flip?postdata=return:">'.$lt{'back'}.'</a>']));
807:: } elsif ((!@possibilities) && ($reinitcheck)) {
1.80.8.8 raeburn 808: $r->print(
809: &Apache::lonhtmlcommon::actionbox(
810: ['<a href="/adm/navmaps">'.$lt{'nav'}.'</a></li>'
811: ]));
812: } else {
813: $r->print(
814: &Apache::lonhtmlcommon::actionbox(
815: ['<a href="/adm/flip?postdata=return:">'.$lt{'back'}.'</a></li>',
816: '<a href="/adm/navmaps">'.$lt{'nav'}.'</a></li>'
817: ]));
818: }
819: $r->print(&Apache::loncommon::end_page());
820:
1.59 www 821: return OK;
822: }
1.5 www 823: } else {
824: # ------------------------------------------------- Problem, could not tie hash
1.80.8.10 raeburn 825: if ($reinitcheck eq 'update') {
826: &Apache::lonhtmlcommon::Close_PrgWin($r,\%prog_state);
827: $r->print(&Apache::loncommon::end_page());
828: }
1.53 albertel 829: $env{'user.error.msg'}="/adm/flip:bre:0:1:Course Data Missing";
1.5 www 830: return HTTP_NOT_ACCEPTABLE;
1.3 www 831: }
1.5 www 832: } else {
833: # ---------------------------------------- No, could not determine where we are
1.80.8.10 raeburn 834: my $newloc = '/adm/ambiguous';
835: if ($reinitcheck eq 'update') {
836: &Apache::lonhtmlcommon::Close_PrgWin($r,\%prog_state);
837: $r->print(&reinited_js($newloc,$env{'request.course.id'},100));
838: $r->print(&Apache::loncommon::end_page());
839: } else {
840: $r->internal_redirect($newloc);
841: }
1.80.8.2 raeburn 842: return OK;
1.2 www 843: }
1.5 www 844: } else {
1.2 www 845: # -------------------------- Class was not initialized or page fliped strangely
1.53 albertel 846: $env{'user.error.msg'}="/adm/flip:bre:0:0:Choose Course";
1.2 www 847: return HTTP_NOT_ACCEPTABLE;
848: }
1.1 www 849: }
850:
851: 1;
852: __END__
853:
1.77 jms 854: =pod
855:
856: =head1 NAME
857:
858: Apache::lonpageflip
859:
860: =head1 SYNOPSIS
861:
862: Deals with forward, backward, and other page flips.
863:
864: This is part of the LearningOnline Network with CAPA project
865: described at http://www.lon-capa.org.
866:
867: =head1 OVERVIEW
868:
869: (empty)
870:
871: =head1 SUBROUTINES
872:
873: =over cleanup()
874:
875: =item addrid()
876:
877: =item fullmove()
878:
879: =item hash_src()
880:
881: =item move()
882:
883: =item get_next_possible_move()
884:
885: =item first_accessible_resource()
886:
887: =item handler()
888:
889: =back
890:
891: =cut
1.1 www 892:
893:
894:
895:
896:
897:
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>