";
+ }
+ }
+ }
+ my $tries = $Apache::lonhomework::history{"$prefix.tries"};
+ my $maxtries = &Apache::lonnet::EXT("resource.$id.maxtries");
+ &Apache::lonxml::debug("got maxtries of :$maxtries:");
+ #if tries are set to negative turn off the Tries/Button and messages
+ if (defined($maxtries) && $maxtries < 0) { return ''; }
+ if ( $tries eq '' ) { $tries = '0'; }
+ if ( $maxtries eq '' ) { $maxtries = '2'; }
+ if ( $maxtries eq 'con_lost' ) { $maxtries = '0'; }
+ my $tries_text=&mt('Tries');
+ if ( $Apache::lonhomework::type eq 'survey' ||
+ $Apache::lonhomework::parsing_a_task) {
+ $tries_text=&mt('Submissions');
+ }
+
+ if ($showbutton) {
+ if ($target eq 'tex') {
+ if ($env{'request.state'} ne "construct"
+ && $Apache::lonhomework::type ne 'exam'
+ && $env{'form.suppress_tries'} ne 'yes') {
+ $trystr = ' {\vskip 1 mm \small \textit{'.$tries_text.'} '.
+ $tries.'/'.$maxtries.'} \vskip 2 mm ';
+ } else {
+ $trystr = '\vskip 0 mm ';
+ }
+ } else {
+ $trystr = "
".$tries_text." $tries";
+ if ($Apache::lonhomework::parsing_a_task) {
+ } elsif($env{'request.state'} ne 'construct') {
+ $trystr.="/$maxtries";
+ } else {
+ if (defined($Apache::inputtags::params{'maxtries'})) {
+ $trystr.="/".$Apache::inputtags::params{'maxtries'};
+ }
+ }
+ $trystr.="
";
+ }
+ }
+
+ if ($Apache::lonhomework::history{"$prefix.afterduedate"}) {
+ #last submissions was after due date
+ $latemessage=&mt(' The last submission was after the Due Date ');;
+ if ($target eq 'web') {
+ $latemessage='
'.$latemessage.'
';
+ }
+ }
+ return ($previousmsg,$latemessage,$message,$trystr,$showbutton);
+}
+
sub gradestatus {
- my ($id,$target) = @_;
+ my ($id,$target,$no_previous) = @_;
my $showbutton = 1;
- my $bgcolor = '';
my $message = '';
my $latemessage = '';
my $trystr='';
@@ -995,72 +1119,27 @@ sub gradestatus {
&& $status ne 'INVALID_ACCESS'
&& $status ne 'NEEDS_CHECKIN'
&& $status ne 'NOT_IN_A_SLOT') {
- my $award = $Apache::lonhomework::history{"resource.$id.award"};
- my $awarded = $Apache::lonhomework::history{"resource.$id.awarded"};
- my $solved = $Apache::lonhomework::history{"resource.$id.solved"};
- my $previous = $Apache::lonhomework::history{"resource.$id.previous"};
- my $awardmsg = $Apache::lonhomework::history{"resource.$id.awardmsg"};
- &Apache::lonxml::debug("Found Award |$award|$solved|$awardmsg");
- if ( $award ne '' || $solved ne '' || $status eq 'SHOW_ANSWER') {
- &Apache::lonxml::debug('Getting message');
- ($showbutton,$bgcolor,$message,$previousmsg) =
- &decideoutput($award,$awarded,$awardmsg,$solved,$previous,
- $target);
- if ($target eq 'tex') {
- $message='\vskip 2 mm '.$message.' ';
- } else {
- $message="
$message
";
- if ($previousmsg) {
- $previousmsg="
$previousmsg
";
- }
- }
- }
- my $tries = $Apache::lonhomework::history{"resource.$id.tries"};
- my $maxtries = &Apache::lonnet::EXT("resource.$id.maxtries");
- &Apache::lonxml::debug("got maxtries of :$maxtries:");
- #if tries are set to negative turn off the Tries/Button and messages
- if (defined($maxtries) && $maxtries < 0) { return ''; }
- if ( $tries eq '' ) { $tries = '0'; }
- if ( $maxtries eq '' ) { $maxtries = '2'; }
- if ( $maxtries eq 'con_lost' ) { $maxtries = '0'; }
- my $tries_text=&mt('Tries');
- if ( $Apache::lonhomework::type eq 'survey' ||
- $Apache::lonhomework::parsing_a_task) {
- $tries_text=&mt('Submissions');
+
+ ($previousmsg,$latemessage,$message,$trystr) =
+ &get_grade_messages($id,"resource.$id",$target,$status,
+ $showbutton);
+ if ( $status eq 'SHOW_ANSWER' || $status eq 'CANNOT_ANSWER') {
+ $showbutton = 0;
}
- if ( $showbutton ) {
- if ($target eq 'tex') {
- if ($env{'request.state'} ne "construct" && $Apache::lonhomework::type ne 'exam' && $env{'form.suppress_tries'} ne 'yes') {
- $trystr = ' {\vskip 1 mm \small \textit{'.$tries_text.'} '.$tries.'/'.$maxtries.'} \vskip 2 mm ';
- } else {
- $trystr = '\vskip 0 mm ';
- }
- } else {
- $trystr = "
".$tries_text." $tries";
- if ($Apache::lonhomework::parsing_a_task) {
- } elsif($env{'request.state'} ne 'construct') {
- $trystr.="/$maxtries";
- } else {
- if (defined($Apache::inputtags::params{'maxtries'})) {
- $trystr.="/".$Apache::inputtags::params{'maxtries'};
- }
- }
- $trystr.="
";
- }
+ if ( $status eq 'SHOW_ANSWER') {
+ undef($previousmsg);
}
- if ( $status eq 'SHOW_ANSWER' || $status eq 'CANNOT_ANSWER') {$showbutton = 0;}
if ( $showbutton ) {
if ($target ne 'tex') {
- $button = '';
- }
- }
- if ($Apache::lonhomework::history{"resource.$id.afterduedate"}) {
- #last submissions was after due date
- $latemessage=&mt(' The last submission was after the Due Date ');;
- if ($target eq 'web') {
- $latemessage='
'.$latemessage.'
';
+ $button =
+ '';
}
}
+
}
my $output= $previousmsg.$latemessage.$message.$trystr;
if ($output =~ /^\s*$/) {
@@ -1069,10 +1148,112 @@ sub gradestatus {
if ($target eq 'tex') {
return $button.' \vskip 0 mm '.$output.' ';
} else {
- return '
'.$button.'
'.$output.'
';
+ $output =
+ '
'.$button.'
'.$output;
+ if (!$no_previous) {
+ $output.='
'.&previous_tries($id,$target).'
';
+ }
+ $output.= '
';
+ return $output;
}
}
}
+
+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) =
+ &get_grade_messages($id,"$prefix",$target,$status);
+
+ if ($previousmsg ne '') {
+ my ($match,$which) = &find_which_previous($i);
+ $message=$previousmsg;
+ my $previous = $count_lookup{$which};
+ $message =~ s{()}{ as submission \# $previous $1};
+ } elsif ($Apache::lonhomework::history{"$prefix.tries"}) {
+ if (!(lc($Apache::lonhomework::problemstatus) eq 'no'
+ && $Apache::inputtags::status[-1] ne 'SHOW_ANSWER')
+ && $Apache::lonhomework::history{"$prefix.solved"} =~/^correct/
+ ) {
+
+ $message =~ s{()(.*?)()}
+ {$1 Correct. $3}s;
+ }
+ my $trystr = "(Try ".
+ $Apache::lonhomework::history{"$prefix.tries"}.')';
+ $message =~ s{()}{ $trystr $1};
+ }
+ my ($class) = ($message =~ m{)}{
};
+
+
+ $output.='
';
+ $output.='
'.$count.'
';
+ $output.=$message;
+
+ foreach my $resid (@Apache::inputtags::response) {
+ my $prefix = $prefix.".$resid";
+ if (exists($Apache::lonhomework::history{"$prefix.submission"})) {
+ my $submission =
+ $Apache::inputtags::submission_display{"$prefix.submission"};
+ if (!defined($submission)) {
+ $submission =
+ $Apache::lonhomework::history{"$prefix.submission"};
+ }
+ $output.='