--- loncom/homework/grades.pm 2020/05/08 15:12:34 1.769 +++ loncom/homework/grades.pm 2020/05/20 22:02:57 1.770 @@ -1,7 +1,7 @@ # The LearningOnline Network with CAPA # The LON-CAPA Grading handler # -# $Id: grades.pm,v 1.769 2020/05/08 15:12:34 raeburn Exp $ +# $Id: grades.pm,v 1.770 2020/05/20 22:02:57 raeburn Exp $ # # Copyright Michigan State University Board of Trustees # @@ -5897,8 +5897,7 @@ sub scantron_selectphase { $ssi_error = 0; - if (&Apache::lonnet::allowed('usc',$env{'request.role.domain'}) || - &Apache::lonnet::allowed('usc',$env{'request.course.id'})) { + if (&Apache::lonnet::allowed('usc',$env{'request.role.domain'}) || $perm{'usc'}) { # Chunk of form to prompt for a scantron file upload. @@ -5906,6 +5905,7 @@ sub scantron_selectphase {
'); my $cdom= $env{'course.'.$env{'request.course.id'}.'.domain'}; my $cnum= $env{'course.'.$env{'request.course.id'}.'.num'}; + my $csec= $env{'request.course.sec'}; my $alertmsg = &mt('Please use the browse button to select a file from your local directory.'); &js_escape(\$alertmsg); my ($formatoptions,$formattitle,$formatjs) = &scantron_upload_dataformat($cdom); @@ -5921,6 +5921,7 @@ sub scantron_selectphase {
'.$default_form_data.' + '.&Apache::loncommon::start_data_table('LC_scantron_action').' @@ -6978,7 +6979,7 @@ sub scantron_warning_screen { ''.&mt('Hand-graded items: points from last bubble in row').''. $env{'form.scantron_lastbubblepoints'}.''; } - return (' + return '

'.&mt("Please double check the information below before clicking on '[_1]'",&mt($button_text)).' @@ -6990,9 +6991,7 @@ sub scantron_warning_screen {

'.&mt("If this information is correct, please click on '[_1]'.",&mt($button_text)).'
'.&mt('If something is incorrect, please return to [_1]Grade/Manage/Review Bubblesheets[_2] to start over.','','').'

- -
-'); +'; } =pod @@ -7018,15 +7017,58 @@ sub scantron_do_warning { } if ( $env{'form.scantron_selectfile'} eq '') { $r->print('

'.&mt("You have not selected a file that contains the student's response data.").'

'); - } + } if ( $env{'form.scantron_format'} eq '') { $r->print('

'.&mt("You have not selected the format of the student's response data.").'

'); - } + } } else { my $warning=&scantron_warning_screen('Grading: Validate Records',$symb); + my ($checksec,@possibles) = &gradable_sections(); + my $gradesections; + if ($checksec) { + my $file=$env{'form.scantron_selectfile'}; + if (&valid_file($file)) { + my %bysec = &scantron_get_sections(); + my $table; + if ((keys(%bysec) > 1) || ((keys(%bysec) == 1) && ((keys(%bysec))[0] ne $checksec))) { + $gradesections = &mt('Your current role is for section [_1].',''.$checksec.'').'
'; + $table = &Apache::loncommon::start_data_table()."\n". + &Apache::loncommon::start_data_table_header_row(). + ''.&mt('Section').''.&mt('Number of records').''. + &Apache::loncommon::end_data_table_header_row()."\n"; + if ($bysec{'none'}) { + $table .= &Apache::loncommon::start_data_table_row(). + ''.&mt('None').''.$bysec{'none'}.''. + &Apache::loncommon::end_data_table_row()."\n"; + } + foreach my $sec (sort { $a <=> $b } keys(%bysec)) { + next if ($sec eq 'none'); + $table .= &Apache::loncommon::start_data_table_row(). + ''.$sec.''.$bysec{$sec}.''. + &Apache::loncommon::end_data_table_row()."\n"; + } + $table .= &Apache::loncommon::end_data_table()."\n"; + $gradesections .= &mt('Sections represented in the bubblesheet data file (based on bubbled student IDs) are as follows:'). + '

'.$table.'

'; + if (@possibles) { + $gradesections .= '

'. + &mt('You have role(s) in [quant,_1,other section,other sections] with privileges to manage grades.', + scalar(@possibles)).'
'. + &mt('Check which of those section(s), in addition to section [_1], you wish to grade using this bubblesheet file:', + ''.$checksec.'').' '; + foreach my $sec (sort {$a <=> $b } @possibles) { + $gradesections .= ''.(' 'x2); + } + $gradesections .= '

'; + } + } + } else { + $gradesections = '

'.&mt('The selected file is unavailable').'

'; + } + } my $bubbledbyhand=&hand_bubble_option(); $r->print(' -'.$warning.$bubbledbyhand.' +'.$warning.$gradesections.$bubbledbyhand.' '); @@ -7113,7 +7155,38 @@ sub scantron_validate_file { if ($env{'form.scantron_corrections'}) { &scantron_process_corrections($r); } - $r->print('

'.&mt('Gathering necessary information.').'

');$r->rflush(); + + $r->print('

'.&mt('Gathering necessary information.').'

'); + my ($checksec,@gradable); + if ($env{'request.course.sec'}) { + ($checksec,my @possibles) = &gradable_sections(); + if ($checksec) { + if (@possibles) { + my @chosensecs = &Apache::loncommon::get_env_multiple('form.scantron_othersections'); + if (@chosensecs) { + foreach my $sec (@chosensecs) { + if (grep(/^\Q$sec\E$/,@possibles)) { + unless (grep(/^\Q$sec\E$/,@gradable)) { + push(@gradable,$sec); + } + } + } + } + } + $r->print('

'); + if (@gradable) { + my @showsections = sort { $a <=> $b } (@gradable,$checksec); + $r->print( + ''); + } else { + $r->print( + ''); + } + $r->print('
'.&mt('Sections to be Graded:').''.join(', ',@showsections).'
'.&mt('Section to be Graded:').''.$checksec.'

'); + } + } + $r->rflush(); + #get the student pick code ready $r->print(&Apache::loncommon::studentbrowser_javascript()); my $nav_error; @@ -7138,7 +7211,7 @@ sub scantron_validate_file { $env{'form.validatepass'} = 0; } my $currentphase=$env{'form.validatepass'}; - + my %skipbysec=(); my $stop=0; while (!$stop && $currentphase < scalar(@validate_phases)) { @@ -7148,13 +7221,29 @@ sub scantron_validate_file { my $which="scantron_validate_".$validate_phases[$currentphase]; { no strict 'refs'; - ($stop,$currentphase)=&$which($r,$currentphase); + my @extras=(); + if ($validate_phases[$currentphase] eq 'ID') { + @extras = (\%skipbysec,$checksec,@gradable); + } + ($stop,$currentphase)=&$which($r,$currentphase,@extras); } } if (!$stop) { my $warning=&scantron_warning_screen('Start Grading',$symb); + my $secinfo; + if (keys(%skipbysec) > 0) { + my $seclist = ''; + $secinfo = '

'. + &mt('Numbers of records for students in sections not being graded [_1]', + $seclist). + '

'; + } $r->print(&mt('Validation process complete.').'
'. - $warning. + $secinfo.$warning. &mt('Perform verification for each student after storage of submissions?'). ' '. @@ -7570,11 +7659,12 @@ sub scantron_validate_sequence { sub scantron_validate_ID { - my ($r,$currentphase) = @_; + my ($r,$currentphase,$skipbysec,$checksec,@gradable) = @_; #get student info my $classlist=&Apache::loncoursedata::get_classlist(); my %idmap=&username_to_idmap($classlist); + my $secidx = &Apache::loncoursedata::CL_SECTION(); #get scantron line setup my %scantron_config=&Apache::lonnet::get_scantron_config($env{'form.scantron_format'}); @@ -7588,6 +7678,7 @@ sub scantron_validate_ID { } my %found=('ids'=>{},'usernames'=>{}); + my $unsavedskips = 0; for (my $i=0;$i<=$scanlines->{'count'};$i++) { my $line=&scantron_get_line($scanlines,$scan_data,$i); if ($line=~/^[\s\cz]*$/) { next; } @@ -7600,13 +7691,41 @@ sub scantron_validate_ID { } if ($found) { my $username=$idmap{$found}; + if ($checksec) { + if (ref($classlist->{$username}) eq 'ARRAY') { + my $stusec = $classlist->{$username}->[$secidx]; + if ($stusec ne $checksec) { + unless ((@gradable > 0) && (grep(/^\Q$stusec\E$/,@gradable))) { + my $skip=1; + &scantron_put_line($scanlines,$scan_data,$i,$line,$skip); + if (ref($skipbysec) eq 'HASH') { + if ($stusec eq '') { + $skipbysec->{'none'} ++; + } else { + $skipbysec->{$stusec} ++; + } + } + $unsavedskips ++; + next; + } + } + } + } if ($found{'ids'}{$found}) { &scantron_get_correction($r,$i,$scan_record,\%scantron_config, $line,'duplicateID',$found); + if ($unsavedskips) { + &scantron_putfile($scanlines,$scan_data); + $unsavedskips = 0; + } return(1,$currentphase); } elsif ($found{'usernames'}{$username}) { &scantron_get_correction($r,$i,$scan_record,\%scantron_config, $line,'duplicateID',$username); + if ($unsavedskips) { + &scantron_putfile($scanlines,$scan_data); + $unsavedskips = 0; + } return(1,$currentphase); } #FIXME store away line we previously saw the ID on to use above @@ -7615,29 +7734,95 @@ sub scantron_validate_ID { } else { if ($id =~ /^\s*$/) { my $username=&scan_data($scan_data,"$i.user"); - if (defined($username) && $found{'usernames'}{$username}) { + if (($checksec && $username ne '')) { + if (ref($classlist->{$username}) eq 'ARRAY') { + my $stusec = $classlist->{$username}->[$secidx]; + if ($stusec ne $checksec) { + unless ((@gradable > 0) && (grep(/^\Q$stusec\E$/,@gradable))) { + my $skip=1; + &scantron_put_line($scanlines,$scan_data,$i,$line,$skip); + if (ref($skipbysec) eq 'HASH') { + if ($stusec eq '') { + $skipbysec->{'none'} ++; + } else { + $skipbysec->{$stusec} ++; + } + } + $unsavedskips ++; + next; + } + } + } + } elsif (defined($username) && $found{'usernames'}{$username}) { &scantron_get_correction($r,$i,$scan_record, \%scantron_config, $line,'duplicateID',$username); + if ($unsavedskips) { + &scantron_putfile($scanlines,$scan_data); + $unsavedskips = 0; + } return(1,$currentphase); } elsif (!defined($username)) { &scantron_get_correction($r,$i,$scan_record, \%scantron_config, $line,'incorrectID'); + if ($unsavedskips) { + &scantron_putfile($scanlines,$scan_data); + $unsavedskips = 0; + } return(1,$currentphase); } $found{'usernames'}{$username}++; } else { &scantron_get_correction($r,$i,$scan_record,\%scantron_config, $line,'incorrectID'); + if ($unsavedskips) { + &scantron_putfile($scanlines,$scan_data); + $unsavedskips = 0; + } return(1,$currentphase); } } } - + if ($unsavedskips) { + &scantron_putfile($scanlines,$scan_data); + $unsavedskips = 0; + } return (0,$currentphase+1); } +sub scantron_get_sections { + my %bysec; + if ($env{'form.scantron_format'} ne '') { + my %scantron_config=&Apache::lonnet::get_scantron_config($env{'form.scantron_format'}); + my ($scanlines,$scan_data)=&scantron_getfile(); + my $classlist=&Apache::loncoursedata::get_classlist(); + my %idmap=&username_to_idmap($classlist); + foreach my $key (keys(%idmap)) { + my $lckey = lc($key); + $idmap{$lckey} = $idmap{$key}; + } + my $secidx = &Apache::loncoursedata::CL_SECTION(); + for (my $i=0;$i<=$scanlines->{'count'};$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); + my $id=lc($$scan_record{'scantron.ID'}); + if (exists($idmap{$id})) { + if (ref($classlist->{$idmap{$id}}) eq 'ARRAY') { + my $stusec = $classlist->{$idmap{$id}}->[$secidx]; + if ($stusec eq '') { + $bysec{'none'} ++; + } else { + $bysec{$stusec} ++; + } + } + } + } + } + return %bysec; +} sub scantron_get_correction { my ($r,$i,$scan_record,$scan_config,$line,$error,$arg, @@ -8655,9 +8840,10 @@ sub scantron_process_students { SCANTRONFORM $r->print($result); + my ($checksec,@possibles)=&gradable_sections(); my @delayqueue; my (%completedstudents,%scandata); - + my $lock=&Apache::lonnet::set_lock(&mt('Grading bubblesheet exam')); my $count=&get_todo_count($scanlines,$scan_data); my %prog_state=&Apache::lonhtmlcommon::Create_PrgWin($r,$count); @@ -8717,6 +8903,13 @@ SCANTRONFORM next; } my $usec = $classlist->{$uname}->[&Apache::loncoursedata::CL_SECTION]; + if (($checksec ne '') && ($checksec ne $usec)) { + unless (grep(/^\Q$usec\E$/,@possibles)) { + &scantron_add_delay(\@delayqueue,$line, + "No role with manage grades privilege in student's section ($usec)",3); + next; + } + } my $user = $uname.':'.$usec; ($uname,$udom)=split(/:/,$uname); @@ -9172,7 +9365,9 @@ sub scantron_upload_scantron_data_save { ''."\n"; if (!&Apache::lonnet::allowed('usc',$env{'form.domainid'}) && !&Apache::lonnet::allowed('usc', - $env{'form.domainid'}.'_'.$env{'form.courseid'})) { + $env{'form.domainid'}.'_'.$env{'form.courseid'}) && + !&Apache::lonnet::allowed('usc', + $env{'form.domainid'}.'_'.$env{'form.courseid'}.'/'.$env{'form.coursesec'})) { $r->print(&mt("You are not allowed to upload bubblesheet data to the requested course.")."
"); unless ($symb) { $r->print($doanotherupload); @@ -9228,8 +9423,17 @@ sub scantron_upload_scantron_data_save { (length($env{'form.upfile'})-1), ''.$result.'')); ($uploadedfile) = ($result =~ m{/([^/]+)$}); + if ($uploadedfile =~ /^scantron_orig_/) { + my $logname = $uploadedfile; + $logname =~ s/^scantron_orig_//; + if ($logname ne '') { + my $now = time; + my %info = ($logname => { $now => $env{'user.name'}.':'.$env{'user.domain'} }); + &Apache::lonnet::put('scantronupload',\%info,$env{'form.domainid'},$env{'form.courseid'}); + } + } $r->print(&validate_uploaded_scantron_file($env{'form.domainid'}, - $env{'form.courseid'},$uploadedfile)); + $env{'form.courseid'},$symb,$uploadedfile)); } else { $r->print( &Apache::lonhtmlcommon::confirm_success(&mt('Upload failed'),1).'
'. @@ -9247,13 +9451,34 @@ sub scantron_upload_scantron_data_save { } sub validate_uploaded_scantron_file { - my ($cdom,$cname,$fname) = @_; + my ($cdom,$cname,$symb,$fname,$context,$countsref) = @_; + my $scanlines=&Apache::lonnet::getfile('/uploaded/'.$cdom.'/'.$cname.'/'.$fname); my @lines; if ($scanlines ne '-1') { @lines=split("\n",$scanlines,-1); } - my $output; + my ($output,$secidx,$checksec,$priv,%crsroleshash,@possibles); + $secidx = &Apache::loncoursedata::CL_SECTION(); + if ($context eq 'download') { + $priv = 'mgr'; + } else { + $priv = 'usc'; + } + unless ((&Apache::lonnet::allowed($priv,$env{'request.role.domain'})) || + (($env{'request.course.id'}) && + (&Apache::lonnet::allowed($priv,$env{'request.course.id'})))) { + if ($env{'request.course.sec'} ne '') { + unless (&Apache::lonnet::allowed($priv, + "$env{'request.course.id'}/$env{'request.course.sec'}")) { + unless ($context eq 'download') { + $output = '

'.&mt('You do not have permission to upload bubblesheet data').'

'; + } + return $output; + } + ($checksec,@possibles)=&gradable_sections(); + } + } if (@lines) { my (%counts,$max_match_format); my ($found_match_count,$max_match_count,$max_match_pct) = (0,0,0); @@ -9283,6 +9508,8 @@ sub validate_uploaded_scantron_file { %{$counts{$key}} = ( 'found' => 0, 'total' => 0, + 'totalanysec' => 0, + 'othersec' => 0, ); foreach my $line (@lines) { next if ($line =~ /^#/); @@ -9290,6 +9517,23 @@ sub validate_uploaded_scantron_file { my $id = substr($line,$idstart-1,$idlength); $id = lc($id); if (exists($idmap{$id})) { + if ($checksec ne '') { + $counts{$key}{'totalanysec'} ++; + if (ref($classlist->{$idmap{$id}}) eq 'ARRAY') { + my $stusec = $classlist->{$idmap{$id}}->[$secidx]; + if ($stusec ne $checksec) { + if (@possibles) { + unless (grep(/^\Q$stusec\E$/,@possibles)) { + $counts{$key}{'othersec'} ++; + next; + } + } else { + $counts{$key}{'othersec'} ++; + next; + } + } + } + } $counts{$key}{'found'} ++; } $counts{$key}{'total'} ++; @@ -9304,7 +9548,7 @@ sub validate_uploaded_scantron_file { } } } - if (ref($unique_formats{$max_match_format}) eq 'ARRAY') { + if ((ref($unique_formats{$max_match_format}) eq 'ARRAY') && ($context ne 'download')) { my $format_descs; my $numwithformat = @{$unique_formats{$max_match_format}}; for (my $i=0; $i<$numwithformat; $i++) { @@ -9349,13 +9593,179 @@ sub validate_uploaded_scantron_file { '
  • '.&mt('The course roster is not up to date.').'
  • '. ''; } + if (($checksec ne '') && (ref($counts{$max_match_format}) eq 'HASH')) { + if ($counts{$max_match_format}{'othersec'}) { + my $percent_nongrade = (100*$counts{$max_match_format}{'othersec'})/($counts{$max_match_format}{'totalanysec'}); + my $showpct = sprintf("%.0f",$percent_nongrade).'%'; + my $confirmdel = &mt('Are you sure you want to permanently delete this file?'); + &js_escape(\$confirmdel); + $output .= '

    '. + &mt('Comparison of student IDs in the uploaded file with the course roster found [_1][quant,_2,match,matches][_3] for students in section(s) for which none of your role(s) have privileges to modify grades', + '',$counts{$max_match_format}{'othersec'},''). + '
    '. + &mt('Unless you are assigned role(s) which allow modification of grades in additional sections, [_1] of the records in this file will be automatically excluded when you perform bubblesheet grading.',''.$showpct.''). + '

    '. + &mt('If you prefer to delete the file now, use: [_1]'). + '

    '. + ''. + ''. + ''. + ''. + ''. + ''. + ''. + '

    '; + } + } } - } else { + if (($context eq 'download') && ($checksec ne '')) { + if ((ref($countsref) eq 'HASH') && (ref($counts{$max_match_format}) eq 'HASH')) { + $countsref->{'totalanysec'} = $counts{$max_match_format}{'totalanysec'}; + $countsref->{'othersec'} = $counts{$max_match_format}{'othersec'}; + } + } + } elsif ($context ne 'download') { $output = '

    '.&mt('Uploaded file contained no data').'

    '; } return $output; } +sub gradable_sections { + my $checksec = $env{'request.course.sec'}; + my @oksecs; + if ($checksec) { + my %availablesecs = §ions_grade_privs(); + if (ref($availablesecs{'mgr'}) eq 'ARRAY') { + foreach my $sec (@{$availablesecs{'mgr'}}) { + unless (grep(/^\Q$sec\E$/,@oksecs)) { + push(@oksecs,$sec); + } + } + if (grep(/^all$/,@oksecs)) { + undef($checksec); + } + } + } + return($checksec,@oksecs); +} + +sub sections_grade_privs { + my $cdom = $env{'course.'.$env{'request.course.id'}.'.domain'}; + my $cnum = $env{'course.'.$env{'request.course.id'}.'.num'}; + my %availablesecs = ( + mgr => [], + vgr => [], + usc => [], + ); + my $ccrole = 'cc'; + if ($env{'course.'.$env{'request.course.id'}.'.type'} eq 'Community') { + $ccrole = 'co'; + } + my %crsroleshash = &Apache::lonnet::get_my_roles($env{'user.name'},$env{'user.domain'}, + 'userroles',['active'], + [$ccrole,'in','cr'],$cdom,1); + my $crsid = $cnum.':'.$cdom; + foreach my $item (keys(%crsroleshash)) { + next unless ($item =~ /^$crsid\:/); + my ($crsnum,$crsdom,$role,$sec) = split(/\:/,$item); + my $suffix = "/$cdom/$cnum./$cdom/$cnum"; + if ($sec ne '') { + $suffix = "/$cdom/$cnum/$sec./$cdom/$cnum/$sec"; + } + if (($role eq $ccrole) || ($role eq 'in')) { + foreach my $priv ('mgr','vgr','usc') { + unless (grep(/^all$/,@{$availablesecs{$priv}})) { + if ($sec eq '') { + $availablesecs{$priv} = ['all']; + } elsif ($sec ne $env{'request.course.sec'}) { + unless (grep(/^\Q$sec\E$/,@{$availablesecs{$priv}})) { + push(@{$availablesecs{$priv}},$sec); + } + } + } + } + } elsif ($role =~ m{^cr/}) { + foreach my $priv ('mgr','vgr','usc') { + unless (grep(/^all$/,@{$availablesecs{$priv}})) { + if ($env{"user.priv.$role.$suffix"} =~ /:$priv&/) { + if ($sec eq '') { + $availablesecs{$priv} = ['all']; + } elsif ($sec ne $env{'request.course.sec'}) { + unless (grep(/^\Q$sec\E$/,@{$availablesecs{$priv}})) { + push(@{$availablesecs{$priv}},$sec); + } + } + } + } + } + } + } + return %availablesecs; +} + +sub scantron_upload_delete { + my ($r,$symb) = @_; + my $filename = $env{'form.uploadedfile'}; + if ($filename =~ /^scantron_orig_/) { + if (&Apache::lonnet::allowed('usc',$env{'form.domainid'}) || + &Apache::lonnet::allowed('usc', + $env{'form.domainid'}.'_'.$env{'form.courseid'}) || + &Apache::lonnet::allowed('usc', + $env{'form.domainid'}.'_'.$env{'form.courseid'}.'/'.$env{'form.coursesec'})) { + my $uploadurl = '/uploaded/'.$env{'form.domainid'}.'/'.$env{'form.courseid'}.'/'.$env{'form.uploadedfile'}; + my $retrieval = &Apache::lonnet::getfile($uploadurl); + if ($retrieval eq '-1') { + $r->print(&Apache::lonhtmlcommon::confirm_success(&mt('File deletion failed'),1).'
    '. + &mt('File requested for deletion not found.')); + } else { + $filename =~ s/^scantron_orig_//; + if ($filename ne '') { + my ($is_valid,$numleft); + my %info = &Apache::lonnet::get('scantronupload',[$filename],$env{'form.domainid'},$env{'form.courseid'}); + if (keys(%info)) { + if (ref($info{$filename}) eq 'HASH') { + foreach my $timestamp (sort(keys(%{$info{$filename}}))) { + if ($info{$filename}{$timestamp} eq $env{'user.name'}.':'.$env{'user.domain'}) { + $is_valid = 1; + delete($info{$filename}{$timestamp}); + } + } + $numleft = scalar(keys(%{$info{$filename}})); + } + } + if ($is_valid) { + my $result = &Apache::lonnet::removeuploadedurl($uploadurl); + if ($result eq 'ok') { + $r->print(&Apache::lonhtmlcommon::confirm_success(&mt('File deletion successful')).'
    '); + if ($numleft) { + &Apache::lonnet::put('scantronupload',\%info,$env{'form.domainid'},$env{'form.courseid'}); + } else { + &Apache::lonnet::del('scantronupload',[$filename],$env{'form.domainid'},$env{'form.courseid'}); + } + } else { + $r->print(&Apache::lonhtmlcommon::confirm_success(&mt('File deletion failed'),1).'
    '. + &mt('Result was [_1]',$result)); + } + } else { + $r->print(&Apache::lonhtmlcommon::confirm_success(&mt('File deletion failed'),1).'
    '. + &mt('File requested for deletion was uploaded by a different user.')); + } + } else { + $r->print(&Apache::lonhtmlcommon::confirm_success(&mt('File deletion failed'),1).'
    '. + &mt('Filename of bubblesheet data file requested for deletion is invalid.')); + } + } + } else { + $r->print(&Apache::lonhtmlcommon::confirm_success(&mt('File deletion failed'),1).'
    '. + &mt('You are not permitted to delete bubblesheet data files from the requested course.')); + } + } else { + $r->print(&Apache::lonhtmlcommon::confirm_success(&mt('File deletion failed'),1).'
    '. + &mt('Filename of bubblesheet data file requested for deletion is invalid.')); + } + return; +} + sub valid_file { my ($requested_file)=@_; foreach my $filename (sort(&scantron_filenames())) { @@ -9378,6 +9788,29 @@ sub scantron_download_scantron_data { '); return; } + my (%uploader,$is_owner,%counts,$percent); + my %uploader = &Apache::lonnet::get('scantronupload',[$file],$cdom,$cname); + if (ref($uploader{$file}) eq 'HASH') { + foreach my $timestamp (sort { $a <=> $b } keys(%{$uploader{$file}})) { + if ($uploader{$file}{$timestamp} eq $env{'user.name'}.':'.$env{'user.domain'}) { + $is_owner = 1; + last; + } + } + } + unless ($is_owner) { + &validate_uploaded_scantron_file($cdom,$cname,$symb,'scantron_orig_'.$file,'download',\%counts); + if ($counts{'totalanysec'}) { + my $percent_othersec = (100*$counts{'othersec'})/($counts{'totalanysec'}); + if ($percent_othersec >= 10) { + my $showpct = sprintf("%.0f",$percent_othersec).'%'; + $r->print('

    '. + &mt('The original uploaded file includes [_1] or more of records for students for which none of your roles have rights to modify grades, so files are unavailable for download.',$showpct). + '

    '); + 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; @@ -9414,7 +9847,7 @@ sub checkscantron_results { my %scantron_config = &Apache::lonnet::get_scantron_config($env{'form.scantron_format'}); my $bubbles_per_row = &bubblesheet_bubbles_per_row(\%scantron_config); - my ($scanlines,$scan_data)=&Apache::grades::scantron_getfile(); + my ($scanlines,$scan_data)=&scantron_getfile(); my $classlist=&Apache::loncoursedata::get_classlist(); my %idmap=&Apache::grades::username_to_idmap($classlist); my $navmap=Apache::lonnavmaps::navmap->new(); @@ -10017,7 +10450,7 @@ sub reset_perm { sub init_perm { &reset_perm(); - foreach my $test_perm ('vgr','mgr','opa') { + foreach my $test_perm ('vgr','mgr','opa','usc') { my $scope = $env{'request.course.id'}; if (!($perm{$test_perm}=&Apache::lonnet::allowed($test_perm,$scope))) { @@ -10898,20 +11331,21 @@ sub handler { &startpage($request,$symb,[{href=>'', text=>'Grade/Manage/Review Bubblesheets'}],1,1); $request->print(&scantron_process_students($request,$symb)); } elsif ($command eq 'scantronupload' && - (&Apache::lonnet::allowed('usc',$env{'request.role.domain'})|| - &Apache::lonnet::allowed('usc',$env{'request.course.id'}))) { + (&Apache::lonnet::allowed('usc',$env{'request.role.domain'}) || $perm{'usc'})) { &startpage($request,$symb,[{href=>'', text=>'Grade/Manage/Review Bubblesheets'}],1,1, undef,undef,undef,undef,'toggleScantab(document.rules);'); $request->print(&scantron_upload_scantron_data($request,$symb)); } elsif ($command eq 'scantronupload_save' && - (&Apache::lonnet::allowed('usc',$env{'request.role.domain'})|| - &Apache::lonnet::allowed('usc',$env{'request.course.id'}))) { + (&Apache::lonnet::allowed('usc',$env{'request.role.domain'}) || $perm{'usc'})) { &startpage($request,$symb,[{href=>'', text=>'Grade/Manage/Review Bubblesheets'}],1,1); $request->print(&scantron_upload_scantron_data_save($request,$symb)); - } elsif ($command eq 'scantron_download' && - &Apache::lonnet::allowed('usc',$env{'request.course.id'})) { + } elsif ($command eq 'scantron_download' && ($perm{'usc'} || $perm{'mgr'})) { &startpage($request,$symb,[{href=>'', text=>'Grade/Manage/Review Bubblesheets'}],1,1); $request->print(&scantron_download_scantron_data($request,$symb)); + } elsif ($command eq 'scantronupload_delete' && + (&Apache::lonnet::allowed('usc',$env{'request.role.domain'}) || $perm{'usc'})) { + &startpage($request,$symb,[{href=>'', text=>'Grade/Manage/Review Bubblesheets'}],1,1); + &scantron_upload_delete($request,$symb); } elsif ($command eq 'checksubmissions' && $perm{'vgr'}) { &startpage($request,$symb,[{href=>'', text=>'Grade/Manage/Review Bubblesheets'}],1,1); $request->print(&checkscantron_results($request,$symb)); @@ -11171,7 +11605,12 @@ Side Effects: None. =item scantron_upload_scantron_data_save() : Adds a provided bubble information data file to the course if user - has the correct privileges to do so. + has the correct privileges to do so. + += item scantron_upload_delete() : + + Deletes a previously uploaded bubble information data file, if user + was the one who uploaded the file, and has the privileges to do so. =item valid_file() :