Annotation of rat/lonpageflip.pm, revision 1.104
1.1 www 1: # The LearningOnline Network with CAPA
2: #
3: # Page flip handler
4: #
1.104 ! raeburn 5: # $Id: lonpageflip.pm,v 1.103 2021/04/29 17:45:25 raeburn Exp $
1.18 www 6: #
7: # Copyright Michigan State University Board of Trustees
8: #
9: # This file is part of the LearningOnline Network with CAPA (LON-CAPA).
10: #
11: # LON-CAPA is free software; you can redistribute it and/or modify
12: # it under the terms of the GNU General Public License as published by
13: # the Free Software Foundation; either version 2 of the License, or
14: # (at your option) any later version.
15: #
16: # LON-CAPA is distributed in the hope that it will be useful,
17: # but WITHOUT ANY WARRANTY; without even the implied warranty of
18: # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19: # GNU General Public License for more details.
20: #
21: # You should have received a copy of the GNU General Public License
22: # along with LON-CAPA; if not, write to the Free Software
23: # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
24: #
25: # /home/httpd/html/adm/gpl.txt
26: #
27: # http://www.lon-capa.org/
28: #
1.1 www 29:
1.76 jms 30:
31:
1.1 www 32: package Apache::lonpageflip;
33:
34: use strict;
1.68 albertel 35: use LONCAPA;
1.4 www 36: use Apache::Constants qw(:common :http REDIRECT);
1.53 albertel 37: use Apache::lonnet;
1.70 albertel 38: use Apache::loncommon();
1.91 raeburn 39: use Apache::lonnavmaps();
1.87 raeburn 40: use Apache::lonuserstate;
1.84 raeburn 41: use Apache::lonlocal;
1.1 www 42: use HTML::TokeParser;
43: use GDBM_File;
44:
1.3 www 45: # ========================================================== Module Global Hash
46:
1.1 www 47: my %hash;
1.34 www 48:
49: sub cleanup {
50: if (tied(%hash)){
51: &Apache::lonnet::logthis('Cleanup pageflip: hash');
52: unless (untie(%hash)) {
53: &Apache::lonnet::logthis('Failed cleanup pageflip: hash');
54: }
55: }
1.63 albertel 56: return OK;
1.34 www 57: }
1.1 www 58:
1.3 www 59: sub addrid {
1.4 www 60: my ($current,$new,$condid)=@_;
61: unless ($condid) { $condid=0; }
1.27 www 62:
1.3 www 63: if ($current) {
1.5 www 64: $current.=','.$new;
1.3 www 65: } else {
1.5 www 66: $current=''.$new;
1.3 www 67: }
1.27 www 68:
1.3 www 69: return $current;
1.25 www 70: }
71:
72: sub fullmove {
73: my ($rid,$mapurl,$direction)=@_;
1.53 albertel 74: if (tie(%hash,'GDBM_File',$env{'request.course.fn'}.'.db',
1.28 albertel 75: &GDBM_READER(),0640)) {
1.25 www 76: ($rid,$mapurl)=&move($rid,$mapurl,$direction);
77: untie(%hash);
78: }
79: return($rid,$mapurl);
1.1 www 80: }
81:
1.50 albertel 82: sub hash_src {
83: my ($id)=@_;
1.56 albertel 84: my ($mapid,$resid)=split(/\./,$id);
85: my $symb=&Apache::lonnet::encode_symb($hash{'map_id_'.$mapid},
86: $resid,$hash{'src_'.$id});
1.90 raeburn 87: my $anchor;
88: if ($hash{'ext_'.$id} eq 'true:') {
89: if ($hash{'src_'.$id} =~ /(\#.+)$/) {
90: $anchor = $1;
91: }
92: }
1.50 albertel 93: if ($hash{'encrypted_'.$id}) {
1.56 albertel 94: return (&Apache::lonenc::encrypted($hash{'src_'.$id}),
1.90 raeburn 95: &Apache::lonenc::encrypted($symb),
96: $hash{'encrypted_'.$id},$anchor);
1.50 albertel 97: }
1.90 raeburn 98: return ($hash{'src_'.$id},$symb,$hash{'encrypted_'.$id},$anchor);
1.50 albertel 99: }
100:
1.15 www 101: sub move {
1.104 ! raeburn 102: my ($next,$endupmap,$direction,$firstres) = @_;
1.72 albertel 103: my $safecount=0;
104: my $allowed=0;
1.98 raeburn 105: my $deeplinkonly=0;
106: my $prev=$next;
107: my ($prevmapid)=split(/\./,$next);
1.72 albertel 108: do {
109: ($next,$endupmap)=&get_next_possible_move($next,$endupmap,$direction);
110:
111: my $url = $hash{'src_'.$next};
112: my ($mapid,$resid)=split(/\./,$next);
113: my $symb = &Apache::lonnet::encode_symb($hash{'map_id_'.$mapid},
114: $resid,$url);
115: if ($url eq '' || $symb eq '') {
116: $allowed = 0;
117: } else {
118: my $priv = &Apache::lonnet::allowed('bre',$url,$symb);
1.104 ! raeburn 119: $allowed = (($priv eq 'F') || ($priv eq '2') || ($priv eq 'A'));
1.72 albertel 120: }
1.98 raeburn 121: $deeplinkonly = 0;
122: if ($hash{'deeplinkonly_'.$next}) {
123: my ($value,$level) = split(/:/,$hash{'deeplinkonly_'.$next});
124: if ($level eq 'resource') {
125: $deeplinkonly = 1;
126: } elsif ($level eq 'map') {
127: if ($mapid != $prevmapid) {
128: $deeplinkonly = 1;
129: }
130: }
1.104 ! raeburn 131: } elsif (($hash{'deeplinkonly_'.$prev}) && (!$firstres)) {
1.98 raeburn 132: my ($value,$level) = split(/:/,$hash{'deeplinkonly_'.$prev});
133: if ($level eq 'resource') {
134: $deeplinkonly = 1;
135: } elsif ($level eq 'map') {
136: if ($mapid != $prevmapid) {
137: $deeplinkonly = 1;
138: }
139: }
140: }
1.72 albertel 141: $safecount++;
142: } while ( ($next)
143: && ($next!~/\,/)
144: && (
145: (!$hash{'src_'.$next})
146: || (
1.98 raeburn 147: (!$env{'request.role.adv'})
148: && (($hash{'randomout_'.$next})
149: || ($deeplinkonly))
1.72 albertel 150: )
151: || (!$allowed)
152: )
153: && ($safecount<10000));
154:
155: return ($next,$endupmap);
156: }
157:
158: sub get_next_possible_move {
1.15 www 159: my ($rid,$mapurl,$direction)=@_;
1.23 www 160: my $startoutrid=$rid;
1.15 www 161:
162: my $next='';
163:
164: my $mincond=1;
165: my $posnext='';
166: if ($direction eq 'forward') {
167: # --------------------------------------------------------------------- Forward
1.33 www 168: while ($hash{'type_'.$rid} eq 'finish') {
169: $rid=$hash{'ids_'.$hash{'map_id_'.(split(/\./,$rid))[0]}};
1.15 www 170: }
1.61 albertel 171: foreach my $id (split(/\,/,$hash{'to_'.$rid})) {
1.64 albertel 172: my $condition= $hash{'conditions_'.$hash{'goesto_'.$id}};
173: my $rescond = &Apache::lonnet::docondval($condition);
174: my $linkcond = &Apache::lonnet::directcondval($hash{'condid_'.$hash{'undercond_'.$id}});
175: my $thiscond = ($rescond<$linkcond)?$rescond:$linkcond;
176: if ($thiscond>=$mincond) {
1.15 www 177: if ($posnext) {
1.61 albertel 178: $posnext.=','.$id.':'.$thiscond;
1.15 www 179: } else {
1.61 albertel 180: $posnext=$id.':'.$thiscond;
1.15 www 181: }
182: if ($thiscond>$mincond) { $mincond=$thiscond; }
183: }
1.61 albertel 184: }
185: foreach my $id (split(/\,/,$posnext)) {
186: my ($linkid,$condval)=split(/\:/,$id);
1.15 www 187: if ($condval>=$mincond) {
188: $next=&addrid($next,$hash{'goesto_'.$linkid},
189: $hash{'condid_'.$hash{'undercond_'.$linkid}});
190: }
1.61 albertel 191: }
1.15 www 192: if ($hash{'is_map_'.$next}) {
1.23 www 193: # This jumps to the beginning of a new map (going down level)
1.15 www 194: if (
195: $hash{'map_type_'.$hash{'map_pc_'.$hash{'src_'.$next}}} eq 'sequence') {
196: $mapurl=$hash{'src_'.$next};
197: $next=$hash{'map_start_'.$hash{'src_'.$next}};
1.47 raeburn 198: } elsif (
199: # This jumps back up from an empty sequence, to a page up one level
200: $hash{'map_type_'.$hash{'map_pc_'.$hash{'src_'.$next}}} eq 'page') {
201: $mapurl=$hash{'map_id_'.(split(/\./,$next))[0]};
1.15 www 202: }
1.23 www 203: } elsif
204: ((split(/\./,$startoutrid))[0]!=(split(/\./,$next))[0]) {
205: # This comes up from a map (coming up one level);
206: $mapurl=$hash{'map_id_'.(split(/\./,$next))[0]};
1.61 albertel 207: }
1.15 www 208: } elsif ($direction eq 'back') {
209: # ------------------------------------------------------------------- Backwards
1.33 www 210: while ($hash{'type_'.$rid} eq 'start') {
211: $rid=$hash{'ids_'.$hash{'map_id_'.(split(/\./,$rid))[0]}};
212: }
1.62 albertel 213: foreach my $id (split(/\,/,$hash{'from_'.$rid})) {
1.64 albertel 214: my $condition= $hash{'conditions_'.$hash{'comesfrom_'.$id}};
215: my $rescond = &Apache::lonnet::docondval($condition);
216: my $linkcond = &Apache::lonnet::directcondval($hash{'condid_'.$hash{'undercond_'.$id}});
217: my $thiscond = ($rescond<$linkcond)?$rescond:$linkcond;
1.62 albertel 218: if ($thiscond>=$mincond) {
219: if ($posnext) {
220: $posnext.=','.$id.':'.$thiscond;
221: } else {
222: $posnext=$id.':'.$thiscond;
223: }
224: if ($thiscond>$mincond) { $mincond=$thiscond; }
225: }
226: }
227: foreach my $id (split(/\,/,$posnext)) {
228: my ($linkid,$condval)=split(/\:/,$id);
229: if ($condval>=$mincond) {
230: $next=&addrid($next,$hash{'comesfrom_'.$linkid},
231: $hash{'condid_'.$hash{'undercond_'.$linkid}});
232: }
233: }
1.15 www 234: if ($hash{'is_map_'.$next}) {
1.24 www 235: # This jumps to the end of a new map (going down one level)
1.15 www 236: if (
237: $hash{'map_type_'.$hash{'map_pc_'.$hash{'src_'.$next}}} eq 'sequence') {
238: $mapurl=$hash{'src_'.$next};
239: $next=$hash{'map_finish_'.$hash{'src_'.$next}};
1.47 raeburn 240: } elsif (
241: $hash{'map_type_'.$hash{'map_pc_'.$hash{'src_'.$next}}} eq 'page') {
242: # This jumps back up from an empty sequence, to a page up one level
243: $mapurl=$hash{'map_id_'.(split(/\./,$next))[0]};
244: }
1.24 www 245: } elsif
246: ((split(/\./,$startoutrid))[0]!=(split(/\./,$next))[0]) {
247: # This comes back up from a map (going up one level);
248: $mapurl=$hash{'map_id_'.(split(/\./,$next))[0]};
1.15 www 249: }
250: }
251: return ($next,$mapurl);
252: }
253:
1.69 www 254: sub first_accessible_resource {
255: my $furl;
256: if (tie(%hash,'GDBM_File',$env{'request.course.fn'}.'.db',
257: &GDBM_READER(),0640)) {
258: $furl=$hash{'first_url'};
1.74 albertel 259: my %args;
260: my ($url,$args) = split(/\?/,$furl);
261: foreach my $pair (split(/\&/,$args)) {
262: my ($name,$value) = split(/=/,$pair);
263: $args{&unescape($name)} = &unescape($value);
264: }
1.104 ! raeburn 265: my $priv = &Apache::lonnet::allowed('bre',$url,$args{'symb'});
! 266: my $allowed = (($priv eq 'F') || ($priv eq '2') || ($priv eq 'A'));
! 267: if (!$allowed) {
1.69 www 268: # Wow, we cannot see this ... move forward to the next one that we can see
1.104 ! raeburn 269: my ($newrid,$newmap)=&move($hash{'first_rid'},$hash{'first_mapurl'},'forward',1);
1.69 www 270: # Build the new URL
1.73 albertel 271: my ($newmapid,$newresid)=split(/\./,$newrid);
1.69 www 272: my $symb=&Apache::lonnet::encode_symb($newmap,$newresid,$hash{'src_'.$newrid});
273: $furl=&add_get_param($hash{'src_'.$newrid},{ 'symb' => $symb });
274: if ($hash{'encrypted_'.$newrid}) {
275: $furl=&Apache::lonenc::encrypted($furl);
276: }
277: }
278: untie(%hash);
279: return $furl;
280: } else {
281: return '/adm/navmaps';
282: }
283: }
284:
1.91 raeburn 285: sub first_answerable_ressymb {
286: my $navmap = Apache::lonnavmaps::navmap->new;
287: return unless (ref($navmap));
288: my $iterator = $navmap->getIterator(undef,undef,undef,1);
289: return unless (ref($iterator));
290: my ($curRes,$result);
291: while ($curRes = $iterator->next()) {
292: if (ref($curRes) && $curRes->is_problem()) {
293: foreach my $part (@{$curRes->parts()}) {
294: if ($curRes->tries($part) < $curRes->maxtries($part)) {
295: $result = $curRes->link().'?symb='.$curRes->shown_symb();
296: last;
297: }
298: }
299: }
300: }
301: if ($result) {
302: return $result;
303: } else {
304: return &first_accessible_resource();
305: }
306: }
307:
1.95 raeburn 308: sub check_http_req {
1.103 raeburn 309: my ($srcref,$hostname) = @_;
1.92 raeburn 310: return unless (ref($srcref) eq 'SCALAR');
1.93 raeburn 311: my $usehttp;
1.92 raeburn 312: if ($env{'request.course.id'}) {
313: my $cnum = $env{'course.'.$env{'request.course.id'}.'.num'};
314: my $cdom = $env{'course.'.$env{'request.course.id'}.'.domain'};
315: if (($$srcref =~ m{^\Q/public/$cdom/$cnum/syllabus\E($|\?)}) &&
316: ($ENV{'SERVER_PORT'} == 443) &&
317: ($env{'course.'.$env{'request.course.id'}.'.externalsyllabus'} =~ m{^http://})) {
1.103 raeburn 318: unless ((&Apache::lonnet::uses_sts()) ||
319: (&Apache::lonnet::waf_allssl($hostname))) {
1.99 raeburn 320: $$srcref .= (($$srcref =~/\?/)? '&':'?') . 'usehttp=1';
321: $usehttp = 1;
322: }
1.95 raeburn 323: } elsif (($$srcref =~ m{^\Q/adm/wrapper/ext/\E(?!https:)}) &&
324: ($ENV{'SERVER_PORT'} == 443)) {
1.103 raeburn 325: unless ((&Apache::lonnet::uses_sts()) ||
326: (&Apache::lonnet::waf_allssl($hostname))) {
1.100 raeburn 327: my ($url,$anchor) = ($$srcref =~ /^([^\#]+)(?:|(\#[^\#]+))$/);
328: $$srcref = $url . (($$srcref =~/\?/)? '&':'?') . 'usehttp=1' .$anchor;
1.99 raeburn 329: $usehttp = 1;
330: }
1.92 raeburn 331: }
332: }
1.93 raeburn 333: return $usehttp;
1.92 raeburn 334: }
335:
1.97 raeburn 336: sub reinited_js {
337: my ($url,$cid,$timeout) = @_;
338: if (!$timeout) {
339: $timeout = 0;
340: }
341: return <<"END";
342: <script type="text/javascript">
343: // <![CDATA[
344: setTimeout(function() {
345: var newurl = '$url';
346: if (document.getElementById('LC_update_$cid')) {
347: document.getElementById('LC_update_$cid').style.display = 'none';
348: }
349: if ((newurl !== null) && (newurl !== '') && (newurl !== 'undefined')) {
350: window.location.href = "$url";
351: }
352: }, $timeout);
353: // ]]>
354: </script>
355: END
356: }
357:
1.1 www 358: # ================================================================ Main Handler
359:
360: sub handler {
1.2 www 361: my $r=shift;
1.1 www 362:
363: # ------------------------------------------- Set document type for header only
364:
1.2 www 365: if ($r->header_only) {
1.51 albertel 366: &Apache::loncommon::content_type($r,'text/html');
367: $r->send_http_header;
368: return OK;
1.2 www 369: }
370:
1.5 www 371: my %cachehash=();
372: my $multichoice=0;
373: my %multichoicehash=();
1.97 raeburn 374: my %prog_state=();
1.98 raeburn 375: my ($redirecturl,$redirectsymb,$enc,$anchor,$deeplinklevel);
1.4 www 376: my $next='';
1.94 raeburn 377: my $hostname = $r->hostname();
1.4 www 378: my @possibilities=();
1.37 www 379: &Apache::loncommon::get_unprocessed_cgi($ENV{'QUERY_STRING'},['postdata']);
1.53 albertel 380: if (($env{'form.postdata'})&&($env{'request.course.fn'})) {
1.88 raeburn 381: my ($direction,$currenturl) = ($env{'form.postdata'}=~/(\w+)\:(.*)/);
1.89 raeburn 382: if ($currenturl=~m|^/enc/|) {
383: $currenturl=&Apache::lonenc::unencrypted($currenturl);
384: }
385: $currenturl=~s/\.\d+\.(\w+)$/\.$1/;
386: $currenturl=~s/^https?\:\/\///;
387: $currenturl=~s/^[^\/]+//;
388: my ($preupdatepos,$last,$reinitcheck);
389: if ($direction eq 'return') {
390: if (tie(%hash,'GDBM_File',$env{'request.course.fn'}.'_symb.db',
391: &GDBM_READER(),0640)) {
392: $last=$hash{'last_known'};
393: untie(%hash);
394: }
1.91 raeburn 395: } elsif ($direction eq 'firstanswerable') {
396: my $furl = &first_answerable_ressymb();
1.103 raeburn 397: my $usehttp = &check_http_req(\$furl,$hostname);
1.94 raeburn 398: if (($usehttp) && ($hostname ne '')) {
399: $furl='http://'.$hostname.$furl;
1.93 raeburn 400: } else {
401: $furl=&Apache::lonnet::absolute_url().$furl;
402: }
1.91 raeburn 403: &Apache::loncommon::content_type($r,'text/html');
1.93 raeburn 404: $r->header_out(Location => $furl);
1.91 raeburn 405: return REDIRECT;
406: } elsif ($direction eq 'endplacement') {
407: &Apache::loncommon::content_type($r,'text/html');
408: $r->send_http_header;
409: $r->print(&Apache::lonplacementtest::showresult());
410: return OK;
1.89 raeburn 411: }
1.87 raeburn 412: if ($env{'request.course.id'}) {
413: # Check if course needs to be re-initialized
414: my $loncaparev = $r->dir_config('lonVersion');
1.89 raeburn 415: ($reinitcheck,my @reinit) = &Apache::loncommon::needs_coursereinit($loncaparev);
416: if ($reinitcheck eq 'switch') {
1.87 raeburn 417: &Apache::loncommon::content_type($r,'text/html');
418: $r->send_http_header;
419: $r->print(&Apache::loncommon::check_release_result(@reinit));
420: return OK;
1.89 raeburn 421: } elsif ($reinitcheck eq 'update') {
1.87 raeburn 422: my $cnum = $env{'course.'.$env{'request.course.id'}.'.num'};
423: my $cdom = $env{'course.'.$env{'request.course.id'}.'.domain'};
1.89 raeburn 424: $preupdatepos = &Apache::lonnet::symbread($currenturl);
425: unless ($direction eq 'return') {
426: if (tie(%hash,'GDBM_File',$env{'request.course.fn'}.'_symb.db',
427: &GDBM_READER(),0640)) {
428: $last=$hash{'last_known'};
429: untie(%hash);
430: }
431: }
1.97 raeburn 432: &Apache::loncommon::content_type($r,'text/html');
433: $r->send_http_header;
434: $r->print(&Apache::loncommon::start_page('Content Changed'));
435: my $preamble = '<div id="LC_update_'.$env{'request.course.id'}.'" class="LC_info">'.
436: '<br />'.
437: &mt('Your course session is being updated because of recent changes by course personnel.').
1.102 raeburn 438: ' '.&mt('Please be patient').'.<br /></div>'.
1.97 raeburn 439: '<div style="padding:0;clear:both;margin:0;border:0"></div>';
440: %prog_state = &Apache::lonhtmlcommon::Create_PrgWin($r,undef,$preamble);
441: &Apache::lonhtmlcommon::Update_PrgWin($r,\%prog_state,&mt('Updating course'));
1.87 raeburn 442: my ($furl,$ferr) = &Apache::lonuserstate::readmap("$cdom/$cnum");
1.102 raeburn 443: &Apache::lonhtmlcommon::Update_PrgWin($r,\%prog_state,&mt('Finished!'));
1.87 raeburn 444: if ($ferr) {
1.97 raeburn 445: &Apache::lonhtmlcommon::Close_PrgWin($r,\%prog_state);
1.87 raeburn 446: my $requrl = $r->uri;
447: $env{'user.error.msg'}="$requrl:bre:0:0:Course not initialized";
448: $env{'user.reinit'} = 1;
449: return HTTP_NOT_ACCEPTABLE;
1.89 raeburn 450: } else {
451: if ($last) {
452: my ($murl,$id,$fn)=&Apache::lonnet::decode_symb($last);
453: unless (&Apache::lonnet::symbverify($last,$fn)) {
454: undef($last);
455: }
456: }
1.87 raeburn 457: }
458: }
459: }
1.54 albertel 460: if ($direction eq 'firstres') {
1.69 www 461: my $furl=&first_accessible_resource();
1.103 raeburn 462: my $usehttp = &check_http_req(\$furl,$hostname);
1.94 raeburn 463: if (($usehttp) && ($hostname ne '')) {
464: $furl='http://'.$hostname.$furl;
1.93 raeburn 465: } else {
466: $furl=&Apache::lonnet::absolute_url().$furl;
467: }
1.97 raeburn 468: if ($reinitcheck eq 'update') {
469: &Apache::lonhtmlcommon::Close_PrgWin($r,\%prog_state);
470: $r->print(&reinited_js($furl,$env{'request.course.id'},100));
471: $r->print(&Apache::loncommon::end_page());
472: return OK;
473: } else {
474: &Apache::loncommon::content_type($r,'text/html');
475: $r->header_out(Location => $furl);
476: return REDIRECT;
477: }
1.54 albertel 478: }
1.101 raeburn 479: if ($direction eq 'return') {
1.10 www 480: # -------------------------------------------------------- Return to last known
1.93 raeburn 481: my ($newloc,$usehttp);
1.53 albertel 482: if (($last) && (tie(%hash,'GDBM_File',$env{'request.course.fn'}.'.db',
1.36 www 483: &GDBM_READER(),0640))) {
1.52 albertel 484: my ($murl,$id,$fn)=&Apache::lonnet::decode_symb($last);
1.50 albertel 485: $id=$hash{'map_pc_'.&Apache::lonnet::clutter($murl)}.'.'.$id;
486: $newloc=$hash{'src_'.$id};
487: if ($newloc) {
1.103 raeburn 488: $usehttp = &check_http_req(\$newloc,$hostname);
1.92 raeburn 489: if ($hash{'encrypted_'.$id}) {
490: $newloc=&Apache::lonenc::encrypted($newloc);
1.101 raeburn 491: }
492: if ($newloc =~ m{^(/adm/wrapper/ext/[^\#]+)(?:|(\#[^\#]+))$}) {
1.100 raeburn 493: my ($url,$anchor) = ($1,$2);
494: if ($anchor) {
1.101 raeburn 495: $newloc = $url.(($url=~/\?/)?'&':'?').'symb='.&escape($last).$anchor;
1.100 raeburn 496: }
1.92 raeburn 497: }
1.50 albertel 498: } else {
1.57 www 499: $newloc='/adm/navmaps';
1.50 albertel 500: }
1.36 www 501: untie %hash;
1.10 www 502: } else {
1.57 www 503: $newloc='/adm/navmaps';
1.89 raeburn 504: }
1.94 raeburn 505: if (($usehttp) && ($hostname ne '')) {
506: $newloc='http://'.$hostname.$newloc;
1.93 raeburn 507: } else {
508: $newloc=&Apache::lonnet::absolute_url().$newloc
509: }
1.97 raeburn 510: if ($reinitcheck eq 'update') {
511: $r->print(&reinited_js($newloc,$env{'request.course.id'},100));
512: $r->print(&Apache::loncommon::end_page());
513: return OK;
514: } else {
515: &Apache::loncommon::content_type($r,'text/html');
516: $r->header_out(Location => $newloc);
517: return REDIRECT;
518: }
1.10 www 519: }
1.35 www 520: #
521: # Is the current URL on the map? If not, start with last known URL
522: #
1.89 raeburn 523:
1.35 www 524: unless (&Apache::lonnet::is_on_map($currenturl)) {
1.89 raeburn 525: if ($preupdatepos) {
526: undef($preupdatepos);
527: } elsif (tie(%hash,'GDBM_File',$env{'request.course.fn'}.'_symb.db',
528: &GDBM_READER(),0640)) {
529: $last=$hash{'last_known'};
1.7 www 530: untie(%hash);
531: }
532: if ($last) {
1.52 albertel 533: $currenturl=&Apache::lonnet::clutter((&Apache::lonnet::decode_symb($last))[2]);
1.7 www 534: } else {
1.97 raeburn 535: my $newloc = &Apache::lonnet::absolute_url().
536: '/adm/navmaps';
537: if ($reinitcheck eq 'update') {
538: &Apache::lonhtmlcommon::Close_PrgWin($r,\%prog_state);
539: $r->print(&reinited_js($newloc,$env{'request.course.id'},100));
540: $r->print(&Apache::loncommon::end_page());
541: return OK;
542: } else {
543: &Apache::loncommon::content_type($r,'text/html');
544: $r->header_out(Location => $newloc);
545: return REDIRECT;
546: }
1.7 www 547: }
548: }
1.3 www 549: # ------------------------------------------- Do we have any idea where we are?
550: my $position;
1.89 raeburn 551: if ($preupdatepos) {
552: $position = $preupdatepos;
553: } else {
554: $position=Apache::lonnet::symbread($currenturl);
555: }
556: if ($position) {
1.3 www 557: # ------------------------------------------------------------------------- Yes
1.41 www 558: my ($startoutmap,$mapnum,$thisurl)=&Apache::lonnet::decode_symb($position);
1.52 albertel 559: $cachehash{$startoutmap}{$thisurl}=[$thisurl,$mapnum];
1.23 www 560: $cachehash{$startoutmap}{'last_known'}=
1.52 albertel 561: [&Apache::lonnet::declutter($currenturl),$mapnum];
1.20 albertel 562:
1.5 www 563: # ============================================================ Tie the big hash
1.53 albertel 564: if (tie(%hash,'GDBM_File',$env{'request.course.fn'}.'.db',
1.28 albertel 565: &GDBM_READER(),0640)) {
1.29 www 566: my $rid=$hash{'map_pc_'.&Apache::lonnet::clutter($startoutmap)}.
567: '.'.$mapnum;
1.14 www 568:
1.15 www 569: # ------------------------------------------------- Move forward, backward, etc
1.22 www 570: my $endupmap;
571: ($next,$endupmap)=&move($rid,$startoutmap,$direction);
1.15 www 572: # -------------------------------------- Do we have one and only one empty URL?
1.22 www 573: # We are now at at least one non-empty URL
1.4 www 574: # ----------------------------------------------------- Check out possibilities
575: if ($next) {
576: @possibilities=split(/\,/,$next);
577: if ($#possibilities==0) {
1.5 www 578: # ---------------------------------------------- Only one possibility, redirect
1.90 raeburn 579: ($redirecturl,$redirectsymb,$enc,$anchor)=&hash_src($next);
1.52 albertel 580: $cachehash{$endupmap}{$redirecturl}=
581: [$redirecturl,(split(/\./,$next))[1]];
1.4 www 582: } else {
1.5 www 583: # ------------------------ There are multiple possibilities for a next resource
584: $multichoice=1;
1.62 albertel 585: foreach my $id (@possibilities) {
586: $multichoicehash{'src_'.$id}=$hash{'src_'.$id};
587: $multichoicehash{'title_'.$id}=$hash{'title_'.$id};
588: $multichoicehash{'type_'.$id}=$hash{'type_'.$id};
589: (my $first, my $second) = $id =~ /(\d+).(\d+)/;
590: my $symbSrc = Apache::lonnet::declutter($hash{'src_'.$id});
591: $multichoicehash{'symb_'.$id} =
1.32 bowersj2 592: Apache::lonnet::declutter($hash{'map_id_'.$first}.'___'.
593: $second.'___'.$symbSrc);
594:
1.62 albertel 595: my ($choicemap,$choiceres)=split(/\./,$id);
1.52 albertel 596: my $map=&Apache::lonnet::declutter($hash{'src_'.$choicemap});
1.62 albertel 597: my $url=$multichoicehash{'src_'.$id};
1.52 albertel 598: $cachehash{$map}{$url}=[$url,$choiceres];
1.62 albertel 599: }
1.4 www 600: }
1.5 www 601: } else {
602: # -------------------------------------------------------------- No place to go
603: $multichoice=-1;
1.98 raeburn 604: if ($hash{'deeplinkonly_'.$rid}) {
605: (my $value,$deeplinklevel) = split(/:/,$hash{'deeplinkonly_'.$rid});
606: }
1.4 www 607: }
1.5 www 608: # ----------------- The program must come past this point to untie the big hash
1.3 www 609: untie(%hash);
1.5 www 610: # --------------------------------------------------------- Store position info
1.52 albertel 611: $cachehash{$startoutmap}{'last_direction'}=[$direction,'notasymb'];
1.86 raeburn 612: foreach my $thismap (keys(%cachehash)) {
1.52 albertel 613: my $mapnum=$cachehash{$thismap}->{'mapnum'};
614: delete($cachehash{$thismap}->{'mapnum'});
615: &Apache::lonnet::symblist($thismap,
616: %{$cachehash{$thismap}});
1.19 www 617: }
1.5 www 618: # ============================================== Do not return before this line
1.4 www 619: if ($redirecturl) {
1.5 www 620: # ----------------------------------------------------- There is a URL to go to
1.38 www 621: if ($direction eq 'forward') {
622: &Apache::lonnet::linklog($currenturl,$redirecturl);
623: }
624: if ($direction eq 'back') {
625: &Apache::lonnet::linklog($redirecturl,$currenturl);
626: }
1.85 musolffc 627: # ------------------------------------- Check for and display critical messages
1.96 raeburn 628: my ($redirect, $url) = &Apache::loncommon::critical_redirect(300,'flip');
1.89 raeburn 629: unless ($redirect) {
1.103 raeburn 630: my $usehttp = &check_http_req(\$redirecturl,$hostname);
1.94 raeburn 631: if (($usehttp) && ($hostname ne '')) {
632: $url='http://'.$hostname.$redirecturl;
1.93 raeburn 633: } else {
634: $url=&Apache::lonnet::absolute_url().$redirecturl;
635: }
1.90 raeburn 636: my $addanchor;
637: if (($anchor ne '') && (!$enc || $env{'request.role.adv'})) {
638: $addanchor = 1;
639: $url =~ s/\#.+$//;
640: }
1.89 raeburn 641: $url = &add_get_param($url, { 'symb' => $redirectsymb});
1.90 raeburn 642: if ($addanchor) {
643: $url .= $anchor;
644: }
1.85 musolffc 645: }
1.97 raeburn 646: if ($reinitcheck eq 'update') {
647: &Apache::lonhtmlcommon::Close_PrgWin($r,\%prog_state);
648: $r->print(&reinited_js($url,$env{'request.course.id'},100));
649: $r->print(&Apache::loncommon::end_page());
650: return OK;
651: } else {
652: &Apache::loncommon::content_type($r,'text/html');
653: $r->header_out(Location => $url);
654: return REDIRECT;
655: }
1.5 www 656: } else {
657: # --------------------------------------------------------- There was a problem
1.51 albertel 658: &Apache::loncommon::content_type($r,'text/html');
1.8 www 659: $r->send_http_header;
1.59 www 660: my %lt=&Apache::lonlocal::texthash('title' => 'End of Sequence',
1.98 raeburn 661: 'deeplink' => 'No link available',
662: 'deeplinkres' =>
663: 'Navigation to other content is unavailable when accessing content via deep-linking',
664: 'deeplinkmap' =>
665: 'You have reached the end of the sequence of available materials for access via deep-linking',
1.59 www 666: 'explain' =>
667: 'You have reached the end of the sequence of materials.',
668: 'back' => 'Go Back',
1.83 raeburn 669: 'nav' => 'Course Contents',
1.59 www 670: 'wherenext' =>
671: 'There are several possibilities of where to go next',
672: 'pick' =>
673: 'Please click on the the resource you intend to access',
674: 'titleheader' => 'Title',
1.89 raeburn 675: 'type' => 'Type',
676: 'update' => 'Content updated',
677: 'expupdate' => 'As a result of a recent update to the sequence of materials, it is not possible to complete the page flip.',
1.91 raeburn 678: 'gonav' => 'Go to the Contents page to select a resource to display.',
679: );
1.83 raeburn 680: if (&Apache::loncommon::course_type() eq 'Community') {
681: $lt{'nav'} = &mt('Community Contents');
682: }
1.8 www 683: if ($#possibilities>0) {
1.67 albertel 684: my $start_page=
685: &Apache::loncommon::start_page('Multiple Resources');
1.8 www 686: $r->print(<<ENDSTART);
1.67 albertel 687: $start_page
1.59 www 688: <h3>$lt{'wherenext'}</h3>
1.8 www 689: <p>
1.59 www 690: $lt{'pick'}:
1.8 www 691: <p>
1.79 bisitz 692: <table border="2">
1.59 www 693: <tr><th>$lt{'titleheader'}</th><th>$lt{'type'}</th></tr>
1.8 www 694: ENDSTART
1.62 albertel 695: foreach my $id (@possibilities) {
1.92 raeburn 696: my $src = $multichoicehash{'src_'.$id};
1.103 raeburn 697: my $usehttp = &check_http_req(\$src,$hostname);
1.94 raeburn 698: if (($usehttp) && ($hostname ne '')) {
699: $src = 'http://'.$hostname.$src;
1.93 raeburn 700: }
1.8 www 701: $r->print(
702: '<tr><td><a href="'.
1.92 raeburn 703: &add_get_param($src,
1.66 albertel 704: {'symb' =>
705: $multichoicehash{'symb_'.$id},
706: }).'">'.
1.62 albertel 707: $multichoicehash{'title_'.$id}.
708: '</a></td><td>'.$multichoicehash{'type_'.$id}.
1.8 www 709: '</td></tr>');
1.26 www 710: }
1.59 www 711: $r->print('</table>');
1.8 www 712: } else {
1.89 raeburn 713: if ($reinitcheck) {
714: if (&Apache::loncommon::course_type() eq 'Community') {
715: $r->print(
716: &Apache::loncommon::start_page('Community Contents Updated'));
717: } else {
718: $r->print(
719: &Apache::loncommon::start_page('Course Contents Updated'));
720: }
721: $r->print('<h2>'.$lt{'update'}.'</h2>'
722: .'<p>'.$lt{'expupdate'}.'<br />'
723: .$lt{'gonav'}.'</p>');
724: } else {
1.91 raeburn 725: if (($env{'course.'.$env{'request.course.id'}.'.type'} eq 'Placement') &&
726: (!$env{'request.role.adv'})) {
727: my ($score,$incomplete) = &Apache::lonplacementtest::check_completion(undef,undef,1);
728: if ($incomplete) {
729: $r->print(&Apache::lonplacementtest::showincomplete($incomplete));
730: } else {
731: $r->print(&Apache::lonplacementtest::showresult(1));
732: }
1.98 raeburn 733: } else {
1.91 raeburn 734: $r->print(
1.98 raeburn 735: &Apache::loncommon::start_page('No Resource'));
736: if ($deeplinklevel eq 'resource') {
737: $r->print('<h2>'.$lt{'deeplink'}.'</h2>'
738: .'<p>'.$lt{'deeplinkres'}.'</p>');
739: } elsif ($deeplinklevel eq 'map') {
740: $r->print('<h2>'.$lt{'title'}.'</h2>'
741: .'<p>'.$lt{'deeplinkmap'}.'</p>');
742: } else {
743: $r->print('<h2>'.$lt{'title'}.'</h2>'
744: .'<p>'.$lt{'explain'}.'</p>');
745: }
1.91 raeburn 746: }
747: }
748: }
749: unless (($env{'course.'.$env{'request.course.id'}.'.type'} eq 'Placement') ||
750: ($env{'request.role.adv'})) {
1.98 raeburn 751: if ($deeplinklevel) {
752: $r->print(
753: &Apache::lonhtmlcommon::actionbox(
754: ['<a href="/adm/flip?postdata=return:">'.$lt{'back'}.'</a>']));
755: } elsif ((!@possibilities) && ($reinitcheck)) {
1.91 raeburn 756: $r->print(
757: &Apache::lonhtmlcommon::actionbox(
758: ['<a href="/adm/navmaps">'.$lt{'nav'}.'</a></li>'
759: ]));
760: } else {
1.89 raeburn 761: $r->print(
1.91 raeburn 762: &Apache::lonhtmlcommon::actionbox(
763: ['<a href="/adm/flip?postdata=return:">'.$lt{'back'}.'</a></li>',
764: '<a href="/adm/navmaps">'.$lt{'nav'}.'</a></li>'
765: ]));
1.89 raeburn 766: }
1.91 raeburn 767:
1.82 bisitz 768: }
1.89 raeburn 769: $r->print(&Apache::loncommon::end_page());
770:
1.59 www 771: return OK;
772: }
1.5 www 773: } else {
774: # ------------------------------------------------- Problem, could not tie hash
1.97 raeburn 775: if ($reinitcheck eq 'update') {
776: &Apache::lonhtmlcommon::Close_PrgWin($r,\%prog_state);
777: $r->print(&Apache::loncommon::end_page());
778: }
1.53 albertel 779: $env{'user.error.msg'}="/adm/flip:bre:0:1:Course Data Missing";
1.5 www 780: return HTTP_NOT_ACCEPTABLE;
1.3 www 781: }
1.5 www 782: } else {
783: # ---------------------------------------- No, could not determine where we are
1.97 raeburn 784: my $newloc = '/adm/ambiguous';
785: if ($reinitcheck eq 'update') {
786: &Apache::lonhtmlcommon::Close_PrgWin($r,\%prog_state);
787: $r->print(&reinited_js($newloc,$env{'request.course.id'},100));
788: $r->print(&Apache::loncommon::end_page());
789: } else {
790: $r->internal_redirect($newloc);
791: }
1.81 raeburn 792: return OK;
1.2 www 793: }
1.5 www 794: } else {
1.2 www 795: # -------------------------- Class was not initialized or page fliped strangely
1.53 albertel 796: $env{'user.error.msg'}="/adm/flip:bre:0:0:Choose Course";
1.2 www 797: return HTTP_NOT_ACCEPTABLE;
798: }
1.1 www 799: }
800:
801: 1;
802: __END__
803:
1.77 jms 804: =pod
805:
806: =head1 NAME
807:
808: Apache::lonpageflip
809:
810: =head1 SYNOPSIS
811:
812: Deals with forward, backward, and other page flips.
813:
814: This is part of the LearningOnline Network with CAPA project
815: described at http://www.lon-capa.org.
816:
817: =head1 OVERVIEW
818:
819: (empty)
820:
821: =head1 SUBROUTINES
822:
823: =over cleanup()
824:
825: =item addrid()
826:
827: =item fullmove()
828:
829: =item hash_src()
830:
831: =item move()
832:
833: =item get_next_possible_move()
834:
835: =item first_accessible_resource()
836:
837: =item handler()
838:
839: =back
840:
841: =cut
1.1 www 842:
843:
844:
845:
846:
847:
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>