Annotation of rat/lonpageflip.pm, revision 1.80.8.10.2.1
1.1 www 1: # The LearningOnline Network with CAPA
2: #
3: # Page flip handler
4: #
1.80.8.10.2.1! (raeburn 5:: # $Id: lonpageflip.pm,v 1.80.8.10 2018/09/10 19:17:39 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.74 albertel 234: my %args;
235: my ($url,$args) = split(/\?/,$furl);
236: foreach my $pair (split(/\&/,$args)) {
237: my ($name,$value) = split(/=/,$pair);
238: $args{&unescape($name)} = &unescape($value);
239: }
1.80.8.6 raeburn 240: if (!&Apache::lonnet::allowed('bre',$url,$args{'symb'})) {
1.69 www 241: # Wow, we cannot see this ... move forward to the next one that we can see
242: my ($newrid,$newmap)=&move($hash{'first_rid'},$hash{'first_mapurl'},'forward');
243: # Build the new URL
1.73 albertel 244: my ($newmapid,$newresid)=split(/\./,$newrid);
1.69 www 245: my $symb=&Apache::lonnet::encode_symb($newmap,$newresid,$hash{'src_'.$newrid});
246: $furl=&add_get_param($hash{'src_'.$newrid},{ 'symb' => $symb });
247: if ($hash{'encrypted_'.$newrid}) {
248: $furl=&Apache::lonenc::encrypted($furl);
249: }
250: }
251: untie(%hash);
252: return $furl;
253: } else {
254: return '/adm/navmaps';
255: }
256: }
257:
1.80.8.10 raeburn 258: sub reinited_js {
259: my ($url,$cid,$timeout) = @_;
260: if (!$timeout) {
261: $timeout = 0;
262: }
263: return <<"END";
264: <script type="text/javascript">
265: // <![CDATA[
266: setTimeout(function() {
267: var newurl = '$url';
268: if (document.getElementById('LC_update_$cid')) {
269: document.getElementById('LC_update_$cid').style.display = 'none';
270: }
271: if ((newurl !== null) && (newurl !== '') && (newurl !== 'undefined')) {
272: window.location.href = "$url";
273: }
274: }, $timeout);
275: // ]]>
276: </script>
277: END
278: }
279:
1.1 www 280: # ================================================================ Main Handler
281:
282: sub handler {
1.2 www 283: my $r=shift;
1.1 www 284:
285: # ------------------------------------------- Set document type for header only
286:
1.2 www 287: if ($r->header_only) {
1.51 albertel 288: &Apache::loncommon::content_type($r,'text/html');
289: $r->send_http_header;
290: return OK;
1.2 www 291: }
292:
1.5 www 293: my %cachehash=();
294: my $multichoice=0;
295: my %multichoicehash=();
1.80.8.10 raeburn 296: my %prog_state=();
1.80.8.9 raeburn 297: my ($redirecturl,$redirectsymb,$enc,$anchor);
1.4 www 298: my $next='';
299: my @possibilities=();
1.37 www 300: &Apache::loncommon::get_unprocessed_cgi($ENV{'QUERY_STRING'},['postdata']);
1.53 albertel 301: if (($env{'form.postdata'})&&($env{'request.course.fn'})) {
1.80.8.7 raeburn 302: my ($direction,$currenturl) = ($env{'form.postdata'}=~/(\w+)\:(.*)/);
1.80.8.8 raeburn 303: if ($currenturl=~m|^/enc/|) {
304: $currenturl=&Apache::lonenc::unencrypted($currenturl);
305: }
306: $currenturl=~s/\.\d+\.(\w+)$/\.$1/;
307: $currenturl=~s/^https?\:\/\///;
308: $currenturl=~s/^[^\/]+//;
309: my ($preupdatepos,$last,$reinitcheck);
310: if ($direction eq 'return') {
311: if (tie(%hash,'GDBM_File',$env{'request.course.fn'}.'_symb.db',
312: &GDBM_READER(),0640)) {
313: $last=$hash{'last_known'};
314: untie(%hash);
315: }
316: }
1.80.8.7 raeburn 317: if ($env{'request.course.id'}) {
318: # Check if course needs to be re-initialized
319: my $loncaparev = $r->dir_config('lonVersion');
1.80.8.8 raeburn 320: ($reinitcheck,my @reinit) = &Apache::loncommon::needs_coursereinit($loncaparev);
321: if ($reinitcheck eq 'switch') {
1.80.8.7 raeburn 322: &Apache::loncommon::content_type($r,'text/html');
323: $r->send_http_header;
324: $r->print(&Apache::loncommon::check_release_result(@reinit));
325: return OK;
1.80.8.8 raeburn 326: } elsif ($reinitcheck eq 'update') {
1.80.8.7 raeburn 327: my $cnum = $env{'course.'.$env{'request.course.id'}.'.num'};
328: my $cdom = $env{'course.'.$env{'request.course.id'}.'.domain'};
1.80.8.8 raeburn 329: $preupdatepos = &Apache::lonnet::symbread($currenturl);
330: unless ($direction eq 'return') {
331: if (tie(%hash,'GDBM_File',$env{'request.course.fn'}.'_symb.db',
332: &GDBM_READER(),0640)) {
333: $last=$hash{'last_known'};
334: untie(%hash);
335: }
336: }
1.80.8.10 raeburn 337: &Apache::loncommon::content_type($r,'text/html');
338: $r->send_http_header;
339: $r->print(&Apache::loncommon::start_page('Content Changed'));
340: my $preamble = '<div id="LC_update_'.$env{'request.course.id'}.'" class="LC_info">'.
341: '<br />'.
342: &mt('Your course session is being updated because of recent changes by course personnel.').
343: ' '.&mt('Please be patient.').'<br /></div>'.
344: '<div style="padding:0;clear:both;margin:0;border:0"></div>';
345: %prog_state = &Apache::lonhtmlcommon::Create_PrgWin($r,undef,$preamble);
346: &Apache::lonhtmlcommon::Update_PrgWin($r,\%prog_state,&mt('Updating course'));
1.80.8.7 raeburn 347: my ($furl,$ferr) = &Apache::lonuserstate::readmap("$cdom/$cnum");
1.80.8.10 raeburn 348: &Apache::lonhtmlcommon::Update_PrgWin($r,\%prog_state,&mt('Finished'));
1.80.8.7 raeburn 349: if ($ferr) {
1.80.8.10 raeburn 350: &Apache::lonhtmlcommon::Close_PrgWin($r,\%prog_state);
1.80.8.7 raeburn 351: my $requrl = $r->uri;
352: $env{'user.error.msg'}="$requrl:bre:0:0:Course not initialized";
353: $env{'user.reinit'} = 1;
354: return HTTP_NOT_ACCEPTABLE;
1.80.8.8 raeburn 355: } else {
356: if ($last) {
357: my ($murl,$id,$fn)=&Apache::lonnet::decode_symb($last);
358: unless (&Apache::lonnet::symbverify($last,$fn)) {
359: undef($last);
360: }
361: }
1.80.8.7 raeburn 362: }
363: }
364: }
1.54 albertel 365: if ($direction eq 'firstres') {
1.69 www 366: my $furl=&first_accessible_resource();
1.80.8.10 raeburn 367: $furl=&Apache::lonnet::absolute_url().$furl;
368: if ($reinitcheck eq 'update') {
369: &Apache::lonhtmlcommon::Close_PrgWin($r,\%prog_state);
370: $r->print(&reinited_js($furl,$env{'request.course.id'},100));
371: $r->print(&Apache::loncommon::end_page());
372: return OK;
373: } else {
374: &Apache::loncommon::content_type($r,'text/html');
375: $r->header_out(Location => $furl);
376: return REDIRECT;
377: }
1.54 albertel 378: }
1.80.8.6 raeburn 379: if ($direction eq 'return') {
1.10 www 380: # -------------------------------------------------------- Return to last known
381: my $newloc;
1.53 albertel 382: if (($last) && (tie(%hash,'GDBM_File',$env{'request.course.fn'}.'.db',
1.36 www 383: &GDBM_READER(),0640))) {
1.52 albertel 384: my ($murl,$id,$fn)=&Apache::lonnet::decode_symb($last);
1.50 albertel 385: $id=$hash{'map_pc_'.&Apache::lonnet::clutter($murl)}.'.'.$id;
386: $newloc=$hash{'src_'.$id};
387: if ($newloc) {
388: if ($hash{'encrypted_'.$id}) { $newloc=&Apache::lonenc::encrypted($newloc); }
389: } else {
1.57 www 390: $newloc='/adm/navmaps';
1.50 albertel 391: }
1.36 www 392: untie %hash;
1.10 www 393: } else {
1.57 www 394: $newloc='/adm/navmaps';
1.80.8.1 raeburn 395: }
1.80.8.10 raeburn 396: $newloc=&Apache::lonnet::absolute_url().$newloc;
397: if ($reinitcheck eq 'update') {
398: $r->print(&reinited_js($newloc,$env{'request.course.id'},100));
399: $r->print(&Apache::loncommon::end_page());
400: return OK;
401: } else {
402: &Apache::loncommon::content_type($r,'text/html');
403: $r->header_out(Location => $newloc);
404: return REDIRECT;
405: }
1.10 www 406: }
1.35 www 407: #
408: # Is the current URL on the map? If not, start with last known URL
409: #
1.80.8.8 raeburn 410:
1.35 www 411: unless (&Apache::lonnet::is_on_map($currenturl)) {
1.80.8.8 raeburn 412: if ($preupdatepos) {
413: undef($preupdatepos);
414: } elsif (tie(%hash,'GDBM_File',$env{'request.course.fn'}.'_symb.db',
415: &GDBM_READER(),0640)) {
416: $last=$hash{'last_known'};
1.7 www 417: untie(%hash);
418: }
419: if ($last) {
1.52 albertel 420: $currenturl=&Apache::lonnet::clutter((&Apache::lonnet::decode_symb($last))[2]);
1.7 www 421: } else {
1.80.8.10 raeburn 422: my $newloc = &Apache::lonnet::absolute_url().
423: '/adm/navmaps';
424: if ($reinitcheck eq 'update') {
425: &Apache::lonhtmlcommon::Close_PrgWin($r,\%prog_state);
426: $r->print(&reinited_js($newloc,$env{'request.course.id'},100));
427: $r->print(&Apache::loncommon::end_page());
428: return OK;
429: } else {
430: &Apache::loncommon::content_type($r,'text/html');
431: $r->header_out(Location => $newloc);
432: return REDIRECT;
433: }
1.7 www 434: }
435: }
1.3 www 436: # ------------------------------------------- Do we have any idea where we are?
437: my $position;
1.80.8.8 raeburn 438: if ($preupdatepos) {
439: $position = $preupdatepos;
440: } else {
441: $position=Apache::lonnet::symbread($currenturl);
442: }
443: if ($position) {
1.3 www 444: # ------------------------------------------------------------------------- Yes
1.41 www 445: my ($startoutmap,$mapnum,$thisurl)=&Apache::lonnet::decode_symb($position);
1.52 albertel 446: $cachehash{$startoutmap}{$thisurl}=[$thisurl,$mapnum];
1.23 www 447: $cachehash{$startoutmap}{'last_known'}=
1.52 albertel 448: [&Apache::lonnet::declutter($currenturl),$mapnum];
1.20 albertel 449:
1.5 www 450: # ============================================================ Tie the big hash
1.53 albertel 451: if (tie(%hash,'GDBM_File',$env{'request.course.fn'}.'.db',
1.28 albertel 452: &GDBM_READER(),0640)) {
1.29 www 453: my $rid=$hash{'map_pc_'.&Apache::lonnet::clutter($startoutmap)}.
454: '.'.$mapnum;
1.14 www 455:
1.15 www 456: # ------------------------------------------------- Move forward, backward, etc
1.22 www 457: my $endupmap;
458: ($next,$endupmap)=&move($rid,$startoutmap,$direction);
1.15 www 459: # -------------------------------------- Do we have one and only one empty URL?
1.22 www 460: # We are now at at least one non-empty URL
1.4 www 461: # ----------------------------------------------------- Check out possibilities
462: if ($next) {
463: @possibilities=split(/\,/,$next);
464: if ($#possibilities==0) {
1.5 www 465: # ---------------------------------------------- Only one possibility, redirect
1.80.8.9 raeburn 466: ($redirecturl,$redirectsymb,$enc,$anchor)=&hash_src($next);
1.52 albertel 467: $cachehash{$endupmap}{$redirecturl}=
468: [$redirecturl,(split(/\./,$next))[1]];
1.4 www 469: } else {
1.5 www 470: # ------------------------ There are multiple possibilities for a next resource
471: $multichoice=1;
1.62 albertel 472: foreach my $id (@possibilities) {
473: $multichoicehash{'src_'.$id}=$hash{'src_'.$id};
474: $multichoicehash{'title_'.$id}=$hash{'title_'.$id};
475: $multichoicehash{'type_'.$id}=$hash{'type_'.$id};
476: (my $first, my $second) = $id =~ /(\d+).(\d+)/;
477: my $symbSrc = Apache::lonnet::declutter($hash{'src_'.$id});
478: $multichoicehash{'symb_'.$id} =
1.32 bowersj2 479: Apache::lonnet::declutter($hash{'map_id_'.$first}.'___'.
480: $second.'___'.$symbSrc);
481:
1.62 albertel 482: my ($choicemap,$choiceres)=split(/\./,$id);
1.52 albertel 483: my $map=&Apache::lonnet::declutter($hash{'src_'.$choicemap});
1.62 albertel 484: my $url=$multichoicehash{'src_'.$id};
1.52 albertel 485: $cachehash{$map}{$url}=[$url,$choiceres];
1.62 albertel 486: }
1.4 www 487: }
1.5 www 488: } else {
489: # -------------------------------------------------------------- No place to go
490: $multichoice=-1;
1.4 www 491: }
1.5 www 492: # ----------------- The program must come past this point to untie the big hash
1.3 www 493: untie(%hash);
1.5 www 494: # --------------------------------------------------------- Store position info
1.52 albertel 495: $cachehash{$startoutmap}{'last_direction'}=[$direction,'notasymb'];
1.80.8.7 raeburn 496: foreach my $thismap (keys(%cachehash)) {
1.52 albertel 497: my $mapnum=$cachehash{$thismap}->{'mapnum'};
498: delete($cachehash{$thismap}->{'mapnum'});
499: &Apache::lonnet::symblist($thismap,
500: %{$cachehash{$thismap}});
1.19 www 501: }
1.5 www 502: # ============================================== Do not return before this line
1.4 www 503: if ($redirecturl) {
1.5 www 504: # ----------------------------------------------------- There is a URL to go to
1.38 www 505: if ($direction eq 'forward') {
506: &Apache::lonnet::linklog($currenturl,$redirecturl);
507: }
508: if ($direction eq 'back') {
509: &Apache::lonnet::linklog($redirecturl,$currenturl);
510: }
1.80.8.5 raeburn 511: # ------------------------------------- Check for and display critical messages
1.80.8.10.2.1! (raeburn 512:: my ($redirect, $url) = &Apache::loncommon::critical_redirect(300,'flip');
1.80.8.5 raeburn 513: unless ($redirect) {
514: $url=&Apache::lonnet::absolute_url().$redirecturl;
1.80.8.9 raeburn 515: my $addanchor;
516: if (($anchor ne '') && (!$enc || $env{'request.role.adv'})) {
517: $addanchor = 1;
518: $url =~ s/\#.+$//;
519: }
1.80.8.5 raeburn 520: $url = &add_get_param($url, { 'symb' => $redirectsymb});
1.80.8.9 raeburn 521: if ($addanchor) {
522: $url .= $anchor;
523: }
1.80.8.1 raeburn 524: }
1.80.8.10 raeburn 525: if ($reinitcheck eq 'update') {
526: &Apache::lonhtmlcommon::Close_PrgWin($r,\%prog_state);
527: $r->print(&reinited_js($url,$env{'request.course.id'},100));
528: $r->print(&Apache::loncommon::end_page());
529: return OK;
530: } else {
531: &Apache::loncommon::content_type($r,'text/html');
532: $r->header_out(Location => $url);
533: return REDIRECT;
534: }
1.5 www 535: } else {
536: # --------------------------------------------------------- There was a problem
1.51 albertel 537: &Apache::loncommon::content_type($r,'text/html');
1.8 www 538: $r->send_http_header;
1.59 www 539: my %lt=&Apache::lonlocal::texthash('title' => 'End of Sequence',
540: 'explain' =>
541: 'You have reached the end of the sequence of materials.',
542: 'back' => 'Go Back',
1.80.8.3 raeburn 543: 'nav' => 'Course Contents',
1.59 www 544: 'wherenext' =>
545: 'There are several possibilities of where to go next',
546: 'pick' =>
547: 'Please click on the the resource you intend to access',
548: 'titleheader' => 'Title',
1.80.8.8 raeburn 549: 'type' => 'Type',
550: 'update' => 'Content updated',
551: 'expupdate' => 'As a result of a recent update to the sequence of materials, it is not possible to complete the page flip.',
552: 'gonav' => 'Go to the Contents page to select a resource to display.');
1.80.8.3 raeburn 553: if (&Apache::loncommon::course_type() eq 'Community') {
554: $lt{'nav'} = &mt('Community Contents');
555: }
1.8 www 556: if ($#possibilities>0) {
1.67 albertel 557: my $start_page=
558: &Apache::loncommon::start_page('Multiple Resources');
1.8 www 559: $r->print(<<ENDSTART);
1.67 albertel 560: $start_page
1.59 www 561: <h3>$lt{'wherenext'}</h3>
1.8 www 562: <p>
1.59 www 563: $lt{'pick'}:
1.8 www 564: <p>
1.79 bisitz 565: <table border="2">
1.59 www 566: <tr><th>$lt{'titleheader'}</th><th>$lt{'type'}</th></tr>
1.8 www 567: ENDSTART
1.62 albertel 568: foreach my $id (@possibilities) {
1.8 www 569: $r->print(
570: '<tr><td><a href="'.
1.66 albertel 571: &add_get_param($multichoicehash{'src_'.$id},
572: {'symb' =>
573: $multichoicehash{'symb_'.$id},
574: }).'">'.
1.62 albertel 575: $multichoicehash{'title_'.$id}.
576: '</a></td><td>'.$multichoicehash{'type_'.$id}.
1.8 www 577: '</td></tr>');
1.26 www 578: }
1.59 www 579: $r->print('</table>');
1.8 www 580: } else {
1.80.8.8 raeburn 581: if ($reinitcheck) {
582: if (&Apache::loncommon::course_type() eq 'Community') {
583: $r->print(
584: &Apache::loncommon::start_page('Community Contents Updated'));
585: } else {
586: $r->print(
587: &Apache::loncommon::start_page('Course Contents Updated'));
588: }
589: $r->print('<h2>'.$lt{'update'}.'</h2>'
590: .'<p>'.$lt{'expupdate'}.'<br />'
591: .$lt{'gonav'}.'</p>');
592: } else {
593: $r->print(
594: &Apache::loncommon::start_page('No Resource')
595: .'<h2>'.$lt{'title'}.'</h2>'
596: .'<p>'.$lt{'explain'}.'</p>');
597: }
1.59 www 598: }
1.80.8.8 raeburn 599: if ((!@possibilities) && ($reinitcheck)) {
600: $r->print(
601: &Apache::lonhtmlcommon::actionbox(
602: ['<a href="/adm/navmaps">'.$lt{'nav'}.'</a></li>'
603: ]));
604: } else {
605: $r->print(
606: &Apache::lonhtmlcommon::actionbox(
607: ['<a href="/adm/flip?postdata=return:">'.$lt{'back'}.'</a></li>',
608: '<a href="/adm/navmaps">'.$lt{'nav'}.'</a></li>'
609: ]));
610: }
611: $r->print(&Apache::loncommon::end_page());
612:
1.59 www 613: return OK;
614: }
1.5 www 615: } else {
616: # ------------------------------------------------- Problem, could not tie hash
1.80.8.10 raeburn 617: if ($reinitcheck eq 'update') {
618: &Apache::lonhtmlcommon::Close_PrgWin($r,\%prog_state);
619: $r->print(&Apache::loncommon::end_page());
620: }
1.53 albertel 621: $env{'user.error.msg'}="/adm/flip:bre:0:1:Course Data Missing";
1.5 www 622: return HTTP_NOT_ACCEPTABLE;
1.3 www 623: }
1.5 www 624: } else {
625: # ---------------------------------------- No, could not determine where we are
1.80.8.10 raeburn 626: my $newloc = '/adm/ambiguous';
627: if ($reinitcheck eq 'update') {
628: &Apache::lonhtmlcommon::Close_PrgWin($r,\%prog_state);
629: $r->print(&reinited_js($newloc,$env{'request.course.id'},100));
630: $r->print(&Apache::loncommon::end_page());
631: } else {
632: $r->internal_redirect($newloc);
633: }
1.80.8.2 raeburn 634: return OK;
1.2 www 635: }
1.5 www 636: } else {
1.2 www 637: # -------------------------- Class was not initialized or page fliped strangely
1.53 albertel 638: $env{'user.error.msg'}="/adm/flip:bre:0:0:Choose Course";
1.2 www 639: return HTTP_NOT_ACCEPTABLE;
640: }
1.1 www 641: }
642:
643: 1;
644: __END__
645:
1.77 jms 646: =pod
647:
648: =head1 NAME
649:
650: Apache::lonpageflip
651:
652: =head1 SYNOPSIS
653:
654: Deals with forward, backward, and other page flips.
655:
656: This is part of the LearningOnline Network with CAPA project
657: described at http://www.lon-capa.org.
658:
659: =head1 OVERVIEW
660:
661: (empty)
662:
663: =head1 SUBROUTINES
664:
665: =over cleanup()
666:
667: =item addrid()
668:
669: =item fullmove()
670:
671: =item hash_src()
672:
673: =item move()
674:
675: =item get_next_possible_move()
676:
677: =item first_accessible_resource()
678:
679: =item handler()
680:
681: =back
682:
683: =cut
1.1 www 684:
685:
686:
687:
688:
689:
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>