--- loncom/homework/grades.pm 2008/04/21 16:30:47 1.518
+++ loncom/homework/grades.pm 2008/12/24 06:31:41 1.542
@@ -1,7 +1,7 @@
# The LearningOnline Network with CAPA
# The LON-CAPA Grading handler
#
-# $Id: grades.pm,v 1.518 2008/04/21 16:30:47 raeburn Exp $
+# $Id: grades.pm,v 1.542 2008/12/24 06:31:41 raeburn Exp $
#
# Copyright Michigan State University Board of Trustees
#
@@ -26,6 +26,8 @@
# http://www.lon-capa.org/
#
+
+
package Apache::grades;
use strict;
use Apache::style;
@@ -58,46 +60,6 @@ my $ssi_error_resource;
my $ssi_error_message;
-# Do an ssi with retries:
-# While I'd love to factor out this with the vesrion in lonprintout,
-# that would either require a data coupling between modules, which I refuse to perpetuate
-# (there's quite enough of that already), or would require the invention of another infrastructure
-# I'm not quite ready to invent (e.g. an ssi_with_retry object).
-#
-# At least the logic that drives this has been pulled out into loncommon.
-
-
-#
-# ssi_with_retries - Does the server side include of a resource.
-# if the ssi call returns an error we'll retry it up to
-# the number of times requested by the caller.
-# If we still have a proble, no text is appended to the
-# output and we set some global variables.
-# to indicate to the caller an SSI error occurred.
-# All of this is supposed to deal with the issues described
-# in LonCAPA BZ 5631 see:
-# http://bugs.lon-capa.org/show_bug.cgi?id=5631
-# by informing the user that this happened.
-#
-# Parameters:
-# resource - The resource to include. This is passed directly, without
-# interpretation to lonnet::ssi.
-# form - The form hash parameters that guide the interpretation of the resource
-#
-# retries - Number of retries allowed before giving up completely.
-# Returns:
-# On success, returns the rendered resource identified by the resource parameter.
-# Side Effects:
-# The following global variables can be set:
-# ssi_error - If an unrecoverable error occurred this becomes true.
-# It is up to the caller to initialize this to false
-# if desired.
-# ssi_error_resource - If an unrecoverable error occurred, this is the value
-# of the resource that could not be rendered by the ssi
-# call.
-# ssi_error_message - The error string fetched from the ssi response
-# in the event of an error.
-#
sub ssi_with_retries {
my ($resource, $retries, %form) = @_;
my ($content, $response) = &Apache::loncommon::ssi_with_retries($resource, $retries, %form);
@@ -240,8 +202,8 @@ sub showResourceInfo {
my %resptype = ();
my $hdgrade='no';
my %partsseen;
- foreach my $partID (sort keys(%$responseType)) {
- foreach my $resID (sort keys(%{ $responseType->{$partID} })) {
+ foreach my $partID (sort(keys(%$responseType))) {
+ foreach my $resID (sort(keys(%{ $responseType->{$partID} }))) {
my $handgrade=$$handgrade{$partID.'_'.$resID};
my $responsetype = $responseType->{$partID}->{$resID};
$hdgrade = $handgrade if ($handgrade eq 'yes');
@@ -255,9 +217,9 @@ sub showResourceInfo {
$partsseen{$partID}=1;
}
my $display_part=&get_display_part($partID,$symb);
- $result.='
'.&mt('Part: [_1]',$display_part).' '.
- $resID.'
'.
- '
'.&mt('Type: [_1]',$responsetype).'
';
+ $result.='
'.&mt('Part').': '.$display_part.
+ ' '.$resID.'
'.
+ '
'.&mt('Type').': '.$responsetype.'
';
# '
'.&mt('Handgrade: [_1]',$handgrade).'
';
}
}
@@ -278,7 +240,7 @@ sub reset_caches {
}
sub get_analyze {
- my ($symb,$uname,$udom)=@_;
+ my ($symb,$uname,$udom,$no_increment)=@_;
my $key = "$symb\0$uname\0$udom";
return $analyze_cache{$key} if (exists($analyze_cache{$key}));
@@ -290,15 +252,16 @@ sub reset_caches {
'grade_symb' => $symb,
'grade_courseid' =>
$env{'request.course.id'},
- 'grade_username' => $uname));
+ 'grade_username' => $uname,
+ 'grade_noincrement' => $no_increment));
(undef,$subresult)=split(/_HASH_REF__/,$subresult,2);
my %analyze=&Apache::lonnet::str2hash($subresult);
return $analyze_cache{$key} = \%analyze;
}
sub get_order {
- my ($partid,$respid,$symb,$uname,$udom)=@_;
- my $analyze = &get_analyze($symb,$uname,$udom);
+ my ($partid,$respid,$symb,$uname,$udom,$no_increment)=@_;
+ my $analyze = &get_analyze($symb,$uname,$udom,$no_increment);
return $analyze->{"$partid.$respid.shown"};
}
@@ -816,20 +779,20 @@ sub listStudents {
my $getsec = $env{'form.section'} eq '' ? 'all' : $env{'form.section'};
my $getgroup = $env{'form.group'} eq '' ? 'all' : $env{'form.group'};
my $submitonly= $env{'form.submitonly'} eq '' ? 'all' : $env{'form.submitonly'};
- my $viewgrade = $env{'form.showgrading'} eq 'yes' ? 'View/Grade/Regrade' : 'View';
+ my $viewgrade = $env{'form.showgrading'} eq 'yes' ? &mt('View/Grade/Regrade') : &mt('View');
$env{'form.probTitle'} = $env{'form.probTitle'} eq '' ?
&Apache::lonnet::gettitle($symb) : $env{'form.probTitle'};
- my $result='
'.
- &mt($viewgrade.' Submissions for a Student or a Group of Students')
+ my $result='
'.$viewgrade.
+ &mt(' Submissions for a Student or a Group of Students')
.'
';
my ($table,undef,$hdgrade,$partlist,$handgrade) = &showResourceInfo($symb,$env{'form.probTitle'},($env{'form.showgrading'} eq 'yes'));
my %lt = ( 'multiple' =>
- "Please select a student or group of students before clicking on the Next button.",
+ &mt("Please select a student or group of students before clicking on the Next button."),
'single' =>
- "Please select the student before clicking on the Next button.",
+ &mt("Please select the student before clicking on the Next button."),
);
%lt = &Apache::lonlocal::texthash(%lt);
$request->print(<View Problem Text: [_1]',
+ ' '.&mt('View Problem Text').': '.
''."\n".
''."\n".
- '').' '."\n";
+ ' '."\n";
$gradeTable .=
- ' '.
- &mt('View Answer: [_1]',
+ ' '.&mt('View Answer').': '.
''."\n".
''."\n".
- '').' '."\n";
+ ' '."\n";
my $submission_options;
if ($env{'form.handgrade'} eq 'yes' && scalar(@$partlist) > 1) {
@@ -900,18 +861,16 @@ LISTJAVASCRIPT
''."\n".
'';
$gradeTable .=
- ' '.
- &mt('Submissions: [_1]',$submission_options).' '."\n";
+ ' '.&mt('Submissions').': '.$submission_options.' '."\n";
$gradeTable .=
- ' '.
- &mt('Grading Increments: [_1]',
+ ' '.&mt('Grading Increments').': '.
'');
+ '';
$gradeTable .=
&build_section_inputs().
@@ -930,15 +889,14 @@ LISTJAVASCRIPT
&Apache::lonhtmlcommon::StatusOptions($saveStatus,undef,1,'javascript:reLoadList(this.form);')).' ';
}
- $gradeTable.=&mt('To '.lc($viewgrade).' a submission or a group of submissions, click on the check box(es) '.
- 'next to the student\'s name(s). Then click on the Next button.').' '."\n".
+ $gradeTable.=&mt('To [_1] a submission or a group of submissions, click on the check box(es) next to the student\'s name(s). Then click on the Next button.',lc($viewgrade)).' '."\n".
''."\n";
# checkall buttons
$gradeTable.=&check_script('gradesub', 'stuinfo');
$gradeTable.=' '."\n";
+ 'value="'.&mt('Next').' →" /> '."\n";
$gradeTable.=&check_buttons();
$gradeTable.='';
my ($classlist, undef, $fullname) = &getclasslist($getsec,'1',$getgroup);
@@ -1030,7 +988,7 @@ LISTJAVASCRIPT
' '.$section.($group ne '' ?'/'.$group:'').''."\n";
if ($env{'form.showgrading'} eq 'yes' && $submitonly ne 'all') {
- foreach (sort keys(%status)) {
+ foreach (sort(keys(%status))) {
next if ($_ =~ /^resource.*?submitted_by$/);
$gradeTable.='
'.&mt($status{$_}).'
'."\n";
}
@@ -1058,7 +1016,7 @@ LISTJAVASCRIPT
$gradeTable.=&Apache::loncommon::end_data_table()."\n".
''."\n";
+ 'value="'.&mt('Next').' →" />'."\n";
if ($ctr == 0) {
my $num_students=(scalar(keys(%$fullname)));
if ($num_students eq 0) {
@@ -1154,6 +1112,7 @@ sub processGroup {
#--- Javascript to handle the submission page functionality ---
sub sub_page_js {
my $request = shift;
+ my $alertmsg = &mt('A number equal or greater than 0 is expected. Entered value = ');
$request->print(<
function updateRadio(formname,id,weight) {
@@ -1164,7 +1123,7 @@ sub sub_page_js {
gradeBox.value = pts;
var resetbox = false;
if (isNaN(pts) || pts < 0) {
- alert("A number equal or greater than 0 is expected. Entered value = "+pts);
+ alert("$alertmsg"+pts);
for (var i=0; iprint(<
@@ -1441,7 +1401,7 @@ INNERJS
else return;
var cleantxt = txt.replace(new RegExp('([\\f\\n\\r\\t\\v ])+', 'g')," ");
if (cleantxt=="") {
- alert("Please select a word or group of words from document and then click this link.");
+ alert("$alertmsg");
return;
}
var nret = prompt("Add selection to keyword list? Edit if desired.",cleantxt);
@@ -1680,7 +1640,7 @@ sub gradeBox {
my $radio.='
'."\n"; # display radio buttons in a nice table 10 across
while ($thisweight<=$wgt) {
- $radio.= '
Part: '.
$display_part.' ( ID '.$respid.
' ) '.
- ''.&mt('Nothing submitted - no attempts').'
';
+ ''.&mt('Nothing submitted - no attempts.').'
';
next;
}
foreach my $submission (@$string) {
@@ -2225,8 +2185,8 @@ KEYWORDS
$seen{$partid}++;
next if ($$handgrade{$part_resp} ne 'yes'
&& $env{'form.lastSub'} eq 'hdgrade');
- push @partlist,$partid;
- push @gradePartRespid,$partid.'.'.$respid;
+ push(@partlist,$partid);
+ push(@gradePartRespid,$partid.'.'.$respid);
$request->print(&gradeBox($request,$symb,$uname,$udom,$counter,$partid,\%record));
}
$request->print('');
@@ -2371,7 +2331,7 @@ sub get_last_submission {
}
if (!@string) {
$string[0] =
- 'Nothing submitted - no attempts.';
+ ''.&mt('Nothing submitted - no attempts.').'';
}
return (\@string,\$timestamp);
}
@@ -2553,7 +2513,7 @@ sub processHandGrade {
my (@parsedlist,@nextlist);
my ($nextflg) = 0;
- foreach (sort
+ foreach my $item (sort
{
if (lc($$fullname{$a}) ne lc($$fullname{$b})) {
return (lc($$fullname{$a}) cmp lc($$fullname{$b}));
@@ -2561,12 +2521,12 @@ sub processHandGrade {
return $a cmp $b;
} (keys(%$fullname))) {
if ($nextflg == 1 && $button =~ /Next$/) {
- push @parsedlist,$_;
+ push(@parsedlist,$item);
}
- $nextflg = 1 if ($_ eq $laststu);
+ $nextflg = 1 if ($item eq $laststu);
if ($button eq 'Previous') {
- last if ($_ eq $firststu);
- push @parsedlist,$_;
+ last if ($item eq $firststu);
+ push(@parsedlist,$item);
}
}
$ctr = 0;
@@ -2589,11 +2549,11 @@ sub processHandGrade {
my $submitted = 0;
my $ungraded = 0;
my $incorrect = 0;
- foreach (keys(%status)) {
- $submitted = 1 if ($status{$_} ne 'nothing');
- $ungraded = 1 if ($status{$_} =~ /^ungraded/);
- $incorrect = 1 if ($status{$_} =~ /^incorrect/);
- my ($foo,$partid,$foo1) = split(/\./,$_);
+ foreach my $item (keys(%status)) {
+ $submitted = 1 if ($status{$item} ne 'nothing');
+ $ungraded = 1 if ($status{$item} =~ /^ungraded/);
+ $incorrect = 1 if ($status{$item} =~ /^incorrect/);
+ my ($foo,$partid,$foo1) = split(/\./,$item);
if ($status{'resource.'.$partid.'.submitted_by'} ne '') {
$submitted = 0;
}
@@ -2604,7 +2564,7 @@ sub processHandGrade {
next if (!$ungraded && ($submitonly eq 'graded'));
next if (!$incorrect && $submitonly eq 'incorrect');
}
- push @nextlist,$student if ($ctr < $ntstu);
+ push(@nextlist,$student) if ($ctr < $ntstu);
last if ($ctr == $ntstu);
$ctr++;
}
@@ -2612,7 +2572,7 @@ sub processHandGrade {
$ctr = 0;
my $total = scalar(@nextlist)-1;
- foreach (sort @nextlist) {
+ foreach (sort(@nextlist)) {
my ($uname,$udom,$submitter) = split(/:/);
$env{'form.student'} = $uname;
$env{'form.userdom'} = $udom;
@@ -2658,7 +2618,7 @@ sub saveHandGrade {
}
} elsif ($dropMenu eq 'reset status'
&& exists($record{'resource.'.$new_part.'.solved'})) { #don't bother if no old records -> no attempts
- foreach my $key (keys (%record)) {
+ foreach my $key (keys(%record)) {
if ($key=~/^resource\.\Q$new_part\E\./) { $newrecord{$key} = ''; }
}
$newrecord{'resource.'.$new_part.'.regrader'}=
@@ -2693,7 +2653,7 @@ sub saveHandGrade {
&handback_files($request,$symb,$stuname,$domain,$newflg,$new_part,\%newrecord);
next;
} else {
- push @parts_graded, $new_part;
+ push(@parts_graded,$new_part);
}
if ($record{'resource.'.$new_part.'.awarded'} ne $partial) {
$newrecord{'resource.'.$new_part.'.awarded'} = $partial;
@@ -2720,7 +2680,7 @@ sub saveHandGrade {
$record{'resource.'.$new_part.'.solved'} eq 'incorrect_by_override' ||
$dropMenu eq 'reset status')
{
- push (@version_parts,$new_part);
+ push(@version_parts,$new_part);
}
}
my $cdom = $env{'course.'.$env{'request.course.id'}.'.domain'};
@@ -2795,8 +2755,10 @@ sub handback_files {
$newflg.'_'.$part_resp.'_returndoc'.$file_counter,
$save_file_name);
if ($result !~ m|^/uploaded/|) {
- $request->print('An error occurred ('.$result.
- ') while trying to upload '.$newflg.'_'.$part_resp.'_returndoc'.$file_counter.' ');
+ $request->print(' '.
+ &mt('An error occurred ([_1]) while trying to upload [_2].',
+ $result,$newflg.'_'.$part_resp.'_returndoc'.$file_counter).
+ '');
} else {
# mark the file as read only
my @files = ($save_file_name);
@@ -2893,7 +2855,7 @@ sub decrement_aggs {
if ($aggtries == $totaltries) {
$decrement{'users'} = 1;
}
- foreach my $type (keys (%decrement)) {
+ foreach my $type (keys(%decrement)) {
$$aggregate{$symb."\0".$part."\0".$type} = -$decrement{$type};
}
return;
@@ -3015,6 +2977,7 @@ sub file_name_version_ext {
sub viewgrades_js {
my ($request) = shift;
+ my $alertmsg = &mt('A number equal or greater than 0 is expected. Entered value = ');
$request->print(<
function writePoint(partid,weight,point) {
@@ -3023,7 +2986,7 @@ sub viewgrades_js {
if (point == "textval") {
point = document.classgrade["TEXTVAL_"+partid].value;
if (isNaN(point) || parseFloat(point) < 0) {
- alert("A number equal or greater than 0 is expected. Entered value = "+parseFloat(point));
+ alert("$alertmsg"+parseFloat(point));
var resetbox = false;
for (var i=0; i'.
- &mt("Assign Common Grade To $sectionClass",$section_display).'
';
+ &mt("Assign Common Grade to [_1]",$sectionClass,$section_display).'';
$result.= &Apache::loncommon::start_data_table();
#radio buttons/text box for assigning points for a section or class.
#handles different parts of a problem
@@ -3253,8 +3216,8 @@ sub viewgrades {
my $line = ' /'.
- $weight{$partid}.' (problem weight)'."\n";
- $line.= '