--- loncom/homework/grades.pm 2009/08/19 19:25:21 1.579
+++ loncom/homework/grades.pm 2010/03/21 18:31:45 1.601
@@ -1,7 +1,7 @@
# The LearningOnline Network with CAPA
# The LON-CAPA Grading handler
#
-# $Id: grades.pm,v 1.579 2009/08/19 19:25:21 raeburn Exp $
+# $Id: grades.pm,v 1.601 2010/03/21 18:31:45 www Exp $
#
# Copyright Michigan State University Board of Trustees
#
@@ -96,10 +96,19 @@ sub ssi_print_error {
#
# --- Retrieve the parts from the metadata file.---
+# Returns an array of everything that the resources stores away
+#
+
sub getpartlist {
- my ($symb) = @_;
+ my ($symb,$errorref) = @_;
my $navmap = Apache::lonnavmaps::navmap->new();
+ unless (ref($navmap)) {
+ if (ref($errorref)) {
+ $$errorref = 'navmap';
+ return;
+ }
+ }
my $res = $navmap->getBySymb($symb);
my $partlist = $res->parts();
my $url = $res->src();
@@ -115,13 +124,17 @@ sub getpartlist {
}
# --- Get the symbolic name of a problem and the url
+# Generate an error message if symb could not be found unless silent flag is set
+# Takes $env{'form.symb'} by default; if not present, takes $env{'form.url'} and tries to get symb from that
+#
+
sub get_symb {
my ($request,$silent) = @_;
(my $url=$env{'form.url'}) =~ s-^http://($ENV{'SERVER_NAME'}|$ENV{'HTTP_HOST'})--;
my $symb=($env{'form.symb'} ne '' ? $env{'form.symb'} : (&Apache::lonnet::symbread($url)));
if ($symb eq '') {
if (!$silent) {
- $request->print("Unable to handle ambiguous references:$url:.");
+ $request->print(&mt("Unable to handle ambiguous references: [_1].",$url));
return ();
}
}
@@ -144,10 +157,20 @@ sub nameUserString {
#--- 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 ($symb) = shift;
+ my ($symb,$response_error) = @_;
my $navmap = Apache::lonnavmaps::navmap->new();
+ unless (ref($navmap)) {
+ if (ref($response_error)) {
+ $$response_error = 1;
+ }
+ return;
+ }
my $res = $navmap->getBySymb($symb);
+ unless (ref($res)) {
+ $$response_error = 1;
+ return;
+ }
my $partlist = $res->parts();
my %vPart =
map { $_ => 1 } (&Apache::loncommon::get_env_multiple('form.vPart'));
@@ -193,40 +216,52 @@ sub get_display_part {
#--- Show resource title
#--- and parts and response type
-sub showResourceInfo {
- my ($symb,$probTitle,$checkboxes) = @_;
- my $col=3;
- if ($checkboxes) { $col=4; }
- my $result = '
'.&mt('Current Resource').': '.$probTitle.'
'."\n";
- $result .='
';
- my ($partlist,$handgrade,$responseType) = &response_type($symb);
- my %resptype = ();
- my $hdgrade='no';
- my %partsseen;
- foreach my $partID (sort(keys(%$responseType))) {
- foreach my $resID (sort(keys(%{ $responseType->{$partID} }))) {
- my $handgrade=$$handgrade{$partID.'_'.$resID};
- my $responsetype = $responseType->{$partID}->{$resID};
- $hdgrade = $handgrade if ($handgrade eq 'yes');
- $result.='
';
- if ($checkboxes) {
- if (exists($partsseen{$partID})) {
- $result.="
';
+ $bottomrow.''.'';
} elsif ($response eq 'essay') {
if (! exists ($env{'form.'.$symb})) {
my (%keyhash) = &Apache::lonnet::dump('nohist_handgrade',
@@ -459,8 +494,7 @@ sub cleanRecord {
#-- A couple of common js functions
sub commonJSfunctions {
my $request = shift;
- $request->print(<
+ $request->print(&Apache::lonhtmlcommon::scripttag(< 1) {
@@ -488,7 +522,6 @@ sub commonJSfunctions {
return selectOne.value;
}
}
-
COMMONJSFUNCTIONS
}
@@ -643,13 +676,13 @@ sub student_gradeStatus {
sub jscriptNform {
my ($symb) = @_;
my $stu_status = join(':',&Apache::loncommon::get_env_multiple('form.Status'));
- my $jscript=''."\n";
+ "\n");
$jscript.= ''."\n";
if ($ctr == 0) {
my $num_students=(scalar(keys(%$fullname)));
if ($num_students eq 0) {
@@ -1107,7 +1158,7 @@ LISTJAVASCRIPT
sub check_script {
my ($form, $type)=@_;
- my $chkallscript=''."\n";
+'."\n");
return $chkallscript;
}
@@ -1177,8 +1228,7 @@ sub processGroup {
sub sub_page_js {
my $request = shift;
my $alertmsg = &mt('A number equal or greater than 0 is expected. Entered value = ');
- $request->print(<
+ $request->print(&Apache::lonhtmlcommon::scripttag(<
SUBJAVASCRIPT
}
@@ -1356,8 +1405,7 @@ sub sub_page_kw_js {
my $iconpath = $request->dir_config('lonIconsURL');
&commonJSfunctions($request);
- my $inner_js_msg_central=<
+ my $inner_js_msg_central= &Apache::lonhtmlcommon::scripttag(<
INNERJS
- my $inner_js_highlight_central=<
+ my $inner_js_highlight_central= &Apache::lonhtmlcommon::scripttag(<
INNERJS
my $start_page_msg_central =
@@ -1433,8 +1478,7 @@ INNERJS
my $docopen=&Apache::lonhtmlcommon::javascript_docopen();
$docopen=~s/^document\.//;
my $alertmsg = &mt('Please select a word or group of words from document and then click this link.');
- $request->print(<
+ $request->print(&Apache::lonhtmlcommon::scripttag(<");
pDoc.write("<\\/td><\\/tr><\\/table> ");
- pDoc.write(" ");
- pDoc.write("
'
+ .&Apache::loncommon::end_data_table_header_row()
+ );
+}
+
+sub gradeBox_end {
+ return (
+ &Apache::loncommon::end_data_table()
+ );
+}
#--- displays the grading box, used in essay type problem and grading by page/sequence
sub gradeBox {
my ($request,$symb,$uname,$udom,$counter,$partid,$record) = @_;
@@ -1697,7 +1759,7 @@ sub gradeBox {
if ($last_resets{$partid}) {
$aggtries = &get_num_tries($record,$last_resets{$partid},$partid);
}
- $result.='
';
+ $result.=&Apache::loncommon::start_data_table_row();
my $ctr = 0;
my $thisweight = 0;
my $increment = &get_increment();
@@ -1705,7 +1767,7 @@ sub gradeBox {
my $radio.='
'."\n"; # display radio buttons in a nice table 10 across
while ($thisweight<=$wgt) {
$radio.= '
\n";
$radio.=(($ctr+1)%10 == 0 ? '
' : '');
@@ -1716,13 +1778,13 @@ sub gradeBox {
my $line.=''."\n";
$line.='
KEYWORDS
@@ -2027,12 +2089,31 @@ KEYWORDS
}
# This is where output for one specific student would start
- my $add_class = ($counter%2) ? 'LC_grade_show_user_odd_row' : '';
- $request->print("\n\n".
- '
'
+ ."\n"
+ );
+
+ # Show additional functions if allowed
+ if ($perm{'vgr'}) {
+ $request->print(
+ &Apache::loncommon::track_student_link(
+ &mt('View recent activity'),
+ $uname,$udom,'check')
+ .' '
+ );
+ }
+ if ($perm{'opa'}) {
+ $request->print(
+ &Apache::loncommon::pprmlink(
+ &mt('Set/Change parameters'),
+ $uname,$udom,$symb,'check'));
+ }
+ # Show Problem
if ($env{'form.vProb'} eq 'all' or $env{'form.vAns'} eq 'all') {
my $mode;
if ($env{'form.vProb'} eq 'all' && $env{'form.vAns'} eq 'all') {
@@ -2047,24 +2128,26 @@ KEYWORDS
}
my %record = &Apache::lonnet::restore($symb,$env{'request.course.id'},$udom,$uname);
- my ($partlist,$handgrade,$responseType) = &response_type($symb);
+ my $res_error;
+ my ($partlist,$handgrade,$responseType) = &response_type($symb,\$res_error);
+ if ($res_error) {
+ $request->print(&navmap_errormsg());
+ return;
+ }
# Display student info
$request->print(($counter == 0 ? '' : ' '));
- my $result='
';
-
- $result.='
';
- $result.= &mt('Submissions');
+
+ my $result='
'
+ .'
'.&mt('Submissions').'
';
$result.=''."\n";
+ '" value="'.$env{'form.fullname'}.'" />'."\n";
if ($env{'form.handgrade'} eq 'no') {
- $result.=''.
- &mt('Part(s) graded correct by the computer is marked with a [_1] symbol.',$checkIcon)."\n";
-
+ $result.='
'
+ .&mt('Part(s) graded correct by the computer is marked with a [_1] symbol.',$checkIcon)
+ ."
\n";
}
-
-
# If any part of the problem is an essay-response (handgraded), then check for collaborators
my $fullname;
my $col_fullnames = [];
@@ -2075,9 +2158,9 @@ KEYWORDS
$result.=$sub_result;
}
$request->print($result."\n");
- $request->print('
'."\n");
+
# print student answer/submission
- # Options are (1) Handgaded submission only
+ # Options are (1) Handgraded submission only
# (2) Last submission, includes submission that is not handgraded
# (for multi-response type part)
# (3) Last submission plus the parts info
@@ -2087,10 +2170,12 @@ KEYWORDS
my $lastsubonly;
- if ($$timestamp eq '') {
- $lastsubonly.='
'.$$string[0].'
';
- } else {
- $lastsubonly = '
Date Submitted: '.$$timestamp."\n";
+ if ($$timestamp eq '') {
+ $lastsubonly.='
'.$$string[0].'
';
+ } else {
+ $lastsubonly =
+ '
'
+ .''.&mt('Date Submitted:').' '.$$timestamp."\n";
my %seenparts;
my @part_response_id = &flatten_responseType($responseType);
@@ -2117,7 +2202,7 @@ KEYWORDS
$lastsubonly.="\n".'
';
next;
@@ -2125,7 +2210,7 @@ KEYWORDS
foreach my $submission (@$string) {
my ($partid,$respid) = ($submission =~ /^resource\.([^\.]*)\.([^\.]*)\.submission/);
if (join('_',@{$part}) ne ($partid.'_'.$respid)) { next; }
- my ($ressub,$subval) = split(/:/,$submission,2);
+ my ($ressub,$hide,$subval) = split(/:/,$submission,3);
# Similarity check
my $similar='';
if($env{'form.checkPlag'}){
@@ -2137,16 +2222,21 @@ KEYWORDS
&Apache::lonnet::coursedescription($ocrsid,
{'one_time' => 1});
- $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'}).
- '
'.
- &keywords_highlight($oessay).
- '
';
+ if ($hide) {
+ $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="
".
+ &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'}).
+ '
'.
+ &keywords_highlight($oessay).
+ '
';
+ }
}
}
my $order=&get_order($partid,$respid,$symb,$uname,$udom);
@@ -2158,31 +2248,39 @@ KEYWORDS
''.&mt('Part: [_1]',$display_part).''.
' '.
'('.&mt('Part ID: [_1]',$respid).')'.
- ' ';
+ ' ';
my $files=&get_submitted_files($udom,$uname,$partid,$respid,\%record);
if (@$files) {
- $lastsubonly.=' '.&mt('Like all files provided by users, this file may contain viruses').' ';
- my $file_counter = 0;
- foreach my $file (@$files) {
- $file_counter++;
- &Apache::lonnet::allowuploaded('/adm/grades',$file);
- $lastsubonly.=' '.$file.'';
- }
+ if ($hide) {
+ $lastsubonly.=' '.&mt('[quant,_1,file] uploaded to this anonymous survey',scalar(@{$files}));
+ } else {
+ $lastsubonly.=' '.&mt('Like all files provided by users, this file may contain viruses').' ';
+ foreach my $file (@$files) {
+ &Apache::lonnet::allowuploaded('/adm/grades',$file);
+ $lastsubonly.=' '.$file.'';
+ }
+ }
$lastsubonly.=' ';
}
- $lastsubonly.=''.&mt('Submitted Answer:').' '.
- &cleanRecord($subval,$responsetype,$symb,$partid,
- $respid,\%record,$order,undef,$uname,$udom);
+ if ($hide) {
+ $lastsubonly.=''.&mt('Anonymous Survey').'';
+ } else {
+ $lastsubonly.=''.&mt('Submitted Answer:').' '.
+ &cleanRecord($subval,$responsetype,$symb,$partid,
+ $respid,\%record,$order,undef,$uname,$udom);
+ }
if ($similar) {$lastsubonly.="
$similar\n";}
$lastsubonly.='
';
}
}
}
- $lastsubonly.='
'."\n";
+ $lastsubonly.='
'."\n"; # End: LC_grade_submissions_body
}
$request->print($lastsubonly);
} elsif ($env{'form.lastSub'} eq 'datesub') {
- my (undef,$responseType,undef,$parts) = &showResourceInfo($symb);
+# my (undef,$responseType,undef,$parts) = &showResourceInfo($symb);
+ my ($parts,$handgrade,$responseType) = &response_type($symb);
+
$request->print(&displaySubByDates($symb,\%record,$parts,$responseType,$checkIcon,$uname,$udom));
} elsif ($env{'form.lastSub'} =~ /^(last|all)$/) {
$request->print(&Apache::loncommon::get_previous_attempt($symb,$uname,$udom,
@@ -2196,7 +2294,7 @@ KEYWORDS
# return if view submission with no grading option
if ($env{'form.showgrading'} eq '' || (!&canmodify($usec))) {
my $toGrade.=' '."\n" if (&canmodify($usec));
$toGrade.='
'."\n";
if (($env{'form.command'} eq 'submission') ||
@@ -2240,11 +2338,11 @@ KEYWORDS
my @partlist;
my @gradePartRespid;
my @part_response_id = &flatten_responseType($responseType);
- $request->print('
';
@@ -2375,7 +2465,7 @@ sub check_collaborators {
#--- Retrieve the last submission for all the parts
sub get_last_submission {
my ($returnhash)=@_;
- my (@string,$timestamp);
+ my (@string,$timestamp,%lasthidden);
if ($$returnhash{'version'}) {
my %lasthash=();
my ($version);
@@ -2387,13 +2477,39 @@ sub get_last_submission {
&Apache::lonlocal::locallocaltime($$returnhash{$version.':timestamp'});
}
}
+ my %typeparts;
+ my $showsurv =
+ &Apache::lonnet::allowed('vas',$env{'request.course.id'});
+ foreach my $key (sort(keys(%lasthash))) {
+ if ($key =~ /\.type$/) {
+ if (($lasthash{$key} eq 'anonsurvey') ||
+ ($lasthash{$key} eq 'anonsurveycred')) {
+ my ($ign,@parts) = split(/\./,$key);
+ pop(@parts);
+ unless ($showsurv) {
+ my $id = join(',',@parts);
+ $typeparts{$ign.'.'.$id} = $lasthash{$key};
+ }
+ delete($lasthash{$key});
+ }
+ }
+ }
+ my @hidden = keys(%typeparts);
foreach my $key (keys(%lasthash)) {
next if ($key !~ /\.submission$/);
-
+ my $hide;
+ if (@hidden) {
+ foreach my $id (@hidden) {
+ if ($key =~ /^\Q$id\E/) {
+ $hide = 1;
+ last;
+ }
+ }
+ }
my ($partid,$foo) = split(/submission$/,$key);
my $draft = $lasthash{$partid.'awarddetail'} eq 'DRAFT' ?
'Draft Copy ' : '';
- push(@string, join(':', $key, $draft.$lasthash{$key}));
+ push(@string, join(':', $key, $hide, $draft.$lasthash{$key}));
}
}
if (!@string) {
@@ -2560,7 +2676,7 @@ sub processHandGrade {
# Go directly to grade student - from submission or link from chart page
if ($button eq 'Grade Student') {
- (undef,undef,$env{'form.handgrade'},undef,undef) = &showResourceInfo($symb);
+# (undef,undef,$env{'form.handgrade'},undef,undef) = &showResourceInfo($symb);
my $processUser = $env{'form.unamedom'.$env{'form.studentNo'}};
($env{'form.student'},$env{'form.userdom'}) = split(/:/,$processUser);
$env{'form.fullname'} = $$fullname{$processUser};
@@ -2598,7 +2714,12 @@ sub processHandGrade {
}
$ctr = 0;
@parsedlist = reverse @parsedlist if ($button eq 'Previous');
- my ($partlist) = &response_type($symb);
+ my $res_error;
+ my ($partlist) = &response_type($symb,\$res_error);
+ if ($res_error) {
+ $request->print(&navmap_errormsg());
+ return;
+ }
foreach my $student (@parsedlist) {
my $submitonly=$env{'form.submitonly'};
my ($uname,$udom) = split(/:/,$student);
@@ -2796,8 +2917,12 @@ sub check_and_remove_from_queue {
sub handback_files {
my ($request,$symb,$stuname,$domain,$newflg,$new_part,$newrecord) = @_;
my $portfolio_root = '/userfiles/portfolio';
- my ($partlist,$handgrade,$responseType) = &response_type($symb);
-
+ my $res_error;
+ my ($partlist,$handgrade,$responseType) = &response_type($symb,\$res_error);
+ if ($res_error) {
+ $request->print(' '.&navmap_errormsg().' ');
+ return;
+ }
my @part_response_id = &flatten_responseType($responseType);
foreach my $part_response_id (@part_response_id) {
my ($part_id,$resp_id) = @{ $part_response_id };
@@ -3045,8 +3170,7 @@ sub viewgrades_js {
my ($request) = shift;
my $alertmsg = &mt('A number equal or greater than 0 is expected. Entered value = ');
- $request->print(<
+ $request->print(&Apache::lonhtmlcommon::scripttag(<
VIEWJAVASCRIPT
}
@@ -3255,7 +3378,11 @@ sub viewgrades {
$result.= '
'.$common_header.'
'.&Apache::loncommon::start_data_table();
#radio buttons/text box for assigning points for a section or class.
#handles different parts of a problem
- my ($partlist,$handgrade,$responseType) = &response_type($symb);
+ my $res_error;
+ my ($partlist,$handgrade,$responseType) = &response_type($symb,\$res_error);
+ if ($res_error) {
+ return &navmap_errormsg();
+ }
my %weight = ();
my $ctsparts = 0;
my %seen = ();
@@ -3281,11 +3408,11 @@ sub viewgrades {
}
$radio.='