--- rat/lonpageflip.pm 2006/01/09 18:51:26 1.62 +++ rat/lonpageflip.pm 2014/05/20 20:40:46 1.85 @@ -2,7 +2,7 @@ # # Page flip handler # -# $Id: lonpageflip.pm,v 1.62 2006/01/09 18:51:26 albertel Exp $ +# $Id: lonpageflip.pm,v 1.85 2014/05/20 20:40:46 musolffc Exp $ # # Copyright Michigan State University Board of Trustees # @@ -27,11 +27,16 @@ # http://www.lon-capa.org/ # + + package Apache::lonpageflip; use strict; +use LONCAPA; use Apache::Constants qw(:common :http REDIRECT); use Apache::lonnet; +use Apache::loncommon(); +use Apache::lonlocal; use HTML::TokeParser; use GDBM_File; @@ -46,6 +51,7 @@ sub cleanup { &Apache::lonnet::logthis('Failed cleanup pageflip: hash'); } } + return OK; } sub addrid { @@ -84,6 +90,39 @@ sub hash_src { } sub move { + my ($next,$endupmap,$direction) = @_; + my $safecount=0; + my $allowed=0; + do { + ($next,$endupmap)=&get_next_possible_move($next,$endupmap,$direction); + + my $url = $hash{'src_'.$next}; + my ($mapid,$resid)=split(/\./,$next); + my $symb = &Apache::lonnet::encode_symb($hash{'map_id_'.$mapid}, + $resid,$url); + if ($url eq '' || $symb eq '') { + $allowed = 0; + } else { + my $priv = &Apache::lonnet::allowed('bre',$url,$symb); + $allowed = (($priv eq 'F') || ($priv eq '2')); + } + $safecount++; + } while ( ($next) + && ($next!~/\,/) + && ( + (!$hash{'src_'.$next}) + || ( + (!$env{'request.role.adv'}) + && $hash{'randomout_'.$next} + ) + || (!$allowed) + ) + && ($safecount<10000)); + + return ($next,$endupmap); +} + +sub get_next_possible_move { my ($rid,$mapurl,$direction)=@_; my $startoutrid=$rid; @@ -97,9 +136,11 @@ sub move { $rid=$hash{'ids_'.$hash{'map_id_'.(split(/\./,$rid))[0]}}; } foreach my $id (split(/\,/,$hash{'to_'.$rid})) { - my $thiscond= - &Apache::lonnet::directcondval($hash{'condid_'.$hash{'undercond_'.$id}}); - if ($thiscond>=$mincond) { + my $condition= $hash{'conditions_'.$hash{'goesto_'.$id}}; + my $rescond = &Apache::lonnet::docondval($condition); + my $linkcond = &Apache::lonnet::directcondval($hash{'condid_'.$hash{'undercond_'.$id}}); + my $thiscond = ($rescond<$linkcond)?$rescond:$linkcond; + if ($thiscond>=$mincond) { if ($posnext) { $posnext.=','.$id.':'.$thiscond; } else { @@ -137,8 +178,10 @@ sub move { $rid=$hash{'ids_'.$hash{'map_id_'.(split(/\./,$rid))[0]}}; } foreach my $id (split(/\,/,$hash{'from_'.$rid})) { - my $thiscond= - &Apache::lonnet::directcondval($hash{'condid_'.$hash{'undercond_'.$id}}); + my $condition= $hash{'conditions_'.$hash{'comesfrom_'.$id}}; + my $rescond = &Apache::lonnet::docondval($condition); + my $linkcond = &Apache::lonnet::directcondval($hash{'condid_'.$hash{'undercond_'.$id}}); + my $thiscond = ($rescond<$linkcond)?$rescond:$linkcond; if ($thiscond>=$mincond) { if ($posnext) { $posnext.=','.$id.':'.$thiscond; @@ -175,28 +218,35 @@ sub move { 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(<Goto first resource

- -

Collapse external navigation window

-ENDNAV - $r->print(&Apache::loncommon::endbodytag().''); + untie(%hash); + return $furl; + } else { + return '/adm/navmaps'; + } } + # ================================================================ Main Handler sub handler { @@ -226,19 +276,14 @@ sub handler { } $currenturl=~s/\.\d+\.(\w+)$/\.$1/; if ($direction eq 'firstres') { - my $furl; - if (tie(my %bighash,'GDBM_File',$env{'request.course.fn'}.'.db', - &GDBM_READER(),0640)) { - $furl=$bighash{'first_url'}; - untie(%bighash); - } + my $furl=&first_accessible_resource(); &Apache::loncommon::content_type($r,'text/html'); $r->header_out(Location => - 'http://'.$ENV{'HTTP_HOST'}.$furl); + &Apache::lonnet::absolute_url().$furl); return REDIRECT; } - if ($direction eq 'return' || $direction eq 'navlaunch') { + if ($direction eq 'return') { # -------------------------------------------------------- Return to last known my $last; if (tie(%hash,'GDBM_File',$env{'request.course.fn'}.'_symb.db', @@ -262,18 +307,13 @@ sub handler { } else { $newloc='/adm/navmaps'; } - if ($newloc eq '/adm/navmaps' && $direction eq 'navlaunch') { - &navlaunch($r); - return OK; - } else { &Apache::loncommon::content_type($r,'text/html'); $r->header_out(Location => - 'http://'.$ENV{'HTTP_HOST'}.$newloc); + &Apache::lonnet::absolute_url().$newloc); return REDIRECT; - } } - $currenturl=~s/^http\:\/\///; + $currenturl=~s/^https?\:\/\///; $currenturl=~s/^[^\/]+//; # # Is the current URL on the map? If not, start with last known URL @@ -288,15 +328,11 @@ sub handler { if ($last) { $currenturl=&Apache::lonnet::clutter((&Apache::lonnet::decode_symb($last))[2]); } else { - if ($direction eq 'return') { &Apache::loncommon::content_type($r,'text/html'); $r->header_out(Location => - 'http://'.$ENV{'HTTP_HOST'}.'/adm/noidea.html'); + &Apache::lonnet::absolute_url(). + '/adm/noidea.html'); return REDIRECT; - } else { - &navlaunch($r); - return OK; - } } } # ------------------------------------------- Do we have any idea where we are? @@ -318,14 +354,6 @@ sub handler { 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}) || - ((!$env{'request.role.adv'}) && $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) { @@ -377,24 +405,13 @@ sub handler { 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'; - $redirectsymb=''; - } - } - &Apache::lonnet::appenv('user.criticalcheck.time'=>time); - } - +# ------------------------------------- Check for and display critical messages + my ($redirect, $url) = &Apache::loncommon::critical_redirect(300); + unless ($redirect) { + $url=&Apache::lonnet::absolute_url().$redirecturl; + $url = &add_get_param($url, { 'symb' => $redirectsymb}); + } &Apache::loncommon::content_type($r,'text/html'); - my $url='http://'.$ENV{'HTTP_HOST'}.$redirecturl; - if ($redirectsymb ne '') { $url.='?symb='.&Apache::lonnet::escape($redirectsymb); } $r->header_out(Location => $url); return REDIRECT; } else { @@ -405,51 +422,52 @@ sub handler { 'explain' => 'You have reached the end of the sequence of materials.', 'back' => 'Go Back', - 'nav' => 'Navigate Course Content', + 'nav' => 'Course Contents', 'wherenext' => 'There are several possibilities of where to go next', 'pick' => 'Please click on the the resource you intend to access', 'titleheader' => 'Title', 'type' => 'Type'); + if (&Apache::loncommon::course_type() eq 'Community') { + $lt{'nav'} = &mt('Community Contents'); + } if ($#possibilities>0) { - my $bodytag= - &Apache::loncommon::bodytag('Multiple Resources'); + my $start_page= + &Apache::loncommon::start_page('Multiple Resources'); $r->print(<Choose Next Location -$bodytag +$start_page

$lt{'wherenext'}

$lt{'pick'}:

- +
ENDSTART foreach my $id (@possibilities) { $r->print( ''); } $r->print('
$lt{'titleheader'}$lt{'type'}
'. + &add_get_param($multichoicehash{'src_'.$id}, + {'symb' => + $multichoicehash{'symb_'.$id}, + }).'">'. $multichoicehash{'title_'.$id}. ''.$multichoicehash{'type_'.$id}. '
'); } else { - my $bodytag=&Apache::loncommon::bodytag('No Resource'); - $r->print(<No Resource -$bodytag -

$lt{'title'}

-

$lt{'explain'}

-ENDNONE - } - $r->print(< -
  • $lt{'back'}
  • -
  • $lt{'nav'}
  • - -ENDMENU + $r->print( + &Apache::loncommon::start_page('No Resource') + .'

    '.$lt{'title'}.'

    ' + .'

    '.$lt{'explain'}.'

    '); + } + $r->print( + &Apache::lonhtmlcommon::actionbox( + [''.$lt{'back'}.'', + ''.$lt{'nav'}.'' + ]) + .&Apache::loncommon::end_page()); return OK; } } else { @@ -460,6 +478,7 @@ ENDMENU } else { # ---------------------------------------- No, could not determine where we are $r->internal_redirect('/adm/ambiguous'); + return OK; } } else { # -------------------------- Class was not initialized or page fliped strangely @@ -471,6 +490,44 @@ ENDMENU 1; __END__ +=pod + +=head1 NAME + +Apache::lonpageflip + +=head1 SYNOPSIS + +Deals with forward, backward, and other page flips. + +This is part of the LearningOnline Network with CAPA project +described at http://www.lon-capa.org. + +=head1 OVERVIEW + +(empty) + +=head1 SUBROUTINES + +=over cleanup() + +=item addrid() + +=item fullmove() + +=item hash_src() + +=item move() + +=item get_next_possible_move() + +=item first_accessible_resource() + +=item handler() + +=back + +=cut