--- loncom/interface/lonuserutils.pm 2010/11/14 22:47:37 1.97.2.24
+++ loncom/interface/lonuserutils.pm 2011/08/05 14:46:58 1.136
@@ -1,7 +1,7 @@
# The LearningOnline Network with CAPA
# Utility functions for managing LON-CAPA user accounts
#
-# $Id: lonuserutils.pm,v 1.97.2.24 2010/11/14 22:47:37 raeburn Exp $
+# $Id: lonuserutils.pm,v 1.136 2011/08/05 14:46:58 raeburn Exp $
#
# Copyright Michigan State University Board of Trustees
#
@@ -1517,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"
.''
@@ -1528,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') {
@@ -1542,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".
@@ -1762,7 +1764,7 @@ sub role_filter {
$role_select .= '';
$output = ''
.&mt('Role: [_1]',$role_select)
- .' ';
+ .' ';
}
return $output;
}
@@ -1993,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);
@@ -2401,7 +2402,7 @@ END
END
if ($actionselect) {
$output .= <<"END";
-$lt{'ac'}
+
$lt{'ac'}
$actionselect
@@ -2446,7 +2447,7 @@ END
}
}
}
- $output .= '';
}
$output .= "\n".''."\n".
&Apache::loncommon::start_data_table().
@@ -2726,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());
@@ -2837,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});
@@ -2856,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');
@@ -3245,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);
@@ -3478,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') {
@@ -3742,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(
''
@@ -3877,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') {
@@ -3987,12 +3987,13 @@ sub upfile_drop_add {
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',
);
- map { $cancreate{$_} = &can_create_user($domain,$context,$_); } keys(%longtypes);
+ 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;
@@ -4019,6 +4020,7 @@ sub upfile_drop_add {
$gen=$entries{$fields{'gen'}};
}
}
+
if ($entries{$fields{'username'}}
ne &LONCAPA::clean_username($entries{$fields{'username'}})) {
my $nowhitespace;
@@ -4146,25 +4148,33 @@ sub upfile_drop_add {
my (%rulematch,%inst_results,%idinst_results);
my $uhome=&Apache::lonnet::homeserver($username,$userdomain);
if ($uhome eq 'no_host') {
- if ($userdomain ne $domain) {
- $r->print(' '.
- &mt('[_1]: The domain specified ([_2]) is different to that of the course.',
- ''.$username.' ',$userdomain).' '.
- &mt('The user does not already exist, and you may not create a new user in a different 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.':'.$domain;
+ 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') {
- 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.'));
@@ -4181,7 +4191,7 @@ sub upfile_drop_add {
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: $showtype.",''.$username.' '));
+ &mt('[_1]: The user does not exist, and you are not permitted to create users of type: [_2].',''.$username.' ',$showtype));
next;
}
} else {
@@ -4271,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) {
@@ -4677,7 +4687,7 @@ sub update_user_list {
if ($sec eq '') {
$nochg = 1;
$keepnosection = 1;
- } else {
+ } else {
push(@retained,$sec);
}
}
@@ -4706,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 {
@@ -4719,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 '') {
@@ -4735,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);
+
}
}
}
@@ -4788,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 ++;
@@ -5261,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;
+ }
}
}
}
@@ -5620,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',