--- loncom/homework/grades.pm 2003/07/17 22:08:25 1.118 +++ loncom/homework/grades.pm 2003/07/18 20:14:35 1.119 @@ -1,7 +1,7 @@ # The LearningOnline Network with CAPA # The LON-CAPA Grading handler # -# $Id: grades.pm,v 1.118 2003/07/17 22:08:25 ng Exp $ +# $Id: grades.pm,v 1.119 2003/07/18 20:14:35 ng Exp $ # # Copyright Michigan State University Board of Trustees # @@ -140,7 +140,6 @@ sub showResourceInfo { #--- Currently filters option response type only. sub cleanRecord { my ($answer,$response) = @_; - $answer =~ s|^
||; if ($response eq 'option') { my (@IDs,@ans); foreach (split(/\&/,&Apache::lonnet::unescape($answer))) { @@ -471,8 +470,7 @@ LISTJAVASCRIPT $request->print($result); my $checkhdgrade = ($ENV{'form.handgrade'} eq 'yes' && scalar(@$partlist) > 1 ) ? 'checked' : ''; - my $checklastsub = ($ENV{'form.handgrade'} eq 'no') ? 'checked' : ''; - $checklastsub = 'checked' if ($checkhdgrade eq '' && $checklastsub eq ''); + my $checklastsub = $checkhdgrade eq '' ? 'checked' : ''; my $gradeTable='
'."\n". ' View Problem Text: no '."\n". ' one student '."\n". @@ -1033,16 +1031,6 @@ sub sub_page_kw_js { hDoc.write(" self.close()"); hDoc.write("}"); -/* hDoc.write("function radioSelection(radioButton) {"); - hDoc.write(" var selection=null;"); - hDoc.write(" for (var i=0; i"); @@ -1233,6 +1221,7 @@ sub submission { $request->print(''."\n". ''."\n". ''."\n". + ''."\n". ''."\n". ''."\n". ''."\n". @@ -1377,8 +1366,7 @@ KEYWORDS $$fullname{$ENV{'form.'.$uname.':'.$udom.':submitted_by'}}.''; $request->print($submitby); } else { - my ($string,$timestamp)= - &get_last_submission (%record); + my ($string,$timestamp)= &get_last_submission (\%record); my $lastsubonly=''. ($$timestamp eq '' ? '' : 'Date Submitted: '. $$timestamp)."\n"; @@ -1416,9 +1404,11 @@ KEYWORDS '"> File uploaded by student '. 'Like all files provided by users, '. 'this file may contain virusses
':''). - 'Submitted Answer: '.($responsetype eq 'essay' ? '
' : ''). + 'Submitted Answer: '.($responsetype =~ /^(essay|option)$/ ? + '
' : ''). &cleanRecord(&keywords_highlight($subval),$responsetype). - ($responsetype eq 'essay' ? '

' : '

').$similar."\n" + ($responsetype =~ /^(essay|option)$/ ? '

' : + '

').$similar."\n" if ($ENV{'form.lastSub'} eq 'lastonly' || ($ENV{'form.lastSub'} eq 'hdgrade' && $$handgrade{$part} =~ /:yes$/)); @@ -1439,7 +1429,6 @@ KEYWORDS # return if view submission with no grading option if ($ENV{'form.showgrading'} eq '' || (!&canmodify($usec))) { -# if (!&canmodify($usec)) { $request->print(''."\n"); $request->print(&show_grading_menu_form($symb,$url)) if (($ENV{'form.command'} eq 'submission') || @@ -1447,12 +1436,12 @@ KEYWORDS return; } + $result=''."\n". + ''."\n". + ''."\n"; # essay grading options if ($ENV{'form.handgrade'} eq 'yes') { - $result=''."\n". - ''."\n". - ''."\n"; my ($lastname,$givenn) = split(/,/,$ENV{'form.fullname'}); my $msgfor = $givenn.' '.$lastname; if (scalar(@col_fullnames) > 0) { @@ -1468,8 +1457,8 @@ KEYWORDS '/mailbkgrd.gif" width="14" height="10" name="mailicon'.$counter.'" />'."\n". '
 (Message will be sent when you click on Save & Next below.)'."\n" if ($ENV{'form.handgrade'} eq 'yes'); - $request->print($result); } + $request->print($result); my %seen = (); my @partlist; @@ -1496,26 +1485,21 @@ KEYWORDS if ($counter == $total) { my $endform='
'. ''."\n"; -# if ($ENV{'form.handgrade'} eq 'yes') { - $endform.='  '."\n"; - my $ntstu =''."\n"; - my $nsel = ($ENV{'form.NTSTU'} ne '' ? $ENV{'form.NTSTU'} : '1'); - $ntstu =~ s/
'; $endform.=&show_grading_menu_form($symb,$url); $request->print($endform); @@ -1525,15 +1509,15 @@ 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 (sort(split(/\:/,$$returnhash{$version.':keys'}))) { + $lasthash{$_}=$$returnhash{$version.':'.$_}; + $timestamp = scalar(localtime($$returnhash{$version.':timestamp'})); } } foreach ((keys %lasthash)) { @@ -1557,13 +1541,8 @@ sub keywords_highlight { (my $styleoff = $styleon) =~ s/\$styleon$_$styleoff\<\/font\>/gi; + $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; return $string; } @@ -1609,7 +1588,8 @@ sub processHandGrade { 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}); + 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; @@ -1626,48 +1606,50 @@ 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, + $ENV{'course.'.$ENV{'request.course.id'}.'.domain'}, + $ENV{'course.'.$ENV{'request.course.id'}.'.num'}); } - $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'); +# my (undef,undef,$fullname) = &getclasslist($ENV{'form.section'},'0'); + my (undef,undef,$fullname) = &getclasslist($ENV{'form.section'},'1'); if ($ENV{'form.refresh'} eq 'on') { my ($ctr,$total) = (0,0); while ($ctr < $ngrade) { @@ -1689,7 +1671,7 @@ sub processHandGrade { # Get the next/previous one or group of students my $firststu = $ENV{'form.unamedom0'}; my $laststu = $ENV{'form.unamedom'.($ngrade-1)}; - $ctr = 2; + my $ctr = 2; while ($laststu eq '') { $laststu = $ENV{'form.unamedom'.($ngrade-$ctr)}; $ctr++; @@ -1773,6 +1755,7 @@ sub saveHandGrade { $wgt = $ENV{'form.WGT'.$newflg.'_'.$_} eq '' ? 1 : $ENV{'form.WGT'.$newflg.'_'.$_}; my $partial= $pts/$wgt; + next if ($partial eq $record{'resource.'.$_.'.awarded'}); #do not update score for part if not changed. $newrecord{'resource.'.$_.'.awarded'} = $partial if ($record{'resource.'.$_.'.awarded'} ne $partial); my $reckey = 'resource.'.$_.'.solved'; @@ -2047,8 +2030,6 @@ sub viewgrades { ''; $result.=''; -# $result.='    '."\n"; #table listing all the students in a section/class #header of table @@ -2824,45 +2805,11 @@ sub displayPage { if ($record{'version'} eq '') { $studentTable.='
 No recorded submission for this problem
'; } else { - $studentTable.='
'. - ''. - ''. - ''. - ''; my %responseType = (); foreach my $partid (@{$parts}) { $responseType{$partid} = $curRes->responseType($partid); } - my ($version); - my %mark; - $mark{'correct_by_student'} = $checkIcon; - for ($version=1;$version<=$record{'version'};$version++) { - my $timestamp = scalar(localtime($record{$version.':timestamp'})); - $studentTable.=''; - my @versionKeys = split(/\:/,$record{$version.':keys'}); - my @displaySub = (); - foreach my $partid (@{$parts}) { - my @matchKey = grep /^resource\.$partid\..*?\.submission$/,@versionKeys; - next if ($record{"$version:resource.$partid.solved"} eq ''); - $displaySub[0].=(exists $record{$version.':'.$matchKey[0]}) ? - 'Part '.$partid.' '. - ($record{"$version:resource.$partid.tries"} eq '' ? 'Trial not counted' : - 'Trial '.$record{"$version:resource.$partid.tries"}).'  '. - &cleanRecord($record{$version.':'.$matchKey[0]},$responseType{$partid}).'
' : ''; - $displaySub[1].=(exists $record{"$version:resource.$partid.award"}) ? - 'Part '.$partid.'  '. - lc($record{"$version:resource.$partid.award"}).' '. - $mark{$record{"$version:resource.$partid.solved"}}.'
' : ''; -# $record{"$version:resource.$partid.solved"}.'
' : ''; - $displaySub[2].=(exists $record{"$version:resource.$partid.regrader"}) ? - $record{"$version:resource.$partid.regrader"}.' (Part: '.$partid.')' : ''; - } - $displaySub[2].=(exists $record{"$version:resource.regrader"}) ? - $record{"$version:resource.regrader"} : ''; - $studentTable.=''; - } - $studentTable.='
Date/TimeSubmissionStatus 
'.$timestamp.''.$displaySub[0].' '.$displaySub[1]. - ($displaySub[2] eq '' ? '' : 'Manually graded by '.$displaySub[2]).' 
'; + $studentTable.= &displaySubByDates(\%record,$parts,\%responseType,$checkIcon); } } elsif ($ENV{'form.lastSub'} eq 'all') { my $last = ($ENV{'form.lastSub'} eq 'last' ? 'last' : ''); @@ -2896,6 +2843,46 @@ sub displayPage { return ''; } +sub displaySubByDates { + my ($record,$parts,$responseType,$checkIcon) = @_; + my $studentTable='
'. + ''. + ''. + ''. + ''; + my ($version); + my %mark; + $mark{'correct_by_student'} = $checkIcon; + for ($version=1;$version<=$$record{'version'};$version++) { + my $timestamp = scalar(localtime($$record{$version.':timestamp'})); + $studentTable.=''; + my @versionKeys = split(/\:/,$$record{$version.':keys'}); + my @displaySub = (); + foreach my $partid (@{$parts}) { + my @matchKey = grep /^resource\.$partid\..*?\.submission$/,@versionKeys; + next if ($$record{"$version:resource.$partid.solved"} eq ''); + $displaySub[0].=(exists $$record{$version.':'.$matchKey[0]}) ? + 'Part '.$partid.' '. + ($$record{"$version:resource.$partid.tries"} eq '' ? 'Trial not counted' : + 'Trial '.$$record{"$version:resource.$partid.tries"}).'  '. + &cleanRecord($$record{$version.':'.$matchKey[0]},$$responseType{$partid}).'
' : ''; + $displaySub[1].=(exists $$record{"$version:resource.$partid.award"}) ? + 'Part '.$partid.'  '. + lc($$record{"$version:resource.$partid.award"}).' '. + $mark{$$record{"$version:resource.$partid.solved"}}.'
' : ''; +# $$record{"$version:resource.$partid.solved"}.'
' : ''; + $displaySub[2].=(exists $$record{"$version:resource.$partid.regrader"}) ? + $$record{"$version:resource.$partid.regrader"}.' (Part: '.$partid.')' : ''; + } + $displaySub[2].=(exists $$record{"$version:resource.regrader"}) ? + $$record{"$version:resource.regrader"} : ''; + $studentTable.=''; + } + $studentTable.='
Date/TimeSubmissionStatus 
'.$timestamp.''.$displaySub[0].' '.$displaySub[1]. + ($displaySub[2] eq '' ? '' : 'Manually graded by '.$displaySub[2]).' 
'; + return $studentTable; +} + sub updateGradeByPage { my ($request) = shift;