--- loncom/interface/lonuserutils.pm 2007/12/22 04:23:05 1.25
+++ loncom/interface/lonuserutils.pm 2007/12/22 22:42:58 1.29
@@ -1,7 +1,7 @@
# The LearningOnline Network with CAPA
# Utility functions for managing LON-CAPA user accounts
#
-# $Id: lonuserutils.pm,v 1.25 2007/12/22 04:23:05 raeburn Exp $
+# $Id: lonuserutils.pm,v 1.29 2007/12/22 22:42:58 raeburn Exp $
#
# Copyright Michigan State University Board of Trustees
#
@@ -1990,7 +1990,7 @@ END
$context,$permission,$mode);
$r->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'}) {
@@ -2029,6 +2029,40 @@ $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 ($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".
@@ -2242,18 +2276,38 @@ END
$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) {
@@ -2386,6 +2440,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 .= '
';
@@ -2412,7 +2480,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;
@@ -2519,7 +2587,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;
@@ -2529,6 +2598,7 @@ END
}
END
+ }
}
}
$output .= <<"END";
@@ -2578,12 +2648,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 .= ''.$lt{'fors'}.'
';
- } elsif ($env{'form.shorole'} eq 'Any') {
+ } elsif ($env{'form.showrole'} eq 'Any') {
$output .= ''.$lt{'fors'}.'
'.
''.$lt{'forn'}.' ';
$info = $lt{'reta'};
@@ -2604,7 +2672,6 @@ END
} else {
$info = '';
}
- my $sections_select .= &course_sections(\%sections_count,$env{'form.showrole'});
my $rowtitle = &mt('New section to assign');
my $secbox = §ion_picker($cdom,$cnum,$env{'form.showrole'},$rowtitle,$permission,$context);
$output .= $info.$secbox;
@@ -2669,11 +2736,12 @@ sub results_header_row {
$description .= &mt('All users in course with [_1] roles',$rolefilter);
}
}
- if (exists($permission->{'view_section'})) {
+ my $viewablesec = &viewable_section($permission);
+ if ($viewablesec ne '') {
if ($env{'form.showrole'} eq 'st') {
- $description .= ' '.&mt('(section [_1] only)',$permission->{'view_section'});
- } elsif ($env{'form.showrole'} eq 'any') {
- $description .= ' '.&mt('(section [_1] only)',$permission->{'view_section'});
+ $description .= ' '.&mt('(section [_1] only)',$viewablesec);
+ } elsif ($env{'form.showrole'} ne 'cc') {
+ $description .= ' '.&mt('(only users affiliated with no section or section [_1])',$viewablesec);
}
}
} elsif ($context eq 'author') {
@@ -2773,8 +2841,8 @@ sub viewable_section {
#################################################
#################################################
sub show_drop_list {
- my ($r,$classlist,$keylist,$nosort,$permission)=@_;
- my $cid=$env{'request.course.id'};
+ my ($r,$classlist,$keylist,$nosort,$permission) = @_;
+ my $cid = $env{'request.course.id'};
my ($cnum,$cdom) = &get_course_identity($cid);
if (! exists($env{'form.sortby'})) {
&Apache::loncommon::get_unprocessed_cgi($ENV{'QUERY_STRING'},
@@ -2903,13 +2971,13 @@ END
#
$r->print(&Apache::loncommon::start_data_table_row());
$r->print(<<"END");
-
|
+ |
$username |
$domain |
$id |
$name |
$section |
- $start |
+ $start $startitem |
$end |
$active_groups |
END
@@ -2917,7 +2985,7 @@ END
}
$r->print(&Apache::loncommon::end_data_table().'
');
%lt=&Apache::lonlocal::texthash(
- 'dp' => "Expire Users' Roles",
+ 'dp' => "Drop Students",
'ca' => "check all",
'ua' => "uncheck all",
);
@@ -2974,6 +3042,10 @@ sub upfile_drop_add {
$fields{$env{'form.f'.$i}}=$keyfields[$i];
}
}
+ if ($env{'form.fullup'} ne 'yes') {
+ $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();
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) {
@@ -3317,10 +3551,13 @@ sub upfile_drop_add {
}
}
# Print out list of dropped students.
- &show_drop_list($r,$classlist,$keylist,'nosort');
+ &show_drop_list($r,$classlist,$keylist,'nosort',$permission);
}
}
} # end of unless
+ if ($env{'form.fullup'} ne 'yes') {
+ $r->print('');
+ }
}
sub print_namespacing_alerts {
@@ -3364,8 +3601,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:(.+)$/) {
@@ -3406,6 +3643,9 @@ sub user_change_result {
$flushc=0;
}
}
+ if ($idresult) {
+ $r->print($idresult);
+ }
return $flushc;
}
@@ -3433,10 +3673,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',
@@ -3503,7 +3743,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') {
@@ -3523,16 +3762,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') {
@@ -3574,27 +3809,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 {
@@ -3628,11 +3872,11 @@ 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(''.&mt("$result_text{'ok'}{$choice} role(s) for [quant,_1,user,users,no users].",$count).'
');
if ($count > 0) {
if ($choice eq 'revoke' || $choice eq 'drop') {
$r->print(''.&mt('Re-enabling will re-activate data for the role.
'));
@@ -3642,23 +3886,20 @@ sub update_user_list {
}
if ($env{'form.makedatesdefault'}) {
if ($choice eq 'chgdates' || $choice eq 'reenable' || $choice eq 'activate') {
- $r->print(&make_dates_default($startdate,$enddate));
+ $r->print(&make_dates_default($startdate,$enddate,$context));
}
}
}
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.'').'
';
}
@@ -3728,16 +3969,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 = '