--- loncom/interface/domainprefs.pm 2019/01/27 14:39:48 1.346 +++ loncom/interface/domainprefs.pm 2019/01/28 21:36:45 1.347 @@ -1,7 +1,7 @@ # The LearningOnline Network with CAPA # Handler to set domain-wide configuration settings # -# $Id: domainprefs.pm,v 1.346 2019/01/27 14:39:48 raeburn Exp $ +# $Id: domainprefs.pm,v 1.347 2019/01/28 21:36:45 raeburn Exp $ # # Copyright Michigan State University Board of Trustees # @@ -7996,14 +7996,24 @@ sub scantron_javascript { // ' checked="checked"', + pad => ' checked="checked"', + rem => ' checked="checked"', + ); + my %optionsoff = ( + hdr => '', + pad => '', + rem => '', + ); my $currcsvsty = 'none'; - my ($datatable,%csvfields,%checked,%onclick); + my ($datatable,%csvfields,%checked,%onclick,%csvoptions); my @fields = &scantroncsv_fields(); my %titles = &scantronconfig_titles(); if (ref($settings) eq 'HASH') { @@ -8209,10 +8229,21 @@ sub print_scantronconfig { $checked{'dat'} = $is_checked; } if (ref($settings->{config}->{csv}) eq 'HASH') { - %csvfields = %{$settings->{config}->{csv}}; - if (keys(%csvfields) > 0) { - $checked{'csv'} = $is_checked; - $currcsvsty = 'inline-block'; + if (ref($settings->{config}->{csv}->{fields}) eq 'HASH') { + %csvfields = %{$settings->{config}->{csv}->{fields}}; + if (keys(%csvfields) > 0) { + $checked{'csv'} = $is_checked; + $currcsvsty = 'block'; + } + } + if (ref($settings->{config}->{csv}->{options}) eq 'HASH') { + %csvoptions = %{$settings->{config}->{csv}->{options}}; + foreach my $option (keys(%optionson)) { + unless ($csvoptions{$option}) { + $optionsoff{$option} = $optionson{$option}; + $optionson{$option} = ''; + } + } } } } else { @@ -8229,7 +8260,7 @@ sub print_scantronconfig { my $id; if ($item eq 'csv') { $id = 'id="scantronconfcsv" '; - } + } $datatable .= ''.(' 'x3); if ($item eq 'csv') { @@ -8258,7 +8289,16 @@ sub print_scantronconfig { } $datatable .= ''; } - $datatable .= ''; + $datatable .= ''. + '
'; $itemcount ++; } } @@ -8271,6 +8311,9 @@ sub scantronconfig_titles { return &Apache::lonlocal::texthash( dat => 'Standard format (.dat)', csv => 'Comma separated values (.csv)', + hdr => 'Remove first line in file (contains column titles)', + pad => 'Prepend 0s to PaperID', + rem => 'Remove leading spaces (except Q columns)', CODE => 'CODE', ID => 'Student ID', PaperID => 'Paper ID', @@ -15137,18 +15180,20 @@ sub modify_scantron { if ($env{'form.scantronformat_del'}) { $confhash{'scantron'}{'scantronformat'} = ''; $changes{'scantronformat'} = 1; + } else { + $confhash{'scantron'}{'scantronformat'} = $domconfig{'scantron'}{'scantronformat'}; } } } + my @options = ('hdr','pad','rem'); my @fields = &scantroncsv_fields(); my %titles = &scantronconfig_titles(); - my @formats = &Apache::loncommon::get_env_multiple('form.scantronformat'); + my @formats = &Apache::loncommon::get_env_multiple('form.scantronconfig'); my ($newdat,$currdat,%newcol,%currcol); if (grep(/^dat$/,@formats)) { $confhash{'scantron'}{config}{dat} = 1; $newdat = 1; } else { - $confhash{'scantron'}{config}{dat} = 0; $newdat = 0; } if (grep(/^csv$/,@formats)) { @@ -15157,21 +15202,30 @@ sub modify_scantron { if ($env{'form.scantronconfig_csv_'.$field} =~ /^(\d+)$/) { my $posscol = $1; if (($posscol < 20) && (!$bynum{$posscol})) { - $confhash{'scantron'}{config}{csv}{$field} = $posscol; + $confhash{'scantron'}{config}{csv}{fields}{$field} = $posscol; $bynum{$posscol} = $field; $newcol{$field} = $posscol; } } } + if (keys(%newcol)) { + foreach my $option (@options) { + if ($env{'form.scantroncsv_'.$option}) { + $confhash{'scantron'}{config}{csv}{options}{$option} = 1; + } + } + } } $currdat = 1; if (ref($domconfig{'scantron'}) eq 'HASH') { if (ref($domconfig{'scantron'}{'config'}) eq 'HASH') { - if (!$domconfig{'scantron'}{'config'}{'dat'}) { + unless (exists($domconfig{'scantron'}{'config'}{'dat'})) { $currdat = 0; } if (ref($domconfig{'scantron'}{'config'}{'csv'}) eq 'HASH') { - %currcol = %{$domconfig{'scantron'}{'config'}{'csv'}}; + if (ref($domconfig{'scantron'}{'config'}{'csv'}{'fields'}) eq 'HASH') { + %currcol = %{$domconfig{'scantron'}{'config'}{'csv'}{'fields'}}; + } } } } @@ -15183,7 +15237,7 @@ sub modify_scantron { if ($currcol{$field} ne $newcol{$field}) { $changes{'config'} = 1; last; - } + } } elsif ($newcol{$field} ne '') { $changes{'config'} = 1; last; @@ -15204,21 +15258,34 @@ sub modify_scantron { $resulttext .= '