--- loncom/interface/lonuserutils.pm 2024/01/05 04:01:40 1.221 +++ loncom/interface/lonuserutils.pm 2025/01/13 01:00:58 1.225 @@ -1,7 +1,7 @@ # The LearningOnline Network with CAPA # Utility functions for managing LON-CAPA user accounts # -# $Id: lonuserutils.pm,v 1.221 2024/01/05 04:01:40 raeburn Exp $ +# $Id: lonuserutils.pm,v 1.225 2025/01/13 01:00:58 raeburn Exp $ # # Copyright Michigan State University Board of Trustees # @@ -2844,6 +2844,7 @@ sub gather_userinfo { ($userdata{'username'},$userdata{'domain'},$userdata{'role'}) = split(/:/,$item); ($userdata{'start'},$userdata{'end'})=split(/:/,$rolehash->{$item}); + next if (($userdata{'username'} eq '') && ($userdata{'domain'} eq '')); &build_user_record($context,\%userdata,$userinfo,$indexhash, $item,$userlist); } elsif ($context eq 'course') { @@ -3517,15 +3518,28 @@ END Future => 'Future', Expired => 'Expired', ); - my (%crslogins,%camanagers); + my (%crslogins,%camanagers,%othdoms); if ($context eq 'course') { # If this is for a single course get last course "log-in". %crslogins=&Apache::lonnet::dump('nohist_crslastlogin',$cdom,$cnum); } elsif ($context eq 'author') { - map { $camanagers{$_.':ca'} = 1; } split(/,/,$env{'environment.authormanagers'}); + my $authormanagers; + if ($env{'request.role'} =~ m{^(?:ca|aa)\./($match_domain)/($match_username)$}) { + my %envhash = &Apache::lonnet::userenvironment($1,$2,'authormanagers'); + $authormanagers = $envhash{'authormanagers'}; + } else { + $authormanagers = $env{'environment.authormanagers'}; + } + if ($authormanagers ne '') { + map { $camanagers{$_.':ca'} = 1; } split(/,/,$authormanagers); + } } # Get groups, role, permanent e-mail so we can sort on them if # necessary. + # Compare user's domain with $env{'request.role.dom'}, and if + # different add to the domains for which to retrieve data on + # viewable user information, by institutional status, for users + # from "other" domains. foreach my $user (keys(%{$userlist})) { if ($user eq '' ) { delete($userlist->{$user}); @@ -3656,6 +3670,9 @@ END $userlist->{$user}->[$index{'authorquota'}] = sprintf("%.2f",$disk_quota); } } + unless ($env{'request.role.domain'} eq $udom) { + $othdoms{$udom} = 1; + } $usercount ++; } my $autocount = 0; @@ -3697,16 +3714,83 @@ END $disabled = ' disabled="disabled"'; } } + my (%shownfields_by_dom,%checkshown); + if (keys(%othdoms)) { + my @userinfo = ('firstname','middlename','lastname','generation', + 'permanentemail','id'); + foreach my $dom (keys(%othdoms)) { + my %shownfields = &get_othdom_shownfields($dom,\@userinfo); + $shownfields_by_dom{$dom} = \%shownfields; + } + foreach my $item (@userinfo) { + if ($item eq 'id') { + if (grep(/^\Q$item\E$/,@cols)) { + $checkshown{$item} = 1; + } + } elsif ($item eq 'permamentemail') { + if (grep(/^email$/,@cols)) { + $checkshown{$item} = 1; + } + } elsif (grep(/^fullname$/,@cols)) { + $checkshown{$item} = 1; + } + } + } foreach my $user (@sorted_users) { my %in; my $sdata = $userlist->{$user}; - $rowcount ++; + $rowcount ++; foreach my $item (@{$keylist}) { $in{$item} = $sdata->[$index{$item}]; } - my $clickers = (&Apache::lonnet::userenvironment($in{'domain'},$in{'username'},'clickers'))[1]; - if ($clickers!~/\w/) { $clickers='-'; } - $in{'clicker'} = $clickers; + if ((grep(/^clicker$/,@cols)) || (keys(%checkshown) && (exists($othdoms{$in{'domain'}})))) { + my %info = &Apache::lonnet::userenvironment($in{'domain'},$in{'username'},'clickers','inststatus', + 'firstname','middlename','lastname','generation'); + if (grep(/^clicker$/,@cols)) { + if ($info{'clickers'} !~/\w/) { $info{'clickers'} = '-'; } + $in{'clicker'} = $info{'clickers'}; + } + if (keys(%checkshown) && exists($othdoms{$in{'domain'}})) { + my @statuses; + if ($info{'inststatus'} ne '') { + @statuses = split(/:/,$info{'inststatus'}); + } else { + @statuses = ('default'); + } + if (ref($shownfields_by_dom{$in{'domain'}}) eq 'HASH') { + my (%shown,$rebuildname,%names); + foreach my $type (@statuses) { + if (ref($shownfields_by_dom{$in{'domain'}}{$type}) eq 'HASH') { + foreach my $key (keys(%{$shownfields_by_dom{$in{'domain'}}{$type}})) { + $shown{$key} = 1; + } + } + } + foreach my $item ('id','permanentemail') { + if ($checkshown{$item} && !$shown{$item}) { + if ($item eq 'permanentemail') { + $in{'email'} = &mt('not shown'); + } else { + $in{$item} = &mt('not shown'); + } + } + } + foreach my $item ('firstname','middlename','lastname','generation') { + if ($checkshown{$item} && !$shown{$item}) { + $rebuildname = 1; + } else { + $names{$item} = $info{$item}; + } + } + if ($rebuildname) { + $in{'fullname'} = &Apache::lonnet::format_name($names{'firstname'}, + $names{'middlename'}, + $names{'lastname'}, + $names{'generation'},'lastname'); + } + } + } + } my $role = $in{'role'}; $in{'role'}=&Apache::lonnet::plaintext($sdata->[$index{'role'}],$crstype); unless ($mode eq 'excel') { @@ -3828,13 +3912,10 @@ END } elsif ($item eq 'clicker') { if (($context eq 'course') && ($mode ne 'autoenroll')) { if ($env{'form.showrole'} eq 'st' || $env{'form.showrole'} eq 'Any') { - my $clickers = - (&Apache::lonnet::userenvironment($in{'domain'},$in{'username'},'clickers'))[1]; - if ($clickers!~/\w/) { $clickers='-'; } - $r->print('