--- loncom/homework/grades.pm 2007/04/15 18:25:56 1.394 +++ loncom/homework/grades.pm 2007/06/13 17:20:12 1.399.2.1 @@ -1,7 +1,7 @@ # The LearningOnline Network with CAPA # The LON-CAPA Grading handler # -# $Id: grades.pm,v 1.394 2007/04/15 18:25:56 banghart Exp $ +# $Id: grades.pm,v 1.399.2.1 2007/06/13 17:20:12 albertel Exp $ # # Copyright Michigan State University Board of Trustees # @@ -102,10 +102,10 @@ sub get_symb { sub nameUserString { my ($type,$fullname,$uname,$udom) = @_; if ($type eq 'header') { - return ' Fullname (Username)'; + return ' Fullname (Username)'; } else { - return ' '.$fullname.' ('.$uname. - ($env{'user.domain'} eq $udom ? '' : ' ('.$udom.')').')'; + return ' '.$fullname.' ('.$uname. + ($env{'user.domain'} eq $udom ? '' : ' ('.$udom.')').')'; } } @@ -151,7 +151,7 @@ sub get_display_part { my ($partID,$symb)=@_; my $display=&Apache::lonnet::EXT('resource.'.$partID.'.display',$symb); if (defined($display) and $display ne '') { - $display.= " (id $partID)"; + $display.= " (id $partID)"; } else { $display=$partID; } @@ -164,9 +164,8 @@ sub showResourceInfo { my ($symb,$probTitle,$checkboxes) = @_; my $col=3; if ($checkboxes) { $col=4; } - my $result =''. - ''."\n"; + my $result = '

'.&mt('Current Resource').': '.$probTitle.'

'."\n"; + $result .='
'.&mt('Current Resource').': '. - $probTitle.'
'; my ($partlist,$handgrade,$responseType) = &response_type($symb); my %resptype = (); my $hdgrade='no'; @@ -186,8 +185,8 @@ sub showResourceInfo { $partsseen{$partID}=1; } my $display_part=&get_display_part($partID,$symb); - $result.=''. + $result.=''. ''; # ''; } @@ -218,7 +217,7 @@ sub get_order { sub cleanRecord { my ($answer,$response,$symb,$partid,$respid,$record,$order,$version, $uname,$udom) = @_; - my $grayFont = ''; + my $grayFont = ''; if ($response =~ /^(option|rank)$/) { my %answer=&Apache::lonnet::str2hash($answer); my %grading=&Apache::lonnet::str2hash($record->{$version."resource.$partid.$respid.submissiongrading"}); @@ -229,11 +228,11 @@ sub cleanRecord { } else { $toprow.=''; } - $bottomrow.=''; + $bottomrow.=''; } return '
Part: '.$display_part.' '. - $resID.'Part: '.$display_part.' '. + $resID.'Type: '.$responsetype.'
Handgrade: '.$handgrade.'
'.$answer{$foil}.' '.$grayFont.$foil.' '.$grayFont.$foil.' 
'. ''.$toprow.''. - ''. + ''. $grayFont.$bottomrow.''.'
Answer
'.$grayFont.'Option ID
'.$grayFont.'Option ID
'; } elsif ($response eq 'match') { my %answer=&Apache::lonnet::str2hash($answer); @@ -244,18 +243,18 @@ sub cleanRecord { my $item=shift(@items); if ($grading{$foil} == 1) { $toprow.=''.$item.' '; - $middlerow.=''.$grayFont.$answer{$foil}.' '; + $middlerow.=''.$grayFont.$answer{$foil}.' '; } else { $toprow.=''.$item.' '; - $middlerow.=''.$grayFont.$answer{$foil}.' '; + $middlerow.=''.$grayFont.$answer{$foil}.' '; } - $bottomrow.=''.$grayFont.$foil.' '; + $bottomrow.=''.$grayFont.$foil.' '; } return '
'. ''.$toprow.''. - ''. + ''. $middlerow.''. - ''. + ''. $bottomrow.''.'
Answer
'.$grayFont.'Item ID
'.$grayFont.'Item ID
'.$grayFont.'Option ID
'.$grayFont.'Option ID
'; } elsif ($response eq 'radiobutton') { my %answer=&Apache::lonnet::str2hash($answer); @@ -272,11 +271,11 @@ sub cleanRecord { } else { $toprow.='false'; } - $bottomrow.=''.$grayFont.$foil.' '; + $bottomrow.=''.$grayFont.$foil.' '; } return '
'. ''.$toprow.''. - ''. + ''. $grayFont.$bottomrow.''.'
Answer
'.$grayFont.'Option ID
'.$grayFont.'Option ID
'; } elsif ($response eq 'essay') { if (! exists ($env{'form.'.$symb})) { @@ -595,9 +594,9 @@ sub verifyreceipt { $receipt =~ s/[^\-\d]//g; my ($symb) = &get_symb($request); - my $title.='

Verifying Submission Receipt '. - $receipt.'

'."\n". - 'Resource: '.$env{'form.probTitle'}.'

'."\n"; + my $title.='

Verifying Submission Receipt '. + $receipt.'

'."\n". + '

Resource: '.$env{'form.probTitle'}.'



'."\n"; my ($string,$contents,$matches) = ('','',0); my (undef,undef,$fullname) = &getclasslist('all','0'); @@ -668,8 +667,8 @@ sub listStudents { $env{'form.probTitle'} = $env{'form.probTitle'} eq '' ? &Apache::lonnet::gettitle($symb) : $env{'form.probTitle'}; - my $result='

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

'; + my $result='

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

'; my ($table,undef,$hdgrade,$partlist,$handgrade) = &showResourceInfo($symb,$env{'form.probTitle'},($env{'form.showgrading'} eq 'yes')); @@ -881,15 +880,15 @@ LISTJAVASCRIPT if ($ctr == 0) { my $num_students=(scalar(keys(%$fullname))); if ($num_students eq 0) { - $gradeTable='
 There are no students currently enrolled.'; + $gradeTable='
 There are no students currently enrolled.'; } else { my $submissions='submissions'; if ($submitonly eq 'incorrect') { $submissions = 'incorrect submissions'; } if ($submitonly eq 'graded' ) { $submissions = 'ungraded submissions'; } if ($submitonly eq 'queued' ) { $submissions = 'queued submissions'; } - $gradeTable='
 '. + $gradeTable='
 '. 'No '.$submissions.' found for this resource for any students. ('.$num_students. - ' students checked for '.$submissions.')

'; + ' students checked for '.$submissions.')
'; } } elsif ($ctr == 1) { $gradeTable =~ s/type=checkbox/type=checkbox checked/; @@ -953,8 +952,8 @@ sub processGroup { my @stuchecked = &Apache::loncommon::get_env_multiple('form.stuinfo'); my $total = scalar(@stuchecked)-1; - foreach (@stuchecked) { - my ($uname,$udom,$fullname) = split(/:/); + foreach my $student (@stuchecked) { + my ($uname,$udom,$fullname) = split(/:/,$student); $env{'form.student'} = $uname; $env{'form.userdom'} = $udom; $env{'form.fullname'} = $fullname; @@ -1344,7 +1343,7 @@ INNERJS pDoc.write("
"); pDoc.write(""); - pDoc.write(" Compose Message for \"+fullname+\"

"); + pDoc.write("

 Compose Message for \"+fullname+\"



"); pDoc.write("
"); pDoc.write(""); @@ -1429,7 +1428,7 @@ INNERJS hDoc.$docopen; hDoc.write('$start_page_highlight_central'); hDoc.write(""); - hDoc.write(" Keyword Highlight Options

"); + hDoc.write("

 Keyword Highlight Options



"); hDoc.write("
'."\n"; + '('.$uname.($env{'user.domain'} eq $udom ? '' : ':'.$udom).')'."\n"; $student=~s/:/_/; # colon doen't work in javascript for names foreach my $apart (@$parts) { my ($part,$type) = &split_part_type($apart); @@ -3146,9 +3169,9 @@ sub editgrades { my ($request) = @_; my $symb=&get_symb($request); - my $title='

Current Grade Status

'; - $title.='Current Resource: '.$env{'form.probTitle'}.'
'."\n"; - $title.='Section: '.$env{'form.section'}.''."\n"; + my $title='

Current Grade Status

'; + $title.='

Current Resource: '.$env{'form.probTitle'}.'


'."\n"; + $title.='

Section: '.$env{'form.section'}.'

'."\n"; my $result= '
"); hDoc.write(""); @@ -1480,7 +1479,7 @@ sub gradeBox { '/check.gif" height="16" border="0" />'; my $wgt = &Apache::lonnet::EXT('resource.'.$partid.'.weight',$symb,$udom,$uname); my $wgtmsg = ($wgt > 0 ? '(problem weight)' : - 'problem weight assigned by computer'); + 'problem weight assigned by computer'); $wgt = ($wgt > 0 ? $wgt : '1'); my $score = ($$record{'resource.'.$partid.'.awarded'} eq '' ? '' : &compute_points($$record{'resource.'.$partid.'.awarded'},$wgt)); @@ -1626,27 +1625,44 @@ sub show_problem { $result.='

'; return $result; } + +sub files_exist { + my ($r, $symb) = @_; + my @students = &Apache::loncommon::get_env_multiple('form.stuinfo'); + + foreach my $student (@students) { + my ($uname,$udom,$fullname) = split(/:/,$student); + my %record = &Apache::lonnet::restore($symb,$env{'request.course.id'}, + $udom,$uname); + my ($string,$timestamp)= &get_last_submission(\%record); + foreach my $submission (@$string) { + my ($partid,$respid) = + ($submission =~ /^resource\.([^\.]*)\.([^\.]*)\.submission/); + my $files=&get_submitted_files($udom,$uname,$partid,$respid, + \%record); + return 1 if (@$files); + } + } + return 0; +} + sub download_all_link { my ($r,$symb) = @_; - my $courseid=$env{'request.course.id'}; - my @stuchecked = &Apache::loncommon::get_env_multiple('form.stuinfo'); - my $parts; - my $total = scalar(@stuchecked)-1; - my $all_students; - foreach my $stu_info (@stuchecked) { - $all_students .= $stu_info."\n"; - } - foreach my $part (&Apache::loncommon::get_env_multiple('form.vPart')) { - $parts .= $part."\n"; - } + my $all_students = + join("\n", &Apache::loncommon::get_env_multiple('form.stuinfo')); + + my $parts = + join("\n",&Apache::loncommon::get_env_multiple('form.vPart')); + my $identifier = &Apache::loncommon::get_cgi_id(); &Apache::lonnet::appenv('cgi.'.$identifier.'.students' => $all_students, 'cgi.'.$identifier.'.symb' => $symb, - 'cgi.'.$identifier.'.parts' => $parts, - 'cgi.'.$identifier.'.courseid' => $courseid); - $r->print('Download All Submitted Documents'); + 'cgi.'.$identifier.'.parts' => $parts,); + $r->print(''. + &mt('Download All Submitted Documents').''); return } + # --------------------------- show submissions of a student, option to grade sub submission { my ($request,$counter,$total) = @_; @@ -1660,9 +1676,9 @@ sub submission { if ($symb eq '') { $request->print("Unable to handle ambiguous references:."); return ''; } if (!&canview($usec)) { - $request->print('Unable to view requested student.('. - $uname.'@'.$udom.' in section '.$usec.' in course id '. - $env{'request.course.id'}.')'); + $request->print('Unable to view requested student.('. + $uname.':'.$udom.' in section '.$usec.' in course id '. + $env{'request.course.id'}.')'); $request->print(&show_grading_menu_form($symb)); return; } @@ -1681,9 +1697,11 @@ sub submission { &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'}; - &download_all_link($request,$symb); - $request->print('

 Submission Record

'."\n". - ' Resource: '.$env{'form.probTitle'}.''."\n"); + if ($env{'form.handgrade'} eq 'yes' && &files_exist($request, $symb)) { + &download_all_link($request, $symb); + } + $request->print('

 Submission Record

'."\n". + '

 Resource: '.$env{'form.probTitle'}.'

'."\n"); if ($env{'form.handgrade'} eq 'no') { my $checkMark='

 Note: Part(s) graded correct by the computer is marked with a '. @@ -1912,9 +1930,9 @@ KEYWORDS my $responsetype = $responseType->{$partid}->{$respid}; if (!exists($record{"resource.$partid.$respid.submission"})) { $lastsubonly.='
Part: '. - $display_part.' ( ID '.$respid. - ' )   '. - 'Nothing submitted - no attempts

'; + $display_part.' ( ID '.$respid. + ' )   '. + 'Nothing submitted - no attempts

'; next; } foreach (@$string) { @@ -1928,10 +1946,10 @@ KEYWORDS &most_similar($uname,$udom,$subval); if ($osim) { $osim=int($osim*100.0); - $similar="

Essay". + $similar="

Essay". " is $osim% similar to an essay by ". &Apache::loncommon::plainname($oname,$odom). - '

'. + '

'. &keywords_highlight($oessay). '

'; } @@ -1941,12 +1959,12 @@ KEYWORDS ($env{'form.lastSub'} eq 'hdgrade' && $$handgrade{$$part[0].'_'.$$part[1]} eq 'yes')) { my $display_part=&get_display_part($partid,$symb); - $lastsubonly.='
Debug -'.'Part: '. - $display_part.' ( hhhh ID '.$respid. - ' )   '; + $lastsubonly.='
Part: '. + $display_part.' ( ID '.$respid. + ' )   '; my $files=&get_submitted_files($udom,$uname,$partid,$respid,\%record); if (@$files) { - $lastsubonly.='
Like all files provided by users, this file may contain virusses
'; + $lastsubonly.='
Like all files provided by users, this file may contain virusses
'; my $file_counter = 0; foreach my $file (@$files) { $file_counter ++; @@ -2088,22 +2106,27 @@ sub get_last_submission { 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'})); + 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. @@ -2113,8 +2136,8 @@ sub keywords_highlight { my $styleon = $env{'form.kwstyle'} eq '' ? '' : $env{'form.kwstyle'}; (my $styleoff = $styleon) =~ s/\$styleon$_$styleoff<\/font>/gi; + foreach my $keyword (@keylist) { + $string =~ s/\b\Q$keyword\E(\b|\.)/$styleon$keyword$styleoff<\/font>/gi; } return $string; } @@ -2140,7 +2163,7 @@ sub processHandGrade { 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; } @@ -2369,7 +2392,7 @@ sub processHandGrade { $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); @@ -2542,8 +2565,8 @@ sub handback_files { $newflg.'_'.$part_resp.'_returndoc'.$file_counter, $save_file_name); if ($result !~ m|^/uploaded/|) { - $request->print(' An errror occured ('.$result. - ') while trying to upload '.$newflg.'_'.$part_resp.'_returndoc'.$file_counter.'
'); + $request->print('An errror occured ('.$result. + ') while trying to upload '.$newflg.'_'.$part_resp.'_returndoc'.$file_counter.'
'); } else { # mark the file as read only my @files = ($save_file_name); @@ -2939,8 +2962,8 @@ sub viewgrades { $env{'course.'.$env{'request.course.id'}.'.domain'}); &Apache::lonnet::clear_EXT_cache_status(); - my $result='

'.&mt('Manual Grading').'

'; - $result.='Current Resource: '.$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($symb); @@ -3068,8 +3091,8 @@ sub viewgrades { 'onClick="javascript:submit();" TARGET=_self />'."\n"; if (scalar(%$fullname) eq 0) { my $colspan=3+scalar(@parts); - $result='There are no students in section "'.$env{'form.section'}. - '" with enrollment status "'.$env{'form.Status'}.'" to modify or grade.'; + $result='There are no students in section "'.$env{'form.section'}. + '" with enrollment status "'.$env{'form.Status'}.'" to modify or grade.'; } $result.=&show_grading_menu_form($symb); return $result; @@ -3086,7 +3109,7 @@ sub viewstudentgrade { "\n".$ctr.' 
 '. ''.$fullname.' '. - '('.$uname.($env{'user.domain'} eq $udom ? '' : ':'.$udom).')
'."\n"; $result.= ''. @@ -3216,7 +3239,7 @@ sub editgrades { my $usec=$classlist->{"$uname:$udom"}[5]; if (!&canmodify($usec)) { my $numcols=scalar(@partid)*4+2; - $noupdate.=$line.""; + $noupdate.=$line.""; next; } my %aggregate = (); @@ -3451,7 +3474,7 @@ sub csvuploadmap_header { my $ignore=&mt('Ignore First Line'); $request->print(< -

Uploading Class Grades

+

Uploading Class Grades

$result

Identify fields

@@ -3614,7 +3637,7 @@ sub csvuploadoptions { my $ignore=&mt('Ignore First Line'); $request->print(< -

Uploading Class Grade Options

+

Uploading Class Grade Options

Not allowed to modify student
Not allowed to modify student