--- loncom/homework/grades.pm 2003/07/17 22:08:25 1.118 +++ loncom/homework/grades.pm 2003/07/22 18:59:57 1.122 @@ -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.122 2003/07/22 18:59:57 ng Exp $ # # Copyright Michigan State University Board of Trustees # @@ -123,24 +123,25 @@ sub showResourceInfo { my $result =''. ''."\n"; my ($partlist,$handgrade) = &response_type($url); - my ($resptype,$hdgrade)=('','no'); + my %resptype = (); #,$hdgrade)=('','no'); + my $hdgrade='no'; for (sort keys(%$handgrade)) { my ($responsetype,$handgrade)=split(/:/,$$handgrade{$_}); - $resptype = $responsetype; + my $partID = (split(/_/))[0]; + $resptype{$partID} = $responsetype; $hdgrade = $handgrade if ($handgrade eq 'yes'); - $result.=''. + $result.=''. ''; # ''; } $result.='
Current Resource: '.$probTitle.'
Part '.(split(/_/))[0].'
Part '.$partID.'Type: '.$responsetype.'
Handgrade: '.$handgrade.'
'."\n"; - return $result,$resptype,$hdgrade,$partlist,$handgrade; + return $result,\%resptype,$hdgrade,$partlist,$handgrade; } #--- Clean response type for display #--- Currently filters option response type only. sub cleanRecord { - my ($answer,$response) = @_; - $answer =~ s|^
||; + my ($answer,$response,$symb) = @_; if ($response eq 'option') { my (@IDs,@ans); foreach (split(/\&/,&Apache::lonnet::unescape($answer))) { @@ -156,6 +157,21 @@ sub cleanRecord { (join ''.$grayFont,@IDs).''. ''; } + if ($response eq 'essay') { + if (! exists ($ENV{'form.'.$symb})) { + my (%keyhash) = &Apache::lonnet::dump('nohist_handgrade', + $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.'.$symb} = 1; # so that we don't have to read it from disk for multiple sub of the same prob. + } + return &keywords_highlight($answer); + } return $answer; } @@ -198,6 +214,7 @@ COMMONJSFUNCTIONS #--- section, ids and fullnames for each user. sub getclasslist { my ($getsec,$filterlist) = @_; + $getsec = $getsec eq '' ? 'all' : $getsec; my $classlist=&Apache::loncoursedata::get_classlist(); # Bail out if we were unable to get the classlist return if (! defined($classlist)); @@ -431,7 +448,7 @@ sub listStudents { my $result='

 '.$viewgrade. ' Submissions for a Student or a Group of Students

'; - my ($table,$resptype,$hdgrade,$partlist,$handgrade) = &showResourceInfo($url,$ENV{'form.probTitle'}); + my ($table,undef,$hdgrade,$partlist,$handgrade) = &showResourceInfo($url,$ENV{'form.probTitle'}); $result.=$table; $request->print(<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". @@ -487,10 +503,10 @@ LISTJAVASCRIPT $gradeTable.=' last sub only'."\n". ' last sub & parts info'."\n". + ' by dates and submissions'."\n". ' all details'."\n". ''."\n". ''."\n". - ''."\n". '
'."\n". '
'."\n". ''."\n". @@ -709,9 +725,10 @@ sub sub_page_js { } function checkSolved(formname,id) { - if (eval("formname.solved"+id+".value") == "correct_by_student") { + if (eval("formname.solved"+id+".value") == "correct_by_student" && formname.overRideScore.value == 'no') { var reply = confirm("This problem has been graded correct by the computer. Do you want to change the score?"); if (!reply) {return "noupdate";} + formname.overRideScore.value = 'yes'; } return "update"; } @@ -722,9 +739,9 @@ sub sub_page_js { return; } -//=========== Check that a point is assigned for all the parts (essay grading only) ============ +//=========== Check that a point is assigned for all the parts ============ function checksubmit(formname,val,total,parttot) { - document.SCORE.gradeOpt.value = val; + formname.gradeOpt.value = val; if (val == "Save & Next") { for (i=0;i<=total;i++) { for (j=0;j //===================== Show list of keywords ==================== - function keywords(keyform) { - var nret = prompt("Keywords list, separated by a space. Add/delete to list if desired.",keyform.value); + function keywords(formname) { + var nret = prompt("Keywords list, separated by a space. Add/delete to list if desired.",formname.keywords.value); if (nret==null) return; - keyform.value = nret; + formname.keywords.value = nret; - document.SCORE.refresh.value = "on"; - if (document.SCORE.keywords.value != "") { - document.SCORE.submit(); + formname.refresh.value = "on"; + if (formname.keywords.value != "") { + formname.submit(); } return; } @@ -1033,16 +1057,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"); @@ -1172,6 +1186,7 @@ sub submission { (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 ''; @@ -1185,7 +1200,10 @@ sub submission { return; } + $ENV{'form.lastSub'} = ($ENV{'form.lastSub'} eq '' ? 'datesub' : $ENV{'form.lastSub'}); my $last = ($ENV{'form.lastSub'} eq 'last' ? 'last' : ''); + my $checkIcon = ''; # header info if ($counter == 0) { @@ -1198,8 +1216,6 @@ sub submission { ' Resource: '.$ENV{'form.probTitle'}.''."\n"); if ($ENV{'form.handgrade'} eq 'no') { - my $checkIcon = ''; my $checkMark='

 Note: Part(s) graded correct by the computer is marked with a '. $checkIcon.' symbol.'."\n"; $request->print($checkMark); @@ -1229,12 +1245,17 @@ sub submission { $ENV{'form.savemsgN'} = $keyhash{$symb.'_savemsgN'} ne '' ? $keyhash{$symb.'_savemsgN'} : '0'; } + my $overRideScore = $ENV{'form.overRideScore'} eq '' ? 'no' : $ENV{'form.overRideScore'}; $request->print(''."\n". ''."\n". ''."\n". + ''."\n". + ''."\n". ''."\n". ''."\n". + ''."\n". + ''."\n". ''."\n". ''."\n". ''."\n". @@ -1242,7 +1263,6 @@ sub submission { ''."\n". ''."\n". ''."\n". - ''."\n". ''."\n". ''."\n". ''."\n". @@ -1270,7 +1290,7 @@ sub submission { # $request->print(<Keyword Options:  -List    +List    Paste Selection to List    Highlight Attribute

@@ -1290,7 +1310,6 @@ KEYWORDS $request->print('


') if ($counter > 0); $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); @@ -1377,8 +1396,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"; @@ -1391,7 +1409,7 @@ KEYWORDS if (!exists($record{'resource.'.$partid.'.'.$respid.'.submission'})) { $lastsubonly.='Part '. $partid.' ( ID '.$respid. - ' )   Nothing submitted

'; + ' )   Nothing submitted - no attempts

'; } else { foreach (@$string) { my ($partid,$respid) = /^resource\.(\w+)\.(\w+)\.submission/; @@ -1416,9 +1434,12 @@ KEYWORDS '"> File uploaded by student '. 'Like all files provided by users, '. 'this file may contain virusses
':''). - 'Submitted Answer: '.($responsetype eq 'essay' ? '
' : ''). - &cleanRecord(&keywords_highlight($subval),$responsetype). - ($responsetype eq 'essay' ? '

' : '

').$similar."\n" + 'Submitted Answer: '.($responsetype =~ /^(essay|option)$/ ? + '
' : ''). +# &cleanRecord(&keywords_highlight($subval),$responsetype). + &cleanRecord($subval,$responsetype,$symb). + ($responsetype =~ /^(essay|option)$/ ? '

' : + '

').$similar."\n" if ($ENV{'form.lastSub'} eq 'lastonly' || ($ENV{'form.lastSub'} eq 'hdgrade' && $$handgrade{$part} =~ /:yes$/)); @@ -1430,29 +1451,34 @@ KEYWORDS $lastsubonly.=''."\n"; $request->print($lastsubonly); } - } else { + } elsif ($ENV{'form.lastSub'} eq 'datesub') { + my (undef,$responseType,undef,$parts) = &showResourceInfo($url); + $request->print(&displaySubByDates(\$symb,\%record,$parts,$responseType,$checkIcon)); + } elsif ($ENV{'form.lastSub'} =~ /^(last|all)$/) { $request->print(&Apache::loncommon::get_previous_attempt($symb,$uname,$udom, $ENV{'request.course.id'}, $last,'.submission', 'Apache::grades::keywords_highlight')); } + + $request->print(''."\n"); # 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)) + my $toGrade.='  '."\n" if (&canmodify($usec)); + $toGrade.=''."\n"; + $toGrade.=&show_grading_menu_form($symb,$url) if (($ENV{'form.command'} eq 'submission') || ($ENV{'form.command'} eq 'processGroup' && $counter == $total)); + $request = print($toGrade); return; } - # essay grading options + # essay grading message center 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) { @@ -1461,6 +1487,8 @@ KEYWORDS } $msgfor =~ s/\'/\\'/g; #' stupid emacs - no! javascript # $result.=''."\n". + $result=''."\n". + ''."\n"; $result.=' '. 'Compose Message to student'.(scalar(@col_fullnames) >= 1 ? 's' : '').'  '. @@ -1494,28 +1522,22 @@ KEYWORDS # print end of form if ($counter == $total) { - my $endform='\n"; -# } else { -# $result.=''. -# "\n"; -# $result.=''."\n"; + } else { + $result.=''. + "\n"; + $result.=''."\n"; } } $result.=''; @@ -2268,7 +2295,7 @@ sub editgrades { my $awarded = $ENV{'form.GD_'.$user.'_'.$part.'_'.$type}; if ($awarded ne '' && $awarded ne $old_aw) { $newrecord{'resource.'.$part.'.'.$type}= $awarded; - $newrecord{'resource.'.$part.'regrader'}="$ENV{'user.name'}:$ENV{'user.domain'}"; + $newrecord{'resource.'.$part.'.regrader'}="$ENV{'user.name'}:$ENV{'user.domain'}"; $updateflag=1; } $line .= ''. @@ -2397,7 +2424,7 @@ sub csvuploadmap_header { $javascript=&csvupload_javascript_forward_associate(); } - my ($result,$resptype,$hdgrade,$partlist,$handgrade) = &showResourceInfo($url,$ENV{'form.probTitle'}); + my ($result) = &showResourceInfo($url,$ENV{'form.probTitle'}); $request->print(< @@ -2609,7 +2636,7 @@ sub csvuploadassign { # #------------------------------------------------------------------- # -#-------------- Next few routines handles grading by page/sequence +#-------------- Next few routines handle grading by page/sequence # #--- Select a page/sequence and a student to grade sub pickStudentPage { @@ -2668,7 +2695,7 @@ LISTJAVASCRIPT $result.=' Submission Details: '. ' none'."\n". - ' dates and submissions'."\n". + ' by dates and submissions'."\n". ' all details'."\n"; $result.=''."\n". @@ -2798,7 +2825,8 @@ sub displayPage { if($curRes == $iterator->BEGIN_MAP) { $depth++; } if($curRes == $iterator->END_MAP) { $depth--; } - if (ref($curRes) && $curRes->is_problem() && !$curRes->randomout) { +# if (ref($curRes) && $curRes->is_problem() && !$curRes->randomout) { + if (ref($curRes) && $curRes->is_problem()) { my $parts = $curRes->parts(); my $title = $curRes->compTitle(); my $symbx = $curRes->symb(); @@ -2824,45 +2852,11 @@ sub displayPage { if ($record{'version'} eq '') { $studentTable.='
 No recorded submission for this problem
'; } else { - $studentTable.='
'. - ''."\n"; -# if ($ENV{'form.handgrade'} eq 'yes') { - $endform.='  '."\n"; - my $ntstu =''."\n"; - my $nsel = ($ENV{'form.NTSTU'} ne '' ? $ENV{'form.NTSTU'} : '1'); - $ntstu =~ s/
'.$old_aw.' 
'. - ''. - ''. - ''. - ''; 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(\$symbx,\%record,$parts,\%responseType,$checkIcon); } } elsif ($ENV{'form.lastSub'} eq 'all') { my $last = ($ENV{'form.lastSub'} eq 'last' ? 'last' : ''); @@ -2896,6 +2890,47 @@ sub displayPage { return ''; } +sub displaySubByDates { + my ($symbx,$record,$parts,$responseType,$checkIcon) = @_; + my $studentTable='
'. + ''. + ''. + ''. + ''; + my ($version); + my %mark; + $mark{'correct_by_student'} = $checkIcon; + return '
 Nothing submitted - no attempts
' + if (!exists($$record{'1:timestamp'})); + 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},$$symbx).'
' : ''; + $displaySub[1].=(exists $$record{"$version:resource.$partid.award"}) ? + 'Part '.$partid.'  '. + lc($$record{"$version:resource.$partid.award"}).' '. + $mark{$$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; @@ -3398,7 +3433,7 @@ sub gradingmenu { GRADINGMENUJS &commonJSfunctions($request); my $result='

 Manual Grading/View Submission

'; - my ($table,$resptype,$hdgrade) = &showResourceInfo($url,$probTitle); + my ($table,undef,$hdgrade) = &showResourceInfo($url,$probTitle); $result.=$table; my (undef,$sections) = &getclasslist('all','0'); my $savedState = &savedState(); @@ -3410,7 +3445,6 @@ GRADINGMENUJS $result.='
'."\n". ''."\n". ''."\n". - ''."\n". ''."\n". ''."\n". ''."\n".