--- rat/lonpageflip.pm 2001/11/29 19:23:49 1.18 +++ rat/lonpageflip.pm 2002/08/12 18:21:42 1.28 @@ -2,7 +2,7 @@ # # Page flip handler # -# $Id: lonpageflip.pm,v 1.18 2001/11/29 19:23:49 www Exp $ +# $Id: lonpageflip.pm,v 1.28 2002/08/12 18:21:42 albertel Exp $ # # Copyright Michigan State University Board of Trustees # @@ -53,18 +53,29 @@ my %hash; sub addrid { my ($current,$new,$condid)=@_; unless ($condid) { $condid=0; } - if (&Apache::lonnet::allowed('bre',$hash{'src_'.$new})) { + if ($current) { $current.=','.$new; } else { $current=''.$new; } - } + return $current; } +sub fullmove { + my ($rid,$mapurl,$direction)=@_; + if (tie(%hash,'GDBM_File',$ENV{'request.course.fn'}.'.db', + &GDBM_READER(),0640)) { + ($rid,$mapurl)=&move($rid,$mapurl,$direction); + untie(%hash); + } + return($rid,$mapurl); +} + sub move { my ($rid,$mapurl,$direction)=@_; + my $startoutrid=$rid; my $next=''; @@ -95,11 +106,16 @@ sub move { } } split(/\,/,$posnext); if ($hash{'is_map_'.$next}) { +# This jumps to the beginning of a new map (going down level) if ( $hash{'map_type_'.$hash{'map_pc_'.$hash{'src_'.$next}}} eq 'sequence') { $mapurl=$hash{'src_'.$next}; $next=$hash{'map_start_'.$hash{'src_'.$next}}; } + } elsif + ((split(/\./,$startoutrid))[0]!=(split(/\./,$next))[0]) { +# This comes up from a map (coming up one level); + $mapurl=$hash{'map_id_'.(split(/\./,$next))[0]}; } } elsif ($direction eq 'back') { # ------------------------------------------------------------------- Backwards @@ -126,14 +142,18 @@ sub move { } } split(/\,/,$posnext); if ($hash{'is_map_'.$next}) { +# This jumps to the end of a new map (going down one level) if ( $hash{'map_type_'.$hash{'map_pc_'.$hash{'src_'.$next}}} eq 'sequence') { $mapurl=$hash{'src_'.$next}; $next=$hash{'map_finish_'.$hash{'src_'.$next}}; } + } elsif + ((split(/\./,$startoutrid))[0]!=(split(/\./,$next))[0]) { +# This comes back up from a map (going up one level); + $mapurl=$hash{'map_id_'.(split(/\./,$next))[0]}; } } - return ($next,$mapurl); } @@ -156,7 +176,6 @@ sub handler { my $redirecturl=''; my $next=''; my @possibilities=(); - if (($ENV{'form.postdata'})&&($ENV{'request.course.fn'})) { $ENV{'form.postdata'}=~/(\w+)\:(.*)/; my $direction=$1; @@ -165,7 +184,7 @@ sub handler { # -------------------------------------------------------- Return to last known my $last; if (tie(%hash,'GDBM_File',$ENV{'request.course.fn'}.'_symb.db', - &GDBM_READER,0640)) { + &GDBM_READER(),0640)) { $last=$hash{'last_known'}; untie(%hash); } @@ -187,7 +206,7 @@ sub handler { ($currenturl=~/^\/adm\/wrapper\//)) { my $last; if (tie(%hash,'GDBM_File',$ENV{'request.course.fn'}.'_symb.db', - &GDBM_READER,0640)) { + &GDBM_READER(),0640)) { $last=$hash{'last_known'}; untie(%hash); } @@ -204,30 +223,36 @@ sub handler { my $position; if ($position=Apache::lonnet::symbread($currenturl)) { # ------------------------------------------------------------------------- Yes - my ($mapurl,$mapnum,$thisurl)=split(/\_\_\_/,$position); - $cachehash{$thisurl}=$mapnum; + my ($startoutmap,$mapnum,$thisurl)=split(/\_\_\_/,$position); + $cachehash{$startoutmap}{$thisurl}=$mapnum; + $cachehash{$startoutmap}{'last_known'}= + &Apache::lonnet::declutter($currenturl); + # ============================================================ Tie the big hash if (tie(%hash,'GDBM_File',$ENV{'request.course.fn'}.'.db', - &GDBM_READER,0640)) { - my $rid=$hash{'map_pc_/res/'.$mapurl}.'.'.$mapnum; + &GDBM_READER(),0640)) { + my $rid=$hash{'map_pc_/res/'.$startoutmap}.'.'.$mapnum; # ------------------------------------------------- Move forward, backward, etc - - ($next,$mapurl)=&move($rid,$mapurl,$direction); + my $endupmap; + ($next,$endupmap)=&move($rid,$startoutmap,$direction); # -------------------------------------- Do we have one and only one empty URL? my $safecount=0; - while (($next) && ($next!~/\,/) && (!$hash{'src_'.$next}) - && ($safecount<25)) { - ($next,$mapurl)=&move($next,$mapurl,$direction); + while (($next) && ($next!~/\,/) && + ((!$hash{'src_'.$next}) || ($hash{'randomout_'.$next})) + && ($safecount<10000)) { + ($next,$endupmap)=&move($next,$endupmap,$direction); $safecount++; } +# We are now at at least one non-empty URL # ----------------------------------------------------- Check out possibilities if ($next) { @possibilities=split(/\,/,$next); if ($#possibilities==0) { # ---------------------------------------------- Only one possibility, redirect $redirecturl=$hash{'src_'.$next}; - $cachehash{&Apache::lonnet::declutter($redirecturl)} + $cachehash{$endupmap} + {&Apache::lonnet::declutter($redirecturl)} =(split(/\./,$next))[1]; } else { # ------------------------ There are multiple possibilities for a next resource @@ -236,12 +261,14 @@ sub handler { $multichoicehash{'src_'.$_}=$hash{'src_'.$_}; $multichoicehash{'title_'.$_}=$hash{'title_'.$_}; $multichoicehash{'type_'.$_}=$hash{'type_'.$_}; + my ($choicemap,$choiceres)=split(/\./,$_); $cachehash - {&Apache::lonnet::declutter( + {&Apache::lonnet::declutter($hash{'src_'.$choicemap})} + {&Apache::lonnet::declutter( $multichoicehash {'src_'.$_} )} - =(split(/\./,$_))[1]; + =$choiceres; } @possibilities; } } else { @@ -251,9 +278,10 @@ sub handler { # ----------------- The program must come past this point to untie the big hash untie(%hash); # --------------------------------------------------------- Store position info - $cachehash{'last_direction'}=$direction; - $cachehash{'last_known'}=&Apache::lonnet::declutter($currenturl); - &Apache::lonnet::symblist($mapurl,%cachehash); + $cachehash{$startoutmap}{'last_direction'}=$direction; + foreach my $thismap (keys %cachehash) { + &Apache::lonnet::symblist($thismap,%{$cachehash{$thismap}}); + } # ============================================== Do not return before this line if ($redirecturl) { # ----------------------------------------------------- There is a URL to go to @@ -277,14 +305,14 @@ Please click on the the resource you int ENDSTART - map { + foreach (@possibilities) { $r->print( ''); - } @possibilities; + } $r->print('
TitleType
'. $multichoicehash{'title_'.$_}. ''.$multichoicehash{'type_'.$_}. '
'); return OK; } else {