File:  [LON-CAPA] / rat / lonpageflip.pm
Revision 1.92: download - view: text, annotated - select for diffs
Sat Feb 18 23:39:24 2017 UTC (7 years, 2 months ago) by raeburn
Branches: MAIN
CVS tags: HEAD
- Append ?usehttp=1 to link to syllabus where LON-CAPA syllabus is configured
  to use external http:// URL, but LON-CAPA server uses https:// to avoid
  mixed active content issue (see also bug 6662).
- Preview of external http:// URL displayed in separate pop-up window
  instead of in modal window on https:// server.

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

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