version 1.1, 2007/02/16 01:37:54
|
version 1.2, 2007/02/26 20:52:55
|
Line 27
|
Line 27
|
use strict; |
use strict; |
use lib '/home/httpd/lib/perl'; |
use lib '/home/httpd/lib/perl'; |
use localenroll; |
use localenroll; |
use LONCAPA::Configuration; |
|
use LONCAPA::Enrollment; |
|
use Apache::lonnet; |
use Apache::lonnet; |
use Apache::loncommon; |
use Apache::loncommon; |
|
use LONCAPA; |
|
|
my @info = ('inststatus','lockedname','lastname','firstname','id'); |
my @info = ('inststatus','lockedname','lastname','firstname','id'); |
# find out which users we need to examine |
# find out which users we need to examine |
Line 43
|
Line 42
|
my $settings; |
my $settings; |
if (ref($domconfig{'autoupdate'}) eq 'HASH') { |
if (ref($domconfig{'autoupdate'}) eq 'HASH') { |
$settings = $domconfig{'autoupdate'}; |
$settings = $domconfig{'autoupdate'}; |
if ($settings->{'run'} eq 'yes') { |
if ($settings->{'run'} eq '1') { |
$run_update = 1; |
$run_update = 1; |
} |
} |
} |
} |
next if (!$run_update); |
next if (!$run_update); |
my %users; |
# get user information |
|
my (%instusers,%instids); |
|
next if (&localenroll::allusers_info($dom,\%instusers,\%instids) ne 'ok'); |
|
my (%users,%unamechg,%possnames); |
my @types = ('active','future'); |
my @types = ('active','future'); |
my @roles = ('st'); |
my @roles = ('st'); |
my @cdoms = ($dom); |
my @cdoms = ($dom); |
Line 56
|
Line 58
|
&descend_tree($dir,0,\%users); |
&descend_tree($dir,0,\%users); |
foreach my $uname (keys(%users)) { |
foreach my $uname (keys(%users)) { |
my %userhash = &Apache::lonnet::userenvironment($dom,$uname,@info); |
my %userhash = &Apache::lonnet::userenvironment($dom,$uname,@info); |
|
my (@inststatuses); |
|
if (!$userhash{'internalname'}) { |
|
if (defined($instusers{$uname})) { |
|
(my $insttypechg,@inststatuses) = |
|
&affiliations_check(\%userhash,$instusers{$uname}); |
|
if ($insttypechg) { |
|
my $inststatusstr = join(':',&escape(@inststatuses)); |
|
my %statushash = ( inststatus => $inststatusstr ); |
|
my $statusres = &Apache::lonnet::put('environment',\%statushash,$dom,$uname); |
|
} |
|
} |
|
} |
if (!$userhash{'lockedname'} && !$userhash{'internalname'}) { |
if (!$userhash{'lockedname'} && !$userhash{'internalname'}) { |
my %userinfo = &localenroll::get_userinfo($dom,$uname,%userhash); |
if (defined($instusers{$uname})) { |
if (keys(%userinfo) > 0) { |
my (@fields,%changes,$changed); |
my @fields = @{$settings->{'default'}}; |
if (@inststatuses > 0) { |
if ($userhash{'inststatus'} ne '') { |
foreach my $type (@inststatuses) { |
if (ref($settings->{$userhash{'inststatus'}}) eq 'ARRAY') { |
if (ref($settings->{fields}{$type}) eq 'ARRAY') { |
@fields = @{$settings->{$userhash{'inststatus'}}}; |
foreach my $field (@{$settings->{fields}{$type}}) { |
|
if (!grep(/^\Q$field\E$/,@fields)) { |
|
push(@fields,$field); |
|
} |
|
} |
|
} |
|
} |
|
} else { |
|
if (ref($settings->{fields}{'default'}) eq 'ARRAY') { |
|
@fields = @{$settings->{fields}{'default'}}; |
} |
} |
} |
} |
my %changes; |
|
my $changed; |
|
foreach my $field (@fields) { |
foreach my $field (@fields) { |
if ($userhash{$field} ne $userinfo{$field}) { |
if ($userhash{$field} ne $instusers{$uname}{$field}) { |
$changed = 1; |
$changed = 1; |
if ($settings->{'classlists'} eq 'yes') { |
if ($settings->{'classlists'} eq 'yes') { |
if ($field eq 'id') { |
if ($field eq 'id') { |
Line 83
|
Line 104
|
if ($changed) { |
if ($changed) { |
my %userupdate; |
my %userupdate; |
foreach my $field (@fields) { |
foreach my $field (@fields) { |
$userupdate{$field} = $userinfo{$field}; |
$userupdate{$field} = $instusers{$uname}{$field}; |
} |
} |
my $putresult = &Apache::lonnet::put |
my $modresult = &Apache::lonnet::modifyuser($dom,$uname,$userupdate{'id'},undef,undef,$userupdate{'firstname'},$userupdate{'middlename'},$userupdate{'lastname'},$userupdate{'generation'},1); |
('environment',\%userupdate,$dom,$uname); |
if ($modresult eq 'ok') { |
if ($putresult eq 'ok') { |
|
if ($settings->{'classlists'} eq 'yes') { |
if ($settings->{'classlists'} eq 'yes') { |
if ($changes{'id'} || $changes{'fullname'}) { |
if ($changes{'id'} || $changes{'fullname'}) { |
my %roleshash = |
my %roleshash = |
Line 104
|
Line 124
|
} |
} |
} |
} |
} |
} |
|
} else { |
|
# check if the username has changed |
|
if (defined($instids{$userhash{'id'}})) { |
|
if (ref($instids{$userhash{'id'}}) eq 'ARRAY') { |
|
foreach my $name (@{$instids{$userhash{'id'}}}) { |
|
if (!exists($users{$name})) { |
|
push(@{$possnames{$uname}},$name); |
|
} |
|
} |
|
} else { |
|
if (!exists($users{$instids{$userhash{'id'}}})) { |
|
$unamechg{$uname} = $instids{$userhash{'id'}}; |
|
} |
|
} |
|
} |
} |
} |
} |
} |
} |
} |
Line 165 sub update_classlist {
|
Line 200 sub update_classlist {
|
} |
} |
} |
} |
|
|
|
sub affiliations_check { |
|
my ($userhash,$insthashref) = @_; |
|
my (@inststatuses,$insttypechg);; |
|
if (ref($insthashref) eq 'HASH') { |
|
if (ref($insthashref->{type}) eq 'ARRAY') { |
|
@inststatuses = @{$insthashref->{type}}; |
|
} |
|
} |
|
my @currstatuses = &unescape(split(/:/,$userhash->{'inststatus'})); |
|
foreach my $status (@inststatuses) { |
|
if (!grep/^\Q$status\E/,@currstatuses) { |
|
$insttypechg = 1; |
|
} |
|
} |
|
if (!$insttypechg) { |
|
foreach my $status (@currstatuses) { |
|
if (!grep/^\Q$status\E/,@inststatuses) { |
|
$insttypechg = 1; |
|
} |
|
} |
|
} |
|
return ($insttypechg,@inststatuses); |
|
} |
|
|