'.$rendered.' ';
@@ -1381,41 +1461,41 @@ sub show_problem {
sub submission {
my ($request,$counter,$total) = @_;
- (my $url=$ENV{'form.url'})=~s-^http://($ENV{'SERVER_NAME'}|$ENV{'HTTP_HOST'})--;
- my ($uname,$udom) = ($ENV{'form.student'},$ENV{'form.userdom'});
- $udom = ($udom eq '' ? $ENV{'user.domain'} : $udom); #has form.userdom changed for a student?
- my $usec = &Apache::lonnet::getsection($udom,$uname,$ENV{'request.course.id'});
- $ENV{'form.fullname'} = &Apache::loncommon::plainname($uname,$udom,'lastname') if $ENV{'form.fullname'} eq '';
+ (my $url=$env{'form.url'})=~s-^http://($ENV{'SERVER_NAME'}|$ENV{'HTTP_HOST'})--;
+ my ($uname,$udom) = ($env{'form.student'},$env{'form.userdom'});
+ $udom = ($udom eq '' ? $env{'user.domain'} : $udom); #has form.userdom changed for a student?
+ my $usec = &Apache::lonnet::getsection($udom,$uname,$env{'request.course.id'});
+ $env{'form.fullname'} = &Apache::loncommon::plainname($uname,$udom,'lastname') if $env{'form.fullname'} eq '';
- my $symb=($ENV{'form.symb'} ne '' ? $ENV{'form.symb'} : (&Apache::lonnet::symbread($url)));
+ my $symb=($env{'form.symb'} ne '' ? $env{'form.symb'} : (&Apache::lonnet::symbread($url)));
if ($symb eq '') { $request->print("Unable to handle ambiguous references:$url:."); return ''; }
if (!&canview($usec)) {
$request->print('Unable to view requested student.('.
$uname.'@'.$udom.' in section '.$usec.' in course id '.
- $ENV{'request.course.id'}.') ');
+ $env{'request.course.id'}.')');
$request->print(&show_grading_menu_form($symb,$url));
return;
}
- if (!$ENV{'form.lastSub'}) { $ENV{'form.lastSub'} = 'datesub'; }
- if (!$ENV{'form.vProb'}) { $ENV{'form.vProb'} = 'yes'; }
- if (!$ENV{'form.vAns'}) { $ENV{'form.vAns'} = 'yes'; }
- my $last = ($ENV{'form.lastSub'} eq 'last' ? 'last' : '');
+ if (!$env{'form.lastSub'}) { $env{'form.lastSub'} = 'datesub'; }
+ if (!$env{'form.vProb'}) { $env{'form.vProb'} = 'yes'; }
+ if (!$env{'form.vAns'}) { $env{'form.vAns'} = 'yes'; }
+ my $last = ($env{'form.lastSub'} eq 'last' ? 'last' : '');
my $checkIcon = ' ';
# header info
if ($counter == 0) {
&sub_page_js($request);
- &sub_page_kw_js($request) if ($ENV{'form.handgrade'} eq 'yes');
- $ENV{'form.probTitle'} = $ENV{'form.probTitle'} eq '' ?
- &Apache::lonnet::gettitle($symb) : $ENV{'form.probTitle'};
+ &sub_page_kw_js($request) if ($env{'form.handgrade'} eq 'yes');
+ $env{'form.probTitle'} = $env{'form.probTitle'} eq '' ?
+ &Apache::lonnet::gettitle($symb) : $env{'form.probTitle'};
$request->print(' Submission Record '."\n".
- ' Resource: '.$ENV{'form.probTitle'}.' '."\n");
+ ' Resource: '.$env{'form.probTitle'}.' '."\n");
- if ($ENV{'form.handgrade'} eq 'no') {
+ if ($env{'form.handgrade'} eq 'no') {
my $checkMark=' Note: Part(s) graded correct by the computer is marked with a '.
$checkIcon.' symbol.'."\n";
$request->print($checkMark);
@@ -1423,13 +1503,13 @@ sub submission {
# option to display problem, only once else it cause problems
# with the form later since the problem has a form.
- if ($ENV{'form.vProb'} eq 'yes' or $ENV{'form.vAns'} eq 'yes') {
+ if ($env{'form.vProb'} eq 'yes' or $env{'form.vAns'} eq 'yes') {
my $mode;
- if ($ENV{'form.vProb'} eq 'yes' && $ENV{'form.vAns'} eq 'yes') {
+ if ($env{'form.vProb'} eq 'yes' && $env{'form.vAns'} eq 'yes') {
$mode='both';
- } elsif ($ENV{'form.vProb'} eq 'yes') {
+ } elsif ($env{'form.vProb'} eq 'yes') {
$mode='text';
- } elsif ($ENV{'form.vAns'} eq 'yes') {
+ } elsif ($env{'form.vAns'} eq 'yes') {
$mode='answer';
}
$request->print(&show_problem($request,$symb,$uname,$udom,0,1,$mode));
@@ -1438,60 +1518,60 @@ sub submission {
# kwclr is the only variable that is guaranteed to be non blank
# if this subroutine has been called once.
my %keyhash = ();
- if ($ENV{'form.kwclr'} eq '' && $ENV{'form.handgrade'} eq 'yes') {
+ if ($env{'form.kwclr'} eq '' && $env{'form.handgrade'} eq 'yes') {
%keyhash = &Apache::lonnet::dump('nohist_handgrade',
- $ENV{'course.'.$ENV{'request.course.id'}.'.domain'},
- $ENV{'course.'.$ENV{'request.course.id'}.'.num'});
+ $env{'course.'.$env{'request.course.id'}.'.domain'},
+ $env{'course.'.$env{'request.course.id'}.'.num'});
- my $loginuser = $ENV{'user.name'}.':'.$ENV{'user.domain'};
- $ENV{'form.keywords'} = $keyhash{$symb.'_keywords'} ne '' ? $keyhash{$symb.'_keywords'} : '';
- $ENV{'form.kwclr'} = $keyhash{$loginuser.'_kwclr'} ne '' ? $keyhash{$loginuser.'_kwclr'} : 'red';
- $ENV{'form.kwsize'} = $keyhash{$loginuser.'_kwsize'} ne '' ? $keyhash{$loginuser.'_kwsize'} : '0';
- $ENV{'form.kwstyle'} = $keyhash{$loginuser.'_kwstyle'} ne '' ? $keyhash{$loginuser.'_kwstyle'} : '';
- $ENV{'form.msgsub'} = $keyhash{$symb.'_subject'} ne '' ?
- $keyhash{$symb.'_subject'} : $ENV{'form.probTitle'};
- $ENV{'form.savemsgN'} = $keyhash{$symb.'_savemsgN'} ne '' ? $keyhash{$symb.'_savemsgN'} : '0';
+ my $loginuser = $env{'user.name'}.':'.$env{'user.domain'};
+ $env{'form.keywords'} = $keyhash{$symb.'_keywords'} ne '' ? $keyhash{$symb.'_keywords'} : '';
+ $env{'form.kwclr'} = $keyhash{$loginuser.'_kwclr'} ne '' ? $keyhash{$loginuser.'_kwclr'} : 'red';
+ $env{'form.kwsize'} = $keyhash{$loginuser.'_kwsize'} ne '' ? $keyhash{$loginuser.'_kwsize'} : '0';
+ $env{'form.kwstyle'} = $keyhash{$loginuser.'_kwstyle'} ne '' ? $keyhash{$loginuser.'_kwstyle'} : '';
+ $env{'form.msgsub'} = $keyhash{$symb.'_subject'} ne '' ?
+ $keyhash{$symb.'_subject'} : $env{'form.probTitle'};
+ $env{'form.savemsgN'} = $keyhash{$symb.'_savemsgN'} ne '' ? $keyhash{$symb.'_savemsgN'} : '0';
}
- my $overRideScore = $ENV{'form.overRideScore'} eq '' ? 'no' : $ENV{'form.overRideScore'};
+ my $overRideScore = $env{'form.overRideScore'} eq '' ? 'no' : $env{'form.overRideScore'};
$request->print(''.&show_grading_menu_form($symb,$url)
}
$request->print($toGrade);
@@ -1722,8 +1810,8 @@ KEYWORDS
}
# essay grading message center
- if ($ENV{'form.handgrade'} eq 'yes') {
- my ($lastname,$givenn) = split(/,/,$ENV{'form.fullname'});
+ if ($env{'form.handgrade'} eq 'yes') {
+ my ($lastname,$givenn) = split(/,/,$env{'form.fullname'});
my $msgfor = $givenn.' '.$lastname;
if (scalar(@col_fullnames) > 0) {
my $lastone = pop @col_fullnames;
@@ -1738,7 +1826,7 @@ KEYWORDS
' '."\n".
' (Message will be sent when you click on Save & Next below.)'."\n"
- if ($ENV{'form.handgrade'} eq 'yes');
+ if ($env{'form.handgrade'} eq 'yes');
$request->print($result);
}
@@ -1749,7 +1837,7 @@ KEYWORDS
my ($partid,$respid) = split(/_/);
next if ($seen{$partid} > 0);
$seen{$partid}++;
- next if ($$handgrade{$_} =~ /:no$/ && $ENV{'form.lastSub'} =~ /^(hdgrade)$/);
+ next if ($$handgrade{$_} =~ /:no$/ && $env{'form.lastSub'} =~ /^(hdgrade)$/);
push @partlist,$partid;
push @gradePartRespid,$partid.'.'.$respid;
@@ -1777,7 +1865,7 @@ KEYWORDS
'1 2 '.
'3 5 '.
'7 10 '."\n";
- my $nsel = ($ENV{'form.NTSTU'} ne '' ? $ENV{'form.NTSTU'} : '1');
+ my $nsel = ($env{'form.NTSTU'} ne '' ? $env{'form.NTSTU'} : '1');
$ntstu =~ s/$nsel $nsel;
$endform.=$ntstu.'student(s) ';
$endform.=' $styleon$_$styleoff<\/font>/gi;
+ $string =~ s/\b\Q$_\E(\b|\.)/$styleon$_$styleoff<\/font>/gi;
}
return $string;
}
@@ -1834,15 +1922,15 @@ sub keywords_highlight {
#--- Called from submission routine
sub processHandGrade {
my ($request) = shift;
- my $url = $ENV{'form.url'};
- my $symb = $ENV{'form.symb'};
- my $button = $ENV{'form.gradeOpt'};
- my $ngrade = $ENV{'form.NCT'};
- my $ntstu = $ENV{'form.NTSTU'};
+ my $url = $env{'form.url'};
+ my $symb = $env{'form.symb'};
+ my $button = $env{'form.gradeOpt'};
+ my $ngrade = $env{'form.NCT'};
+ my $ntstu = $env{'form.NTSTU'};
if ($button eq 'Save & Next') {
my $ctr = 0;
while ($ctr < $ngrade) {
- my ($uname,$udom) = split(/:/,$ENV{'form.unamedom'.$ctr});
+ my ($uname,$udom) = split(/:/,$env{'form.unamedom'.$ctr});
my ($errorflag,$pts,$wgt) = &saveHandGrade($request,$url,$symb,$uname,$udom,$ctr);
if ($errorflag eq 'no_score') {
$ctr++;
@@ -1853,36 +1941,36 @@ sub processHandGrade {
$ctr++;
next;
}
- my $includemsg = $ENV{'form.includemsg'.$ctr};
+ my $includemsg = $env{'form.includemsg'.$ctr};
my ($subject,$message,$msgstatus) = ('','','');
if ($includemsg =~ /savemsg|newmsg\Q$ctr\E/) {
- $subject = $ENV{'form.msgsub'} if ($includemsg =~ /^msgsub/);
+ $subject = $env{'form.msgsub'} if ($includemsg =~ /^msgsub/);
my (@msgnum) = split(/,/,$includemsg);
foreach (@msgnum) {
- $message.=$ENV{'form.'.$_} if ($_ =~ /savemsg|newmsg/ && $_ ne '');
+ $message.=$env{'form.'.$_} if ($_ =~ /savemsg|newmsg/ && $_ ne '');
}
$message =&Apache::lonfeedback::clear_out_html($message);
$message.="\n\nPoint".($pts > 1 ? 's':'').' awarded = '.$pts.' out of '.$wgt;
$message.=" for $ENV{'form.probTitle'} ";
+ "?symb=$symb\">$env{'form.probTitle'}";
$msgstatus = &Apache::lonmsg::user_normal_msg ($uname,$udom,
- $ENV{'form.msgsub'},$message);
+ $env{'form.msgsub'},$message);
}
- if ($ENV{'form.collaborator'.$ctr}) {
+ if ($env{'form.collaborator'.$ctr}) {
my @collabstrs=&Apache::loncommon::get_env_multiple("form.collaborator$ctr");
foreach my $collabstr (@collabstrs) {
my ($part,@collaborators) = split(/:/,$collabstr);
foreach (@collaborators) {
my ($errorflag,$pts,$wgt) =
&saveHandGrade($request,$url,$symb,$_,$udom,$ctr,
- $ENV{'form.unamedom'.$ctr},$part);
+ $env{'form.unamedom'.$ctr},$part);
if ($errorflag eq 'not_allowed') {
$request->print("Not allowed to modify grades for $_:$udom ");
next;
} else {
if ($message ne '') {
- $msgstatus = &Apache::lonmsg::user_normal_msg($_,$udom,$ENV{'form.msgsub'},$message);
+ $msgstatus = &Apache::lonmsg::user_normal_msg($_,$udom,$env{'form.msgsub'},$message);
}
}
@@ -1893,61 +1981,61 @@ sub processHandGrade {
}
}
- if ($ENV{'form.handgrade'} eq 'yes') {
+ if ($env{'form.handgrade'} eq 'yes') {
# Keywords sorted in alphabatical order
- my $loginuser = $ENV{'user.name'}.':'.$ENV{'user.domain'};
+ my $loginuser = $env{'user.name'}.':'.$env{'user.domain'};
my %keyhash = ();
- $ENV{'form.keywords'} =~ s/,\s{0,}|\s+/ /g;
- $ENV{'form.keywords'} =~ s/^\s+|\s+$//;
- my (@keywords) = sort(split(/\s+/,$ENV{'form.keywords'}));
- $ENV{'form.keywords'} = join(' ',@keywords);
- $keyhash{$symb.'_keywords'} = $ENV{'form.keywords'};
- $keyhash{$symb.'_subject'} = $ENV{'form.msgsub'};
- $keyhash{$loginuser.'_kwclr'} = $ENV{'form.kwclr'};
- $keyhash{$loginuser.'_kwsize'} = $ENV{'form.kwsize'};
- $keyhash{$loginuser.'_kwstyle'} = $ENV{'form.kwstyle'};
+ $env{'form.keywords'} =~ s/,\s{0,}|\s+/ /g;
+ $env{'form.keywords'} =~ s/^\s+|\s+$//;
+ my (@keywords) = sort(split(/\s+/,$env{'form.keywords'}));
+ $env{'form.keywords'} = join(' ',@keywords);
+ $keyhash{$symb.'_keywords'} = $env{'form.keywords'};
+ $keyhash{$symb.'_subject'} = $env{'form.msgsub'};
+ $keyhash{$loginuser.'_kwclr'} = $env{'form.kwclr'};
+ $keyhash{$loginuser.'_kwsize'} = $env{'form.kwsize'};
+ $keyhash{$loginuser.'_kwstyle'} = $env{'form.kwstyle'};
# message center - Order of message gets changed. Blank line is eliminated.
- # New messages are saved in ENV for the next student.
+ # New messages are saved in env for the next student.
# All messages are saved in nohist_handgrade.db
my ($ctr,$idx) = (1,1);
- while ($ctr <= $ENV{'form.savemsgN'}) {
- if ($ENV{'form.savemsg'.$ctr} ne '') {
- $keyhash{$symb.'_savemsg'.$idx} = $ENV{'form.savemsg'.$ctr};
+ while ($ctr <= $env{'form.savemsgN'}) {
+ if ($env{'form.savemsg'.$ctr} ne '') {
+ $keyhash{$symb.'_savemsg'.$idx} = $env{'form.savemsg'.$ctr};
$idx++;
}
$ctr++;
}
$ctr = 0;
while ($ctr < $ngrade) {
- if ($ENV{'form.newmsg'.$ctr} ne '') {
- $keyhash{$symb.'_savemsg'.$idx} = $ENV{'form.newmsg'.$ctr};
- $ENV{'form.savemsg'.$idx} = $ENV{'form.newmsg'.$ctr};
+ if ($env{'form.newmsg'.$ctr} ne '') {
+ $keyhash{$symb.'_savemsg'.$idx} = $env{'form.newmsg'.$ctr};
+ $env{'form.savemsg'.$idx} = $env{'form.newmsg'.$ctr};
$idx++;
}
$ctr++;
}
- $ENV{'form.savemsgN'} = --$idx;
- $keyhash{$symb.'_savemsgN'} = $ENV{'form.savemsgN'};
+ $env{'form.savemsgN'} = --$idx;
+ $keyhash{$symb.'_savemsgN'} = $env{'form.savemsgN'};
my $putresult = &Apache::lonnet::put
('nohist_handgrade',\%keyhash,
- $ENV{'course.'.$ENV{'request.course.id'}.'.domain'},
- $ENV{'course.'.$ENV{'request.course.id'}.'.num'});
+ $env{'course.'.$env{'request.course.id'}.'.domain'},
+ $env{'course.'.$env{'request.course.id'}.'.num'});
}
# Called by Save & Refresh from Highlight Attribute Window
- my (undef,undef,$fullname) = &getclasslist($ENV{'form.section'},'1');
- if ($ENV{'form.refresh'} eq 'on') {
+ my (undef,undef,$fullname) = &getclasslist($env{'form.section'},'1');
+ if ($env{'form.refresh'} eq 'on') {
my ($ctr,$total) = (0,0);
while ($ctr < $ngrade) {
- $total++ if $ENV{'form.unamedom'.$ctr} ne '';
+ $total++ if $env{'form.unamedom'.$ctr} ne '';
$ctr++;
}
- $ENV{'form.NTSTU'}=$ngrade;
+ $env{'form.NTSTU'}=$ngrade;
$ctr = 0;
while ($ctr < $total) {
- my $processUser = $ENV{'form.unamedom'.$ctr};
- ($ENV{'form.student'},$ENV{'form.userdom'}) = split(/:/,$processUser);
- $ENV{'form.fullname'} = $$fullname{$processUser};
+ my $processUser = $env{'form.unamedom'.$ctr};
+ ($env{'form.student'},$env{'form.userdom'}) = split(/:/,$processUser);
+ $env{'form.fullname'} = $$fullname{$processUser};
&submission($request,$ctr,$total-1);
$ctr++;
}
@@ -1956,20 +2044,20 @@ sub processHandGrade {
# Go directly to grade student - from submission or link from chart page
if ($button eq 'Grade Student') {
- (undef,undef,$ENV{'form.handgrade'},undef,undef) = &showResourceInfo($url);
- my $processUser = $ENV{'form.unamedom'.$ENV{'form.studentNo'}};
- ($ENV{'form.student'},$ENV{'form.userdom'}) = split(/:/,$processUser);
- $ENV{'form.fullname'} = $$fullname{$processUser};
+ (undef,undef,$env{'form.handgrade'},undef,undef) = &showResourceInfo($url);
+ my $processUser = $env{'form.unamedom'.$env{'form.studentNo'}};
+ ($env{'form.student'},$env{'form.userdom'}) = split(/:/,$processUser);
+ $env{'form.fullname'} = $$fullname{$processUser};
&submission($request,0,0);
return '';
}
# Get the next/previous one or group of students
- my $firststu = $ENV{'form.unamedom0'};
- my $laststu = $ENV{'form.unamedom'.($ngrade-1)};
+ my $firststu = $env{'form.unamedom0'};
+ my $laststu = $env{'form.unamedom'.($ngrade-1)};
my $ctr = 2;
while ($laststu eq '') {
- $laststu = $ENV{'form.unamedom'.($ngrade-$ctr)};
+ $laststu = $env{'form.unamedom'.($ngrade-$ctr)};
$ctr++;
$laststu = $firststu if ($ctr > $ngrade);
}
@@ -1990,16 +2078,18 @@ sub processHandGrade {
@parsedlist = reverse @parsedlist if ($button eq 'Previous');
my ($partlist) = &response_type($url);
foreach my $student (@parsedlist) {
- my $submitonly=$ENV{'form.submitonly'};
+ my $submitonly=$env{'form.submitonly'};
my ($uname,$udom) = split(/:/,$student);
if ($submitonly =~ /^(yes|graded|incorrect)$/) {
-# my %record = &Apache::lonnet::restore($symb,$ENV{'request.course.id'},$udom,$uname);
+# my %record = &Apache::lonnet::restore($symb,$env{'request.course.id'},$udom,$uname);
my %status=&student_gradeStatus($url,$symb,$udom,$uname,$partlist);
my $submitted = 0;
- my $graded = 1;
+ my $ungraded = 0;
+ my $incorrect = 0;
foreach (keys(%status)) {
$submitted = 1 if ($status{$_} ne 'nothing');
- $graded = 0 if ($status{$_} =~ /^correct/);
+ $ungraded = 1 if ($status{$_} =~ /^ungraded/);
+ $incorrect = 1 if ($status{$_} =~ /^incorrect/);
my ($foo,$partid,$foo1) = split(/\./,$_);
if ($status{'resource.'.$partid.'.submitted_by'} ne '') {
$submitted = 0;
@@ -2008,8 +2098,8 @@ sub processHandGrade {
next if (!$submitted && ($submitonly eq 'yes' ||
$submitonly eq 'incorrect' ||
$submitonly eq 'graded'));
- next if (!$graded && ($submitonly eq 'graded' ||
- $submitonly eq 'incorrect'));
+ next if (!$ungraded && ($submitonly eq 'graded'));
+ next if (!$incorrect && $submitonly eq 'incorrect');
}
push @nextlist,$student if ($ctr < $ntstu);
last if ($ctr == $ntstu);
@@ -2021,9 +2111,9 @@ sub processHandGrade {
foreach (sort @nextlist) {
my ($uname,$udom,$submitter) = split(/:/);
- $ENV{'form.student'} = $uname;
- $ENV{'form.userdom'} = $udom;
- $ENV{'form.fullname'} = $$fullname{$_};
+ $env{'form.student'} = $uname;
+ $env{'form.userdom'} = $udom;
+ $env{'form.fullname'} = $$fullname{$_};
&submission($request,$ctr,$total);
$ctr++;
}
@@ -2040,49 +2130,70 @@ sub processHandGrade {
#---- Save the score and award for each student, if changed
sub saveHandGrade {
my ($request,$url,$symb,$stuname,$domain,$newflg,$submitter,$part) = @_;
+ my @v_flag;
my $usec = &Apache::lonnet::getsection($domain,$stuname,
- $ENV{'request.course.id'});
+ $env{'request.course.id'});
if (!&canmodify($usec)) { return('not_allowed'); }
- my %record = &Apache::lonnet::restore($symb,$ENV{'request.course.id'},$domain,$stuname);
+ my %record = &Apache::lonnet::restore($symb,$env{'request.course.id'},$domain,$stuname);
+ my @parts_graded;
my %newrecord = ();
my ($pts,$wgt) = ('','');
- foreach (split(/:/,$ENV{'form.partlist'.$newflg})) {
+ my %aggregate = ();
+ my $aggregateflag = 0;
+ foreach my $new_part (split(/:/,$env{'form.partlist'.$newflg})) {
#collaborator may vary for different parts
- if ($submitter && $_ ne $part) { next; }
- my $dropMenu = $ENV{'form.GD_SEL'.$newflg.'_'.$_};
+ if ($submitter && $new_part ne $part) { next; }
+ my $dropMenu = $env{'form.GD_SEL'.$newflg.'_'.$new_part};
if ($dropMenu eq 'excused') {
- if ($record{'resource.'.$_.'.solved'} ne 'excused') {
- $newrecord{'resource.'.$_.'.solved'} = 'excused';
- if (exists($record{'resource.'.$_.'.awarded'})) {
- $newrecord{'resource.'.$_.'.awarded'} = '';
+ if ($record{'resource.'.$new_part.'.solved'} ne 'excused') {
+ $newrecord{'resource.'.$new_part.'.solved'} = 'excused';
+ if (exists($record{'resource.'.$new_part.'.awarded'})) {
+ $newrecord{'resource.'.$new_part.'.awarded'} = '';
}
- $newrecord{'resource.'.$_.'.regrader'}="$ENV{'user.name'}:$ENV{'user.domain'}";
+ $newrecord{'resource.'.$new_part.'.regrader'}="$env{'user.name'}:$env{'user.domain'}";
}
} elsif ($dropMenu eq 'reset status'
- && exists($record{'resource.'.$_.'.solved'})) { #don't bother if no old records -> no attempts
+ && exists($record{'resource.'.$new_part.'.solved'})) { #don't bother if no old records -> no attempts
foreach my $key (keys (%record)) {
- if ($key=~/^resource\.\Q$_\E\./) { $newrecord{$key} = ''; }
+ if ($key=~/^resource\.\Q$new_part\E\./) { $newrecord{$key} = ''; }
}
- $newrecord{'resource.'.$_.'.regrader'}=
- "$ENV{'user.name'}:$ENV{'user.domain'}";
+ $newrecord{'resource.'.$new_part.'.regrader'}=
+ "$env{'user.name'}:$env{'user.domain'}";
+ my $totaltries = $record{'resource.'.$part.'.tries'};
+
+ my %last_resets = &get_last_resets($symb,$env{'request.course.id'},
+ [$new_part]);
+ my $aggtries =$totaltries;
+ if ($last_resets{$new_part}) {
+ $aggtries = &get_num_tries(\%record,$last_resets{$new_part},
+ $new_part);
+ }
+
+ my $solvedstatus = $record{'resource.'.$new_part.'.solved'};
+ if ($aggtries > 0) {
+ &decrement($symb,$new_part,\%aggregate,$aggtries,$totaltries,$solvedstatus);
+ $aggregateflag = 1;
+ }
} elsif ($dropMenu eq '') {
- $pts = ($ENV{'form.GD_BOX'.$newflg.'_'.$_} ne '' ?
- $ENV{'form.GD_BOX'.$newflg.'_'.$_} :
- $ENV{'form.RADVAL'.$newflg.'_'.$_});
- if ($pts eq '' && $ENV{'form.GD_SEL'.$newflg.'_'.$_} eq '') {
+ $pts = ($env{'form.GD_BOX'.$newflg.'_'.$new_part} ne '' ?
+ $env{'form.GD_BOX'.$newflg.'_'.$new_part} :
+ $env{'form.RADVAL'.$newflg.'_'.$new_part});
+ if ($pts eq '' && $env{'form.GD_SEL'.$newflg.'_'.$new_part} eq '') {
next;
}
- $wgt = $ENV{'form.WGT'.$newflg.'_'.$_} eq '' ? 1 :
- $ENV{'form.WGT'.$newflg.'_'.$_};
+ $wgt = $env{'form.WGT'.$newflg.'_'.$new_part} eq '' ? 1 :
+ $env{'form.WGT'.$newflg.'_'.$new_part};
my $partial= $pts/$wgt;
- if ($partial eq $record{'resource.'.$_.'.awarded'}) {
+ if ($partial eq $record{'resource.'.$new_part.'.awarded'}) {
#do not update score for part if not changed.
next;
+ } else {
+ push @parts_graded, $new_part;
}
- if ($record{'resource.'.$_.'.awarded'} ne $partial) {
- $newrecord{'resource.'.$_.'.awarded'} = $partial;
+ if ($record{'resource.'.$new_part.'.awarded'} ne $partial) {
+ $newrecord{'resource.'.$new_part.'.awarded'} = $partial;
}
- my $reckey = 'resource.'.$_.'.solved';
+ my $reckey = 'resource.'.$new_part.'.solved';
if ($partial == 0) {
if ($record{$reckey} ne 'incorrect_by_override') {
$newrecord{$reckey} = 'incorrect_by_override';
@@ -2093,20 +2204,147 @@ sub saveHandGrade {
}
}
if ($submitter &&
- ($record{'resource.'.$_.'.submitted_by'} ne $submitter)) {
- $newrecord{'resource.'.$_.'.submitted_by'} = $submitter;
+ ($record{'resource.'.$new_part.'.submitted_by'} ne $submitter)) {
+ $newrecord{'resource.'.$new_part.'.submitted_by'} = $submitter;
}
- $newrecord{'resource.'.$_.'.regrader'}=
- "$ENV{'user.name'}:$ENV{'user.domain'}";
+ $newrecord{'resource.'.$new_part.'.regrader'}=
+ "$env{'user.name'}:$env{'user.domain'}";
+ }
+ # unless problem has been graded, set flag to version the submitted files
+ unless ($record{'resource.'.$new_part.'.solved'} =~ /^correct_/ || $record{'resource.'.$new_part.'.solved'} eq 'incorrect_by_override') {
+ push (@v_flag,$new_part);
}
}
if (scalar(keys(%newrecord)) > 0) {
+ if (scalar(@v_flag)) {
+ &version_portfiles(\%record, \@parts_graded, $env{'request.course.id'}, $symb, $domain, $stuname, \@v_flag);
+ }
&Apache::lonnet::cstore(\%newrecord,$symb,
- $ENV{'request.course.id'},$domain,$stuname);
+ $env{'request.course.id'},$domain,$stuname);
+ }
+ if ($aggregateflag) {
+ &Apache::lonnet::cinc('nohist_resourcetracker',\%aggregate,
+ $env{'course.'.$env{'request.course.id'}.'.domain'},
+ $env{'course.'.$env{'request.course.id'}.'.num'});
}
return '',$pts,$wgt;
}
+# ----------- Provides number of tries since last reset.
+sub get_num_tries {
+ my ($record,$last_reset,$part) = @_;
+ my $timestamp = '';
+ my $num_tries = 0;
+ if ($$record{'version'}) {
+ for (my $version=$$record{'version'};$version>=1;$version--) {
+ if (exists($$record{$version.':resource.'.$part.'.solved'})) {
+ $timestamp = $$record{$version.':timestamp'};
+ if ($timestamp > $last_reset) {
+ $num_tries ++;
+ } else {
+ last;
+ }
+ }
+ }
+ }
+ return $num_tries;
+}
+
+# ----------- Determine decrements required in aggregate totals
+sub decrement_aggs {
+ my ($symb,$part,$aggregate,$aggtries,$totaltries,$solvedstatus) = @_;
+ my %decrement = (
+ attempts => 0,
+ users => 0,
+ correct => 0
+ );
+ $decrement{'attempts'} = $aggtries;
+ if ($solvedstatus =~ /^correct/) {
+ $decrement{'correct'} = 1;
+ }
+ if ($aggtries == $totaltries) {
+ $decrement{'users'} = 1;
+ }
+ foreach my $type (keys (%decrement)) {
+ $$aggregate{$symb."\0".$part."\0".$type} = -$decrement{$type};
+ }
+ return;
+}
+
+# ----------- Determine timestamps for last reset of aggregate totals for parts
+sub get_last_resets {
+ my ($symb,$courseid,$partids) =@_;
+ my %last_resets;
+ my $cdom = $env{'course.'.$courseid.'.domain'};
+ my $cname = $env{'course.'.$courseid.'.num'};
+ my @keys;
+ foreach my $part (@{$partids}) {
+ push(@keys,"$symb\0$part\0resettime");
+ }
+ my %results=&Apache::lonnet::get('nohist_resourcetracker',\@keys,
+ $cdom,$cname);
+ foreach my $part (@{$partids}) {
+ $last_resets{$part}=$results{"$symb\0$part\0resettime"};
+ }
+ return %last_resets;
+}
+
+# ----------- Handles creating versions for portfolio files as answers
+sub version_portfiles {
+ my ($record, $parts_graded, $courseid, $symb, $domain, $stuname, $v_flag) = @_;
+ my $version_parts = join('|',@$v_flag);
+ my $parts = join('|', @$parts_graded);
+ my $portfolio_root = &Apache::loncommon::propath($domain,
+ $stuname).
+ '/userfiles/portfolio';
+ foreach my $key (keys(%$record)) {
+ my $new_portfiles;
+
+ if ($key =~ /^resource\.($version_parts)\./ && $key =~ /\.portfiles$/ ) {
+ my @v_portfiles;
+ my @portfiles = split(/,/,$$record{$key});
+ &Apache::lonnet::logthis("should be unmarking and remarking $key",@portfiles);
+ foreach my $file (@portfiles) {
+ &Apache::lonnet::unmark_as_readonly($domain,$stuname,[$symb,$env{'request.course.id'}],$file);
+ my ($directory,$answer_file) =($file =~ /^(.*?)([^\/]*$)/);
+ my $version = 0;
+ my @answer_file_parts = split(/\./, $answer_file);
+ my @dir_list = &Apache::lonnet::dirlist($directory,$domain,$stuname,$portfolio_root);
+ my @file_names;
+ my @file_name_parts;
+ foreach my $row (@dir_list) {
+ @file_names = split(/\&/,$row,2);
+ @file_name_parts = split(/\./, $file_names[0]);
+ # ($file_name_parts[scalar @file_name_parts] eq $answer_file_parts[scalar @answer_file_parts])
+ if (($file_name_parts[0] eq $answer_file_parts[0]) &&
+ ($file_name_parts[-1] eq $answer_file_parts[-1])) {
+ # gets here if filename and extension match, regardless of version
+ if (scalar @file_name_parts == 3) { # a versioned file is found
+ # so save it for later
+ if ($file_name_parts[1] > $version) {$version = $file_name_parts[1]};
+ }
+ }
+ }
+ $version++;
+ $env{'form.copy'} = &Apache::lonnet::getfile("/uploaded/$domain/$stuname/portfolio$directory$answer_file");
+ if($env{'form.copy'} eq '-1') {
+ &Apache::lonnet::logthis('problem getting file '.$directory.$answer_file);
+ } else {
+ my $copy_result = &Apache::lonnet::finishuserfileupload($stuname,$domain,'copy',
+ '/portfolio'.$directory.$answer_file_parts[0].'.'.$version.'.'.$answer_file_parts[-1]);
+ push(@v_portfiles, $answer_file_parts[0].'.'.$version.'.'.$answer_file_parts[-1]);
+ &Apache::lonnet::mark_as_readonly($domain,$stuname,
+ ['/portfolio'.$directory.$answer_file_parts[0].'.'.$version.'.'.$answer_file_parts[-1]],
+ [$symb,$env{'request.course.id'},'graded']);
+ }
+ }
+ $$record{$key} = join(',',@v_portfiles);
+ }
+ }
+ return 'ok';
+
+}
+
#--------------------------------------------------------------------------------------
#
#-------------------------- Next few routines handles grading by section or whole class
@@ -2172,6 +2410,7 @@ sub viewgrades_js {
function writeRadText(partid,weight) {
var selval = document.classgrade["SELVAL_"+partid];
var radioButton = document.classgrade["RADVAL_"+partid];
+ var override = document.classgrade["FORCE_"+partid].checked;
var textbox = document.classgrade["TEXTVAL_"+partid];
if (selval[1].selected || selval[2].selected) {
for (var i=0; i'.&mt('Manual Grading').' ';
- $result.='Current Resource: '.$ENV{'form.probTitle'}.' '."\n";
+ $result.='Current Resource: '.$env{'form.probTitle'}.' '."\n";
#view individual student submission form - called using Javascript viewOneStudent
$result.=&jscriptNform($url,$symb);
@@ -2300,18 +2539,18 @@ sub viewgrades {
' '."\n".
' '."\n".
' '."\n".
- ' '."\n".
- ' '."\n".
- ' '."\n".
- ' '."\n";
+ ' '."\n".
+ ' '."\n".
+ ' '."\n".
+ ' '."\n";
my $sectionClass;
- if ($ENV{'form.section'} eq 'all') {
+ if ($env{'form.section'} eq 'all') {
$sectionClass='Class ';
- } elsif ($ENV{'form.section'} eq 'none') {
+ } elsif ($env{'form.section'} eq 'none') {
$sectionClass='Students in no Section ';
} else {
- $sectionClass='Students in Section '.$ENV{'form.section'}.'';
+ $sectionClass='Students in Section '.$env{'form.section'}.'';
}
$result.='Assign Common Grade To '.$sectionClass;
$result.= ' '.' '.''."\n".
@@ -2371,11 +2611,13 @@ sub viewgrades {
'