--- loncom/interface/lonuserutils.pm 2013/12/09 18:47:18 1.158
+++ loncom/interface/lonuserutils.pm 2016/04/02 04:30:21 1.173
@@ -1,7 +1,7 @@
# The LearningOnline Network with CAPA
# Utility functions for managing LON-CAPA user accounts
#
-# $Id: lonuserutils.pm,v 1.158 2013/12/09 18:47:18 raeburn Exp $
+# $Id: lonuserutils.pm,v 1.173 2016/04/02 04:30:21 raeburn Exp $
#
# Copyright Michigan State University Board of Trustees
#
@@ -401,7 +401,7 @@ sub javascript_validations {
my $showcredits;
my %domdefaults = &Apache::lonnet::get_domain_defaults($domain);
- if ($domdefaults{'officialcredits'} || $domdefaults{'unofficialcredits'}) {
+ if ($domdefaults{'officialcredits'} || $domdefaults{'unofficialcredits'} || $domdefaults{'textbookcredits'}) {
$showcredits = 1;
}
@@ -450,6 +450,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 +643,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 +783,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).
@@ -1013,7 +1016,9 @@ sub print_upload_manager_footer {
.&Apache::lonhtmlcommon::row_closure();
}
if ($context eq 'course' || $context eq 'domain') {
- $Str .= &forceid_change($context);
+ $Str .= &Apache::lonhtmlcommon::row_title(&mt('Student/Employee ID'))
+ .&forceid_change($context)
+ .&Apache::lonhtmlcommon::row_closure(1); # last row in pick_box
}
$Str .= &Apache::lonhtmlcommon::end_pick_box();
@@ -1047,10 +1052,12 @@ sub get_defaultcredits {
return unless(($cdom =~ /^$match_domain$/) && ($cnum =~ /^$match_courseid$/));
my ($defaultcredits,$domdefcredits);
my %domdefaults = &Apache::lonnet::get_domain_defaults($cdom);
- if ($domdefaults{'officialcredits'} || $domdefaults{'unofficialcredits'}) {
+ if ($domdefaults{'officialcredits'} || $domdefaults{'unofficialcredits'} || $domdefaults{'textbookcredits'}) {
my $instcode = $env{'course.'.$cdom.'_'.$cnum.'.internal.coursecode'};
if ($instcode) {
$domdefcredits = $domdefaults{'officialcredits'};
+ } elsif ($env{'course.'.$cdom.'_'.$cnum.'.internal.textbook'}) {
+ $domdefcredits = $domdefaults{'textbookcredits'};
} else {
$domdefcredits = $domdefaults{'unofficialcredits'};
}
@@ -1076,18 +1083,15 @@ sub get_defaultcredits {
sub forceid_change {
my ($context) = @_;
my $output =
- &Apache::lonhtmlcommon::row_title(&mt('Student/Employee ID'))
- .' '
- .&mt('Disable Student/Employee ID Safeguard and force change of conflicting IDs')
- .' '."\n"
- .&mt('(only do if you know what you are doing.)')."\n";
+ ' '
+ .&mt('Force change of existing ID')
+ .' '.&Apache::loncommon::help_open_topic('ForceIDChange')."\n";
if ($context eq 'domain') {
- $output .= ' '.
- &mt('Update student/employee ID in courses in which user is active/future student,[_1](if forcing change).',' ').
- ' '."\n";
+ $output .=
+ ' '
+ .' '
+ .&mt("Update ID in user's course(s).").' '."\n";
}
- $output .= &Apache::lonhtmlcommon::row_closure(1); # last row in pick_box
return $output;
}
@@ -1392,9 +1396,9 @@ sub default_role_selector {
&default_course_roles($context,$checkpriv,'Course',%customroles)."\n".
'
'.
''.
- ''.
+ ' '.
$lt{'exs'}.''.
- ' <--'.&mt('Pick course first').
+ ' <--'.&mt('Pick course first').
' '.
' '.
''.$lt{'new'}.' '.
@@ -1637,7 +1641,7 @@ sub print_userlist {
return;
}
my ($indexhash,$keylist) = &make_keylist_array();
- my (%userlist,%userinfo,$clearcoursepick);
+ my (%userlist,%userinfo,$clearcoursepick,$needauthorquota,$needauthorusage);
if (($context eq 'domain') &&
($env{'form.roletype'} eq 'course') ||
($env{'form.roletype'} eq 'community')) {
@@ -1709,6 +1713,12 @@ sub print_userlist {
\%cstr_roles,$permission);
} elsif ($context eq 'domain') {
if ($env{'form.roletype'} eq 'domain') {
+ if (grep(/^authorusage$/,@cols)) {
+ $needauthorusage = 1;
+ }
+ if (grep(/^authorquota$/,@cols)) {
+ $needauthorquota = 1;
+ }
%dom_roles = &Apache::lonnet::get_domain_roles($env{'request.role.domain'});
foreach my $key (keys(%dom_roles)) {
if (ref($dom_roles{$key}) eq 'HASH') {
@@ -1821,7 +1831,7 @@ sub print_userlist {
} else {
($usercount) = &show_users_list($r,$context,$env{'form.output'},
$permission,$env{'form.Status'},\%userlist,
- $keylist,'',$showcredits);
+ $keylist,'',$showcredits,$needauthorquota,$needauthorusage);
}
if (!$usercount) {
$r->print(''
@@ -1991,7 +2001,7 @@ sub get_cols_array {
push(@cols,'photo');
}
if ($context eq 'domain') {
- push (@cols,'extent');
+ push (@cols,('authorusage','authorquota','extent'));
}
}
return @cols;
@@ -2027,6 +2037,8 @@ sub column_checkboxes {
if (($env{'form.roletype'} eq 'course') ||
($env{'form.roletype'} eq 'community')) {
$disabledchk{'status'} = 1;
+ $disabledchk{'authorusage'} = 1;
+ $disabledchk{'authorquota'} = 1;
} elsif ($env{'form.roletype'} eq 'domain') {
$disabledchk{'extent'} = 1;
}
@@ -2078,7 +2090,11 @@ sub column_checkboxes {
if (($env{'form.roletype'} eq 'domain') || ($env{'form.roletype'} eq '')) {
$style = ' style="display: none;"';
}
- }
+ } elsif (($cols[$i] eq 'authorusage') || ($cols[$i] eq 'authorquota')) {
+ if ($env{'form.roletype'} ne 'domain') {
+ $style = ' style="display: none;"';
+ }
+ }
$output .= ''.
''.
$lt{$cols[$i]}.' '.
@@ -2112,6 +2128,8 @@ sub get_column_names {
'photo' => "photo",
'lastlogin' => "last login",
'extent' => "extent",
+ 'authorusage' => "disk usage (%)",
+ 'authorquota' => "disk quota (MB)",
'ca' => "check all",
'ua' => "uncheck all",
'clicker' => "clicker-ID",
@@ -2395,6 +2413,8 @@ sub make_keylist_array {
$index->{'photo'} = &Apache::loncoursedata::CL_PHOTO();
$index->{'thumbnail'} = &Apache::loncoursedata::CL_THUMBNAIL();
$index->{'credits'} = &Apache::loncoursedata::CL_CREDITS();
+ $index->{'authorquota'} = &Apache::loncoursedata::CL_AUTHORQUOTA();
+ $index->{'authorusage'} = &Apache::loncoursedata::CL_AUTHORUSAGE();
foreach my $key (keys(%{$index})) {
$keylist->[$index->{$key}] = $key;
}
@@ -2444,10 +2464,11 @@ sub process_date_info {
sub show_users_list {
my ($r,$context,$mode,$permission,$statusmode,$userlist,$keylist,$formname,
- $showcredits)=@_;
+ $showcredits,$needauthorquota,$needauthorusage)=@_;
if ($formname eq '') {
$formname = 'studentform';
}
+ my $londocroot = $Apache::lonnet::perlvar{'lonDocRoot'};
#
# Variables for excel output
my ($excel_workbook, $excel_sheet, $excel_filename,$row,$format);
@@ -2464,6 +2485,10 @@ sub show_users_list {
}
} else {
push(@sortable,'extent');
+ if (($context eq 'domain') && ($env{'form.roletype'} eq 'domain') &&
+ (($env{'form.showrole'} eq 'Any') || ($env{'form.showrole'} eq 'au'))) {
+ push(@sortable,('authorusage','authorquota'));
+ }
}
if ($mode eq 'pickauthor') {
@sortable = ('username','fullname','email','status');
@@ -2710,13 +2735,13 @@ END
} else {
$output .= "\n".' '."\n";
if ($actionselect) {
- $output .= ''.&mt('Select').' '."\n";
+ $output .= ''.&mt('Select').' '."\n";
}
}
foreach my $item (@cols) {
- $output .= "";
+ $output .= ' ';
if ($is_sortable{$item}) {
- $output .= "$lt{$item} ";
+ $output .= "$lt{$item} ▼ ";
} else {
$output .= $lt{$item};
}
@@ -2891,6 +2916,26 @@ END
if ($emails{'permanentemail'} =~ /\S/) {
$userlist->{$user}->[$index{'email'}] = $emails{'permanentemail'};
}
+ if (($context eq 'domain') && ($env{'form.roletype'} eq 'domain') &&
+ ($role eq 'au')) {
+ my ($disk_quota,$current_disk_usage,$percent);
+ if (($needauthorusage) || ($needauthorquota)) {
+ $disk_quota = &Apache::loncommon::get_user_quota($uname,$udom,'author');
+ }
+ if ($needauthorusage) {
+ $current_disk_usage =
+ &Apache::lonnet::diskusage($udom,$uname,"$londocroot/priv/$udom/$uname");
+ if ($disk_quota == 0) {
+ $percent = 100.0;
+ } else {
+ $percent = $current_disk_usage/(10 * $disk_quota);
+ }
+ $userlist->{$user}->[$index{'authorusage'}] = sprintf("%.0f",$percent);
+ }
+ if ($needauthorquota) {
+ $userlist->{$user}->[$index{'authorquota'}] = sprintf("%.2f",$disk_quota);
+ }
+ }
$usercount ++;
}
my $autocount = 0;
@@ -2911,12 +2956,20 @@ END
my $index = $index{$sortby};
my $second = $index{'username'};
my $third = $index{'domain'};
- my @sorted_users = sort {
- lc($userlist->{$a}->[$index]) cmp lc($userlist->{$b}->[$index])
- ||
- lc($userlist->{$a}->[$second]) cmp lc($userlist->{$b}->[$second]) ||
- lc($userlist->{$a}->[$third]) cmp lc($userlist->{$b}->[$third])
- } (keys(%$userlist));
+ my @sorted_users;
+ if (($sortby eq 'authorquota') || ($sortby eq 'authorusage')) {
+ @sorted_users = sort {
+ $userlist->{$b}->[$index] <=> $userlist->{$a}->[$index] ||
+ lc($userlist->{$a}->[$second]) cmp lc($userlist->{$b}->[$second]) ||
+ lc($userlist->{$a}->[$third]) cmp lc($userlist->{$b}->[$third])
+ } (keys(%$userlist));
+ } else {
+ @sorted_users = sort {
+ lc($userlist->{$a}->[$index]) cmp lc($userlist->{$b}->[$index]) ||
+ lc($userlist->{$a}->[$second]) cmp lc($userlist->{$b}->[$second]) ||
+ lc($userlist->{$a}->[$third]) cmp lc($userlist->{$b}->[$third])
+ } (keys(%$userlist));
+ }
my $rowcount = 0;
foreach my $user (@sorted_users) {
my %in;
@@ -2927,7 +2980,7 @@ END
}
my $clickers = (&Apache::lonnet::userenvironment($in{'domain'},$in{'username'},'clickers'))[1];
if ($clickers!~/\w/) { $clickers='-'; }
- $in{'clicker'} = $clickers;
+ $in{'clicker'} = $clickers;
my $role = $in{'role'};
$in{'role'}=&Apache::lonnet::plaintext($sdata->[$index{'role'}],$crstype);
unless ($mode eq 'excel') {
@@ -2954,10 +3007,10 @@ END
if ($mode eq 'autoenroll') {
my $cellentry;
if ($in{'type'} eq 'auto') {
- $cellentry = ''.&mt('auto').' Change ';
+ $cellentry = ''.&mt('auto').' '.&mt('Change').' ';
$autocount ++;
} else {
- $cellentry = ''.&mt('manual').' Change';
+ $cellentry = ''.&mt('manual').' '.&mt('Change').'';
$manualcount ++;
if ($in{'lockedtype'}) {
$cellentry .= ' '.&mt('Unlock').' ';
@@ -3051,6 +3104,8 @@ END
$r->print(' '."\n");
}
}
+ } elsif (($item eq 'authorquota') || ($item eq 'authorusage')) {
+ $r->print(''.$in{$item}.' '."\n");
} else {
$r->print(''.$in{$item}.' '."\n");
}
@@ -3086,10 +3141,10 @@ END
$r->print(&Apache::loncommon::end_data_table().' ');
} elsif ($mode eq 'excel') {
$excel_workbook->close();
- $r->print(&mt('[_1]Your Excel spreadsheet[_2] is ready for download.', '',' ')."
\n");
+ $r->print(''.&mt('[_1]Your Excel spreadsheet[_2] is ready for download.', '',' ')."
\n");
} elsif ($mode eq 'csv') {
close($CSVfile);
- $r->print(&mt('[_1]Your CSV file[_2] is ready for download.', '',' ')."
\n");
+ $r->print(''.&mt('[_1]Your CSV file[_2] is ready for download.', '',' ')."
\n");
$r->rflush();
}
if ($mode eq 'autoenroll') {
@@ -3121,6 +3176,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;
@@ -3787,7 +3846,6 @@ sub show_drop_list {
$check_uncheck_js
// ]]>
-
END
my ($indexhash,$keylist) = &make_keylist_array();
@@ -3824,6 +3882,7 @@ END
$classlist,$keylist,$cdom,$cnum);
my %lt=&Apache::lonlocal::texthash('usrn' => "username",
'dom' => "domain",
+ 'id' => "ID",
'sn' => "student name",
'mn' => "member name",
'sec' => "section",
@@ -3842,7 +3901,7 @@ END
$lt{'usrn'}
$lt{'dom'}
- ID
+ $lt{'id'}
$nametitle
$lt{'sec'}
$lt{'start'}
@@ -3856,21 +3915,21 @@ END
$r->print(<
- $lt{'usrn'}
+ $lt{'usrn'}
- $lt{'dom'}
+ $lt{'dom'}
- ID
+ $lt{'id'}
- $nametitle
+ $nametitle
- $lt{'sec'}
+ $lt{'sec'}
- $lt{'start'}
+ $lt{'start'}
- $lt{'end'}
+ $lt{'end'}
- $lt{'groups'}
+ $lt{'groups'}
END
$r->print(&Apache::loncommon::end_data_table_header_row());
@@ -3941,7 +4000,6 @@ END
$btn = $lt{'dm'};
}
$r->print(<<"END");
-
@@ -4239,7 +4297,10 @@ 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;
foreach my $line (@userdata) {
+ $counter ++;
my @secs;
my %entries=&Apache::loncommon::record_sep($line);
# Determine user name
@@ -4271,23 +4332,20 @@ 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;
}
my $username = $entries{$fields{'username'}};
my $userdomain = $entries{$fields{'domain'}};
@@ -4299,10 +4357,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);
@@ -4314,14 +4377,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;
}
}
@@ -4373,13 +4443,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;
}
}
@@ -4409,55 +4478,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 ) {
@@ -4490,77 +4540,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').' ');
+ $r->rflush();
+ }
+ my %prog_state = &Apache::lonhtmlcommon::Create_PrgWin($r,$total);
+ $r->print('
');
+ 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];
}
}
}
@@ -4575,38 +4753,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'}).
@@ -4699,11 +4866,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'} ++;
@@ -4712,8 +4880,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'} ++;
@@ -4722,8 +4890,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'} ++;
@@ -4732,14 +4900,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;
}
@@ -4767,7 +4937,7 @@ sub print_drop_menu {
} else {
&show_drop_list($r,$classlist,'nosort',$permission,$crstype);
}
- $r->print(''. &Apache::loncommon::end_page());
+ $r->print('');
return;
}
@@ -5164,18 +5334,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) {
@@ -5300,7 +5477,7 @@ sub setsections_javascript {
}
$rolecode = "var match = str.split('_');
var role = match[3];\n";
- } elsif ($formname eq 'enrollstudent') {
+ } elsif (($formname eq 'enrollstudent') || ($formname eq 'selfenroll')) {
$checkincluded = 'formname.name == "'.$formname.'"';
if ($checkauth) {
$finish = "var authcheck = auth_check();\n".
@@ -5334,7 +5511,8 @@ sub setsections_javascript {
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.',
nonw => 'Section names may only contain letters or numbers.',
- );
+ );
+ &js_escape(\%alerts);
$setsection_js .= <<"ENDSECCODE";
function setSections(formname,crstype) {
@@ -5345,6 +5523,9 @@ function setSections(formname,crstype) {
var groups = new Array($groupslist);
for (var i=0;i $env{'course.'.$env{'request.course.id'}.'.internal.selfenrollmgrdc'},
+ 'internal.selfenrollmgrcc' => $env{'course.'.$env{'request.course.id'}.'.internal.selfenrollmgrcc'},
+ 'internal.coursecode' => $env{'course.'.$env{'request.course.id'}.'.internal.coursecode'},
+ 'internal.textbook' =>$env{'course.'.$env{'request.course.id'}.'.internal.textbook'},
+ );
+ my ($managed_by_cc,$managed_by_dc) = &selfenrollment_administration($cdom,$cnum,$crstype,\%coursehash);
+ if (ref($managed_by_cc) eq 'ARRAY') {
+ if (@{$managed_by_cc}) {
+ $permission{'selfenrolladmin'} = 1;
+ }
+ }
+ }
} elsif ($context eq 'author') {
$permission{'cusr'} = &authorpriv($env{'user.name'},$env{'request.role.domain'});
$permission{'view'} = $permission{'cusr'};
@@ -5952,6 +6149,7 @@ sub sectioncheck_alerts {
thwa => 'There was a problem with your course selection',
thwc => 'There was a problem with your community selection',
);
+ &js_escape(\%alerts);
return %alerts;
}
@@ -5962,6 +6160,7 @@ sub authcheck_alerts {
krb => 'You need to specify the Kerberos domain.',
ipass => 'You need to specify the initial password.',
);
+ &js_escape(\%alerts);
return %alerts;
}
@@ -5980,5 +6179,128 @@ sub is_courseowner {
return;
}
+sub get_selfenroll_titles {
+ my @row = ('types','registered','enroll_dates','access_dates','section',
+ 'approval','limit');
+ my %lt = &Apache::lonlocal::texthash (
+ types => 'Users allowed to self-enroll',
+ registered => 'Registration status (official courses)' ,
+ enroll_dates => 'Dates self-enrollment available',
+ access_dates => 'Access dates for self-enrolling users',
+ section => "Self-enrolling users' section",
+ approval => 'Processing of requests',
+ limit => 'Enrollment limit',
+ );
+ return (\@row,\%lt);
+}
+
+sub selfenroll_default_descs {
+ my %desc = (
+ types => {
+ dom => &mt('Course domain'),
+ all => &mt('Any domain'),
+ '' => &mt('None'),
+ },
+ limit => {
+ none => &mt('No limit'),
+ allstudents => &mt('Limit by total students'),
+ selfenrolled => &mt('Limit by total self-enrolled'),
+ },
+ approval => {
+ '0' => &mt('Processed automatically'),
+ '1' => &mt('Queued for approval'),
+ '2' => &mt('Queued, pending validation'),
+ },
+ registered => {
+ 0 => 'No registration required',
+ 1 => 'Registered students only',
+ },
+ );
+ return %desc;
+}
+
+sub selfenroll_validation_types {
+ my @items = ('url','fields','button','markup');
+ my %names = &Apache::lonlocal::texthash (
+ url => 'Web address of validation server/script',
+ fields => 'Form fields to send to validator',
+ button => 'Text for validation button',
+ markup => 'Validation description (HTML)',
+ );
+ my @fields = ('username','domain','uniquecode','course','coursetype','description');
+ return (\@items,\%names,\@fields);
+}
+
+sub get_extended_type {
+ my ($cdom,$cnum,$crstype,$current) = @_;
+ my $type = 'unofficial';
+ my %settings;
+ if (ref($current) eq 'HASH') {
+ %settings = %{$current};
+ } else {
+ %settings = &Apache::lonnet::get('environment',['internal.coursecode','internal.textbook'],$cdom,$cnum);
+ }
+ if ($crstype eq 'Community') {
+ $type = 'community';
+ } elsif ($crstype eq 'Placement') {
+ $type = 'placement';
+ } elsif ($settings{'internal.coursecode'}) {
+ $type = 'official';
+ } elsif ($settings{'internal.textbook'}) {
+ $type = 'textbook';
+ }
+ return $type;
+}
+
+sub selfenrollment_administration {
+ my ($cdom,$cnum,$crstype,$coursehash) = @_;
+ my %settings;
+ if (ref($coursehash) eq 'HASH') {
+ %settings = %{$coursehash};
+ } else {
+ %settings = &Apache::lonnet::get('environment',
+ ['internal.selfenrollmgrdc','internal.selfenrollmgrcc',
+ 'internal.coursecode','internal.textbook'],$cdom,$cnum);
+ }
+ my ($possconfigs) = &get_selfenroll_titles();
+ my %domdefaults = &Apache::lonnet::get_domain_defaults($cdom);
+ my $selfenrolltype = &get_extended_type($cdom,$cnum,$crstype,\%settings);
+
+ my (@in_course,@in_domain);
+ if ($settings{'internal.selfenrollmgrcc'} ne '') {
+ @in_course = split(/,/,$settings{'internal.selfenrollmgrcc'});
+ my @diffs = &Apache::loncommon::compare_arrays($possconfigs,\@in_course);
+ unless (@diffs) {
+ return (\@in_course,\@in_domain);
+ }
+ }
+ if ($settings{'internal.selfenrollmgrdc'} ne '') {
+ my @in_domain = split(/,/,$settings{'internal.selfenrollmgrdc'});
+ my @diffs = &Apache::loncommon::compare_arrays(\@in_domain,$possconfigs);
+ unless (@diffs) {
+ return (\@in_course,\@in_domain);
+ }
+ }
+ my @combined = @in_course;
+ push(@combined,@in_domain);
+ my @diffs = &Apache::loncommon::compare_arrays(\@combined,$possconfigs);
+ unless (@diffs) {
+ return (\@in_course,\@in_domain);
+ }
+ if ($domdefaults{$selfenrolltype.'selfenrolladmdc'} eq '') {
+ push(@in_course,@diffs);
+ } else {
+ my @defaultdc = split(/,/,$domdefaults{$selfenrolltype.'selfenrolladmdc'});
+ foreach my $item (@diffs) {
+ if (grep(/^\Q$item\E$/,@defaultdc)) {
+ push(@in_domain,$item);
+ } else {
+ push(@in_course,$item);
+ }
+ }
+ }
+ return (\@in_course,\@in_domain);
+}
+
1;