--- loncom/interface/domainprefs.pm 2017/11/16 23:33:05 1.160.6.84.2.9
+++ loncom/interface/domainprefs.pm 2019/02/03 20:43:00 1.160.6.84.2.10
@@ -1,7 +1,7 @@
# The LearningOnline Network with CAPA
# Handler to set domain-wide configuration settings
#
-# $Id: domainprefs.pm,v 1.160.6.84.2.9 2017/11/16 23:33:05 raeburn Exp $
+# $Id: domainprefs.pm,v 1.160.6.84.2.10 2019/02/03 20:43:00 raeburn Exp $
#
# Copyright Michigan State University Board of Trustees
#
@@ -377,11 +377,12 @@ sub handler {
modify => \&modify_usermodification,
},
'scantron' =>
- { text => 'Bubblesheet format file',
+ { text => 'Bubblesheet format',
help => 'Domain_Configuration_Scantron_Format',
- header => [ {col1 => 'Item',
- col2 => '',
- }],
+ header => [ {col1 => 'Bubblesheet format file',
+ col2 => ''},
+ {col1 => 'Bubblesheet data upload formats',
+ col2 => 'Settings'}],
print => \&print_scantron,
modify => \&modify_scantron,
},
@@ -553,6 +554,9 @@ END
if (grep(/^contacts$/,@actions)) {
$js .= &contacts_javascript();
}
+ if (grep(/^scantron$/,@actions)) {
+ $js .= &scantron_javascript();
+ }
&Apache::lonconfigsettings::display_settings($r,$dom,$phase,$context,\@prefs_order,\%prefs,\%domconfig,$confname,$js);
} else {
# check if domconfig user exists for the domain.
@@ -743,6 +747,8 @@ sub print_config_box {
$output .= $item->{'print'}->('top',$dom,$settings,\$rowtotal);
} elsif ($action eq 'coursecategories') {
$output .= $item->{'print'}->('top',$dom,$item,$settings,\$rowtotal);
+ } elsif ($action eq 'scantron') {
+ $output .= $item->{'print'}->($r,'top',$dom,$confname,$settings,\$rowtotal);
} elsif ($action eq 'login') {
if ($numheaders == 4) {
$colspan = ' colspan="2"';
@@ -798,6 +804,8 @@ sub print_config_box {
($action eq 'defaults') || ($action eq 'directorysrch') ||
($action eq 'helpsettings')) {
$output .= $item->{'print'}->('bottom',$dom,$settings,\$rowtotal);
+ } elsif ($action eq 'scantron') {
+ $output .= $item->{'print'}->($r,'bottom',$dom,$confname,$settings,\$rowtotal);
} elsif ($action eq 'login') {
if ($numheaders == 4) {
$output .= &print_login('page',$dom,$confname,$phase,$settings,\$rowtotal).'
@@ -957,8 +965,6 @@ sub print_config_box {
($action eq 'serverstatuses') || ($action eq 'loadbalancing') ||
($action eq 'ltitools')) {
$output .= $item->{'print'}->($dom,$settings,\$rowtotal);
- } elsif ($action eq 'scantron') {
- $output .= &print_scantronformat($r,$dom,$confname,$settings,\$rowtotal);
}
}
$output .= '
@@ -6292,6 +6298,58 @@ sub defaults_titles {
return (\%titles);
}
+sub print_scantron {
+ my ($r,$position,$dom,$confname,$settings,$rowtotal) = @_;
+ if ($position eq 'top') {
+ return &print_scantronformat($r,$dom,$confname,$settings,\$rowtotal);
+ } else {
+ return &print_scantronconfig($dom,$settings,\$rowtotal);
+ }
+}
+
+sub scantron_javascript {
+ return <<"ENDSCRIPT";
+
+
+
+ENDSCRIPT
+
+}
+
sub print_scantronformat {
my ($r,$dom,$confname,$settings,$rowtotal) = @_;
my $itemcount = 1;
@@ -6318,8 +6376,8 @@ sub print_scantronformat {
if ($configuserok eq 'ok') {
if ($author_ok eq 'ok') {
my %legacyfile = (
- default => $Apache::lonnet::perlvar{'lonTabDir'}.'/default_scantronformat.tab',
- custom => $Apache::lonnet::perlvar{'lonTabDir'}.'/scantronformat.tab',
+ default => $Apache::lonnet::perlvar{'lonTabDir'}.'/default_scantronformat.tab',
+ custom => $Apache::lonnet::perlvar{'lonTabDir'}.'/scantronformat.tab',
);
my %md5chk;
foreach my $type (keys(%legacyfile)) {
@@ -6328,7 +6386,7 @@ sub print_scantronformat {
}
if ($md5chk{'default'} ne $md5chk{'custom'}) {
foreach my $type (keys(%legacyfile)) {
- ($scantronurls{$type},my $error) =
+ ($scantronurls{$type},my $error) =
&legacy_scantronformat($r,$dom,$confname,
$type,$legacyfile{$type},
$scantronurls{$type},
@@ -6339,13 +6397,13 @@ sub print_scantronformat {
}
if (keys(%error) == 0) {
$is_custom = 1;
- $confhash{'scantron'}{'scantronformat'} =
+ $confhash{'scantron'}{'scantronformat'} =
$scantronurls{'custom'};
- my $putresult =
+ my $putresult =
&Apache::lonnet::put_dom('configuration',
\%confhash,$dom);
if ($putresult ne 'ok') {
- $error{'custom'} =
+ $error{'custom'} =
''.
&mt('An error occurred updating the domain configuration: [_1]',$putresult).'';
}
@@ -6465,6 +6523,129 @@ sub legacy_scantronformat {
return ($url,$error);
}
+sub print_scantronconfig {
+ my ($dom,$settings,$rowtotal) = @_;
+ my $itemcount = 2;
+ my $is_checked = ' checked="checked"';
+ my %optionson = (
+ hdr => ' checked="checked"',
+ pad => ' checked="checked"',
+ rem => ' checked="checked"',
+ );
+ my %optionsoff = (
+ hdr => '',
+ pad => '',
+ rem => '',
+ );
+ my $currcsvsty = 'none';
+ my ($datatable,%csvfields,%checked,%onclick,%csvoptions);
+ my @fields = &scantroncsv_fields();
+ my %titles = &scantronconfig_titles();
+ if (ref($settings) eq 'HASH') {
+ if (ref($settings->{config}) eq 'HASH') {
+ if ($settings->{config}->{dat}) {
+ $checked{'dat'} = $is_checked;
+ }
+ if (ref($settings->{config}->{csv}) eq 'HASH') {
+ 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 {
+ $checked{'dat'} = $is_checked;
+ }
+ } else {
+ $checked{'dat'} = $is_checked;
+ }
+ $onclick{'csv'} = ' onclick="toggleScantron(this.form);"';
+ my $css_class = $itemcount%2? ' class="LC_odd_row"':'';
+ $datatable = '
'.&mt('Supported formats').' | '.
+ '';
+ foreach my $item ('dat','csv') {
+ my $id;
+ if ($item eq 'csv') {
+ $id = 'id="scantronconfcsv" ';
+ }
+ $datatable .= ''.(' 'x3);
+ if ($item eq 'csv') {
+ $datatable .= ''.
+ '';
+ $itemcount ++;
+ }
+ }
+ $datatable .= ' |
';
+ $$rowtotal ++;
+ return $datatable;
+}
+
+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 Question Response columns)',
+ CODE => 'CODE',
+ ID => 'Student ID',
+ PaperID => 'Paper ID',
+ FirstName => 'First Name',
+ LastName => 'Last Name',
+ FirstQuestion => 'First Question Response',
+ Section => 'Section',
+ );
+}
+
+sub scantroncsv_fields {
+ return ('PaperID','LastName','FirstName','ID','Section','CODE','FirstQuestion');
+}
+
sub print_coursecategories {
my ($position,$dom,$hdritem,$settings,$rowtotal) = @_;
my $datatable;
@@ -8828,15 +9009,17 @@ sub modify_quotas {
if ($type eq 'textbooks') {
if ($env{'form.'.$type.'_addbook_image.filename'} ne '') {
my ($cdom,$cnum) = split(/_/,$newbook{$type});
- my ($imageurl,$error) =
- &process_textbook_image($r,$dom,$confname,$type.'_addbook_image',$cdom,$cnum,$type,
- $configuserok,$switchserver,$author_ok);
- if ($imageurl) {
- $confhash{$type}{$newbook{$type}}{'image'} = $imageurl;
- }
- if ($error) {
- &Apache::lonnet::logthis($error);
- $errors .= ''.$error.'';
+ if (&Apache::lonnet::homeserver($cnum,$cdom) eq 'no_host') {
+ my ($imageurl,$error) =
+ &process_textbook_image($r,$dom,$confname,$type.'_addbook_image',$cdom,$cnum,$type,
+ $configuserok,$switchserver,$author_ok);
+ if ($imageurl) {
+ $confhash{$type}{$newbook{$type}}{'image'} = $imageurl;
+ }
+ if ($error) {
+ &Apache::lonnet::logthis($error);
+ $errors .= ''.$error.'';
+ }
}
}
}
@@ -12221,7 +12404,7 @@ sub modify_scantron {
my $custom = 'custom.tab';
my $default = 'default.tab';
my $servadm = $r->dir_config('lonAdmEMail');
- my ($configuserok,$author_ok,$switchserver) =
+ my ($configuserok,$author_ok,$switchserver) =
&config_check($dom,$confname,$servadm);
if ($env{'form.scantronformat.filename'} ne '') {
my $error;
@@ -12256,6 +12439,67 @@ 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.scantronconfig');
+ my ($newdat,$currdat,%newcol,%currcol);
+ if (grep(/^dat$/,@formats)) {
+ $confhash{'scantron'}{config}{dat} = 1;
+ $newdat = 1;
+ } else {
+ $newdat = 0;
+ }
+ if (grep(/^csv$/,@formats)) {
+ my %bynum;
+ foreach my $field (@fields) {
+ if ($env{'form.scantronconfig_csv_'.$field} =~ /^(\d+)$/) {
+ my $posscol = $1;
+ if (($posscol < 20) && (!$bynum{$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') {
+ unless (exists($domconfig{'scantron'}{'config'}{'dat'})) {
+ $currdat = 0;
+ }
+ if (ref($domconfig{'scantron'}{'config'}{'csv'}) eq 'HASH') {
+ if (ref($domconfig{'scantron'}{'config'}{'csv'}{'fields'}) eq 'HASH') {
+ %currcol = %{$domconfig{'scantron'}{'config'}{'csv'}{'fields'}};
+ }
+ }
+ }
+ }
+ if ($currdat != $newdat) {
+ $changes{'config'} = 1;
+ } else {
+ foreach my $field (@fields) {
+ if ($currcol{$field} ne '') {
+ if ($currcol{$field} ne $newcol{$field}) {
+ $changes{'config'} = 1;
+ last;
+ }
+ } elsif ($newcol{$field} ne '') {
+ $changes{'config'} = 1;
+ last;
}
}
}
@@ -12266,29 +12510,64 @@ sub modify_scantron {
if (keys(%changes) > 0) {
if (ref($confhash{'scantron'}) eq 'HASH') {
$resulttext = &mt('Changes made:').'';
- if ($confhash{'scantron'}{'scantronformat'} eq '') {
- $resulttext .= '- '.&mt('[_1] bubblesheet format file removed; [_2] file will be used for courses in this domain.',$custom,$default).'
';
- } else {
- $resulttext .= '- '.&mt('Custom bubblesheet format file ([_1]) uploaded for use with courses in this domain.',$custom).'
';
+ if ($changes{'scantronformat'}) {
+ if ($confhash{'scantron'}{'scantronformat'} eq '') {
+ $resulttext .= '- '.&mt('[_1] bubblesheet format file removed; [_2] file will be used for courses in this domain.',$custom,$default).'
';
+ } else {
+ $resulttext .= '- '.&mt('Custom bubblesheet format file ([_1]) uploaded for use with courses in this domain.',$custom).'
';
+ }
+ }
+ if ($changes{'config'}) {
+ if (ref($confhash{'scantron'}{'config'}) eq 'HASH') {
+ if ($confhash{'scantron'}{'config'}{'dat'}) {
+ $resulttext .= '- '.&mt('Bubblesheet data upload formats includes .dat format').'
';
+ }
+ if (ref($confhash{'scantron'}{'config'}{'csv'}) eq 'HASH') {
+ if (ref($confhash{'scantron'}{'config'}{'csv'}{'fields'}) eq 'HASH') {
+ if (keys(%{$confhash{'scantron'}{'config'}{'csv'}{'fields'}})) {
+ $resulttext .= '- '.&mt('Bubblesheet data upload formats includes .csv format, with following fields/column numbers supported:').'
';
+ foreach my $field (@fields) {
+ if ($confhash{'scantron'}{'config'}{'csv'}{'fields'}{$field} ne '') {
+ my $showcol = $confhash{'scantron'}{'config'}{'csv'}{'fields'}{$field} + 1;
+ $resulttext .= '- '.$titles{$field}.': '.$showcol.'
';
+ }
+ }
+ $resulttext .= '
';
+ if (ref($confhash{'scantron'}{'config'}{'csv'}{'options'}) eq 'HASH') {
+ if (keys(%{$confhash{'scantron'}{'config'}{'csv'}{'options'}})) {
+ $resulttext .= '- '.&mt('Bubblesheet data upload formats includes .csv format, with following options:').'
';
+ foreach my $option (@options) {
+ if ($confhash{'scantron'}{'config'}{'csv'}{'options'}{$option} ne '') {
+ $resulttext .= '- '.$titles{$option}.'
';
+ }
+ }
+ $resulttext .= '
';
+ }
+ }
+ }
+ }
+ }
+ } else {
+ $resulttext .= '- '.&mt('No bubblesheet data upload formats set -- will default to assuming .dat format').'
';
+ }
}
$resulttext .= '
';
} else {
$resulttext = &mt('Changes made to bubblesheet format file.');
}
- $resulttext .= '';
&Apache::loncommon::devalidate_domconfig_cache($dom);
if (ref($lastactref) eq 'HASH') {
$lastactref->{'domainconfig'} = 1;
}
} else {
- $resulttext = &mt('No changes made to bubblesheet format file');
+ $resulttext = &mt('No changes made to bubblesheet format settings');
}
} else {
$resulttext = ''.
&mt('An error occurred: [_1]',$putresult).'';
}
} else {
- $resulttext = &mt('No changes made to bubblesheet format file');
+ $resulttext = &mt('No changes made to bubblesheet format settings');
}
if ($errors) {
$resulttext .= &mt('The following errors occurred: ').'