--- rat/lonpageflip.pm 2001/11/29 19:23:49 1.18 +++ rat/lonpageflip.pm 2002/10/10 19:05:32 1.31 @@ -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.31 2002/10/10 19:05:32 www 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=''; @@ -73,7 +84,7 @@ sub move { if ($direction eq 'forward') { # --------------------------------------------------------------------- Forward if ($hash{'type_'.$rid} eq 'finish') { - $rid=$hash{'ids_/res/'.$mapurl}; + $rid=$hash{'ids_'.&Apache::lonnet::clutter($mapurl)}; } map { my $thiscond= @@ -95,16 +106,21 @@ 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 if ($hash{'type_'.$rid} eq 'start') { - $rid=$hash{'ids_/res/'.$mapurl}; + $rid=$hash{'ids_'.&Apache::lonnet::clutter($mapurl)}; } map { my $thiscond= @@ -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,13 +184,13 @@ 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); } my $newloc; if ($last) { - $newloc='/res/'.(split(/\_\_\_/,$last))[1]; + $newloc=&Apache::lonnet::clutter((split(/\_\_\_/,$last))[1]); } else { $newloc='/adm/noidea.html'; } @@ -183,16 +202,15 @@ sub handler { } $currenturl=~s/^http\:\/\///; $currenturl=~s/^[^\/]+//; - unless (($currenturl=~/^\/res\//) || - ($currenturl=~/^\/adm\/wrapper\//)) { + unless ($currenturl=~/^\/(res|adm\/wrapper|public|adm\/coursedocs)\//) { 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); } if ($last) { - $currenturl='/res/'.(split(/\_\_\_/,$last))[1]; + $currenturl=&Apache::lonnet::clutter((split(/\_\_\_/,$last))[1]); } else { $r->content_type('text/html'); $r->header_out(Location => @@ -204,30 +222,37 @@ 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_'.&Apache::lonnet::clutter($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,12 +278,27 @@ 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 +# ------------------------------------------------- Check for critical messages + if ((time-$ENV{'user.criticalcheck.time'})>300) { + my @what=&Apache::lonnet::dump + ('critical',$ENV{'user.domain'}, + $ENV{'user.name'}); + if ($what[0]) { + if (($what[0] ne 'con_lost') && + ($what[0]!~/^error\:/)) { + $redirecturl='/adm/email?critical=display'; + } + } + &Apache::lonnet::appenv('user.criticalcheck.time'=>time); + } + $r->content_type('text/html'); $r->header_out(Location => 'http://'.$ENV{'HTTP_HOST'}.$redirecturl); @@ -277,14 +319,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 {