Annotation of rat/lonpageflip.pm, revision 1.75

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

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