--- rat/lonpageflip.pm 2002/12/02 14:39:02 1.32 +++ rat/lonpageflip.pm 2004/10/19 15:26:53 1.49 @@ -2,7 +2,7 @@ # # Page flip handler # -# $Id: lonpageflip.pm,v 1.32 2002/12/02 14:39:02 bowersj2 Exp $ +# $Id: lonpageflip.pm,v 1.49 2004/10/19 15:26:53 albertel Exp $ # # Copyright Michigan State University Board of Trustees # @@ -50,6 +50,15 @@ use GDBM_File; my %hash; +sub cleanup { + if (tied(%hash)){ + &Apache::lonnet::logthis('Cleanup pageflip: hash'); + unless (untie(%hash)) { + &Apache::lonnet::logthis('Failed cleanup pageflip: hash'); + } + } +} + sub addrid { my ($current,$new,$condid)=@_; unless ($condid) { $condid=0; } @@ -83,8 +92,8 @@ sub move { my $posnext=''; if ($direction eq 'forward') { # --------------------------------------------------------------------- Forward - if ($hash{'type_'.$rid} eq 'finish') { - $rid=$hash{'ids_'.&Apache::lonnet::clutter($mapurl)}; + while ($hash{'type_'.$rid} eq 'finish') { + $rid=$hash{'ids_'.$hash{'map_id_'.(split(/\./,$rid))[0]}}; } map { my $thiscond= @@ -111,6 +120,10 @@ sub move { $hash{'map_type_'.$hash{'map_pc_'.$hash{'src_'.$next}}} eq 'sequence') { $mapurl=$hash{'src_'.$next}; $next=$hash{'map_start_'.$hash{'src_'.$next}}; + } elsif ( +# This jumps back up from an empty sequence, to a page up one level + $hash{'map_type_'.$hash{'map_pc_'.$hash{'src_'.$next}}} eq 'page') { + $mapurl=$hash{'map_id_'.(split(/\./,$next))[0]}; } } elsif ((split(/\./,$startoutrid))[0]!=(split(/\./,$next))[0]) { @@ -119,9 +132,9 @@ sub move { } } elsif ($direction eq 'back') { # ------------------------------------------------------------------- Backwards - if ($hash{'type_'.$rid} eq 'start') { - $rid=$hash{'ids_'.&Apache::lonnet::clutter($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_'.$_}}); @@ -147,7 +160,11 @@ sub move { $hash{'map_type_'.$hash{'map_pc_'.$hash{'src_'.$next}}} eq 'sequence') { $mapurl=$hash{'src_'.$next}; $next=$hash{'map_finish_'.$hash{'src_'.$next}}; - } + } elsif ( + $hash{'map_type_'.$hash{'map_pc_'.$hash{'src_'.$next}}} eq 'page') { +# This jumps back up from an empty sequence, to a page up one level + $mapurl=$hash{'map_id_'.(split(/\./,$next))[0]}; + } } elsif ((split(/\./,$startoutrid))[0]!=(split(/\./,$next))[0]) { # This comes back up from a map (going up one level); @@ -176,10 +193,12 @@ sub handler { my $redirecturl=''; my $next=''; my @possibilities=(); + &Apache::loncommon::get_unprocessed_cgi($ENV{'QUERY_STRING'},['postdata']); if (($ENV{'form.postdata'})&&($ENV{'request.course.fn'})) { $ENV{'form.postdata'}=~/(\w+)\:(.*)/; my $direction=$1; my $currenturl=$2; + $currenturl=~s/\.\d+\.(\w+)$/\.$1/; if ($direction eq 'return') { # -------------------------------------------------------- Return to last known my $last; @@ -189,8 +208,15 @@ sub handler { untie(%hash); } my $newloc; - if ($last) { - $newloc=&Apache::lonnet::clutter((split(/\_\_\_/,$last))[1]); + if (($last) && (tie(%hash,'GDBM_File',$ENV{'request.course.fn'}.'.db', + &GDBM_READER(),0640))) { + my ($murl,$fn)=&Apache::lonnet::decode_symb($last); + my $id; + ($murl,$id,$fn)=&Apache::lonnet::decode_symb(&Apache::lonnet::symbread($fn)); + $newloc=$hash{'src_'. + $hash{'map_pc_'.&Apache::lonnet::clutter($murl)}.'.'.$id}; + unless ($newloc) { $newloc='/adm/noidea.html'; } + untie %hash; } else { $newloc='/adm/noidea.html'; } @@ -202,7 +228,10 @@ sub handler { } $currenturl=~s/^http\:\/\///; $currenturl=~s/^[^\/]+//; - unless ($currenturl=~/^\/(res|adm\/wrapper|public|adm\/coursedocs)\//) { +# +# Is the current URL on the map? If not, start with last known URL +# + unless (&Apache::lonnet::is_on_map($currenturl)) { my $last; if (tie(%hash,'GDBM_File',$ENV{'request.course.fn'}.'_symb.db', &GDBM_READER(),0640)) { @@ -210,7 +239,7 @@ sub handler { untie(%hash); } if ($last) { - $currenturl=&Apache::lonnet::clutter((split(/\_\_\_/,$last))[1]); + $currenturl=&Apache::lonnet::clutter((&Apache::lonnet::decode_symb($last))[1]); } else { $r->content_type('text/html'); $r->header_out(Location => @@ -222,7 +251,7 @@ sub handler { my $position; if ($position=Apache::lonnet::symbread($currenturl)) { # ------------------------------------------------------------------------- Yes - my ($startoutmap,$mapnum,$thisurl)=split(/\_\_\_/,$position); + my ($startoutmap,$mapnum,$thisurl)=&Apache::lonnet::decode_symb($position); $cachehash{$startoutmap}{$thisurl}=$mapnum; $cachehash{$startoutmap}{'last_known'}= &Apache::lonnet::declutter($currenturl); @@ -239,7 +268,8 @@ sub handler { # -------------------------------------- Do we have one and only one empty URL? my $safecount=0; while (($next) && ($next!~/\,/) && - ((!$hash{'src_'.$next}) || ($hash{'randomout_'.$next})) + ((!$hash{'src_'.$next}) || + ((!$ENV{'request.role.adv'}) && $hash{'randomout_'.$next})) && ($safecount<10000)) { ($next,$endupmap)=&move($next,$endupmap,$direction); $safecount++; @@ -291,6 +321,12 @@ sub handler { # ============================================== Do not return before this line if ($redirecturl) { # ----------------------------------------------------- There is a URL to go to + if ($direction eq 'forward') { + &Apache::lonnet::linklog($currenturl,$redirecturl); + } + if ($direction eq 'back') { + &Apache::lonnet::linklog($redirecturl,$currenturl); + } # ------------------------------------------------- Check for critical messages if ((time-$ENV{'user.criticalcheck.time'})>300) { my @what=&Apache::lonnet::dump @@ -314,11 +350,12 @@ sub handler { $r->content_type('text/html'); $r->send_http_header; if ($#possibilities>0) { + my $bodytag= + &Apache::loncommon::bodytag('Multiple Resources'); $r->print(<Choose Next Location - -

LON-CAPA

-There are several possibilities of where to go next. +$bodytag +

There are several possibilities of where to go next

Please click on the the resource you intend to access:

@@ -337,13 +374,17 @@ ENDSTART $r->print(''); return OK; } else { + my $bodytag=&Apache::loncommon::bodytag('No Resource'); $r->print(<Choose Next Location - - -

Sorry!

-

Next resource could not be identified.

-

You probably are at the beginning or the end of the course.

+No Resource +$bodytag +

Next resource could not be identified.

+

You probably are at the beginning or the end of the +course.

+ ENDNONE @@ -357,7 +398,10 @@ ENDNONE } } else { # ---------------------------------------- No, could not determine where we are - $r->internal_redirect('/adm/ambiguous'); + if ( &Apache::lonnet::mod_perl_version() == 2 ) { + &Apache::lonnet::cleanenv(); + } + $r->internal_redirect('/adm/ambiguous'); } } else { # -------------------------- Class was not initialized or page fliped strangely