'.
- ' '."\n";
- if ($ENV{'form.handgrade'} eq 'yes') {
- $endform.=' '."\n";
- my $ntstu =''.
- '1 2 '.
- '3 5 '.
- '7 10 '."\n";
- my $nsel = ($ENV{'form.NTSTU'} ne '' ? $ENV{'form.NTSTU'} : '1');
- $ntstu =~ s/$nsel $nsel;
- $endform.=$ntstu.'student(s) ';
- } else {
- $endform.=' '."\n";
- }
- $endform.=' '."\n".
- ' ';
- $endform.='(Next and Previous do not save the scores.)'."\n"
- if ($ENV{'form.handgrade'} eq 'yes');
+ my $endform='';
- $endform.=&show_grading_menu_form($symb,$url);
+ $endform.=&show_grading_menu_form($symb);
$request->print($endform);
}
return '';
@@ -1438,99 +2141,123 @@ KEYWORDS
#--- Retrieve the last submission for all the parts
sub get_last_submission {
- my (%returnhash)=@_;
+ my ($returnhash)=@_;
my (@string,$timestamp);
- if ($returnhash{'version'}) {
+ if ($$returnhash{'version'}) {
my %lasthash=();
my ($version);
- for ($version=1;$version<=$returnhash{'version'};$version++) {
- foreach (sort(split(/\:/,$returnhash{$version.':keys'}))) {
- $lasthash{$_}=$returnhash{$version.':'.$_};
- $timestamp = scalar(localtime($returnhash{$version.':timestamp'}));
+ for ($version=1;$version<=$$returnhash{'version'};$version++) {
+ foreach my $key (sort(split(/\:/,
+ $$returnhash{$version.':keys'}))) {
+ $lasthash{$key}=$$returnhash{$version.':'.$key};
+ $timestamp =
+ scalar(localtime($$returnhash{$version.':timestamp'}));
}
}
- foreach ((keys %lasthash)) {
- if ($_ =~ /\.submission$/) {
- my ($partid,$foo) = split(/submission$/,$_);
- my $draft = $lasthash{$partid.'awarddetail'} eq 'DRAFT' ?
- 'Draft Copy ' : '';
- push @string, (join(':',$_,$draft.$lasthash{$_}));
- }
+ foreach my $key (keys(%lasthash)) {
+ next if ($key !~ /\.submission$/);
+
+ my ($partid,$foo) = split(/submission$/,$key);
+ my $draft = $lasthash{$partid.'awarddetail'} eq 'DRAFT' ?
+ 'Draft Copy ' : '';
+ push(@string, join(':', $key, $draft.$lasthash{$key}));
}
}
- @string = $string[0] eq '' ? 'Nothing submitted - no attempts.' : @string;
- return \@string,\$timestamp;
+ if (!@string) {
+ $string[0] =
+ 'Nothing submitted - no attempts. ';
+ }
+ return (\@string,\$timestamp);
}
#--- High light keywords, with style choosen by user.
sub keywords_highlight {
my $string = shift;
- my $size = $ENV{'form.kwsize'} eq '0' ? '' : 'size='.$ENV{'form.kwsize'};
- my $styleon = $ENV{'form.kwstyle'} eq '' ? '' : $ENV{'form.kwstyle'};
+ my $size = $env{'form.kwsize'} eq '0' ? '' : 'size='.$env{'form.kwsize'};
+ my $styleon = $env{'form.kwstyle'} eq '' ? '' : $env{'form.kwstyle'};
(my $styleoff = $styleon) =~ s/\\<\//;
- my @keylist = split(/[,\s+]/,$ENV{'form.keywords'});
- foreach (@keylist) {
- $string =~ s/\b\Q$_\E(\b|\.)/\$styleon$_$styleoff\<\/font\>/gi;
- }
- # This is not really the right place to do this, but I cannot find a
- # better one at this time. So here we go - the m in the s:::mg causes
- # ^ to match the beginning of a new line. So we replace(???) the beginning
- # of the line with to make things formatted a little better.
- $string =~ s:^: :mg;
+ my @keylist = split(/[,\s+]/,$env{'form.keywords'});
+ foreach my $keyword (@keylist) {
+ $string =~ s/\b\Q$keyword\E(\b|\.)/$styleon$keyword$styleoff<\/font>/gi;
+ }
return $string;
}
#--- 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 $symb = &get_symb($request);
+ my (undef,undef,$url) = &Apache::lonnet::decode_symb($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 ($errorflag,$pts,$wgt) = &saveHandGrade($request,$url,$symb,$uname,$udom,$ctr);
+ my ($uname,$udom) = split(/:/,$env{'form.unamedom'.$ctr});
+ my ($errorflag,$pts,$wgt) = &saveHandGrade($request,$symb,$uname,$udom,$ctr);
if ($errorflag eq 'no_score') {
$ctr++;
next;
}
if ($errorflag eq 'not_allowed') {
- $request->print("Not allowed to modify grades for $uname:$udom ");
+ $request->print("Not allowed to modify grades for $uname:$udom ");
$ctr++;
next;
}
- my $includemsg = $ENV{'form.includemsg'.$ctr};
+ my $includemsg = $env{'form.includemsg'.$ctr};
my ($subject,$message,$msgstatus) = ('','','');
+ my $restitle = &Apache::lonnet::gettitle($symb);
+ my ($feedurl,$showsymb) =
+ &get_feedurl_and_symb($symb,$uname,$udom);
+ my $messagetail;
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'); }
+ $subject.=' ['.$restitle.']';
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'} ";
- $msgstatus = &Apache::lonmsg::user_normal_msg ($uname,$udom,
- $ENV{'form.msgsub'},$message);
- }
- if ($ENV{'form.collaborator'.$ctr}) {
- my (@collaborators) = split(/:/,$ENV{'form.collaborator'.$ctr});
- foreach (@collaborators) {
- my ($errorflag,$pts,$wgt) = &saveHandGrade($request,$url,$symb,$_,$udom,$ctr,$ENV{'form.unamedom'.$ctr});
- 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);
+ if ($env{'form.withgrades'.$ctr}) {
+ $message.="\n\nPoint".($pts > 1 ? 's':'').' awarded = '.$pts.' out of '.$wgt;
+ $messagetail = " for $env{'form.probTitle'} ";
+ }
+ $msgstatus =
+ &Apache::lonmsg::user_normal_msg($uname,$udom,$subject,
+ $message.$messagetail,
+ undef,$feedurl,undef,
+ undef,undef,$showsymb,
+ $restitle);
+ $request->print(' '.&mt('Sending message to [_1]:[_2]',$uname,$udom).': '.
+ $msgstatus);
+ }
+ 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 my $collaborator (@collaborators) {
+ my ($errorflag,$pts,$wgt) =
+ &saveHandGrade($request,$symb,$collaborator,$udom,$ctr,
+ $env{'form.unamedom'.$ctr},$part);
+ if ($errorflag eq 'not_allowed') {
+ $request->print("".&mt('Not allowed to modify grades for [_1]',"$collaborator:$udom")." ");
+ next;
+ } elsif ($message ne '') {
+ my ($baseurl,$showsymb) =
+ &get_feedurl_and_symb($symb,$collaborator,
+ $udom);
+ if ($env{'form.withgrades'.$ctr}) {
+ $messagetail = " for $env{'form.probTitle'} ";
+ }
+ $msgstatus =
+ &Apache::lonmsg::user_normal_msg($collaborator,$udom,$subject,$message.$messagetail,undef,$baseurl,undef,undef,undef,$showsymb,$restitle);
}
}
}
@@ -1539,79 +2266,94 @@ sub processHandGrade {
}
}
- # Keywords sorted in alphabatical order
- 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'};
-
- # message center - Order of message gets changed. Blank line is eliminated.
- # 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};
- $idx++;
+ if ($env{'form.handgrade'} eq 'yes') {
+ # Keywords sorted in alphabatical order
+ 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'};
+
+ # message center - Order of message gets changed. Blank line is eliminated.
+ # 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};
+ $idx++;
+ }
+ $ctr++;
}
- $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};
- $idx++;
+ $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};
+ $idx++;
+ }
+ $ctr++;
}
- $ctr++;
+ $env{'form.savemsgN'} = --$idx;
+ $keyhash{$symb.'_savemsgN'} = $env{'form.savemsgN'};
+ my $putresult = &Apache::lonnet::put
+ ('nohist_handgrade',\%keyhash,$cdom,$cnum);
}
- $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'});
-
# Called by Save & Refresh from Highlight Attribute Window
- my (undef,undef,$fullname) = &getclasslist($ENV{'form.section'},'0');
- 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++;
}
return '';
}
+# 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($symb);
+ 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)};
- $ctr = 2;
+ 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,$_;
}
@@ -1622,21 +2364,42 @@ sub processHandGrade {
}
}
$ctr = 0;
- my ($partlist,$handgrade) = &response_type($ENV{'form.url'});
@parsedlist = reverse @parsedlist if ($button eq 'Previous');
+ my ($partlist) = &response_type($symb);
foreach my $student (@parsedlist) {
+ my $submitonly=$env{'form.submitonly'};
my ($uname,$udom) = split(/:/,$student);
- if ($ENV{'form.submitonly'} eq 'yes') {
- my (%status) = &student_gradeStatus($ENV{'form.url'},$symb,$udom,$uname,$partlist) ;
- my $statusflg = '';
+
+ 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 %status=&student_gradeStatus($symb,$udom,$uname,$partlist);
+ my $submitted = 0;
+ my $ungraded = 0;
+ my $incorrect = 0;
foreach (keys(%status)) {
- $statusflg = 1 if ($status{$_} ne 'nothing');
- my ($foo,$partid,$foo1) = split(/\./);
- $statusflg = '' if ($status{'resource.'.$partid.'.submitted_by'} ne '');
+ $submitted = 1 if ($status{$_} ne 'nothing');
+ $ungraded = 1 if ($status{$_} =~ /^ungraded/);
+ $incorrect = 1 if ($status{$_} =~ /^incorrect/);
+ my ($foo,$partid,$foo1) = split(/\./,$_);
+ if ($status{'resource.'.$partid.'.submitted_by'} ne '') {
+ $submitted = 0;
+ }
}
- next if ($statusflg eq '');
+ next if (!$submitted && ($submitonly eq 'yes' ||
+ $submitonly eq 'incorrect' ||
+ $submitonly eq 'graded'));
+ next if (!$ungraded && ($submitonly eq 'graded'));
+ next if (!$incorrect && $submitonly eq 'incorrect');
}
push @nextlist,$student if ($ctr < $ntstu);
+ last if ($ctr == $ntstu);
$ctr++;
}
@@ -1645,17 +2408,17 @@ 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++;
}
if ($total < 0) {
- my $the_end = 'LON-CAPA User Message '."\n";
+ 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);
$request->print($the_end);
}
return '';
@@ -1663,50 +2426,379 @@ sub processHandGrade {
#---- Save the score and award for each student, if changed
sub saveHandGrade {
- my ($request,$url,$symb,$stuname,$domain,$newflg,$submitter) = @_;
+ my ($request,$symb,$stuname,$domain,$newflg,$submitter,$part) = @_;
+ my @version_parts;
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})) {
- if ($ENV{'form.GD_SEL'.$newflg.'_'.$_} eq 'excused') {
- if ($record{'resource.'.$_.'.solved'} ne 'excused') {
- $newrecord{'resource.'.$_.'.solved'} = 'excused';
- if (exists($record{'resource.'.$_.'.awarded'})) {
- $newrecord{'resource.'.$_.'.awarded'} = '';
+ my %aggregate = ();
+ my $aggregateflag = 0;
+ my @parts = split(/:/,$env{'form.partlist'.$newflg});
+ foreach my $new_part (@parts) {
+ #collaborator ($submi may vary for different parts
+ if ($submitter && $new_part ne $part) { next; }
+ my $dropMenu = $env{'form.GD_SEL'.$newflg.'_'.$new_part};
+ if ($dropMenu eq 'excused') {
+ 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.'.$new_part.'.regrader'}="$env{'user.name'}:$env{'user.domain'}";
}
- } else {
- $pts = ($ENV{'form.GD_BOX'.$newflg.'_'.$_} ne '' ?
- $ENV{'form.GD_BOX'.$newflg.'_'.$_} :
- $ENV{'form.RADVAL'.$newflg.'_'.$_});
- return 'no_score' if ($pts eq '' && $ENV{'form.GD_SEL'.$newflg.'_'.$_} eq '');
- $wgt = $ENV{'form.WGT'.$newflg.'_'.$_} eq '' ? 1 :
- $ENV{'form.WGT'.$newflg.'_'.$_};
+ } 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)) {
+ if ($key=~/^resource\.\Q$new_part\E\./) { $newrecord{$key} = ''; }
+ }
+ $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_aggs($symb,$new_part,\%aggregate,$aggtries,$totaltries,$solvedstatus);
+ $aggregateflag = 1;
+ }
+ } elsif ($dropMenu 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.'_'.$new_part} eq '' ? 1 :
+ $env{'form.WGT'.$newflg.'_'.$new_part};
my $partial= $pts/$wgt;
- $newrecord{'resource.'.$_.'.awarded'} = $partial
- if ($record{'resource.'.$_.'.awarded'} ne $partial);
- my $reckey = 'resource.'.$_.'.solved';
+ if ($partial eq $record{'resource.'.$new_part.'.awarded'}) {
+ #do not update score for part if not changed.
+ &handback_files($request,$symb,$stuname,$domain,$newflg,$new_part,\%newrecord);
+ next;
+ } else {
+ push @parts_graded, $new_part;
+ }
+ if ($record{'resource.'.$new_part.'.awarded'} ne $partial) {
+ $newrecord{'resource.'.$new_part.'.awarded'} = $partial;
+ }
+ my $reckey = 'resource.'.$new_part.'.solved';
if ($partial == 0) {
- $newrecord{$reckey} = 'incorrect_by_override'
- if ($record{$reckey} ne 'incorrect_by_override');
+ if ($record{$reckey} ne 'incorrect_by_override') {
+ $newrecord{$reckey} = 'incorrect_by_override';
+ }
} else {
- $newrecord{$reckey} = 'correct_by_override'
- if ($record{$reckey} ne 'correct_by_override');
+ if ($record{$reckey} ne 'correct_by_override') {
+ $newrecord{$reckey} = 'correct_by_override';
+ }
+ }
+ if ($submitter &&
+ ($record{'resource.'.$new_part.'.submitted_by'} ne $submitter)) {
+ $newrecord{'resource.'.$new_part.'.submitted_by'} = $submitter;
+ }
+ $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' ||
+ $dropMenu eq 'reset status')
+ {
+ push (@version_parts,$new_part);
+ }
+ }
+ my $cdom = $env{'course.'.$env{'request.course.id'}.'.domain'};
+ my $cnum = $env{'course.'.$env{'request.course.id'}.'.num'};
+
+ if (%newrecord) {
+ if (@version_parts) {
+ my @changed_keys = &version_portfiles(\%record, \@parts_graded,
+ $env{'request.course.id'}, $symb, $domain, $stuname, \@version_parts);
+ @newrecord{@changed_keys} = @record{@changed_keys};
+ foreach my $new_part (@version_parts) {
+ &handback_files($request,$symb,$stuname,$domain,$newflg,
+ $new_part,\%newrecord);
}
- $newrecord{'resource.'.$_.'.submitted_by'} = $submitter
- if ($submitter && ($record{'resource.'.$_.'.submitted_by'} ne $submitter));
- $newrecord{'resource.'.$_.'regrader'}="$ENV{'user.name'}:$ENV{'user.domain'}";
- }
+ }
+ &Apache::lonnet::cstore(\%newrecord,$symb,
+ $env{'request.course.id'},$domain,$stuname);
+ &check_and_remove_from_queue(\@parts,\%record,\%newrecord,$symb,
+ $cdom,$cnum,$domain,$stuname);
+ }
+ if ($aggregateflag) {
+ &Apache::lonnet::cinc('nohist_resourcetracker',\%aggregate,
+ $cdom,$cnum);
+ }
+ return ('',$pts,$wgt);
+}
+
+sub check_and_remove_from_queue {
+ my ($parts,$record,$newrecord,$symb,$cdom,$cnum,$domain,$stuname) = @_;
+ my @ungraded_parts;
+ foreach my $part (@{$parts}) {
+ if ( $record->{ 'resource.'.$part.'.awarded'} eq ''
+ && $record->{ 'resource.'.$part.'.solved' } ne 'excused'
+ && $newrecord->{'resource.'.$part.'.awarded'} eq ''
+ && $newrecord->{'resource.'.$part.'.solved' } ne 'excused'
+ ) {
+ push(@ungraded_parts, $part);
+ }
+ }
+ if ( !@ungraded_parts ) {
+ &Apache::bridgetask::remove_from_queue('gradingqueue',$symb,$cdom,
+ $cnum,$domain,$stuname);
+ }
+}
+
+sub handback_files {
+ my ($request,$symb,$stuname,$domain,$newflg,$new_part,$newrecord) = @_;
+ my $portfolio_root = &propath($domain,$stuname).'/userfiles/portfolio';
+ my ($partlist,$handgrade,$responseType) = &response_type($symb);
+
+ my @part_response_id = &flatten_responseType($responseType);
+ foreach my $part_response_id (@part_response_id) {
+ my ($part_id,$resp_id) = @{ $part_response_id };
+ my $part_resp = join('_',@{ $part_response_id });
+ if (($env{'form.'.$newflg.'_'.$part_resp.'_returndoc1'}) && ($new_part == $part_id)) {
+ # if multiple files are uploaded names will be 'returndoc2','returndoc3'
+ my $file_counter = 1;
+ my $file_msg;
+ while ($env{'form.'.$newflg.'_'.$part_resp.'_returndoc'.$file_counter}) {
+ my $fname=$env{'form.'.$newflg.'_'.$part_resp.'_returndoc'.$file_counter.'.filename'};
+ my ($directory,$answer_file) =
+ ($env{'form.'.$newflg.'_'.$part_resp.'_origdoc'.$file_counter} =~ /^(.*?)([^\/]*)$/);
+ my ($answer_name,$answer_ver,$answer_ext) =
+ &file_name_version_ext($answer_file);
+ my ($portfolio_path) = ($directory =~ /^.+$stuname\/portfolio(.*)/);
+ my @dir_list = &Apache::lonnet::dirlist($portfolio_path,$domain,$stuname,$portfolio_root);
+ my $version = &get_next_version($answer_name, $answer_ext, \@dir_list);
+ # fix file name
+ my ($save_file_name) = (($directory.$answer_name.".$version.".$answer_ext) =~ /^.+\/${stuname}\/(.*)/);
+ my $result=&Apache::lonnet::finishuserfileupload($stuname,$domain,
+ $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.' ');
+ } else {
+ # mark the file as read only
+ my @files = ($save_file_name);
+ my @what = ($symb,$env{'request.course.id'},'handback');
+ &Apache::lonnet::mark_as_readonly($domain,$stuname,\@files,\@what);
+ if (exists($$newrecord{"resource.$new_part.$resp_id.handback"})) {
+ $$newrecord{"resource.$new_part.$resp_id.handback"}.=',';
+ }
+ $$newrecord{"resource.$new_part.$resp_id.handback"} .= $save_file_name;
+ $file_msg.= "\n".''.$save_file_name." ";
+
+ }
+ $request->print(" ".$fname." will be the uploaded file name");
+ $request->print(" ".$env{'form.'.$newflg.'_'.$part_resp.'_origdoc'.$file_counter});
+ $file_counter++;
+ }
+ my $subject = "File Handed Back by Instructor ";
+ my $message = "A file has been returned that was originally submitted in reponse to: ";
+ $message .= "".&Apache::lonnet::gettitle($symb)." ";
+ $message .= ' The returned file(s) are named: '. $file_msg;
+ $message .= " and can be found in your portfolio space.";
+ my ($feedurl,$showsymb) =
+ &get_feedurl_and_symb($symb,$domain,$stuname);
+ my $restitle = &Apache::lonnet::gettitle($symb);
+ my $msgstatus =
+ &Apache::lonmsg::user_normal_msg($stuname,$domain,$subject.
+ ' (File Returned) ['.$restitle.']',$message,undef,
+ $feedurl,undef,undef,undef,$showsymb,$restitle);
+ }
+ }
+ return;
+}
+
+sub get_feedurl_and_symb {
+ my ($symb,$uname,$udom) = @_;
+ my (undef,undef,$url) = &Apache::lonnet::decode_symb($symb);
+ $url = &Apache::lonnet::clutter($url);
+ my $encrypturl=&Apache::lonnet::EXT('resource.0.encrypturl',
+ $symb,$udom,$uname);
+ if ($encrypturl =~ /^yes$/i) {
+ &Apache::lonenc::encrypted(\$url,1);
+ &Apache::lonenc::encrypted(\$symb,1);
+ }
+ return ($url,$symb);
+}
+
+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);
+ }
+ }
+ if ($$record{"resource.$partid.$respid.uploadedurl"}) {
+ push(@files,$$record{"resource.$partid.$respid.uploadedurl"});
}
+ return (\@files);
+}
- if (scalar(keys(%newrecord)) > 0) {
- &Apache::lonnet::cstore(\%newrecord,$symb,
- $ENV{'request.course.id'},$domain,$stuname);
+# ----------- 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 @returned_keys;
+ my $parts = join('|', @$parts_graded);
+ my $portfolio_root = &propath($domain,$stu_name).
+ '/userfiles/portfolio';
+ foreach my $key (keys(%$record)) {
+ my $new_portfiles;
+ if ($key =~ /^resource\.($version_parts)\./ && $key =~ /\.portfiles$/ ) {
+ my @versioned_portfiles;
+ my @portfiles = split(/\s*,\s*/,$$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 ($answer_name,$answer_ver,$answer_ext) =
+ &file_name_version_ext($answer_file);
+ my @dir_list = &Apache::lonnet::dirlist($directory,$domain,$stu_name,$portfolio_root);
+ my $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(@versioned_portfiles, $directory.$new_answer);
+ &Apache::lonnet::mark_as_readonly($domain,$stu_name,
+ [$directory.$new_answer],
+ [$symb,$env{'request.course.id'},'graded']);
+ }
+ }
+ $$record{$key} = join(',',@versioned_portfiles);
+ push(@returned_keys,$key);
+ }
+ }
+ return (@returned_keys);
+}
+
+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 '',$pts,$wgt;
+ return($name,$version,$ext);
}
#--------------------------------------------------------------------------------------
@@ -1720,10 +2812,10 @@ sub viewgrades_js {
$request->print(<
function writePoint(partid,weight,point) {
- var radioButton = eval("document.classgrade.RADVAL_"+partid);
- var textbox = eval("document.classgrade.TEXTVAL_"+partid);
+ var radioButton = document.classgrade["RADVAL_"+partid];
+ var textbox = document.classgrade["TEXTVAL_"+partid];
if (point == "textval") {
- var point = eval("document.classgrade.TEXTVAL_"+partid+".value");
+ 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));
var resetbox = false;
@@ -1754,15 +2846,14 @@ sub viewgrades_js {
}
} else {
- textbox.value = point;
+ textbox.value = parseFloat(point);
}
for (i=0;iManual Grading ';
+ my ($symb) = &get_symb($request);
+ #need to make sure we have the correct data for later EXT calls,
+ #thus invalidate the cache
+ &Apache::lonnet::devalidatecourseresdata(
+ $env{'course.'.$env{'request.course.id'}.'.num'},
+ $env{'course.'.$env{'request.course.id'}.'.domain'});
+ &Apache::lonnet::clear_EXT_cache_status();
- $result.='Problem: '.$ENV{'form.probTitle'}.' '."\n";
+ my $result=''.&mt('Manual Grading').' ';
+ $result.='Current Resource: '.$env{'form.probTitle'}.' '."\n";
#view individual student submission form - called using Javascript viewOneStudent
- $result.=&jscriptNform($url,$symb);
+ $result.=&jscriptNform($symb);
#beginning of class grading form
$result.= '