';
@@ -1517,7 +1537,10 @@ sub handback_box {
next if (!@$files);
my $file_counter = 1;
foreach my $file (@$files) {
- my ($file_disp) = ($file =~ m|.+/(.+)$|);
+ my ($file_path, $file_disp) = ($file =~ m|(.+/)(.+)$|);
+ my ($name,$version,$ext) = &file_name_version_ext($file_disp);
+ $file_disp = "$name.$ext";
+ $file = $file_path.$file_disp;
$result.=&mt('Return commented version of [_1] to student.',
''.$file_disp.'');
$result.=''."\n";
@@ -1992,6 +2015,8 @@ KEYWORDS
' ';
$endform.='(Next and Previous (student) do not save the scores.)'."\n" ;
+ $endform.="";
$endform.='
';
$endform.=&show_grading_menu_form($symb);
$request->print($endform);
@@ -2269,20 +2294,19 @@ sub processHandGrade {
#---- Save the score and award for each student, if changed
sub saveHandGrade {
my ($request,$symb,$stuname,$domain,$newflg,$submitter,$part) = @_;
- my @v_flag;
+ my @version_parts;
my $usec = &Apache::lonnet::getsection($domain,$stuname,
$env{'request.course.id'});
if (!&canmodify($usec)) { return('not_allowed'); }
- my %record = &Apache::lonnet::restore($symb,$env{'request.course.id'},$domain,$stuname);
+ my %record = &Apache::lonnet::restore($symb,$env{'request.course.id'},$domain,$stuname);
my @parts_graded;
my %newrecord = ();
my ($pts,$wgt) = ('','');
my %aggregate = ();
my $aggregateflag = 0;
-
my @parts = split(/:/,$env{'form.partlist'.$newflg});
foreach my $new_part (@parts) {
- #collaborator may vary for different parts
+ #collaborator ($submi may vary for different parts
if ($submitter && $new_part ne $part) { next; }
my $dropMenu = $env{'form.GD_SEL'.$newflg.'_'.$new_part};
if ($dropMenu eq 'excused') {
@@ -2327,6 +2351,7 @@ sub saveHandGrade {
my $partial= $pts/$wgt;
if ($partial eq $record{'resource.'.$new_part.'.awarded'}) {
#do not update score for part if not changed.
+ &handback_files($request,$symb,$stuname,$domain,$newflg,$new_part,\%newrecord);
next;
} else {
push @parts_graded, $new_part;
@@ -2350,50 +2375,26 @@ sub saveHandGrade {
}
$newrecord{'resource.'.$new_part.'.regrader'}=
"$env{'user.name'}:$env{'user.domain'}";
+ &handback_files($request,$symb,$stuname,$domain,$newflg,$new_part,\%newrecord);
}
- my ($partlist,$handgrade,$responseType) = &response_type($symb);
- foreach my $part_resp (sort(keys(%$handgrade))) {
- my ($part_id, $resp_id) = split(/_/,$part_resp);
- if (($env{'form.'.$newflg.'_'.$part_resp.'_returndoc1'}) && ($new_part == $part_id)) {
- # if multiple files are uploaded names will be 'returndoc2','returndoc3'
- my $file_counter = 1;
- while ($env{'form.'.$newflg.'_'.$part_resp.'_returndoc'.$file_counter}) {
- my $fname=$env{'form.'.$newflg.'_'.$part_resp.'_returndoc'.$file_counter.'.filename'};
- $newrecord{"resource.$new_part.$resp_id.handback"} = $env{'form.returndocorig'.$file_counter};
- # set the filename to match the submitted file name
- $env{'form.'.$newflg.'_'.$part_resp.'_returndoc1.filename'} = $env{'form.'.$newflg.'_'.$part_resp.'_origdoc'.$file_counter};
- my $result=&Apache::lonnet::userfileupload($newflg.'_'.$part_resp.'_returndoc'.$file_counter,'',
- 'portfolio',undef,undef,undef,$stuname,$domain);
- if ($result !~ m|^/uploaded/|) {
- $request->print(' An errror occured ('.$result.
- ') while trying to upload '.&display_file().' ');
- # $request->print(&done('Back'));
- }
- $request->print(" ".$fname." will be the uploaded file name");
- $request->print("Will upload document".$env{'form.'.$newflg.'_'.$part_resp.'_origdoc'.$file_counter});
- $file_counter++;
- }
- }
- }
-
# unless problem has been graded, set flag to version the submitted files
unless ($record{'resource.'.$new_part.'.solved'} =~ /^correct_/ ||
$record{'resource.'.$new_part.'.solved'} eq 'incorrect_by_override' ||
$dropMenu eq 'reset status')
{
- push (@v_flag,$new_part);
+ push (@version_parts,$new_part);
}
}
my $cdom = $env{'course.'.$env{'request.course.id'}.'.domain'};
my $cnum = $env{'course.'.$env{'request.course.id'}.'.num'};
- if (scalar(keys(%newrecord)) > 0) {
- if (scalar(@v_flag)) {
- &version_portfiles(\%record, \@parts_graded, $env{'request.course.id'}, $symb, $domain, $stuname, \@v_flag);
+ if (%newrecord) {
+ if (@version_parts) {
+ my @changed_keys = &version_portfiles(\%record, \@parts_graded, $env{'request.course.id'}, $symb, $domain, $stuname, \@version_parts);
+ @newrecord{@changed_keys} = @record{@changed_keys};
}
&Apache::lonnet::cstore(\%newrecord,$symb,
$env{'request.course.id'},$domain,$stuname);
-
my @ungraded_parts;
foreach my $part (@parts) {
if ( !defined($record{'resource.'.$part.'.awarded'})
@@ -2413,6 +2414,47 @@ sub saveHandGrade {
return ('',$pts,$wgt);
}
+sub handback_files {
+ my ($request,$symb,$stuname,$domain,$newflg,$new_part,$newrecord) = @_;
+ my $portfolio_root = &Apache::loncommon::propath($domain,
+ $stuname).
+ '/userfiles/portfolio';
+ my ($partlist,$handgrade,$responseType) = &response_type($symb);
+ foreach my $part_resp (sort(keys(%$handgrade))) {
+ my ($part_id, $resp_id) = split(/_/,$part_resp);
+ if (($env{'form.'.$newflg.'_'.$part_resp.'_returndoc1'}) && ($new_part == $part_id)) {
+ # if multiple files are uploaded names will be 'returndoc2','returndoc3'
+ my $file_counter = 1;
+ while ($env{'form.'.$newflg.'_'.$part_resp.'_returndoc'.$file_counter}) {
+ my $fname=$env{'form.'.$newflg.'_'.$part_resp.'_returndoc'.$file_counter.'.filename'};
+ my ($directory,$answer_file) =
+ ($env{'form.'.$newflg.'_'.$part_resp.'_origdoc'.$file_counter} =~ /^(.*?)([^\/]*)$/);
+ my ($answer_name,$answer_ver,$answer_ext) =
+ &file_name_version_ext($answer_file);
+ $directory =~ /^.+$stuname\/portfolio(.*)/;
+ my $portfolio_path = $1;
+ my @dir_list = &Apache::lonnet::dirlist($portfolio_path,$domain,$stuname,$portfolio_root);
+ my $version = &get_next_version($answer_name, $answer_ext, \@dir_list);
+ my $new_answer = &version_selected_portfile($domain, $stuname, $portfolio_path, $answer_file, $version);
+ $$newrecord{"resource.$new_part.$resp_id.handback"} = $new_answer;
+ # set the filename to match the submitted file name
+ $env{'form.'.$newflg.'_'.$part_resp.'_returndoc1.filename'} = $env{'form.'.$newflg.'_'.$part_resp.'_origdoc'.$file_counter};
+ my $result=&Apache::lonnet::userfileupload($newflg.'_'.$part_resp.'_returndoc'.$file_counter,'',
+ 'portfolio',undef,undef,undef,$stuname,$domain);
+ if ($result !~ m|^/uploaded/|) {
+ $request->print(' An errror occured ('.$result.
+ ') while trying to upload '.&display_file().' ');
+ # $request->print(&done('Back'));
+ }
+ $request->print(" ".$fname." will be the uploaded file name");
+ $request->print("Will upload document ".$env{'form.'.$newflg.'_'.$part_resp.'_origdoc'.$file_counter});
+ $file_counter++;
+ }
+ }
+ }
+ return;
+}
+
sub get_submitted_files {
my ($udom,$uname,$partid,$respid,$record) = @_;
my @files;
@@ -2491,6 +2533,7 @@ sub get_last_resets {
sub version_portfiles {
my ($record, $parts_graded, $courseid, $symb, $domain, $stu_name, $v_flag) = @_;
my $version_parts = join('|',@$v_flag);
+ my @returned_keys;
my $parts = join('|', @$parts_graded);
my $portfolio_root = &Apache::loncommon::propath($domain,
$stu_name).
@@ -2498,33 +2541,32 @@ sub version_portfiles {
foreach my $key (keys(%$record)) {
my $new_portfiles;
if ($key =~ /^resource\.($version_parts)\./ && $key =~ /\.portfiles$/ ) {
- my @v_portfiles;
+ my @versioned_portfiles;
my @portfiles = split(/,/,$$record{$key});
foreach my $file (@portfiles) {
&Apache::lonnet::unmark_as_readonly($domain,$stu_name,[$symb,$env{'request.course.id'}],$file);
my ($directory,$answer_file) =($file =~ /^(.*?)([^\/]*)$/);
- my $version = 0;
my ($answer_name,$answer_ver,$answer_ext) =
&file_name_version_ext($answer_file);
my @dir_list = &Apache::lonnet::dirlist($directory,$domain,$stu_name,$portfolio_root);
- $version = &get_next_version($answer_name, $answer_ext, \@dir_list);
+ my $version = &get_next_version($answer_name, $answer_ext, \@dir_list);
my $new_answer = &version_selected_portfile($domain, $stu_name, $directory, $answer_file, $version);
if ($new_answer ne 'problem getting file') {
- push(@v_portfiles, $directory.$new_answer);
+ push(@versioned_portfiles, $directory.$new_answer);
&Apache::lonnet::mark_as_readonly($domain,$stu_name,
['/portfolio'.$directory.$new_answer],
[$symb,$env{'request.course.id'},'graded']);
}
-
}
- $$record{$key} = join(',',@v_portfiles);
+ $$record{$key} = join(',',@versioned_portfiles);
+ push(@returned_keys,$key);
}
}
- return 'ok';
+ return (@returned_keys);
}
sub get_next_version {
- my ($answer_name, $answer_ext, $dir_list);
+ my ($answer_name, $answer_ext, $dir_list) = @_;
my $version;
foreach my $row (@$dir_list) {
my ($file) = split(/\&/,$row,2);
@@ -3494,6 +3536,7 @@ sub csvuploadassign {
my ($request)= @_;
my ($symb)=&get_symb($request);
if (!$symb) {return '';}
+ my $error_msg = '';
&Apache::loncommon::load_tmp_file($request);
my @gradedata = &Apache::loncommon::upfile_record_sep();
if ($env{'form.noFirstLine'}) { shift(@gradedata); }
@@ -3546,12 +3589,20 @@ sub csvuploadassign {
my $part=$1;
my $wgt =&Apache::lonnet::EXT('resource.'.$part.'.weight',
$symb,$domain,$username);
- $entries{$fields{$dest}}=~s/\s//g;
- my $pcr=$entries{$fields{$dest}} / $wgt;
- my $award='correct_by_override';
- $grades{"resource.$part.awarded"}=$pcr;
- $grades{"resource.$part.solved"}=$award;
- $points{$part}=1;
+ if ($wgt) {
+ $entries{$fields{$dest}}=~s/\s//g;
+ my $pcr=$entries{$fields{$dest}} / $wgt;
+ my $award='correct_by_override';
+ $grades{"resource.$part.awarded"}=$pcr;
+ $grades{"resource.$part.solved"}=$award;
+ $points{$part}=1;
+ } else {
+ $error_msg = " " .
+ &mt("Some point values were assigned"
+ ." for problems with a weight "
+ ."of zero. These values were "
+ ."ignored.");
+ }
} else {
if ($dest=~/stores_(.*)_awarded/) { if ($points{$1}) {next;} }
if ($dest=~/stores_(.*)_solved/) { if ($points{$1}) {next;} }
@@ -3591,7 +3642,7 @@ sub csvuploadassign {
}
$request->print(" \n");
$request->print(&show_grading_menu_form($symb));
- return '';
+ return $error_msg;
}
#------------- end of section for handling csv file upload ---------
#
@@ -5971,19 +6022,14 @@ sub handler {
sub send_header {
my ($request)= @_;
- $request->print(&Apache::lontexconvert::header());
-# $request->print("
-#");
- $request->print(&Apache::loncommon::bodytag('Grading'));
+ &Apache::lontexconvert::init_tth();
+ $request->print(&Apache::loncommon::start_page('Grading'));
$request->rflush();
}
sub send_footer {
my ($request)= @_;
- $request->print('