--- loncom/homework/structuretags.pm 2005/04/22 17:15:33 1.289 +++ loncom/homework/structuretags.pm 2005/06/03 18:17:57 1.292 @@ -1,7 +1,7 @@ # The LearningOnline Network with CAPA # definition of tags that give a structure to a document # -# $Id: structuretags.pm,v 1.289 2005/04/22 17:15:33 albertel Exp $ +# $Id: structuretags.pm,v 1.292 2005/06/03 18:17:57 raeburn Exp $ # # Copyright Michigan State University Board of Trustees # @@ -68,6 +68,35 @@ sub end_tex { return ''; } +sub body_tag_start { + my ($target,$background,$bgcolor)=@_; + my $body_tag_start=''."\n"; + } + return $body_tag_start; +} + sub page_start { my ($target,$token,$tagstack,$parstack,$parser,$safeeval)=@_; my %found; @@ -93,35 +122,13 @@ sub page_start { $body_tag_start=&Apache::loncommon::bodytag(); $body_tag_start.=&Apache::lonxml::message_location(); } elsif (!defined($found{'body'})) { - $body_tag_start=''."\n"; - } - if ($target eq 'web' && $env{'request.state'} ne 'construct') { + my $bgcolor=&Apache::lonxml::get_param('bgcolor',$parstack, + $safeeval); + $body_tag_start=&body_tag_start($background,$bgcolor); + if ( ($target eq 'web' || $target eq 'webgrade') + && $env{'request.state'} ne 'construct') { my ($symb,undef,undef,undef,$publicuser)= &Apache::lonxml::whichuser(); if ($symb eq '' && !$publicuser) { @@ -365,16 +372,59 @@ sub store_aggregates { } if ($Apache::lonhomework::results{'resource.'.$part.'.tries'} == 1) { $aggregate{$symb."\0".$part."\0users"} = 1; + } else { + my $last_reset = &get_last_reset($symb,$cdomain,$cname,$part); + if ($last_reset) { + if (&get_num_tries($last_reset,$part) == 0) { + $aggregate{$symb."\0".$part."\0users"} = 1; + } + } } $aggregate{$symb."\0".$part."\0attempts"} = 1; } - if (%aggregate) { + if (keys (%aggregate) > 0) { &Apache::lonnet::cinc('nohist_resourcetracker',\%aggregate, - $cdomain,$cname); + $cdomain,$cname); + } +} +# ----------- Timestamp of last reset of aggregates +sub get_last_reset { + my ($symb,$cdomain,$cname,$part) =@_; + my $last_reset = ''; + my %resethash = &Apache::lonnet::restore($symb,'nohist_resourcetracker',$cdomain,$cname); + if ($resethash{'version'}) { + for (my $version=$resethash{'version'};$version>=1;$version--) { + if (exists($resethash{$version.':'.$part."\0".'prev_attempts'})) { + $last_reset = $resethash{$version.':timestamp'}; + last; + } + } } + return $last_reset; } +# ----------- Provides number of tries since last reset of aggregates +sub get_num_tries { + my ($last_reset,$part) = @_; + my $timestamp = ''; + my $num_tries = 0; + if ($Apache::lonhomework::history{'version'}) { + for (my $version=$Apache::lonhomework::history{'version'};$version>=1;$version--) { + if (exists($Apache::lonhomework::history{$version.':resource.'.$part.'.solved'})) { + $timestamp = $Apache::lonhomework::history{$version.':timestamp'}; + if ($timestamp > $last_reset) { + $num_tries ++; + } else { + last; + } + } + } + } + return $num_tries; +} + + sub checkout_msg { my %lt=&Apache::lonlocal::texthash( 'resource'=>'The resource needs to be checked out',