--- loncom/homework/lonhomework.pm 2015/04/14 21:35:56 1.349.2.2 +++ loncom/homework/lonhomework.pm 2015/05/26 13:25:52 1.349.2.3 @@ -1,7 +1,7 @@ # The LearningOnline Network with CAPA # The LON-CAPA Homework handler # -# $Id: lonhomework.pm,v 1.349.2.2 2015/04/14 21:35:56 musolffc Exp $ +# $Id: lonhomework.pm,v 1.349.2.3 2015/05/26 13:25:52 raeburn Exp $ # # Copyright Michigan State University Board of Trustees # @@ -51,6 +51,7 @@ use Apache::functionplotresponse(); use Apache::drawimage(); use Apache::Constants qw(:common); use Apache::loncommon(); +use Apace::lonparmset(); use Apache::lonlocal; use Time::HiRes qw( gettimeofday tv_interval ); use HTML::Entities(); @@ -1331,30 +1332,46 @@ sub update_construct_style { } } -# Sets timer to zero for the entire folder containing the current resource for the -# current user. +# +# Sets interval for current user so time left will be zero, either for the entire folder +# containing the current resource, or just the resource, depending on value of first item +# in interval array retrieved from EXT("resource.0.interval"); +# sub zero_timer { - my $symb = shift; - my $first_access = &Apache::lonnet::get_first_access("map",$symb); - my $done_time = time() - $first_access; - &Apache::lonparmset::storeparm_by_symb($symb,"0_interval","2",$done_time, - "date_interval",$env{'user.name'},$env{'user.domain'},,'',); + my ($symb) = @_; + my ($hastimeleft,$first_access,$now); + my @interval=&Apache::lonnet::EXT("resource.0.interval"); + if (@interval > 1) { + if ($interval[1] eq 'course') { + return; + } else { + my $now = time; + my $first_access=&Apache::lonnet::get_first_access($interval[1],$symb); + if ($first_access > 0) { + if ($first_access+$interval[0] > $now) { + my $done_time = $now - $first_access; + my $snum = 1; + if ($interval[1] eq 'map') { + $snum = 2; + } + my $result = + &Apache::lonparmset::storeparm_by_symb_inner($symb,'0_interval', + $snum,$done_time, + 'date_interval', + $env{'user.name'}, + $env{'user.domain'}); + return $result; + } + } + } + } + return; } - sub handler { #my $t0 = [&gettimeofday()]; my $request=$_[0]; - my ($symb) = &Apache::lonnet::whichuser(); - - # Set the event timer to zero if the "done button" was clicked. The button is - # part of the doneButton form created in lonmenu.pm - if ($env{"form.done"} eq "true") { - &zero_timer($symb); - $env{"form.done"} = ""; - } - $Apache::lonxml::request=$request; $Apache::lonxml::debug=$env{'user.debug'}; $env{'request.uri'}=$request->uri; @@ -1377,8 +1394,10 @@ sub handler { &unset_permissions(); return OK; } + &Apache::lonxml::debug("Permissions:$Apache::lonhomework::browse:$Apache::lonhomework::viewgrades:$Apache::lonhomework::modifygrades:$Apache::lonhomework::queuegrade"); &Apache::lonxml::debug("Problem Mode ".$env{'form.problemmode'}); + my ($symb) = &Apache::lonnet::whichuser(); &Apache::lonxml::debug('symb is '.$symb); if ($env{'request.state'} eq "construct") { if ( -e $file ) { @@ -1406,6 +1425,12 @@ sub handler { &newproblem($request); } } else { + # Set the event timer to zero if the "done button" was clicked. The button is + # part of the doneButton form created in lonmenu.pm + if ($symb && $env{'form.LC_interval_done'} eq 'true') { + &zero_timer($symb); + undef($env{'form.LC_interval_done'}); + } # just render the page normally outside of construction space &Apache::lonxml::debug("not construct"); &renderpage($request,$file);