Annotation of rat/lonpageflip.pm, revision 1.77

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

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