File:  [LON-CAPA] / rat / lonpageflip.pm
Revision 1.80.8.10.2.1: download - view: text, annotated - select for diffs
Mon May 25 16:42:59 2020 UTC (3 years, 11 months ago) by raeburn
Branches: version_2_11_2_msu
- For 2.11.2 (modified)
  Include changes in 1.96

    1: # The LearningOnline Network with CAPA
    2: #
    3: # Page flip handler
    4: #
    5: # $Id: lonpageflip.pm,v 1.80.8.10.2.1 2020/05/25 16:42:59 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::lonuserstate;
   40: use Apache::lonlocal;
   41: use HTML::TokeParser;
   42: use GDBM_File;
   43: 
   44: # ========================================================== Module Global Hash
   45:   
   46: my %hash;
   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:     }
   55:     return OK;
   56: }
   57: 
   58: sub addrid {
   59:     my ($current,$new,$condid)=@_;
   60:     unless ($condid) { $condid=0; }
   61: 
   62: 	if ($current) {
   63: 	    $current.=','.$new;
   64:         } else {
   65:             $current=''.$new;
   66:         }
   67: 
   68:     return $current;
   69: }
   70: 
   71: sub fullmove {
   72:     my ($rid,$mapurl,$direction)=@_;
   73:     if (tie(%hash,'GDBM_File',$env{'request.course.fn'}.'.db',
   74:                         &GDBM_READER(),0640)) {
   75: 	($rid,$mapurl)=&move($rid,$mapurl,$direction);
   76:         untie(%hash);
   77:     }
   78:     return($rid,$mapurl);
   79: }
   80: 
   81: sub hash_src {
   82:     my ($id)=@_;
   83:     my ($mapid,$resid)=split(/\./,$id);
   84:     my $symb=&Apache::lonnet::encode_symb($hash{'map_id_'.$mapid},
   85: 					  $resid,$hash{'src_'.$id});
   86:     my $anchor;
   87:     if ($hash{'ext_'.$id} eq 'true:') {
   88:         if ($hash{'src_'.$id} =~ /(\#.+)$/) {
   89:             $anchor = $1;
   90:         }
   91:     }
   92:     if ($hash{'encrypted_'.$id}) {
   93: 	return (&Apache::lonenc::encrypted($hash{'src_'.$id}),
   94: 		&Apache::lonenc::encrypted($symb),
   95:                 $hash{'encrypted_'.$id},$anchor);
   96:     }
   97:     return ($hash{'src_'.$id},$symb,$hash{'encrypted_'.$id},$anchor);
   98: }
   99: 
  100: sub move {
  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 {
  134:     my ($rid,$mapurl,$direction)=@_;
  135:     my $startoutrid=$rid;
  136: 
  137:     my $next='';
  138: 
  139:               my $mincond=1;
  140:               my $posnext='';
  141:               if ($direction eq 'forward') {
  142: # --------------------------------------------------------------------- Forward
  143:                   while ($hash{'type_'.$rid} eq 'finish') {
  144: 	             $rid=$hash{'ids_'.$hash{'map_id_'.(split(/\./,$rid))[0]}};
  145:                   }
  146: 		  foreach my $id (split(/\,/,$hash{'to_'.$rid})) {
  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) {
  152: 		          if ($posnext) {
  153: 		             $posnext.=','.$id.':'.$thiscond;
  154:                           } else {
  155:                              $posnext=$id.':'.$thiscond;
  156: 		          }
  157:                           if ($thiscond>$mincond) { $mincond=$thiscond; }
  158: 	              }
  159:                   } 
  160: 		  foreach my $id (split(/\,/,$posnext))  {
  161:                       my ($linkid,$condval)=split(/\:/,$id);
  162:                       if ($condval>=$mincond) {
  163: 		          $next=&addrid($next,$hash{'goesto_'.$linkid},
  164:                                 $hash{'condid_'.$hash{'undercond_'.$linkid}});
  165:                       }
  166:                   }
  167:                   if ($hash{'is_map_'.$next}) {
  168: # This jumps to the beginning of a new map (going down level)
  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}};
  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]};
  177:                      }
  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]};
  182: 		  }
  183:               } elsif ($direction eq 'back') {
  184: # ------------------------------------------------------------------- Backwards
  185:                  while ($hash{'type_'.$rid} eq 'start') {
  186: 	             $rid=$hash{'ids_'.$hash{'map_id_'.(split(/\./,$rid))[0]}};
  187: 		 }
  188: 		 foreach my $id (split(/\,/,$hash{'from_'.$rid})) {
  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;
  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: 		 }
  209:                   if ($hash{'is_map_'.$next}) {
  210: # This jumps to the end of a new map (going down one level)
  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}};
  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:                       }
  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]};
  224:                   }
  225: 	      }
  226:               return ($next,$mapurl);
  227: }
  228: 
  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'};
  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: 	}
  240:         if (!&Apache::lonnet::allowed('bre',$url,$args{'symb'})) {
  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
  244: 	    my ($newmapid,$newresid)=split(/\./,$newrid);
  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: 
  258: sub reinited_js {
  259:     my ($url,$cid,$timeout) = @_;
  260:     if (!$timeout) {
  261:         $timeout = 0;
  262:     }
  263:     return <<"END";
  264: <script type="text/javascript">
  265: // <![CDATA[
  266: setTimeout(function() {
  267:     var newurl = '$url';
  268:     if (document.getElementById('LC_update_$cid')) {
  269:         document.getElementById('LC_update_$cid').style.display = 'none';
  270:     }
  271:     if ((newurl !== null) && (newurl !== '') && (newurl !== 'undefined')) {
  272:         window.location.href = "$url";
  273:     }
  274: }, $timeout);
  275: // ]]>
  276: </script>
  277: END
  278: }
  279: 
  280: # ================================================================ Main Handler
  281: 
  282: sub handler {
  283:    my $r=shift;
  284: 
  285: # ------------------------------------------- Set document type for header only
  286: 
  287:   if ($r->header_only) {
  288:       &Apache::loncommon::content_type($r,'text/html');
  289:       $r->send_http_header;
  290:       return OK;
  291:   }
  292: 
  293:   my %cachehash=(); 
  294:   my $multichoice=0;
  295:   my %multichoicehash=();
  296:   my %prog_state=(); 
  297:   my ($redirecturl,$redirectsymb,$enc,$anchor);
  298:   my $next='';
  299:   my @possibilities=();
  300:    &Apache::loncommon::get_unprocessed_cgi($ENV{'QUERY_STRING'},['postdata']);
  301:   if (($env{'form.postdata'})&&($env{'request.course.fn'})) {
  302:       my ($direction,$currenturl) = ($env{'form.postdata'}=~/(\w+)\:(.*)/);
  303:       if ($currenturl=~m|^/enc/|) {
  304:           $currenturl=&Apache::lonenc::unencrypted($currenturl);
  305:       }
  306:       $currenturl=~s/\.\d+\.(\w+)$/\.$1/;
  307:       $currenturl=~s/^https?\:\/\///;
  308:       $currenturl=~s/^[^\/]+//;
  309:       my ($preupdatepos,$last,$reinitcheck);
  310:       if ($direction eq 'return') {
  311:           if (tie(%hash,'GDBM_File',$env{'request.course.fn'}.'_symb.db',
  312:                     &GDBM_READER(),0640)) {
  313:               $last=$hash{'last_known'};
  314:               untie(%hash);
  315:           }
  316:       }
  317:       if ($env{'request.course.id'}) {
  318:           # Check if course needs to be re-initialized
  319:           my $loncaparev = $r->dir_config('lonVersion');
  320:           ($reinitcheck,my @reinit) = &Apache::loncommon::needs_coursereinit($loncaparev);
  321:           if ($reinitcheck eq 'switch') {
  322:               &Apache::loncommon::content_type($r,'text/html');
  323:               $r->send_http_header;
  324:               $r->print(&Apache::loncommon::check_release_result(@reinit));
  325:               return OK;
  326:           } elsif ($reinitcheck eq 'update') {
  327:               my $cnum = $env{'course.'.$env{'request.course.id'}.'.num'};
  328:               my $cdom = $env{'course.'.$env{'request.course.id'}.'.domain'};
  329:               $preupdatepos = &Apache::lonnet::symbread($currenturl);
  330:               unless ($direction eq 'return') {
  331:                   if (tie(%hash,'GDBM_File',$env{'request.course.fn'}.'_symb.db',
  332:                                 &GDBM_READER(),0640)) {
  333:                       $last=$hash{'last_known'};
  334:                       untie(%hash);
  335:                   }
  336:               }
  337:               &Apache::loncommon::content_type($r,'text/html');
  338:               $r->send_http_header;
  339:               $r->print(&Apache::loncommon::start_page('Content Changed'));
  340:               my $preamble = '<div id="LC_update_'.$env{'request.course.id'}.'" class="LC_info">'.
  341:                              '<br />'.
  342:                              &mt('Your course session is being updated because of recent changes by course personnel.').
  343:                              ' '.&mt('Please be patient.').'<br /></div>'.
  344:                              '<div style="padding:0;clear:both;margin:0;border:0"></div>';
  345:               %prog_state = &Apache::lonhtmlcommon::Create_PrgWin($r,undef,$preamble);
  346:               &Apache::lonhtmlcommon::Update_PrgWin($r,\%prog_state,&mt('Updating course'));
  347:               my ($furl,$ferr) = &Apache::lonuserstate::readmap("$cdom/$cnum");
  348:               &Apache::lonhtmlcommon::Update_PrgWin($r,\%prog_state,&mt('Finished'));
  349:               if ($ferr) {
  350:                   &Apache::lonhtmlcommon::Close_PrgWin($r,\%prog_state);
  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:           $furl=&Apache::lonnet::absolute_url().$furl;
  368:           if ($reinitcheck eq 'update') {
  369:               &Apache::lonhtmlcommon::Close_PrgWin($r,\%prog_state);
  370:               $r->print(&reinited_js($furl,$env{'request.course.id'},100));
  371:               $r->print(&Apache::loncommon::end_page());
  372:               return OK;
  373:           } else {
  374: 	      &Apache::loncommon::content_type($r,'text/html');
  375: 	      $r->header_out(Location => $furl);
  376: 	      return REDIRECT;
  377:           }
  378:       }
  379:       if ($direction eq 'return') { 
  380: # -------------------------------------------------------- Return to last known
  381:          my $newloc;
  382:          if (($last) && (tie(%hash,'GDBM_File',$env{'request.course.fn'}.'.db',
  383:                         &GDBM_READER(),0640))) {
  384:             my ($murl,$id,$fn)=&Apache::lonnet::decode_symb($last);
  385: 	    $id=$hash{'map_pc_'.&Apache::lonnet::clutter($murl)}.'.'.$id;
  386: 	    $newloc=$hash{'src_'.$id};
  387: 	    if ($newloc) {
  388: 		if ($hash{'encrypted_'.$id}) { $newloc=&Apache::lonenc::encrypted($newloc); }
  389: 	    } else {
  390: 		$newloc='/adm/navmaps';
  391: 	    }
  392:             untie %hash;
  393:          } else {
  394: 	    $newloc='/adm/navmaps';
  395:          }
  396:          $newloc=&Apache::lonnet::absolute_url().$newloc;
  397:          if ($reinitcheck eq 'update') {
  398:              $r->print(&reinited_js($newloc,$env{'request.course.id'},100));
  399:              $r->print(&Apache::loncommon::end_page());
  400:              return OK;
  401:          } else {
  402:              &Apache::loncommon::content_type($r,'text/html');
  403:              $r->header_out(Location => $newloc);
  404:              return REDIRECT;
  405:          }
  406:       }
  407: #
  408: # Is the current URL on the map? If not, start with last known URL
  409: #
  410: 
  411:       unless (&Apache::lonnet::is_on_map($currenturl)) {
  412:          if ($preupdatepos) {
  413:              undef($preupdatepos);
  414:          } elsif (tie(%hash,'GDBM_File',$env{'request.course.fn'}.'_symb.db',
  415:                             &GDBM_READER(),0640)) {
  416:              $last=$hash{'last_known'};
  417:              untie(%hash);
  418:          }
  419:          if ($last) {
  420: 	     $currenturl=&Apache::lonnet::clutter((&Apache::lonnet::decode_symb($last))[2]);
  421: 	 } else {
  422:              my $newloc = &Apache::lonnet::absolute_url().
  423:                           '/adm/navmaps';
  424:              if ($reinitcheck eq 'update') {
  425:                  &Apache::lonhtmlcommon::Close_PrgWin($r,\%prog_state);
  426:                  $r->print(&reinited_js($newloc,$env{'request.course.id'},100));
  427:                  $r->print(&Apache::loncommon::end_page());
  428:                  return OK;
  429:              } else {
  430:                  &Apache::loncommon::content_type($r,'text/html');
  431: 	         $r->header_out(Location => $newloc);
  432: 	         return REDIRECT;
  433:              }
  434:          }
  435:       }
  436: # ------------------------------------------- Do we have any idea where we are?
  437:       my $position;
  438:       if ($preupdatepos) {
  439:           $position = $preupdatepos;
  440:       } else {
  441:           $position=Apache::lonnet::symbread($currenturl);
  442:       }
  443:       if ($position) {
  444: # ------------------------------------------------------------------------- Yes
  445: 	  my ($startoutmap,$mapnum,$thisurl)=&Apache::lonnet::decode_symb($position);
  446:           $cachehash{$startoutmap}{$thisurl}=[$thisurl,$mapnum];
  447:           $cachehash{$startoutmap}{'last_known'}=
  448:                              [&Apache::lonnet::declutter($currenturl),$mapnum];
  449: 
  450: # ============================================================ Tie the big hash
  451:           if (tie(%hash,'GDBM_File',$env{'request.course.fn'}.'.db',
  452:                         &GDBM_READER(),0640)) {
  453:               my $rid=$hash{'map_pc_'.&Apache::lonnet::clutter($startoutmap)}.
  454:                       '.'.$mapnum;
  455: 
  456: # ------------------------------------------------- Move forward, backward, etc
  457:               my $endupmap;
  458:               ($next,$endupmap)=&move($rid,$startoutmap,$direction);
  459: # -------------------------------------- Do we have one and only one empty URL?
  460: # We are now at at least one non-empty URL
  461: # ----------------------------------------------------- Check out possibilities
  462:               if ($next) {
  463:                   @possibilities=split(/\,/,$next);
  464:                   if ($#possibilities==0) {
  465: # ---------------------------------------------- Only one possibility, redirect
  466: 	              ($redirecturl,$redirectsymb,$enc,$anchor)=&hash_src($next);
  467:                       $cachehash{$endupmap}{$redirecturl}=
  468: 			  [$redirecturl,(split(/\./,$next))[1]];
  469:                   } else {
  470: # ------------------------ There are multiple possibilities for a next resource
  471:                       $multichoice=1;
  472: 		      foreach my $id (@possibilities) {
  473: 			  $multichoicehash{'src_'.$id}=$hash{'src_'.$id};
  474:                           $multichoicehash{'title_'.$id}=$hash{'title_'.$id};
  475:                           $multichoicehash{'type_'.$id}=$hash{'type_'.$id};
  476:                           (my $first, my $second) = $id =~ /(\d+).(\d+)/;
  477:                           my $symbSrc = Apache::lonnet::declutter($hash{'src_'.$id});
  478:                           $multichoicehash{'symb_'.$id} = 
  479:                               Apache::lonnet::declutter($hash{'map_id_'.$first}.'___'.
  480:                                                         $second.'___'.$symbSrc);
  481:                                                          
  482:                           my ($choicemap,$choiceres)=split(/\./,$id);
  483: 			  my $map=&Apache::lonnet::declutter($hash{'src_'.$choicemap});
  484: 			  my $url=$multichoicehash{'src_'.$id};
  485:                           $cachehash{$map}{$url}=[$url,$choiceres];
  486:                       }
  487:                   }
  488: 	      } else {
  489: # -------------------------------------------------------------- No place to go
  490:                   $multichoice=-1;
  491:               }
  492: # ----------------- The program must come past this point to untie the big hash
  493: 	      untie(%hash);
  494: # --------------------------------------------------------- Store position info
  495:               $cachehash{$startoutmap}{'last_direction'}=[$direction,'notasymb'];
  496:               foreach my $thismap (keys(%cachehash)) {
  497: 		  my $mapnum=$cachehash{$thismap}->{'mapnum'};
  498: 		  delete($cachehash{$thismap}->{'mapnum'});
  499: 		  &Apache::lonnet::symblist($thismap,
  500: 					    %{$cachehash{$thismap}});
  501: 	      }
  502: # ============================================== Do not return before this line
  503:               if ($redirecturl) {
  504: # ----------------------------------------------------- There is a URL to go to
  505: 		  if ($direction eq 'forward') {
  506:                      &Apache::lonnet::linklog($currenturl,$redirecturl);
  507: 		  }
  508: 		  if ($direction eq 'back') {
  509:                      &Apache::lonnet::linklog($redirecturl,$currenturl);
  510: 		  }
  511: # ------------------------------------- Check for and display critical messages
  512:                   my ($redirect, $url) = &Apache::loncommon::critical_redirect(300,'flip');
  513:                   unless ($redirect) {
  514:                       $url=&Apache::lonnet::absolute_url().$redirecturl;
  515:                       my $addanchor;
  516:                       if (($anchor ne '') && (!$enc || $env{'request.role.adv'})) {
  517:                           $addanchor = 1;
  518:                           $url =~ s/\#.+$//;
  519:                       }
  520:                       $url = &add_get_param($url, { 'symb' => $redirectsymb});
  521:                       if ($addanchor) {
  522:                           $url .= $anchor;
  523:                       }
  524:                   }
  525:                   if ($reinitcheck eq 'update') {
  526:                       &Apache::lonhtmlcommon::Close_PrgWin($r,\%prog_state);
  527:                       $r->print(&reinited_js($url,$env{'request.course.id'},100));
  528:                       $r->print(&Apache::loncommon::end_page());
  529:                       return OK;
  530:                   } else {
  531:                       &Apache::loncommon::content_type($r,'text/html');
  532:                       $r->header_out(Location => $url);
  533:                       return REDIRECT;
  534:                   }
  535: 	      } else {
  536: # --------------------------------------------------------- There was a problem
  537:                   &Apache::loncommon::content_type($r,'text/html');
  538:                   $r->send_http_header;
  539: 		  my %lt=&Apache::lonlocal::texthash('title' => 'End of Sequence',
  540: 						     'explain' =>
  541: 						     'You have reached the end of the sequence of materials.',
  542: 						     'back' => 'Go Back',
  543: 						     'nav' => 'Course Contents',
  544: 						     'wherenext' =>
  545: 						     'There are several possibilities of where to go next',
  546: 						     'pick' =>
  547: 						     'Please click on the the resource you intend to access',
  548: 						     'titleheader' => 'Title',
  549: 						     'type' => 'Type',
  550:                                                      'update' => 'Content updated',
  551:                                                      'expupdate' => 'As a result of a recent update to the sequence of materials, it is not possible to complete the page flip.',
  552:                                                      'gonav' => 'Go to the Contents page to select a resource to display.');
  553:                   if (&Apache::loncommon::course_type() eq 'Community') {
  554:                       $lt{'nav'} = &mt('Community Contents');
  555:                   }
  556:                   if ($#possibilities>0) {
  557: 		      my $start_page=
  558: 			  &Apache::loncommon::start_page('Multiple Resources');
  559:                      $r->print(<<ENDSTART);
  560: $start_page
  561: <h3>$lt{'wherenext'}</h3>
  562: <p>
  563: $lt{'pick'}:
  564: <p>
  565: <table border="2">
  566: <tr><th>$lt{'titleheader'}</th><th>$lt{'type'}</th></tr>
  567: ENDSTART
  568:                      foreach my $id (@possibilities) {
  569:                         $r->print(
  570:                               '<tr><td><a href="'.
  571: 				  &add_get_param($multichoicehash{'src_'.$id},
  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:                           $r->print(
  594:                               &Apache::loncommon::start_page('No Resource')
  595:                              .'<h2>'.$lt{'title'}.'</h2>'
  596:                              .'<p>'.$lt{'explain'}.'</p>');
  597:                       }
  598: 		  }
  599:                   if ((!@possibilities) && ($reinitcheck))  {
  600:                       $r->print(
  601:                           &Apache::lonhtmlcommon::actionbox(
  602:                               ['<a href="/adm/navmaps">'.$lt{'nav'}.'</a></li>'
  603:                               ]));
  604:                   } else {
  605:                       $r->print(
  606:                           &Apache::lonhtmlcommon::actionbox(
  607:                               ['<a href="/adm/flip?postdata=return:">'.$lt{'back'}.'</a></li>',
  608:                                '<a href="/adm/navmaps">'.$lt{'nav'}.'</a></li>'
  609:                               ]));
  610:                   }
  611:                   $r->print(&Apache::loncommon::end_page());
  612:       
  613:                   return OK;
  614: 	      }
  615: 	  } else {
  616: # ------------------------------------------------- Problem, could not tie hash
  617:               if ($reinitcheck eq 'update') {
  618:                   &Apache::lonhtmlcommon::Close_PrgWin($r,\%prog_state);
  619:                   $r->print(&Apache::loncommon::end_page());
  620:               }
  621:               $env{'user.error.msg'}="/adm/flip:bre:0:1:Course Data Missing";
  622:               return HTTP_NOT_ACCEPTABLE; 
  623:           }
  624:       } else {
  625: # ---------------------------------------- No, could not determine where we are
  626:           my $newloc = '/adm/ambiguous';
  627:           if ($reinitcheck eq 'update') {
  628:               &Apache::lonhtmlcommon::Close_PrgWin($r,\%prog_state);
  629:               $r->print(&reinited_js($newloc,$env{'request.course.id'},100));
  630:               $r->print(&Apache::loncommon::end_page());
  631:           } else {
  632: 	      $r->internal_redirect($newloc);
  633:           }
  634:           return OK;
  635:       }
  636:   } else {
  637: # -------------------------- Class was not initialized or page fliped strangely
  638:       $env{'user.error.msg'}="/adm/flip:bre:0:0:Choose Course";
  639:       return HTTP_NOT_ACCEPTABLE; 
  640:   } 
  641: }
  642: 
  643: 1;
  644: __END__
  645: 
  646: =pod
  647: 
  648: =head1 NAME
  649: 
  650: Apache::lonpageflip
  651: 
  652: =head1 SYNOPSIS
  653: 
  654: Deals with forward, backward, and other page flips.
  655: 
  656: This is part of the LearningOnline Network with CAPA project
  657: described at http://www.lon-capa.org.
  658: 
  659: =head1 OVERVIEW
  660: 
  661: (empty)
  662: 
  663: =head1 SUBROUTINES
  664: 
  665: =over cleanup()
  666: 
  667: =item addrid()
  668: 
  669: =item fullmove()
  670: 
  671: =item hash_src()
  672: 
  673: =item move()
  674: 
  675: =item get_next_possible_move()
  676: 
  677: =item first_accessible_resource()
  678: 
  679: =item handler()
  680: 
  681: =back
  682: 
  683: =cut
  684: 
  685: 
  686: 
  687: 
  688: 
  689: 

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