--- rat/lonpageflip.pm 2002/04/11 15:43:40 1.20 +++ rat/lonpageflip.pm 2002/12/06 14:06:53 1.33 @@ -2,7 +2,7 @@ # # Page flip handler # -# $Id: lonpageflip.pm,v 1.20 2002/04/11 15:43:40 albertel Exp $ +# $Id: lonpageflip.pm,v 1.33 2002/12/06 14:06:53 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=''; @@ -72,8 +83,8 @@ sub move { my $posnext=''; if ($direction eq 'forward') { # --------------------------------------------------------------------- Forward - if ($hash{'type_'.$rid} eq 'finish') { - $rid=$hash{'ids_/res/'.$mapurl}; + while ($hash{'type_'.$rid} eq 'finish') { + $rid=$hash{'ids_'.$hash{'map_id_'.(split(/\./,$rid))[0]}}; } map { my $thiscond= @@ -95,17 +106,22 @@ 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}; - } + while ($hash{'type_'.$rid} eq 'start') { + $rid=$hash{'ids_'.$hash{'map_id_'.(split(/\./,$rid))[0]}}; + } map { my $thiscond= &Apache::lonnet::directcondval($hash{'condid_'.$hash{'undercond_'.$_}}); @@ -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); } @@ -164,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'; } @@ -182,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 => @@ -203,32 +222,36 @@ sub handler { my $position; if ($position=Apache::lonnet::symbread($currenturl)) { # ------------------------------------------------------------------------- Yes - my ($mapurl,$mapnum,$thisurl)=split(/\_\_\_/,$position); - $cachehash{$mapurl}{$thisurl}=$mapnum; - $cachehash{$mapurl}{'last_known'}=&Apache::lonnet::declutter($currenturl); + 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{$mapurl} + $cachehash{$endupmap} {&Apache::lonnet::declutter($redirecturl)} =(split(/\./,$next))[1]; } else { @@ -238,12 +261,20 @@ sub handler { $multichoicehash{'src_'.$_}=$hash{'src_'.$_}; $multichoicehash{'title_'.$_}=$hash{'title_'.$_}; $multichoicehash{'type_'.$_}=$hash{'type_'.$_}; - $cachehash{$mapurl} - {&Apache::lonnet::declutter( + (my $first, my $second) = $_ =~ /(\d+).(\d+)/; + my $symbSrc = Apache::lonnet::declutter($hash{'src_'.$_}); + $multichoicehash{'symb_'.$_} = + Apache::lonnet::declutter($hash{'map_id_'.$first}.'___'. + $second.'___'.$symbSrc); + + my ($choicemap,$choiceres)=split(/\./,$_); + $cachehash + {&Apache::lonnet::declutter($hash{'src_'.$choicemap})} + {&Apache::lonnet::declutter( $multichoicehash {'src_'.$_} )} - =(split(/\./,$_))[1]; + =$choiceres; } @possibilities; } } else { @@ -253,13 +284,27 @@ sub handler { # ----------------- The program must come past this point to untie the big hash untie(%hash); # --------------------------------------------------------- Store position info - $cachehash{$mapurl}{'last_direction'}=$direction; + $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); @@ -280,14 +325,15 @@ Please click on the the resource you int ENDSTART - map { + foreach (@possibilities) { $r->print( ''); - } @possibilities; + } $r->print('
TitleType
'. + $multichoicehash{'src_'.$_}.'?symb=' . + Apache::lonnet::escape($multichoicehash{'symb_'.$_}).'">'. $multichoicehash{'title_'.$_}. ''.$multichoicehash{'type_'.$_}. '
'); return OK; } else {