--- loncom/interface/lonuserutils.pm 2010/11/13 01:29:34 1.97.2.20
+++ loncom/interface/lonuserutils.pm 2010/01/20 16:46:23 1.114
@@ -1,7 +1,7 @@
# The LearningOnline Network with CAPA
# Utility functions for managing LON-CAPA user accounts
#
-# $Id: lonuserutils.pm,v 1.97.2.20 2010/11/13 01:29:34 raeburn Exp $
+# $Id: lonuserutils.pm,v 1.114 2010/01/20 16:46:23 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);
@@ -1448,7 +1447,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"
.''
@@ -1459,7 +1458,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') {
@@ -1693,7 +1692,7 @@ sub role_filter {
$role_select .= '';
$output = ''
.&mt('Role: [_1]',$role_select)
- .' ';
+ .' ';
}
return $output;
}
@@ -2278,7 +2277,7 @@ END
push(@cols,'section');
}
if (!($context eq 'domain' && ($env{'form.roletype'} eq 'course')
- && ($env{'form.roletype'} eq 'community'))) {
+ && ($env{'form.roletype'} eq 'community'))) {
push(@cols,('start','end'));
}
if ($env{'form.showrole'} eq 'Any' || $env{'form.showrole'} eq 'cr') {
@@ -2289,7 +2288,7 @@ END
$env{'form.roletype'} eq 'community')) {
push (@cols,'extent');
}
- if (($statusmode eq 'Any') &&
+ if (($statusmode eq 'Any') &&
(!($context eq 'domain' && (($env{'form.roletype'} eq 'course')
|| ($env{'form.roletype'} eq 'community'))))) {
push(@cols,'status');
@@ -2310,7 +2309,6 @@ END
if ($mode ne 'autoenroll') {
$results_description = &results_header_row($rolefilter,$statusmode,
$context,$permission,$mode,$crstype);
-
$r->print(''.$results_description.' ');
}
my ($output,$actionselect,%canchange,%canchangesec);
@@ -2332,7 +2330,7 @@ END
END
if ($actionselect) {
$output .= <<"END";
-
$lt{'ac'}
+
$lt{'ac'}
$actionselect
@@ -2377,7 +2375,7 @@ END
}
}
}
- $output .= '';
}
$output .= "\n".''."\n".
&Apache::loncommon::start_data_table().
@@ -2657,7 +2656,7 @@ END
if ($clickers!~/\w/) { $clickers='-'; }
$in{'clicker'} = $clickers;
my $role = $in{'role'};
- $in{'role'}=&Apache::lonnet::plaintext($sdata->[$index{'role'}],$crstype);
+ $in{'role'}=&Apache::lonnet::plaintext($sdata->[$index{'role'}],$crstype);
if (! defined($in{'start'}) || $in{'start'} == 0) {
$in{'start'} = &mt('none');
} else {
@@ -3174,8 +3173,8 @@ ENDJS
my %lt = &Apache::lonlocal::texthash (
chac => 'Access dates to apply for selected users',
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.',
+ 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 role in a course that is not a student role, a user may have roles in more than one section of a course at a time.',
reta => "Retain each user's current section affiliations?",
dnap => '(Does not apply to student roles).',
);
@@ -3194,13 +3193,13 @@ ENDJS
$permission,$crstype);
}
$output .= ''.$headertext.' '.
- ' '."\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(
''
@@ -3808,7 +3813,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') {
@@ -3924,7 +3929,6 @@ sub upfile_drop_add {
my @secs;
my %entries=&Apache::loncommon::record_sep($line);
# Determine user name
- $entries{$fields{'username'}} =~ s/^\s+|\s+$//g;
unless (($entries{$fields{'username'}} eq '') ||
(!defined($entries{$fields{'username'}}))) {
my ($fname, $mname, $lname,$gen) = ('','','','');
@@ -3947,17 +3951,11 @@ sub upfile_drop_add {
}
if ($entries{$fields{'username'}}
ne &LONCAPA::clean_username($entries{$fields{'username'}})) {
- my $nowhitespace;
- if ($entries{$fields{'username'}} =~ /\s/) {
- $nowhitespace = ' - '.&mt('usernames may not contain spaces.');
- }
$r->print(' '.
&mt('[_1]: Unacceptable username for user [_2] [_3] [_4] [_5]',
- ''.$entries{$fields{'username'}}.' ',$fname,$mname,$lname,$gen).
- $nowhitespace);
+ ''.$entries{$fields{'username'}}.' ',$fname,$mname,$lname,$gen));
next;
} else {
- $entries{$fields{'domain'}} =~ s/^\s+|\s+$//g;
if ($entries{$fields{'domain'}}
ne &LONCAPA::clean_domain($entries{$fields{'domain'}})) {
$r->print(' '. ''.$entries{$fields{'domain'}}.
@@ -4016,7 +4014,6 @@ sub upfile_drop_add {
# determine email address
my $email='';
if (defined($fields{'email'})) {
- $entries{$fields{'email'}} =~ s/^\s+|\s+$//g;
if (defined($entries{$fields{'email'}})) {
$email=$entries{$fields{'email'}};
unless ($email=~/^[^\@]+\@[^\@]+$/) { $email=''; }
@@ -4063,7 +4060,7 @@ sub upfile_drop_add {
$role = $defaultrole;
}
# Clean up whitespace
- foreach (\$id,\$fname,\$mname,\$lname,\$gen,\$inststatus) {
+ foreach (\$id,\$fname,\$mname,\$lname,\$gen) {
$$_ =~ s/(\s+$|^\s+)//g;
}
# check against rules
@@ -4168,7 +4165,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) {
@@ -4395,9 +4392,10 @@ sub print_drop_menu {
# ================================================================== Phase four
sub update_user_list {
- my ($r,$context,$setting,$choice,$crstype) = @_;
+ my ($r,$context,$setting,$choice) = @_;
my $now = time;
my $count=0;
+ my $crstype;
if ($context eq 'course') {
$crstype = &Apache::loncommon::course_type();
}
@@ -4412,7 +4410,7 @@ sub update_user_list {
'reenable' => 'Re-enabled',
'activate' => 'Activated',
'chgdates' => 'Changed Access Dates for',
- 'chgsec' => 'Changed section(s) for',
+ 'chgsec' => 'Changed section for',
'drop' => 'Dropped',
},
error => {'revoke' => 'revoking',
@@ -4429,9 +4427,8 @@ sub update_user_list {
($startdate,$enddate) = &get_dates_from_form();
}
foreach my $item (@changelist) {
- my ($role,$uname,$udom,$cid,$sec,$scope,$result,$type,$locktype,
- @sections,$scopestem,$singlesec,$showsecs,$warn_singlesec,
- $nothingtodo,$keepnosection);
+ my ($role,$uname,$udom,$cid,$sec,$scope,$result,$type,$locktype,@sections,
+ $scopestem);
if ($choice eq 'drop') {
($uname,$udom,$sec) = split(/:/,$item,-1);
$role = 'st';
@@ -4530,23 +4527,14 @@ sub update_user_list {
} elsif ($choice eq 'chgsec') {
my (@newsecs,$revresult,$nochg,@retained);
if (($role ne 'cc') && ($role ne 'co')) {
- my @secs = sort(split(/,/,$env{'form.newsecs'}));
- if (@secs) {
- my %curr_groups = &Apache::longroup::coursegroups();
- foreach my $sec (@secs) {
- next if (($sec =~ /\W/) || ($sec eq 'none') ||
- (exists($curr_groups{$sec})));
- push(@newsecs,$sec);
- }
- }
+ @newsecs = split(/,/,$env{'form.newsecs'});
}
# remove existing section if not to be retained.
- if (!$env{'form.retainsec'} || ($role eq 'st')) {
+ if (!$env{'form.retainsec'}) {
if ($sec eq '') {
if (@newsecs == 0) {
- $result = 'ok';
+ $result = &mt('No change in section assignment (none)');
$nochg = 1;
- $nothingtodo = 1;
} else {
$revresult =
&Apache::lonnet::revokerole($udom,$uname,
@@ -4573,23 +4561,13 @@ sub update_user_list {
} else {
if ($sec eq '') {
$nochg = 1;
- $keepnosection = 1;
} else {
push(@retained,$sec);
}
}
# add new sections
- my (@diffs,@shownew);
- if (@retained) {
- @diffs = &Apache::loncommon::compare_arrays(\@retained,\@newsecs);
- } else {
- @diffs = @newsecs;
- }
if (@newsecs == 0) {
- if ($nochg) {
- $result = 'ok';
- $nothingtodo = 1;
- } else {
+ if (!$nochg) {
if ($role eq 'st') {
$result =
&Apache::lonnet::modify_student_enrollment($udom,$uname,undef,undef,undef,undef,undef,undef,$end,$start,$type,$locktype,$cid,'',$context);
@@ -4598,41 +4576,15 @@ sub update_user_list {
$result = &Apache::lonnet::assignrole($udom,$uname,$newscope,$role,$end,$start,'','',$context);
}
}
- $showsecs = &mt('No section');
- } elsif (@diffs == 0) {
- $result = 'ok';
- $nothingtodo = 1;
} else {
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;
- if ($newsec eq '') {
- $showsingle = &mt('No section');
- } else {
- $showsingle = $newsec;
- }
- 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 {
- $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;
- last;
- } else {
- if ($newsec eq '') {
- $showsecs = &mt('No section');
- } else {
- $showsecs = $newsec;
- }
- }
} else {
my $newscope = $scopestem;
if ($newsec ne '') {
$newscope .= '/'.$newsec;
- push(@shownew,$newsec);
}
$result = &Apache::lonnet::assignrole($udom,$uname,
$newscope,$role,$end,$start);
@@ -4640,15 +4592,6 @@ sub update_user_list {
}
}
}
- unless ($role eq 'st') {
- unless ($showsecs) {
- my @tolist = sort(@shownew,@retained);
- if ($keepnosection) {
- push(@tolist,&mt('No section'));
- }
- $showsecs = join(', ',@tolist);
- }
- }
}
}
my $extent = $scope;
@@ -4659,48 +4602,13 @@ sub update_user_list {
}
}
if ($result eq 'ok' || $result eq 'ok:') {
- my $dates;
- if (($choice eq 'chgsec') || ($choice eq 'chgdates')) {
- $dates = &dates_feedback($start,$end,$now);
- }
- if ($choice eq 'chgsec') {
- if ($nothingtodo) {
- $r->print(&mt("Section assignment for role of '[_1]' in [_2] for '[_3]' unchanged.",$plrole,$extent,''.
- &Apache::loncommon::plainname($uname,$udom).
- ' ').' ');
- if ($sec eq '') {
- $r->print(&mt('[_1]No section[_2] - [_3]','',' ',$dates));
- } else {
- $r->print(&mt('Section(s): [_1] - [_2]',
- ''.$showsecs.' ',$dates));
- }
- $r->print(' ');
- } else {
- $r->print(&mt("$result_text{'ok'}{$choice} role of '[_1]' in [_2] for '[_3]' to [_4] - [_5]",$plrole,$extent,
- ''.&Apache::loncommon::plainname($uname,$udom).' ',
- ''.$showsecs.' ',$dates).' ');
- $count ++;
- }
- if ($warn_singlesec) {
- $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,
- ''.&Apache::loncommon::plainname($uname,$udom).' ',
- $dates).' ');
- $count ++;
- } else {
- $r->print(&mt("$result_text{'ok'}{$choice} role of '[_1]' in [_2] for '[_3]'.",$plrole,$extent,
- ''.&Apache::loncommon::plainname($uname,$udom).' ').
- ' ');
- $count ++;
- }
+ $r->print(&mt("$result_text{'ok'}{$choice} role of '[_1]' in [_2] for [_3]",
+ $plrole,$extent,$uname.':'.$udom).' ');
+ $count++;
} else {
$r->print(
- &mt("Error $result_text{'error'}{$choice} [_1] in [_2] for '[_3]': [_4].",
- $plrole,$extent,
- ''.&Apache::loncommon::plainname($uname,$udom).' ',
- $result).' ');
+ &mt("Error $result_text{'error'}{$choice} [_1] in [_2] for [_3]: [_4].",
+ $plrole,$extent,$uname.':'.$udom,$result).' ');
}
}
$r->print(''."\n");
}
-sub dates_feedback {
- my ($start,$end,$now) = @_;
- my $dates;
- if ($start < $now) {
- if ($end == 0) {
- $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 {
- $dates = &mt('role(s) expired: [_1].',&Apache::lonlocal::locallocaltime($end));
- }
- } else {
- if ($end == 0 || $end > $now) {
- $dates = &mt('future role(s); starts: [_1].',&Apache::lonlocal::locallocaltime($start));
- } else {
- $dates = &mt('role(s) expired: [_1].',&Apache::lonlocal::locallocaltime($end));
- }
- }
- return $dates;
-}
-
sub classlist_drop {
my ($scope,$uname,$udom,$now) = @_;
my ($cdom,$cnum) = ($scope=~m{^/($match_domain)/($match_courseid)});
@@ -4937,7 +4824,7 @@ sub setsections_javascript {
accr => 'A course coordinator role will be added with access to all sections.',
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.',
- inec => 'In each community, each user may only have one member role at a time.',
+ inec => 'In each community, each user may only have on member role at a time.',
youh => 'You had selected ',
secs => 'sections.',
plmo => 'Please modify your selections so they include no more than one section.',
@@ -4952,14 +4839,11 @@ sub setsections_javascript {
function setSections(formname,crstype) {
var re1 = /^currsec_/;
var re2 =/\\W/;
- var trimleading = /^\\s+/;
- var trimtrailing = /\\s+\$/;
var groups = new Array($groupslist);
for (var i=0;i 0) {
+ if (formname.elements[i+1].value != "" && formname.elements[i+1].value != null) {
+ sections = sections + "," + formname.elements[i+1].value;
+ }
+ }
+ else {
+ sections = formname.elements[i+1].value;
+ }
+ var newsecs = formname.elements[i+1].value;
+ var numsplit;
var validsecs = new Array();
- var validsecstr = '';
var badsecs = new Array();
if (newsecs != null && newsecs != "") {
- var numsplit;
- if (newsecs.indexOf(',') == -1) {
- numsplit = new Array(newsecs);
- } else {
- numsplit = newsecs.split(/,/g);
- }
- for (var m=0; m 0) {
@@ -5025,6 +4899,7 @@ function setSections(formname,crstype) {
}
numsec = numsec + validsecs.length;
}
+
if ((role == 'st') && (numsec > 1)) {
if (crstype == 'Community') {
alert("$alerts{'inea'} $alerts{'youh'} "+numsec+" $alerts{'secs'}\\n$alerts{'plmo'}");
@@ -5032,36 +4907,25 @@ function setSections(formname,crstype) {
alert("$alerts{'inco'} $alerts{'youh'} "+numsec+" $alerts{'secs'}\\n$alerts{'plmo'}");
}
return;
- } else {
- if (validsecs != null) {
- for (var j=0; j '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',