version 1.26, 2023/12/06 23:38:45
|
version 1.27, 2023/12/06 23:46:16
|
Line 49
|
Line 49
|
# find out which users we need to examine |
# find out which users we need to examine |
my @domains = sort(&Apache::lonnet::current_machine_domains()); |
my @domains = sort(&Apache::lonnet::current_machine_domains()); |
foreach my $dom (@domains) { |
foreach my $dom (@domains) { |
my %domconfig = &Apache::lonnet::get_dom('configuration',['autoupdate'], |
my %domconfig = &Apache::lonnet::get_dom('configuration',['autoupdate','usercreation'], |
$dom); |
$dom); |
#only run if configured to |
#only run if configured to |
my $run_update = 0; |
my $run_update = 0; |
Line 74
|
Line 74
|
# get courseIDs for domain |
# get courseIDs for domain |
my %courses=&Apache::lonnet::courseiddump($dom,'.',1,'.','.','.',1,[$hostid],'.'); |
my %courses=&Apache::lonnet::courseiddump($dom,'.',1,'.','.','.',1,[$hostid],'.'); |
# get user information |
# get user information |
my (%users,%instusers,%instids,%counts); |
my (%users,%instusers,%instids,%counts,@idrules); |
my $dir = $Apache::lonnet::perlvar{lonUsersDir}.'/'.$dom; |
my $dir = $Apache::lonnet::perlvar{lonUsersDir}.'/'.$dom; |
&descend_tree($dom,$dir,0,\%users,\%courses,$allowed_inactivity,$check_unexpired); |
&descend_tree($dom,$dir,0,\%users,\%courses,$allowed_inactivity,$check_unexpired); |
my $resp = &localenroll::allusers_info($dom,\%instusers,\%instids,\%users,\%counts); |
my $resp = &localenroll::allusers_info($dom,\%instusers,\%instids,\%users,\%counts); |
Line 98
|
Line 98
|
my @types = ('active','future'); |
my @types = ('active','future'); |
my @roles = ('st'); |
my @roles = ('st'); |
my @cdoms = ($dom); |
my @cdoms = ($dom); |
|
if (ref($domconfig{'usercreation'}) eq 'HASH') { |
|
if (ref($domconfig{'usercreation'}{'id_rule'}) eq 'ARRAY') { |
|
@idrules = @{$domconfig{'usercreation'}{'id_rule'}}; |
|
} |
|
} |
foreach my $uname (sort(keys(%users))) { |
foreach my $uname (sort(keys(%users))) { |
my %userhash = &Apache::lonnet::userenvironment($dom,$uname,@info); |
my %userhash = &Apache::lonnet::userenvironment($dom,$uname,@info); |
my (@inststatuses); |
my (@inststatuses); |
Line 132
|
Line 137
|
} |
} |
foreach my $field (@fields) { |
foreach my $field (@fields) { |
if ($userhash{$field} ne $instusers{$uname}{$field}) { |
if ($userhash{$field} ne $instusers{$uname}{$field}) { |
$changed = 1; |
# Do not change student/employee ID when field is modifiable |
if ($settings->{'classlists'} == 1) { |
# but institutional data is absent or does not match rules |
if ($field eq 'id') { |
# defined for IDs for institutional users in domain |
$changes{'id'} = 1; |
if ($field eq 'id') { |
} elsif ($field eq 'lastname' || $field eq 'firstname' || $field eq 'middlename' || $field eq 'generation') { |
if ($instusers{$uname}{$field} eq '') { |
$changes{'fullname'} = 1; |
$instusers{$uname}{$field} = $userhash{$field}; |
|
next; |
|
} elsif (@idrules > 0) { |
|
my %idchecks; |
|
if (&LONCAPA::localenroll::id_check($dom,$instusers{$uname}{$field}, |
|
\@idrules,\%idchecks) eq 'ok') { |
|
my $matches; |
|
foreach my $result (values(%idchecks)) { |
|
if ($result) { |
|
$matches = 1; |
|
last; |
|
} |
|
} |
|
if ($matches) { |
|
$changed = 1; |
|
} else { |
|
$instusers{$uname}{$field} = $userhash{$field}; |
|
next; |
|
} |
|
} |
|
} |
|
} else { |
|
$changed = 1; |
|
} |
|
if ($field eq 'id') { |
|
$changes{'id'} = 1; |
|
} elsif ($field eq 'lastname' || $field eq 'firstname' || $field eq 'middlename' || $field eq 'generation') { |
|
$changes{'fullname'} = 1; |
|
} |
|
} |
|
} |
|
# Do not change name information when lastname and firstname are modifiable |
|
# but institutional data is absent for both components of a user's name. |
|
if ($changed) { |
|
if ($changes{'fullname'}) { |
|
my %modifiable; |
|
map { $modifiable{$_} = 1; } @fields; |
|
if (($modifiable{'lastname'}) && ($modifiable{'firstname'}) && |
|
($instusers{$uname}{'lastname'} eq '') && ($instusers{$uname}{'firstname'} eq '')) { |
|
if ($changes{'fullname'}) { |
|
undef($changes{'fullname'}); |
|
} |
|
if ($changes{'id'}) { |
|
foreach my $field ('lastname','firstname','middlename','generation') { |
|
$instusers{$uname}{$field} = $userhash{$field}; |
|
} |
|
} else { |
|
undef($changed); |
} |
} |
} |
} |
} |
} |