--- loncom/interface/lonuserutils.pm 2007/12/22 00:47:25 1.23
+++ loncom/interface/lonuserutils.pm 2007/12/26 14:38:13 1.36
@@ -1,7 +1,7 @@
# The LearningOnline Network with CAPA
# Utility functions for managing LON-CAPA user accounts
#
-# $Id: lonuserutils.pm,v 1.23 2007/12/22 00:47:25 raeburn Exp $
+# $Id: lonuserutils.pm,v 1.36 2007/12/26 14:38:13 raeburn Exp $
#
# Copyright Michigan State University Board of Trustees
#
@@ -304,7 +304,7 @@ sub print_upload_manager_header {
my $javascript_validations =
&javascript_validations('upload',$krbdefdom,$password_choice,undef,
$env{'request.role.domain'},$context,
- $permission,$groupslist);
+ $groupslist);
my $checked=(($env{'form.noFirstLine'})?' checked="checked" ':'');
$r->print(&mt('Total number of records found in file: [_1].',$distotal).
" \n");
@@ -332,7 +332,7 @@ sub print_upload_manager_header {
###############################################################
sub javascript_validations {
my ($mode,$krbdefdom,$curr_authtype,$curr_authfield,$domain,
- $context,$permission,$groupslist)=@_;
+ $context,$groupslist)=@_;
my %param = (
kerb_def_dom => $krbdefdom,
@@ -738,13 +738,13 @@ sub print_upload_manager_footer {
}
if ($context eq 'author') {
$Str .= '
'.&mt('Default role')."
\n".
- &mt('Choose the role to assign to users without one specified in the uploaded file');
+ &mt('Choose the role to assign to users without a value specified in the uploaded file');
} elsif ($context eq 'course') {
$Str .= '
'.&mt('Default role and section')."
\n".
- &mt('Choose the role and/or section to assign to users without one specified in the uploaded file');
+ &mt('Choose the role and/or section(s) to assign to users without values specified in the uploaded file');
} else {
- $Str .= '
'.&mt('Default role and/or section')." \n".
- &mt('Role and/or section for users without one in the uploaded file.');
+ $Str .= '
'.&mt('Default role and/or section(s)')." \n".
+ &mt('Role and/or section(s) for users without values specified in the uploaded file.');
}
$Str .= ' ';
if (($context eq 'domain') || ($context eq 'author')) {
@@ -761,8 +761,7 @@ sub print_upload_manager_footer {
$permission,$context,'upload');
$Str .= $secbox."
".&mt('Full Update')."
\n".
'\n";
+ ' '.&mt('Display students with current/future access who are not in the uploaded file.').' '.&mt('Students selected from this list can be dropped.').''."\n";
}
if ($context eq 'course' || $context eq 'domain') {
$Str .= &forceid_change($context);
@@ -786,13 +785,14 @@ sub forceid_change {
"
\n".' '."\n".
- &mt('(only do if you know what you are doing.)')." \n";
+ &mt('(only do if you know what you are doing.)')."\n";
if ($context eq 'domain') {
- $output .= '
'."\n";
+ ''."\n";
}
+ $output .= '';
return $output;
}
@@ -962,7 +962,7 @@ sub date_setting_table {
($env{'form.action'} eq 'upload')) {
if ($env{'request.course.sec'} eq '') {
$dateDefault = ''.
- '';
}
@@ -1001,14 +1001,14 @@ sub make_dates_default {
{'default_enrollment_start_date'=>$startdate,
'default_enrollment_end_date' =>$enddate},$cdom,$cnum);
if ($put_result eq 'ok') {
- $result .= &mt('Set default start and end dates for course').
+ $result .= &mt('Set default start and end access dates for course.').
' '."\n";
#
# Refresh the course environment
&Apache::lonnet::coursedescription($env{'request.course.id'},
{'freshen_cache' => 1});
} else {
- $result .= &mt('Unable to set default dates for course').":".$put_result.
+ $result .= &mt('Unable to set default access dates for course.').":".$put_result.
' ';
}
}
@@ -1263,7 +1263,7 @@ sub print_userlist {
if ($env{'form.showrole'} eq 'Any') {
$roleselected = ' selected="selected" ';
}
- my $role_select;
+ my ($role_select,$cnum,$cdom);
if ($context eq 'domain') {
$role_select = &domain_roles_select();
$r->print(''.&mt('Role Type: [_1]',$role_select).'');
@@ -1287,9 +1287,14 @@ sub print_userlist {
}
$role_select .= '';
$r->print(''.&mt('Role: [_1]',$role_select).'');
+ if ($context eq 'course') {
+ ($cnum,$cdom) = &get_course_identity();
+ $r->print(§ion_group_filter($cnum,$cdom));
+ }
}
if (!(($context eq 'domain') && ($env{'form.roletype'} eq 'course'))) {
- $r->print(&list_submit_button(&mt('Update Display'))."\n\n");
+ $r->print(' '.&list_submit_button(&mt('Update Display')).
+ "\n\n");
}
my ($indexhash,$keylist) = &make_keylist_array();
my (%userlist,%userinfo);
@@ -1305,7 +1310,7 @@ sub print_userlist {
&Apache::lonhtmlcommon::row_closure(1).
&Apache::lonhtmlcommon::end_pick_box().''.
'
\n");
+ "\n".''.&mt('Warning: data retrieval for multiple courses can take considerable time, as this operation is not currently optimized.').''."\n");
if ($env{'form.coursepick'}) {
$r->print(''.&mt('Searching').' ...
');
}
@@ -1329,8 +1334,6 @@ sub print_userlist {
$userlist{$student} = $classlist->{$student};
}
}
- my $cid = $env{'request.course.id'};
- my ($cnum,$cdom) = &get_course_identity($cid);
my $showroles;
if ($env{'form.showrole'} ne 'Any') {
$showroles = [$env{'form.showrole'}];
@@ -1466,6 +1469,62 @@ sub print_userlist {
$env{'form.phase'}.'" />');
}
+sub section_group_filter {
+ my ($cnum,$cdom) = @_;
+ my @filters;
+ if ($env{'request.course.sec'} eq '') {
+ @filters = ('sec');
+ }
+ push(@filters,'grp');
+ my %name = (
+ sec => 'secfilter',
+ grp => 'grpfilter',
+ );
+ my %title = &Apache::lonlocal::texthash (
+ sec => 'Section(s)',
+ grp => 'Group(s)',
+ all => 'all',
+ none => 'none',
+ );
+ my ($output,@options);
+ foreach my $item (@filters) {
+ my $markup;
+ if ($env{'form.'.$name{$item}} eq '') {
+ $env{'form.'.$name{$item}} = 'all';
+ }
+ if ($item eq 'sec') {
+ if ($env{'form.showrole'} eq 'cc') {
+ $env{'form.'.$name{$item}} = 'none';
+ }
+ my %sections_count = &Apache::loncommon::get_sections($cdom,$cnum);
+ @options = sort(keys(%sections_count));
+ } elsif ($item eq 'grp') {
+ my %curr_groups = &Apache::longroup::coursegroups();
+ @options = sort(keys(%curr_groups));
+ }
+ if (@options > 0) {
+ my $currsel;
+ $markup = ''."\n";
+ foreach my $option ('all','none',@options) {
+ $currsel = '';
+ if ($env{'form.'.$name{$item}} eq $option) {
+ $currsel = ' selected="selected" ';
+ }
+ $markup .= ' '."\n";
+ }
+ $markup .= ''."\n";
+ $output .= (' 'x3).''.$title{$item}.': '.$markup.'';
+ }
+ }
+ return $output;
+}
+
sub list_submit_button {
my ($text) = @_;
return '';
@@ -1479,7 +1538,8 @@ sub gather_userinfo {
($userdata{'username'},$userdata{'domain'},$userdata{'role'}) =
split(/:/,$item);
($userdata{'start'},$userdata{'end'})=split(/:/,$rolehash->{$item});
- &build_user_record(\%userdata,$userinfo,$indexhash,$item,$userlist);
+ &build_user_record($context,\%userdata,$userinfo,$indexhash,
+ $item,$userlist);
} elsif ($context eq 'course') {
my $viewablesec = &viewable_section($permission);
($userdata{'username'},$userdata{'domain'},$userdata{'role'},
@@ -1488,13 +1548,15 @@ sub gather_userinfo {
if (($viewablesec ne '') && ($userdata{'section'} ne '')) {
next if ($viewablesec ne $userdata{'section'});
}
- &build_user_record(\%userdata,$userinfo,$indexhash,$item,$userlist);
+ &build_user_record($context,\%userdata,$userinfo,$indexhash,
+ $item,$userlist);
} elsif ($context eq 'domain') {
if ($env{'form.roletype'} eq 'domain') {
($userdata{'role'},$userdata{'username'},$userdata{'domain'}) =
split(/:/,$item);
($userdata{'end'},$userdata{'start'})=split(/:/,$rolehash->{$item});
- &build_user_record(\%userdata,$userinfo,$indexhash,$item,$userlist);
+ &build_user_record($context,\%userdata,$userinfo,$indexhash,
+ $item,$userlist);
} elsif ($env{'form.roletype'} eq 'author') {
if (ref($rolehash->{$item}) eq 'HASH') {
$userdata{'extent'} = $item;
@@ -1503,7 +1565,8 @@ sub gather_userinfo {
($userdata{'start'},$userdata{'end'}) =
split(/:/,$rolehash->{$item}{$key});
my $uniqid = $key.':'.$item;
- &build_user_record(\%userdata,$userinfo,$indexhash,$uniqid,$userlist);
+ &build_user_record($context,\%userdata,$userinfo,
+ $indexhash,$uniqid,$userlist);
}
}
} elsif ($env{'form.roletype'} eq 'course') {
@@ -1521,9 +1584,9 @@ sub gather_userinfo {
# FIXME: actions on courses disabled for now
# if ($permission->{'cusr'}) {
# if ($numcids > 1) {
-# $spanstart .= '';
+# $spanstart .= ' ';
# } else {
-# $spanstart .= '';
+# $spanstart .= ' ';
# }
# }
$spanend = ' ';
@@ -1533,13 +1596,20 @@ sub gather_userinfo {
$rolehash->{$item}{$cid}{'desc'}.$space;
if (ref($rolehash->{$item}{$cid}{'secs'}) eq 'HASH') {
foreach my $sec (sort(keys(%{$rolehash->{$item}{$cid}{'secs'}}))) {
- $userdata{'extent'} .= $sec.$space.$rolehash->{$item}{$cid}{'secs'}{$sec}.$spanend;
+ if (($env{'form.Status'} eq 'Any') ||
+ ($env{'form.Status'} eq $rolehash->{$item}{$cid}{'secs'}{$sec})) {
+ $userdata{'extent'} .= $sec.$space.$rolehash->{$item}{$cid}{'secs'}{$sec}.$spanend;
+ $userdata{'status'} = $rolehash->{$item}{$cid}{'secs'}{$sec};
+ }
}
}
}
}
}
- &build_user_record(\%userdata,$userinfo,$indexhash,$item,$userlist);
+ if ($userdata{'status'} ne '') {
+ &build_user_record($context,\%userdata,$userinfo,
+ $indexhash,$item,$userlist);
+ }
}
}
}
@@ -1547,14 +1617,15 @@ sub gather_userinfo {
}
sub build_user_record {
- my ($userdata,$userinfo,$indexhash,$record_key,$userlist) = @_;
+ my ($context,$userdata,$userinfo,$indexhash,$record_key,$userlist) = @_;
next if ($userdata->{'start'} eq '-1' && $userdata->{'end'} eq '-1');
- &process_date_info($userdata);
+ if (!(($context eq 'domain') && ($env{'form.roletype'} eq 'course'))) {
+ &process_date_info($userdata);
+ }
my $username = $userdata->{'username'};
my $domain = $userdata->{'domain'};
if (ref($userinfo->{$username.':'.$domain}) eq 'HASH') {
- $userdata->{'fullname'} =
- $userinfo->{$username.':'.$domain}{'fullname'};
+ $userdata->{'fullname'} = $userinfo->{$username.':'.$domain}{'fullname'};
$userdata->{'id'} = $userinfo->{$username.':'.$domain}{'id'};
} else {
&aggregate_user_info($domain,$username,$userinfo);
@@ -1844,8 +1915,8 @@ END
if ($mode ne 'autoenroll') {
my $check_uncheck_js = &Apache::loncommon::check_uncheck_jscript();
my $alert = &mt("You must select at least one user by checking a user's 'Select' checkbox");
- my $singconfirm = &mt(' for a single user');
- my $multconfirm = &mt(' for multiple users');
+ my $singconfirm = &mt(' for a single user?');
+ my $multconfirm = &mt(' for multiple users?');
my $date_sec_selector = &date_section_javascript($context,$setting,$statusmode);
$r->print(<print(''.$results_description.' ');
}
- my ($output,$actionselect);
+ my ($output,$actionselect,%canchange,%canchangesec);
if ($mode eq 'html' || $mode eq 'view' || $mode eq 'autoenroll') {
if ($mode ne 'autoenroll') {
if ($permission->{'cusr'}) {
@@ -2015,6 +2086,45 @@ $lt{'ac'}: $actionselect
END
+ my @allroles;
+ if ($env{'form.showrole'} eq 'Any') {
+ my $custom = 1;
+ if ($context eq 'domain') {
+ @allroles = &roles_by_context($setting,$custom);
+ } else {
+ @allroles = &roles_by_context($context,$custom);
+ }
+ } else {
+ @allroles = ($env{'form.showrole'});
+ }
+ foreach my $role (@allroles) {
+ if ($context eq 'domain') {
+ if ($setting eq 'domain') {
+ if (&Apache::lonnet::allowed('c'.$role,
+ $env{'request.role.domain'})) {
+ $canchange{$role} = 1;
+ }
+ } elsif ($setting eq 'author') {
+ if (&Apache::lonnet::allowed('c'.$role,
+ $env{'request.role.domain'})) {
+ $canchange{$role} = 1;
+ }
+ }
+ } elsif ($context eq 'author') {
+ if (&Apache::lonnet::allowed('c'.$role,
+ $env{'user.domain'}.'/'.$env{'user.name'})) {
+ $canchange{$role} = 1;
+ }
+ } elsif ($context eq 'course') {
+ if (&Apache::lonnet::allowed('c'.$role,$env{'request.course.id'})) {
+ $canchange{$role} = 1;
+ } elsif ($env{'request.course.sec'} ne '') {
+ if (&Apache::lonnet::allowed('c'.$role,$env{'request.course.id'}.'/'.$env{'request.course.sec'})) {
+ $canchangesec{$role} = $env{'request.course.sec'};
+ }
+ }
+ }
+ }
}
}
$output .= "\n
\n".
@@ -2110,6 +2220,17 @@ END
$index{$idx} = $i++;
}
my $usercount = 0;
+ my ($secfilter,$grpfilter);
+ if ($context eq 'course') {
+ $secfilter = $env{'form.secfilter'};
+ $grpfilter = $env{'form.grpfilter'};
+ if ($secfilter eq '') {
+ $secfilter = 'all';
+ }
+ if ($grpfilter eq '') {
+ $grpfilter = 'all';
+ }
+ }
# Get groups, role, permanent e-mail so we can sort on them if
# necessary.
foreach my $user (keys(%{$userlist})) {
@@ -2147,11 +2268,40 @@ END
delete($userlist->{$user});
next;
}
- if (ref($classgroups) eq 'HASH') {
- $groups = $classgroups->{$user};
- }
- if (ref($groups->{active}) eq 'HASH') {
- $userlist->{$user}->[$index{'groups'}] = join(', ',keys(%{$groups->{'active'}}));
+ if ($context eq 'course') {
+ my @ac_groups;
+ if (ref($classgroups) eq 'HASH') {
+ $groups = $classgroups->{$user};
+ }
+ if (ref($groups->{'active'}) eq 'HASH') {
+ @ac_groups = keys(%{$groups->{'active'}});
+ $userlist->{$user}->[$index{'groups'}] = join(', ',@ac_groups);
+ }
+ if ($mode ne 'autoenroll') {
+ my $section = $userlist->{$user}->[$index{'section'}];
+ if ($secfilter eq 'none') {
+ if ($section ne '') {
+ delete($userlist->{$user});
+ next;
+ }
+ } elsif ($secfilter ne 'all') {
+ if ($section ne $secfilter) {
+ delete($userlist->{$user});
+ next;
+ }
+ }
+ if ($grpfilter eq 'none') {
+ if (@ac_groups > 0) {
+ delete($userlist->{$user});
+ next;
+ }
+ } elsif ($grpfilter ne 'all') {
+ if (!grep(/^\Q$grpfilter\E$/,@ac_groups)) {
+ delete($userlist->{$user});
+ next;
+ }
+ }
+ }
}
my %emails = &Apache::loncommon::getemails($uname,$udom);
if ($emails{'permanentemail'} =~ /\S/) {
@@ -2226,20 +2376,39 @@ END
$r->print("
$cellentry
\n");
} else {
$r->print("
$rowcount
\n");
- $checkval;
if ($actionselect) {
- $checkval = $user;
- if ($context eq 'course') {
- if ($role eq 'st') {
- $checkval .= ':st';
+ my $showcheckbox;
+ if ($role =~ /^cr\//) {
+ $showcheckbox = $canchange{'cr'};
+ } else {
+ $showcheckbox = $canchange{$role};
+ }
+ if (!$showcheckbox) {
+ if ($context eq 'course') {
+ if ($canchangesec{$role} ne '') {
+ if ($canchangesec{$role} eq $in{'section'}) {
+ $showcheckbox = 1;
+ }
+ }
}
- $checkval .= ':'.$in{'section'};
- if ($role eq 'st') {
- $checkval .= ':'.$in{'type'}.':'.$in{'lockedtype'};
+ }
+ if ($showcheckbox) {
+ $checkval = $user;
+ if ($context eq 'course') {
+ if ($role eq 'st') {
+ $checkval .= ':st';
+ }
+ $checkval .= ':'.$in{'section'};
+ if ($role eq 'st') {
+ $checkval .= ':'.$in{'type'}.':'.
+ $in{'lockedtype'};
+ }
}
+ $r->print('
');
+ } else {
+ $r->print('
');
}
- $r->print('
');
}
}
foreach my $item (@cols) {
@@ -2372,6 +2541,20 @@ sub select_actions {
if ($context eq 'domain' && $setting eq 'course') {
return;
}
+ if ($context eq 'course') {
+ if ($env{'form.showrole'} ne 'Any') {
+ if (!&Apache::lonnet::allowed('c'.$env{'form.showrole'},
+ $env{'request.course.id'})) {
+ if ($env{'request.course.sec'} eq '') {
+ return;
+ } else {
+ if (!&Apache::lonnet::allowed('c'.$env{'form.showrole'},$env{'request.course.id'}.'/'.$env{'request.course.sec'})) {
+ return;
+ }
+ }
+ }
+ }
+ }
if ($statusmode eq 'Any') {
$options .= '
';
@@ -2398,7 +2581,7 @@ sub select_actions {
';
}
if (($context eq 'course') || ($context eq 'domain' && $setting eq 'course')) {
- if ($statusmode ne 'Expired') {
+ if (($statusmode ne 'Expired') && ($env{'request.course.sec'} eq '')) {
$options .= '
';
$choices{'sections'} = 1;
@@ -2505,7 +2688,8 @@ END
if (($env{'form.bulkaction'} eq 'reenable') ||
($env{'form.bulkaction'} eq 'activate') ||
($env{'form.bulkaction'} eq 'chgdates')) {
- $output .= <<"END";
+ if ($env{'request.course.sec'} eq '') {
+ $output .= <<"END";
if (formname.makedatesdefault.checked == true) {
opener.document.$callingform.makedatesdefault.value = 1;
@@ -2515,6 +2699,7 @@ END
}
END
+ }
}
}
$output .= <<"END";
@@ -2564,12 +2749,10 @@ END
$date_items;
if ($context eq 'course' && $env{'form.bulkaction'} eq 'chgsec') {
my ($cnum,$cdom) = &get_course_identity();
- my %sections_count =
- &Apache::loncommon::get_sections($cdom,$cnum);
my $info;
if ($env{'form.showrole'} eq 'st') {
$output .= '
\n".
- &mt('Roles added for [_1] users. If user is active, the new role will be available when the user next logs in to LON-CAPA.',$counts{'role'})."
\n");
+ &mt('Roles added for [quant,_1,user].',$counts{'role'}).' '.&mt('If a user is currently logged-in to LON-CAPA, any new roles which are active will be available when the user next logs in.')."\n");
+ } else {
+ $r->print('
'.&mt('No roles added').'
');
}
if ($counts{'auth'} > 0) {
$r->print("
\n".
@@ -3277,23 +3672,22 @@ sub upfile_drop_add {
$counts{'auth'})."
\n");
}
$r->print(&print_namespacing_alerts($domain,\%alerts,\%curr_rules));
- $r->print('');
#####################################
- # Drop students #
+ # Display list of students to drop #
#####################################
if ($env{'form.fullup'} eq 'yes') {
- $r->print('
'.&mt('Dropping Students')."
\n");
+ $r->print('
'.&mt('Students to Drop')."
\n");
# Get current classlist
- my ($classlist,$keylist)=&Apache::loncoursedata::get_classlist();
+ my $classlist = &Apache::loncoursedata::get_classlist();
if (! defined($classlist)) {
- $r->print(&mt('There are no students currently enrolled.').
- "\n");
+ $r->print(''.
+ ''.
+ &mt('There are no students with current/future access to the course.').
+ ''."\n");
} else {
# Remove the students we just added from the list of students.
- foreach (@userdata) {
- my %entries=&Apache::loncommon::record_sep($_);
+ foreach my $line (@userdata) {
+ my %entries=&Apache::loncommon::record_sep($line);
unless (($entries{$fields{'username'}} eq '') ||
(!defined($entries{$fields{'username'}}))) {
delete($classlist->{$entries{$fields{'username'}}.
@@ -3301,10 +3695,13 @@ sub upfile_drop_add {
}
}
# Print out list of dropped students.
- &show_drop_list($r,$classlist,$keylist,'nosort');
+ &show_drop_list($r,$classlist,'nosort',$permission);
}
}
} # end of unless
+ if ($env{'form.fullup'} ne 'yes') {
+ $r->print('');
+ }
}
sub print_namespacing_alerts {
@@ -3348,8 +3745,8 @@ sub print_namespacing_alerts {
}
sub user_change_result {
- my ($r,$userresult,$authresult,$roleresult,$counts,$flushc,$username,
- $userchg) = @_;
+ my ($r,$userresult,$authresult,$roleresult,$idresult,$counts,$flushc,
+ $username,$userchg) = @_;
my $okresult = 0;
if ($userresult ne 'ok') {
if ($userresult =~ /^error:(.+)$/) {
@@ -3390,6 +3787,9 @@ sub user_change_result {
$flushc=0;
}
}
+ if ($idresult) {
+ $r->print($idresult);
+ }
return $flushc;
}
@@ -3398,14 +3798,12 @@ sub print_drop_menu {
my ($r,$context,$permission) = @_;
$r->print('
'.&mt("Drop Students").'
'."\n".
''. &Apache::loncommon::end_page());
return;
}
@@ -3417,10 +3815,10 @@ sub update_user_list {
my $now = time;
my $count=0;
my @changelist;
- if ($choice ne '') {
- @changelist = &Apache::loncommon::get_env_multiple('form.actionlist');
- } else {
+ if ($choice eq 'drop') {
@changelist = &Apache::loncommon::get_env_multiple('form.droplist');
+ } else {
+ @changelist = &Apache::loncommon::get_env_multiple('form.actionlist');
}
my %result_text = ( ok => { 'revoke' => 'Revoked',
'delete' => 'Deleted',
@@ -3487,7 +3885,6 @@ sub update_user_list {
}
}
my $plrole = &Apache::lonnet::plaintext($role);
- my ($uid,$first,$middle,$last,$gene,$sec);
my $start = $env{'form.'.$item.'_start'};
my $end = $env{'form.'.$item.'_end'};
if ($choice eq 'drop') {
@@ -3507,16 +3904,12 @@ sub update_user_list {
&Apache::lonnet::revokerole($udom,$uname,$scope,$role);
}
} elsif ($choice eq 'delete') {
- $start = -1;
- $end = -1;
if ($role eq 'st') {
-# FIXME - how does role deletion affect classlist?
- &Apache::lonnet::modify_student_enrollment($udom,$uname,undef,undef,undef,undef,undef,$sec,$end,$start,$type,$locktype,$cid);
- } else {
- $result =
- &Apache::lonnet::assignrole($udom,$uname,$scope,$role,$now,
- 0,1);
- }
+ &Apache::lonnet::modify_student_enrollment($udom,$uname,undef,undef,undef,undef,undef,$sec,$now,$start,$type,$locktype,$cid);
+ }
+ $result =
+ &Apache::lonnet::assignrole($udom,$uname,$scope,$role,$now,
+ $start,1);
} else {
#reenable, activate, change access dates or change section
if ($choice ne 'chgsec') {
@@ -3558,27 +3951,36 @@ sub update_user_list {
$nochg = 1;
}
} else {
- if (!grep(/^\Q$sec\E$/,@newsecs)) {
- $revresult =
- &Apache::lonnet::revokerole($udom,$uname,$scope,$role);
+ if (@newsecs > 0) {
+ if (grep(/^\Q$sec\E$/,@newsecs)) {
+ push(@retained,$sec);
+ } else {
+ $revresult =
+ &Apache::lonnet::revokerole($udom,$uname,
+ $scope,$role);
+ }
} else {
- push(@retained,$sec);
+ $revresult =
+ &Apache::lonnet::revokerole($udom,$uname,
+ $scope,$role);
}
}
} else {
- push(@retained,$sec);
+ if ($sec eq '') {
+ $nochg = 1;
+ } else {
+ push(@retained,$sec);
+ }
}
# add new sections
if (@newsecs == 0) {
if (!$nochg) {
- if ($sec ne '') {
- if ($role eq 'st') {
- $result =
- &Apache::lonnet::modify_student_enrollment($udom,$uname,undef,undef,undef,undef,undef,undef,$end,$start,$type,$locktype,$cid);
- } else {
- my $newscope = $scopestem;
- $result = &Apache::lonnet::assignrole($udom,$uname,$newscope,$role,$end,$start);
- }
+ if ($role eq 'st') {
+ $result =
+ &Apache::lonnet::modify_student_enrollment($udom,$uname,undef,undef,undef,undef,undef,undef,$end,$start,$type,$locktype,$cid);
+ } else {
+ my $newscope = $scopestem;
+ $result = &Apache::lonnet::assignrole($udom,$uname,$newscope,$role,$end,$start);
}
}
} else {
@@ -3612,11 +4014,24 @@ sub update_user_list {
$count++;
} else {
$r->print(
- &mt("Error $result_text{'error'}{$choice} [_1] in [_2] for [_3]:[_4]",
+ &mt("Error $result_text{'error'}{$choice} [_1] in [_2] for [_3]: [_4].",
$plrole,$extent,$uname.':'.$udom,$result).' ');
}
}
- $r->print('
'.&mt("$result_text{'ok'}{$choice} role(s) for [quant,_1,user,users,users].",$count).'
');
+ $r->print(''."\n");
}
sub classlist_drop {
- my ($scope,$uname,$udom,$now,$action) = @_;
+ my ($scope,$uname,$udom,$now) = @_;
my ($cdom,$cnum) = ($scope=~m{^/($match_domain)/($match_courseid)});
- my $cid=$cdom.'_'.$cnum;
- my $user = $uname.':'.$udom;
- if ($action eq 'drop') {
+ if (&Apache::lonnet::is_course($cdom,$cnum)) {
+ my $user = $uname.':'.$udom;
if (!&active_student_roles($cnum,$cdom,$uname,$udom)) {
my $result =
&Apache::lonnet::cput('classlist',
- { $user => $now },
- $env{'course.'.$cid.'.domain'},
- $env{'course.'.$cid.'.num'});
+ { $user => $now },$cdom,$cnum);
return &mt('Drop from classlist: [_1]',
''.$result.'').' ';
}
@@ -3712,16 +4129,26 @@ sub course_sections {
my ($sections_count,$role) = @_;
my $output = '';
my @sections = (sort {$a <=> $b} keys %{$sections_count});
- if (scalar(@sections) == 1) {
+ my $numsec = scalar(@sections);
+ if ($numsec <= 1) {
$output = '