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