--- loncom/interface/lonuserutils.pm 2010/11/14 22:47:37 1.97.2.24
+++ loncom/interface/lonuserutils.pm 2010/01/14 18:06:14 1.111
@@ -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.111 2010/01/14 18:06:14 bisitz 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);
@@ -296,8 +295,7 @@ sub hidden_input {
}
sub print_upload_manager_header {
- my ($r,$datatoken,$distotal,$krbdefdom,$context,$permission,$crstype,
- $can_assign)=@_;
+ my ($r,$datatoken,$distotal,$krbdefdom,$context,$permission,$crstype)=@_;
my $javascript;
#
if (! exists($env{'form.upfile_associate'})) {
@@ -311,9 +309,9 @@ sub print_upload_manager_header {
}
}
if ($env{'form.upfile_associate'} eq 'reverse') {
- $javascript=&upload_manager_javascript_reverse_associate($can_assign);
+ $javascript=&upload_manager_javascript_reverse_associate();
} else {
- $javascript=&upload_manager_javascript_forward_associate($can_assign);
+ $javascript=&upload_manager_javascript_forward_associate();
}
#
# Deal with restored settings
@@ -534,7 +532,6 @@ END
if (message!='') {
message+='\\n';
}
- message+='$alert{'section'}';
}
if (foundemail==0) {
if (message!='') {
@@ -588,46 +585,6 @@ END
###############################################################
###############################################################
sub upload_manager_javascript_forward_associate {
- my ($can_assign) = @_;
- my ($auth_update,$numbuttons,$argreset);
- if (ref($can_assign) eq 'HASH') {
- 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
- }
- }
-
return(<{'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
- }
- }
-
return(<=2) && (tf<=5) && (nw!=0)) {
eval('vf.f1.selectedIndex=0;')
}
- $auth_update
+ // 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='';
+ }
}
function clearpwd(vf) {
@@ -1047,9 +978,8 @@ sub print_upload_manager_form {
my ($krbdef,$krbdefdom) =
&Apache::loncommon::get_kerberos_defaults($defdom);
#
- my ($authnum,%can_assign) = &Apache::loncommon::get_assignable_auth($defdom);
&print_upload_manager_header($r,$datatoken,$distotal,$krbdefdom,$context,
- $permission,$crstype,\%can_assign);
+ $permission,$crstype);
my $i;
my $keyfields;
if ($total>=0) {
@@ -1517,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"
.'
'
@@ -1528,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') {
@@ -1762,7 +1692,7 @@ sub role_filter {
$role_select .= '';
$output = '';
+ .' ';
}
return $output;
}
@@ -1802,7 +1732,7 @@ sub section_group_filter {
}
if (@options > 0) {
my $currsel;
- $markup = '
\n");
if ($counts{'role'} > 0) {
@@ -4498,9 +4393,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();
}
@@ -4515,7 +4411,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',
@@ -4532,9 +4428,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';
@@ -4633,23 +4528,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,
@@ -4676,23 +4562,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);
@@ -4701,41 +4577,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);
@@ -4743,15 +4593,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;
@@ -4762,48 +4603,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)});
@@ -5040,7 +4825,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.',
- inco => '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.',
@@ -5048,21 +4833,16 @@ sub setsections_javascript {
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.',
- nonw => 'Section names may only contain letters or numbers.',
);
$setsection_js .= <<"ENDSECCODE";
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) {
- alert("$alerts{'nonw'}\\n$alerts{'plch'}");
- return;
+ }
+ if (numsec > 0) {
+ if (formname.elements[i+1].value != "" && formname.elements[i+1].value != null) {
+ sections = sections + "," + formname.elements[i+1].value;
}
- numsec = numsec + validsecs.length;
}
+ else {
+ sections = formname.elements[i+1].value;
+ }
+ var newsecs = formname.elements[i+1].value;
+ var numsplit;
+ if (newsecs != null && newsecs != "") {
+ numsplit = newsecs.split(/,/g);
+ numsec = numsec + numsplit.length;
+ }
+
if ((role == 'st') && (numsec > 1)) {
if (crstype == 'Community') {
alert("$alerts{'inea'} $alerts{'youh'} "+numsec+" $alerts{'secs'}\\n$alerts{'plmo'}");
@@ -5135,36 +4893,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',