Annotation of rat/lonpageflip.pm, revision 1.80.8.4

1.1       www         1: # The LearningOnline Network with CAPA
                      2: #
                      3: # Page flip handler
                      4: #
1.80.8.4! raeburn     5: # $Id: lonpageflip.pm,v 1.80.8.3 2013/12/13 14:48:05 raeburn Exp $
1.18      www         6: #
                      7: # Copyright Michigan State University Board of Trustees
                      8: #
                      9: # This file is part of the LearningOnline Network with CAPA (LON-CAPA).
                     10: #
                     11: # LON-CAPA is free software; you can redistribute it and/or modify
                     12: # it under the terms of the GNU General Public License as published by
                     13: # the Free Software Foundation; either version 2 of the License, or
                     14: # (at your option) any later version.
                     15: #
                     16: # LON-CAPA is distributed in the hope that it will be useful,
                     17: # but WITHOUT ANY WARRANTY; without even the implied warranty of
                     18: # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
                     19: # GNU General Public License for more details.
                     20: #
                     21: # You should have received a copy of the GNU General Public License
                     22: # along with LON-CAPA; if not, write to the Free Software
                     23: # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
                     24: #
                     25: # /home/httpd/html/adm/gpl.txt
                     26: #
                     27: # http://www.lon-capa.org/
                     28: #
1.1       www        29: 
1.76      jms        30: 
                     31: 
1.1       www        32: package Apache::lonpageflip;
                     33: 
                     34: use strict;
1.68      albertel   35: use LONCAPA;
1.4       www        36: use Apache::Constants qw(:common :http REDIRECT);
1.53      albertel   37: use Apache::lonnet;
1.70      albertel   38: use Apache::loncommon();
1.80.8.4! raeburn    39: use Apache::lonlocal;
1.1       www        40: use HTML::TokeParser;
                     41: use GDBM_File;
                     42: 
1.3       www        43: # ========================================================== Module Global Hash
                     44:   
1.1       www        45: my %hash;
1.34      www        46: 
                     47: sub cleanup {
                     48:     if (tied(%hash)){
                     49: 	&Apache::lonnet::logthis('Cleanup pageflip: hash');
                     50:         unless (untie(%hash)) {
                     51: 	    &Apache::lonnet::logthis('Failed cleanup pageflip: hash');
                     52:         }
                     53:     }
1.63      albertel   54:     return OK;
1.34      www        55: }
1.1       www        56: 
1.3       www        57: sub addrid {
1.4       www        58:     my ($current,$new,$condid)=@_;
                     59:     unless ($condid) { $condid=0; }
1.27      www        60: 
1.3       www        61: 	if ($current) {
1.5       www        62: 	    $current.=','.$new;
1.3       www        63:         } else {
1.5       www        64:             $current=''.$new;
1.3       www        65:         }
1.27      www        66: 
1.3       www        67:     return $current;
1.25      www        68: }
                     69: 
                     70: sub fullmove {
                     71:     my ($rid,$mapurl,$direction)=@_;
1.53      albertel   72:     if (tie(%hash,'GDBM_File',$env{'request.course.fn'}.'.db',
1.28      albertel   73:                         &GDBM_READER(),0640)) {
1.25      www        74: 	($rid,$mapurl)=&move($rid,$mapurl,$direction);
                     75:         untie(%hash);
                     76:     }
                     77:     return($rid,$mapurl);
1.1       www        78: }
                     79: 
1.50      albertel   80: sub hash_src {
                     81:     my ($id)=@_;
1.56      albertel   82:     my ($mapid,$resid)=split(/\./,$id);
                     83:     my $symb=&Apache::lonnet::encode_symb($hash{'map_id_'.$mapid},
                     84: 					  $resid,$hash{'src_'.$id});
1.50      albertel   85:     if ($hash{'encrypted_'.$id}) {
1.56      albertel   86: 	return (&Apache::lonenc::encrypted($hash{'src_'.$id}),
                     87: 		&Apache::lonenc::encrypted($symb));
1.50      albertel   88:     }
1.56      albertel   89:     return ($hash{'src_'.$id},$symb);
1.50      albertel   90: }
                     91: 
1.15      www        92: sub move {
1.72      albertel   93:     my ($next,$endupmap,$direction) = @_;
                     94:     my $safecount=0;
                     95:     my $allowed=0;
                     96:     do {
                     97: 	($next,$endupmap)=&get_next_possible_move($next,$endupmap,$direction);
                     98: 
                     99: 	my $url = $hash{'src_'.$next};
                    100: 	my ($mapid,$resid)=split(/\./,$next);
                    101: 	my $symb = &Apache::lonnet::encode_symb($hash{'map_id_'.$mapid},
                    102: 						$resid,$url);
                    103: 	if ($url eq '' || $symb eq '') {
                    104: 	    $allowed = 0;
                    105: 	} else {
                    106: 	    my $priv = &Apache::lonnet::allowed('bre',$url,$symb);
                    107: 	    $allowed = (($priv eq 'F') || ($priv eq '2'));
                    108: 	}
                    109: 	$safecount++;
                    110:     } while (   ($next)
                    111: 	     && ($next!~/\,/)
                    112: 	     && (
                    113: 		    (!$hash{'src_'.$next})
                    114: 		 || (
                    115: 		        (!$env{'request.role.adv'})
                    116: 		     &&  $hash{'randomout_'.$next}
                    117: 		    )
                    118: 		 || (!$allowed)
                    119: 		)
                    120: 	     && ($safecount<10000));
                    121: 
                    122:     return ($next,$endupmap);
                    123: }
                    124: 
                    125: sub get_next_possible_move {
1.15      www       126:     my ($rid,$mapurl,$direction)=@_;
1.23      www       127:     my $startoutrid=$rid;
1.15      www       128: 
                    129:     my $next='';
                    130: 
                    131:               my $mincond=1;
                    132:               my $posnext='';
                    133:               if ($direction eq 'forward') {
                    134: # --------------------------------------------------------------------- Forward
1.33      www       135:                   while ($hash{'type_'.$rid} eq 'finish') {
                    136: 	             $rid=$hash{'ids_'.$hash{'map_id_'.(split(/\./,$rid))[0]}};
1.15      www       137:                   }
1.61      albertel  138: 		  foreach my $id (split(/\,/,$hash{'to_'.$rid})) {
1.64      albertel  139: 		     my $condition= $hash{'conditions_'.$hash{'goesto_'.$id}};
                    140: 		     my $rescond  = &Apache::lonnet::docondval($condition);
                    141: 		     my $linkcond = &Apache::lonnet::directcondval($hash{'condid_'.$hash{'undercond_'.$id}});
                    142: 		     my $thiscond = ($rescond<$linkcond)?$rescond:$linkcond;
                    143: 		     if ($thiscond>=$mincond) {
1.15      www       144: 		          if ($posnext) {
1.61      albertel  145: 		             $posnext.=','.$id.':'.$thiscond;
1.15      www       146:                           } else {
1.61      albertel  147:                              $posnext=$id.':'.$thiscond;
1.15      www       148: 		          }
                    149:                           if ($thiscond>$mincond) { $mincond=$thiscond; }
                    150: 	              }
1.61      albertel  151:                   } 
                    152: 		  foreach my $id (split(/\,/,$posnext))  {
                    153:                       my ($linkid,$condval)=split(/\:/,$id);
1.15      www       154:                       if ($condval>=$mincond) {
                    155: 		          $next=&addrid($next,$hash{'goesto_'.$linkid},
                    156:                                 $hash{'condid_'.$hash{'undercond_'.$linkid}});
                    157:                       }
1.61      albertel  158:                   }
1.15      www       159:                   if ($hash{'is_map_'.$next}) {
1.23      www       160: # This jumps to the beginning of a new map (going down level)
1.15      www       161:                       if (
                    162:       $hash{'map_type_'.$hash{'map_pc_'.$hash{'src_'.$next}}} eq 'sequence') {
                    163: 			  $mapurl=$hash{'src_'.$next};
                    164: 			  $next=$hash{'map_start_'.$hash{'src_'.$next}};
1.47      raeburn   165:                      } elsif (
                    166: # This jumps back up from an empty sequence, to a page up one level
                    167:                          $hash{'map_type_'.$hash{'map_pc_'.$hash{'src_'.$next}}} eq 'page') {
                    168:                          $mapurl=$hash{'map_id_'.(split(/\./,$next))[0]};
1.15      www       169:                      }
1.23      www       170:                   } elsif 
                    171:                     ((split(/\./,$startoutrid))[0]!=(split(/\./,$next))[0]) {
                    172: # This comes up from a map (coming up one level);
                    173: 		      $mapurl=$hash{'map_id_'.(split(/\./,$next))[0]};
1.61      albertel  174: 		  }
1.15      www       175:               } elsif ($direction eq 'back') {
                    176: # ------------------------------------------------------------------- Backwards
1.33      www       177:                  while ($hash{'type_'.$rid} eq 'start') {
                    178: 	             $rid=$hash{'ids_'.$hash{'map_id_'.(split(/\./,$rid))[0]}};
                    179: 		 }
1.62      albertel  180: 		 foreach my $id (split(/\,/,$hash{'from_'.$rid})) {
1.64      albertel  181: 		     my $condition= $hash{'conditions_'.$hash{'comesfrom_'.$id}};
                    182: 		     my $rescond  = &Apache::lonnet::docondval($condition);
                    183: 		     my $linkcond = &Apache::lonnet::directcondval($hash{'condid_'.$hash{'undercond_'.$id}});
                    184: 		     my $thiscond = ($rescond<$linkcond)?$rescond:$linkcond;
1.62      albertel  185: 		     if ($thiscond>=$mincond) {
                    186: 			 if ($posnext) {
                    187: 		             $posnext.=','.$id.':'.$thiscond;
                    188: 			 } else {
                    189:                              $posnext=$id.':'.$thiscond;
                    190: 			 }
                    191: 			 if ($thiscond>$mincond) { $mincond=$thiscond; }
                    192: 		     }
                    193: 		 } 
                    194: 		 foreach my $id (split(/\,/,$posnext)) {
                    195: 		     my ($linkid,$condval)=split(/\:/,$id);
                    196: 		     if ($condval>=$mincond) {
                    197: 			 $next=&addrid($next,$hash{'comesfrom_'.$linkid},
                    198: 				       $hash{'condid_'.$hash{'undercond_'.$linkid}});
                    199: 		     }
                    200: 		 }
1.15      www       201:                   if ($hash{'is_map_'.$next}) {
1.24      www       202: # This jumps to the end of a new map (going down one level)
1.15      www       203:                       if (
                    204:       $hash{'map_type_'.$hash{'map_pc_'.$hash{'src_'.$next}}} eq 'sequence') {
                    205: 			  $mapurl=$hash{'src_'.$next};
                    206: 			  $next=$hash{'map_finish_'.$hash{'src_'.$next}};
1.47      raeburn   207:                       } elsif (
                    208:       $hash{'map_type_'.$hash{'map_pc_'.$hash{'src_'.$next}}} eq 'page') {
                    209: # This jumps back up from an empty sequence, to a page up one level
                    210:                           $mapurl=$hash{'map_id_'.(split(/\./,$next))[0]};
                    211:                       }
1.24      www       212:                   } elsif 
                    213:                     ((split(/\./,$startoutrid))[0]!=(split(/\./,$next))[0]) {
                    214: # This comes back up from a map (going up one level);
                    215: 		      $mapurl=$hash{'map_id_'.(split(/\./,$next))[0]};
1.15      www       216:                   }
                    217: 	      }
                    218:               return ($next,$mapurl);
                    219: }
                    220: 
1.80.8.1  raeburn   221: sub navlaunch {
                    222:     my ($r)=@_;
                    223:     &Apache::loncommon::content_type($r,'text/html');
                    224:     &Apache::loncommon::no_cache($r);
                    225:     $r->send_http_header;
                    226:     $r->print(&Apache::loncommon::start_page('Launched'));
                    227:     $r->print(<<ENDNAV);
                    228:     <p><a href="/adm/flip?postdata=firstres%3a">Goto first resource</a></p>
                    229:     <script type="text/javascript">
                    230:         function collapse() {
                    231:             menu=window.open("/adm/navmaps?collapseExternal","loncapanav",
                    232:                              "height=600,width=400,scrollbars=1");
                    233:             this.document.location='/adm/navmaps?turningOffExternal';
                    234:         }
                    235:     </script>
                    236:     <p><a href="javascript:collapse();">Collapse external navigation window</a></p>
                    237: ENDNAV
                    238:     $r->print(&Apache::loncommon::end_page());
                    239: }
                    240: 
1.69      www       241: sub first_accessible_resource {
                    242:     my $furl;
                    243:     if (tie(%hash,'GDBM_File',$env{'request.course.fn'}.'.db',
                    244: 	    &GDBM_READER(),0640)) {
                    245: 	$furl=$hash{'first_url'};
1.74      albertel  246: 	my %args;
                    247: 	my ($url,$args) = split(/\?/,$furl);
                    248: 	foreach my $pair (split(/\&/,$args)) {
                    249: 	    my ($name,$value) = split(/=/,$pair);
                    250: 	    $args{&unescape($name)} = &unescape($value);
                    251: 	}
1.80.8.1  raeburn   252:         if ((($env{'environment.remotenavmap'} eq 'on') && ($furl =~ m{^/adm/navmaps})) ||
                    253:             (!&Apache::lonnet::allowed('bre',$url,$args{'symb'}))) {
1.69      www       254: # Wow, we cannot see this ... move forward to the next one that we can see
                    255: 	    my ($newrid,$newmap)=&move($hash{'first_rid'},$hash{'first_mapurl'},'forward');
                    256: # Build the new URL
1.73      albertel  257: 	    my ($newmapid,$newresid)=split(/\./,$newrid);
1.69      www       258: 	    my $symb=&Apache::lonnet::encode_symb($newmap,$newresid,$hash{'src_'.$newrid});
                    259: 	    $furl=&add_get_param($hash{'src_'.$newrid},{ 'symb' => $symb });
                    260: 	    if ($hash{'encrypted_'.$newrid}) {
                    261: 		$furl=&Apache::lonenc::encrypted($furl);
                    262: 	    }
                    263: 	}
                    264: 	untie(%hash);
                    265: 	return $furl;
                    266:     } else {
                    267: 	return '/adm/navmaps';
                    268:     }
                    269: }
                    270: 
1.1       www       271: # ================================================================ Main Handler
                    272: 
                    273: sub handler {
1.2       www       274:    my $r=shift;
1.1       www       275: 
                    276: # ------------------------------------------- Set document type for header only
                    277: 
1.2       www       278:   if ($r->header_only) {
1.51      albertel  279:       &Apache::loncommon::content_type($r,'text/html');
                    280:       $r->send_http_header;
                    281:       return OK;
1.2       www       282:   }
                    283: 
1.5       www       284:   my %cachehash=(); 
                    285:   my $multichoice=0;
                    286:   my %multichoicehash=();
1.56      albertel  287:   my ($redirecturl,$redirectsymb);
1.4       www       288:   my $next='';
                    289:   my @possibilities=();
1.37      www       290:    &Apache::loncommon::get_unprocessed_cgi($ENV{'QUERY_STRING'},['postdata']);
1.53      albertel  291:   if (($env{'form.postdata'})&&($env{'request.course.fn'})) {
                    292:       $env{'form.postdata'}=~/(\w+)\:(.*)/;
1.2       www       293:       my $direction=$1;
1.40      www       294:       my $currenturl=$2;
1.50      albertel  295:       if ($currenturl=~m|^/enc/|) {
                    296: 	  $currenturl=&Apache::lonenc::unencrypted($currenturl);
                    297:       }
1.46      www       298:       $currenturl=~s/\.\d+\.(\w+)$/\.$1/;
1.54      albertel  299:       if ($direction eq 'firstres') {
1.69      www       300: 	  my $furl=&first_accessible_resource();
1.54      albertel  301: 	  &Apache::loncommon::content_type($r,'text/html');
                    302: 	  $r->header_out(Location => 
1.71      albertel  303: 			 &Apache::lonnet::absolute_url().$furl);
1.54      albertel  304: 	     
                    305: 	  return REDIRECT;
                    306:       }
1.80.8.1  raeburn   307:       if ($direction eq 'return' || $direction eq 'navlaunch') {
1.10      www       308: # -------------------------------------------------------- Return to last known
                    309:          my $last;
1.53      albertel  310:          if (tie(%hash,'GDBM_File',$env{'request.course.fn'}.'_symb.db',
1.28      albertel  311:                     &GDBM_READER(),0640)) {
1.10      www       312: 	     $last=$hash{'last_known'};
                    313:              untie(%hash);
                    314:          }
                    315:          my $newloc;
1.53      albertel  316:          if (($last) && (tie(%hash,'GDBM_File',$env{'request.course.fn'}.'.db',
1.36      www       317:                         &GDBM_READER(),0640))) {
1.52      albertel  318:             my ($murl,$id,$fn)=&Apache::lonnet::decode_symb($last);
1.50      albertel  319: 	    $id=$hash{'map_pc_'.&Apache::lonnet::clutter($murl)}.'.'.$id;
                    320: 	    $newloc=$hash{'src_'.$id};
                    321: 	    if ($newloc) {
                    322: 		if ($hash{'encrypted_'.$id}) { $newloc=&Apache::lonenc::encrypted($newloc); }
                    323: 			      
                    324: 	    } else {
1.57      www       325: 		$newloc='/adm/navmaps';
1.50      albertel  326: 	    }
1.36      www       327:             untie %hash;
1.10      www       328:          } else {
1.57      www       329: 	    $newloc='/adm/navmaps';
1.80.8.1  raeburn   330:          }
                    331:          if (($newloc =~ m{^/adm/navmaps}) && ($direction eq 'navlaunch')) {
                    332:              &navlaunch($r);
                    333:              return OK;
                    334:          } else {
1.54      albertel  335: 	     &Apache::loncommon::content_type($r,'text/html');
                    336: 	     $r->header_out(Location => 
1.71      albertel  337: 			    &Apache::lonnet::absolute_url().$newloc);
1.54      albertel  338: 	     
                    339: 	     return REDIRECT;
1.80.8.1  raeburn   340:          }
1.10      www       341:       }
1.78      raeburn   342:       $currenturl=~s/^https?\:\/\///;
1.2       www       343:       $currenturl=~s/^[^\/]+//;
1.35      www       344: #
                    345: # Is the current URL on the map? If not, start with last known URL
                    346: #
                    347:       unless (&Apache::lonnet::is_on_map($currenturl)) {
1.7       www       348: 	 my $last;
1.53      albertel  349:          if (tie(%hash,'GDBM_File',$env{'request.course.fn'}.'_symb.db',
1.28      albertel  350:                     &GDBM_READER(),0640)) {
1.7       www       351: 	     $last=$hash{'last_known'};
                    352:              untie(%hash);
                    353:          }
                    354:          if ($last) {
1.52      albertel  355: 	     $currenturl=&Apache::lonnet::clutter((&Apache::lonnet::decode_symb($last))[2]);
1.7       www       356: 	 } else {
1.80.8.1  raeburn   357:              if ($direction eq 'return') {
1.54      albertel  358: 		 &Apache::loncommon::content_type($r,'text/html');
                    359: 		 $r->header_out(Location => 
1.71      albertel  360: 				&Apache::lonnet::absolute_url().
1.70      albertel  361: 				'/adm/noidea.html');
1.54      albertel  362: 		 return REDIRECT;
1.80.8.1  raeburn   363:              } else {
                    364:                  &navlaunch($r);
                    365:                  return OK;
                    366:              }
1.7       www       367:          }
                    368:       }
1.3       www       369: # ------------------------------------------- Do we have any idea where we are?
                    370:       my $position;
                    371:       if ($position=Apache::lonnet::symbread($currenturl)) {
                    372: # ------------------------------------------------------------------------- Yes
1.41      www       373: 	  my ($startoutmap,$mapnum,$thisurl)=&Apache::lonnet::decode_symb($position);
1.52      albertel  374:           $cachehash{$startoutmap}{$thisurl}=[$thisurl,$mapnum];
1.23      www       375:           $cachehash{$startoutmap}{'last_known'}=
1.52      albertel  376:                              [&Apache::lonnet::declutter($currenturl),$mapnum];
1.20      albertel  377: 
1.5       www       378: # ============================================================ Tie the big hash
1.53      albertel  379:           if (tie(%hash,'GDBM_File',$env{'request.course.fn'}.'.db',
1.28      albertel  380:                         &GDBM_READER(),0640)) {
1.29      www       381:               my $rid=$hash{'map_pc_'.&Apache::lonnet::clutter($startoutmap)}.
                    382:                       '.'.$mapnum;
1.14      www       383: 
1.15      www       384: # ------------------------------------------------- Move forward, backward, etc
1.22      www       385:               my $endupmap;
                    386:               ($next,$endupmap)=&move($rid,$startoutmap,$direction);
1.15      www       387: # -------------------------------------- Do we have one and only one empty URL?
1.22      www       388: # We are now at at least one non-empty URL
1.4       www       389: # ----------------------------------------------------- Check out possibilities
                    390:               if ($next) {
                    391:                   @possibilities=split(/\,/,$next);
                    392:                   if ($#possibilities==0) {
1.5       www       393: # ---------------------------------------------- Only one possibility, redirect
1.56      albertel  394: 	              ($redirecturl,$redirectsymb)=&hash_src($next);
1.52      albertel  395:                       $cachehash{$endupmap}{$redirecturl}=
                    396: 			  [$redirecturl,(split(/\./,$next))[1]];
1.4       www       397:                   } else {
1.5       www       398: # ------------------------ There are multiple possibilities for a next resource
                    399:                       $multichoice=1;
1.62      albertel  400: 		      foreach my $id (@possibilities) {
                    401: 			  $multichoicehash{'src_'.$id}=$hash{'src_'.$id};
                    402:                           $multichoicehash{'title_'.$id}=$hash{'title_'.$id};
                    403:                           $multichoicehash{'type_'.$id}=$hash{'type_'.$id};
                    404:                           (my $first, my $second) = $id =~ /(\d+).(\d+)/;
                    405:                           my $symbSrc = Apache::lonnet::declutter($hash{'src_'.$id});
                    406:                           $multichoicehash{'symb_'.$id} = 
1.32      bowersj2  407:                               Apache::lonnet::declutter($hash{'map_id_'.$first}.'___'.
                    408:                                                         $second.'___'.$symbSrc);
                    409:                                                          
1.62      albertel  410:                           my ($choicemap,$choiceres)=split(/\./,$id);
1.52      albertel  411: 			  my $map=&Apache::lonnet::declutter($hash{'src_'.$choicemap});
1.62      albertel  412: 			  my $url=$multichoicehash{'src_'.$id};
1.52      albertel  413:                           $cachehash{$map}{$url}=[$url,$choiceres];
1.62      albertel  414:                       }
1.4       www       415:                   }
1.5       www       416: 	      } else {
                    417: # -------------------------------------------------------------- No place to go
                    418:                   $multichoice=-1;
1.4       www       419:               }
1.5       www       420: # ----------------- The program must come past this point to untie the big hash
1.3       www       421: 	      untie(%hash);
1.5       www       422: # --------------------------------------------------------- Store position info
1.52      albertel  423:               $cachehash{$startoutmap}{'last_direction'}=[$direction,'notasymb'];
1.19      www       424:               foreach my $thismap (keys %cachehash) {
1.52      albertel  425: 		  my $mapnum=$cachehash{$thismap}->{'mapnum'};
                    426: 		  delete($cachehash{$thismap}->{'mapnum'});
                    427: 		  &Apache::lonnet::symblist($thismap,
                    428: 					    %{$cachehash{$thismap}});
1.19      www       429: 	      }
1.5       www       430: # ============================================== Do not return before this line
1.4       www       431:               if ($redirecturl) {
1.5       www       432: # ----------------------------------------------------- There is a URL to go to
1.38      www       433: 		  if ($direction eq 'forward') {
                    434:                      &Apache::lonnet::linklog($currenturl,$redirecturl);
                    435: 		  }
                    436: 		  if ($direction eq 'back') {
                    437:                      &Apache::lonnet::linklog($redirecturl,$currenturl);
                    438: 		  }
1.31      www       439: # ------------------------------------------------- Check for critical messages
1.53      albertel  440: 		  if ((time-$env{'user.criticalcheck.time'})>300) {
1.31      www       441:                      my @what=&Apache::lonnet::dump
1.53      albertel  442:                                   ('critical',$env{'user.domain'},
                    443:                                               $env{'user.name'});
1.31      www       444:                      if ($what[0]) {
                    445: 	                if (($what[0] ne 'con_lost') && 
                    446:                             ($what[0]!~/^error\:/)) {
                    447: 	                   $redirecturl='/adm/email?critical=display';
1.56      albertel  448: 			   $redirectsymb='';
1.31      www       449:                         }
                    450:                      }
1.75      raeburn   451:                      &Apache::lonnet::appenv({'user.criticalcheck.time'=>time});
1.31      www       452: 		  }
                    453: 
1.80.8.1  raeburn   454:                   if (($redirecturl =~ m{^/adm/navmaps}) &&
                    455:                       ($env{'environment.remotenavmap'} eq 'on')) {
                    456:                       &navlaunch($r);
                    457:                       return OK;
                    458:                   }
1.51      albertel  459: 		  &Apache::loncommon::content_type($r,'text/html');
1.71      albertel  460: 		  my $url=&Apache::lonnet::absolute_url().$redirecturl;
1.66      albertel  461: 		  $url = &add_get_param($url, { 'symb' => $redirectsymb});
1.56      albertel  462:                   $r->header_out(Location => $url);
1.4       www       463:                   return REDIRECT;
1.5       www       464: 	      } else {
                    465: # --------------------------------------------------------- There was a problem
1.51      albertel  466:                   &Apache::loncommon::content_type($r,'text/html');
1.8       www       467:                   $r->send_http_header;
1.59      www       468: 		  my %lt=&Apache::lonlocal::texthash('title' => 'End of Sequence',
                    469: 						     'explain' =>
                    470: 						     'You have reached the end of the sequence of materials.',
                    471: 						     'back' => 'Go Back',
1.80.8.3  raeburn   472: 						     'nav' => 'Course Contents',
1.59      www       473: 						     'wherenext' =>
                    474: 						     'There are several possibilities of where to go next',
                    475: 						     'pick' =>
                    476: 						     'Please click on the the resource you intend to access',
                    477: 						     'titleheader' => 'Title',
                    478: 						     'type' => 'Type');
1.80.8.3  raeburn   479:                   if (&Apache::loncommon::course_type() eq 'Community') {
                    480:                       $lt{'nav'} = &mt('Community Contents');
                    481:                   }
1.8       www       482:                   if ($#possibilities>0) {
1.67      albertel  483: 		      my $start_page=
                    484: 			  &Apache::loncommon::start_page('Multiple Resources');
1.8       www       485:                      $r->print(<<ENDSTART);
1.67      albertel  486: $start_page
1.59      www       487: <h3>$lt{'wherenext'}</h3>
1.8       www       488: <p>
1.59      www       489: $lt{'pick'}:
1.8       www       490: <p>
1.79      bisitz    491: <table border="2">
1.59      www       492: <tr><th>$lt{'titleheader'}</th><th>$lt{'type'}</th></tr>
1.8       www       493: ENDSTART
1.62      albertel  494:                      foreach my $id (@possibilities) {
1.8       www       495:                         $r->print(
                    496:                               '<tr><td><a href="'.
1.66      albertel  497: 				  &add_get_param($multichoicehash{'src_'.$id},
                    498: 						 {'symb' =>
                    499: 						      $multichoicehash{'symb_'.$id},
                    500: 						  }).'">'.
1.62      albertel  501:                               $multichoicehash{'title_'.$id}.
                    502:                               '</a></td><td>'.$multichoicehash{'type_'.$id}.
1.8       www       503: 			      '</td></tr>');
1.26      www       504:                      }
1.59      www       505:                      $r->print('</table>');
1.8       www       506:                   } else {
1.80.8.3  raeburn   507:                       $r->print(
                    508:                           &Apache::loncommon::start_page('No Resource')
                    509:                          .'<h2>'.$lt{'title'}.'</h2>'
                    510:                          .'<p>'.$lt{'explain'}.'</p>');
1.59      www       511: 		  }
1.80.8.3  raeburn   512:                   $r->print(
                    513:                       &Apache::lonhtmlcommon::actionbox(
                    514:                           ['<a href="/adm/flip?postdata=return:">'.$lt{'back'}.'</a></li>',
                    515:                            '<a href="/adm/navmaps">'.$lt{'nav'}.'</a></li>'
                    516:                           ])
                    517:                      .&Apache::loncommon::end_page());
1.59      www       518:                   return OK;
                    519: 	      }
1.5       www       520: 	  } else {
                    521: # ------------------------------------------------- Problem, could not tie hash
1.53      albertel  522:               $env{'user.error.msg'}="/adm/flip:bre:0:1:Course Data Missing";
1.5       www       523:               return HTTP_NOT_ACCEPTABLE; 
1.3       www       524:           }
1.5       www       525:       } else {
                    526: # ---------------------------------------- No, could not determine where we are
1.42      albertel  527: 	  $r->internal_redirect('/adm/ambiguous');
1.80.8.2  raeburn   528:           return OK;
1.2       www       529:       }
1.5       www       530:   } else {
1.2       www       531: # -------------------------- Class was not initialized or page fliped strangely
1.53      albertel  532:       $env{'user.error.msg'}="/adm/flip:bre:0:0:Choose Course";
1.2       www       533:       return HTTP_NOT_ACCEPTABLE; 
                    534:   } 
1.1       www       535: }
                    536: 
                    537: 1;
                    538: __END__
                    539: 
1.77      jms       540: =pod
                    541: 
                    542: =head1 NAME
                    543: 
                    544: Apache::lonpageflip
                    545: 
                    546: =head1 SYNOPSIS
                    547: 
                    548: Deals with forward, backward, and other page flips.
                    549: 
                    550: This is part of the LearningOnline Network with CAPA project
                    551: described at http://www.lon-capa.org.
                    552: 
                    553: =head1 OVERVIEW
                    554: 
                    555: (empty)
                    556: 
                    557: =head1 SUBROUTINES
                    558: 
                    559: =over cleanup()
                    560: 
                    561: =item addrid()
                    562: 
                    563: =item fullmove()
                    564: 
                    565: =item hash_src()
                    566: 
                    567: =item move()
                    568: 
                    569: =item get_next_possible_move()
                    570: 
1.80.8.1  raeburn   571: =item navlaunch()
                    572: 
1.77      jms       573: =item first_accessible_resource()
                    574: 
                    575: =item handler()
                    576: 
                    577: =back
                    578: 
                    579: =cut
1.1       www       580: 
                    581: 
                    582: 
                    583: 
                    584: 
                    585: 

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