--- rat/lonpageflip.pm 2002/05/23 15:07:55 1.25 +++ rat/lonpageflip.pm 2003/10/29 22:09:17 1.46 @@ -2,7 +2,7 @@ # # Page flip handler # -# $Id: lonpageflip.pm,v 1.25 2002/05/23 15:07:55 www Exp $ +# $Id: lonpageflip.pm,v 1.46 2003/10/29 22:09:17 www Exp $ # # Copyright Michigan State University Board of Trustees # @@ -50,23 +50,32 @@ 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; } - 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)) { + &GDBM_READER(),0640)) { ($rid,$mapurl)=&move($rid,$mapurl,$direction); untie(%hash); } @@ -83,8 +92,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= @@ -119,9 +128,9 @@ sub move { } } 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_'.$_}}); @@ -176,21 +185,30 @@ 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; 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]; + 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,16 +220,18 @@ sub handler { } $currenturl=~s/^http\:\/\///; $currenturl=~s/^[^\/]+//; - unless (($currenturl=~/^\/res\//) || - ($currenturl=~/^\/adm\/wrapper\//)) { +# +# 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)) { + &GDBM_READER(),0640)) { $last=$hash{'last_known'}; untie(%hash); } if ($last) { - $currenturl='/res/'.(split(/\_\_\_/,$last))[1]; + $currenturl=&Apache::lonnet::clutter((&Apache::lonnet::decode_symb($last))[1]); } else { $r->content_type('text/html'); $r->header_out(Location => @@ -223,23 +243,25 @@ 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); # ============================================================ Tie the big hash if (tie(%hash,'GDBM_File',$ENV{'request.course.fn'}.'.db', - &GDBM_READER,0640)) { - my $rid=$hash{'map_pc_/res/'.$startoutmap}.'.'.$mapnum; + &GDBM_READER(),0640)) { + my $rid=$hash{'map_pc_'.&Apache::lonnet::clutter($startoutmap)}. + '.'.$mapnum; # ------------------------------------------------- Move forward, backward, etc 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)) { + while (($next) && ($next!~/\,/) && + ((!$hash{'src_'.$next}) || ($hash{'randomout_'.$next})) + && ($safecount<10000)) { ($next,$endupmap)=&move($next,$endupmap,$direction); $safecount++; } @@ -260,6 +282,12 @@ sub handler { $multichoicehash{'src_'.$_}=$hash{'src_'.$_}; $multichoicehash{'title_'.$_}=$hash{'title_'.$_}; $multichoicehash{'type_'.$_}=$hash{'type_'.$_}; + (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})} @@ -284,6 +312,26 @@ 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 + ('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); @@ -293,35 +341,41 @@ 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:

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 { + 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 @@ -335,7 +389,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