File:  [LON-CAPA] / rat / lonpageflip.pm
Revision 1.91: download - view: text, annotated - select for diffs
Mon May 30 02:52:42 2016 UTC (7 years, 11 months ago) by raeburn
Branches: MAIN
CVS tags: HEAD
- Bug 6808. New course container -- "Placement" for Placement Tests.
  - Placement Tets includes 'firstanswerable' as a direction to
    take student to first unanaswered proble in an incomplete test.

    1: # The LearningOnline Network with CAPA
    2: #
    3: # Page flip handler
    4: #
    5: # $Id: lonpageflip.pm,v 1.91 2016/05/30 02:52:42 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: # ================================================================ Main Handler
  283: 
  284: sub handler {
  285:    my $r=shift;
  286: 
  287: # ------------------------------------------- Set document type for header only
  288: 
  289:   if ($r->header_only) {
  290:       &Apache::loncommon::content_type($r,'text/html');
  291:       $r->send_http_header;
  292:       return OK;
  293:   }
  294: 
  295:   my %cachehash=(); 
  296:   my $multichoice=0;
  297:   my %multichoicehash=();
  298:   my ($redirecturl,$redirectsymb,$enc,$anchor);
  299:   my $next='';
  300:   my @possibilities=();
  301:    &Apache::loncommon::get_unprocessed_cgi($ENV{'QUERY_STRING'},['postdata']);
  302:   if (($env{'form.postdata'})&&($env{'request.course.fn'})) {
  303:       my ($direction,$currenturl) = ($env{'form.postdata'}=~/(\w+)\:(.*)/);
  304:       if ($currenturl=~m|^/enc/|) {
  305:           $currenturl=&Apache::lonenc::unencrypted($currenturl);
  306:       }
  307:       $currenturl=~s/\.\d+\.(\w+)$/\.$1/;
  308:       $currenturl=~s/^https?\:\/\///;
  309:       $currenturl=~s/^[^\/]+//;
  310:       my ($preupdatepos,$last,$reinitcheck);
  311:       if ($direction eq 'return') {
  312:           if (tie(%hash,'GDBM_File',$env{'request.course.fn'}.'_symb.db',
  313:                     &GDBM_READER(),0640)) {
  314:               $last=$hash{'last_known'};
  315:               untie(%hash);
  316:           }
  317:       } elsif ($direction eq 'firstanswerable') {
  318:           my $furl = &first_answerable_ressymb();
  319:           &Apache::loncommon::content_type($r,'text/html');
  320:           $r->header_out(Location =>
  321:                          &Apache::lonnet::absolute_url().$furl);
  322:           return REDIRECT;
  323:       } elsif ($direction eq 'endplacement') {
  324:           &Apache::loncommon::content_type($r,'text/html');
  325:           $r->send_http_header;
  326:           $r->print(&Apache::lonplacementtest::showresult());
  327:           return OK;
  328:       }
  329:       if ($env{'request.course.id'}) {
  330:           # Check if course needs to be re-initialized
  331:           my $loncaparev = $r->dir_config('lonVersion');
  332:           ($reinitcheck,my @reinit) = &Apache::loncommon::needs_coursereinit($loncaparev);
  333:           if ($reinitcheck eq 'switch') {
  334:               &Apache::loncommon::content_type($r,'text/html');
  335:               $r->send_http_header;
  336:               $r->print(&Apache::loncommon::check_release_result(@reinit));
  337:               return OK;
  338:           } elsif ($reinitcheck eq 'update') {
  339:               my $cnum = $env{'course.'.$env{'request.course.id'}.'.num'};
  340:               my $cdom = $env{'course.'.$env{'request.course.id'}.'.domain'};
  341:               $preupdatepos = &Apache::lonnet::symbread($currenturl);
  342:               unless ($direction eq 'return') {
  343:                   if (tie(%hash,'GDBM_File',$env{'request.course.fn'}.'_symb.db',
  344:                                 &GDBM_READER(),0640)) {
  345:                       $last=$hash{'last_known'};
  346:                       untie(%hash);
  347:                   }
  348:               }
  349:               my ($furl,$ferr) = &Apache::lonuserstate::readmap("$cdom/$cnum");
  350:               if ($ferr) {
  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;
  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:                   }
  362:               }
  363:           }
  364:       }
  365:       if ($direction eq 'firstres') {
  366: 	  my $furl=&first_accessible_resource();
  367: 	  &Apache::loncommon::content_type($r,'text/html');
  368: 	  $r->header_out(Location => 
  369: 			 &Apache::lonnet::absolute_url().$furl);
  370: 	     
  371: 	  return REDIRECT;
  372:       }
  373:       if ($direction eq 'return') { 
  374: # -------------------------------------------------------- Return to last known
  375:          my $newloc;
  376:          if (($last) && (tie(%hash,'GDBM_File',$env{'request.course.fn'}.'.db',
  377:                         &GDBM_READER(),0640))) {
  378:             my ($murl,$id,$fn)=&Apache::lonnet::decode_symb($last);
  379: 	    $id=$hash{'map_pc_'.&Apache::lonnet::clutter($murl)}.'.'.$id;
  380: 	    $newloc=$hash{'src_'.$id};
  381: 	    if ($newloc) {
  382: 		if ($hash{'encrypted_'.$id}) { $newloc=&Apache::lonenc::encrypted($newloc); }
  383: 	    } else {
  384: 		$newloc='/adm/navmaps';
  385: 	    }
  386:             untie %hash;
  387:          } else {
  388: 	    $newloc='/adm/navmaps';
  389:          }
  390: 	 &Apache::loncommon::content_type($r,'text/html');
  391: 	 $r->header_out(Location => 
  392: 			&Apache::lonnet::absolute_url().$newloc);
  393: 	     
  394: 	 return REDIRECT;
  395:       }
  396: #
  397: # Is the current URL on the map? If not, start with last known URL
  398: #
  399: 
  400:       unless (&Apache::lonnet::is_on_map($currenturl)) {
  401:          if ($preupdatepos) {
  402:              undef($preupdatepos);
  403:          } elsif (tie(%hash,'GDBM_File',$env{'request.course.fn'}.'_symb.db',
  404:                             &GDBM_READER(),0640)) {
  405:              $last=$hash{'last_known'};
  406:              untie(%hash);
  407:          }
  408:          my $newloc;
  409:          if ($last) {
  410: 	     $currenturl=&Apache::lonnet::clutter((&Apache::lonnet::decode_symb($last))[2]);
  411: 	 } else {
  412: 	     &Apache::loncommon::content_type($r,'text/html');
  413: 	     $r->header_out(Location => 
  414: 			    &Apache::lonnet::absolute_url().
  415: 			    '/adm/navmaps');
  416: 	     return REDIRECT;
  417:          }
  418:       }
  419: # ------------------------------------------- Do we have any idea where we are?
  420:       my $position;
  421:       if ($preupdatepos) {
  422:           $position = $preupdatepos;
  423:       } else {
  424:           $position=Apache::lonnet::symbread($currenturl);
  425:       }
  426:       if ($position) {
  427: # ------------------------------------------------------------------------- Yes
  428: 	  my ($startoutmap,$mapnum,$thisurl)=&Apache::lonnet::decode_symb($position);
  429:           $cachehash{$startoutmap}{$thisurl}=[$thisurl,$mapnum];
  430:           $cachehash{$startoutmap}{'last_known'}=
  431:                              [&Apache::lonnet::declutter($currenturl),$mapnum];
  432: 
  433: # ============================================================ Tie the big hash
  434:           if (tie(%hash,'GDBM_File',$env{'request.course.fn'}.'.db',
  435:                         &GDBM_READER(),0640)) {
  436:               my $rid=$hash{'map_pc_'.&Apache::lonnet::clutter($startoutmap)}.
  437:                       '.'.$mapnum;
  438: 
  439: # ------------------------------------------------- Move forward, backward, etc
  440:               my $endupmap;
  441:               ($next,$endupmap)=&move($rid,$startoutmap,$direction);
  442: # -------------------------------------- Do we have one and only one empty URL?
  443: # We are now at at least one non-empty URL
  444: # ----------------------------------------------------- Check out possibilities
  445:               if ($next) {
  446:                   @possibilities=split(/\,/,$next);
  447:                   if ($#possibilities==0) {
  448: # ---------------------------------------------- Only one possibility, redirect
  449: 	              ($redirecturl,$redirectsymb,$enc,$anchor)=&hash_src($next);
  450:                       $cachehash{$endupmap}{$redirecturl}=
  451: 			  [$redirecturl,(split(/\./,$next))[1]];
  452:                   } else {
  453: # ------------------------ There are multiple possibilities for a next resource
  454:                       $multichoice=1;
  455: 		      foreach my $id (@possibilities) {
  456: 			  $multichoicehash{'src_'.$id}=$hash{'src_'.$id};
  457:                           $multichoicehash{'title_'.$id}=$hash{'title_'.$id};
  458:                           $multichoicehash{'type_'.$id}=$hash{'type_'.$id};
  459:                           (my $first, my $second) = $id =~ /(\d+).(\d+)/;
  460:                           my $symbSrc = Apache::lonnet::declutter($hash{'src_'.$id});
  461:                           $multichoicehash{'symb_'.$id} = 
  462:                               Apache::lonnet::declutter($hash{'map_id_'.$first}.'___'.
  463:                                                         $second.'___'.$symbSrc);
  464:                                                          
  465:                           my ($choicemap,$choiceres)=split(/\./,$id);
  466: 			  my $map=&Apache::lonnet::declutter($hash{'src_'.$choicemap});
  467: 			  my $url=$multichoicehash{'src_'.$id};
  468:                           $cachehash{$map}{$url}=[$url,$choiceres];
  469:                       }
  470:                   }
  471: 	      } else {
  472: # -------------------------------------------------------------- No place to go
  473:                   $multichoice=-1;
  474:               }
  475: # ----------------- The program must come past this point to untie the big hash
  476: 	      untie(%hash);
  477: # --------------------------------------------------------- Store position info
  478:               $cachehash{$startoutmap}{'last_direction'}=[$direction,'notasymb'];
  479:               foreach my $thismap (keys(%cachehash)) {
  480: 		  my $mapnum=$cachehash{$thismap}->{'mapnum'};
  481: 		  delete($cachehash{$thismap}->{'mapnum'});
  482: 		  &Apache::lonnet::symblist($thismap,
  483: 					    %{$cachehash{$thismap}});
  484: 	      }
  485: # ============================================== Do not return before this line
  486:               if ($redirecturl) {
  487: # ----------------------------------------------------- There is a URL to go to
  488: 		  if ($direction eq 'forward') {
  489:                      &Apache::lonnet::linklog($currenturl,$redirecturl);
  490: 		  }
  491: 		  if ($direction eq 'back') {
  492:                      &Apache::lonnet::linklog($redirecturl,$currenturl);
  493: 		  }
  494: # ------------------------------------- Check for and display critical messages
  495:                   my ($redirect, $url) = &Apache::loncommon::critical_redirect(300);
  496:                   unless ($redirect) {
  497:                       $url=&Apache::lonnet::absolute_url().$redirecturl;
  498:                       my $addanchor;
  499:                       if (($anchor ne '') && (!$enc || $env{'request.role.adv'})) {
  500:                           $addanchor = 1;
  501:                           $url =~ s/\#.+$//;
  502:                       }
  503:                       $url = &add_get_param($url, { 'symb' => $redirectsymb});
  504:                       if ($addanchor) {
  505:                           $url .= $anchor;
  506:                       }
  507:                   }
  508:                   &Apache::loncommon::content_type($r,'text/html');
  509:                   $r->header_out(Location => $url);
  510:                   return REDIRECT;
  511: 	      } else {
  512: # --------------------------------------------------------- There was a problem
  513:                   &Apache::loncommon::content_type($r,'text/html');
  514:                   $r->send_http_header;
  515: 		  my %lt=&Apache::lonlocal::texthash('title' => 'End of Sequence',
  516: 						     'explain' =>
  517: 						     'You have reached the end of the sequence of materials.',
  518: 						     'back' => 'Go Back',
  519: 						     'nav' => 'Course Contents',
  520: 						     'wherenext' =>
  521: 						     'There are several possibilities of where to go next',
  522: 						     'pick' =>
  523: 						     'Please click on the the resource you intend to access',
  524: 						     'titleheader' => 'Title',
  525: 						     'type' => 'Type',
  526:                                                      'update' => 'Content updated',
  527:                                                      'expupdate' => 'As a result of a recent update to the sequence of materials, it is not possible to complete the page flip.',
  528:                                                      'gonav' => 'Go to the Contents page to select a resource to display.',
  529:                                                      );
  530:                   if (&Apache::loncommon::course_type() eq 'Community') {
  531:                       $lt{'nav'} = &mt('Community Contents');
  532:                   }
  533:                   if ($#possibilities>0) {
  534: 		      my $start_page=
  535: 			  &Apache::loncommon::start_page('Multiple Resources');
  536:                      $r->print(<<ENDSTART);
  537: $start_page
  538: <h3>$lt{'wherenext'}</h3>
  539: <p>
  540: $lt{'pick'}:
  541: <p>
  542: <table border="2">
  543: <tr><th>$lt{'titleheader'}</th><th>$lt{'type'}</th></tr>
  544: ENDSTART
  545:                      foreach my $id (@possibilities) {
  546:                         $r->print(
  547:                               '<tr><td><a href="'.
  548: 				  &add_get_param($multichoicehash{'src_'.$id},
  549: 						 {'symb' =>
  550: 						      $multichoicehash{'symb_'.$id},
  551: 						  }).'">'.
  552:                               $multichoicehash{'title_'.$id}.
  553:                               '</a></td><td>'.$multichoicehash{'type_'.$id}.
  554: 			      '</td></tr>');
  555:                      }
  556:                      $r->print('</table>');
  557:                   } else {
  558:                       if ($reinitcheck) {
  559:                           if (&Apache::loncommon::course_type() eq 'Community') {
  560:                               $r->print(
  561:                                   &Apache::loncommon::start_page('Community Contents Updated'));
  562:                           } else { 
  563:                               $r->print(
  564:                                   &Apache::loncommon::start_page('Course Contents Updated'));
  565:                           }
  566:                           $r->print('<h2>'.$lt{'update'}.'</h2>'
  567:                                   .'<p>'.$lt{'expupdate'}.'<br />'
  568:                                   .$lt{'gonav'}.'</p>');
  569:                       } else {
  570:                           if (($env{'course.'.$env{'request.course.id'}.'.type'} eq 'Placement') && 
  571:                               (!$env{'request.role.adv'})) {
  572:                               my ($score,$incomplete) = &Apache::lonplacementtest::check_completion(undef,undef,1); 
  573:                               if ($incomplete) {
  574:                                   $r->print(&Apache::lonplacementtest::showincomplete($incomplete)); 
  575:                               } else {
  576:                                   $r->print(&Apache::lonplacementtest::showresult(1));
  577:                               }
  578:                           } else {  
  579:                               $r->print(
  580:                                   &Apache::loncommon::start_page('No Resource')
  581:                                  .'<h2>'.$lt{'title'}.'</h2>'
  582:                                  .'<p>'.$lt{'explain'}.'</p>');
  583:                           }
  584:                       }
  585: 		  }
  586:                   unless (($env{'course.'.$env{'request.course.id'}.'.type'} eq 'Placement') ||
  587:                           ($env{'request.role.adv'})) {
  588:                       if ((!@possibilities) && ($reinitcheck))  {
  589:                           $r->print(
  590:                               &Apache::lonhtmlcommon::actionbox(
  591:                                   ['<a href="/adm/navmaps">'.$lt{'nav'}.'</a></li>'
  592:                                   ]));
  593:                       } else {
  594:                           $r->print(
  595:                               &Apache::lonhtmlcommon::actionbox(
  596:                                   ['<a href="/adm/flip?postdata=return:">'.$lt{'back'}.'</a></li>',
  597:                                    '<a href="/adm/navmaps">'.$lt{'nav'}.'</a></li>'
  598:                                   ]));
  599:                       }
  600: 
  601:                   }
  602:                   $r->print(&Apache::loncommon::end_page());
  603:       
  604:                   return OK;
  605: 	      }
  606: 	  } else {
  607: # ------------------------------------------------- Problem, could not tie hash
  608:               $env{'user.error.msg'}="/adm/flip:bre:0:1:Course Data Missing";
  609:               return HTTP_NOT_ACCEPTABLE; 
  610:           }
  611:       } else {
  612: # ---------------------------------------- No, could not determine where we are
  613: 	  $r->internal_redirect('/adm/ambiguous');
  614:           return OK;
  615:       }
  616:   } else {
  617: # -------------------------- Class was not initialized or page fliped strangely
  618:       $env{'user.error.msg'}="/adm/flip:bre:0:0:Choose Course";
  619:       return HTTP_NOT_ACCEPTABLE; 
  620:   } 
  621: }
  622: 
  623: 1;
  624: __END__
  625: 
  626: =pod
  627: 
  628: =head1 NAME
  629: 
  630: Apache::lonpageflip
  631: 
  632: =head1 SYNOPSIS
  633: 
  634: Deals with forward, backward, and other page flips.
  635: 
  636: This is part of the LearningOnline Network with CAPA project
  637: described at http://www.lon-capa.org.
  638: 
  639: =head1 OVERVIEW
  640: 
  641: (empty)
  642: 
  643: =head1 SUBROUTINES
  644: 
  645: =over cleanup()
  646: 
  647: =item addrid()
  648: 
  649: =item fullmove()
  650: 
  651: =item hash_src()
  652: 
  653: =item move()
  654: 
  655: =item get_next_possible_move()
  656: 
  657: =item first_accessible_resource()
  658: 
  659: =item handler()
  660: 
  661: =back
  662: 
  663: =cut
  664: 
  665: 
  666: 
  667: 
  668: 
  669: 

FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>