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