--- loncom/interface/lonuserutils.pm 2010/11/14 21:19:08 1.97.2.22
+++ loncom/interface/lonuserutils.pm 2012/04/25 21:22:01 1.138
@@ -1,7 +1,7 @@
# The LearningOnline Network with CAPA
# Utility functions for managing LON-CAPA user accounts
#
-# $Id: lonuserutils.pm,v 1.97.2.22 2010/11/14 21:19:08 raeburn Exp $
+# $Id: lonuserutils.pm,v 1.138 2012/04/25 21:22:01 raeburn Exp $
#
# Copyright Michigan State University Board of Trustees
#
@@ -47,8 +47,7 @@ sub modifystudent {
# this one. If $csec is defined, drop them from all other sections of
# this course and add them to section $csec
my ($cnum,$cdom) = &get_course_identity($courseid);
- my $extra = &Apache::lonnet::freeze_escape({'skipcheck' => 1});
- my %roles = &Apache::lonnet::dump('roles',$udom,$unam,'.',undef,$extra);
+ my %roles = &Apache::lonnet::dump('roles',$udom,$unam);
my ($tmp) = keys(%roles);
# Bail out if we were unable to get the students roles
return "$1" if ($tmp =~ /^(con_lost|error|no_such_host)/i);
@@ -802,14 +801,6 @@ function flip(vf,tf) {
if ((tf>=2) && (tf<=5) && (nw!=0)) {
eval('vf.f1.selectedIndex=0;')
}
- // intial password specified, pick internal authentication
- if (tf==8 && nw!=0) {
- changed_radio('int',document.studentform);
- set_auth_radio_buttons('int',document.studentform);
- vf.krbarg.value='';
- vf.intarg.value='';
- vf.locarg.value='';
- }
$auth_update
}
@@ -1430,6 +1421,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+)$/) {
@@ -1525,7 +1517,7 @@ sub print_userlist {
return;
}
if (!(($context eq 'domain') &&
- (($env{'form.roletype'} eq 'course') || ($env{'form.roletype'} eq 'community')))) {
+ (($env{'form.roletype'} eq 'course') || ($env{'form.roletype'} eq 'community')))) {
$r->print(
"\n
\n"
.''
@@ -1536,7 +1528,7 @@ sub print_userlist {
my ($indexhash,$keylist) = &make_keylist_array();
my (%userlist,%userinfo,$clearcoursepick);
if (($context eq 'domain') &&
- ($env{'form.roletype'} eq 'course') ||
+ ($env{'form.roletype'} eq 'course') ||
($env{'form.roletype'} eq 'community')) {
my ($crstype,$numcodes,$title,$warning);
if ($env{'form.roletype'} eq 'course') {
@@ -1550,9 +1542,11 @@ sub print_userlist {
$title = &mt('Select Communities');
$warning = &mt('Warning: data retrieval for multiple communities can take considerable time, as this operation is not currently optimized.');
}
+ my @standardnames = &Apache::loncommon::get_standard_codeitems();
my $courseform =
&Apache::lonhtmlcommon::course_selection($formname,$numcodes,
- $codetitles,$idlist,$idlist_titles,$crstype);
+ $codetitles,$idlist,$idlist_titles,$crstype,
+ \@standardnames);
$r->print('
'.&Apache::lonhtmlcommon::start_pick_box()."\n".
&Apache::lonhtmlcommon::start_pick_box()."\n".
&Apache::lonhtmlcommon::row_title($title,'LC_oddrow_value')."\n".
@@ -1770,7 +1764,7 @@ sub role_filter {
$role_select .= '';
$output = ''
.&mt('Role: [_1]',$role_select)
- .' ';
+ .' ';
}
return $output;
}
@@ -2001,7 +1995,7 @@ function setCourseCat(formname) {
if (formname.Year.options[formname.Year.selectedIndex].value == -1) {
return;
}
- courseSet('Year');
+ courseSet('$codetitles[0]');
for (var j=0; jprint(''.$results_description.' ');
}
my ($output,$actionselect,%canchange,%canchangesec);
@@ -2409,7 +2402,7 @@ END
END
if ($actionselect) {
$output .= <<"END";
-$lt{'ac'}
+
$lt{'ac'}
$actionselect
@@ -2454,7 +2447,7 @@ END
}
}
}
- $output .= '';
}
$output .= "\n".''."\n".
&Apache::loncommon::start_data_table().
@@ -2734,16 +2728,18 @@ END
if ($clickers!~/\w/) { $clickers='-'; }
$in{'clicker'} = $clickers;
my $role = $in{'role'};
- $in{'role'}=&Apache::lonnet::plaintext($sdata->[$index{'role'}],$crstype);
- if (! defined($in{'start'}) || $in{'start'} == 0) {
- $in{'start'} = &mt('none');
- } else {
- $in{'start'} = &Apache::lonlocal::locallocaltime($in{'start'});
- }
- if (! defined($in{'end'}) || $in{'end'} == 0) {
- $in{'end'} = &mt('none');
- } else {
- $in{'end'} = &Apache::lonlocal::locallocaltime($in{'end'});
+ $in{'role'}=&Apache::lonnet::plaintext($sdata->[$index{'role'}],$crstype);
+ unless ($mode eq 'excel') {
+ if (! defined($in{'start'}) || $in{'start'} == 0) {
+ $in{'start'} = &mt('none');
+ } else {
+ $in{'start'} = &Apache::lonlocal::locallocaltime($in{'start'});
+ }
+ if (! defined($in{'end'}) || $in{'end'} == 0) {
+ $in{'end'} = &mt('none');
+ } else {
+ $in{'end'} = &Apache::lonlocal::locallocaltime($in{'end'});
+ }
}
if ($mode eq 'view' || $mode eq 'html' || $mode eq 'autoenroll' || $mode eq 'pickauthor') {
$r->print(&Apache::loncommon::start_data_table_row());
@@ -2845,16 +2841,6 @@ END
} elsif ($mode eq 'csv') {
next if (! defined($CSVfile));
# no need to bother with $linkto
- if (! defined($in{'start'}) || $in{'start'} == 0) {
- $in{'start'} = &mt('none');
- } else {
- $in{'start'} = &Apache::lonlocal::locallocaltime($in{'start'});
- }
- if (! defined($in{'end'}) || $in{'end'} == 0) {
- $in{'end'} = &mt('none');
- } else {
- $in{'end'} = &Apache::lonlocal::locallocaltime($in{'end'});
- }
my @line = ();
foreach my $item (@cols) {
push @line,&Apache::loncommon::csv_translate($in{$item});
@@ -2864,9 +2850,9 @@ END
my $col = 0;
foreach my $item (@cols) {
if ($item eq 'start' || $item eq 'end') {
- if (defined($item) && $item != 0) {
+ if ((defined($in{$item})) && ($in{$item} != 0)) {
$excel_sheet->write($row,$col++,
- &Apache::lonstathelpers::calc_serial($in{item}),
+ &Apache::lonstathelpers::calc_serial($in{$item}),
$format->{'date'});
} else {
$excel_sheet->write($row,$col++,'none');
@@ -3253,7 +3239,7 @@ ENDJS
chse => 'Changes in section affiliation to apply to selected users',
fors => 'For student roles, changing the section will result in a section switch as students may only be in one section of a course at a time.',
forn => 'For a course role that is not "student", users may have roles in more than one section at a time.',
- reta => "Retain each user's current section affiliations?",
+ reta => "Retain each user's current section affiliations?",
dnap => '(Does not apply to student roles).',
);
my ($date_items,$headertext);
@@ -3486,7 +3472,6 @@ sub results_header_row {
}
} elsif (($env{'form.roletype'} eq 'course') ||
($env{'form.roletype'} eq 'community')) {
-
my $coursefilter = $env{'form.coursepick'};
if ($env{'form.roletype'} eq 'course') {
if ($coursefilter eq 'category') {
@@ -3750,8 +3735,15 @@ sub print_first_users_upload_form {
&mt("How do I create a CSV file from a spreadsheet"))
.' '."\n";
$str .= &Apache::lonhtmlcommon::start_pick_box()
- .&Apache::lonhtmlcommon::row_title(&mt('File'))
- .&Apache::loncommon::upfile_select_html()
+ .&Apache::lonhtmlcommon::row_title(&mt('File'));
+ if (&Apache::lonlocal::current_language() ne 'en') {
+ if ($context eq 'course') {
+ $str .= ''."\n"
+ .&mt('Please upload an UTF8 encoded file to ensure a correct character encoding in your classlist.')."\n"
+ .'
'."\n";
+ }
+ }
+ $str .= &Apache::loncommon::upfile_select_html()
.&Apache::lonhtmlcommon::row_closure()
.&Apache::lonhtmlcommon::row_title(
''
@@ -3885,7 +3877,7 @@ sub upfile_drop_add {
} elsif ($setting eq 'course') {
$defaultrole = $env{'form.courserole'};
$defaultsec = $env{'form.sections'};
- }
+ }
} elsif ($context eq 'author') {
$defaultrole = $env{'form.defaultrole'};
} elsif ($context eq 'course') {
@@ -3992,10 +3984,16 @@ sub upfile_drop_add {
$r->print($groupwarn.' ');
}
}
- my (%curr_rules,%got_rules,%alerts);
+ my (%curr_rules,%got_rules,%alerts,%cancreate);
my %customroles = &my_custom_roles($crstype);
my @permitted_roles =
- &roles_on_upload($context,$setting,$crstype,%customroles);
+ &roles_on_upload($context,$setting,$crstype,%customroles);
+ my %longtypes = &Apache::lonlocal::texthash(
+ official => 'Institutional',
+ unofficial => 'Non-institutional',
+ );
+ my $newuserdom = $env{'request.role.domain'};
+ map { $cancreate{$_} = &can_create_user($newuserdom,$context,$_); } keys(%longtypes);
# Get new users list
foreach my $line (@userdata) {
my @secs;
@@ -4022,6 +4020,7 @@ sub upfile_drop_add {
$gen=$entries{$fields{'gen'}};
}
}
+
if ($entries{$fields{'username'}}
ne &LONCAPA::clean_username($entries{$fields{'username'}})) {
my $nowhitespace;
@@ -4149,20 +4148,52 @@ sub upfile_drop_add {
my (%rulematch,%inst_results,%idinst_results);
my $uhome=&Apache::lonnet::homeserver($username,$userdomain);
if ($uhome eq 'no_host') {
- next if ($userdomain ne $domain);
+ 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).' ');
+ } elsif ($context eq 'author') {
+ $r->print(&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).' ');
+ }
+ $r->print(&mt('The user does not already exist, and you may not create a new user in a different domain.'));
+ next;
+ }
$checkid = 1;
$newuser = 1;
+ my $user = $username.':'.$newuserdom;
my $checkhash;
my $checks = { 'username' => 1 };
- $checkhash->{$username.':'.$domain} = { 'newuser' => 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'}{$domain}) eq 'HASH') {
- next if ($alerts{'username'}{$domain}{$username});
+ 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;
+ }
} else {
if ($context eq 'course' || $context eq 'author') {
if ($userdomain eq $domain ) {
@@ -4213,7 +4244,12 @@ sub upfile_drop_add {
\%got_rules);
if (ref($alerts{'id'}) eq 'HASH') {
if (ref($alerts{'id'}{$userdomain}) eq 'HASH') {
- next if ($alerts{'id'}{$userdomain}{$id});
+ 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.',
+ ''.$username.' ').' '.
+ &mt('Consequently, the user was not created.'));
+ next;
+ }
}
}
}
@@ -4245,7 +4281,7 @@ sub upfile_drop_add {
$role = 'cr_'.$env{'user.domain'}.'_'.
$env{'user.name'}.'_'.$role;
}
- if (($role ne 'cc') && ($role ne 'co')) {
+ if (($role ne 'cc') && ($role ne 'co')) {
if (@secs > 1) {
$multiple = 1;
foreach my $sec (@secs) {
@@ -4651,7 +4687,7 @@ sub update_user_list {
if ($sec eq '') {
$nochg = 1;
$keepnosection = 1;
- } else {
+ } else {
push(@retained,$sec);
}
}
@@ -4680,12 +4716,12 @@ sub update_user_list {
$result = 'ok';
$nothingtodo = 1;
} else {
- foreach my $newsec (@newsecs) {
+ 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);
if (@newsecs > 1) {
- my $showsingle;
+ my $showsingle;
if ($newsec eq '') {
$showsingle = &mt('No section');
} else {
@@ -4693,10 +4729,10 @@ sub update_user_list {
}
if ($crstype eq 'Community') {
$warn_singlesec = &mt('Although more than one section was indicated, a role was only added for the first section - [_1], as each community member may only be in one section at a time.',''.$showsingle.' ');
- } else {
+ } else {
$warn_singlesec = &mt('Although more than one section was indicated, a role was only added for the first section - [_1], as each student may only be in one section of a course at a time.',''.$showsingle.' ');
}
- $showsecs = $showsingle;
+ $showsecs = $showsingle;
last;
} else {
if ($newsec eq '') {
@@ -4709,10 +4745,11 @@ sub update_user_list {
my $newscope = $scopestem;
if ($newsec ne '') {
$newscope .= '/'.$newsec;
- push(@shownew,$newsec);
+ push(@shownew,$newsec);
}
$result = &Apache::lonnet::assignrole($udom,$uname,
$newscope,$role,$end,$start);
+
}
}
}
@@ -4762,7 +4799,7 @@ sub update_user_list {
$r->print(''.$warn_singlesec.'
');
}
} elsif ($choice eq 'chgdates') {
- $r->print(&mt("$result_text{'ok'}{$choice} role of '[_1]' in [_2] for '[_3]' - [_4]",$plrole,$extent,
+ $r->print(&mt("$result_text{'ok'}{$choice} role of '[_1]' in [_2] for '[_3]' - [_4]",$plrole,$extent,
''.&Apache::loncommon::plainname($uname,$udom).' ',
$dates).' ');
$count ++;
@@ -5235,18 +5272,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;
+ }
}
}
}
@@ -5594,7 +5653,7 @@ sub sectioncheck_alerts {
my %alerts = &Apache::lonlocal::texthash(
curd => 'You must select a course or community in the current domain',
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',
+ inco => 'In each community, each user may only have one member role at a time',
youh => 'You had selected',
sect => 'sections',
plsm => 'Please modify your selections so they include no more than one section',