+STUFF
+ $r->print(" ".&show_grading_menu_form($symb,$url)."");
+ return '';
+}
+
+sub scantron_form_start {
+ my ($max_bubble)=@_;
+ my $result= <
+
+
+
+
+
+
+
+
+SCANTRONFORM
+ return $result;
+}
sub scantron_validate_file {
my ($r) = @_;
my ($symb,$url)=&get_symb_and_url($r);
if (!$symb) {return '';}
my $default_form_data=&defaultFormData($symb,$url);
+
+ # do the detection of only doing skipped records first befroe we delete
+ # them when doing the corrections reset
+ if ($ENV{'form.scantron_options_redo'} ne 'redo_skipped_ready') {
+ &reset_skipping_status();
+ }
+ if ($ENV{'form.scantron_options_redo'} eq 'redo_skipped') {
+ &remember_current_skipped();
+ &scantron_remove_file('skipped');
+ $ENV{'form.scantron_options_redo'}='redo_skipped_ready';
+ }
+
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.");
- }
+ &check_for_error($r,&scantron_remove_file('corrected'));
+ &check_for_error($r,&scantron_remove_file('skipped'));
+ &check_for_error($r,&scantron_remove_scan_data());
$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
+ my $max_bubble=&scantron_get_maxbubble($r);
+ my $result=&scantron_form_start($max_bubble).$default_form_data;
$r->print($result);
my @validate_phases=( 'ID',
@@ -3938,9 +4056,14 @@ SCANTRONFORM
}
}
if (!$stop) {
- $r->print("Validation process complete. ");
- $r->print('');
- $r->print('');
+ my $warning=&scantron_warning_screen('Start Grading');
+ $r->print(<
+$warning
+
+
+STUFF
+
} else {
$r->print('');
$r->print("");
@@ -3956,35 +4079,44 @@ SCANTRONFORM
return '';
}
-sub scantron_remove {
+sub scantron_remove_file {
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_';
+ if ($which eq 'corrected' || $which eq 'skipped') {
+ $file.=$which.'_';
} else {
return 'refused';
}
$file.=$ENV{'form.scantron_selectfile'};
- my $result=&Apache::lonnet::removeuserfile($cname,$cdom,$file);
+ return &Apache::lonnet::removeuserfile($cname,$cdom,$file);
+}
+
+sub scantron_remove_scan_data {
+ my $cname=$ENV{'course.'.$ENV{'request.course.id'}.'.num'};
+ my $cdom=$ENV{'course.'.$ENV{'request.course.id'}.'.domain'};
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_/) {
+ if ($ENV{'form.scantron_options_redo'} eq 'redo_skipped_ready' &&
+ $key=~/remember_skipping/) {
+ next;
+ }
push(@todelete,$key);
}
}
+ my $result;
if (@todelete) {
- &Apache::lonnet::del('nohist_scantrondata',\@todelete,$cdom,$cname);
+ $result=&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
+ #FIXME really would prefer a scantron directory
my $cname=$ENV{'course.'.$ENV{'request.course.id'}.'.num'};
my $cdom=$ENV{'course.'.$ENV{'request.course.id'}.'.domain'};
my $lines;
@@ -4027,34 +4159,48 @@ sub lonnet_putfile {
sub scantron_putfile {
my ($scanlines,$scan_data) = @_;
- #FIXME really would prefer a scantron directory but tokenwrapper
- # doesn't allow access to subdirs of userfiles
+ #FIXME really would prefer a scantron directory
my $cname=$ENV{'course.'.$ENV{'request.course.id'}.'.num'};
my $cdom=$ENV{'course.'.$ENV{'request.course.id'}.'.domain'};
- my $prefix='scantron_';
+ if ($scanlines) {
+ my $prefix='scantron_';
# no need to update orig, shouldn't change
# &lonnet_putfile(join("\n",@{$scanlines->{'orig'}}),$prefix.'orig_'.
# $ENV{'form.scantron_selectfile'});
- &lonnet_putfile(join("\n",@{$scanlines->{'corrected'}}),
- $prefix.'corrected_'.
- $ENV{'form.scantron_selectfile'});
- &lonnet_putfile(join("\n",@{$scanlines->{'skipped'}}),
- $prefix.'skipped_'.
- $ENV{'form.scantron_selectfile'});
+ &lonnet_putfile(join("\n",@{$scanlines->{'corrected'}}),
+ $prefix.'corrected_'.
+ $ENV{'form.scantron_selectfile'});
+ &lonnet_putfile(join("\n",@{$scanlines->{'skipped'}}),
+ $prefix.'skipped_'.
+ $ENV{'form.scantron_selectfile'});
+ }
&Apache::lonnet::put('nohist_scantrondata',$scan_data,$cdom,$cname);
}
sub scantron_get_line {
- my ($scanlines,$i)=@_;
- if ($scanlines->{'skipped'}[$i]) {return undef;}
+ my ($scanlines,$scan_data,$i)=@_;
+ if (&should_be_skipped($scan_data,$i)) { return undef; }
+ if ($scanlines->{'skipped'}[$i]) { return undef; }
if ($scanlines->{'corrected'}[$i]) {return $scanlines->{'corrected'}[$i];}
return $scanlines->{'orig'}[$i];
}
+sub get_todo_count {
+ my ($scanlines,$scan_data)=@_;
+ my $count=0;
+ for (my $i=0;$i<=$scanlines->{'count'};$i++) {
+ my $line=&scantron_get_line($scanlines,$scan_data,$i);
+ if ($line=~/^[\s\cz]*$/) { next; }
+ $count++;
+ }
+ return $count;
+}
+
sub scantron_put_line {
- my ($scanlines,$i,$newline,$skip)=@_;
+ my ($scanlines,$scan_data,$i,$newline,$skip)=@_;
if ($skip) {
$scanlines->{'skipped'}[$i]=$newline;
+ &allow_skipping($scan_data,$i);
return;
}
$scanlines->{'corrected'}[$i]=$newline;
@@ -4073,7 +4219,7 @@ sub scantron_validate_ID {
my %found=('ids'=>{},'usernames'=>{});
for (my $i=0;$i<=$scanlines->{'count'};$i++) {
- my $line=&scantron_get_line($scanlines,$i);
+ my $line=&scantron_get_line($scanlines,$scan_data,$i);
if ($line=~/^[\s\cz]*$/) { next; }
my $scan_record=&scantron_parse_scanline($line,$i,\%scantron_config,
$scan_data);
@@ -4308,7 +4454,7 @@ sub scantron_validate_CODE {
my ($scanlines,$scan_data)=&scantron_getfile();
for (my $i=0;$i<=$scanlines->{'count'};$i++) {
- my $line=&scantron_get_line($scanlines,$i);
+ my $line=&scantron_get_line($scanlines,$scan_data,$i);
if ($line=~/^[\s\cz]*$/) { next; }
my $scan_record=&scantron_parse_scanline($line,$i,\%scantron_config,
$scan_data);
@@ -4320,7 +4466,8 @@ sub scantron_validate_CODE {
$line,'incorrectCODE',\%allcodes);
return(1,$currentphase);
}
- if (exists($usedCODEs{$CODE}) && $ENV{'form.scantron_CODEunique'}
+ if (exists($usedCODEs{$CODE})
+ && $ENV{'form.scantron_CODEunique'} eq 'yes'
&& !$$scan_record{'scantron.CODE_ignore_dup'}) {
&scantron_get_correction($r,$i,$scan_record,
\%scantron_config,
@@ -4342,7 +4489,7 @@ sub scantron_validate_doublebubble {
my %scantron_config=&get_scantron_config($ENV{'form.scantron_format'});
my ($scanlines,$scan_data)=&scantron_getfile();
for (my $i=0;$i<=$scanlines->{'count'};$i++) {
- my $line=&scantron_get_line($scanlines,$i);
+ my $line=&scantron_get_line($scanlines,$scan_data,$i);
if ($line=~/^[\s\cz]*$/) { next; }
my $scan_record=&scantron_parse_scanline($line,$i,\%scantron_config,
$scan_data);
@@ -4392,7 +4539,7 @@ sub scantron_validate_missingbubbles {
my $max_bubble=&scantron_get_maxbubble();
if (!$max_bubble) { $max_bubble=2**31; }
for (my $i=0;$i<=$scanlines->{'count'};$i++) {
- my $line=&scantron_get_line($scanlines,$i);
+ my $line=&scantron_get_line($scanlines,$scan_data,$i);
if ($line=~/^[\s\cz]*$/) { next; }
my $scan_record=&scantron_parse_scanline($line,$i,\%scantron_config,
$scan_data);
@@ -4437,19 +4584,25 @@ SCANTRONFORM
my @delayqueue;
my %completedstudents;
+ my $count=&get_todo_count($scanlines,$scan_data);
my %prog_state=&Apache::lonhtmlcommon::Create_PrgWin($r,'Scantron Status',
- 'Scantron Progress',$scanlines->{'count'},
+ 'Scantron Progress',$count,
'inline',undef,'scantronupload');
&Apache::lonhtmlcommon::Update_PrgWin($r,\%prog_state,
'Processing first student');
my $start=&Time::HiRes::time();
my $i=-1;
- my ($uname,$udom);
+ my ($uname,$udom,$started);
while ($i<$scanlines->{'count'}) {
($uname,$udom)=('','');
$i++;
- my $line=&scantron_get_line($scanlines,$i);
+ my $line=&scantron_get_line($scanlines,$scan_data,$i);
if ($line=~/^[\s\cz]*$/) { next; }
+ if ($started) {
+ &Apache::lonhtmlcommon::Increment_PrgWin($r,\%prog_state,
+ 'last student');
+ }
+ $started=1;
my $scan_record=&scantron_parse_scanline($line,$i,\%scantron_config,
$scan_data);
unless ($uname=&scantron_find_student($scan_record,$scan_data,
@@ -4481,21 +4634,19 @@ SCANTRONFORM
$form{'CODE'}=$scan_record->{'scantron.CODE'};
}
my $result=&Apache::lonnet::ssi($resource->src(),%form);
-
+ if (&Apache::loncommon::connection_aborted($r)) { last; }
}
$completedstudents{$uname}={'line'=>$line};
+ if (&Apache::loncommon::connection_aborted($r)) { last; }
} continue {
&Apache::lonnet::delenv('form.counter');
&Apache::lonnet::delenv('scantron\.');
- &Apache::lonhtmlcommon::Increment_PrgWin($r,\%prog_state,
- 'last student');
}
&Apache::lonhtmlcommon::Close_PrgWin($r,\%prog_state);
# my $lasttime = &Time::HiRes::time()-$start;
# $r->print("took $lasttime ");
- $navmap->untieHashes();
- $r->print("Done ");
+ $r->print("");
$r->print(&show_grading_menu_form($symb,$url));
return '';
}
@@ -4555,7 +4706,8 @@ sub scantron_upload_scantron_data_save {
}
return '';
}
- $r->print("Doing upload to ".$ENV{'form.courseid'}." ");
+ my %coursedata=&Apache::lonnet::coursedescription($ENV{'form.domainid'}.'_'.$ENV{'form.courseid'});
+ $r->print("Doing upload to ".$coursedata{'description'}." ");
my $home=&Apache::lonnet::homeserver($ENV{'form.courseid'},
$ENV{'form.domainid'});
my $fname=$ENV{'form.upfile.filename'};
@@ -4572,6 +4724,7 @@ sub scantron_upload_scantron_data_save {
$fname=~s/[^\w\.\-]//g;
# See if there is anything left
unless ($fname) { return 'error: no uploaded file'; }
+ my $uploadedfile=$fname;
$fname='scantron_orig_'.$fname;
if (length($ENV{'form.upfile'}) < 2) {
$r->print("Error: The file you attempted to upload, ".&HTML::Entities::encode($ENV{'form.upfile.filename'},'<>&"').", contained no information. Please check that you entered the correct filename.");
@@ -4580,17 +4733,61 @@ sub scantron_upload_scantron_data_save {
if ($result =~ m|^/uploaded/|) {
$r->print("Success: Successfully uploaded ".(length($ENV{'form.upfile'})-1)." bytes of data into location ".$result."");
} else {
- $r->print("Error: An error (".$result.") occured when attempting to upload the file, ".&HTML::Entities::encode($ENV{'form.upfile.filename'},'<>&"')."");
+ $r->print("Error: An error (".$result.") occurred when attempting to upload the file, ".&HTML::Entities::encode($ENV{'form.upfile.filename'},'<>&"')."");
}
}
if ($symb) {
- $r->print(&show_grading_menu_form($symb,$url));
+ $r->print(&scantron_selectphase($r,$uploadedfile));
} else {
$r->print($doanotherupload);
}
return '';
}
+sub valid_file {
+ my ($requested_file)=@_;
+ foreach my $filename (sort(&scantron_filenames())) {
+ &Apache::lonnet::logthis("$requested_file $filename");
+ if ($requested_file eq $filename) { return 1; }
+ }
+ return 0;
+}
+
+sub scantron_download_scantron_data {
+ my ($r)=@_;
+ my $default_form_data=&defaultFormData(&get_symb_and_url($r,1));
+ my $cname=$ENV{'course.'.$ENV{'request.course.id'}.'.num'};
+ my $cdom=$ENV{'course.'.$ENV{'request.course.id'}.'.domain'};
+ my $file=$ENV{'form.scantron_selectfile'};
+ if (! &valid_file($file)) {
+ $r->print(<
+ The requested file name was invalid.
+
+ERROR
+ $r->print(&show_grading_menu_form(&get_symb_and_url($r,1)));
+ return;
+ }
+ my $orig='/uploaded/'.$cdom.'/'.$cname.'/scantron_orig_'.$file;
+ my $corrected='/uploaded/'.$cdom.'/'.$cname.'/scantron_corrected_'.$file;
+ my $skipped='/uploaded/'.$cdom.'/'.$cname.'/scantron_skipped_'.$file;
+ &Apache::lonnet::allowuploaded('/adm/grades',$orig);
+ &Apache::lonnet::allowuploaded('/adm/grades',$corrected);
+ &Apache::lonnet::allowuploaded('/adm/grades',$skipped);
+ $r->print(<
+ Original file as uploaded by the scantron office.
+
+
+ Corrections, a file of corrected records that were used in grading.
+
+
+ Skipped, a file of records that were skipped.
+
+DOWNLOAD
+ $r->print(&show_grading_menu_form(&get_symb_and_url($r,1)));
+ return '';
+}
#-------- end of section for handling grading scantron forms -------
#
@@ -4705,9 +4902,6 @@ GRADINGMENUJS
$result.=&mt('Student Status').':'.&Apache::lonhtmlcommon::StatusOptions($saveStatus,undef,1,undef);
- if (ref($sections) && (grep /no/,@$sections)) {
- $result.=' (Section "no" implies the students were not assigned a section.) ';
- }
$result.=' |
';
$result.='