# The LearningOnline Network with CAPA # # Page flip handler # # $Id: lonpageflip.pm,v 1.57 2005/11/08 17:57:53 www Exp $ # # Copyright Michigan State University Board of Trustees # # This file is part of the LearningOnline Network with CAPA (LON-CAPA). # # LON-CAPA is free software; you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by # the Free Software Foundation; either version 2 of the License, or # (at your option) any later version. # # LON-CAPA is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details. # # You should have received a copy of the GNU General Public License # along with LON-CAPA; if not, write to the Free Software # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA # # /home/httpd/html/adm/gpl.txt # # http://www.lon-capa.org/ # package Apache::lonpageflip; use strict; use Apache::Constants qw(:common :http REDIRECT); use Apache::lonnet; use HTML::TokeParser; use GDBM_File; # ========================================================== Module Global Hash 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 ($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 hash_src { my ($id)=@_; my ($mapid,$resid)=split(/\./,$id); my $symb=&Apache::lonnet::encode_symb($hash{'map_id_'.$mapid}, $resid,$hash{'src_'.$id}); if ($hash{'encrypted_'.$id}) { return (&Apache::lonenc::encrypted($hash{'src_'.$id}), &Apache::lonenc::encrypted($symb)); } return ($hash{'src_'.$id},$symb); } sub move { my ($rid,$mapurl,$direction)=@_; my $startoutrid=$rid; my $next=''; my $mincond=1; my $posnext=''; if ($direction eq 'forward') { # --------------------------------------------------------------------- Forward while ($hash{'type_'.$rid} eq 'finish') { $rid=$hash{'ids_'.$hash{'map_id_'.(split(/\./,$rid))[0]}}; } map { my $thiscond= &Apache::lonnet::directcondval($hash{'condid_'.$hash{'undercond_'.$_}}); if ($thiscond>=$mincond) { if ($posnext) { $posnext.=','.$_.':'.$thiscond; } else { $posnext=$_.':'.$thiscond; } if ($thiscond>$mincond) { $mincond=$thiscond; } } } split(/\,/,$hash{'to_'.$rid}); map { my ($linkid,$condval)=split(/\:/,$_); if ($condval>=$mincond) { $next=&addrid($next,$hash{'goesto_'.$linkid}, $hash{'condid_'.$hash{'undercond_'.$linkid}}); } } 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 ( # 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]) { # This comes up from a map (coming up one level); $mapurl=$hash{'map_id_'.(split(/\./,$next))[0]}; } } elsif ($direction eq 'back') { # ------------------------------------------------------------------- Backwards 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_'.$_}}); if ($thiscond>=$mincond) { if ($posnext) { $posnext.=','.$_.':'.$thiscond; } else { $posnext=$_.':'.$thiscond; } if ($thiscond>$mincond) { $mincond=$thiscond; } } } split(/\,/,$hash{'from_'.$rid}); map { my ($linkid,$condval)=split(/\:/,$_); if ($condval>=$mincond) { $next=&addrid($next,$hash{'comesfrom_'.$linkid}, $hash{'condid_'.$hash{'undercond_'.$linkid}}); } } 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 ( $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); $mapurl=$hash{'map_id_'.(split(/\./,$next))[0]}; } } return ($next,$mapurl); } sub navlaunch { my ($r)=@_; &Apache::loncommon::content_type($r,'text/html'); &Apache::loncommon::no_cache($r); $r->send_http_header; my $html=&Apache::lonxml::xmlbegin(); $r->print("$html
\n"); $r->print(''. &Apache::loncommon::bodytag('Launched')); $r->print(<