--- loncom/homework/structuretags.pm 2005/04/07 06:56:22 1.284 +++ loncom/homework/structuretags.pm 2005/04/29 21:22:33 1.291 @@ -1,7 +1,7 @@ # The LearningOnline Network with CAPA # definition of tags that give a structure to a document # -# $Id: structuretags.pm,v 1.284 2005/04/07 06:56:22 albertel Exp $ +# $Id: structuretags.pm,v 1.291 2005/04/29 21:22:33 albertel 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) { @@ -317,10 +324,11 @@ sub initialize_storage { # Stores away the result has to a student's environment # checks form.grade_ for specific values, other wises stores # to the running users environment +# Will increment totals for attempts, students, and corrects +# if running user has student role. sub finalize_storage { my $result; - my ($temp) = keys %Apache::lonhomework::results; - if ( $temp ne '' ) { + if (%Apache::lonhomework::results) { my ($symb,$courseid,$domain,$name) = &Apache::lonxml::whichuser(); if ($env{'request.state'} eq 'construct' || $symb eq '') { $Apache::lonhomework::results{'rndseed'}=$env{'form.rndseed'}; @@ -331,10 +339,48 @@ sub finalize_storage { $result=&Apache::lonnet::cstore(\%Apache::lonhomework::results, $symb,$courseid,$domain,$name); &Apache::lonxml::debug('Store return message:'.$result); + if ($env{'request.role'} =~/^st/) { + &store_aggregates($symb,$courseid); + } } } return $result; } +use Data::Dumper; + +# -------------------------------------------------------------store_aggregates +# Sends hash of values to be incremented in nohist_resourcetracker.db +# for the course. Increments total number of attempts, unique students +# and corrects for each part for an instance of a problem, as appropriate. +sub store_aggregates { + my ($symb,$courseid) = @_; + my %aggregate; + my @parts; + my $cdomain = $env{'course.'.$env{'request.course.id'}.'.domain'}; + my $cname = $env{'course.'.$env{'request.course.id'}.'.num'}; + foreach my $key (keys(%Apache::lonhomework::results)) { + if ($key =~ /resource\.([^\.]+)\.tries/) { + push(@parts, $1); + } + } + foreach my $part (@parts) { + if ($Apache::lonhomework::results{'resource.'.$part.'.award'} + eq 'APPROX_ANS' || + $Apache::lonhomework::results{'resource.'.$part.'.award'} + eq 'EXACT_ANS') { + $aggregate{$symb."\0".$part."\0correct"} = 1; + } + if ($Apache::lonhomework::results{'resource.'.$part.'.tries'} == 1) { + $aggregate{$symb."\0".$part."\0users"} = 1; + } + $aggregate{$symb."\0".$part."\0attempts"} = 1; + } + if (%aggregate) { + &Apache::lonnet::cinc('nohist_resourcetracker',\%aggregate, + $cdomain,$cname); + + } +} sub checkout_msg { my %lt=&Apache::lonlocal::texthash(