--- loncom/homework/grades.pm 2003/07/23 18:04:51 1.124 +++ loncom/homework/grades.pm 2003/07/25 20:35:40 1.125 @@ -1,7 +1,7 @@ # The LearningOnline Network with CAPA # The LON-CAPA Grading handler # -# $Id: grades.pm,v 1.124 2003/07/23 18:04:51 ng Exp $ +# $Id: grades.pm,v 1.125 2003/07/25 20:35:40 ng Exp $ # # Copyright Michigan State University Board of Trustees # @@ -33,6 +33,7 @@ # June-August H.K. Ng # Year 2003 # February, March H.K. Ng +# July, H. K. Ng # package Apache::grades; @@ -98,7 +99,8 @@ sub get_fullname { #--- Get the partlist and the response type for a given problem. --- #--- Indicate if a response type is coded handgraded or not. --- sub response_type { - my ($url) = shift; + my ($url,$symb) = shift; + $symb=($ENV{'form.symb'} ne '' ? $ENV{'form.symb'} : (&Apache::lonnet::symbread($url))) if ($symb eq ''); my $allkeys = &Apache::lonnet::metadata($url,'keys'); my %seen = (); my (@partlist,%handgrade); @@ -107,7 +109,9 @@ sub response_type { my ($responsetype,$part) = split(/_/,$_,2); my ($partid,$respid) = split(/_/,$part); $responsetype =~ s/response$//; # make it compatible w/ navmaps - should move to that!! - $handgrade{$part} = $responsetype.':'.($allkeys =~ /parameter_$part\_handgrade/ ? 'yes' : 'no'); +# my ($value) = &Apache::lonnet::EXT('resource.'.$part.'.handgrade',$symb); +# $handgrade{$part} = $responsetype.':'.($value eq 'yes' ? 'yes' : 'no'); #a bug $value is 'yes' regardless + $handgrade{$part} = $responsetype.':'.(($allkeys =~ /parameter_$part\_handgrade/) ? 'yes' : 'no'); next if ($seen{$partid} > 0); $seen{$partid}++; push @partlist,$partid; @@ -321,6 +325,7 @@ sub jscriptNform { ''."\n". ''."\n". ''."\n". + ''."\n". ''."\n". ''."\n". ''."\n". @@ -645,9 +650,9 @@ sub sub_page_js { $request->print(< function updateRadio(formname,id,weight) { - var gradeBox = eval("formname.GD_BOX"+id); - var radioButton = eval("formname.RADVAL"+id); - var oldpts = eval("formname.oldpts"+id+".value"); + var gradeBox = formname["GD_BOX"+id]; + var radioButton = formname["RADVAL"+id]; + var oldpts = formname["oldpts"+id].value; var pts = checkSolved(formname,id) == 'update' ? gradeBox.value : oldpts; gradeBox.value = pts; var resetbox = false; @@ -669,7 +674,7 @@ sub sub_page_js { var resp = confirm("You entered a value ("+pts+ ") greater than the weight for the part. Accept?"); if (resp == false) { - gradeBox.value = ""; + gradeBox.value = oldpts; return; } } @@ -681,18 +686,17 @@ sub sub_page_js { } } updateSelect(formname,id); - var stores = eval("formname.stores"+id); - stores.value = "0"; + formname["stores"+id].value = "0"; } function writeBox(formname,id,pts) { - var gradeBox = eval("formname.GD_BOX"+id); + var gradeBox = formname["GD_BOX"+id]; if (checkSolved(formname,id) == 'update') { gradeBox.value = pts; } else { - var oldpts = eval("formname.oldpts"+id+".value"); + var oldpts = formname["oldpts"+id].value; gradeBox.value = oldpts; - var radioButton = eval("formname.RADVAL"+id); + var radioButton = formname["RADVAL"+id]; for (var i=0; i'."\n"; if ($$record{'resource.'.$partid.'.solved'} eq 'excused') { $result.=''. - ''."\n"; + ''; } else { $result.=''. - ''."\n"; + ''; } + $result.=''."\n"; $result.="  \n"; $result.=''."\n". ''."\n". @@ -1340,7 +1343,8 @@ KEYWORDS $request->print(&show_problem($request,$symb,$uname,$udom,1,1)); } my %record = &Apache::lonnet::restore($symb,$ENV{'request.course.id'},$udom,$uname); - my ($partlist,$handgrade) = &response_type($url); + + my ($partlist,$handgrade) = &response_type($url,$symb); # Display student info $request->print(($counter == 0 ? '' : '
')); @@ -1438,7 +1442,8 @@ KEYWORDS if (!exists($record{'resource.'.$partid.'.'.$respid.'.submission'})) { $lastsubonly.='Part '. $partid.' ( ID '.$respid. - ' )   Nothing submitted - no attempts

'; + ' )   '. + 'Nothing submitted - no attempts

'; } else { foreach (@$string) { my ($partid,$respid) = /^resource\.(\w+)\.(\w+)\.submission/; @@ -1465,7 +1470,6 @@ KEYWORDS 'this file may contain virusses
':''). 'Submitted Answer: '.($responsetype =~ /^(essay|option)$/ ? '
' : ''). -# &cleanRecord(&keywords_highlight($subval),$responsetype). &cleanRecord($subval,$responsetype,$symb). ($responsetype =~ /^(essay|option)$/ ? '

' : '

').$similar."\n" @@ -1596,7 +1600,7 @@ sub get_last_submission { } } } - @string = $string[0] eq '' ? 'Nothing submitted - no attempts.' : @string; + @string = $string[0] eq '' ? 'Nothing submitted - no attempts.' : @string; return \@string,\$timestamp; } @@ -1766,7 +1770,7 @@ sub processHandGrade { } } $ctr = 0; - my ($partlist,$handgrade) = &response_type($ENV{'form.url'}); + my ($partlist,$handgrade) = &response_type($ENV{'form.url'},$symb); @parsedlist = reverse @parsedlist if ($button eq 'Previous'); foreach my $student (@parsedlist) { my ($uname,$udom) = split(/:/,$student); @@ -1815,14 +1819,23 @@ sub saveHandGrade { my %newrecord = (); my ($pts,$wgt) = ('',''); foreach (split(/:/,$ENV{'form.partlist'.$newflg})) { - if ($ENV{'form.GD_SEL'.$newflg.'_'.$_} eq 'excused') { + my $dropMenu = $ENV{'form.GD_SEL'.$newflg.'_'.$_}; + if ($dropMenu eq 'excused') { if ($record{'resource.'.$_.'.solved'} ne 'excused') { $newrecord{'resource.'.$_.'.solved'} = 'excused'; if (exists($record{'resource.'.$_.'.awarded'})) { $newrecord{'resource.'.$_.'.awarded'} = ''; } + $newrecord{'resource.'.$_.'.regrader'}="$ENV{'user.name'}:$ENV{'user.domain'}"; } - } else { + } elsif ($dropMenu eq 'reset status' + && exists($record{'resource.'.$_.'.solved'})) { #don't bother if no old records -> no attempts + $newrecord{'resource.'.$_.'.tries'} = 0; + $newrecord{'resource.'.$_.'.solved'} = ''; + $newrecord{'resource.'.$_.'.award'} = ''; + $newrecord{'resource.'.$_.'.awarded'} = 0; + $newrecord{'resource.'.$_.'.regrader'}="$ENV{'user.name'}:$ENV{'user.domain'}"; + } elsif ($dropMenu eq '') { $pts = ($ENV{'form.GD_BOX'.$newflg.'_'.$_} ne '' ? $ENV{'form.GD_BOX'.$newflg.'_'.$_} : $ENV{'form.RADVAL'.$newflg.'_'.$_}); @@ -1865,10 +1878,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; @@ -1899,15 +1912,13 @@ sub viewgrades_js { } } else { - textbox.value = point; + textbox.value = parseFloat(point); } for (i=0;i'."\n". ''."\n". ''."\n". + ''."\n". ''."\n"; $result.='

Assign Common Grade To '; @@ -2062,7 +2071,7 @@ sub viewgrades { '
'; #radio buttons/text box for assigning points for a section or class. #handles different parts of a problem - my ($partlist,$handgrade) = &response_type($ENV{'form.url'}); + my ($partlist,$handgrade) = &response_type($url,$symb); my %weight = (); my $ctsparts = 0; $result.=''; @@ -2098,7 +2107,9 @@ sub viewgrades { 'onChange="javascript:writeRadText(\''.$partid.'\','. $weight{$partid}.')"> '. ''. - ''."\n"; +# ''."\n"; + ''. + ''."\n"; $ctsparts++; } $result.='
'.'
'.''."\n". @@ -2189,10 +2200,13 @@ sub viewstudentgrade { $result.='\n"; } else { $result.=' Old '.$display.' '. - ' New '.$display.' '; + $display =~ s/Number of Attempts/Tries/; + $header .= ' Old '.$display.' '. + ' New '.$display.' '; $columns{$partid}+=2; } } @@ -2302,8 +2317,20 @@ sub editgrades { } elsif ($partial == 0) { $score = 'incorrect_by_override'; } - $score = 'excused' if (($ENV{'form.GD_'.$user.'_'.$_.'_solved'} eq 'excused') && - ($score ne 'excused')); + my $dropMenu = $ENV{'form.GD_'.$user.'_'.$_.'_solved'}; + $score = 'excused' if (($dropMenu eq 'excused') && ($score ne 'excused')); + + if ($dropMenu eq 'reset status' && + $old_score ne '') { # ignore if no previous attempts => nothing to reset + print "reset status
"; + $newrecord{'resource.'.$_.'.tries'} = 0; + $newrecord{'resource.'.$_.'.solved'} = ''; + $newrecord{'resource.'.$_.'.award'} = ''; + $newrecord{'resource.'.$_.'.awarded'} = 0; + $newrecord{'resource.'.$_.'.regrader'}="$ENV{'user.name'}:$ENV{'user.domain'}"; + $updateflag = 1; + } + $line .= ''.$old_aw.' '. ''.$awarded. ($score eq 'excused' ? $score : '').' '; @@ -2347,7 +2374,7 @@ sub editgrades { } $result .= ''."\n". &show_grading_menu_form ($symb,$url); - my $msg = 'Number of records updated = '.$rec_update. + my $msg = '
Number of records updated = '.$rec_update. ' for '.$count.' student'.($count <= 1 ? '' : 's').'.
'. 'Total number of students = '.$ENV{'form.total'}.'
'; return $title.$msg.$result; @@ -2679,9 +2706,9 @@ function checkPickOne(formname) { alert("Please select the student you wish to grade."); return; } - var ptr = pullDownSelection(formname.selectpage); - formname.page.value = eval("formname.page"+ptr+".value"); - formname.title.value = eval("formname.title"+ptr+".value"); + ptr = pullDownSelection(formname.selectpage); + formname.page.value = formname["page"+ptr].value; + formname.title.value = formname["title"+ptr].value; formname.submit(); } @@ -2761,7 +2788,7 @@ LISTJAVASCRIPT $studentTable.='  ' if ($ptr%4 == 3); $studentTable.=' ' if ($ptr%4 == 0); $studentTable.=''."\n"; - $studentTable.='
 '."\n"; $studentTable.=&show_grading_menu_form($symb,$url); @@ -2830,11 +2857,13 @@ sub displayPage { my $studentTable='
'."\n". ''."\n". + ''."\n". ''."\n". ''."\n". ''."\n". ''."\n". ''."\n". + ''."\n". ''."\n"; my $checkIcon = 'No recorded submission for this problem
'; @@ -2910,7 +2940,7 @@ sub displayPage { $navmap->untieHashes(); $studentTable.=''."\n". - '  '. '
'."\n"; $studentTable.=&show_grading_menu_form($symb,$url); @@ -2976,7 +3006,7 @@ sub updateGradeByPage { return; } my $result='

 '.$ENV{'form.title'}.'

'; - $result.='

 Student: '.$$fullname{$ENV{'form.student'}}. + $result.='

 Student: '.$ENV{'form.fullname'}. ' ('.$uname.($udom eq $cdom ? '':':'.$udom).')

'."\n"; $request->print($result); @@ -2991,7 +3021,7 @@ sub updateGradeByPage { my $studentTable='
'. ''. - ''. + ''. ''. ''. ''; @@ -3023,31 +3053,40 @@ sub updateGradeByPage { my $score; if ($partial > 0) { $score = 'correct_by_override'; - } elsif ($partial == 0) { + } elsif ($newpts ne '') { #empty is taken as 0 $score = 'incorrect_by_override'; } - if ($ENV{'form.GD_SEL'.$question.'_'.$partid} eq 'excused') { + my $dropMenu = $ENV{'form.GD_SEL'.$question.'_'.$partid}; + if ($dropMenu eq 'excused') { $partial = ''; $score = 'excused'; + } elsif ($dropMenu eq 'reset status' + && $ENV{'form.solved'.$question.'_'.$partid} ne '') { #update only if previous record exists + print "got to reset = $ENV{'form.solved'.$question.'_'.$partid}:
"; + $newrecord{'resource.'.$partid.'.tries'} = 0; + $newrecord{'resource.'.$partid.'.solved'} = ''; + $newrecord{'resource.'.$partid.'.award'} = ''; + $newrecord{'resource.'.$partid.'.awarded'} = 0; + $newrecord{'resource.'.$partid.'.regrader'} = "$ENV{'user.name'}:$ENV{'user.domain'}"; + $changeflag++; + $newpts = ''; } + my $oldstatus = $ENV{'form.solved'.$question.'_'.$partid}; $displayPts[0].=' Part '.$partid.' = '. (($oldstatus eq 'excused') ? 'excused' : $oldpts). ' 
'; $displayPts[1].=' Part '.$partid.' = '. - ($oldstatus eq 'correct_by_student' ? $oldpts : - (($score eq 'excused') ? 'excused' : $newpts)). + (($score eq 'excused') ? 'excused' : $newpts). ' 
'; $question++; - if (($oldstatus eq 'correct_by_student') || - ($newpts eq $oldpts && $score eq $oldstatus)) - { - next; - } + next if ($dropMenu eq 'reset status' || ($newpts == $oldpts && $score ne 'excused')); + $newrecord{'resource.'.$partid.'.awarded'} = $partial if $partial ne ''; - $newrecord{'resource.'.$partid.'.solved'} = $score; - $newrecord{'resource.'.$partid.'.regrader'}="$ENV{'user.name'}:$ENV{'user.domain'}"; + $newrecord{'resource.'.$partid.'.solved'} = $score if $score ne ''; + $newrecord{'resource.'.$partid.'.regrader'} = "$ENV{'user.name'}:$ENV{'user.domain'}" + if (scalar(keys(%newrecord)) > 0); $changeflag++; } @@ -3055,6 +3094,7 @@ sub updateGradeByPage { &Apache::lonnet::cstore(\%newrecord,$symbx,$ENV{'request.course.id'}, $udom,$uname); } + $studentTable.=''. ''. ''; @@ -3396,7 +3436,7 @@ SCANTRONFORM #--- Show a Grading Menu button - Calls the next routine --- sub show_grading_menu_form { my ($symb,$url)=@_; - my $result.=''."\n". + my $result.='
'."\n". ''."\n". ''."\n". ''."\n".
 No  Prob.  Title  Previous Score  New Score 
'.$displayPts[0].''.$displayPts[1].'