--- loncom/homework/grades.pm 2023/02/12 21:01:30 1.792 +++ loncom/homework/grades.pm 2023/04/02 03:16:28 1.793 @@ -1,7 +1,7 @@ # The LearningOnline Network with CAPA # The LON-CAPA Grading handler # -# $Id: grades.pm,v 1.792 2023/02/12 21:01:30 raeburn Exp $ +# $Id: grades.pm,v 1.793 2023/04/02 03:16:28 raeburn Exp $ # # Copyright Michigan State University Board of Trustees # @@ -2558,182 +2558,12 @@ sub submission { # (3) All transactions (by date) # (4) The whole record (with detailed information for all transactions) - my ($string,$timestamp,$lastgradetime,$lastsubmittime) = - &get_last_submission(\%record,$is_tool); - - my $lastsubonly; - - if ($timestamp eq '') { - $lastsubonly.='
'.$string->[0].'
'; - } elsif ($is_tool) { - $lastsubonly = - '
' - .''.&mt('Date Grade Passed Back:').' '.$timestamp."
\n"; - } else { - my ($shownsubmdate,$showngradedate); - if ($lastsubmittime && $lastgradetime) { - $shownsubmdate = &Apache::lonlocal::locallocaltime($lastsubmittime); - if ($lastgradetime > $lastsubmittime) { - $showngradedate = &Apache::lonlocal::locallocaltime($lastgradetime); - } - } else { - $shownsubmdate = $timestamp; - } - $lastsubonly = - '
' - .''.&mt('Date Submitted:').' '.$shownsubmdate."\n"; - if ($showngradedate) { - $lastsubonly .= '
'.&mt('Date Graded:').' '.$showngradedate."\n"; - } - - my %seenparts; - my @part_response_id = &flatten_responseType($responseType); - foreach my $part (@part_response_id) { - my ($partid,$respid) = @{ $part }; - my $display_part=&get_display_part($partid,$symb); - if ($env{"form.$uname:$udom:$partid:submitted_by"}) { - if (exists($seenparts{$partid})) { next; } - $seenparts{$partid}=1; - $request->print( - ''.&mt('Part: [_1]',$display_part).''. - ' '.&mt('Collaborative submission by: [_1]', - ''. - $$fullname{$env{"form.$uname:$udom:$partid:submitted_by"}}.''). - '
'); - next; - } - my $responsetype = $responseType->{$partid}->{$respid}; - if (!exists($record{"resource.$partid.$respid.submission"})) { - $lastsubonly.="\n".'
'. - ''.&mt('Part: [_1]',$display_part).''. - ' '. - '('.&mt('Response ID: [_1]',$respid).')'. - '   '. - ''.&mt('Nothing submitted - no attempts.').'

'; - next; - } - foreach my $submission (@$string) { - my ($partid,$respid) = ($submission =~ /^resource\.([^\.]*)\.([^\.]*)\.submission/); - if (join('_',@{$part}) ne ($partid.'_'.$respid)) { next; } - my ($ressub,$hide,$draft,$subval) = split(/:/,$submission,4); - # Similarity check - my $similar=''; - my ($type,$trial,$rndseed); - if ($hide eq 'rand') { - $type = 'randomizetry'; - $trial = $record{"resource.$partid.tries"}; - $rndseed = $record{"resource.$partid.rndseed"}; - } - if ($env{'form.checkPlag'}) { - my ($oname,$odom,$ocrsid,$oessay,$osim)= - &most_similar($uname,$udom,$symb,$subval); - if ($osim) { - $osim=int($osim*100.0); - if ($hide eq 'anon') { - $similar='
'.&mt("Essay was found to be similar to another essay submitted for this assignment.").'
'. - &mt('As the current submission is for an anonymous survey, no other details are available.').'

'; - } else { - $similar='
'; - if ($essayurl eq 'lib/templates/simpleproblem.problem') { - $similar .= '

'. - &mt('Essay is [_1]% similar to an essay by [_2]', - $osim, - &Apache::loncommon::plainname($oname,$odom).' ('.$oname.':'.$odom.')'). - '

'; - } else { - my %old_course_desc; - if ($ocrsid ne '') { - if (ref($coursedesc_by_cid{$ocrsid}) eq 'HASH') { - %old_course_desc = %{$coursedesc_by_cid{$ocrsid}}; - } else { - my $args; - if ($ocrsid ne $env{'request.course.id'}) { - $args = {'one_time' => 1}; - } - %old_course_desc = - &Apache::lonnet::coursedescription($ocrsid,$args); - $coursedesc_by_cid{$ocrsid} = \%old_course_desc; - } - $similar .= - '

'. - &mt('Essay is [_1]% similar to an essay by [_2] in course [_3] (course id [_4]:[_5])', - $osim, - &Apache::loncommon::plainname($oname,$odom).' ('.$oname.':'.$odom.')', - $old_course_desc{'description'}, - $old_course_desc{'num'}, - $old_course_desc{'domain'}). - '

'; - } else { - $similar .= - '

'. - &mt('Essay is [_1]% similar to an essay by [_2] in an unknown course', - $osim, - &Apache::loncommon::plainname($oname,$odom).' ('.$oname.':'.$odom.')'). - '

'; - } - } - $similar .= '
'. - &keywords_highlight($oessay). - '

'; - } - } - } - my $order=&get_order($partid,$respid,$symb,$uname,$udom, - undef,$type,$trial,$rndseed); - if (($env{'form.lastSub'} eq 'lastonly') || - ($env{'form.lastSub'} eq 'datesub') || - ($env{'form.lastSub'} =~ /^(last|all)$/)) { - my $display_part=&get_display_part($partid,$symb); - $lastsubonly.='
'. - ''.&mt('Part: [_1]',$display_part).''. - ' '. - '('.&mt('Response ID: [_1]',$respid).')'. - '   '; - my $files=&get_submitted_files($udom,$uname,$partid,$respid,\%record); - if (@$files) { - if ($hide eq 'anon') { - $lastsubonly.='
'.&mt('[quant,_1,file] uploaded to this anonymous survey',scalar(@{$files})); - } else { - $lastsubonly.='

'.''.&mt('Submitted Files:').'' - .'
'; - if(@$files == 1) { - $lastsubonly .= &mt('Like all files provided by users, this file may contain viruses!'); - } else { - $lastsubonly .= &mt('Like all files provided by users, these files may contain viruses!'); - } - $lastsubonly .= ''; - foreach my $file (@$files) { - &Apache::lonnet::allowuploaded('/adm/grades',$file); - $lastsubonly.='
'.$file.''; - } - } - $lastsubonly.='
'; - } - if ($hide eq 'anon') { - $lastsubonly.='
'.&mt('Anonymous Survey').''; - } else { - $lastsubonly.='
'.&mt('Submitted Answer:').' '; - if ($draft) { - $lastsubonly.= ' '.&mt('Draft Copy').''; - } - $subval = - &cleanRecord($subval,$responsetype,$symb,$partid, - $respid,\%record,$order,undef,$uname,$udom,$type,$trial,$rndseed); - if ($responsetype eq 'essay') { - $subval =~ s{\n}{
}g; - } - $lastsubonly.=$subval."\n"; - } - if ($similar) {$lastsubonly.="

$similar\n";} - $lastsubonly.='
'; - } - } - } - $lastsubonly.='
'."\n"; # End: LC_grade_submissions_body - } + my ($lastsubonly,$partinfo) = + &show_last_submission($uname,$udom,$symb,$essayurl,$responseType,$env{'form.lastSub'}, + $is_tool,$fullname,\%record,\%coursedesc_by_cid); + $request->print($partinfo); $request->print($lastsubonly); + if ($env{'form.lastSub'} eq 'datesub') { my ($parts,$handgrade,$responseType) = &response_type($symb,\$res_error); $request->print(&displaySubByDates($symb,\%record,$parts,$responseType,$checkIcon,$uname,$udom)); @@ -2857,6 +2687,186 @@ sub submission { return ''; } +sub show_last_submission { + my ($uname,$udom,$symb,$essayurl,$responseType,$viewtype,$is_tool,$fullname, + $record,$coursedesc_by_cid) = @_; + my ($string,$timestamp,$lastgradetime,$lastsubmittime) = + &get_last_submission($record,$is_tool); + + my ($lastsubonly,$partinfo); + if ($timestamp eq '') { + $lastsubonly.='
'.$string->[0].'
'; + } elsif ($is_tool) { + $lastsubonly = + '
' + .''.&mt('Date Grade Passed Back:').' '.$timestamp."
\n"; + } else { + my ($shownsubmdate,$showngradedate); + if ($lastsubmittime && $lastgradetime) { + $shownsubmdate = &Apache::lonlocal::locallocaltime($lastsubmittime); + if ($lastgradetime > $lastsubmittime) { + $showngradedate = &Apache::lonlocal::locallocaltime($lastgradetime); + } + } else { + $shownsubmdate = $timestamp; + } + $lastsubonly = + '
' + .''.&mt('Date Submitted:').' '.$shownsubmdate."\n"; + if ($showngradedate) { + $lastsubonly .= '
'.&mt('Date Graded:').' '.$showngradedate."\n"; + } + + my %seenparts; + my @part_response_id = &flatten_responseType($responseType); + foreach my $part (@part_response_id) { + my ($partid,$respid) = @{ $part }; + my $display_part=&get_display_part($partid,$symb); + if ($env{"form.$uname:$udom:$partid:submitted_by"}) { + if (exists($seenparts{$partid})) { next; } + $seenparts{$partid}=1; + $partinfo .= + ''.&mt('Part: [_1]',$display_part).''. + ' '.&mt('Collaborative submission by: [_1]', + ''. + $$fullname{$env{"form.$uname:$udom:$partid:submitted_by"}}.''). + '
'; + next; + } + my $responsetype = $responseType->{$partid}->{$respid}; + if (!exists($record->{"resource.$partid.$respid.submission"})) { + $lastsubonly.="\n".'
'. + ''.&mt('Part: [_1]',$display_part).''. + ' '. + '('.&mt('Response ID: [_1]',$respid).')'. + '   '. + ''.&mt('Nothing submitted - no attempts.').'

'; + next; + } + foreach my $submission (@$string) { + my ($partid,$respid) = ($submission =~ /^resource\.([^\.]*)\.([^\.]*)\.submission/); + if (join('_',@{$part}) ne ($partid.'_'.$respid)) { next; } + my ($ressub,$hide,$draft,$subval) = split(/:/,$submission,4); + # Similarity check + my $similar=''; + my ($type,$trial,$rndseed); + if ($hide eq 'rand') { + $type = 'randomizetry'; + $trial = $record->{"resource.$partid.tries"}; + $rndseed = $record->{"resource.$partid.rndseed"}; + } + if ($env{'form.checkPlag'}) { + my ($oname,$odom,$ocrsid,$oessay,$osim)= + &most_similar($uname,$udom,$symb,$subval); + if ($osim) { + $osim=int($osim*100.0); + if ($hide eq 'anon') { + $similar='
'.&mt("Essay was found to be similar to another essay submitted for this assignment.").'
'. + &mt('As the current submission is for an anonymous survey, no other details are available.').'

'; + } else { + $similar='
'; + if ($essayurl eq 'lib/templates/simpleproblem.problem') { + $similar .= '

'. + &mt('Essay is [_1]% similar to an essay by [_2]', + $osim, + &Apache::loncommon::plainname($oname,$odom).' ('.$oname.':'.$odom.')'). + '

'; + } else { + my %old_course_desc; + if ($ocrsid ne '') { + if (ref($coursedesc_by_cid->{$ocrsid}) eq 'HASH') { + %old_course_desc = %{$coursedesc_by_cid->{$ocrsid}}; + } else { + my $args; + if ($ocrsid ne $env{'request.course.id'}) { + $args = {'one_time' => 1}; + } + %old_course_desc = + &Apache::lonnet::coursedescription($ocrsid,$args); + $coursedesc_by_cid->{$ocrsid} = \%old_course_desc; + } + $similar .= + '

'. + &mt('Essay is [_1]% similar to an essay by [_2] in course [_3] (course id [_4]:[_5])', + $osim, + &Apache::loncommon::plainname($oname,$odom).' ('.$oname.':'.$odom.')', + $old_course_desc{'description'}, + $old_course_desc{'num'}, + $old_course_desc{'domain'}). + '

'; + } else { + $similar .= + '

'. + &mt('Essay is [_1]% similar to an essay by [_2] in an unknown course', + $osim, + &Apache::loncommon::plainname($oname,$odom).' ('.$oname.':'.$odom.')'). + '

'; + } + } + $similar .= '
'. + &keywords_highlight($oessay). + '

'; + } + } + } + my $order=&get_order($partid,$respid,$symb,$uname,$udom, + undef,$type,$trial,$rndseed); + if (($viewtype eq 'lastonly') || + ($viewtype eq 'datesub') || + ($viewtype =~ /^(last|all)$/)) { + my $display_part=&get_display_part($partid,$symb); + $lastsubonly.='
'. + ''.&mt('Part: [_1]',$display_part).''. + ' '. + '('.&mt('Response ID: [_1]',$respid).')'. + '   '; + my $files=&get_submitted_files($udom,$uname,$partid,$respid,$record); + if (@$files) { + if ($hide eq 'anon') { + $lastsubonly.='
'.&mt('[quant,_1,file] uploaded to this anonymous survey',scalar(@{$files})); + } else { + $lastsubonly.='

'.''.&mt('Submitted Files:').'' + .'
'; + if(@$files == 1) { + $lastsubonly .= &mt('Like all files provided by users, this file may contain viruses!'); + } else { + $lastsubonly .= &mt('Like all files provided by users, these files may contain viruses!'); + } + $lastsubonly .= ''; + foreach my $file (@$files) { + &Apache::lonnet::allowuploaded('/adm/grades',$file); + $lastsubonly.='
'.$file.''; + } + } + $lastsubonly.='
'; + } + if ($hide eq 'anon') { + $lastsubonly.='
'.&mt('Anonymous Survey').''; + } else { + $lastsubonly.='
'.&mt('Submitted Answer:').' '; + if ($draft) { + $lastsubonly.= ' '.&mt('Draft Copy').''; + } + $subval = + &cleanRecord($subval,$responsetype,$symb,$partid, + $respid,$record,$order,undef,$uname,$udom,$type,$trial,$rndseed); + if ($responsetype eq 'essay') { + $subval =~ s{\n}{
}g; + } + $lastsubonly.=$subval."\n"; + } + if ($similar) {$lastsubonly.="

$similar\n";} + $lastsubonly.='
'; + } + } + } + $lastsubonly.='
'."\n"; # End: LC_grade_submissions_body + } + return ($lastsubonly,$partinfo); +} + sub check_collaborators { my ($symb,$uname,$udom,$record,$handgrade,$counter) = @_; my ($result,@col_fullnames); @@ -11555,6 +11565,77 @@ sub select_problem { $r->print(''); } +#----- display problem, answer, and submissions for a single student (no grading) + +sub view_as_user { + my ($symb,$vuname,$vudom,$hasperm) = @_; + my $plainname = &Apache::loncommon::plainname($vuname,$vudom,'lastname'); + my $displayname = &nameUserString('',$plainname,$vuname,$vudom); + my $output = &Apache::loncommon::get_student_view($symb,$vuname,$vudom, + $env{'request.course.id'}, + undef,{'disable_submit' => 1}). + "\n\n". + '
'. + '

'.$displayname.'

'. + "\n". + &Apache::loncommon::track_student_link('View recent activity', + $vuname,$vudom,'check').' '. + "\n"; + if (&Apache::lonnet::allowed('opa',$env{'request.course.id'}) || + (($env{'request.course.sec'} ne '') && + &Apache::lonnet::allowed('opa',$env{'request.course.id'}.'/'.$env{'request.course.sec'}))) { + $output .= &Apache::loncommon::pprmlink(&mt('Set/Change parameters'), + $vuname,$vudom,$symb,'check'); + } + $output .= "\n"; + my $companswer = &Apache::loncommon::get_student_answers($symb,$vuname,$vudom, + $env{'request.course.id'}); + $companswer=~s|||g; + $companswer=~s|||g; + $companswer=~s|name="submit"|name="would_have_been_submit"|g; + $output .= '
'. + '

'.&mt('Correct answer for[_1]',$displayname).'

'. + $companswer. + '
'."\n"; + my $is_tool = ($symb =~ /ext\.tool$/); + my ($essayurl,%coursedesc_by_cid); + (undef,undef,$essayurl) = &Apache::lonnet::decode_symb($symb); + my %record = &Apache::lonnet::restore($symb,$env{'request.course.id'},$vudom,$vuname); + my $res_error; + my ($partlist,$handgrade,$responseType,$numresp,$numessay) = + &response_type($symb,\$res_error); + my $fullname; + my $collabinfo; + if ($numessay) { + unless ($hasperm) { + &init_perm(); + } + ($collabinfo,$fullname)= + &check_collaborators($symb,$vuname,$vudom,\%record,$handgrade,0); + unless ($hasperm) { + &reset_perm(); + } + } + my $checkIcon = ''.&mt('Check Mark').
+                    ''; + my ($lastsubonly,$partinfo) = + &show_last_submission($vuname,$vudom,$symb,$essayurl,$responseType,'datesub', + '',$fullname,\%record,\%coursedesc_by_cid); + $output .= '
'. + '

'.&mt('Submissions').'

'."\n".$collabinfo."\n"; + if (($numresp > $numessay) & !$is_tool) { + $output .='

'. + &mt('Part(s) graded correct by the computer is marked with a [_1] symbol.',$checkIcon). + "

\n"; + } + $output .= $partinfo; + $output .= $lastsubonly; + $output .= &displaySubByDates($symb,\%record,$partlist,$responseType,$checkIcon,$vuname,$vudom); + $output .= '
'."\n"; + return $output; +} + sub handler { my $request=$_[0]; &reset_caches();