--- loncom/interface/lonuserutils.pm 2014/02/16 15:38:53 1.163
+++ loncom/interface/lonuserutils.pm 2017/08/08 15:34:32 1.186
@@ -1,7 +1,7 @@
# The LearningOnline Network with CAPA
# Utility functions for managing LON-CAPA user accounts
#
-# $Id: lonuserutils.pm,v 1.163 2014/02/16 15:38:53 raeburn Exp $
+# $Id: lonuserutils.pm,v 1.186 2017/08/08 15:34:32 raeburn Exp $
#
# Copyright Michigan State University Board of Trustees
#
@@ -30,12 +30,29 @@
package Apache::lonuserutils;
+=pod
+
+=head1 NAME
+
+Apache::lonuserutils.pm
+
+=head1 SYNOPSIS
+
+ Utilities for management of users and custom roles
+
+ Provides subroutines called by loncreateuser.pm
+
+=head1 OVERVIEW
+
+=cut
+
use strict;
use Apache::lonnet;
use Apache::loncommon();
use Apache::lonhtmlcommon;
use Apache::lonlocal;
use Apache::longroup;
+use HTML::Entities;
use LONCAPA qw(:DEFAULT :match);
###############################################################
@@ -450,6 +467,7 @@ sub javascript_validations {
if (($mode eq 'upload') && ($context eq 'domain')) {
$alert{'inststatus'} = &mt('The optional affiliation field was not specified');
}
+ &js_escape(\%alert);
my $function_name = <<"END";
$setsections_js
@@ -642,8 +660,9 @@ sub upload_manager_javascript_forward_as
$numbuttons ++;
}
if (!$can_assign->{'int'}) {
- my $warning = &mt('You may not specify an initial password for each user, as this is only available when new users use LON-CAPA internal authentication.').'\n'.
+ my $warning = &mt('You may not specify an initial password for each user, as this is only available when new users use LON-CAPA internal authentication.')."\n".
&mt('Your current role does not have rights to create users with that authentication type.');
+ &js_escape(\$warning);
$auth_update = <<"END";
// Currently the initial password field is only supported for internal auth
// (see bug 6368).
@@ -781,6 +800,7 @@ sub upload_manager_javascript_reverse_as
if (!$can_assign->{'int'}) {
my $warning = &mt('You may not specify an initial password, as this is only available when new users use LON-CAPA internal authentication.\n').
&mt('Your current role does not have rights to create users with that authentication type.');
+ &js_escape(\$warning);
$auth_update = <<"END";
// Currently the initial password field is only supported for internal auth
// (see bug 6368).
@@ -923,8 +943,14 @@ sub print_upload_manager_footer {
&Apache::lonhtmlcommon::row_closure();
}
+ my ($trustedref,$untrustedref);
+ if ($context eq 'course') {
+ ($trustedref,$untrustedref) = &Apache::lonnet::trusted_domains('enroll',$defdom);
+ } elsif ($context eq 'author') {
+ ($trustedref,$untrustedref) = &Apache::lonnet::trusted_domains('othcoau',$defdom);
+ }
$Str .= &Apache::lonhtmlcommon::row_title(&mt('Default domain'))
- .&Apache::loncommon::select_dom_form($defdom,'defaultdomain',undef,1)
+ .&Apache::loncommon::select_dom_form($defdom,'defaultdomain',undef,1,undef,$trustedref,$untrustedref)
.&Apache::lonhtmlcommon::row_closure();
$Str .= &Apache::lonhtmlcommon::row_title(&mt('Starting and Ending Dates'))
@@ -1081,7 +1107,7 @@ sub forceid_change {
my ($context) = @_;
my $output =
''.&Apache::loncommon::help_open_topic('ForceIDChange')."\n";
if ($context eq 'domain') {
$output .=
@@ -1527,10 +1553,10 @@ sub curr_role_permissions {
# ======================================================= Existing Custom Roles
sub my_custom_roles {
- my ($crstype) = @_;
+ my ($crstype,$udom,$uname) = @_;
my %returnhash=();
my $extra = &Apache::lonnet::freeze_escape({'skipcheck' => 1});
- my %rolehash=&Apache::lonnet::dump('roles');
+ my %rolehash=&Apache::lonnet::dump('roles',$udom,$uname);
foreach my $key (keys(%rolehash)) {
if ($key=~/^rolesdef\_(\w+)$/) {
if ($crstype eq 'Community') {
@@ -2287,7 +2313,7 @@ sub courses_selector {
my $allidlist = $idlist{$codetitles[0]};
$jscript .= &Apache::courseclassifier::courseset_js_start($formname,$longtitles_str,$allidlist);
$jscript .= $scripttext;
- $jscript .= &Apache::courseclassifier::javascript_code_selections($formname,@codetitles);
+ $jscript .= &Apache::courseclassifier::javascript_code_selections($formname,\@codetitles);
}
}
my $cb_jscript = &Apache::loncommon::coursebrowser_javascript($cdom);
@@ -2410,6 +2436,7 @@ sub make_keylist_array {
$index->{'photo'} = &Apache::loncoursedata::CL_PHOTO();
$index->{'thumbnail'} = &Apache::loncoursedata::CL_THUMBNAIL();
$index->{'credits'} = &Apache::loncoursedata::CL_CREDITS();
+ $index->{'instsec'} = &Apache::loncoursedata::CL_INSTSEC();
$index->{'authorquota'} = &Apache::loncoursedata::CL_AUTHORQUOTA();
$index->{'authorusage'} = &Apache::loncoursedata::CL_AUTHORUSAGE();
foreach my $key (keys(%{$index})) {
@@ -2542,14 +2569,22 @@ $verify_action_js
function username_display_launch(username,domain) {
var target;
- for (var i=0; i "Open in a new window",
'modify' => "Modify a user's information",
'track' => "View a user's recent activity",
+ 'activity' => "View a user's access log",
);
my %lt = (%coltxt,%acttxt);
my $rolefilter = $env{'form.showrole'};
@@ -2694,12 +2730,17 @@ END
if ($permission->{'cusr'}) {
unshift (@linkdests,'modify');
}
- if (&Apache::lonnet::allowed('vsa', $env{'request.course.id'}) ||
- &Apache::lonnet::allowed('vsa', $env{'request.course.id'}.'/'.
- $env{'request.course.sec'})) {
- push(@linkdests,'track');
+ if ($context eq 'course') {
+ if (&Apache::lonnet::allowed('vsa', $env{'request.course.id'}) ||
+ &Apache::lonnet::allowed('vsa', $env{'request.course.id'}.'/'.
+ $env{'request.course.sec'})) {
+ push(@linkdests,'track');
+ }
+ } elsif ($context eq 'domain') {
+ if (&Apache::lonnet::allowed('vac',$env{'request.role.domain'})) {
+ push(@linkdests,'activity');
+ }
}
-
$output .= '
';
my $usernamelink = $env{'form.usernamelink'};
if ($usernamelink eq '') {
@@ -2722,7 +2763,7 @@ END
.''.$lt{'owin'}
.'
';
}
- $output .= "\n".' '."\n".
+ $output .= "\n".''."\n".
&Apache::loncommon::start_data_table().
&Apache::loncommon::start_data_table_header_row();
if ($mode eq 'autoenroll') {
@@ -2968,6 +3009,12 @@ END
} (keys(%$userlist));
}
my $rowcount = 0;
+ my $disabled;
+ if ($mode eq 'autoenroll') {
+ unless ($permission->{'cusr'}) {
+ $disabled = ' disabled="disabled"';
+ }
+ }
foreach my $user (@sorted_users) {
my %in;
my $sdata = $userlist->{$user};
@@ -3004,16 +3051,16 @@ END
if ($mode eq 'autoenroll') {
my $cellentry;
if ($in{'type'} eq 'auto') {
- $cellentry = ''.&mt('auto').' ';
+ $cellentry = ''.&mt('auto').' ';
$autocount ++;
} else {
- $cellentry = '
'."\n");
} elsif ($item eq 'status') {
my $showitem = $in{$item};
if (defined($ltstatus{$in{$item}})) {
@@ -3173,6 +3226,10 @@ sub bulkaction_javascript {
my $noaction = &mt("You need to select an action to take for the user(s) you have selected");
my $singconfirm = &mt(' for a single user?');
my $multconfirm = &mt(' for multiple users?');
+ &js_escape(\$alert);
+ &js_escape(\$noaction);
+ &js_escape(\$singconfirm);
+ &js_escape(\$multconfirm);
my $output = <<"ENDJS";
function verify_action (field) {
var numchecked = 0;
@@ -4087,17 +4144,19 @@ sub upfile_drop_add {
$fieldstype{$field.'_choice'} = 'scalar';
}
&Apache::loncommon::store_course_settings('enrollment_upload',\%fieldstype);
- my ($cid,$crstype,$setting);
+ my ($cid,$crstype,$setting,$crsdom);
if ($context eq 'domain') {
$setting = $env{'form.roleaction'};
}
if ($env{'request.course.id'} ne '') {
$cid = $env{'request.course.id'};
$crstype = &Apache::loncommon::course_type();
+ $crsdom = $env{'course.'.$env{'request.course.id'}.'.domain'};
} elsif ($setting eq 'course') {
if (&Apache::lonnet::is_course($env{'form.dcdomain'},$env{'form.dccourse'})) {
$cid = $env{'form.dcdomain'}.'_'.$env{'form.dccourse'};
$crstype = &Apache::loncommon::course_type($cid);
+ $crsdom = $env{'form.dcdomain'};
}
}
my ($startdate,$enddate) = &get_dates_from_form();
@@ -4108,7 +4167,43 @@ sub upfile_drop_add {
my $defdom=$env{'request.role.domain'};
my $domain;
if ($env{'form.defaultdomain'} ne '') {
- $domain = $env{'form.defaultdomain'};
+ if (($context eq 'course') || ($setting eq 'course')) {
+ unless ($env{'form.defaultdomain'} eq $crsdom) {
+ if (&Apache::lonnet::will_trust('enroll',$crsdom,$env{'form.defaultdomain'})) {
+ $domain = $env{'form.defaultdomain'};
+ } else {
+ $r->print(''.&mt('Error').
+ &mt('Enrollment of users not permitted for specified default domain: [_1].',
+ &Apache::lonnet::domain($env{'form.defaultdomain'},'description')).'');
+ $r->print(&Apache::loncommon::end_page());
+ }
+ return;
+ }
+ } elsif ($context eq 'author') {
+ unless ($env{'form.defaultdomain'} eq $defdom) {
+ if ((&Apache::lonnet::will_trust('othcoau',$defdom,$env{'form.defaultdomain'})) &&
+ (&Apache::lonnet::will_trust('coaurem',$env{'form.defaultdomain'},$defdom))) {
+ $domain = $env{'form.defaultdomain'};
+ } else {
+ $r->print(''.&mt('Error').
+ &mt('Addition of users not permitted for specified default domain: [_1].',
+ &Apache::lonnet::domain($env{'form.defaultdomain'},'description')).'');
+ $r->print(&Apache::loncommon::end_page());
+ }
+ return;
+ }
+ } elsif (($context eq 'domain') && ($setting eq 'domain')) {
+ unless ($env{'form.defaultdomain'} eq $defdom) {
+ if (&Apache::lonnet::will_trust('domroles',$defdom,$env{'form.defaultdomain'})) {
+ $domain = $env{'form.defaultdomain'};
+ } else {
+ $r->print(''.&mt('Error').
+ &mt('Addition of users not permitted for specified default domain: [_1].',
+ &Apache::lonnet::domain($env{'form.defaultdomain'},'description')).'');
+ $r->print(&Apache::loncommon::end_page());
+ }
+ }
+ }
} else {
$domain = $defdom;
}
@@ -4290,7 +4385,11 @@ sub upfile_drop_add {
my $newuserdom = $env{'request.role.domain'};
map { $cancreate{$_} = &can_create_user($newuserdom,$context,$_); } keys(%longtypes);
# Get new users list
+ my (%existinguser,%userinfo,%disallow,%rulematch,%inst_results,%alerts,%checkuname);
+ my $counter = -1;
+ my (%willtrust,%trustchecked);
foreach my $line (@userdata) {
+ $counter ++;
my @secs;
my %entries=&Apache::loncommon::record_sep($line);
# Determine user name
@@ -4322,23 +4421,42 @@ sub upfile_drop_add {
if ($entries{$fields{'username'}} =~ /\s/) {
$nowhitespace = ' - '.&mt('usernames may not contain spaces.');
}
- $r->print(
- ' '.
+ $disallow{$counter} =
&mt('Unacceptable username [_1] for user [_2] [_3] [_4] [_5]',
- '"'.$entries{$fields{'username'}}.'"',
- $fname,$mname,$lname,$gen).
- $nowhitespace);
+ '"'.$entries{$fields{'username'}}.'"',
+ $fname,$mname,$lname,$gen).$nowhitespace;
next;
} else {
$entries{$fields{'domain'}} =~ s/^\s+|\s+$//g;
if ($entries{$fields{'domain'}}
ne &LONCAPA::clean_domain($entries{$fields{'domain'}})) {
- $r->print(
- ' '.
+ $disallow{$counter} =
&mt('Unacceptable domain [_1] for user [_2] [_3] [_4] [_5]',
- '"'.$entries{$fields{'domain'}}.'"',
- $fname,$mname,$lname,$gen));
- next;
+ '"'.$entries{$fields{'domain'}}.'"',
+ $fname,$mname,$lname,$gen);
+ next;
+ } elsif ($entries{$fields{'domain'}} ne $domain) {
+ my $possdom = $entries{$fields{'domain'}};
+ if ($context eq 'course' || $setting eq 'course') {
+ unless ($trustchecked{$possdom}) {
+ $willtrust{$possdom} = &Apache::lonnet::will_trust('enroll',$domain,$possdom);
+ $trustchecked{$possdom} = 1;
+ }
+ } elsif ($context eq 'author') {
+ unless ($trustchecked{$possdom}) {
+ $willtrust{$possdom} = &Apache::lonnet::will_trust('othcoau',$domain,$possdom);
+ }
+ if ($willtrust{$possdom}) {
+ $willtrust{$possdom} = &Apache::lonnet::will_trust('coaurem',$possdom,$domain);
+ }
+ }
+ unless ($willtrust{$possdom}) {
+ $disallow{$counter} =
+ &mt('Unacceptable domain [_1] for user [_2] [_3] [_4] [_5]',
+ '"'.$possdom.'"',
+ $fname,$mname,$lname,$gen);
+ next;
+ }
}
my $username = $entries{$fields{'username'}};
my $userdomain = $entries{$fields{'domain'}};
@@ -4350,10 +4468,15 @@ sub upfile_drop_add {
$entries{$fields{'sec'}} =~ s/\W//g;
my $item = $entries{$fields{'sec'}};
if ($item eq "none" || $item eq 'all') {
- $r->print(' '.&mt('[_1]: Unable to enroll user [_2] [_3] [_4] [_5] in a section named "[_6]" - this is a reserved word.',''.$username.'',$fname,$mname,$lname,$gen,$item));
+ $disallow{$counter} =
+ &mt('[_1]: Unable to enroll user [_2] [_3] [_4] [_5] in a section named "[_6]" - this is a reserved word.',
+ ''.$username.'',$fname,$mname,$lname,$gen,$item);
next;
} elsif (exists($curr_groups{$item})) {
- $r->print(' '.&mt('[_1]: Unable to enroll user [_2] [_3] [_4] [_5] in a section named "[_6]" - this is a course group.',''.$username.'',$fname,$mname,$lname,$gen,$item).' '.&mt('Section names and group names must be distinct.'));
+ $disallow{$counter} =
+ &mt('[_1]: Unable to enroll user [_2] [_3] [_4] [_5] in a section named "[_6]" - this is a course group.',
+ ''.$username.'',$fname,$mname,$lname,$gen,$item).' '.
+ &mt('Section names and group names must be distinct.');
next;
} else {
push(@secs,$item);
@@ -4365,14 +4488,21 @@ sub upfile_drop_add {
if (ref($userlist{$username.':'.$userdomain}) eq 'ARRAY') {
my $currsec = $userlist{$username.':'.$userdomain}[$secidx];
if ($currsec ne $env{'request.course.sec'}) {
- $r->print(' '.&mt('[_1]: Unable to enroll user [_2] [_3] [_4] [_5] in a section named "[_6]".',''.$username.'',$fname,$mname,$lname,$gen,$secs[0]).' ');
+ $disallow{$counter} =
+ &mt('[_1]: Unable to enroll user [_2] [_3] [_4] [_5] in a section named "[_6]".',
+ ''.$username.'',$fname,$mname,$lname,$gen,$secs[0]);
if ($currsec eq '') {
- $r->print(&mt('This user already has an active/future student role in the course, unaffiliated to any section.'));
+ $disallow{$counter} .=
+ &mt('This user already has an active/future student role in the course, unaffiliated to any section.');
} else {
- $r->print(&mt('This user already has an active/future role in section "[_1]" of the course.',$currsec));
+ $disallow{$counter} .=
+ &mt('This user already has an active/future role in section "[_1]" of the course.',$currsec);
}
- $r->print(' '.&mt('Although your current role has privileges to add students to section "[_1]", you do not have privileges to modify existing enrollments in other sections.',$secs[0]).' ');
+ $disallow{$counter} .=
+ ' '.
+ &mt('Although your current role has privileges to add students to section "[_1]", you do not have privileges to modify existing enrollments in other sections.',
+ $secs[0]);
next;
}
}
@@ -4424,13 +4554,12 @@ sub upfile_drop_add {
}
if ($role eq '') {
my $rolestr = join(', ',@permitted_roles);
- $r->print(' '
- .&mt('[_1]: You do not have permission to add the requested role [_2] for the user.'
- ,''.$entries{$fields{'username'}}.''
- ,$entries{$fields{'role'}})
- .' '
- .&mt('Allowable role(s) is/are: [_1].',$rolestr)."\n"
- );
+ $disallow{$counter} =
+ &mt('[_1]: You do not have permission to add the requested role [_2] for the user.'
+ ,''.$entries{$fields{'username'}}.''
+ ,$entries{$fields{'role'}})
+ .' '
+ .&mt('Allowable role(s) is/are: [_1].',$rolestr);
next;
}
}
@@ -4460,55 +4589,36 @@ sub upfile_drop_add {
# check against rules
my $checkid = 0;
my $newuser = 0;
- my (%rulematch,%inst_results,%idinst_results);
my $uhome=&Apache::lonnet::homeserver($username,$userdomain);
if ($uhome eq 'no_host') {
if ($userdomain ne $newuserdom) {
if ($context eq 'course') {
- $r->print(' '.
- &mt('[_1]: The domain specified ([_2]) is different to that of the course.',
- ''.$username.'',$userdomain).' ');
+ $disallow{$counter} =
+ &mt('[_1]: The domain specified ([_2]) is different to that of the course.',
+ ''.$username.'',$userdomain);
} elsif ($context eq 'author') {
- $r->print(&mt('[_1]: The domain specified ([_2]) is different to that of the author.',
- ''.$username.'',$userdomain).' ');
+ $disallow{$counter} =
+ &mt('[_1]: The domain specified ([_2]) is different to that of the author.',
+ ''.$username.'',$userdomain);
} else {
- $r->print(&mt('[_1]: The domain specified ([_2]) is different to that of your current role.',
- ''.$username.'',$userdomain).' ');
+ $disallow{$counter} =
+ &mt('[_1]: The domain specified ([_2]) is different to that of your current role.',
+ ''.$username.'',$userdomain);
}
- $r->print(&mt('The user does not already exist, and you may not create a new user in a different domain.'));
+ $disallow{$counter} .=
+ &mt('The user does not already exist, and you may not create a new user in a different domain.');
next;
+ } else {
+ unless ($password || $env{'form.login'} eq 'loc') {
+ $disallow{$counter} =
+ &mt('[_1]: This is a new user but no default password was provided, and the authentication type requires one.',
+ ''.$username.'');
+ next;
+ }
}
$checkid = 1;
$newuser = 1;
- my $user = $username.':'.$newuserdom;
- my $checkhash;
- my $checks = { 'username' => 1 };
- $checkhash->{$username.':'.$newuserdom} = { 'newuser' => 1, };
- &Apache::loncommon::user_rule_check($checkhash,$checks,
- \%alerts,\%rulematch,\%inst_results,\%curr_rules,
- \%got_rules);
- if (ref($alerts{'username'}) eq 'HASH') {
- if (ref($alerts{'username'}{$newuserdom}) eq 'HASH') {
- if ($alerts{'username'}{$newuserdom}{$username}) {
- $r->print(' '.
- &mt('[_1]: matches the username format at your institution, but is not known to your directory service.',''.$username.'').' '.
- &mt('Consequently, the user was not created.'));
- next;
- }
- }
- }
- my $usertype = 'unofficial';
- if (ref($rulematch{$user}) eq 'HASH') {
- if ($rulematch{$user}{'username'}) {
- $usertype = 'official';
- }
- }
- unless ($cancreate{$usertype}) {
- my $showtype = $longtypes{$usertype};
- $r->print(' '.
- &mt('[_1]: The user does not exist, and you are not permitted to create users of type: [_2].',''.$username.'',$showtype));
- next;
- }
+ $checkuname{$username.':'.$newuserdom} = { 'newuser' => $newuser, 'id' => $id };
} else {
if ($context eq 'course' || $context eq 'author') {
if ($userdomain eq $domain ) {
@@ -4541,77 +4651,205 @@ sub upfile_drop_add {
}
}
}
+ if ($id) {
+ $existinguser{$userdomain}{$username} = $id;
+ }
}
- if ($id ne '') {
- if (!$newuser) {
- my %idhash = &Apache::lonnet::idrget($userdomain,($username));
- if ($idhash{$username} ne $id) {
- $checkid = 1;
+ $userinfo{$counter} = {
+ username => $username,
+ domain => $userdomain,
+ fname => $fname,
+ mname => $mname,
+ lname => $lname,
+ gen => $gen,
+ email => $email,
+ id => $id,
+ password => $password,
+ inststatus => $inststatus,
+ role => $role,
+ sections => \@secs,
+ credits => $credits,
+ newuser => $newuser,
+ checkid => $checkid,
+ };
+ }
+ }
+ } # end of foreach (@userdata)
+ if ($counter > -1) {
+ my $total = $counter + 1;
+ my %checkids;
+ if ((keys(%existinguser)) || (keys(%checkuname))) {
+ $r->print(&mt('Please be patient -- checking for institutional data ...'));
+ $r->rflush();
+ if (keys(%existinguser)) {
+ foreach my $dom (keys(%existinguser)) {
+ if (ref($existinguser{$dom}) eq 'HASH') {
+ my %idhash = &Apache::lonnet::idrget($dom,keys(%{$existinguser{$dom}}));
+ foreach my $username (keys(%{$existinguser{$dom}})) {
+ if ($idhash{$username} ne $existinguser{$dom}{$username}) {
+ $checkids{$username.':'.$dom} = {
+ 'id' => $existinguser{$dom}{$username},
+ };
+ }
+ }
+ if (keys(%checkids)) {
+ &Apache::loncommon::user_rule_check(\%checkids,{ 'id' => 1 },
+ \%alerts,\%rulematch,
+ \%inst_results,\%curr_rules,
+ \%got_rules);
}
}
- if ($checkid) {
- my $checkhash;
- my $checks = { 'id' => 1 };
- $checkhash->{$username.':'.$userdomain} = { 'newuser' => $newuser,
- 'id' => $id };
- &Apache::loncommon::user_rule_check($checkhash,$checks,
- \%alerts,\%rulematch,\%idinst_results,\%curr_rules,
- \%got_rules);
+ }
+ }
+ if (keys(%checkuname)) {
+ &Apache::loncommon::user_rule_check(\%checkuname,{ 'username' => 1, 'id' => 1, },
+ \%alerts,\%rulematch,\%inst_results,
+ \%curr_rules,\%got_rules);
+ }
+ $r->print(' '.&mt('done').'
');
+ for (my $i=0; $i<=$counter; $i++) {
+ if ($disallow{$i}) {
+ $r->print('
'.$disallow{$i}.'
');
+ } elsif (ref($userinfo{$i}) eq 'HASH') {
+ my $password = $userinfo{$i}{'password'};
+ my $newuser = $userinfo{$i}{'newuser'};
+ my $checkid = $userinfo{$i}{'checkid'};
+ my $id = $userinfo{$i}{'id'};
+ my $role = $userinfo{$i}{'role'};
+ my @secs;
+ if (ref($userinfo{$i}{'sections'}) eq 'ARRAY') {
+ @secs = @{$userinfo{$i}{'sections'}};
+ }
+ my $fname = $userinfo{$i}{'fname'};
+ my $mname = $userinfo{$i}{'mname'};
+ my $lname = $userinfo{$i}{'lname'};
+ my $gen = $userinfo{$i}{'gen'};
+ my $email = $userinfo{$i}{'email'};
+ my $inststatus = $userinfo{$i}{'inststatus'};
+ my $credits = $userinfo{$i}{'credits'};
+ my $username = $userinfo{$i}{'username'};
+ my $userdomain = $userinfo{$i}{'domain'};
+ my $user = $username.':'.$userdomain;
+ if ($newuser) {
+ if (ref($alerts{'username'}) eq 'HASH') {
+ if (ref($alerts{'username'}{$userdomain}) eq 'HASH') {
+ if ($alerts{'username'}{$userdomain}{$username}) {
+ $r->print('
'.
+ &mt('[_1]: matches the username format at your institution, but is not known to your directory service.',''.$username.'').' '.
+ &mt('Consequently, the user was not created.').'
');
+ next;
+ }
+ }
+ }
+ if (ref($inst_results{$user}) eq 'HASH') {
+ if ($inst_results{$user}{'firstname'} ne '') {
+ $fname = $inst_results{$user}{'firstname'};
+ }
+ if ($inst_results{$user}{'middlename'} ne '') {
+ $mname = $inst_results{$user}{'middlename'};
+ }
+ if ($inst_results{$user}{'lasttname'} ne '') {
+ $lname = $inst_results{$user}{'lastname'};
+ }
+ if ($inst_results{$user}{'permanentemail'} ne '') {
+ $email = $inst_results{$user}{'permanentemail'};
+ }
+ if ($inst_results{$user}{'id'} ne '') {
+ $id = $inst_results{$user}{'id'};
+ $checkid = 0;
+ }
+ if (ref($inst_results{$user}{'inststatus'}) eq 'ARRAY') {
+ $inststatus = join(':',@{$inst_results{$user}{'inststatus'}});
+ }
+ }
+ if (($checkid) && ($id ne '')) {
if (ref($alerts{'id'}) eq 'HASH') {
if (ref($alerts{'id'}{$userdomain}) eq 'HASH') {
- if ($alerts{'id'}{$userdomain}{$id}) {
- $r->print(&mt('[_1]: has a student/employee ID matching the format at your institution, but the ID is found by your directory service.',
+ if ($alerts{'id'}{$userdomain}{$username}) {
+ $r->print('
'.
+ &mt('[_1]: has a student/employee ID matching the format at your institution, but the ID is not found by your directory service.',
''.$username.'').' '.
- &mt('Consequently, the user was not created.'));
+ &mt('Consequently, the user was not created.').'
');
next;
}
}
}
}
+ my $usertype = 'unofficial';
+ if (ref($rulematch{$user}) eq 'HASH') {
+ if ($rulematch{$user}{'username'}) {
+ $usertype = 'official';
+ }
+ }
+ unless ($cancreate{$usertype}) {
+ my $showtype = $longtypes{$usertype};
+ $r->print('
'.
+ &mt('[_1]: The user does not exist, and you are not permitted to create users of type: [_2].',''.$username.'',$showtype).'
');
+ next;
+ }
+ } elsif ($id ne '') {
+ if (exists($checkids{$user})) {
+ $checkid = 1;
+ if (ref($alerts{'id'}) eq 'HASH') {
+ if (ref($alerts{'id'}{$userdomain}) eq 'HASH') {
+ if ($alerts{'id'}{$userdomain}{$username}) {
+ $r->print('
'.
+ &mt('[_1]: has a student/employee ID matching the format at your institution, but the ID is not found by your directory service.',
+ ''.$username.'').' '.
+ &mt('Consequently, the ID was not changed.').'
');
+ $id = '';
+ }
+ }
+ }
+ }
}
- if ($password || $env{'form.login'} eq 'loc') {
- my $multiple = 0;
- my ($userresult,$authresult,$roleresult,$idresult);
- my (%userres,%authres,%roleres,%idres);
- my $singlesec = '';
- if ($role eq 'st') {
- my $sec;
+ my $multiple = 0;
+ my ($userresult,$authresult,$roleresult,$idresult);
+ my (%userres,%authres,%roleres,%idres);
+ my $singlesec = '';
+ if ($role eq 'st') {
+ my $sec;
+ if (ref($userinfo{$i}{'sections'}) eq 'ARRAY') {
if (@secs > 0) {
$sec = $secs[0];
}
- &modifystudent($userdomain,$username,$cid,$sec,
- $desiredhost,$context);
- $roleresult =
- &Apache::lonnet::modifystudent
- ($userdomain,$username,$id,$amode,$password,
- $fname,$mname,$lname,$gen,$sec,$enddate,
- $startdate,$env{'form.forceid'},
- $desiredhost,$email,'manual','',$cid,
- '',$context,$inststatus,$credits);
- $userresult = $roleresult;
- } else {
- if ($role ne '') {
- if ($context eq 'course' || $setting eq 'course') {
- if ($customroles{$role}) {
- $role = 'cr_'.$env{'user.domain'}.'_'.
- $env{'user.name'}.'_'.$role;
- }
- if (($role ne 'cc') && ($role ne 'co')) {
- if (@secs > 1) {
- $multiple = 1;
- foreach my $sec (@secs) {
- ($userres{$sec},$authres{$sec},$roleres{$sec},$idres{$sec}) =
- &modifyuserrole($context,$setting,
- $changeauth,$cid,$userdomain,$username,
- $id,$amode,$password,$fname,
- $mname,$lname,$gen,$sec,
- $env{'form.forceid'},$desiredhost,
- $email,$role,$enddate,
- $startdate,$checkid,$inststatus);
- }
- } elsif (@secs > 0) {
- $singlesec = $secs[0];
+ }
+ &modifystudent($userdomain,$username,$cid,$sec,
+ $desiredhost,$context);
+ $roleresult =
+ &Apache::lonnet::modifystudent
+ ($userdomain,$username,$id,$amode,$password,
+ $fname,$mname,$lname,$gen,$sec,$enddate,
+ $startdate,$env{'form.forceid'},
+ $desiredhost,$email,'manual','',$cid,
+ '',$context,$inststatus,$credits);
+ $userresult = $roleresult;
+ } else {
+ if ($role ne '') {
+ if ($context eq 'course' || $setting eq 'course') {
+ if ($customroles{$role}) {
+ $role = 'cr_'.$env{'user.domain'}.'_'.
+ $env{'user.name'}.'_'.$role;
+ }
+ if (($role ne 'cc') && ($role ne 'co')) {
+ if (@secs > 1) {
+ $multiple = 1;
+ foreach my $sec (@secs) {
+ ($userres{$sec},$authres{$sec},$roleres{$sec},$idres{$sec}) =
+ &modifyuserrole($context,$setting,
+ $changeauth,$cid,$userdomain,$username,
+ $id,$amode,$password,$fname,
+ $mname,$lname,$gen,$sec,
+ $env{'form.forceid'},$desiredhost,
+ $email,$role,$enddate,
+ $startdate,$checkid,$inststatus);
}
+ } elsif (@secs > 0) {
+ $singlesec = $secs[0];
}
}
}
@@ -4626,38 +4864,27 @@ sub upfile_drop_add {
$checkid,$inststatus);
}
}
- if ($multiple) {
- foreach my $sec (sort(keys(%userres))) {
- $flushc =
+ }
+ if ($multiple) {
+ foreach my $sec (sort(keys(%userres))) {
+ $flushc =
&user_change_result($r,$userres{$sec},$authres{$sec},
$roleres{$sec},$idres{$sec},\%counts,$flushc,
$username,$userdomain,\%userchg);
- }
- } else {
- $flushc =
- &user_change_result($r,$userresult,$authresult,
- $roleresult,$idresult,\%counts,$flushc,
- $username,$userdomain,\%userchg);
}
} else {
- if ($context eq 'course') {
- $r->print(' '.
- &mt('[_1]: Unable to enroll. No password specified.',''.$username.'')
- );
- } elsif ($context eq 'author') {
- $r->print(' '.
- &mt('[_1]: Unable to add co-author. No password specified.',''.$username.'')
- );
- } else {
- $r->print(' '.
- &mt('[_1]: Unable to add user. No password specified.',''.$username.'')
- );
- }
+ $flushc =
+ &user_change_result($r,$userresult,$authresult,
+ $roleresult,$idresult,\%counts,$flushc,
+ $username,$userdomain,\%userchg);
}
}
- }
- } # end of foreach (@userdata)
+ &Apache::lonhtmlcommon::Increment_PrgWin($r,\%prog_state,'last user');
+ } # end of loop
+ $r->print('
');
+ &Apache::lonhtmlcommon::Close_PrgWin($r,\%prog_state);
+ }
# Flush the course logs so reverse user roles immediately updated
$r->register_cleanup(\&Apache::lonnet::flushcourselogs);
$r->print("\n
\n".&mt('Processed [quant,_1,user].',$counts{'user'}).
@@ -4750,11 +4977,12 @@ sub user_change_result {
my ($r,$userresult,$authresult,$roleresult,$idresult,$counts,$flushc,
$username,$userdomain,$userchg) = @_;
my $okresult = 0;
+ my @status;
if ($userresult ne 'ok') {
if ($userresult =~ /^error:(.+)$/) {
my $error = $1;
- $r->print(' '.
- &mt('[_1]: Unable to add/modify: [_2]',''.$username.':'.$userdomain.'',$error));
+ push(@status,
+ &mt('[_1]: Unable to add/modify: [_2]',''.$username.':'.$userdomain.'',$error));
}
} else {
$counts->{'user'} ++;
@@ -4763,8 +4991,8 @@ sub user_change_result {
if ($authresult ne 'ok') {
if ($authresult =~ /^error:(.+)$/) {
my $error = $1;
- $r->print(' '.
- &mt('[_1]: Unable to modify authentication: [_2]',''.$username.':'.$userdomain.'',$error));
+ push(@status,
+ &mt('[_1]: Unable to modify authentication: [_2]',''.$username.':'.$userdomain.'',$error));
}
} else {
$counts->{'auth'} ++;
@@ -4773,8 +5001,8 @@ sub user_change_result {
if ($roleresult ne 'ok') {
if ($roleresult =~ /^error:(.+)$/) {
my $error = $1;
- $r->print(' '.
- &mt('[_1]: Unable to add role: [_2]',''.$username.':'.$userdomain.'',$error));
+ push(@status,
+ &mt('[_1]: Unable to add role: [_2]',''.$username.':'.$userdomain.'',$error));
}
} else {
$counts->{'role'} ++;
@@ -4783,14 +5011,16 @@ sub user_change_result {
if ($okresult) {
$flushc++;
$userchg->{$username.':'.$userdomain}=1;
- $r->print('. ');
if ($flushc>15) {
$r->rflush;
$flushc=0;
}
}
if ($idresult) {
- $r->print($idresult);
+ push(@status,$idresult);
+ }
+ if (@status) {
+ $r->print('
'.join(' ',@status).'
');
}
return $flushc;
}
@@ -4861,7 +5091,7 @@ sub update_user_list {
foreach my $item (@changelist) {
my ($role,$uname,$udom,$cid,$sec,$scope,$result,$type,$locktype,
@sections,$scopestem,$singlesec,$showsecs,$warn_singlesec,
- $nothingtodo,$keepnosection,$credits);
+ $nothingtodo,$keepnosection,$credits,$instsec);
if ($choice eq 'drop') {
($uname,$udom,$sec) = split(/:/,$item,-1);
$role = 'st';
@@ -4874,8 +5104,9 @@ sub update_user_list {
$scope = $scopestem.'/'.$sec;
}
} elsif ($context eq 'course') {
- ($uname,$udom,$role,$sec,$type,$locktype,$credits) =
- split(/\:/,$item);
+ ($uname,$udom,$role,$sec,$type,$locktype,$credits,$instsec) =
+ split(/\:/,$item,8);
+ $instsec = &unescape($instsec);
$cid = $env{'request.course.id'};
$scopestem = '/'.$cid;
$scopestem =~s/\_/\//g;
@@ -4894,8 +5125,9 @@ sub update_user_list {
} elsif ($setting eq 'author') {
($uname,$udom,$role,$scope) = split(/\:/,$item);
} elsif ($setting eq 'course') {
- ($uname,$udom,$role,$cid,$sec,$type,$locktype,$credits) =
- split(/\:/,$item);
+ ($uname,$udom,$role,$cid,$sec,$type,$locktype,$credits,$instsec) =
+ split(/\:/,$item,9);
+ $instsec = &unescape($instsec);
$scope = '/'.$cid;
$scope =~s/\_/\//g;
if ($sec ne '') {
@@ -4917,7 +5149,7 @@ sub update_user_list {
$end = $now;
if ($role eq 'st') {
$result =
- &Apache::lonnet::modify_student_enrollment($udom,$uname,undef,undef,undef,undef,undef,$sec,$end,$start,$type,$locktype,$cid,'',$context,$credits);
+ &Apache::lonnet::modify_student_enrollment($udom,$uname,undef,undef,undef,undef,undef,$sec,$end,$start,$type,$locktype,$cid,'',$context,$credits,$instsec);
} else {
$result =
&Apache::lonnet::revokerole($udom,$uname,$scope,$role,
@@ -4925,7 +5157,7 @@ sub update_user_list {
}
} elsif ($choice eq 'delete') {
if ($role eq 'st') {
- &Apache::lonnet::modify_student_enrollment($udom,$uname,undef,undef,undef,undef,undef,$sec,$now,$start,$type,$locktype,$cid,'',$context,$credits);
+ &Apache::lonnet::modify_student_enrollment($udom,$uname,undef,undef,undef,undef,undef,$sec,$now,$start,$type,$locktype,$cid,'',$context,$credits,$instsec);
}
$result =
&Apache::lonnet::assignrole($udom,$uname,$scope,$role,$now,
@@ -4938,7 +5170,7 @@ sub update_user_list {
}
if ($choice eq 'reenable') {
if ($role eq 'st') {
- $result = &Apache::lonnet::modify_student_enrollment($udom,$uname,undef,undef,undef,undef,undef,$sec,$end,$start,$type,$locktype,$cid,'',$context,$credits);
+ $result = &Apache::lonnet::modify_student_enrollment($udom,$uname,undef,undef,undef,undef,undef,$sec,$end,$start,$type,$locktype,$cid,'',$context,$credits,$instsec);
} else {
$result =
&Apache::lonnet::assignrole($udom,$uname,$scope,$role,$end,
@@ -4946,14 +5178,14 @@ sub update_user_list {
}
} elsif ($choice eq 'activate') {
if ($role eq 'st') {
- $result = &Apache::lonnet::modify_student_enrollment($udom,$uname,undef,undef,undef,undef,undef,$sec,$end,$start,$type,$locktype,$cid,'',$context,$credits);
+ $result = &Apache::lonnet::modify_student_enrollment($udom,$uname,undef,undef,undef,undef,undef,$sec,$end,$start,$type,$locktype,$cid,'',$context,$credits,$instsec);
} else {
$result = &Apache::lonnet::assignrole($udom,$uname,$scope,$role,$end,
$now,'','',$context);
}
} elsif ($choice eq 'chgdates') {
if ($role eq 'st') {
- $result = &Apache::lonnet::modify_student_enrollment($udom,$uname,undef,undef,undef,undef,undef,$sec,$end,$start,$type,$locktype,$cid,'',$context,$credits);
+ $result = &Apache::lonnet::modify_student_enrollment($udom,$uname,undef,undef,undef,undef,undef,$sec,$end,$start,$type,$locktype,$cid,'',$context,$credits,$instsec);
} else {
$result = &Apache::lonnet::assignrole($udom,$uname,$scope,$role,$end,
$start,'','',$context);
@@ -5023,7 +5255,7 @@ sub update_user_list {
} else {
if ($role eq 'st') {
$result =
- &Apache::lonnet::modify_student_enrollment($udom,$uname,undef,undef,undef,undef,undef,undef,$end,$start,$type,$locktype,$cid,'',$context,$credits);
+ &Apache::lonnet::modify_student_enrollment($udom,$uname,undef,undef,undef,undef,undef,undef,$end,$start,$type,$locktype,$cid,'',$context,$credits,$instsec);
} else {
my $newscope = $scopestem;
$result = &Apache::lonnet::assignrole($udom,$uname,$newscope,$role,$end,$start,'','',$context);
@@ -5037,7 +5269,7 @@ sub update_user_list {
foreach my $newsec (@newsecs) {
if (!grep(/^\Q$newsec\E$/,@retained)) {
if ($role eq 'st') {
- $result = &Apache::lonnet::modify_student_enrollment($udom,$uname,undef,undef,undef,undef,undef,$newsec,$end,$start,$type,$locktype,$cid,'',$context,$credits);
+ $result = &Apache::lonnet::modify_student_enrollment($udom,$uname,undef,undef,undef,undef,undef,$newsec,$end,$start,$type,$locktype,$cid,'',$context,$credits,$instsec);
if (@newsecs > 1) {
my $showsingle;
if ($newsec eq '') {
@@ -5215,18 +5447,25 @@ sub active_student_roles {
sub section_check_js {
my $groupslist= &get_groupslist();
+ my %js_lt = &Apache::lonlocal::texthash(
+ mayn => 'may not be used as the name for a section, as it is a reserved word.',
+ plch => 'Please choose a different section name.',
+ mnot => 'may not be used as a section name, as it is the name of a course group.',
+ secn => 'Section names and group names must be distinct. Please choose a different section name.',
+ );
+ &js_escape(\%js_lt);
return <<"END";
function validate(caller) {
var groups = new Array($groupslist);
var secname = caller.value;
if ((secname == 'all') || (secname == 'none')) {
- alert("'"+secname+"' may not be used as the name for a section, as it is a reserved word.\\nPlease choose a different section name.");
+ alert("'"+secname+"' $js_lt{'mayn'}\\n$js_lt{'plch'}");
return 'error';
}
if (secname != '') {
for (var k=0; k $b} keys %{$sections_count});
+ my @sections = (sort {$a <=> $b} keys(%{$sections_count}));
my $numsec = scalar(@sections);
my $is_selected = ' selected="selected"';
if ($numsec <= 1) {
- $output = '