@@ -3689,17 +3687,19 @@ sub scantron_fixup_scanline {
$args->{'username'}.':'.$args->{'domain'});
}
} elsif ($field eq 'CODE') {
- if (length($args->{'CODE'}) > $$scantron_config{'CODElength'}) {
- return ($line,1,'New CODE value too large');
+ if ($args->{'CODE_ignore_dup'}) {
+ &scan_data($scan_data,"$whichline.CODE_ignore_dup",'1');
}
- if (length($args->{'CODE'}) < $$scantron_config{'CODElength'}) {
- $args->{'CODE'}=sprintf('%-'.$$scantron_config{'CODElength'}.'s',
- $args->{'CODE'});
- }
- substr($line,$$scantron_config{'CODEstart'}-1,
- $$scantron_config{'CODElength'})=$args->{'CODE'};
- if ($args->{'CODE'}=~/^\s*$/) {
- &scan_data($scan_data,"$whichline.CODE",$args->{'CODE'});
+ &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');
+ }
+ if (length($args->{'CODE'}) < $$scantron_config{'CODElength'}) {
+ $args->{'CODE'}=sprintf('%-'.$$scantron_config{'CODElength'}.'s',$args->{'CODE'});
+ }
+ substr($line,$$scantron_config{'CODEstart'}-1,
+ $$scantron_config{'CODElength'})=$args->{'CODE'};
}
} elsif ($field eq 'answer') {
my $length=$scantron_config->{'Qlength'};
@@ -3731,19 +3731,25 @@ sub scan_data {
}
sub scantron_parse_scanline {
- my ($line,$whichline,$scantron_config,$scan_data,$justCODE)=@_;
+ my ($line,$whichline,$scantron_config,$scan_data,$justHeader)=@_;
my %record;
my $questions=substr($line,$$scantron_config{'Qstart'}-1);
my $data=substr($line,0,$$scantron_config{'Qstart'}-1);
if ($$scantron_config{'CODElocation'} ne 0) {
if ($$scantron_config{'CODElocation'} < 0) {
- $record{'scantron.CODE'}=substr($data,$$scantron_config{'CODEstart'}-1,
+ $record{'scantron.CODE'}=substr($data,
+ $$scantron_config{'CODEstart'}-1,
$$scantron_config{'CODElength'});
+ 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
}
}
- if ($justCODE) { return \%record; }
$record{'scantron.ID'}=substr($data,$$scantron_config{'IDstart'}-1,
$$scantron_config{'IDlength'});
$record{'scantron.PaperID'}=
@@ -3755,6 +3761,8 @@ sub scantron_parse_scanline {
$record{'scantron.LastName'}=
substr($data,$$scantron_config{'LastName'}-1,
$$scantron_config{'LastNamelength'});
+ if ($justHeader) { return \%record; }
+
my @alphabet=('A'..'Z');
my $questnum=0;
while ($questions) {
@@ -3836,10 +3844,25 @@ sub scantron_process_corrections {
'username'=>$ENV{'form.scantron_username'},
'domain'=>$ENV{'form.scantron_domain'}});
} elsif ($ENV{'form.scantron_corrections'} =~ /^(duplicate|incorrect)CODE$/) {
- my $newCODE=$ENV{'form.scantron_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') {
+ $newCODE=$ENV{'form.scantron_CODE_selectedvalue'};
+ } elsif ($resolution eq 'use_typed') {
+ $newCODE=$ENV{'form.scantron_CODE_newvalue'};
+ } elsif ($resolution =~ /^use_closest_(\d+)/) {
+ $newCODE=$ENV{"form.scantron_CODE_closest_$1"};
+ }
+ 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)=
@@ -3864,10 +3887,18 @@ 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');
+ 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);
}
+ $r->print("Gathering neccessary info.
");$r->rflush();
+ my $max_bubble=&scantron_get_maxbubble($r);
#get the student pick code ready
$r->print(&Apache::loncommon::studentbrowser_javascript());
my $result= <
-
+
+
+
+
+
$default_form_data
SCANTRONFORM
$r->print($result);
@@ -3885,14 +3920,10 @@ SCANTRONFORM
'doublebubble',
'missingbubbles');
if (!$ENV{'form.validatepass'}) {
- $ENV{'form.valiadatepass'} = 0;
+ $ENV{'form.validatepass'} = 0;
}
- my $currentphase=$ENV{'form.valiadatepass'};
+ my $currentphase=$ENV{'form.validatepass'};
- if ($ENV{'form.scantron_selectfile'}=~m-^/-) {
- #first pass copy file to classdir
-
- }
my $stop=0;
while (!$stop && $currentphase < scalar(@validate_phases)) {
$r->print(" Validating ".$validate_phases[$currentphase]."
");
@@ -3922,6 +3953,32 @@ 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'};
+ my $result=&Apache::lonnet::removeuserfile($cname,$cdom,$file);
+ my @keys=&Apache::lonnet::getkeys('nohist_scantrondata',$cdom,$cname);
+ my @todelete;
+ my $filename=$ENV{'form.scantron_selectfile'};
+ foreach my $key (@keys) {
+ if ($key=~/^\Q$filename\E_/) {
+ push(@todelete,$key);
+ }
+ }
+ 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
@@ -4027,11 +4084,11 @@ sub scantron_validate_ID {
if ($found{'ids'}{$found}) {
&scantron_get_correction($r,$i,$scan_record,\%scantron_config,
$line,'duplicateID',$found);
- return(1);
+ return(1,$currentphase);
} elsif ($found{'usernames'}{$username}) {
&scantron_get_correction($r,$i,$scan_record,\%scantron_config,
$line,'duplicateID',$username);
- return(1);
+ return(1,$currentphase);
}
#FIXME store away line we previously saw the ID on to use above
$found{'ids'}{$found}++;
@@ -4043,18 +4100,18 @@ sub scantron_validate_ID {
&scantron_get_correction($r,$i,$scan_record,
\%scantron_config,
$line,'duplicateID',$username);
- return(1);
+ return(1,$currentphase);
} elsif (!defined($username)) {
&scantron_get_correction($r,$i,$scan_record,
\%scantron_config,
$line,'incorrectID');
- return(1);
+ return(1,$currentphase);
}
$found{'usernames'}{$username}++;
} else {
&scantron_get_correction($r,$i,$scan_record,\%scantron_config,
$line,'incorrectID');
- return(1);
+ return(1,$currentphase);
}
}
}
@@ -4105,7 +4162,7 @@ sub scantron_get_correction {
if ($error eq 'incorrectCODE') {
$r->print("The encoded CODE is not in the list of possible CODEs
\n");
} elsif ($error eq 'duplicateCODE') {
- $r->print("The encoded CODE has also been used by a previous paper $arg, and CODEs were supposed to be unique
\n");
+ $r->print("The encoded CODE has also been used by a previous paper ".join(', ',@{$arg}).", and CODEs are supposed to be unique
\n");
}
$r->print("The CODE on the form is ".
$$scan_record{'scantron.CODE'}." \n");
@@ -4116,12 +4173,25 @@ sub scantron_get_correction {
$$scan_record{'scantron.FirstName'}."
");
$r->print("How should I handle this? \n");
$r->print("\n ");
- $r->print(" Use the CODE ".$$scan_record{'scantron.CODE'}." that is was on the paper, ignoring the error.");
+ my $i=0;
+ if ($error eq 'incorrectCODE') {
+ my ($max,$closest)=&scantron_get_closely_matching_CODEs($arg,$$scan_record{'scantron.CODE'});
+ foreach my $testcode (@{$closest}) {
+ my $checked='';
+ if (!$i) { $checked=' checked="on" '; }
+ $r->print(" Use the similar CODE ".$testcode." instead. ");
+ $r->print("\n ");
+ $i++;
+ }
+ }
+ my $checked; if (!$i) { $checked=' checked="on" '; }
+ $r->print(" Use the CODE ".$$scan_record{'scantron.CODE'}." that is was on the paper, ignoring the error.");
$r->print("\n ");
+
$r->print(<
function change_radio(field) {
- var slct=document.scantronupload.scan_CODE_resolution;
+ var slct=document.scantronupload.scantron_CODE_resolution;
var i;
for (i=0;iprint(" Select a CODE from the list of all CODEs and use it. Selected CODE is ");
+ $r->print(" Select a CODE from the list of all CODEs and use it. Selected CODE is ");
$r->print("\n ");
- $r->print(" Use as the CODE.");
+ $r->print(" Use as the CODE.");
$r->print("\n ");
} elsif ($error eq 'doublebubble') {
-#FIXME Need to print out who this is along with the paper info
$r->print("There have been multiple bubbles scanned for a some question(s)
\n");
$r->print(' ');
@@ -4187,28 +4256,52 @@ sub scantron_bubble_selector {
$r->print('
');
}
+sub num_matches {
+ my ($orig,$code) = @_;
+ my @code=split(//,$code);
+ my @orig=split(//,$orig);
+ my $same=0;
+ for (my $i=0;$i