'.$rendered.' ';
@@ -1400,40 +1538,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'} = &get_fullname ($uname,$udom) 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.$usec.$ENV{'request.course.id'}.') ');
+ $uname.'@'.$udom.' in section '.$usec.' in 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);
@@ -1441,13 +1580,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));
@@ -1456,60 +1595,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);
@@ -1733,8 +1886,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;
@@ -1745,13 +1898,24 @@ KEYWORDS
' '."\n";
$result.=' '.
- 'Compose Message to student'.(scalar(@col_fullnames) >= 1 ? 's' : '').' '.
+ &mt('Compose message to student').(scalar(@col_fullnames) >= 1 ? 's' : '').' ('.
+ &mt('incl. grades').' )'.
' '."\n".
- ' (Message will be sent when you click on Save & Next below.)'."\n"
- if ($ENV{'form.handgrade'} eq 'yes');
+ ' ('.
+ &mt('Message will be sent when you click on Save & Next below.').")\n";
$request->print($result);
}
+ if ($perm{'vgr'}) {
+ $request->print(' '.
+ &Apache::loncommon::track_student_link(&mt('View recent activity'),
+ $uname,$udom,'check'));
+ }
+ if ($perm{'opa'}) {
+ $request->print(' '.
+ &Apache::loncommon::pprmlink(&mt('Set/Change parameters'),
+ $uname,$udom,$symb,'check'));
+ }
my %seen = ();
my @partlist;
@@ -1760,7 +1924,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;
@@ -1788,7 +1952,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;
}
@@ -1845,15 +2009,18 @@ 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'};
+ my $cdom = $env{'course.'.$env{'request.course.id'}.'.domain'};
+ my $cnum = $env{'course.'.$env{'request.course.id'}.'.num'};
+
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++;
@@ -1864,38 +2031,43 @@ 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/);
+ unless ($subject=~/\w/) { $subject=&mt('Grading Feedback'); }
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 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);
+ $subject.' ['.
+ &Apache::lonnet::declutter($url).']',$message);
+ $request->print(' '.&mt('Sending message to [_1]@[_2]',$uname,$udom).': '.
+ $msgstatus);
}
- 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) {
+ foreach my $collaborator (@collaborators) {
my ($errorflag,$pts,$wgt) =
- &saveHandGrade($request,$url,$symb,$_,$udom,$ctr,
- $ENV{'form.unamedom'.$ctr},$part);
+ &saveHandGrade($request,$url,$symb,$collaborator,$udom,$ctr,
+ $env{'form.unamedom'.$ctr},$part);
if ($errorflag eq 'not_allowed') {
- $request->print("Not allowed to modify grades for $_:$udom ");
+ $request->print("Not allowed to modify grades for $collaborator:$udom ");
next;
} else {
if ($message ne '') {
- $msgstatus = &Apache::lonmsg::user_normal_msg($_,$udom,$ENV{'form.msgsub'},$message);
+ $msgstatus = &Apache::lonmsg::user_normal_msg($collaborator,$udom,$env{'form.msgsub'},$message);
}
-
}
}
}
@@ -1904,61 +2076,59 @@ 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'});
+ ('nohist_handgrade',\%keyhash,$cdom,$cnum);
}
# 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++;
}
@@ -1967,27 +2137,33 @@ 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);
}
my (@parsedlist,@nextlist);
my ($nextflg) = 0;
- foreach (sort {lc($$fullname{$a}) cmp lc($$fullname{$b}) } keys %$fullname) {
+ foreach (sort
+ {
+ if (lc($$fullname{$a}) ne lc($$fullname{$b})) {
+ return (lc($$fullname{$a}) cmp lc($$fullname{$b}));
+ }
+ return $a cmp $b;
+ } (keys(%$fullname))) {
if ($nextflg == 1 && $button =~ /Next$/) {
push @parsedlist,$_;
}
@@ -2001,16 +2177,26 @@ 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 eq 'queued') {
+ my %queue_status =
+ &Apache::bridgetask::get_student_status($symb,$cdom,$cnum,
+ $udom,$uname);
+ next if (!defined($queue_status{'gradingqueue'}));
+ }
+
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;
@@ -2019,8 +2205,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);
@@ -2032,9 +2218,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++;
}
@@ -2042,7 +2228,7 @@ sub processHandGrade {
my $the_end = 'LON-CAPA User Message '."\n";
$the_end.='Message: No more students for this section or class. '."\n";
$the_end.='Click on the button below to return to the grading menu. '."\n";
- $the_end.=&show_grading_menu_form ($symb,$url);
+ $the_end.=&show_grading_menu_form($symb,$url);
$request->print($the_end);
}
return '';
@@ -2051,49 +2237,72 @@ 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;
+
+ my @parts = split(/:/,$env{'form.partlist'.$newflg});
+ foreach my $new_part (@parts) {
#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';
@@ -2104,18 +2313,233 @@ 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'}";
+ }
+ if ($env{'form.part'.$new_part.'_returndoc1'}) {
+ # if multiple files are uploaded names will be 'returndoc2','returndoc3'
+
+ my $portfolio_root = &Apache::loncommon::propath($domain,
+ $stuname).
+ '/userfiles/portfolio';
+ $request->print(' '.$portfolio_root.' ');
+
+ # my $result=&Apache::lonnet::userfileupload('uploaddoc','',
+ # 'portfolio'.$env{'form.currentpath'});
+
+ my $file_counter = 1;
+ my $respid = $env{'form.respid'};
+ while ($env{'form.part'.$new_part.'_returndoc'.$file_counter}) {
+ my $fname=$env{'form.returndoc'.$file_counter.'.filename'};
+ $newrecord{"resource.$new_part.$respid.handback"} = $env{'form.returndocorig'.$file_counter};
+ $request->print(" ".$fname." will be the uploaded file name");
+ $request->print("Will upload document ".$env{'form.returndocorig'.$file_counter});
+ $file_counter++;
+ }
+ }
+
+ # 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' ||
+ $dropMenu eq 'reset status')
+ {
+ push (@v_flag,$new_part);
}
}
+ my $cdom = $env{'course.'.$env{'request.course.id'}.'.domain'};
+ my $cnum = $env{'course.'.$env{'request.course.id'}.'.num'};
+
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);
+
+ my @ungraded_parts;
+ foreach my $part (@parts) {
+ if ( !defined($record{'resource.'.$part.'.awarded'})
+ && !defined($newrecord{'resource.'.$part.'.awarded'}) ) {
+ push(@ungraded_parts, $part);
+ }
+ }
+ if ( !@ungraded_parts ) {
+ &Apache::bridgetask::remove_from_queue('gradingqueue',$symb,$cdom,
+ $cnum,$domain,$stuname);
+ }
+ }
+ if ($aggregateflag) {
+ &Apache::lonnet::cinc('nohist_resourcetracker',\%aggregate,
+ $cdom,$cnum);
+ }
+ return ('',$pts,$wgt);
+}
+sub get_submitted_files {
+ my ($udom,$uname,$partid,$respid,$record) = @_;
+ my @files;
+ if ($$record{"resource.$partid.$respid.portfiles"}) {
+ my $file_url = '/uploaded/'.$udom.'/'.$uname.'/portfolio';
+ foreach my $file (split(',',$$record{"resource.$partid.$respid.portfiles"})) {
+ push(@files,$file_url.$file);
+ }
}
- return '',$pts,$wgt;
+ if ($$record{"resource.$partid.$respid.uploadedurl"}) {
+ push(@files,$$record{"resource.$partid.$respid.uploadedurl"});
+ }
+ return (\@files);
+}
+# ----------- 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, $stu_name, $v_flag) = @_;
+ my $version_parts = join('|',@$v_flag);
+ my $parts = join('|', @$parts_graded);
+ my $portfolio_root = &Apache::loncommon::propath($domain,
+ $stu_name).
+ '/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});
+ foreach my $file (@portfiles) {
+ &Apache::lonnet::unmark_as_readonly($domain,$stu_name,[$symb,$env{'request.course.id'}],$file);
+ my ($directory,$answer_file) =($file =~ /^(.*?)([^\/]*)$/);
+ my $version = 0;
+ my ($answer_name,$answer_ver,$answer_ext) =
+ &file_name_version_ext($answer_file);
+ my @dir_list = &Apache::lonnet::dirlist($directory,$domain,$stu_name,$portfolio_root);
+ $version = &get_next_version($answer_name, $answer_ext, \@dir_list);
+ my $new_answer = &version_selected_portfile($domain, $stu_name, $directory, $answer_file, $version);
+ if ($new_answer ne 'problem getting file') {
+ push(@v_portfiles, $directory.$new_answer);
+ &Apache::lonnet::mark_as_readonly($domain,$stu_name,
+ ['/portfolio'.$directory.$new_answer],
+ [$symb,$env{'request.course.id'},'graded']);
+ }
+
+ }
+ $$record{$key} = join(',',@v_portfiles);
+ }
+ }
+ return 'ok';
+}
+
+sub get_next_version {
+ my ($answer_name, $answer_ext, $dir_list);
+ my $version;
+ foreach my $row (@$dir_list) {
+ my ($file) = split(/\&/,$row,2);
+ my ($file_name,$file_version,$file_ext) =
+ &file_name_version_ext($file);
+ if (($file_name eq $answer_name) &&
+ ($file_ext eq $answer_ext)) {
+ # gets here if filename and extension match, regardless of version
+ if ($file_version ne '') {
+ # a versioned file is found so save it for later
+ if ($file_version > $version) {
+ $version = $file_version;
+ }
+ }
+ }
+ }
+ $version ++;
+ return($version);
+}
+
+sub version_selected_portfile {
+ my ($domain,$stu_name,$directory,$file_name,$version) = @_;
+ my ($answer_name,$answer_ver,$answer_ext) =
+ &file_name_version_ext($file_name);
+ my $new_answer;
+ $env{'form.copy'} = &Apache::lonnet::getfile("/uploaded/$domain/$stu_name/portfolio$directory$file_name");
+ if($env{'form.copy'} eq '-1') {
+ &Apache::lonnet::logthis('problem getting file '.$file_name);
+ $new_answer = 'problem getting file';
+ } else {
+ $new_answer = $answer_name.'.'.$version.'.'.$answer_ext;
+ my $copy_result = &Apache::lonnet::finishuserfileupload(
+ $stu_name,$domain,'copy',
+ '/portfolio'.$directory.$new_answer);
+ }
+ return ($new_answer);
+}
+
+sub file_name_version_ext {
+ my ($file)=@_;
+ my @file_parts = split(/\./, $file);
+ my ($name,$version,$ext);
+ if (@file_parts > 1) {
+ $ext=pop(@file_parts);
+ if (@file_parts > 1 && $file_parts[-1] =~ /^\d+$/) {
+ $version=pop(@file_parts);
+ }
+ $name=join('.',@file_parts);
+ } else {
+ $name=join('.',@file_parts);
+ }
+ return($name,$version,$ext);
}
#--------------------------------------------------------------------------------------
@@ -2167,6 +2591,7 @@ sub viewgrades_js {
}
for (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);
@@ -2311,18 +2740,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".
@@ -2351,9 +2780,9 @@ sub viewgrades {
$result.=''.'
'.' '."\n".
@@ -2382,11 +2812,13 @@ sub viewgrades {
'