--- rat/lonpageflip.pm 2015/03/23 00:03:16 1.89 +++ rat/lonpageflip.pm 2017/02/18 23:39:24 1.92 @@ -2,7 +2,7 @@ # # Page flip handler # -# $Id: lonpageflip.pm,v 1.89 2015/03/23 00:03:16 raeburn Exp $ +# $Id: lonpageflip.pm,v 1.92 2017/02/18 23:39:24 raeburn Exp $ # # Copyright Michigan State University Board of Trustees # @@ -36,6 +36,7 @@ use LONCAPA; use Apache::Constants qw(:common :http REDIRECT); use Apache::lonnet; use Apache::loncommon(); +use Apache::lonnavmaps(); use Apache::lonuserstate; use Apache::lonlocal; use HTML::TokeParser; @@ -83,11 +84,18 @@ sub hash_src { my ($mapid,$resid)=split(/\./,$id); my $symb=&Apache::lonnet::encode_symb($hash{'map_id_'.$mapid}, $resid,$hash{'src_'.$id}); + my $anchor; + if ($hash{'ext_'.$id} eq 'true:') { + if ($hash{'src_'.$id} =~ /(\#.+)$/) { + $anchor = $1; + } + } if ($hash{'encrypted_'.$id}) { return (&Apache::lonenc::encrypted($hash{'src_'.$id}), - &Apache::lonenc::encrypted($symb)); + &Apache::lonenc::encrypted($symb), + $hash{'encrypted_'.$id},$anchor); } - return ($hash{'src_'.$id},$symb); + return ($hash{'src_'.$id},$symb,$hash{'encrypted_'.$id},$anchor); } sub move { @@ -237,6 +245,7 @@ sub first_accessible_resource { my ($newmapid,$newresid)=split(/\./,$newrid); my $symb=&Apache::lonnet::encode_symb($newmap,$newresid,$hash{'src_'.$newrid}); $furl=&add_get_param($hash{'src_'.$newrid},{ 'symb' => $symb }); + &check_for_syllabus(\$furl); if ($hash{'encrypted_'.$newrid}) { $furl=&Apache::lonenc::encrypted($furl); } @@ -248,6 +257,43 @@ sub first_accessible_resource { } } +sub first_answerable_ressymb { + my $navmap = Apache::lonnavmaps::navmap->new; + return unless (ref($navmap)); + my $iterator = $navmap->getIterator(undef,undef,undef,1); + return unless (ref($iterator)); + my ($curRes,$result); + while ($curRes = $iterator->next()) { + if (ref($curRes) && $curRes->is_problem()) { + foreach my $part (@{$curRes->parts()}) { + if ($curRes->tries($part) < $curRes->maxtries($part)) { + $result = $curRes->link().'?symb='.$curRes->shown_symb(); + last; + } + } + } + } + if ($result) { + return $result; + } else { + return &first_accessible_resource(); + } +} + +sub check_for_syllabus { + my ($srcref) = @_; + return unless (ref($srcref) eq 'SCALAR'); + if ($env{'request.course.id'}) { + my $cnum = $env{'course.'.$env{'request.course.id'}.'.num'}; + my $cdom = $env{'course.'.$env{'request.course.id'}.'.domain'}; + if (($$srcref =~ m{^\Q/public/$cdom/$cnum/syllabus\E($|\?)}) && + ($ENV{'SERVER_PORT'} == 443) && + ($env{'course.'.$env{'request.course.id'}.'.externalsyllabus'} =~ m{^http://})) { + $$srcref .= (($$srcref =~/\?/)? '&':'?') . 'usehttp=1'; + } + } +} + # ================================================================ Main Handler sub handler { @@ -264,7 +310,7 @@ sub handler { my %cachehash=(); my $multichoice=0; my %multichoicehash=(); - my ($redirecturl,$redirectsymb); + my ($redirecturl,$redirectsymb,$enc,$anchor); my $next=''; my @possibilities=(); &Apache::loncommon::get_unprocessed_cgi($ENV{'QUERY_STRING'},['postdata']); @@ -283,6 +329,17 @@ sub handler { $last=$hash{'last_known'}; untie(%hash); } + } elsif ($direction eq 'firstanswerable') { + my $furl = &first_answerable_ressymb(); + &Apache::loncommon::content_type($r,'text/html'); + $r->header_out(Location => + &Apache::lonnet::absolute_url().$furl); + return REDIRECT; + } elsif ($direction eq 'endplacement') { + &Apache::loncommon::content_type($r,'text/html'); + $r->send_http_header; + $r->print(&Apache::lonplacementtest::showresult()); + return OK; } if ($env{'request.course.id'}) { # Check if course needs to be re-initialized @@ -337,7 +394,12 @@ sub handler { $id=$hash{'map_pc_'.&Apache::lonnet::clutter($murl)}.'.'.$id; $newloc=$hash{'src_'.$id}; if ($newloc) { - if ($hash{'encrypted_'.$id}) { $newloc=&Apache::lonenc::encrypted($newloc); } + &check_for_syllabus(\$newloc); + if ($hash{'encrypted_'.$id}) { + $newloc=&Apache::lonenc::encrypted($newloc); + } elsif ($newloc =~ m{^(/adm/wrapper/ext/[^\#]+)\#([^\#]+)$}) { + $newloc = $1.&escape('#').$2; + } } else { $newloc='/adm/navmaps'; } @@ -404,7 +466,7 @@ sub handler { @possibilities=split(/\,/,$next); if ($#possibilities==0) { # ---------------------------------------------- Only one possibility, redirect - ($redirecturl,$redirectsymb)=&hash_src($next); + ($redirecturl,$redirectsymb,$enc,$anchor)=&hash_src($next); $cachehash{$endupmap}{$redirecturl}= [$redirecturl,(split(/\./,$next))[1]]; } else { @@ -452,8 +514,17 @@ sub handler { # ------------------------------------- Check for and display critical messages my ($redirect, $url) = &Apache::loncommon::critical_redirect(300); unless ($redirect) { + &check_for_syllabus(\$redirecturl); $url=&Apache::lonnet::absolute_url().$redirecturl; + my $addanchor; + if (($anchor ne '') && (!$enc || $env{'request.role.adv'})) { + $addanchor = 1; + $url =~ s/\#.+$//; + } $url = &add_get_param($url, { 'symb' => $redirectsymb}); + if ($addanchor) { + $url .= $anchor; + } } &Apache::loncommon::content_type($r,'text/html'); $r->header_out(Location => $url); @@ -475,7 +546,8 @@ sub handler { 'type' => 'Type', 'update' => 'Content updated', 'expupdate' => 'As a result of a recent update to the sequence of materials, it is not possible to complete the page flip.', - 'gonav' => 'Go to the Contents page to select a resource to display.'); + 'gonav' => 'Go to the Contents page to select a resource to display.', + ); if (&Apache::loncommon::course_type() eq 'Community') { $lt{'nav'} = &mt('Community Contents'); } @@ -492,9 +564,11 @@ $lt{'pick'}: $lt{'titleheader'}$lt{'type'} ENDSTART foreach my $id (@possibilities) { + my $src = $multichoicehash{'src_'.$id}; + &check_for_syllabus(\$src); $r->print( ''. @@ -516,23 +590,37 @@ ENDSTART .'

'.$lt{'expupdate'}.'
' .$lt{'gonav'}.'

'); } else { - $r->print( - &Apache::loncommon::start_page('No Resource') - .'

'.$lt{'title'}.'

' - .'

'.$lt{'explain'}.'

'); + if (($env{'course.'.$env{'request.course.id'}.'.type'} eq 'Placement') && + (!$env{'request.role.adv'})) { + my ($score,$incomplete) = &Apache::lonplacementtest::check_completion(undef,undef,1); + if ($incomplete) { + $r->print(&Apache::lonplacementtest::showincomplete($incomplete)); + } else { + $r->print(&Apache::lonplacementtest::showresult(1)); + } + } else { + $r->print( + &Apache::loncommon::start_page('No Resource') + .'

'.$lt{'title'}.'

' + .'

'.$lt{'explain'}.'

'); + } } } - if ((!@possibilities) && ($reinitcheck)) { - $r->print( - &Apache::lonhtmlcommon::actionbox( - ['
'.$lt{'nav'}.'' - ])); - } else { - $r->print( - &Apache::lonhtmlcommon::actionbox( - [''.$lt{'back'}.'', - ''.$lt{'nav'}.'' - ])); + unless (($env{'course.'.$env{'request.course.id'}.'.type'} eq 'Placement') || + ($env{'request.role.adv'})) { + if ((!@possibilities) && ($reinitcheck)) { + $r->print( + &Apache::lonhtmlcommon::actionbox( + [''.$lt{'nav'}.'' + ])); + } else { + $r->print( + &Apache::lonhtmlcommon::actionbox( + [''.$lt{'back'}.'', + ''.$lt{'nav'}.'' + ])); + } + } $r->print(&Apache::loncommon::end_page());