--- loncom/interface/lonuserutils.pm 2010/09/20 00:21:08 1.125
+++ loncom/interface/lonuserutils.pm 2013/01/23 17:48:37 1.147
@@ -1,7 +1,7 @@
# The LearningOnline Network with CAPA
# Utility functions for managing LON-CAPA user accounts
#
-# $Id: lonuserutils.pm,v 1.125 2010/09/20 00:21:08 raeburn Exp $
+# $Id: lonuserutils.pm,v 1.147 2013/01/23 17:48:37 bisitz Exp $
#
# Copyright Michigan State University Board of Trustees
#
@@ -335,13 +335,22 @@ sub print_upload_manager_header {
$env{'request.role.domain'},$context,
$groupslist,$crstype);
my $checked=(($env{'form.noFirstLine'})?' checked="checked"':'');
- $r->print('
'
- .&mt('Total number of records found in file: [_1]'
- ,''.$distotal.'')
- ."
\n");
- $r->print('
'.
- &mt('Identify fields in uploaded list')."
\n");
- $r->print(&mt('Enter as many fields as you can. The system will inform you and bring you back to this page, if the data selected are insufficient to add users.')." \n");
+ $r->print(
+ '
'.&mt('Identify fields in uploaded list')."
\n".
+ '
'.
+ &mt('Total number of records found in file: [_1]'
+ ,''.$distotal.'').
+ "
\n"
+ );
+ if ($distotal == 0) {
+ $r->print('
'.&mt('None found').'
');
+ }
+ $r->print(
+ '
'.
+ &mt('Enter as many fields as you can.').' '.
+ &mt('The system will inform you and bring you back to this page,[_1]if the data selected are insufficient to add users.',' ').
+ "
'
+ );
+ $r->print(
+ ''
+ );
}
###############################################################
@@ -533,6 +548,7 @@ END
if (message!='') {
message+='\\n';
}
+ message+='$alert{'section'}';
}
if (foundemail==0) {
if (message!='') {
@@ -587,28 +603,43 @@ END
###############################################################
sub upload_manager_javascript_forward_associate {
my ($can_assign) = @_;
- my $auth_update;
+ my ($auth_update,$numbuttons,$argreset);
if (ref($can_assign) eq 'HASH') {
- if (keys(%{$can_assign}) > 1) {
+ if ($can_assign->{'krb4'} || $can_assign->{'krb5'}) {
+ $argreset .= " vf.krbarg.value='';\n";
+ $numbuttons ++ ;
+ }
+ if ($can_assign->{'int'}) {
+ $argreset .= " vf.intarg.value='';\n";
+ $numbuttons ++;
+ }
+ if ($can_assign->{'loc'}) {
+ $argreset .= " vf.locarg.value='';\n";
+ $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'
+ &mt('Your current role does not have rights to create users with that authentication type.');
+ $auth_update = <<"END";
+ // Currently the initial password field is only supported for internal auth
+ // (see bug 6368).
+ if (nw==9) {
+ eval('vf.f'+tf+'.selectedIndex=0;')
+ alert('$warning');
+ }
+END
+ } elsif ($numbuttons > 1) {
$auth_update = <<"END";
// If we set the password, make the password form below correspond to
// the new value.
if (nw==9) {
changed_radio('int',document.studentform);
set_auth_radio_buttons('int',document.studentform);
+$argreset
+ }
+
END
}
- if ($can_assign->{'krb4'} || $can_assign->{'krb5'}) {
- $auth_update .= " vf.krbarg.value='';\n";
- }
- if ($can_assign->{'int'}) {
- $auth_update .= " vf.intarg.value='';\n";
- }
- if ($can_assign->{'loc'}) {
- $auth_update .= " vf.locarg.value='';\n";
- }
- $auth_update .= "
- }\n";
}
return(< 1) {
+ if ($can_assign->{'krb4'} || $can_assign->{'krb5'}) {
+ $argreset .= " vf.krbarg.value='';\n";
+ $numbuttons ++ ;
+ }
+ if ($can_assign->{'int'}) {
+ $argreset .= " vf.intarg.value='';\n";
+ $numbuttons ++;
+ }
+ if ($can_assign->{'loc'}) {
+ $argreset .= " vf.locarg.value='';\n";
+ $numbuttons ++;
+ }
+ 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.');
+ $auth_update = <<"END";
+ // Currently the initial password field is only supported for internal auth
+ // (see bug 6368).
+ if (tf==8 && nw!=0) {
+ eval('vf.f'+tf+'.selectedIndex=0;')
+ alert('$warning');
+ }
+END
+ } elsif ($numbuttons > 1) {
$auth_update = <<"END";
// initial password specified, pick internal authentication
if (tf==8 && nw!=0) {
changed_radio('int',document.studentform);
set_auth_radio_buttons('int',document.studentform);
+$argreset
+ }
+
END
}
- if ($can_assign->{'krb'}) {
- $auth_update .= " vf.krbarg.value='';\n";
- }
- if ($can_assign->{'int'}) {
- $auth_update .= " vf.intarg.value='';\n";
- }
- if ($can_assign->{'loc'}) {
- $auth_update .= " vf.locarg.value='';\n";
- }
- $auth_update .= "
- }\n";
}
+
return(<print('
');
&print_upload_manager_footer($r,$i,$keyfields,$defdom,$today,$halfyear,
$context,$permission,$crstype);
}
@@ -1387,6 +1435,7 @@ sub curr_role_permissions {
sub my_custom_roles {
my ($crstype) = @_;
my %returnhash=();
+ my $extra = &Apache::lonnet::freeze_escape({'skipcheck' => 1});
my %rolehash=&Apache::lonnet::dump('roles');
foreach my $key (keys(%rolehash)) {
if ($key=~/^rolesdef\_(\w+)$/) {
@@ -1409,8 +1458,9 @@ sub print_userlist {
if ($env{'form.Status'} !~ /^(Any|Expired|Active|Future)$/) {
$env{'form.Status'} = 'Active';
}
+ my $onchange = "javascript:updateCols('Status');";
my $status_select = &Apache::lonhtmlcommon::StatusOptions
- ($env{'form.Status'});
+ ($env{'form.Status'},undef,undef,$onchange);
if ($env{'form.showrole'} eq '') {
if ($context eq 'course') {
@@ -1443,12 +1493,12 @@ sub print_userlist {
$r->print('');
return;
}
if (!(($context eq 'domain') &&
(($env{'form.roletype'} eq 'course') || ($env{'form.roletype'} eq 'community')))) {
- $r->print(
- "\n\n"
- .'
');
}
$r->rflush();
if ($context eq 'course') {
@@ -1650,21 +1705,23 @@ sub print_userlist {
}
}
if (keys(%userlist) == 0) {
+ my $msg = '';
if ($context eq 'author') {
- $r->print(&mt('There are no co-authors to display.')."\n");
+ $msg = &mt('There are no co-authors to display.');
} elsif ($context eq 'domain') {
if ($env{'form.roletype'} eq 'domain') {
- $r->print(&mt('There are no users with domain roles to display.')."\n");
+ $msg = &mt('There are no users with domain roles to display.');
} elsif ($env{'form.roletype'} eq 'author') {
- $r->print(&mt('There are no authors or co-authors to display.')."\n");
+ $msg = &mt('There are no authors or co-authors to display.');
} elsif ($env{'form.roletype'} eq 'course') {
- $r->print(&mt('There are no course users to display')."\n");
+ $msg = &mt('There are no course users to display');
} elsif ($env{'form.roletype'} eq 'community') {
- $r->print(&mt('There are no community users to display')."\n");
+ $msg = &mt('There are no community users to display');
}
} elsif ($context eq 'course') {
$r->print(&mt('There are no course users to display.')."\n");
}
+ $r->print('
'."\n") if $msg;
} else {
# Print out the available choices
my $usercount;
@@ -1676,7 +1733,7 @@ sub print_userlist {
$permission,$env{'form.Status'},\%userlist,$keylist);
}
if (!$usercount) {
- $r->print(' '
+ $r->print(' '
.&mt('There are no users matching the search criteria.')
.''
);
@@ -1684,6 +1741,7 @@ sub print_userlist {
}
$r->print('');
+ return;
}
sub role_filter {
@@ -1696,11 +1754,11 @@ sub role_filter {
my ($role_select);
if ($context eq 'domain') {
$role_select = &domain_roles_select();
- $output = '';
+ .'';
} else {
- $role_select = '
\n");
if ($counts{'role'} > 0) {
@@ -4324,7 +4483,7 @@ sub upfile_drop_add {
if (! defined($classlist)) {
$r->print(''.
''.
- &mt('There are no students with current/future access to the course.').
+ '
'.&mt('There are no students with current/future access to the course.').'
'.
''."\n");
} elsif (ref($classlist) eq 'HASH') {
# Remove the students we just added from the list of students.
@@ -4448,11 +4607,13 @@ sub print_drop_menu {
''."\n");
+ $r->print(
+ &Apache::lonhtmlcommon::actionbox(
+ [''.$linktext.''])
+ .''."\n");
}
sub dates_feedback {
@@ -4810,7 +4974,7 @@ sub dates_feedback {
my $dates;
if ($start < $now) {
if ($end == 0) {
- $dates .= &mt('role(s) active now; no end date');
+ $dates = &mt('role(s) active now; no end date');
} elsif ($end > $now) {
$dates = &mt('role(s) active now; ends [_1].',&Apache::lonlocal::locallocaltime($end));
} else {
@@ -5007,7 +5171,7 @@ sub setsections_javascript {
acor => 'A coordinator role will be added with access to all sections',
inea => 'In each course, each user may only have one student role at a time.',
inco => 'In each community, each user may only have one member role at a time.',
- youh => 'You had selected ',
+ youh => 'You had selected',
secs => 'sections.',
plmo => 'Please modify your selections so they include no more than one section.',
mayn => 'may not be used as the name for a section, as it is a reserved word.',
@@ -5227,18 +5391,40 @@ sub can_modify_userinfo {
}
sub check_usertype {
- my ($dom,$uname,$rules) = @_;
+ my ($dom,$uname,$rules,$curr_rules,$got_rules) = @_;
my $usertype;
- if (ref($rules) eq 'HASH') {
- my @user_rules = keys(%{$rules});
- if (@user_rules > 0) {
- my %rule_check = &Apache::lonnet::inst_rulecheck($dom,$uname,undef,'username',\@user_rules);
- if (keys(%rule_check) > 0) {
- $usertype = 'unofficial';
- foreach my $item (keys(%rule_check)) {
- if ($rule_check{$item}) {
- $usertype = 'official';
- last;
+ if ((ref($got_rules) eq 'HASH') && (ref($curr_rules) eq 'HASH')) {
+ if (!$got_rules->{$dom}) {
+ my %domconfig = &Apache::lonnet::get_dom('configuration',
+ ['usercreation'],$dom);
+ if (ref($domconfig{'usercreation'}) eq 'HASH') {
+ foreach my $item ('username','id') {
+ if (ref($domconfig{'usercreation'}{$item.'_rule'}) eq 'ARRAY') {
+ $curr_rules->{$dom}{$item} =
+ $domconfig{'usercreation'}{$item.'_rule'};
+ }
+ }
+ }
+ $got_rules->{$dom} = 1;
+ }
+ if (ref($rules) eq 'HASH') {
+ my @user_rules;
+ if (ref($curr_rules->{$dom}{'username'}) eq 'ARRAY') {
+ foreach my $rule (keys(%{$rules})) {
+ if (grep(/^\Q$rule\E/,@{$curr_rules->{$dom}{'username'}})) {
+ push(@user_rules,$rule);
+ }
+ }
+ }
+ if (@user_rules > 0) {
+ my %rule_check = &Apache::lonnet::inst_rulecheck($dom,$uname,undef,'username',\@user_rules);
+ if (keys(%rule_check) > 0) {
+ $usertype = 'unofficial';
+ foreach my $item (keys(%rule_check)) {
+ if ($rule_check{$item}) {
+ $usertype = 'official';
+ last;
+ }
}
}
}
@@ -5614,5 +5800,20 @@ sub authcheck_alerts {
return %alerts;
}
+sub is_courseowner {
+ my ($thiscourse,$courseowner) = @_;
+ if ($courseowner eq '') {
+ if ($env{'request.course.id'} eq $thiscourse) {
+ $courseowner = $env{'course.'.$env{'request.course.id'}.'.internal.courseowner'};
+ }
+ }
+ if ($courseowner ne '') {
+ if ($courseowner eq $env{'user.name'}.':'.$env{'user.domain'}) {
+ return 1;
+ }
+ }
+ return;
+}
+
1;