1: # The LearningOnline Network with CAPA
2: #
3: # Page flip handler
4: #
5: # $Id: lonpageflip.pm,v 1.94 2017/02/25 19:40:29 raeburn Exp $
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: #
29:
30:
31:
32: package Apache::lonpageflip;
33:
34: use strict;
35: use LONCAPA;
36: use Apache::Constants qw(:common :http REDIRECT);
37: use Apache::lonnet;
38: use Apache::loncommon();
39: use Apache::lonnavmaps();
40: use Apache::lonuserstate;
41: use Apache::lonlocal;
42: use HTML::TokeParser;
43: use GDBM_File;
44:
45: # ========================================================== Module Global Hash
46:
47: my %hash;
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: }
56: return OK;
57: }
58:
59: sub addrid {
60: my ($current,$new,$condid)=@_;
61: unless ($condid) { $condid=0; }
62:
63: if ($current) {
64: $current.=','.$new;
65: } else {
66: $current=''.$new;
67: }
68:
69: return $current;
70: }
71:
72: sub fullmove {
73: my ($rid,$mapurl,$direction)=@_;
74: if (tie(%hash,'GDBM_File',$env{'request.course.fn'}.'.db',
75: &GDBM_READER(),0640)) {
76: ($rid,$mapurl)=&move($rid,$mapurl,$direction);
77: untie(%hash);
78: }
79: return($rid,$mapurl);
80: }
81:
82: sub hash_src {
83: my ($id)=@_;
84: my ($mapid,$resid)=split(/\./,$id);
85: my $symb=&Apache::lonnet::encode_symb($hash{'map_id_'.$mapid},
86: $resid,$hash{'src_'.$id});
87: my $anchor;
88: if ($hash{'ext_'.$id} eq 'true:') {
89: if ($hash{'src_'.$id} =~ /(\#.+)$/) {
90: $anchor = $1;
91: }
92: }
93: if ($hash{'encrypted_'.$id}) {
94: return (&Apache::lonenc::encrypted($hash{'src_'.$id}),
95: &Apache::lonenc::encrypted($symb),
96: $hash{'encrypted_'.$id},$anchor);
97: }
98: return ($hash{'src_'.$id},$symb,$hash{'encrypted_'.$id},$anchor);
99: }
100:
101: sub move {
102: my ($next,$endupmap,$direction) = @_;
103: my $safecount=0;
104: my $allowed=0;
105: do {
106: ($next,$endupmap)=&get_next_possible_move($next,$endupmap,$direction);
107:
108: my $url = $hash{'src_'.$next};
109: my ($mapid,$resid)=split(/\./,$next);
110: my $symb = &Apache::lonnet::encode_symb($hash{'map_id_'.$mapid},
111: $resid,$url);
112: if ($url eq '' || $symb eq '') {
113: $allowed = 0;
114: } else {
115: my $priv = &Apache::lonnet::allowed('bre',$url,$symb);
116: $allowed = (($priv eq 'F') || ($priv eq '2'));
117: }
118: $safecount++;
119: } while ( ($next)
120: && ($next!~/\,/)
121: && (
122: (!$hash{'src_'.$next})
123: || (
124: (!$env{'request.role.adv'})
125: && $hash{'randomout_'.$next}
126: )
127: || (!$allowed)
128: )
129: && ($safecount<10000));
130:
131: return ($next,$endupmap);
132: }
133:
134: sub get_next_possible_move {
135: my ($rid,$mapurl,$direction)=@_;
136: my $startoutrid=$rid;
137:
138: my $next='';
139:
140: my $mincond=1;
141: my $posnext='';
142: if ($direction eq 'forward') {
143: # --------------------------------------------------------------------- Forward
144: while ($hash{'type_'.$rid} eq 'finish') {
145: $rid=$hash{'ids_'.$hash{'map_id_'.(split(/\./,$rid))[0]}};
146: }
147: foreach my $id (split(/\,/,$hash{'to_'.$rid})) {
148: my $condition= $hash{'conditions_'.$hash{'goesto_'.$id}};
149: my $rescond = &Apache::lonnet::docondval($condition);
150: my $linkcond = &Apache::lonnet::directcondval($hash{'condid_'.$hash{'undercond_'.$id}});
151: my $thiscond = ($rescond<$linkcond)?$rescond:$linkcond;
152: if ($thiscond>=$mincond) {
153: if ($posnext) {
154: $posnext.=','.$id.':'.$thiscond;
155: } else {
156: $posnext=$id.':'.$thiscond;
157: }
158: if ($thiscond>$mincond) { $mincond=$thiscond; }
159: }
160: }
161: foreach my $id (split(/\,/,$posnext)) {
162: my ($linkid,$condval)=split(/\:/,$id);
163: if ($condval>=$mincond) {
164: $next=&addrid($next,$hash{'goesto_'.$linkid},
165: $hash{'condid_'.$hash{'undercond_'.$linkid}});
166: }
167: }
168: if ($hash{'is_map_'.$next}) {
169: # This jumps to the beginning of a new map (going down level)
170: if (
171: $hash{'map_type_'.$hash{'map_pc_'.$hash{'src_'.$next}}} eq 'sequence') {
172: $mapurl=$hash{'src_'.$next};
173: $next=$hash{'map_start_'.$hash{'src_'.$next}};
174: } elsif (
175: # This jumps back up from an empty sequence, to a page up one level
176: $hash{'map_type_'.$hash{'map_pc_'.$hash{'src_'.$next}}} eq 'page') {
177: $mapurl=$hash{'map_id_'.(split(/\./,$next))[0]};
178: }
179: } elsif
180: ((split(/\./,$startoutrid))[0]!=(split(/\./,$next))[0]) {
181: # This comes up from a map (coming up one level);
182: $mapurl=$hash{'map_id_'.(split(/\./,$next))[0]};
183: }
184: } elsif ($direction eq 'back') {
185: # ------------------------------------------------------------------- Backwards
186: while ($hash{'type_'.$rid} eq 'start') {
187: $rid=$hash{'ids_'.$hash{'map_id_'.(split(/\./,$rid))[0]}};
188: }
189: foreach my $id (split(/\,/,$hash{'from_'.$rid})) {
190: my $condition= $hash{'conditions_'.$hash{'comesfrom_'.$id}};
191: my $rescond = &Apache::lonnet::docondval($condition);
192: my $linkcond = &Apache::lonnet::directcondval($hash{'condid_'.$hash{'undercond_'.$id}});
193: my $thiscond = ($rescond<$linkcond)?$rescond:$linkcond;
194: if ($thiscond>=$mincond) {
195: if ($posnext) {
196: $posnext.=','.$id.':'.$thiscond;
197: } else {
198: $posnext=$id.':'.$thiscond;
199: }
200: if ($thiscond>$mincond) { $mincond=$thiscond; }
201: }
202: }
203: foreach my $id (split(/\,/,$posnext)) {
204: my ($linkid,$condval)=split(/\:/,$id);
205: if ($condval>=$mincond) {
206: $next=&addrid($next,$hash{'comesfrom_'.$linkid},
207: $hash{'condid_'.$hash{'undercond_'.$linkid}});
208: }
209: }
210: if ($hash{'is_map_'.$next}) {
211: # This jumps to the end of a new map (going down one level)
212: if (
213: $hash{'map_type_'.$hash{'map_pc_'.$hash{'src_'.$next}}} eq 'sequence') {
214: $mapurl=$hash{'src_'.$next};
215: $next=$hash{'map_finish_'.$hash{'src_'.$next}};
216: } elsif (
217: $hash{'map_type_'.$hash{'map_pc_'.$hash{'src_'.$next}}} eq 'page') {
218: # This jumps back up from an empty sequence, to a page up one level
219: $mapurl=$hash{'map_id_'.(split(/\./,$next))[0]};
220: }
221: } elsif
222: ((split(/\./,$startoutrid))[0]!=(split(/\./,$next))[0]) {
223: # This comes back up from a map (going up one level);
224: $mapurl=$hash{'map_id_'.(split(/\./,$next))[0]};
225: }
226: }
227: return ($next,$mapurl);
228: }
229:
230: sub first_accessible_resource {
231: my $furl;
232: if (tie(%hash,'GDBM_File',$env{'request.course.fn'}.'.db',
233: &GDBM_READER(),0640)) {
234: $furl=$hash{'first_url'};
235: my %args;
236: my ($url,$args) = split(/\?/,$furl);
237: foreach my $pair (split(/\&/,$args)) {
238: my ($name,$value) = split(/=/,$pair);
239: $args{&unescape($name)} = &unescape($value);
240: }
241: if (!&Apache::lonnet::allowed('bre',$url,$args{'symb'})) {
242: # Wow, we cannot see this ... move forward to the next one that we can see
243: my ($newrid,$newmap)=&move($hash{'first_rid'},$hash{'first_mapurl'},'forward');
244: # Build the new URL
245: my ($newmapid,$newresid)=split(/\./,$newrid);
246: my $symb=&Apache::lonnet::encode_symb($newmap,$newresid,$hash{'src_'.$newrid});
247: $furl=&add_get_param($hash{'src_'.$newrid},{ 'symb' => $symb });
248: if ($hash{'encrypted_'.$newrid}) {
249: $furl=&Apache::lonenc::encrypted($furl);
250: }
251: }
252: untie(%hash);
253: return $furl;
254: } else {
255: return '/adm/navmaps';
256: }
257: }
258:
259: sub first_answerable_ressymb {
260: my $navmap = Apache::lonnavmaps::navmap->new;
261: return unless (ref($navmap));
262: my $iterator = $navmap->getIterator(undef,undef,undef,1);
263: return unless (ref($iterator));
264: my ($curRes,$result);
265: while ($curRes = $iterator->next()) {
266: if (ref($curRes) && $curRes->is_problem()) {
267: foreach my $part (@{$curRes->parts()}) {
268: if ($curRes->tries($part) < $curRes->maxtries($part)) {
269: $result = $curRes->link().'?symb='.$curRes->shown_symb();
270: last;
271: }
272: }
273: }
274: }
275: if ($result) {
276: return $result;
277: } else {
278: return &first_accessible_resource();
279: }
280: }
281:
282: sub check_for_syllabus {
283: my ($srcref) = @_;
284: return unless (ref($srcref) eq 'SCALAR');
285: my $usehttp;
286: if ($env{'request.course.id'}) {
287: my $cnum = $env{'course.'.$env{'request.course.id'}.'.num'};
288: my $cdom = $env{'course.'.$env{'request.course.id'}.'.domain'};
289: if (($$srcref =~ m{^\Q/public/$cdom/$cnum/syllabus\E($|\?)}) &&
290: ($ENV{'SERVER_PORT'} == 443) &&
291: ($env{'course.'.$env{'request.course.id'}.'.externalsyllabus'} =~ m{^http://})) {
292: $$srcref .= (($$srcref =~/\?/)? '&':'?') . 'usehttp=1';
293: $usehttp = 1;
294: }
295: }
296: return $usehttp;
297: }
298:
299: # ================================================================ Main Handler
300:
301: sub handler {
302: my $r=shift;
303:
304: # ------------------------------------------- Set document type for header only
305:
306: if ($r->header_only) {
307: &Apache::loncommon::content_type($r,'text/html');
308: $r->send_http_header;
309: return OK;
310: }
311:
312: my %cachehash=();
313: my $multichoice=0;
314: my %multichoicehash=();
315: my ($redirecturl,$redirectsymb,$enc,$anchor);
316: my $next='';
317: my $hostname = $r->hostname();
318: my @possibilities=();
319: &Apache::loncommon::get_unprocessed_cgi($ENV{'QUERY_STRING'},['postdata']);
320: if (($env{'form.postdata'})&&($env{'request.course.fn'})) {
321: my ($direction,$currenturl) = ($env{'form.postdata'}=~/(\w+)\:(.*)/);
322: if ($currenturl=~m|^/enc/|) {
323: $currenturl=&Apache::lonenc::unencrypted($currenturl);
324: }
325: $currenturl=~s/\.\d+\.(\w+)$/\.$1/;
326: $currenturl=~s/^https?\:\/\///;
327: $currenturl=~s/^[^\/]+//;
328: my ($preupdatepos,$last,$reinitcheck);
329: if ($direction eq 'return') {
330: if (tie(%hash,'GDBM_File',$env{'request.course.fn'}.'_symb.db',
331: &GDBM_READER(),0640)) {
332: $last=$hash{'last_known'};
333: untie(%hash);
334: }
335: } elsif ($direction eq 'firstanswerable') {
336: my $furl = &first_answerable_ressymb();
337: my $usehttp = &check_for_syllabus(\$furl);
338: if (($usehttp) && ($hostname ne '')) {
339: $furl='http://'.$hostname.$furl;
340: } else {
341: $furl=&Apache::lonnet::absolute_url().$furl;
342: }
343: &Apache::loncommon::content_type($r,'text/html');
344: $r->header_out(Location => $furl);
345: return REDIRECT;
346: } elsif ($direction eq 'endplacement') {
347: &Apache::loncommon::content_type($r,'text/html');
348: $r->send_http_header;
349: $r->print(&Apache::lonplacementtest::showresult());
350: return OK;
351: }
352: if ($env{'request.course.id'}) {
353: # Check if course needs to be re-initialized
354: my $loncaparev = $r->dir_config('lonVersion');
355: ($reinitcheck,my @reinit) = &Apache::loncommon::needs_coursereinit($loncaparev);
356: if ($reinitcheck eq 'switch') {
357: &Apache::loncommon::content_type($r,'text/html');
358: $r->send_http_header;
359: $r->print(&Apache::loncommon::check_release_result(@reinit));
360: return OK;
361: } elsif ($reinitcheck eq 'update') {
362: my $cnum = $env{'course.'.$env{'request.course.id'}.'.num'};
363: my $cdom = $env{'course.'.$env{'request.course.id'}.'.domain'};
364: $preupdatepos = &Apache::lonnet::symbread($currenturl);
365: unless ($direction eq 'return') {
366: if (tie(%hash,'GDBM_File',$env{'request.course.fn'}.'_symb.db',
367: &GDBM_READER(),0640)) {
368: $last=$hash{'last_known'};
369: untie(%hash);
370: }
371: }
372: my ($furl,$ferr) = &Apache::lonuserstate::readmap("$cdom/$cnum");
373: if ($ferr) {
374: my $requrl = $r->uri;
375: $env{'user.error.msg'}="$requrl:bre:0:0:Course not initialized";
376: $env{'user.reinit'} = 1;
377: return HTTP_NOT_ACCEPTABLE;
378: } else {
379: if ($last) {
380: my ($murl,$id,$fn)=&Apache::lonnet::decode_symb($last);
381: unless (&Apache::lonnet::symbverify($last,$fn)) {
382: undef($last);
383: }
384: }
385: }
386: }
387: }
388: if ($direction eq 'firstres') {
389: my $furl=&first_accessible_resource();
390: my $usehttp = &check_for_syllabus(\$furl);
391: if (($usehttp) && ($hostname ne '')) {
392: $furl='http://'.$hostname.$furl;
393: } else {
394: $furl=&Apache::lonnet::absolute_url().$furl;
395: }
396: &Apache::loncommon::content_type($r,'text/html');
397: $r->header_out(Location => $furl);
398: return REDIRECT;
399: }
400: if ($direction eq 'return') {
401: # -------------------------------------------------------- Return to last known
402: my ($newloc,$usehttp);
403: if (($last) && (tie(%hash,'GDBM_File',$env{'request.course.fn'}.'.db',
404: &GDBM_READER(),0640))) {
405: my ($murl,$id,$fn)=&Apache::lonnet::decode_symb($last);
406: $id=$hash{'map_pc_'.&Apache::lonnet::clutter($murl)}.'.'.$id;
407: $newloc=$hash{'src_'.$id};
408: if ($newloc) {
409: $usehttp = &check_for_syllabus(\$newloc);
410: if ($hash{'encrypted_'.$id}) {
411: $newloc=&Apache::lonenc::encrypted($newloc);
412: } elsif ($newloc =~ m{^(/adm/wrapper/ext/[^\#]+)\#([^\#]+)$}) {
413: $newloc = $1.&escape('#').$2;
414: }
415: } else {
416: $newloc='/adm/navmaps';
417: }
418: untie %hash;
419: } else {
420: $newloc='/adm/navmaps';
421: }
422: if (($usehttp) && ($hostname ne '')) {
423: $newloc='http://'.$hostname.$newloc;
424: } else {
425: $newloc=&Apache::lonnet::absolute_url().$newloc
426: }
427: &Apache::loncommon::content_type($r,'text/html');
428: $r->header_out(Location => $newloc);
429: return REDIRECT;
430: }
431: #
432: # Is the current URL on the map? If not, start with last known URL
433: #
434:
435: unless (&Apache::lonnet::is_on_map($currenturl)) {
436: if ($preupdatepos) {
437: undef($preupdatepos);
438: } elsif (tie(%hash,'GDBM_File',$env{'request.course.fn'}.'_symb.db',
439: &GDBM_READER(),0640)) {
440: $last=$hash{'last_known'};
441: untie(%hash);
442: }
443: my $newloc;
444: if ($last) {
445: $currenturl=&Apache::lonnet::clutter((&Apache::lonnet::decode_symb($last))[2]);
446: } else {
447: &Apache::loncommon::content_type($r,'text/html');
448: $r->header_out(Location =>
449: &Apache::lonnet::absolute_url().
450: '/adm/navmaps');
451: return REDIRECT;
452: }
453: }
454: # ------------------------------------------- Do we have any idea where we are?
455: my $position;
456: if ($preupdatepos) {
457: $position = $preupdatepos;
458: } else {
459: $position=Apache::lonnet::symbread($currenturl);
460: }
461: if ($position) {
462: # ------------------------------------------------------------------------- Yes
463: my ($startoutmap,$mapnum,$thisurl)=&Apache::lonnet::decode_symb($position);
464: $cachehash{$startoutmap}{$thisurl}=[$thisurl,$mapnum];
465: $cachehash{$startoutmap}{'last_known'}=
466: [&Apache::lonnet::declutter($currenturl),$mapnum];
467:
468: # ============================================================ Tie the big hash
469: if (tie(%hash,'GDBM_File',$env{'request.course.fn'}.'.db',
470: &GDBM_READER(),0640)) {
471: my $rid=$hash{'map_pc_'.&Apache::lonnet::clutter($startoutmap)}.
472: '.'.$mapnum;
473:
474: # ------------------------------------------------- Move forward, backward, etc
475: my $endupmap;
476: ($next,$endupmap)=&move($rid,$startoutmap,$direction);
477: # -------------------------------------- Do we have one and only one empty URL?
478: # We are now at at least one non-empty URL
479: # ----------------------------------------------------- Check out possibilities
480: if ($next) {
481: @possibilities=split(/\,/,$next);
482: if ($#possibilities==0) {
483: # ---------------------------------------------- Only one possibility, redirect
484: ($redirecturl,$redirectsymb,$enc,$anchor)=&hash_src($next);
485: $cachehash{$endupmap}{$redirecturl}=
486: [$redirecturl,(split(/\./,$next))[1]];
487: } else {
488: # ------------------------ There are multiple possibilities for a next resource
489: $multichoice=1;
490: foreach my $id (@possibilities) {
491: $multichoicehash{'src_'.$id}=$hash{'src_'.$id};
492: $multichoicehash{'title_'.$id}=$hash{'title_'.$id};
493: $multichoicehash{'type_'.$id}=$hash{'type_'.$id};
494: (my $first, my $second) = $id =~ /(\d+).(\d+)/;
495: my $symbSrc = Apache::lonnet::declutter($hash{'src_'.$id});
496: $multichoicehash{'symb_'.$id} =
497: Apache::lonnet::declutter($hash{'map_id_'.$first}.'___'.
498: $second.'___'.$symbSrc);
499:
500: my ($choicemap,$choiceres)=split(/\./,$id);
501: my $map=&Apache::lonnet::declutter($hash{'src_'.$choicemap});
502: my $url=$multichoicehash{'src_'.$id};
503: $cachehash{$map}{$url}=[$url,$choiceres];
504: }
505: }
506: } else {
507: # -------------------------------------------------------------- No place to go
508: $multichoice=-1;
509: }
510: # ----------------- The program must come past this point to untie the big hash
511: untie(%hash);
512: # --------------------------------------------------------- Store position info
513: $cachehash{$startoutmap}{'last_direction'}=[$direction,'notasymb'];
514: foreach my $thismap (keys(%cachehash)) {
515: my $mapnum=$cachehash{$thismap}->{'mapnum'};
516: delete($cachehash{$thismap}->{'mapnum'});
517: &Apache::lonnet::symblist($thismap,
518: %{$cachehash{$thismap}});
519: }
520: # ============================================== Do not return before this line
521: if ($redirecturl) {
522: # ----------------------------------------------------- There is a URL to go to
523: if ($direction eq 'forward') {
524: &Apache::lonnet::linklog($currenturl,$redirecturl);
525: }
526: if ($direction eq 'back') {
527: &Apache::lonnet::linklog($redirecturl,$currenturl);
528: }
529: # ------------------------------------- Check for and display critical messages
530: my ($redirect, $url) = &Apache::loncommon::critical_redirect(300);
531: unless ($redirect) {
532: my $usehttp = &check_for_syllabus(\$redirecturl);
533: if (($usehttp) && ($hostname ne '')) {
534: $url='http://'.$hostname.$redirecturl;
535: } else {
536: $url=&Apache::lonnet::absolute_url().$redirecturl;
537: }
538: my $addanchor;
539: if (($anchor ne '') && (!$enc || $env{'request.role.adv'})) {
540: $addanchor = 1;
541: $url =~ s/\#.+$//;
542: }
543: $url = &add_get_param($url, { 'symb' => $redirectsymb});
544: if ($addanchor) {
545: $url .= $anchor;
546: }
547: }
548: &Apache::loncommon::content_type($r,'text/html');
549: $r->header_out(Location => $url);
550: return REDIRECT;
551: } else {
552: # --------------------------------------------------------- There was a problem
553: &Apache::loncommon::content_type($r,'text/html');
554: $r->send_http_header;
555: my %lt=&Apache::lonlocal::texthash('title' => 'End of Sequence',
556: 'explain' =>
557: 'You have reached the end of the sequence of materials.',
558: 'back' => 'Go Back',
559: 'nav' => 'Course Contents',
560: 'wherenext' =>
561: 'There are several possibilities of where to go next',
562: 'pick' =>
563: 'Please click on the the resource you intend to access',
564: 'titleheader' => 'Title',
565: 'type' => 'Type',
566: 'update' => 'Content updated',
567: 'expupdate' => 'As a result of a recent update to the sequence of materials, it is not possible to complete the page flip.',
568: 'gonav' => 'Go to the Contents page to select a resource to display.',
569: );
570: if (&Apache::loncommon::course_type() eq 'Community') {
571: $lt{'nav'} = &mt('Community Contents');
572: }
573: if ($#possibilities>0) {
574: my $start_page=
575: &Apache::loncommon::start_page('Multiple Resources');
576: $r->print(<<ENDSTART);
577: $start_page
578: <h3>$lt{'wherenext'}</h3>
579: <p>
580: $lt{'pick'}:
581: <p>
582: <table border="2">
583: <tr><th>$lt{'titleheader'}</th><th>$lt{'type'}</th></tr>
584: ENDSTART
585: foreach my $id (@possibilities) {
586: my $src = $multichoicehash{'src_'.$id};
587: my $usehttp = &check_for_syllabus(\$src);
588: if (($usehttp) && ($hostname ne '')) {
589: $src = 'http://'.$hostname.$src;
590: }
591: $r->print(
592: '<tr><td><a href="'.
593: &add_get_param($src,
594: {'symb' =>
595: $multichoicehash{'symb_'.$id},
596: }).'">'.
597: $multichoicehash{'title_'.$id}.
598: '</a></td><td>'.$multichoicehash{'type_'.$id}.
599: '</td></tr>');
600: }
601: $r->print('</table>');
602: } else {
603: if ($reinitcheck) {
604: if (&Apache::loncommon::course_type() eq 'Community') {
605: $r->print(
606: &Apache::loncommon::start_page('Community Contents Updated'));
607: } else {
608: $r->print(
609: &Apache::loncommon::start_page('Course Contents Updated'));
610: }
611: $r->print('<h2>'.$lt{'update'}.'</h2>'
612: .'<p>'.$lt{'expupdate'}.'<br />'
613: .$lt{'gonav'}.'</p>');
614: } else {
615: if (($env{'course.'.$env{'request.course.id'}.'.type'} eq 'Placement') &&
616: (!$env{'request.role.adv'})) {
617: my ($score,$incomplete) = &Apache::lonplacementtest::check_completion(undef,undef,1);
618: if ($incomplete) {
619: $r->print(&Apache::lonplacementtest::showincomplete($incomplete));
620: } else {
621: $r->print(&Apache::lonplacementtest::showresult(1));
622: }
623: } else {
624: $r->print(
625: &Apache::loncommon::start_page('No Resource')
626: .'<h2>'.$lt{'title'}.'</h2>'
627: .'<p>'.$lt{'explain'}.'</p>');
628: }
629: }
630: }
631: unless (($env{'course.'.$env{'request.course.id'}.'.type'} eq 'Placement') ||
632: ($env{'request.role.adv'})) {
633: if ((!@possibilities) && ($reinitcheck)) {
634: $r->print(
635: &Apache::lonhtmlcommon::actionbox(
636: ['<a href="/adm/navmaps">'.$lt{'nav'}.'</a></li>'
637: ]));
638: } else {
639: $r->print(
640: &Apache::lonhtmlcommon::actionbox(
641: ['<a href="/adm/flip?postdata=return:">'.$lt{'back'}.'</a></li>',
642: '<a href="/adm/navmaps">'.$lt{'nav'}.'</a></li>'
643: ]));
644: }
645:
646: }
647: $r->print(&Apache::loncommon::end_page());
648:
649: return OK;
650: }
651: } else {
652: # ------------------------------------------------- Problem, could not tie hash
653: $env{'user.error.msg'}="/adm/flip:bre:0:1:Course Data Missing";
654: return HTTP_NOT_ACCEPTABLE;
655: }
656: } else {
657: # ---------------------------------------- No, could not determine where we are
658: $r->internal_redirect('/adm/ambiguous');
659: return OK;
660: }
661: } else {
662: # -------------------------- Class was not initialized or page fliped strangely
663: $env{'user.error.msg'}="/adm/flip:bre:0:0:Choose Course";
664: return HTTP_NOT_ACCEPTABLE;
665: }
666: }
667:
668: 1;
669: __END__
670:
671: =pod
672:
673: =head1 NAME
674:
675: Apache::lonpageflip
676:
677: =head1 SYNOPSIS
678:
679: Deals with forward, backward, and other page flips.
680:
681: This is part of the LearningOnline Network with CAPA project
682: described at http://www.lon-capa.org.
683:
684: =head1 OVERVIEW
685:
686: (empty)
687:
688: =head1 SUBROUTINES
689:
690: =over cleanup()
691:
692: =item addrid()
693:
694: =item fullmove()
695:
696: =item hash_src()
697:
698: =item move()
699:
700: =item get_next_possible_move()
701:
702: =item first_accessible_resource()
703:
704: =item handler()
705:
706: =back
707:
708: =cut
709:
710:
711:
712:
713:
714:
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>