'."\n");
+ }
}
if ($context eq 'course') {
if ($env{'form.showrole'} eq 'st' || $env{'form.showrole'} eq 'Any') {
@@ -2094,6 +2251,21 @@ END
}
}
+sub print_username_link {
+ my ($permission,$in) = @_;
+ my $output;
+ if (!$permission->{'cusr'}) {
+ $output = &Apache::loncommon::aboutmewrapper($in->{'username'},
+ $in->{'username'},
+ $in->{'domain'});
+ } else {
+ $output = '{'username'}','$in->{'domain'}'".')" />'.
+ $in->{'username'}.'';
+ }
+ return $output;
+}
+
sub role_type_names {
my %lt = &Apache::lonlocal::texthash (
'domain' => 'Domain Roles',
@@ -2103,6 +2275,254 @@ sub role_type_names {
return %lt;
}
+sub select_actions {
+ my ($context,$setting,$statusmode) = @_;
+ my %lt = &Apache::lonlocal::texthash(
+ revoke => "Revoke user roles",
+ delete => "Delete user roles",
+ reenable => "Re-enable expired user roles",
+ activate => "Make future user roles active now",
+ chgdates => "Change starting/ending dates",
+ chgsec => "Change section associated with user roles",
+ );
+ my ($output,$options,%choices);
+ if ($statusmode eq 'Any') {
+ $options .= '
+';
+ $choices{'dates'} = 1;
+ } else {
+ if ($statusmode eq 'Active' || $statusmode eq 'Future') {
+ $options .= '
+';
+ }
+ if ($statusmode eq 'Future') {
+ $options .= '
+';
+ $choices{'dates'} = 1;
+ } elsif ($statusmode eq 'Expired') {
+ $options .= '
+';
+ $choices{'dates'} = 1;
+ }
+ }
+ if ($context eq 'domain') {
+ $options .= '
+';
+ }
+ if (($context eq 'course') || ($context eq 'domain' && $setting eq 'course')) {
+ if ($statusmode ne 'Expired') {
+ $options .= '
+';
+ $choices{'sections'} = 1;
+ }
+ }
+ if ($options) {
+ $output = ''."\n".
+ ''."\n".$options."\n".'';
+ if ($choices{'dates'}) {
+ $output .=
+ ''."\n".
+ ''."\n".
+ ''."\n".
+ ''."\n".
+ ''."\n".
+ ''."\n".
+ ''."\n".
+ ''."\n".
+ ''."\n".
+ ''."\n".
+ ''."\n".
+ ''."\n";
+ if ($context eq 'course') {
+ $output .= ''."\n";
+ }
+ }
+ if ($choices{'sections'}) {
+ $output .= ''."\n".
+ ''."\n";
+ }
+ }
+ return $output;
+}
+
+sub date_section_javascript {
+ my ($context,$setting) = @_;
+ my $title;
+ if (($context eq 'course') || ($context eq 'domain' && $setting eq 'course')) {
+ $title = &mt('Date and Section selector');
+ } else {
+ $title = &mt('Date selector');
+ }
+ my $output = '
+
+ENDTWO
+ return $output;
+}
+
+sub date_section_selector {
+ my ($context) = @_;
+ my $callingform = $env{'form.callingform'};
+ my $formname = 'dateselect';
+ my $groupslist = &get_groupslist();
+ my $sec_js = &setsections_javascript($formname,$groupslist);
+ my $output = <<"END";
+
+';
+ 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 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).',
+ );
+ my ($date_items,$headertext);
+ if ($env{'form.bulkaction'} eq 'chgsec') {
+ $headertext = $lt{'chse'};
+ } else {
+ $headertext = $lt{'chac'};
+ my $starttime;
+ if (($env{'form.bulkaction'} eq 'activate') ||
+ ($env{'form.bulkaction'} eq 'reenable')) {
+ $starttime = time;
+ }
+ $date_items = &date_setting_table($starttime,undef,$context,
+ $env{'form.bulkaction'});
+ }
+ $output .= '
'.$headertext.'
'.
+ '';
+ return $output;
+}
+
sub results_header_row {
my ($rolefilter,$statusmode,$context) = @_;
my ($description,$showfilter);
@@ -2113,8 +2533,7 @@ sub results_header_row {
$description = &mt('Course - ').$env{'course.'.$env{'request.course.id'}.'.description'}.': ';
if ($statusmode eq 'Expired') {
$description .= &mt('Users in course with expired [_1] roles',$showfilter);
- }
- if ($statusmode eq 'Future') {
+ } elsif ($statusmode eq 'Future') {
$description .= &mt('Users in course with future [_1] roles',$showfilter);
} elsif ($statusmode eq 'Active') {
$description .= &mt('Users in course with active [_1] roles',$showfilter);
@@ -2851,36 +3270,226 @@ sub print_expire_menu {
# ================================================================== Phase four
-sub expire_user_list {
- my ($r,$context) = @_;
+sub update_user_list {
+ my ($r,$context,$setting,$choice) = @_;
+ my $now = time;
my $count=0;
- my @droplist = &Apache::loncommon::get_env_multiple('form.droplist');
- foreach (@droplist) {
- my ($uname,$udom)=split(/\:/,$_);
- # drop student
- my $result = &modifystudent($udom,$uname,$env{'request.course.id'});
+ my @changelist;
+ if ($choice ne '') {
+ @changelist = &Apache::loncommon::get_env_multiple('form.actionlist');
+ } else {
+ @changelist = &Apache::loncommon::get_env_multiple('form.droplist');
+ }
+ my %result_text = ( ok => { 'revoke' => 'Revoked',
+ 'delete' => 'Deleted',
+ 'reenable' => 'Re-enabled',
+ 'activate' => 'Activated',
+ },
+ error => {'revoke' => 'revoking',
+ 'delete' => 'deleting',
+ 'reenable' => 're-enabling',
+ 'activate' => 'activating',
+ },
+ );
+ my ($startdate,$enddate);
+ if ($choice eq 'chgdates' || $choice eq 'reenable' || $choice eq 'activate') {
+ ($startdate,$enddate) = &get_dates_from_form();
+ }
+ foreach my $item (@changelist) {
+ my ($role,$uname,$udom,$cid,$sec,$scope,$result,$type,$locktype,@sections,
+ $scopestem);
+ if ($context eq 'course') {
+ ($uname,$udom,$role,$sec,$type,$locktype) = split(/\:/,$item,-1);
+ $cid = $env{'request.course.id'};
+ $scopestem = '/'.$cid;
+ $scopestem =~s/\_/\//g;
+ if ($sec eq '') {
+ $scope = $scopestem;
+ } else {
+ $scope = $scopestem.'/'.$sec;
+ }
+ } elsif ($context eq 'construction_space') {
+ ($uname,$udom,$role) = split(/\:/,$item,-1);
+ $scope = '/'.$env{'user.domain'}.'/'.$env{'user.name'};
+ } elsif ($context eq 'domain') {
+ if ($setting eq 'domain') {
+ ($role,$uname,$udom) = split(/\:/,$item,-1);
+ $scope = '/'.$env{'request.role.domain'}.'/';
+ } elsif ($setting eq 'construction_space') {
+ ($uname,$udom,$role,$scope) = split(/\:/,$item);
+ } elsif ($setting eq 'course') {
+ ($uname,$udom,$role,$cid,$sec,$type,$locktype) =
+ split(/\:/,$item);
+ $scope = '/'.$cid;
+ $scope =~s/\_/\//g;
+ if ($sec ne '') {
+ $scope .= '/'.$sec;
+ }
+ }
+ }
+ 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'};
+ # revoke or delete user role
+ if ($choice eq 'revoke') {
+ $end = $now;
+ if ($role eq 'st') {
+ $result =
+ &Apache::lonnet::modify_student_enrollment($udom,$uname,undef,undef,undef,undef,undef,$sec,$end,$start,$type,$locktype,$cid);
+ } else {
+ $result =
+ &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);
+ }
+ } else {
+ #reenable, activate, change access dates or change section
+ if ($choice ne 'chgsec') {
+ $start = $startdate;
+ $end = $enddate;
+ }
+ if ($choice eq 'reenable') {
+ if ($role eq 'st') {
+ $result = &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,$end,
+ $now);
+ }
+ } elsif ($choice eq 'activate') {
+ if ($role eq 'st') {
+ $result = &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,$end,
+ $now);
+ }
+ } elsif ($choice eq 'chgdates') {
+ if ($role eq 'st') {
+ $result = &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,$end,
+ $start);
+ }
+ } elsif ($choice eq 'chgsec') {
+ my (@newsecs,$revresult,$nochg,@retained);
+ if ($role ne 'cc') {
+ @newsecs = split(/,/,$env{'form.newsecs'});
+ }
+ # remove existing section if not to be retained.
+ if (!$env{'form.retainsec'}) {
+ if ($sec eq '') {
+ if (@newsecs == 0) {
+ $result = &mt('No change in section assignment (none)');
+ $nochg = 1;
+ }
+ } else {
+ if (!grep(/^\Q$sec\E$/,@newsecs)) {
+ $revresult =
+ &Apache::lonnet::revokerole($udom,$uname,$scope,$role);
+ } else {
+ push(@retained,$sec);
+ }
+ }
+ } 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);
+ }
+ }
+ }
+ } 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);
+ } else {
+ my $newscope = $scopestem;
+ if ($newsec ne '') {
+ $newscope .= '/'.$newsec;
+ }
+ $result = &Apache::lonnet::assignrole($udom,$uname,
+ $newscope,$role,$end,$start);
+ }
+ }
+ }
+ }
+ }
+ }
if ($result eq 'ok' || $result eq 'ok:') {
- $r->print(&mt('Dropped [_1]',$uname.'@'.$udom).' ');
+ $r->print(&mt("$result_text{'ok'}{$choice} role of '[_1]' in [_2] for [_3]",
+ $plrole,$scope,$uname.':'.$udom).' ');
$count++;
} else {
$r->print(
- &mt('Error dropping [_1]:[_2]',$uname.'@'.$udom,$result).
- ' ');
+ &mt("Error $result_text{'error'}{$choice} [_1] in [_2] for [_3]:[_4]",
+ $plrole,$scope,$uname.':'.$udom,$result).' ');
+ }
+ }
+ $r->print('
'.&mt("$result_text{'ok'}{$choice} role(s) for [quant,_1,user,users,users].",$count).'
');
+ if ($count > 0) {
+ if ($choice eq 'revoke') {
+ $r->print('
'.&mt('Re-enabling will re-activate data for the role.
'));
+ }
+ # Flush the course logs so reverse user roles immediately updated
+ &Apache::lonnet::flushcourselogs();
+ }
+ if ($env{'form.makedatesdefault'}) {
+ if ($choice eq 'chgdates' || $choice eq 'reenable' || $choice eq 'activate') {
+ $r->print(&make_dates_default($startdate,$enddate));
}
}
- $r->print('
'.&mt('Dropped [_1] user(s).',$count).'
');
- $r->print('
'.&mt('Re-enrollment will re-activate data.')) if ($count);
}
-sub section_check_js {
- my $groupslist;
- my %curr_groups = &Apache::longroup::coursegroups();
- if (%curr_groups) {
- $groupslist = join('","',sort(keys(%curr_groups)));
+sub classlist_drop {
+ my ($scope,$uname,$udom,$now,$action) = @_;
+ my ($cdom,$cnum) = ($scope=~m{^/($match_domain)/($match_courseid)});
+ my $cid=$cdom.'_'.$cnum;
+ my $user = $uname.':'.$udom;
+ if ($action eq 'drop') {
+ if (!&active_student_roles($cnum,$cdom,$uname,$udom)) {
+ my $result =
+ &Apache::lonnet::cput('classlist',
+ { $user => $now },
+ $env{'course.'.$cid.'.domain'},
+ $env{'course.'.$cid.'.num'});
+ return &mt('Drop from classlist: [_1]',
+ ''.$result.'').' ';
+ }
}
+}
+
+sub active_student_roles {
+ my ($cnum,$cdom,$uname,$udom) = @_;
+ my %roles =
+ &Apache::lonnet::get_my_roles($uname,$udom,'userroles',
+ ['future','active'],['st']);
+ return exists($roles{"$cnum:$cdom:st"});
+}
+
+sub section_check_js {
+ my $groupslist= &get_groupslist();
return <<"END";
function validate(caller) {
- var groups = new Array("$groupslist");
+ var groups = new Array($groupslist);
var secname = caller.value;
if ((secname == 'all') || (secname == 'none')) {
alert("'"+secname+"' may not be used as the name for a section, as it is a reserved word.\\nPlease choose a different section name.");
@@ -2927,5 +3536,144 @@ sub set_login {
return $response;
}
+sub course_sections {
+ my ($sections_count,$role) = @_;
+ my $output = '';
+ my @sections = (sort {$a <=> $b} keys %{$sections_count});
+ if (scalar(@sections) == 1) {
+ $output = '