';
} else {
my $newitem = $confhash->{$role}{$item};
@@ -3217,71 +3305,191 @@ sub check_switchserver {
return $switchserver;
}
-sub javascript_set_colnums {
- return < 1100) {
- document.pickactions.numcols[1].checked = true;
+sub modify_quotas {
+ my ($dom,$action,%domconfig) = @_;
+ my ($context,@usertools);
+ if ($action eq 'quotas') {
+ $context = 'tools';
+ } else {
+ $context = $action;
+ }
+ if ($context eq 'requestcourses') {
+ @usertools = ('official','unofficial');
} else {
- document.pickactions.numcols[0].checked = true;
+ @usertools = ('aboutme','blog','portfolio');
}
-}
-END
-}
-
-sub modify_quotas {
- my ($dom,%domconfig) = @_;
+ my %domdefaults = &Apache::lonnet::get_domain_defaults($dom);
my ($resulttext,%changes);
my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
- my %formhash;
+ my %titles = &tool_titles();
+ my (%confhash,%toolshash);
foreach my $key (keys(%env)) {
- if ($key =~ /^form\.quota_(.+)$/) {
- $formhash{$1} = $env{$key};
+ unless ($context eq 'requestcourses') {
+ if ($key =~ /^form\.quota_(.+)$/) {
+ $confhash{'defaultquota'}{$1} = $env{$key};
+ }
+ }
+ if ($key =~ /^form\.\Q$context\E_(.+)$/) {
+ @{$toolshash{$1}} = &Apache::loncommon::get_env_multiple($key);
}
}
- $formhash{'default'} = $env{'form.defaultquota'};
- if (ref($domconfig{'quotas'}) eq 'HASH') {
- foreach my $key (keys(%{$domconfig{'quotas'}})) {
- if (exists($formhash{$key})) {
- if ($formhash{$key} ne $domconfig{'quotas'}{$key}) {
- $changes{$key} = 1;
+ unless ($context eq 'requestcourses') {
+ $confhash{'defaultquota'}{'default'} = $env{'form.defaultquota'};
+ }
+ foreach my $item (@usertools) {
+ foreach my $type (@{$types},'default','_LC_adv') {
+ if (grep(/^\Q$type\E$/,@{$toolshash{$item}})) {
+ $confhash{$item}{$type} = 1;
+ } else {
+ $confhash{$item}{$type} = 0;
+ }
+ if (ref($domconfig{$action}) eq 'HASH') {
+ if (ref($domconfig{$action}{$item}) eq 'HASH') {
+ if ($domconfig{$action}{$item}{$type} ne $confhash{$item}{$type}) {
+ $changes{$item}{$type} = 1;
+ }
+ } else {
+ if ($context eq 'requestcourses') {
+ if ($confhash{$item}{$type}) {
+ $changes{$item}{$type} = 1;
+ }
+ } else {
+ if (!$confhash{$item}{$type}) {
+ $changes{$item}{$type} = 1;
+ }
+ }
}
} else {
- $formhash{$key} = $domconfig{'quotas'}{$key};
+ if ($context eq 'requestcourses') {
+ if ($confhash{$item}{$type}) {
+ $changes{$item}{$type} = 1;
+ }
+ } else {
+ if (!$confhash{$item}{$type}) {
+ $changes{$item}{$type} = 1;
+ }
+ }
}
}
}
- foreach my $key (keys(%formhash)) {
- if ($formhash{$key} ne '') {
- if (ref($domconfig{'quotas'}) eq 'HASH') {
- if (!exists($domconfig{'quotas'}{$key})) {
- $changes{$key} = 1;
+ unless ($context eq 'requestcourses') {
+ if (ref($domconfig{'quotas'}) eq 'HASH') {
+ if (ref($domconfig{'quotas'}{'defaultquota'}) eq 'HASH') {
+ foreach my $key (keys(%{$domconfig{'quotas'}{'defaultquota'}})) {
+ if (exists($confhash{'defaultquota'}{$key})) {
+ if ($confhash{'defaultquota'}{$key} ne $domconfig{'quotas'}{'defaultquota'}{$key}) {
+ $changes{'defaultquota'}{$key} = 1;
+ }
+ } else {
+ $confhash{'defaultquota'}{$key} = $domconfig{'quotas'}{'defaultquota'}{$key};
+ }
}
} else {
- $changes{$key} = 1;
+ foreach my $key (keys(%{$domconfig{'quotas'}})) {
+ if (exists($confhash{'defaultquota'}{$key})) {
+ if ($confhash{'defaultquota'}{$key} ne $domconfig{'quotas'}{$key}) {
+ $changes{'defaultquota'}{$key} = 1;
+ }
+ } else {
+ $confhash{'defaultquota'}{$key} = $domconfig{'quotas'}{$key};
+ }
+ }
}
}
+ if (ref($confhash{'defaultquota'}) eq 'HASH') {
+ foreach my $key (keys(%{$confhash{'defaultquota'}})) {
+ if (ref($domconfig{'quotas'}) eq 'HASH') {
+ if (ref($domconfig{'quotas'}{'defaultquota'}) eq 'HASH') {
+ if (!exists($domconfig{'quotas'}{'defaultquota'}{$key})) {
+ $changes{'defaultquota'}{$key} = 1;
+ }
+ } else {
+ if (!exists($domconfig{'quotas'}{$key})) {
+ $changes{'defaultquota'}{$key} = 1;
+ }
+ }
+ } else {
+ $changes{'defaultquota'}{$key} = 1;
+ }
+ }
+ }
+ }
+
+ foreach my $key (keys(%confhash)) {
+ $domdefaults{$key} = $confhash{$key};
}
+
my %quotahash = (
- quotas => {%formhash},
+ $action => { %confhash }
);
my $putresult = &Apache::lonnet::put_dom('configuration',\%quotahash,
$dom);
if ($putresult eq 'ok') {
if (keys(%changes) > 0) {
+ my $cachetime = 24*60*60;
+ &Apache::lonnet::do_cache_new('domdefaults',$dom,\%domdefaults,$cachetime);
+
$resulttext = &mt('Changes made:').'
';
- foreach my $type (@{$types},'default') {
- if (defined($changes{$type})) {
- my $typetitle = $usertypes->{$type};
- if ($type eq 'default') {
- $typetitle = $othertitle;
+ unless ($context eq 'requestcourses') {
+ if (ref($changes{'defaultquota'}) eq 'HASH') {
+ $resulttext .= '
'.&mt('Portfolio default quotas').'
';
+ foreach my $type (@{$types},'default') {
+ if (defined($changes{'defaultquota'}{$type})) {
+ my $typetitle = $usertypes->{$type};
+ if ($type eq 'default') {
+ $typetitle = $othertitle;
+ }
+ $resulttext .= '
'.&mt('[_1] set to [_2] Mb',$typetitle,$confhash{'defaultquota'}{$type}).'
';
+ }
+ }
+ $resulttext .= '
';
+ }
+ }
+ my %newenv;
+ foreach my $item (@usertools) {
+ if (ref($changes{$item}) eq 'HASH') {
+ my $newacc =
+ &Apache::lonnet::usertools_access($env{'user.name'},
+ $env{'user.domain'},
+ $item,'reload',$context);
+ if ($context eq 'requestcourses') {
+ if ($env{'environment.canrequest.'.$item} ne $newacc) {
+ $newenv{'environment.canrequest.'.$item} = $newacc;
+ }
+ } else {
+ if ($env{'environment.availabletools.'.$item} ne $newacc) {
+ $newenv{'environment.availabletools.'.$item} = $newacc;
+ }
}
- $resulttext .= '
'.&mt('[_1] set to [_2] Mb',$typetitle,$formhash{$type}).'
';
+ $resulttext .= '
'.$titles{$item}.'
';
+ foreach my $type (@{$types},'default','_LC_adv') {
+ if ($changes{$item}{$type}) {
+ my $typetitle = $usertypes->{$type};
+ if ($type eq 'default') {
+ $typetitle = $othertitle;
+ } elsif ($type eq '_LC_adv') {
+ $typetitle = 'LON-CAPA Advanced Users';
+ }
+ if ($confhash{$item}{$type}) {
+ $resulttext .= '
'.&mt('Set to be available to [_1]',$typetitle).'
';
+ } else {
+ $resulttext .= '
'.&mt('Set to be unavailable to [_1]',$typetitle).'
';
+ }
+ }
+ }
+ $resulttext .= '
';
}
}
$resulttext .= '
';
+ if (keys(%newenv)) {
+ &Apache::lonnet::appenv(\%newenv);
+ }
} else {
- $resulttext = &mt('No changes made to default quotas');
+ if ($context eq 'requestcourses') {
+ $resulttext = &mt('No changes made to rights to request creation of courses.');
+ } else {
+ $resulttext = &mt('No changes made to availability of personal information pages, blogs, portfolios or default quotas');
+ }
}
} else {
$resulttext = ''.
@@ -3664,7 +3872,7 @@ sub modify_contacts {
}
my (%others,%to);
my @contacts = ('supportemail','adminemail');
- my @mailings = ('errormail','packagesmail','helpdeskmail');
+ my @mailings = ('errormail','packagesmail','helpdeskmail','lonstatusmail');
foreach my $type (@mailings) {
@{$newsetting{$type}} =
&Apache::loncommon::get_env_multiple('form.'.$type);
@@ -3709,6 +3917,7 @@ sub modify_contacts {
$default{'errormail'} = 'adminemail';
$default{'packagesmail'} = 'adminemail';
$default{'helpdeskmail'} = 'supportemail';
+ $default{'lonstatusmail'} = 'adminemail';
foreach my $item (@contacts) {
if ($to{$item} ne $default{$item}) {
$changes{$item} = 1;
@@ -3791,10 +4000,19 @@ sub modify_usercreation {
$cancreate{$item} = $env{'form.can_createuser_'.$item};
}
}
+ my ($othertitle,$usertypes,$types) =
+ &Apache::loncommon::sorted_inst_types($dom);
+ if (ref($types) eq 'ARRAY') {
+ if (@{$types} > 0) {
+ @{$cancreate{'statustocreate'}} =
+ &Apache::loncommon::get_env_multiple('form.statustocreate');
+ }
+ push(@contexts,'statustocreate');
+ }
if (ref($curr_usercreation{'cancreate'}) eq 'HASH') {
foreach my $item (@contexts) {
- if ($item eq 'selfcreate') {
- if (ref($curr_usercreation{'cancreate'}{$item}) eq 'ARRAY') {
+ if (($item eq 'selfcreate') || ($item eq 'statustocreate')) {
+ if (ref($curr_usercreation{'cancreate'}{$item}) eq 'ARRAY') {
foreach my $curr (@{$curr_usercreation{'cancreate'}{$item}}) {
if (!grep(/^$curr$/,@{$cancreate{$item}})) {
if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
@@ -3981,6 +4199,26 @@ sub modify_usercreation {
}
$chgtext .= '
';
}
+ } elsif ($type eq 'statustocreate') {
+ if (@{$cancreate{'selfcreate'}} > 0) {
+ if (@{$cancreate{$type}} == 0) {
+ if (!grep(/^email$/,@{$cancreate{'selfcreate'}})) {
+ $chgtext .= &mt("However, no institutional affiliations (including 'other') are currently permitted to create accounts.");
+ }
+ } elsif (ref($usertypes) eq 'HASH') {
+ if (grep(/^(login|sso)$/,@{$cancreate{'selfcreate'}})) {
+ $chgtext .= &mt('creation of a new account for an institutional user is restricted to the following institutional affiliation(s):').'
';
+ foreach my $case (@{$cancreate{$type}}) {
+ if ($case eq 'default') {
+ $chgtext .= '
'.$othertitle.'
';
+ } else {
+ $chgtext .= '
'.$usertypes->{$case}.'
';
+ }
+ }
+ $chgtext .= '
';
+ }
+ }
+ }
} else {
if ($cancreate{$type} eq 'none') {
$chgtext .= &mt('creation of new users is not permitted, except by a Domain Coordinator.');
@@ -4088,10 +4326,11 @@ sub modify_usermodification {
$curr_usermodification{$key} = $domconfig{'usermodification'}{$key};
}
}
- my @contexts = ('author','course');
+ my @contexts = ('author','course','selfcreate');
my %context_title = (
author => 'In author context',
course => 'In course context',
+ selfcreate => 'When self creating account',
);
my @fields = ('lastname','firstname','middlename','generation',
'permanentemail','id');
@@ -4099,6 +4338,12 @@ sub modify_usermodification {
author => ['ca','aa'],
course => ['st','ep','ta','in','cr'],
);
+ my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
+ if (ref($types) eq 'ARRAY') {
+ push(@{$types},'default');
+ $usertypes->{'default'} = $othertitle;
+ }
+ $roles{'selfcreate'} = $types;
my %fieldtitles = &Apache::loncommon::personal_data_fieldtitles();
my %modifyhash;
foreach my $context (@contexts) {
@@ -4146,13 +4391,26 @@ sub modify_usermodification {
if (ref($changes{$context}) eq 'ARRAY') {
foreach my $role (@{$changes{$context}}) {
my $rolename;
- if ($role eq 'cr') {
- $rolename = &mt('Custom');
+ if ($context eq 'selfcreate') {
+ $rolename = $role;
+ if (ref($usertypes) eq 'HASH') {
+ if ($usertypes->{$role} ne '') {
+ $rolename = $usertypes->{$role};
+ }
+ }
} else {
- $rolename = &Apache::lonnet::plaintext($role);
+ if ($role eq 'cr') {
+ $rolename = &mt('Custom');
+ } else {
+ $rolename = &Apache::lonnet::plaintext($role);
+ }
}
my @modifiable;
- $resulttext .= '
'.&mt('Target user with [_1] role',$rolename).' - '.&mt('modifiable fields: ');
+ if ($context eq 'selfcreate') {
+ $resulttext .= '
'.&mt('Self-creation of account by users with status: [_1] ',$rolename).' - '.&mt('modifiable fields (if institutional data blank): ');
+ } else {
+ $resulttext .= '
'.&mt('Target user with [_1] role',$rolename).' - '.&mt('modifiable fields: ');
+ }
foreach my $field (@fields) {
if ($modifyhash{$context}{$role}{$field}) {
push(@modifiable,$fieldtitles{$field});
@@ -4184,7 +4442,7 @@ sub modify_defaults {
my ($dom,$r) = @_;
my ($resulttext,$mailmsgtxt,%newvalues,%changes,@errors);
my %domdefaults = &Apache::lonnet::get_domain_defaults($dom);
- my @items = ('auth_def','auth_arg_def','lang_def','timezone_def');
+ my @items = ('auth_def','auth_arg_def','lang_def','timezone_def','datelocale_def');
my @authtypes = ('internal','krb4','krb5','localauth');
foreach my $item (@items) {
$newvalues{$item} = $env{'form.'.$item};
@@ -4207,25 +4465,28 @@ sub modify_defaults {
}
} elsif ($item eq 'timezone_def') {
if ($newvalues{$item} ne '') {
- my @timezones = &DateTime::TimeZone->all_names;
- if (!grep(/^\Q$newvalues{$item}\E/,@timezones)) {
+ if (!DateTime::TimeZone->is_valid_name($newvalues{$item})) {
push(@errors,$item);
}
}
+ } elsif ($item eq 'datelocale_def') {
+ if ($newvalues{$item} ne '') {
+ my @datelocale_ids = DateTime::Locale->ids();
+ if (!grep(/^\Q$newvalues{$item}\E$/,@datelocale_ids)) {
+ push(@errors,$item);
+ }
+ }
}
if (grep(/^\Q$item\E$/,@errors)) {
$newvalues{$item} = $domdefaults{$item};
} elsif ($domdefaults{$item} ne $newvalues{$item}) {
$changes{$item} = 1;
}
+ $domdefaults{$item} = $newvalues{$item};
}
my %defaults_hash = (
- defaults => { auth_def => $newvalues{'auth_def'},
- auth_arg_def => $newvalues{'auth_arg_def'},
- lang_def => $newvalues{'lang_def'},
- timezone_def => $newvalues{'timezone_def'},
- }
- );
+ defaults => \%newvalues,
+ );
my $title = &defaults_titles();
my $putresult = &Apache::lonnet::put_dom('configuration',\%defaults_hash,
$dom);
@@ -4254,9 +4515,8 @@ sub modify_defaults {
$resulttext .= '';
$mailmsgtext .= "\n";
my $cachetime = 24*60*60;
- &Apache::lonnet::do_cache_new('domdefaults',$dom,
- $defaults_hash{'defaults'},$cachetime);
- if ($changes{'auth_def'} || $changes{'auth_arg_def'} || $changes{'lang_def'}) {
+ &Apache::lonnet::do_cache_new('domdefaults',$dom,\%domdefaults,$cachetime);
+ if ($changes{'auth_def'} || $changes{'auth_arg_def'} || $changes{'lang_def'} || $changes{'datelocale_def'}) {
my $sysmail = $r->dir_config('lonSysEMail');
&Apache::lonmsg::sendemail($sysmail,"LON-CAPA Domain Settings Change - $dom",$mailmsgtext);
}
@@ -4374,8 +4634,10 @@ sub modify_coursecategories {
} else {
$changes{'togglecats'} = 1;
$changes{'categorize'} = 1;
- $domconfig{'coursecategories'}{'togglecats'} = $env{'form.togglecats'};
- $domconfig{'coursecategories'}{'categorize'} = $env{'form.categorize'};
+ $domconfig{'coursecategories'} = {
+ togglecats => $env{'form.togglecats'},
+ categorize => $env{'form.categorize'},
+ };
}
if (ref($cathash) eq 'HASH') {
if (($domconfig{'coursecategories'}{'cats'}{'instcode::0'} ne '') && ($env{'form.instcode'} == 0)) {
@@ -4537,6 +4799,131 @@ sub modify_coursecategories {
}
return $resulttext;
}
+
+sub modify_serverstatuses {
+ my ($dom,%domconfig) = @_;
+ my ($resulttext,%changes,%currserverstatus,%newserverstatus);
+ if (ref($domconfig{'serverstatuses'}) eq 'HASH') {
+ %currserverstatus = %{$domconfig{'serverstatuses'}};
+ }
+ my @pages = &serverstatus_pages();
+ foreach my $type (@pages) {
+ $newserverstatus{$type}{'namedusers'} = '';
+ $newserverstatus{$type}{'machines'} = '';
+ if (defined($env{'form.'.$type.'_namedusers'})) {
+ my @users = split(/,/,$env{'form.'.$type.'_namedusers'});
+ my @okusers;
+ foreach my $user (@users) {
+ my ($uname,$udom) = split(/:/,$user);
+ if (($udom =~ /^$match_domain$/) &&
+ (&Apache::lonnet::domain($udom)) &&
+ ($uname =~ /^$match_username$/)) {
+ if (!grep(/^\Q$user\E/,@okusers)) {
+ push(@okusers,$user);
+ }
+ }
+ }
+ if (@okusers > 0) {
+ @okusers = sort(@okusers);
+ $newserverstatus{$type}{'namedusers'} = join(',',@okusers);
+ }
+ }
+ if (defined($env{'form.'.$type.'_machines'})) {
+ my @machines = split(/,/,$env{'form.'.$type.'_machines'});
+ my @okmachines;
+ foreach my $ip (@machines) {
+ my @parts = split(/\./,$ip);
+ next if (@parts < 4);
+ my $badip = 0;
+ for (my $i=0; $i<4; $i++) {
+ if (!(($parts[$i] >= 0) && ($parts[$i] <= 255))) {
+ $badip = 1;
+ last;
+ }
+ }
+ if (!$badip) {
+ push(@okmachines,$ip);
+ }
+ }
+ @okmachines = sort(@okmachines);
+ $newserverstatus{$type}{'machines'} = join(',',@okmachines);
+ }
+ }
+ my %serverstatushash = (
+ serverstatuses => \%newserverstatus,
+ );
+ my %changes;
+ foreach my $type (@pages) {
+ foreach my $setting ('namedusers','machines') {
+ my (@current,@new);
+ if (ref($currserverstatus{$type}) eq 'HASH') {
+ if ($currserverstatus{$type}{$setting} ne '') {
+ @current = split(/,/,$currserverstatus{$type}{$setting});
+ }
+ }
+ if ($newserverstatus{$type}{$setting} ne '') {
+ @new = split(/,/,$newserverstatus{$type}{$setting});
+ }
+ if (@current > 0) {
+ if (@new > 0) {
+ foreach my $item (@current) {
+ if (!grep(/^\Q$item\E$/,@new)) {
+ $changes{$type}{$setting} = 1;
+ last;
+ }
+ }
+ foreach my $item (@new) {
+ if (!grep(/^\Q$item\E$/,@current)) {
+ $changes{$type}{$setting} = 1;
+ last;
+ }
+ }
+ } else {
+ $changes{$type}{$setting} = 1;
+ }
+ } elsif (@new > 0) {
+ $changes{$type}{$setting} = 1;
+ }
+ }
+ }
+ if (keys(%changes) > 0) {
+ my $titles= &LONCAPA::lonauthcgi::serverstatus_titles();
+ my $putresult = &Apache::lonnet::put_dom('configuration',
+ \%serverstatushash,$dom);
+ if ($putresult eq 'ok') {
+ $resulttext .= &mt('Changes made:').'
';
+ foreach my $type (@pages) {
+ if (ref($changes{$type}) eq 'HASH') {
+ $resulttext .= '
'.$titles->{$type}.'
';
+ if ($changes{$type}{'namedusers'}) {
+ if ($newserverstatus{$type}{'namedusers'} eq '') {
+ $resulttext .= '
'.&mt("Access terminated for all specific (named) users").'
'."\n";
+ } else {
+ $resulttext .= '
'.&mt("Access available for the following specified users: ").$newserverstatus{$type}{'namedusers'}.'
'."\n";
+ }
+ }
+ if ($changes{$type}{'machines'}) {
+ if ($newserverstatus{$type}{'machines'} eq '') {
+ $resulttext .= '
'.&mt("Access terminated for all specific IP addresses").'
'."\n";
+ } else {
+ $resulttext .= '
'.&mt("Access available for the following specified IP addresses: ").$newserverstatus{$type}{'machines'}.'
'."\n";
+ }
+
+ }
+ $resulttext .= '
';
+ }
+ }
+ $resulttext .= '
';
+ } else {
+ $resulttext = ''.
+ &mt('An error occurred saving access settings for server status pages: [_1].',$putresult).'';
+
+ }
+ } else {
+ $resulttext = &mt('No changes made to access to server status pages');
+ }
+ return $resulttext;
+}
sub recurse_check {
my ($chkcats,$categories,$depth,$name) = @_;