Annotation of rat/lonpageflip.pm, revision 1.80.8.5

1.1       www         1: # The LearningOnline Network with CAPA
                      2: #
                      3: # Page flip handler
                      4: #
1.80.8.5! raeburn     5: # $Id: lonpageflip.pm,v 1.80.8.4 2014/04/28 20:23:35 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.80.8.5! raeburn   439: # ------------------------------------- Check for and display critical messages
        !           440:                   my ($redirect, $url) = &Apache::loncommon::critical_redirect(300);
        !           441:                   unless ($redirect) {
        !           442:                       $url=&Apache::lonnet::absolute_url().$redirecturl;
        !           443:                       $url = &add_get_param($url, { 'symb' => $redirectsymb});
1.80.8.1  raeburn   444:                   }
1.80.8.5! raeburn   445:                   &Apache::loncommon::content_type($r,'text/html');
1.56      albertel  446:                   $r->header_out(Location => $url);
1.4       www       447:                   return REDIRECT;
1.5       www       448: 	      } else {
                    449: # --------------------------------------------------------- There was a problem
1.51      albertel  450:                   &Apache::loncommon::content_type($r,'text/html');
1.8       www       451:                   $r->send_http_header;
1.59      www       452: 		  my %lt=&Apache::lonlocal::texthash('title' => 'End of Sequence',
                    453: 						     'explain' =>
                    454: 						     'You have reached the end of the sequence of materials.',
                    455: 						     'back' => 'Go Back',
1.80.8.3  raeburn   456: 						     'nav' => 'Course Contents',
1.59      www       457: 						     'wherenext' =>
                    458: 						     'There are several possibilities of where to go next',
                    459: 						     'pick' =>
                    460: 						     'Please click on the the resource you intend to access',
                    461: 						     'titleheader' => 'Title',
                    462: 						     'type' => 'Type');
1.80.8.3  raeburn   463:                   if (&Apache::loncommon::course_type() eq 'Community') {
                    464:                       $lt{'nav'} = &mt('Community Contents');
                    465:                   }
1.8       www       466:                   if ($#possibilities>0) {
1.67      albertel  467: 		      my $start_page=
                    468: 			  &Apache::loncommon::start_page('Multiple Resources');
1.8       www       469:                      $r->print(<<ENDSTART);
1.67      albertel  470: $start_page
1.59      www       471: <h3>$lt{'wherenext'}</h3>
1.8       www       472: <p>
1.59      www       473: $lt{'pick'}:
1.8       www       474: <p>
1.79      bisitz    475: <table border="2">
1.59      www       476: <tr><th>$lt{'titleheader'}</th><th>$lt{'type'}</th></tr>
1.8       www       477: ENDSTART
1.62      albertel  478:                      foreach my $id (@possibilities) {
1.8       www       479:                         $r->print(
                    480:                               '<tr><td><a href="'.
1.66      albertel  481: 				  &add_get_param($multichoicehash{'src_'.$id},
                    482: 						 {'symb' =>
                    483: 						      $multichoicehash{'symb_'.$id},
                    484: 						  }).'">'.
1.62      albertel  485:                               $multichoicehash{'title_'.$id}.
                    486:                               '</a></td><td>'.$multichoicehash{'type_'.$id}.
1.8       www       487: 			      '</td></tr>');
1.26      www       488:                      }
1.59      www       489:                      $r->print('</table>');
1.8       www       490:                   } else {
1.80.8.3  raeburn   491:                       $r->print(
                    492:                           &Apache::loncommon::start_page('No Resource')
                    493:                          .'<h2>'.$lt{'title'}.'</h2>'
                    494:                          .'<p>'.$lt{'explain'}.'</p>');
1.59      www       495: 		  }
1.80.8.3  raeburn   496:                   $r->print(
                    497:                       &Apache::lonhtmlcommon::actionbox(
                    498:                           ['<a href="/adm/flip?postdata=return:">'.$lt{'back'}.'</a></li>',
                    499:                            '<a href="/adm/navmaps">'.$lt{'nav'}.'</a></li>'
                    500:                           ])
                    501:                      .&Apache::loncommon::end_page());
1.59      www       502:                   return OK;
                    503: 	      }
1.5       www       504: 	  } else {
                    505: # ------------------------------------------------- Problem, could not tie hash
1.53      albertel  506:               $env{'user.error.msg'}="/adm/flip:bre:0:1:Course Data Missing";
1.5       www       507:               return HTTP_NOT_ACCEPTABLE; 
1.3       www       508:           }
1.5       www       509:       } else {
                    510: # ---------------------------------------- No, could not determine where we are
1.42      albertel  511: 	  $r->internal_redirect('/adm/ambiguous');
1.80.8.2  raeburn   512:           return OK;
1.2       www       513:       }
1.5       www       514:   } else {
1.2       www       515: # -------------------------- Class was not initialized or page fliped strangely
1.53      albertel  516:       $env{'user.error.msg'}="/adm/flip:bre:0:0:Choose Course";
1.2       www       517:       return HTTP_NOT_ACCEPTABLE; 
                    518:   } 
1.1       www       519: }
                    520: 
                    521: 1;
                    522: __END__
                    523: 
1.77      jms       524: =pod
                    525: 
                    526: =head1 NAME
                    527: 
                    528: Apache::lonpageflip
                    529: 
                    530: =head1 SYNOPSIS
                    531: 
                    532: Deals with forward, backward, and other page flips.
                    533: 
                    534: This is part of the LearningOnline Network with CAPA project
                    535: described at http://www.lon-capa.org.
                    536: 
                    537: =head1 OVERVIEW
                    538: 
                    539: (empty)
                    540: 
                    541: =head1 SUBROUTINES
                    542: 
                    543: =over cleanup()
                    544: 
                    545: =item addrid()
                    546: 
                    547: =item fullmove()
                    548: 
                    549: =item hash_src()
                    550: 
                    551: =item move()
                    552: 
                    553: =item get_next_possible_move()
                    554: 
1.80.8.1  raeburn   555: =item navlaunch()
                    556: 
1.77      jms       557: =item first_accessible_resource()
                    558: 
                    559: =item handler()
                    560: 
                    561: =back
                    562: 
                    563: =cut
1.1       www       564: 
                    565: 
                    566: 
                    567: 
                    568: 
                    569: 

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