1: # The LearningOnline Network with CAPA
2: #
3: # Page flip handler
4: #
5: # $Id: lonpageflip.pm,v 1.80.8.13.2.3 2023/01/20 23:34:08 raeburn Exp $
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: #
29:
30:
31:
32: package Apache::lonpageflip;
33:
34: use strict;
35: use LONCAPA;
36: use Apache::Constants qw(:common :http REDIRECT);
37: use Apache::lonnet;
38: use Apache::loncommon();
39: use Apache::lonnavmaps();
40: use Apache::lonuserstate;
41: use Apache::lonlocal;
42: use HTML::TokeParser;
43: use GDBM_File;
44:
45: # ========================================================== Module Global Hash
46:
47: my %hash;
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: }
56: return OK;
57: }
58:
59: sub addrid {
60: my ($current,$new,$condid)=@_;
61: unless ($condid) { $condid=0; }
62:
63: if ($current) {
64: $current.=','.$new;
65: } else {
66: $current=''.$new;
67: }
68:
69: return $current;
70: }
71:
72: sub fullmove {
73: my ($rid,$mapurl,$direction)=@_;
74: if (tie(%hash,'GDBM_File',$env{'request.course.fn'}.'.db',
75: &GDBM_READER(),0640)) {
76: ($rid,$mapurl)=&move($rid,$mapurl,$direction);
77: untie(%hash);
78: }
79: return($rid,$mapurl);
80: }
81:
82: sub hash_src {
83: my ($id)=@_;
84: my ($mapid,$resid)=split(/\./,$id);
85: my $symb=&Apache::lonnet::encode_symb($hash{'map_id_'.$mapid},
86: $resid,$hash{'src_'.$id});
87: my $anchor;
88: if ($hash{'ext_'.$id} eq 'true:') {
89: if ($hash{'src_'.$id} =~ /(\#.+)$/) {
90: $anchor = $1;
91: }
92: }
93: if ($hash{'encrypted_'.$id}) {
94: return (&Apache::lonenc::encrypted($hash{'src_'.$id}),
95: &Apache::lonenc::encrypted($symb),
96: $hash{'encrypted_'.$id},$anchor);
97: }
98: return ($hash{'src_'.$id},$symb,$hash{'encrypted_'.$id},$anchor);
99: }
100:
101: sub move {
102: my ($next,$endupmap,$direction,$firstres) = @_;
103: my $safecount=0;
104: my $allowed=0;
105: my $deeplinkonly=0;
106: my $deeplinkchecked;
107: my $deeplink_login_pc;
108: my $prev=$next;
109: my ($prevmapid)=split(/\./,$next);
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 {
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'));
126: }
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: }
197: $safecount++;
198: } while ( ($next)
199: && ($next!~/\,/)
200: && (
201: (!$hash{'src_'.$next})
202: || (
203: (!$env{'request.role.adv'})
204: && (($hash{'randomout_'.$next})
205: || ($deeplinkonly)
206: || ($hash{'deeplinkout_'.$next}))
207: )
208: || (!$allowed)
209: )
210: && ($safecount<10000));
211:
212: return ($next,$endupmap);
213: }
214:
215: sub get_next_possible_move {
216: my ($rid,$mapurl,$direction)=@_;
217: my $startoutrid=$rid;
218:
219: my $next='';
220:
221: my $mincond=1;
222: my $posnext='';
223: if ($direction eq 'forward') {
224: # --------------------------------------------------------------------- Forward
225: while ($hash{'type_'.$rid} eq 'finish') {
226: $rid=$hash{'ids_'.$hash{'map_id_'.(split(/\./,$rid))[0]}};
227: }
228: foreach my $id (split(/\,/,$hash{'to_'.$rid})) {
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) {
234: if ($posnext) {
235: $posnext.=','.$id.':'.$thiscond;
236: } else {
237: $posnext=$id.':'.$thiscond;
238: }
239: if ($thiscond>$mincond) { $mincond=$thiscond; }
240: }
241: }
242: foreach my $id (split(/\,/,$posnext)) {
243: my ($linkid,$condval)=split(/\:/,$id);
244: if ($condval>=$mincond) {
245: $next=&addrid($next,$hash{'goesto_'.$linkid},
246: $hash{'condid_'.$hash{'undercond_'.$linkid}});
247: }
248: }
249: if ($hash{'is_map_'.$next}) {
250: # This jumps to the beginning of a new map (going down level)
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}};
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]};
259: }
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]};
264: }
265: } elsif ($direction eq 'back') {
266: # ------------------------------------------------------------------- Backwards
267: while ($hash{'type_'.$rid} eq 'start') {
268: $rid=$hash{'ids_'.$hash{'map_id_'.(split(/\./,$rid))[0]}};
269: }
270: foreach my $id (split(/\,/,$hash{'from_'.$rid})) {
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;
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: }
283: }
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: }
291: if ($hash{'is_map_'.$next}) {
292: # This jumps to the end of a new map (going down one level)
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}};
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: }
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]};
306: }
307: }
308: return ($next,$mapurl);
309: }
310:
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'};
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)) {
323: my ($name,$value) = split(/=/,$pair);
324: $args{&unescape($name)} = &unescape($value);
325: }
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) {
329: # Wow, we cannot see this ... move forward to the next one that we can see
330: my ($newrid,$newmap)=&move($hash{'first_rid'},$hash{'first_mapurl'},'forward',1);
331: # Build the new URL
332: if ($newrid eq '') {
333: $furl = '/adm/navmaps';
334: } else {
335: my ($newmapid,$newresid)=split(/\./,$newrid);
336: my $symb=&Apache::lonnet::encode_symb($newmap,$newresid,$hash{'src_'.$newrid});
337: $furl=&add_get_param($hash{'src_'.$newrid},{ 'symb' => $symb });
338: if ($hash{'encrypted_'.$newrid}) {
339: $furl=&Apache::lonenc::encrypted($furl);
340: }
341: }
342: }
343: untie(%hash);
344: return $furl;
345: } else {
346: return '/adm/navmaps';
347: }
348: }
349:
350: sub check_http_req {
351: my ($srcref,$hostname) = @_;
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://})) {
360: unless ((&Apache::lonnet::uses_sts()) ||
361: (&Apache::lonnet::waf_allssl($hostname))) {
362: $$srcref .= (($$srcref =~/\?/)? '&':'?') . 'usehttp=1';
363: $usehttp = 1;
364: }
365: } elsif (($$srcref =~ m{^\Q/adm/wrapper/ext/\E(?!https:)}) &&
366: ($ENV{'SERVER_PORT'} == 443)) {
367: unless ((&Apache::lonnet::uses_sts()) ||
368: (&Apache::lonnet::waf_allssl($hostname))) {
369: my ($url,$anchor) = ($$srcref =~ /^([^\#]+)(?:|(\#[^\#]+))$/);
370: $$srcref = $url . (($$srcref =~/\?/)? '&':'?') . 'usehttp=1' .$anchor;
371: $usehttp = 1;
372: }
373: }
374: }
375: return $usehttp;
376: }
377:
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:
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:
419: # ================================================================ Main Handler
420:
421: sub handler {
422: my $r=shift;
423:
424: # ------------------------------------------- Set document type for header only
425:
426: if ($r->header_only) {
427: &Apache::loncommon::content_type($r,'text/html');
428: $r->send_http_header;
429: return OK;
430: }
431:
432: my %cachehash=();
433: my $multichoice=0;
434: my %multichoicehash=();
435: my %prog_state=();
436: my ($redirecturl,$redirectsymb,$enc,$anchor,$deeplinklevel);
437: my $next='';
438: my $hostname = $r->hostname();
439: my @possibilities=();
440: &Apache::loncommon::get_unprocessed_cgi($ENV{'QUERY_STRING'},['postdata']);
441: if (($env{'form.postdata'})&&($env{'request.course.fn'})) {
442: my ($direction,$currenturl) = ($env{'form.postdata'}=~/(\w+)\:(.*)/);
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: }
457: if ($env{'request.course.id'}) {
458: # Check if course needs to be re-initialized
459: my $loncaparev = $r->dir_config('lonVersion');
460: ($reinitcheck,my @reinit) = &Apache::loncommon::needs_coursereinit($loncaparev);
461: if ($reinitcheck eq 'switch') {
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;
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')) {
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: }
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.').
487: ' '.&mt('Please be patient').'.<br /></div>'.
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'));
491: my ($furl,$ferr) = &Apache::lonuserstate::readmap("$cdom/$cnum");
492: &Apache::lonhtmlcommon::Update_PrgWin($r,\%prog_state,&mt('Finished!'));
493: if ($ferr) {
494: &Apache::lonhtmlcommon::Close_PrgWin($r,\%prog_state);
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;
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: }
506: }
507: }
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: }
518: }
519: if ($direction eq 'firstres') {
520: my $furl=&first_accessible_resource();
521: my $usehttp = &check_http_req(\$furl,$hostname);
522: if (($usehttp) && ($hostname ne '')) {
523: $furl='http://'.$hostname.$furl;
524: } else {
525: $furl=&Apache::lonnet::absolute_url().$furl;
526: }
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: }
537: }
538: if ($direction eq 'return') {
539: # -------------------------------------------------------- Return to last known
540: my ($newloc,$usehttp);
541: if (($last) && (tie(%hash,'GDBM_File',$env{'request.course.fn'}.'.db',
542: &GDBM_READER(),0640))) {
543: my ($murl,$id,$fn)=&Apache::lonnet::decode_symb($last);
544: $id=$hash{'map_pc_'.&Apache::lonnet::clutter($murl)}.'.'.$id;
545: $newloc=$hash{'src_'.$id};
546: if ($newloc) {
547: $usehttp = &check_http_req(\$newloc,$hostname);
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: }
557: } else {
558: $newloc='/adm/navmaps';
559: }
560: untie %hash;
561: } else {
562: $newloc='/adm/navmaps';
563: }
564: if (($usehttp) && ($hostname ne '')) {
565: $newloc='http://'.$hostname.$newloc;
566: } else {
567: $newloc=&Apache::lonnet::absolute_url().$newloc
568: }
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: }
578: }
579: #
580: # Is the current URL on the map? If not, start with last known URL
581: #
582:
583: unless (&Apache::lonnet::is_on_map($currenturl)) {
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'};
589: untie(%hash);
590: }
591: if ($last) {
592: $currenturl=&Apache::lonnet::clutter((&Apache::lonnet::decode_symb($last))[2]);
593: } else {
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: }
606: }
607: }
608: # ------------------------------------------- Do we have any idea where we are?
609: my $position;
610: if ($preupdatepos) {
611: $position = $preupdatepos;
612: } else {
613: $position=Apache::lonnet::symbread($currenturl);
614: }
615: if ($position) {
616: # ------------------------------------------------------------------------- Yes
617: my ($startoutmap,$mapnum,$thisurl)=&Apache::lonnet::decode_symb($position);
618: $cachehash{$startoutmap}{$thisurl}=[$thisurl,$mapnum];
619: $cachehash{$startoutmap}{'last_known'}=
620: [&Apache::lonnet::declutter($currenturl),$mapnum];
621:
622: # ============================================================ Tie the big hash
623: if (tie(%hash,'GDBM_File',$env{'request.course.fn'}.'.db',
624: &GDBM_READER(),0640)) {
625: my $rid=$hash{'map_pc_'.&Apache::lonnet::clutter($startoutmap)}.
626: '.'.$mapnum;
627:
628: # ------------------------------------------------- Move forward, backward, etc
629: my $endupmap;
630: ($next,$endupmap)=&move($rid,$startoutmap,$direction);
631: # -------------------------------------- Do we have one and only one empty URL?
632: # We are now at at least one non-empty URL
633: # ----------------------------------------------------- Check out possibilities
634: if ($next) {
635: @possibilities=split(/\,/,$next);
636: if ($#possibilities==0) {
637: # ---------------------------------------------- Only one possibility, redirect
638: ($redirecturl,$redirectsymb,$enc,$anchor)=&hash_src($next);
639: $cachehash{$endupmap}{$redirecturl}=
640: [$redirecturl,(split(/\./,$next))[1]];
641: } else {
642: # ------------------------ There are multiple possibilities for a next resource
643: $multichoice=1;
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} =
651: Apache::lonnet::declutter($hash{'map_id_'.$first}.'___'.
652: $second.'___'.$symbSrc);
653:
654: my ($choicemap,$choiceres)=split(/\./,$id);
655: my $map=&Apache::lonnet::declutter($hash{'src_'.$choicemap});
656: my $url=$multichoicehash{'src_'.$id};
657: $cachehash{$map}{$url}=[$url,$choiceres];
658: }
659: }
660: } else {
661: # -------------------------------------------------------------- No place to go
662: $multichoice=-1;
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: }
672: }
673: # ----------------- The program must come past this point to untie the big hash
674: untie(%hash);
675: # --------------------------------------------------------- Store position info
676: $cachehash{$startoutmap}{'last_direction'}=[$direction,'notasymb'];
677: foreach my $thismap (keys(%cachehash)) {
678: my $mapnum=$cachehash{$thismap}->{'mapnum'};
679: delete($cachehash{$thismap}->{'mapnum'});
680: &Apache::lonnet::symblist($thismap,
681: %{$cachehash{$thismap}});
682: }
683: # ============================================== Do not return before this line
684: if ($redirecturl) {
685: # ----------------------------------------------------- There is a URL to go to
686: if ($direction eq 'forward') {
687: &Apache::lonnet::linklog($currenturl,$redirecturl);
688: }
689: if ($direction eq 'back') {
690: &Apache::lonnet::linklog($redirecturl,$currenturl);
691: }
692: # ------------------------------------- Check for and display critical messages
693: my ($redirect, $url) = &Apache::loncommon::critical_redirect(300,'flip');
694: unless ($redirect) {
695: my $usehttp = &check_http_req(\$redirecturl,$hostname);
696: if (($usehttp) && ($hostname ne '')) {
697: $url='http://'.$hostname.$redirecturl;
698: } else {
699: $url=&Apache::lonnet::absolute_url().$redirecturl;
700: }
701: my $addanchor;
702: if (($anchor ne '') && (!$enc || $env{'request.role.adv'})) {
703: $addanchor = 1;
704: $url =~ s/\#.+$//;
705: }
706: $url = &add_get_param($url, { 'symb' => $redirectsymb});
707: if ($addanchor) {
708: $url .= $anchor;
709: }
710: }
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: }
721: } else {
722: # --------------------------------------------------------- There was a problem
723: &Apache::loncommon::content_type($r,'text/html');
724: $r->send_http_header;
725: my %lt=&Apache::lonlocal::texthash('title' => 'End of Sequence',
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',
731: 'explain' =>
732: 'You have reached the end of the sequence of materials.',
733: 'back' => 'Go Back',
734: 'nav' => 'Course Contents',
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',
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.');
744: if (&Apache::loncommon::course_type() eq 'Community') {
745: $lt{'nav'} = &mt('Community Contents');
746: }
747: if ($#possibilities>0) {
748: my $start_page=
749: &Apache::loncommon::start_page('Multiple Resources');
750: $r->print(<<ENDSTART);
751: $start_page
752: <h3>$lt{'wherenext'}</h3>
753: <p>
754: $lt{'pick'}:
755: <p>
756: <table border="2">
757: <tr><th>$lt{'titleheader'}</th><th>$lt{'type'}</th></tr>
758: ENDSTART
759: foreach my $id (@possibilities) {
760: my $src = $multichoicehash{'src_'.$id};
761: my $usehttp = &check_http_req(\$src,$hostname);
762: if (($usehttp) && ($hostname ne '')) {
763: $src = 'http://'.$hostname.$src;
764: }
765: $r->print(
766: '<tr><td><a href="'.
767: &add_get_param($src,
768: {'symb' =>
769: $multichoicehash{'symb_'.$id},
770: }).'">'.
771: $multichoicehash{'title_'.$id}.
772: '</a></td><td>'.$multichoicehash{'type_'.$id}.
773: '</td></tr>');
774: }
775: $r->print('</table>');
776: } else {
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(
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: }
801: }
802: }
803: if ($deeplinklevel) {
804: $r->print(
805: &Apache::lonhtmlcommon::actionbox(
806: ['<a href="/adm/flip?postdata=return:">'.$lt{'back'}.'</a>']));
807: } elsif ((!@possibilities) && ($reinitcheck)) {
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:
821: return OK;
822: }
823: } else {
824: # ------------------------------------------------- Problem, could not tie hash
825: if ($reinitcheck eq 'update') {
826: &Apache::lonhtmlcommon::Close_PrgWin($r,\%prog_state);
827: $r->print(&Apache::loncommon::end_page());
828: }
829: $env{'user.error.msg'}="/adm/flip:bre:0:1:Course Data Missing";
830: return HTTP_NOT_ACCEPTABLE;
831: }
832: } else {
833: # ---------------------------------------- No, could not determine where we are
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: }
842: return OK;
843: }
844: } else {
845: # -------------------------- Class was not initialized or page fliped strangely
846: $env{'user.error.msg'}="/adm/flip:bre:0:0:Choose Course";
847: return HTTP_NOT_ACCEPTABLE;
848: }
849: }
850:
851: 1;
852: __END__
853:
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
892:
893:
894:
895:
896:
897:
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>