--- loncom/homework/grades.pm 2004/04/29 04:47:47 1.191 +++ loncom/homework/grades.pm 2004/04/29 07:21:16 1.192 @@ -1,7 +1,7 @@ # The LearningOnline Network with CAPA # The LON-CAPA Grading handler # -# $Id: grades.pm,v 1.191 2004/04/29 04:47:47 albertel Exp $ +# $Id: grades.pm,v 1.192 2004/04/29 07:21:16 albertel Exp $ # # Copyright Michigan State University Board of Trustees # @@ -3517,8 +3517,8 @@ sub scantron_selectphase { Options: - Redo skipped records
- Ignore Original Corrections + Do only skipped records
+ Remove any exisiting corrections @@ -3685,9 +3685,11 @@ sub scantron_fixup_scanline { $args->{'username'}.':'.$args->{'domain'}); } } elsif ($field eq 'CODE') { - if ($args->{'CODE'} eq 'use_unfound') { - &scan_data($scan_data,"$whichline.useCODE",'1'); - } else { + if ($args->{'CODE_ignore_dup'}) { + &scan_data($scan_data,"$whichline.CODE_ignore_dup",'1'); + } + &scan_data($scan_data,"$whichline.useCODE",'1'); + if ($args->{'CODE'} ne 'use_unfound') { if (length($args->{'CODE'}) > $$scantron_config{'CODElength'}) { return ($line,1,'New CODE value too large'); } @@ -3696,9 +3698,6 @@ sub scantron_fixup_scanline { } substr($line,$$scantron_config{'CODEstart'}-1, $$scantron_config{'CODElength'})=$args->{'CODE'}; -# if ($args->{'CODE'}=~/^\s*$/) { -# &scan_data($scan_data,"$whichline.CODE",$args->{'CODE'}); -# } } } elsif ($field eq 'answer') { my $length=$scantron_config->{'Qlength'}; @@ -3742,6 +3741,9 @@ sub scantron_parse_scanline { if (&scan_data($scan_data,"$whichline.useCODE")) { $record{'scantron.useCODE'}=1; } + if (&scan_data($scan_data,"$whichline.CODE_ignore_dup")) { + $record{'scantron.CODE_ignore_dup'}=1; + } } else { #FIXME interpret first N questions } @@ -3841,6 +3843,7 @@ sub scantron_process_corrections { } elsif ($ENV{'form.scantron_corrections'} =~ /^(duplicate|incorrect)CODE$/) { my $resolution=$ENV{'form.scantron_CODE_resolution'}; my $newCODE; + my %args; if ($resolution eq 'use_unfound') { $newCODE='use_unfound'; } elsif ($resolution eq 'use_found') { @@ -3848,9 +3851,13 @@ sub scantron_process_corrections { } elsif ($resolution eq 'use_typed') { $newCODE=$ENV{'form.scantron_CODE_newvalue'}; } + if ($ENV{'form.scantron_corrections'} eq 'duplicateCODE') { + $args{'CODE_ignore_dup'}=1; + } + $args{'CODE'}=$newCODE; ($line,$err,$errmsg)= &scantron_fixup_scanline(\%scantron_config,$scan_data,$line,$which, - 'CODE',{'CODE'=>$newCODE}); + 'CODE',\%args); } elsif ($ENV{'form.scantron_corrections'} =~ /^(missing|double)bubble$/) { foreach my $question (split(',',$ENV{'form.scantron_questions'})) { ($line,$err,$errmsg)= @@ -3875,7 +3882,14 @@ sub scantron_validate_file { my ($symb,$url)=&get_symb_and_url($r); if (!$symb) {return '';} my $default_form_data=&defaultFormData($symb,$url); - + if ($ENV{'form.scantron_options_ignore'} eq 'ignore_corrections') { + my $result=&scantron_remove('corrected'); + &Apache::lonnet::logthis("result was $result"); + if ($result ne 'ok' && $result ne 'not_found' ) { + $r->print("An error occured ($result) when trying to Remove the existing corrections."); + } + $ENV{'form.scantron_options_ignore'}='done'; + } if ($ENV{'form.scantron_corrections'}) { &scantron_process_corrections($r); } @@ -3891,8 +3905,8 @@ sub scantron_validate_file { - - + + $default_form_data SCANTRONFORM $r->print($result); @@ -3939,6 +3953,37 @@ SCANTRONFORM return ''; } +sub scantron_remove { + my ($which)=@_; + my $cname=$ENV{'course.'.$ENV{'request.course.id'}.'.num'}; + my $cdom=$ENV{'course.'.$ENV{'request.course.id'}.'.domain'}; + my $file='scantron_'; + if ($which eq 'corrected') { + $file.='corrected_'; + } else { + return 'refused'; + } + $file.=$ENV{'form.scantron_selectfile'}; + &Apache::lonnet::logthis("removeing $file"); + my $result=&Apache::lonnet::removeuserfile($cname,$cdom,$file); + my @keys=&Apache::lonnet::getkeys('nohist_scantrondata',$cdom,$cname); + &Apache::lonnet::logthis('got keys '.join(':',@keys)); + &Apache::lonnet::logthis("cdom $cdom cname $cname"); + my @todelete; + my $filename=$ENV{'form.scantron_selectfile'}; + &Apache::lonnet::logthis('filename '.$filename); + foreach my $key (@keys) { + if ($key=~/^\Q$filename\E_/) { + push(@todelete,$key); + } + } + &Apache::lonnet::logthis('todelete '.join(':',@todelete)); + if (@todelete) { + &Apache::lonnet::del('nohist_scantrondata',\@todelete,$cdom,$cname); + } + return $result; +} + sub scantron_getfile { #FIXME really would prefer a scantron directory but tokenwrapper # doesn't allow access to subdirs of userfiles @@ -4240,7 +4285,8 @@ sub scantron_validate_CODE { $line,'incorrectCODE',$CODE); return(1); } - if (exists($usedCODEs{$CODE}) && $ENV{'form.scantron_CODEunique'}) { + if (exists($usedCODEs{$CODE}) && $ENV{'form.scantron_CODEunique'} + && !$$scan_record{'scantron.CODE_ignore_dup'}) { &scantron_get_correction($r,$i,$scan_record, \%scantron_config, $line,'duplicateCODE',$CODE);