';
+ $$rowtotal ++;
+ return $datatable;
+}
+
+sub legacy_scantronformat {
+ my ($r,$dom,$confname,$file,$legacyfile,$newurl,$newfile) = @_;
+ my ($url,$error);
+ my @statinfo = &Apache::lonnet::stat_file($newurl);
+ if ((!@statinfo) || ($statinfo[0] eq 'no_such_dir')) {
+ (my $result,$url) =
+ &publishlogo($r,'copy',$legacyfile,$dom,$confname,'scantron',
+ '','',$newfile);
+ if ($result ne 'ok') {
+ $error = &mt("An error occurred publishing the [_1] scantron format file in RES space. Error was: [_2].",$newfile,$result);
+ }
+ }
+ return ($url,$error);
+}
sub modifiable_userdata_row {
my ($context,$role,$settings,$numinrow,$rowcount) = @_;
@@ -2128,16 +2261,8 @@ sub modify_colors {
foreach my $item (@bgs,@links,@logintext) {
$confhash->{$role}{$item} = $env{'form.'.$role.'_'.$item};
}
- my ($configuserok,$author_ok,$switchserver,%currroles);
- my $uhome = &Apache::lonnet::homeserver($confname,$dom,1);
- ($configuserok,%currroles) = &check_configuser($uhome,$dom,
- $confname,$servadm);
- if ($configuserok eq 'ok') {
- $switchserver = &check_switchserver($dom,$confname);
- if ($switchserver eq '') {
- $author_ok = &check_authorstatus($dom,$confname,%currroles);
- }
- }
+ my ($configuserok,$author_ok,$switchserver) =
+ &config_check($dom,$confname,$servadm);
my ($width,$height) = &thumb_dimensions();
if (ref($domconfig->{$role}) ne 'HASH') {
$domconfig->{$role} = {};
@@ -2169,11 +2294,11 @@ sub modify_colors {
$error = &mt("Upload of [_1] image for $role page(s) failed because an error occurred publishing the file in RES space. Error was: [_2].",$choices{img},$result);
}
} else {
- $error = &mt("Upload of [_1] image for $role page(s) failed because an author role could not be assigned to a Domain Configuation user ([_2]) in domain: [_3]. Error was: [_4].",$choices{$img},$confname,$dom,$author_ok);
+ $error = &mt("Upload of [_1] image for $role page(s) failed because an author role could not be assigned to a Domain Configuration user ([_2]) in domain: [_3]. Error was: [_4].",$choices{$img},$confname,$dom,$author_ok);
}
}
} else {
- $error = &mt("Upload of [_1] image for $role page(s) failed because a Domain Configuation user ([_2]) could not be created in domain: [_3]. Error was: [_4].",$choices{$img},$confname,$dom,$configuserok);
+ $error = &mt("Upload of [_1] image for $role page(s) failed because a Domain Configuration user ([_2]) could not be created in domain: [_3]. Error was: [_4].",$choices{$img},$confname,$dom,$configuserok);
}
if ($error) {
&Apache::lonnet::logthis($error);
@@ -2272,6 +2397,21 @@ sub modify_colors {
return ($errors,%changes);
}
+sub config_check {
+ my ($dom,$confname,$servadm) = @_;
+ my ($configuserok,$author_ok,$switchserver,%currroles);
+ my $uhome = &Apache::lonnet::homeserver($confname,$dom,1);
+ ($configuserok,%currroles) = &check_configuser($uhome,$dom,
+ $confname,$servadm);
+ if ($configuserok eq 'ok') {
+ $switchserver = &check_switchserver($dom,$confname);
+ if ($switchserver eq '') {
+ $author_ok = &check_authorstatus($dom,$confname,%currroles);
+ }
+ }
+ return ($configuserok,$author_ok,$switchserver);
+}
+
sub default_change_checker {
my ($role,$images,$links,$bgs,$logintext,$confhash,$changes) = @_;
foreach my $item (@{$links}) {
@@ -2411,7 +2551,7 @@ sub check_authorstatus {
}
sub publishlogo {
- my ($r,$action,$formname,$dom,$confname,$subdir,$thumbwidth,$thumbheight) = @_;
+ my ($r,$action,$formname,$dom,$confname,$subdir,$thumbwidth,$thumbheight,$savefileas) = @_;
my ($output,$fname,$logourl);
if ($action eq 'upload') {
$fname=$env{'form.'.$formname.'.filename'};
@@ -2419,6 +2559,9 @@ sub publishlogo {
} else {
($fname) = ($formname =~ /([^\/]+)$/);
}
+ if ($savefileas ne '') {
+ $fname = $savefileas;
+ }
$fname=&Apache::lonnet::clean_filename($fname);
# See if there is anything left
unless ($fname) { return ('error: no uploaded file'); }
@@ -2446,7 +2589,7 @@ sub publishlogo {
!defined(&Apache::loncommon::fileembstyle($1))) {
$output = &mt('Unrecognized file extension ([_1]) - rename the file with a proper extension and re-upload.',$1);
} elsif ($file=~/\.(\d+)\.(\w+)$/) {
- $output = &mt('File name not allowed a rename the file to remove the number immediately before the file extension([_1]) and re-upload.',$2);
+ $output = &mt('File name not allowed - rename the file to remove the number immediately before the file extension([_1]) and re-upload.',$2);
} elsif (-d "$filepath/$file") {
$output = &mt('File name is a directory name - rename the file and re-upload');
} else {
@@ -3608,5 +3751,85 @@ sub modify_defaults {
}
return $resulttext;
}
+
+sub modify_scantron {
+ my ($r,$dom,$confname,$domconfig) = @_;
+ my ($resulttext,%confhash,%changes,$errors);
+ my $custom = 'custom.tab';
+ my $default = 'default.tab';
+ my $servadm = $r->dir_config('lonAdmEMail');
+ my ($configuserok,$author_ok,$switchserver) =
+ &config_check($dom,$confname,$servadm);
+ if ($env{'form.scantronformat.filename'} ne '') {
+ my $error;
+ if ($configuserok eq 'ok') {
+ if ($switchserver) {
+ $error = &mt("Upload of scantron format file is not permitted to this server: [_1]",$switchserver);
+ } else {
+ if ($author_ok eq 'ok') {
+ my ($result,$scantronurl) =
+ &publishlogo($r,'upload','scantronformat',$dom,
+ $confname,'scantron','','',$custom);
+ if ($result eq 'ok') {
+ $confhash{'scantron'}{'scantronformat'} = $scantronurl;
+ $changes{'scantron'}{'scantronformat'} = 1;
+ } else {
+ $error = &mt("Upload of [_1] failed because an error occurred publishing the file in RES space. Error was: [_2].",$custom,$result);
+ }
+ } else {
+ $error = &mt("Upload of [_1] failed because an author role could not be assigned to a Domain Configuration user ([_2]) in domain: [_3]. Error was: [_4].",$custom,$confname,$dom,$author_ok);
+ }
+ }
+ } else {
+ $error = &mt("Upload of [_1] failed because a Domain Configuration user ([_2]) could not be created in domain: [_3]. Error was: [_4].",$custom,$confname,$dom,$configuserok);
+ }
+ if ($error) {
+ &Apache::lonnet::logthis($error);
+ $errors .= '
'.$error.'
';
+ }
+ }
+ if (ref($domconfig) eq 'HASH') {
+ if (ref($domconfig->{'scantron'}) eq 'HASH') {
+ if ($domconfig->{'scantron'}{'scantronformat'} ne '') {
+ if ($env{'form.scantronformat_del'}) {
+ $confhash{'scantron'}{'scantronformat'} = '';
+ $changes{'scantron'}{'scantronformat'} = 1;
+ }
+ }
+ }
+ }
+ if (keys(%confhash) > 0) {
+ my $putresult = &Apache::lonnet::put_dom('configuration',\%confhash,
+ $dom);
+ if ($putresult eq 'ok') {
+ if (keys(%changes) > 0) {
+ $resulttext = &mt('Changes made:').'
';
+ if (ref($changes{'scantron'}) eq 'HASH') {
+ if ($changes{'scantron'}{'scantronformat'}) {
+ if ($confhash{'scantron'}{'scantronformat'} eq '') {
+ $resulttext .= '
'.&mt('[_1] scantron format file removed; [_2] file will be used for courses in this domain.',$custom,$default).'
';
+ } else {
+ $resulttext .= '
'.&mt('Custom scantron format file ([_1]) uploaded for use with courses in this domain.',$custom).'
';
+ }
+ }
+ }
+ $resulttext .= '
';
+ &Apache::loncommon::devalidate_domconfig_cache($dom);
+ } else {
+ $resulttext = &mt('No changes made to scantron format file');
+ }
+ } else {
+ $resulttext = ''.
+ &mt('An error occurred: [_1]',$putresult).'';
+ }
+ } else {
+ $resulttext = &mt('No changes made to scantron format file');
+ }
+ if ($errors) {
+ $resulttext .= &mt('The following errors occurred: ').'