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