--- loncom/homework/inputtags.pm 2007/03/13 00:21:28 1.218 +++ loncom/homework/inputtags.pm 2007/03/15 02:52:16 1.219 @@ -1,7 +1,7 @@ # The LearningOnline Network with CAPA # input definitons # -# $Id: inputtags.pm,v 1.218 2007/03/13 00:21:28 albertel Exp $ +# $Id: inputtags.pm,v 1.219 2007/03/15 02:52:16 albertel Exp $ # # Copyright Michigan State University Board of Trustees # @@ -957,6 +957,42 @@ sub setgradedata { } } +sub find_which_previous { + my ($version) = @_; + my $part = $Apache::inputtags::part; + my (@previous_version); + foreach my $resp (@Apache::inputtags::response) { + my $key = "$version:resource.$part.$resp.submission"; + my $submission = $Apache::lonhomework::history{$key}; + my %previous = &Apache::response::check_for_previous($submission, + $part,$resp, + $version); + push(@previous_version,$previous{'version'}); + } + return &previous_match(\@previous_version, + scalar(@Apache::inputtags::response)); +} + +sub previous_match { + my ($previous_array,$count) = @_; + my $match = 0; + my @matches; + foreach my $versionar (@$previous_array) { + foreach my $version (@$versionar) { + $matches[$version]++; + } + } + my $which=0; + foreach my $elem (@matches) { + if ($elem eq $count) { + $match=1; + last; + } + $which++; + } + return ($match,$which); +} + sub grade { my ($target) = @_; my $id = $Apache::inputtags::part; @@ -975,14 +1011,10 @@ sub grade { my ($finalaward,$msg) = &finalizeawards(\@awards,\@msgs); my $previously_used; if ( $#Apache::inputtags::previous eq $#awards ) { - my $match=0; - my @matches; - foreach my $versionar (@Apache::inputtags::previous_version) { - foreach my $version (@$versionar) { - $matches[$version]++; - } - } - foreach my $elem (@matches) {if ($elem eq ($#awards+1)) {$match=1;}} + my ($match) = + &previous_match(\@Apache::inputtags::previous_version, + scalar(@Apache::inputtags::response)); + if ($match) { $previously_used = 'PREVIOUSLY_LAST'; foreach my $value (@Apache::inputtags::previous) { @@ -1121,11 +1153,17 @@ sub previous_tries { my ($id,$target) = @_; my $output; my $status = $Apache::inputtags::status['-1']; - + + my $count; + my %count_lookup; + foreach my $i (1..$Apache::lonhomework::history{'version'}) { my $prefix = $i.":resource.$id"; next if (!exists($Apache::lonhomework::history{"$prefix.award"})); + $count++; + $count_lookup{$i} = $count; + my ($previousmsg,$latemessage,$message,$trystr); ($previousmsg,$latemessage,$message,$trystr) = @@ -1134,11 +1172,21 @@ sub previous_tries { undef($trystr); } - if ($previousmsg eq '') { $previousmsg=''; } - if ($trystr eq '') { $trystr = ''; } + if ($previousmsg ne '') { + my ($match,$which) = &find_which_previous($i); + $message=$previousmsg; + my $previous = $count_lookup{$which}; + $message =~ s{()}{ as submission $previous $1}; + + } elsif ($trystr ne '') { + ($trystr) = ($trystr =~ m{(\d+)/\d+}); + $message =~ s{()}{$1 $trystr }; + } + $output.=''; - $output.=$message.$previousmsg.$trystr; + $output.=''.$count.''; + $output.=$message; foreach my $resid (@Apache::inputtags::response) { my $prefix = $prefix.".$resid"; @@ -1154,11 +1202,15 @@ sub previous_tries { $output.=''; } } - $output.=''; + $output.=''."\n"; } return if ($output eq ''); - - $output =''.$output.'
'; + my $headers = + ''.''.&mt('Submission #').''.&mt('Try'). + ''. + &mt('Submitted Answer').''; + $output =''.$headers.$output.'
'; + $output .='
'.join("\n",@Apache::inputtags::previous_version).'
'; #return $output; $output=~s/\\/\\\\/g; $output=~s/\'/\\\'/g;