Annotation of rat/lonpageflip.pm, revision 1.73

1.1       www         1: # The LearningOnline Network with CAPA
                      2: #
                      3: # Page flip handler
                      4: #
1.73    ! albertel    5: # $Id: lonpageflip.pm,v 1.72 2006/10/20 19:42:28 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'};
                    243:         if (!&Apache::lonnet::allowed('bre',$furl)) {
                    244: # Wow, we cannot see this ... move forward to the next one that we can see
                    245: 	    my ($newrid,$newmap)=&move($hash{'first_rid'},$hash{'first_mapurl'},'forward');
                    246: # Build the new URL
1.73    ! albertel  247: 	    my ($newmapid,$newresid)=split(/\./,$newrid);
1.69      www       248: 	    my $symb=&Apache::lonnet::encode_symb($newmap,$newresid,$hash{'src_'.$newrid});
                    249: 	    $furl=&add_get_param($hash{'src_'.$newrid},{ 'symb' => $symb });
                    250: 	    if ($hash{'encrypted_'.$newrid}) {
                    251: 		$furl=&Apache::lonenc::encrypted($furl);
                    252: 	    }
                    253: 	}
                    254: 	untie(%hash);
                    255: 	return $furl;
                    256:     } else {
                    257: 	return '/adm/navmaps';
                    258:     }
                    259: }
                    260: 
1.1       www       261: # ================================================================ Main Handler
                    262: 
                    263: sub handler {
1.2       www       264:    my $r=shift;
1.1       www       265: 
                    266: # ------------------------------------------- Set document type for header only
                    267: 
1.2       www       268:   if ($r->header_only) {
1.51      albertel  269:       &Apache::loncommon::content_type($r,'text/html');
                    270:       $r->send_http_header;
                    271:       return OK;
1.2       www       272:   }
                    273: 
1.5       www       274:   my %cachehash=(); 
                    275:   my $multichoice=0;
                    276:   my %multichoicehash=();
1.56      albertel  277:   my ($redirecturl,$redirectsymb);
1.4       www       278:   my $next='';
                    279:   my @possibilities=();
1.37      www       280:    &Apache::loncommon::get_unprocessed_cgi($ENV{'QUERY_STRING'},['postdata']);
1.53      albertel  281:   if (($env{'form.postdata'})&&($env{'request.course.fn'})) {
                    282:       $env{'form.postdata'}=~/(\w+)\:(.*)/;
1.2       www       283:       my $direction=$1;
1.40      www       284:       my $currenturl=$2;
1.50      albertel  285:       if ($currenturl=~m|^/enc/|) {
                    286: 	  $currenturl=&Apache::lonenc::unencrypted($currenturl);
                    287:       }
1.46      www       288:       $currenturl=~s/\.\d+\.(\w+)$/\.$1/;
1.54      albertel  289:       if ($direction eq 'firstres') {
1.69      www       290: 	  my $furl=&first_accessible_resource();
1.54      albertel  291: 	  &Apache::loncommon::content_type($r,'text/html');
                    292: 	  $r->header_out(Location => 
1.71      albertel  293: 			 &Apache::lonnet::absolute_url().$furl);
1.54      albertel  294: 	     
                    295: 	  return REDIRECT;
                    296:       }
                    297:       if ($direction eq 'return' || $direction eq 'navlaunch') {
1.10      www       298: # -------------------------------------------------------- Return to last known
                    299:          my $last;
1.53      albertel  300:          if (tie(%hash,'GDBM_File',$env{'request.course.fn'}.'_symb.db',
1.28      albertel  301:                     &GDBM_READER(),0640)) {
1.10      www       302: 	     $last=$hash{'last_known'};
                    303:              untie(%hash);
                    304:          }
                    305:          my $newloc;
1.53      albertel  306:          if (($last) && (tie(%hash,'GDBM_File',$env{'request.course.fn'}.'.db',
1.36      www       307:                         &GDBM_READER(),0640))) {
1.52      albertel  308:             my ($murl,$id,$fn)=&Apache::lonnet::decode_symb($last);
1.50      albertel  309: 	    $id=$hash{'map_pc_'.&Apache::lonnet::clutter($murl)}.'.'.$id;
                    310: 	    $newloc=$hash{'src_'.$id};
                    311: 	    if ($newloc) {
                    312: 		if ($hash{'encrypted_'.$id}) { $newloc=&Apache::lonenc::encrypted($newloc); }
                    313: 			      
                    314: 	    } else {
1.57      www       315: 		$newloc='/adm/navmaps';
1.50      albertel  316: 	    }
1.36      www       317:             untie %hash;
1.10      www       318:          } else {
1.57      www       319: 	    $newloc='/adm/navmaps';
1.10      www       320:          }  
1.57      www       321: 	 if ($newloc eq '/adm/navmaps' && $direction eq 'navlaunch') {
1.54      albertel  322: 	     &navlaunch($r);
                    323: 	     return OK;
                    324: 	 } else {
                    325: 	     &Apache::loncommon::content_type($r,'text/html');
                    326: 	     $r->header_out(Location => 
1.71      albertel  327: 			    &Apache::lonnet::absolute_url().$newloc);
1.54      albertel  328: 	     
                    329: 	     return REDIRECT;
                    330: 	 }
1.10      www       331:       }
1.2       www       332:       $currenturl=~s/^http\:\/\///;
                    333:       $currenturl=~s/^[^\/]+//;
1.35      www       334: #
                    335: # Is the current URL on the map? If not, start with last known URL
                    336: #
                    337:       unless (&Apache::lonnet::is_on_map($currenturl)) {
1.7       www       338: 	 my $last;
1.53      albertel  339:          if (tie(%hash,'GDBM_File',$env{'request.course.fn'}.'_symb.db',
1.28      albertel  340:                     &GDBM_READER(),0640)) {
1.7       www       341: 	     $last=$hash{'last_known'};
                    342:              untie(%hash);
                    343:          }
                    344:          if ($last) {
1.52      albertel  345: 	     $currenturl=&Apache::lonnet::clutter((&Apache::lonnet::decode_symb($last))[2]);
1.7       www       346: 	 } else {
1.54      albertel  347: 	     if ($direction eq 'return') {
                    348: 		 &Apache::loncommon::content_type($r,'text/html');
                    349: 		 $r->header_out(Location => 
1.71      albertel  350: 				&Apache::lonnet::absolute_url().
1.70      albertel  351: 				'/adm/noidea.html');
1.54      albertel  352: 		 return REDIRECT;
                    353: 	     } else {
                    354: 		 &navlaunch($r);
                    355: 		 return OK;
                    356: 	     }
1.7       www       357:          }
                    358:       }
1.3       www       359: # ------------------------------------------- Do we have any idea where we are?
                    360:       my $position;
                    361:       if ($position=Apache::lonnet::symbread($currenturl)) {
                    362: # ------------------------------------------------------------------------- Yes
1.41      www       363: 	  my ($startoutmap,$mapnum,$thisurl)=&Apache::lonnet::decode_symb($position);
1.52      albertel  364:           $cachehash{$startoutmap}{$thisurl}=[$thisurl,$mapnum];
1.23      www       365:           $cachehash{$startoutmap}{'last_known'}=
1.52      albertel  366:                              [&Apache::lonnet::declutter($currenturl),$mapnum];
1.20      albertel  367: 
1.5       www       368: # ============================================================ Tie the big hash
1.53      albertel  369:           if (tie(%hash,'GDBM_File',$env{'request.course.fn'}.'.db',
1.28      albertel  370:                         &GDBM_READER(),0640)) {
1.29      www       371:               my $rid=$hash{'map_pc_'.&Apache::lonnet::clutter($startoutmap)}.
                    372:                       '.'.$mapnum;
1.14      www       373: 
1.15      www       374: # ------------------------------------------------- Move forward, backward, etc
1.22      www       375:               my $endupmap;
                    376:               ($next,$endupmap)=&move($rid,$startoutmap,$direction);
1.15      www       377: # -------------------------------------- Do we have one and only one empty URL?
1.22      www       378: # We are now at at least one non-empty URL
1.4       www       379: # ----------------------------------------------------- Check out possibilities
                    380:               if ($next) {
                    381:                   @possibilities=split(/\,/,$next);
                    382:                   if ($#possibilities==0) {
1.5       www       383: # ---------------------------------------------- Only one possibility, redirect
1.56      albertel  384: 	              ($redirecturl,$redirectsymb)=&hash_src($next);
1.52      albertel  385:                       $cachehash{$endupmap}{$redirecturl}=
                    386: 			  [$redirecturl,(split(/\./,$next))[1]];
1.4       www       387:                   } else {
1.5       www       388: # ------------------------ There are multiple possibilities for a next resource
                    389:                       $multichoice=1;
1.62      albertel  390: 		      foreach my $id (@possibilities) {
                    391: 			  $multichoicehash{'src_'.$id}=$hash{'src_'.$id};
                    392:                           $multichoicehash{'title_'.$id}=$hash{'title_'.$id};
                    393:                           $multichoicehash{'type_'.$id}=$hash{'type_'.$id};
                    394:                           (my $first, my $second) = $id =~ /(\d+).(\d+)/;
                    395:                           my $symbSrc = Apache::lonnet::declutter($hash{'src_'.$id});
                    396:                           $multichoicehash{'symb_'.$id} = 
1.32      bowersj2  397:                               Apache::lonnet::declutter($hash{'map_id_'.$first}.'___'.
                    398:                                                         $second.'___'.$symbSrc);
                    399:                                                          
1.62      albertel  400:                           my ($choicemap,$choiceres)=split(/\./,$id);
1.52      albertel  401: 			  my $map=&Apache::lonnet::declutter($hash{'src_'.$choicemap});
1.62      albertel  402: 			  my $url=$multichoicehash{'src_'.$id};
1.52      albertel  403:                           $cachehash{$map}{$url}=[$url,$choiceres];
1.62      albertel  404:                       }
1.4       www       405:                   }
1.5       www       406: 	      } else {
                    407: # -------------------------------------------------------------- No place to go
                    408:                   $multichoice=-1;
1.4       www       409:               }
1.5       www       410: # ----------------- The program must come past this point to untie the big hash
1.3       www       411: 	      untie(%hash);
1.5       www       412: # --------------------------------------------------------- Store position info
1.52      albertel  413:               $cachehash{$startoutmap}{'last_direction'}=[$direction,'notasymb'];
1.19      www       414:               foreach my $thismap (keys %cachehash) {
1.52      albertel  415: 		  my $mapnum=$cachehash{$thismap}->{'mapnum'};
                    416: 		  delete($cachehash{$thismap}->{'mapnum'});
                    417: 		  &Apache::lonnet::symblist($thismap,
                    418: 					    %{$cachehash{$thismap}});
1.19      www       419: 	      }
1.5       www       420: # ============================================== Do not return before this line
1.4       www       421:               if ($redirecturl) {
1.5       www       422: # ----------------------------------------------------- There is a URL to go to
1.38      www       423: 		  if ($direction eq 'forward') {
                    424:                      &Apache::lonnet::linklog($currenturl,$redirecturl);
                    425: 		  }
                    426: 		  if ($direction eq 'back') {
                    427:                      &Apache::lonnet::linklog($redirecturl,$currenturl);
                    428: 		  }
1.31      www       429: # ------------------------------------------------- Check for critical messages
1.53      albertel  430: 		  if ((time-$env{'user.criticalcheck.time'})>300) {
1.31      www       431:                      my @what=&Apache::lonnet::dump
1.53      albertel  432:                                   ('critical',$env{'user.domain'},
                    433:                                               $env{'user.name'});
1.31      www       434:                      if ($what[0]) {
                    435: 	                if (($what[0] ne 'con_lost') && 
                    436:                             ($what[0]!~/^error\:/)) {
                    437: 	                   $redirecturl='/adm/email?critical=display';
1.56      albertel  438: 			   $redirectsymb='';
1.31      www       439:                         }
                    440:                      }
                    441:                      &Apache::lonnet::appenv('user.criticalcheck.time'=>time);
                    442: 		  }
                    443: 
1.51      albertel  444: 		  &Apache::loncommon::content_type($r,'text/html');
1.71      albertel  445: 		  my $url=&Apache::lonnet::absolute_url().$redirecturl;
1.66      albertel  446: 		  $url = &add_get_param($url, { 'symb' => $redirectsymb});
1.56      albertel  447:                   $r->header_out(Location => $url);
1.4       www       448:                   return REDIRECT;
1.5       www       449: 	      } else {
                    450: # --------------------------------------------------------- There was a problem
1.51      albertel  451:                   &Apache::loncommon::content_type($r,'text/html');
1.8       www       452:                   $r->send_http_header;
1.59      www       453: 		  my %lt=&Apache::lonlocal::texthash('title' => 'End of Sequence',
                    454: 						     'explain' =>
                    455: 						     'You have reached the end of the sequence of materials.',
                    456: 						     'back' => 'Go Back',
                    457: 						     'nav' => 'Navigate Course Content',
                    458: 						     'wherenext' =>
                    459: 						     'There are several possibilities of where to go next',
                    460: 						     'pick' =>
                    461: 						     'Please click on the the resource you intend to access',
                    462: 						     'titleheader' => 'Title',
                    463: 						     'type' => 'Type');
1.8       www       464:                   if ($#possibilities>0) {
1.67      albertel  465: 		      my $start_page=
                    466: 			  &Apache::loncommon::start_page('Multiple Resources');
1.8       www       467:                      $r->print(<<ENDSTART);
1.67      albertel  468: $start_page
1.59      www       469: <h3>$lt{'wherenext'}</h3>
1.8       www       470: <p>
1.59      www       471: $lt{'pick'}:
1.8       www       472: <p>
                    473: <table border=2>
1.59      www       474: <tr><th>$lt{'titleheader'}</th><th>$lt{'type'}</th></tr>
1.8       www       475: ENDSTART
1.62      albertel  476:                      foreach my $id (@possibilities) {
1.8       www       477:                         $r->print(
                    478:                               '<tr><td><a href="'.
1.66      albertel  479: 				  &add_get_param($multichoicehash{'src_'.$id},
                    480: 						 {'symb' =>
                    481: 						      $multichoicehash{'symb_'.$id},
                    482: 						  }).'">'.
1.62      albertel  483:                               $multichoicehash{'title_'.$id}.
                    484:                               '</a></td><td>'.$multichoicehash{'type_'.$id}.
1.8       www       485: 			      '</td></tr>');
1.26      www       486:                      }
1.59      www       487:                      $r->print('</table>');
1.8       www       488:                   } else {
1.67      albertel  489: 		      my $start_page=
                    490: 			  &Apache::loncommon::start_page('No Resource');
1.59      www       491: 		      $r->print(<<ENDNONE);
1.67      albertel  492: $start_page
1.59      www       493: <h3>$lt{'title'}</h3>
                    494: <p>$lt{'explain'}</p>
                    495: ENDNONE
                    496: 		  }
                    497: 		  $r->print(<<ENDMENU);
1.37      www       498: <ul>
1.59      www       499: <li><a href="/adm/flip?postdata=return:">$lt{'back'}</a></li>
                    500: <li><a href="/adm/navmaps">$lt{'nav'}</a></li>
1.67      albertel  501: </ul>
1.59      www       502: ENDMENU
1.67      albertel  503:                   $r->print(&Apache::loncommon::end_page());
1.59      www       504:                   return OK;
                    505: 	      }
1.5       www       506: 	  } else {
                    507: # ------------------------------------------------- Problem, could not tie hash
1.53      albertel  508:               $env{'user.error.msg'}="/adm/flip:bre:0:1:Course Data Missing";
1.5       www       509:               return HTTP_NOT_ACCEPTABLE; 
1.3       www       510:           }
1.5       www       511:       } else {
                    512: # ---------------------------------------- No, could not determine where we are
1.42      albertel  513: 	  $r->internal_redirect('/adm/ambiguous');
1.2       www       514:       }
1.5       www       515:   } else {
1.2       www       516: # -------------------------- Class was not initialized or page fliped strangely
1.53      albertel  517:       $env{'user.error.msg'}="/adm/flip:bre:0:0:Choose Course";
1.2       www       518:       return HTTP_NOT_ACCEPTABLE; 
                    519:   } 
1.1       www       520: }
                    521: 
                    522: 1;
                    523: __END__
                    524: 
                    525: 
                    526: 
                    527: 
                    528: 
                    529: 
                    530: 

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