--- loncom/interface/lonuserutils.pm 2007/10/22 22:16:38 1.1
+++ loncom/interface/lonuserutils.pm 2017/08/07 20:22:13 1.185
@@ -1,7 +1,7 @@
# The LearningOnline Network with CAPA
# Utility functions for managing LON-CAPA user accounts
#
-# $Id: lonuserutils.pm,v 1.1 2007/10/22 22:16:38 raeburn Exp $
+# $Id: lonuserutils.pm,v 1.185 2017/08/07 20:22:13 raeburn Exp $
#
# Copyright Michigan State University Board of Trustees
#
@@ -30,23 +30,40 @@
package Apache::lonuserutils;
+=pod
+
+=head1 NAME
+
+Apache::lonuserutils.pm
+
+=head1 SYNOPSIS
+
+ Utilities for management of users and custom roles
+
+ Provides subroutines called by loncreateuser.pm
+
+=head1 OVERVIEW
+
+=cut
+
use strict;
use Apache::lonnet;
use Apache::loncommon();
use Apache::lonhtmlcommon;
use Apache::lonlocal;
-use LONCAPA();
+use Apache::longroup;
+use HTML::Entities;
+use LONCAPA qw(:DEFAULT :match);
###############################################################
###############################################################
# Drop student from all sections of a course, except optional $csec
sub modifystudent {
- my ($udom,$unam,$courseid,$csec,$desiredhost)=@_;
+ my ($udom,$unam,$courseid,$csec,$desiredhost,$context)=@_;
# if $csec is undefined, drop the student from all the courses matching
# this one. If $csec is defined, drop them from all other sections of
# this course and add them to section $csec
- my $cdom = $env{'course.'.$courseid.'.domain'};
- my $cnum = $env{'course.'.$courseid.'.num'};
+ my ($cnum,$cdom) = &get_course_identity($courseid);
my %roles = &Apache::lonnet::dump('roles',$udom,$unam);
my ($tmp) = keys(%roles);
# Bail out if we were unable to get the students roles
@@ -68,14 +85,15 @@ sub modifystudent {
my $reply=&Apache::lonnet::modifystudent
# dom name id mode pass f m l g
($udom,$unam,'', '', '',undef,undef,undef,undef,
- $section,time,undef,undef,$desiredhost);
+ $section,time,undef,undef,$desiredhost,'','manual',
+ '',$courseid,'',$context);
$result .= $reply.':';
}
}
}
}
if ($result eq '') {
- $result = 'Unable to find section for this student';
+ $result = &mt('Unable to find section for this student');
} else {
$result =~ s/(ok:)+/ok/g;
}
@@ -85,71 +103,207 @@ sub modifystudent {
sub modifyuserrole {
my ($context,$setting,$changeauth,$cid,$udom,$uname,$uid,$umode,$upass,
$first,$middle,$last,$gene,$sec,$forceid,$desiredhome,$email,$role,
- $end,$start) = @_;
- my ($scope,$userresult,$authresult,$roleresult);
+ $end,$start,$checkid,$inststatus) = @_;
+ my ($scope,$userresult,$authresult,$roleresult,$idresult);
if ($setting eq 'course' || $context eq 'course') {
$scope = '/'.$cid;
$scope =~ s/\_/\//g;
- if ($role ne 'cc' && $sec ne '') {
+ if (($role ne 'cc') && ($role ne 'co') && ($sec ne '')) {
$scope .='/'.$sec;
}
- } elsif ($setting eq 'domain') {
+ } elsif ($context eq 'domain') {
$scope = '/'.$env{'request.role.domain'}.'/';
- } elsif ($setting eq 'construction_space') {
+ } elsif ($context eq 'author') {
$scope = '/'.$env{'user.domain'}.'/'.$env{'user.name'};
}
if ($context eq 'domain') {
my $uhome = &Apache::lonnet::homeserver($uname,$udom);
if ($uhome ne 'no_host') {
- if (($changeauth) && (&Apache::lonnet::allowed('mau',$udom))) {
+ if (($changeauth eq 'Yes') && (&Apache::lonnet::allowed('mau',$udom))) {
if ((($umode =~ /^krb4|krb5|internal$/) && $upass ne '') ||
($umode eq 'localauth')) {
$authresult = &Apache::lonnet::modifyuserauth($udom,$uname,$umode,$upass);
}
}
+ if (($forceid) && (&Apache::lonnet::allowed('mau',$udom)) &&
+ ($env{'form.recurseid'}) && ($checkid)) {
+ my %userupdate = (
+ lastname => $last,
+ middlename => $middle,
+ firstname => $first,
+ generation => $gene,
+ id => $uid,
+ );
+ $idresult = &propagate_id_change($uname,$udom,\%userupdate);
+ }
}
}
$userresult =
&Apache::lonnet::modifyuser($udom,$uname,$uid,$umode,$upass,$first,
$middle,$last,$gene,$forceid,$desiredhome,
- $email,$role,$start,$end);
+ $email,$inststatus);
if ($userresult eq 'ok') {
- if ($role ne '') {
+ if ($role ne '') {
+ $role =~ s/_/\//g;
$roleresult = &Apache::lonnet::assignrole($udom,$uname,$scope,
- $role,$end,$start);
+ $role,$end,$start,'',
+ '',$context);
+ }
+ }
+ return ($userresult,$authresult,$roleresult,$idresult);
+}
+
+sub propagate_id_change {
+ my ($uname,$udom,$user) = @_;
+ my (@types,@roles);
+ @types = ('active','future');
+ @roles = ('st');
+ my $idresult;
+ my %roleshash = &Apache::lonnet::get_my_roles($uname,
+ $udom,'userroles',\@types,\@roles);
+ my %args = (
+ one_time => 1,
+ );
+ foreach my $item (keys(%roleshash)) {
+ my ($cnum,$cdom,$role) = split(/:/,$item,-1);
+ my ($start,$end) = split(/:/,$roleshash{$item});
+ if (&Apache::lonnet::is_course($cdom,$cnum)) {
+ my $result = &update_classlist($cdom,$cnum,$udom,$uname,$user);
+ my %coursehash =
+ &Apache::lonnet::coursedescription($cdom.'_'.$cnum,\%args);
+ my $cdesc = $coursehash{'description'};
+ if ($cdesc eq '') {
+ $cdesc = $cdom.'_'.$cnum;
+ }
+ if ($result eq 'ok') {
+ $idresult .= &mt('Classlist update for "[_1]" in "[_2]".',$uname.':'.$udom,$cdesc).' '."\n";
+ } else {
+ $idresult .= &mt('Error: "[_1]" during classlist update for "[_2]" in "[_3]".',$result,$uname.':'.$udom,$cdesc).' '."\n";
+ }
+ }
+ }
+ return $idresult;
+}
+
+sub update_classlist {
+ my ($cdom,$cnum,$udom,$uname,$user,$newend) = @_;
+ my ($uid,$classlistentry);
+ my $fullname =
+ &Apache::lonnet::format_name($user->{'firstname'},$user->{'middlename'},
+ $user->{'lastname'},$user->{'generation'},
+ 'lastname');
+ my %classhash = &Apache::lonnet::get('classlist',[$uname.':'.$udom],
+ $cdom,$cnum);
+ my @classinfo = split(/:/,$classhash{$uname.':'.$udom});
+ my $ididx=&Apache::loncoursedata::CL_ID() - 2;
+ my $nameidx=&Apache::loncoursedata::CL_FULLNAME() - 2;
+ my $endidx = &Apache::loncoursedata::CL_END() - 2;
+ my $startidx = &Apache::loncoursedata::CL_START() - 2;
+ for (my $i=0; $i<@classinfo; $i++) {
+ if ($i == $endidx) {
+ if ($newend ne '') {
+ $classlistentry .= $newend.':';
+ } else {
+ $classlistentry .= $classinfo[$i].':';
+ }
+ } elsif ($i == $startidx) {
+ if ($newend ne '') {
+ if ($classinfo[$i] > $newend) {
+ $classlistentry .= $newend.':';
+ } else {
+ $classlistentry .= $classinfo[$i].':';
+ }
+ } else {
+ $classlistentry .= $classinfo[$i].':';
+ }
+ } elsif ($i == $ididx) {
+ if (defined($user->{'id'})) {
+ $classlistentry .= $user->{'id'}.':';
+ } else {
+ $classlistentry .= $classinfo[$i].':';
+ }
+ } elsif ($i == $nameidx) {
+ if (defined($user->{'lastname'})) {
+ $classlistentry .= $fullname.':';
+ } else {
+ $classlistentry .= $classinfo[$i].':';
+ }
+ } else {
+ $classlistentry .= $classinfo[$i].':';
}
}
- return ($userresult,$authresult,$roleresult);
+ $classlistentry =~ s/:$//;
+ my $reply=&Apache::lonnet::cput('classlist',
+ {"$uname:$udom" => $classlistentry},
+ $cdom,$cnum);
+ if (($reply eq 'ok') || ($reply eq 'delayed')) {
+ return 'ok';
+ } else {
+ return 'error: '.$reply;
+ }
}
+
###############################################################
###############################################################
-# build a domain and server selection form
-sub domain_form {
- my ($defdom) = @_;
- # Set up domain and server selection forms
+# build a role type and role selection form
+sub domain_roles_select {
+ # Set up the role type and role selection boxes when in
+ # domain context
+ #
+ # Role types
+ my @roletypes = ('domain','author','course','community');
+ my %lt = &role_type_names();
+ my $onchangefirst = "updateCols('showrole')";
+ my $onchangesecond = "updateCols('showrole')";
#
- # Get the domains
- my @domains = &Apache::lonnet::all_domains();
# build up the menu information to be passed to
# &Apache::loncommon::linked_select_forms
my %select_menus;
- foreach my $dom (@domains) {
+ if ($env{'form.roletype'} eq '') {
+ $env{'form.roletype'} = 'domain';
+ }
+ foreach my $roletype (@roletypes) {
# set up the text for this domain
- $select_menus{$dom}->{'text'}= $dom;
+ $select_menus{$roletype}->{'text'}= $lt{$roletype};
+ my $crstype;
+ if ($roletype eq 'community') {
+ $crstype = 'Community';
+ }
# we want a choice of 'default' as the default in the second menu
- $select_menus{$dom}->{'default'}= 'default';
- $select_menus{$dom}->{'select2'}->{'default'} = 'default';
+ if ($env{'form.roletype'} ne '') {
+ $select_menus{$roletype}->{'default'} = $env{'form.showrole'};
+ } else {
+ $select_menus{$roletype}->{'default'} = 'Any';
+ }
# Now build up the other items in the second menu
- my %servers = &Apache::lonnet::get_servers($dom,'library');
- foreach my $server (keys(%servers)) {
- $select_menus{$dom}->{'select2'}->{$server}
- = "$server $servers{$server}";
+ my @roles;
+ if ($roletype eq 'domain') {
+ @roles = &domain_roles();
+ } elsif ($roletype eq 'author') {
+ @roles = &construction_space_roles();
+ } else {
+ my $custom = 1;
+ @roles = &course_roles('domain',undef,$custom,$roletype);
+ }
+ my $order = ['Any',@roles];
+ $select_menus{$roletype}->{'order'} = $order;
+ foreach my $role (@roles) {
+ if ($role eq 'cr') {
+ $select_menus{$roletype}->{'select2'}->{$role} =
+ &mt('Custom role');
+ } else {
+ $select_menus{$roletype}->{'select2'}->{$role} =
+ &Apache::lonnet::plaintext($role,$crstype);
+ }
}
+ $select_menus{$roletype}->{'select2'}->{'Any'} = &mt('Any');
}
- my $result = &Apache::loncommon::linked_select_forms
- ('studentform',' with home server ',$defdom,
- 'lcdomain','lcserver',\%select_menus);
+ my $result = &Apache::loncommon::linked_select_forms
+ ('studentform',(' 'x3).&mt('Role: '),$env{'form.roletype'},
+ 'roletype','showrole',\%select_menus,
+ ['domain','author','course','community'],$onchangefirst,
+ $onchangesecond);
return $result;
}
@@ -161,7 +315,8 @@ sub hidden_input {
}
sub print_upload_manager_header {
- my ($r,$datatoken,$distotal,$krbdefdom,$context)=@_;
+ my ($r,$datatoken,$distotal,$krbdefdom,$context,$permission,$crstype,
+ $can_assign)=@_;
my $javascript;
#
if (! exists($env{'form.upfile_associate'})) {
@@ -175,9 +330,9 @@ sub print_upload_manager_header {
}
}
if ($env{'form.upfile_associate'} eq 'reverse') {
- $javascript=&upload_manager_javascript_reverse_associate();
+ $javascript=&upload_manager_javascript_reverse_associate($can_assign);
} else {
- $javascript=&upload_manager_javascript_forward_associate();
+ $javascript=&upload_manager_javascript_forward_associate($can_assign);
}
#
# Deal with restored settings
@@ -191,15 +346,31 @@ sub print_upload_manager_header {
$password_choice = 'int';
}
#
+ my $groupslist;
+ if ($context eq 'course') {
+ $groupslist = &get_groupslist();
+ }
my $javascript_validations =
- &javascript_validations('auth',$krbdefdom,$password_choice,undef,
- $env{'request.role.domain'});
- my $checked=(($env{'form.noFirstLine'})?' checked="checked" ':'');
- $r->print(&mt('Total number of records found in file: [_1].',$distotal).
- " \n");
- $r->print('
'.
- &mt('Identify fields in uploaded list')."
\n");
- $r->print(&mt('Enter as many fields as you can. The system will inform you and bring you back to this page, if the data selected are insufficient to add users.')." \n");
+ &javascript_validations('upload',$krbdefdom,$password_choice,undef,
+ $env{'request.role.domain'},$context,
+ $groupslist,$crstype);
+ my $checked=(($env{'form.noFirstLine'})?' checked="checked"':'');
+ $r->print(
+ '
'.&mt('Identify fields in uploaded list')."
\n".
+ '
'.
+ &mt('Total number of records found in file: [_1]'
+ ,''.$distotal.'').
+ "
\n"
+ );
+ if ($distotal == 0) {
+ $r->print('
'.&mt('None found').'
');
+ }
+ $r->print(
+ '
'.
+ &mt('Enter as many fields as you can.').' '.
+ &mt('The system will inform you and bring you back to this page,[_1]if the data selected are insufficient to add users.',' ').
+ "
'."\n".
- &mt('Pick the action to take on roles for these users:').' ';
- }
- if ($context eq 'construction_space') {
- $Str .= '
'.&mt('Default role')."
\n".
- &mt('Choose the role to assign to users without one 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');
+ $Str .= &Apache::lonhtmlcommon::row_closure()
+ .&Apache::lonhtmlcommon::row_title(
+ &mt('LON-CAPA Home Server for New Users'))
+ .&mt('LON-CAPA domain: [_1] with home server:','"'.$defdom.'"')
+ .$home_server_pick
+ .&Apache::lonhtmlcommon::row_closure();
} else {
- $Str .= '
'.&mt('Default role and/or section')." \n".
- &mt('Role and/or section for users without one in the uploaded file.');
+ $Str .= $home_server_pick.
+ &Apache::lonhtmlcommon::row_closure();
}
- $Str .= '
'.&mt('Course Level').' '.$cb_script.$coursepick;
+ $Str .= &Apache::lonhtmlcommon::row_title(
+ &mt('Settings for assigning roles'))
+ .&mt('Pick the action to take on roles for these users:').' '
+ .''
+ .' '
+ .' '
+ .'';
+ } elsif ($context eq 'author') {
+ $Str .= &Apache::lonhtmlcommon::row_title(
+ &mt('Default role'))
+ .&mt('Choose the role to assign to users without a value specified in the uploaded file.')
+ } elsif ($context eq 'course') {
+ if ($showcredits) {
+ $Str .= &Apache::lonhtmlcommon::row_title(
+ &mt('Default role, section and credits'))
+ .&mt('Choose the role and/or section(s) and/or credits to assign to users without values specified in the uploaded file.');
+ } else {
+ $Str .= &Apache::lonhtmlcommon::row_title(
+ &mt('Default role and section'))
+ .&mt('Choose the role and/or section(s) to assign to users without values specified in the uploaded file.');
+ }
} else {
- $Str .= $options;
- }
- if ($context eq 'course') {
- $Str .= "
".&mt('Full Update')."
\n".
- '\n";
- }
- $Str .= "
".&mt('ID/Student Number')."
\n";
- $Str .= "
\n".' '."\n".
- &mt('(only do if you know what you are doing.)')."
\n";
+ }
+ my %role_types = &role_type_names();
+ $output .= &Apache::loncommon::end_data_table_header_row();
# Done with the HTML header line
-
} elsif ($mode eq 'csv') {
#
# Open a file
$CSVfilename = '/prtspool/'.
- $env{'user.name'}.'_'.$env{'user.domain'}.'_'.
- time.'_'.rand(1000000000).'.csv';
+ $env{'user.name'}.'_'.$env{'user.domain'}.'_'.
+ time.'_'.rand(1000000000).'.csv';
unless ($CSVfile = Apache::File->new('>/home/httpd'.$CSVfilename)) {
$r->log_error("Couldn't open $CSVfilename for output $!");
- $r->print("Problems occured in writing the csv file. ".
- "This error has been logged. ".
- "Please alert your LON-CAPA administrator.");
+ $r->print(
+ '
'
+ .&mt('Problems occurred in writing the CSV file.')
+ .' '.&mt('This error has been logged.')
+ .' '.&mt('Please alert your LON-CAPA administrator.')
+ .'
'
+ );
$CSVfile = undef;
}
#
# Write headers and data to file
- if($statusmode eq 'Expired') {
- print $CSVfile '"'.&mt('Users with expired roles').'"'."\n"; }
- if($statusmode eq 'Future') {
- print $CSVfile '"'.&mt('Users with future roles').'"'."\n";
- }
+ print $CSVfile '"'.$results_description.'"'."\n";
print $CSVfile '"'.join('","',map {
&Apache::loncommon::csv_translate($lt{$_})
- } (@cols)).'"'."\n";
+ } (@cols))."\"\n";
} elsif ($mode eq 'excel') {
# Create the excel spreadsheet
($excel_workbook,$excel_filename,$format) =
&Apache::loncommon::create_workbook($r);
return if (! defined($excel_workbook));
$excel_sheet = $excel_workbook->addworksheet('userlist');
- #
- my $description;
- if ($context eq 'course') {
- $description = &mt('Class List for ').
- $env{'course.'.$env{'request.course.id'}.'.description'};
- } elsif ($context eq 'construction_space') {
- $description = &mt('List of co-authors for construction space for [_1]',
- &Apache::loncommon::plainname($env{'user.name'},$env{'user.domain'}));
- } else {
- $description = &mt('List of users for domain: [_1]',&Apache::lonnet::domain($env{'request.role.domain'},'description'));
- }
- $excel_sheet->write($row++,0,$description,$format->{'h1'});
+ $excel_sheet->write($row++,0,$results_description,$format->{'h2'});
#
my @colnames = map {$lt{$_}} (@cols);
+
$excel_sheet->write($row++,0,\@colnames,$format->{'bold'});
}
# Done with header lines in all formats
-
- #
- # Sort the users
my %index;
my $i;
- foreach (@$keylist) {
- $index{$_} = $i++;
+ foreach my $idx (@$keylist) {
+ $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';
+ }
+ }
+ my %ltstatus = &Apache::lonlocal::texthash(
+ Active => 'Active',
+ Future => 'Future',
+ Expired => 'Expired',
+ );
+ # If this is for a single course get last course "log-in".
+ my %crslogins;
+ if ($context eq 'course') {
+ %crslogins=&Apache::lonnet::dump('nohist_crslastlogin',$cdom,$cnum);
+ }
+ # Get groups, role, permanent e-mail so we can sort on them if
+ # necessary.
+ foreach my $user (keys(%{$userlist})) {
+ if ($user eq '' ) {
+ delete($userlist->{$user});
+ next;
+ }
+ if ($context eq 'domain' && $user eq $env{'request.role.domain'}.'-domainconfig:'.$env{'request.role.domain'}) {
+ delete($userlist->{$user});
+ next;
+ }
+ my ($uname,$udom,$role,$groups,$email);
+ if (($statusmode ne 'Any') &&
+ ($userlist->{$user}->[$index{'status'}] ne $statusmode)) {
+ delete($userlist->{$user});
+ next;
+ }
+ if ($context eq 'domain') {
+ if ($env{'form.roletype'} eq 'domain') {
+ ($role,$uname,$udom) = split(/:/,$user);
+ if (($uname eq $env{'request.role.domain'}.'-domainconfig') &&
+ ($udom eq $env{'request.role.domain'})) {
+ delete($userlist->{$user});
+ next;
+ }
+ } elsif ($env{'form.roletype'} eq 'author') {
+ ($uname,$udom,$role) = split(/:/,$user,-1);
+ } elsif (($env{'form.roletype'} eq 'course') ||
+ ($env{'form.roletype'} eq 'community')) {
+ ($uname,$udom,$role) = split(/:/,$user);
+ }
+ } else {
+ ($uname,$udom,$role) = split(/:/,$user,-1);
+ if (($context eq 'course') && $role eq '') {
+ $role = 'st';
+ }
+ }
+ $userlist->{$user}->[$index{'role'}] = $role;
+ if (($env{'form.showrole'} ne 'Any') && (!($env{'form.showrole'} eq 'cr' && $role =~ /^cr\//)) && ($role ne $env{'form.showrole'})) {
+ delete($userlist->{$user});
+ next;
+ }
+ 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 (($env{'request.course.sec'} ne '') &&
+ ($section ne $env{'request.course.sec'})) {
+ if ($role eq 'st') {
+ delete($userlist->{$user});
+ next;
+ }
+ }
+ 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;
+ }
+ }
+ if ($env{'course.'.$env{'request.course.id'}.'.internal.showphoto'}) {
+ if ((grep/^photo$/,@cols) && ($role eq 'st')) {
+ $userlist->{$user}->[$index{'photo'}] =
+ &Apache::lonnet::retrievestudentphoto($udom,$uname,'jpg');
+ $userlist->{$user}->[$index{'thumbnail'}] =
+ &Apache::lonnet::retrievestudentphoto($udom,$uname,
+ 'gif','thumbnail');
+ }
+ }
+ if (($role eq 'st') && ($defaultcredits)) {
+ if ($userlist->{$user}->[$index{'credits'}] eq '') {
+ $userlist->{$user}->[$index{'credits'}] = $defaultcredits;
+ }
+ }
+ }
+ }
+ my %emails = &Apache::loncommon::getemails($uname,$udom);
+ if ($emails{'permanentemail'} =~ /\S/) {
+ $userlist->{$user}->[$index{'email'}] = $emails{'permanentemail'};
+ }
+ if (($context eq 'domain') && ($env{'form.roletype'} eq 'domain') &&
+ ($role eq 'au')) {
+ my ($disk_quota,$current_disk_usage,$percent);
+ if (($needauthorusage) || ($needauthorquota)) {
+ $disk_quota = &Apache::loncommon::get_user_quota($uname,$udom,'author');
+ }
+ if ($needauthorusage) {
+ $current_disk_usage =
+ &Apache::lonnet::diskusage($udom,$uname,"$londocroot/priv/$udom/$uname");
+ if ($disk_quota == 0) {
+ $percent = 100.0;
+ } else {
+ $percent = $current_disk_usage/(10 * $disk_quota);
+ }
+ $userlist->{$user}->[$index{'authorusage'}] = sprintf("%.0f",$percent);
+ }
+ if ($needauthorquota) {
+ $userlist->{$user}->[$index{'authorquota'}] = sprintf("%.2f",$disk_quota);
+ }
+ }
+ $usercount ++;
}
- $index{'groups'} = scalar(@$keylist);
- my $index = $index{$sortby};
- my $second = $index{'username'};
- my $third = $index{'domain'};
- my @Sorted_Students = sort {
- lc($classlist->{$a}->[$index]) cmp lc($classlist->{$b}->[$index])
- ||
- lc($classlist->{$a}->[$second]) cmp lc($classlist->{$b}->[$second]) ||
- lc($classlist->{$a}->[$third]) cmp lc($classlist->{$b}->[$third])
- } (keys(%$classlist));
- my $studentcount = 0;
my $autocount = 0;
my $manualcount = 0;
- my $unlockcount = 0;
my $lockcount = 0;
- foreach my $student (@Sorted_Students) {
- my $sdata = $classlist->{$student};
- my $groups = $classgroups->{$student};
- my $username = $sdata->[$index{'username'}];
- my $domain = $sdata->[$index{'domain'}];
- my $section = $sdata->[$index{'section'}];
- my $active_groups;
- if (ref($groups->{active}) eq 'HASH') {
- $active_groups = join(', ',keys(%{$groups->{'active'}}));
+ my $unlockcount = 0;
+ if ($usercount) {
+ $r->print($output);
+ } else {
+ if ($mode eq 'autoenroll') {
+ return ($usercount,$autocount,$manualcount,$lockcount,$unlockcount);
+ } else {
+ return;
}
- my $name = $sdata->[$index{'fullname'}];
- my $id = $sdata->[$index{'id'}];
- my $status = $sdata->[$index{'status'}];
- next if (($statusmode ne 'Any') && ($status ne $statusmode));
- my $start = $sdata->[$index{'start'}];
- my $end = $sdata->[$index{'end'}];
- if (! defined($start) || $start == 0) {
- $start = &mt('none');
+ }
+ #
+ # Sort the users
+ my $index = $index{$sortby};
+ my $second = $index{'username'};
+ my $third = $index{'domain'};
+ my @sorted_users;
+ if (($sortby eq 'authorquota') || ($sortby eq 'authorusage')) {
+ @sorted_users = sort {
+ $userlist->{$b}->[$index] <=> $userlist->{$a}->[$index] ||
+ lc($userlist->{$a}->[$second]) cmp lc($userlist->{$b}->[$second]) ||
+ lc($userlist->{$a}->[$third]) cmp lc($userlist->{$b}->[$third])
+ } (keys(%$userlist));
+ } else {
+ @sorted_users = sort {
+ lc($userlist->{$a}->[$index]) cmp lc($userlist->{$b}->[$index]) ||
+ lc($userlist->{$a}->[$second]) cmp lc($userlist->{$b}->[$second]) ||
+ lc($userlist->{$a}->[$third]) cmp lc($userlist->{$b}->[$third])
+ } (keys(%$userlist));
+ }
+ my $rowcount = 0;
+ my $disabled;
+ if ($mode eq 'autoenroll') {
+ unless ($permission->{'cusr'}) {
+ $disabled = ' disabled="disabled"';
+ }
+ }
+ foreach my $user (@sorted_users) {
+ my %in;
+ my $sdata = $userlist->{$user};
+ $rowcount ++;
+ foreach my $item (@{$keylist}) {
+ $in{$item} = $sdata->[$index{$item}];
+ }
+ my $clickers = (&Apache::lonnet::userenvironment($in{'domain'},$in{'username'},'clickers'))[1];
+ if ($clickers!~/\w/) { $clickers='-'; }
+ $in{'clicker'} = $clickers;
+ my $role = $in{'role'};
+ $in{'role'}=&Apache::lonnet::plaintext($sdata->[$index{'role'}],$crstype);
+ unless ($mode eq 'excel') {
+ if (! defined($in{'start'}) || $in{'start'} == 0) {
+ $in{'start'} = &mt('none');
+ } else {
+ $in{'start'} = &Apache::lonlocal::locallocaltime($in{'start'});
+ }
+ if (! defined($in{'end'}) || $in{'end'} == 0) {
+ $in{'end'} = &mt('none');
+ } else {
+ $in{'end'} = &Apache::lonlocal::locallocaltime($in{'end'});
+ }
+ }
+ if ($context eq 'course') {
+ my $lastlogin = $crslogins{$in{'username'}.':'.$in{'domain'}.':'.$in{'section'}.':'.$role};
+ if ($lastlogin ne '') {
+ $in{'lastlogin'} = &Apache::lonlocal::locallocaltime($lastlogin);
+ }
+ }
+ if ($mode eq 'view' || $mode eq 'html' || $mode eq 'autoenroll' || $mode eq 'pickauthor') {
+ $r->print(&Apache::loncommon::start_data_table_row());
+ my $checkval;
+ if ($mode eq 'autoenroll') {
+ my $cellentry;
+ if ($in{'type'} eq 'auto') {
+ $cellentry = ''.&mt('auto').' '.&mt('Change').'';
+ $autocount ++;
+ } else {
+ $cellentry = '
END
return;
}
-
-
#
# Print out the initial form to get the file containing a list of users
#
sub print_first_users_upload_form {
my ($r,$context) = @_;
my $str;
- $str = '';
+ $str = '';
$str .= '';
- $str .= '';
- $str .= "
\n";
- $str .= &Apache::loncommon::help_open_topic("Course_Create_Class_List",
- &mt("How do I create a users list from a spreadsheet")).
- " \n";
- $str .= &Apache::loncommon::help_open_topic("Course_Convert_To_CSV",
- &mt("How do I create a CSV file from a spreadsheet")).
- " \n";
- $str .= &Apache::loncommon::end_page();
+ $str .= '';
+
+ $str .= &Apache::grades::checkforfile_js();
+
+ $str .= '
'.&mt('Upload a file containing information about users').'
'."\n";
+
+ # Excel and CSV Help
+ $str .= '
'
+ .&Apache::loncommon::help_open_topic("Course_Create_Class_List",
+ &mt("How do I create a users list from a spreadsheet"))
+ .' '.&Apache::loncommon::help_open_topic("Course_Convert_To_CSV",
+ &mt("How do I create a CSV file from a spreadsheet"))
+ ."
\n";
+ $str .= &Apache::lonhtmlcommon::start_pick_box()
+ .&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"
+ .'
';
+
$r->print($str);
return;
}
# ================================================= Drop/Add from uploaded file
sub upfile_drop_add {
- my ($r,$context) = @_;
+ my ($r,$context,$permission,$showcredits) = @_;
&Apache::loncommon::load_tmp_file($r);
my @userdata=&Apache::loncommon::upfile_record_sep();
if($env{'form.noFirstLine'}){shift(@userdata);}
@@ -1607,36 +4127,91 @@ sub upfile_drop_add {
$fields{$env{'form.f'.$i}}=$keyfields[$i];
}
}
+ if ($env{'form.fullup'} ne 'yes') {
+ $r->print('');
+ $r->print(&print_namespacing_alerts($domain,\%alerts,\%curr_rules));
#####################################
- # 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");
- } else {
+ $r->print(''."\n");
+ } elsif (ref($classlist) eq 'HASH') {
# 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'}}.
@@ -1906,21 +4924,65 @@ 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 {
+ my ($domain,$alerts,$curr_rules) = @_;
+ my $output;
+ if (ref($alerts) eq 'HASH') {
+ if (keys(%{$alerts}) > 0) {
+ if (ref($alerts->{'username'}) eq 'HASH') {
+ foreach my $dom (sort(keys(%{$alerts->{'username'}}))) {
+ my $count;
+ if (ref($alerts->{'username'}{$dom}) eq 'HASH') {
+ $count = keys(%{$alerts->{'username'}{$dom}});
+ }
+ my $domdesc = &Apache::lonnet::domain($domain,'description');
+ if (ref($curr_rules->{$dom}) eq 'HASH') {
+ $output .= &Apache::loncommon::instrule_disallow_msg(
+ 'username',$domdesc,$count,'upload');
+ }
+ $output .= &Apache::loncommon::user_rule_formats($dom,
+ $domdesc,$curr_rules->{$dom}{'username'},
+ 'username');
+ }
+ }
+ if (ref($alerts->{'id'}) eq 'HASH') {
+ foreach my $dom (sort(keys(%{$alerts->{'id'}}))) {
+ my $count;
+ if (ref($alerts->{'id'}{$dom}) eq 'HASH') {
+ $count = keys(%{$alerts->{'id'}{$dom}});
+ }
+ my $domdesc = &Apache::lonnet::domain($domain,'description');
+ if (ref($curr_rules->{$dom}) eq 'HASH') {
+ $output .= &Apache::loncommon::instrule_disallow_msg(
+ 'id',$domdesc,$count,'upload');
+ }
+ $output .= &Apache::loncommon::user_rule_formats($dom,
+ $domdesc,$curr_rules->{$dom}{'id'},'id');
+ }
+ }
+ }
+ }
}
sub user_change_result {
- my ($r,$userresult,$authresult,$roleresult,$counts,$flushc,$username,
- $userchg) = @_;
+ my ($r,$userresult,$authresult,$roleresult,$idresult,$counts,$flushc,
+ $username,$userdomain,$userchg) = @_;
my $okresult = 0;
+ my @status;
if ($userresult ne 'ok') {
if ($userresult =~ /^error:(.+)$/) {
my $error = $1;
- $r->print(' '.
- &mt('[_1]: Unable to add/modify: [_2]',$username,$error));
+ push(@status,
+ &mt('[_1]: Unable to add/modify: [_2]',''.$username.':'.$userdomain.'',$error));
}
} else {
$counts->{'user'} ++;
@@ -1929,8 +4991,8 @@ sub user_change_result {
if ($authresult ne 'ok') {
if ($authresult =~ /^error:(.+)$/) {
my $error = $1;
- $r->print(' '.
- &mt('[_1]: Unable to modify authentication: [_2]',$username,$error));
+ push(@status,
+ &mt('[_1]: Unable to modify authentication: [_2]',''.$username.':'.$userdomain.'',$error));
}
} else {
$counts->{'auth'} ++;
@@ -1939,8 +5001,8 @@ sub user_change_result {
if ($roleresult ne 'ok') {
if ($roleresult =~ /^error:(.+)$/) {
my $error = $1;
- $r->print(' '.
- &mt('[_1]: Unable to add role: [_2]',$username,$error));
+ push(@status,
+ &mt('[_1]: Unable to add role: [_2]',''.$username.':'.$userdomain.'',$error));
}
} else {
$counts->{'role'} ++;
@@ -1948,73 +5010,462 @@ sub user_change_result {
}
if ($okresult) {
$flushc++;
- $userchg->{$username}=1;
- $r->print('. ');
+ $userchg->{$username.':'.$userdomain}=1;
if ($flushc>15) {
$r->rflush;
$flushc=0;
}
}
+ if ($idresult) {
+ push(@status,$idresult);
+ }
+ if (@status) {
+ $r->print('
'.join(' ',@status).'
');
+ }
return $flushc;
}
# ========================================================= Menu Phase Two Drop
-sub print_expire_menu {
- my ($r,$context) = @_;
- $r->print("
".&mt("Expire Users' Roles")."
");
- my $cid=$env{'request.course.id'};
- my ($classlist,$keylist) = &Apache::loncoursedata::get_classlist();
+sub print_drop_menu {
+ my ($r,$context,$permission,$crstype) = @_;
+ my $heading;
+ if ($crstype eq 'Community') {
+ $heading = &mt("Drop Members");
+ } else {
+ $heading = &mt("Drop Students");
+ }
+ $r->print('
'.$heading.'
'."\n".
+ '');
return;
}
-
# ================================================================== Phase four
-sub expire_user_list {
- my ($r,$context) = @_;
+sub update_user_list {
+ my ($r,$context,$setting,$choice,$crstype) = @_;
+ 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'});
+ if ($context eq 'course') {
+ $crstype = &Apache::loncommon::course_type();
+ }
+ my @changelist;
+ 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',
+ 'reenable' => 'Re-enabled',
+ 'activate' => 'Activated',
+ 'chgdates' => 'Changed Access Dates for',
+ 'chgsec' => 'Changed section(s) for',
+ 'drop' => 'Dropped',
+ },
+ error => {'revoke' => 'revoking',
+ 'delete' => 'deleting',
+ 'reenable' => 're-enabling',
+ 'activate' => 'activating',
+ 'chgdates' => 'changing access dates for',
+ 'chgsec' => 'changing section for',
+ 'drop' => 'dropping',
+ },
+ );
+ 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,$singlesec,$showsecs,$warn_singlesec,
+ $nothingtodo,$keepnosection,$credits,$instsec);
+ if ($choice eq 'drop') {
+ ($uname,$udom,$sec) = split(/:/,$item,-1);
+ $role = 'st';
+ $cid = $env{'request.course.id'};
+ $scopestem = '/'.$cid;
+ $scopestem =~s/\_/\//g;
+ if ($sec eq '') {
+ $scope = $scopestem;
+ } else {
+ $scope = $scopestem.'/'.$sec;
+ }
+ } elsif ($context eq 'course') {
+ ($uname,$udom,$role,$sec,$type,$locktype,$credits,$instsec) =
+ split(/\:/,$item,8);
+ $instsec = &unescape($instsec);
+ $cid = $env{'request.course.id'};
+ $scopestem = '/'.$cid;
+ $scopestem =~s/\_/\//g;
+ if ($sec eq '') {
+ $scope = $scopestem;
+ } else {
+ $scope = $scopestem.'/'.$sec;
+ }
+ } elsif ($context eq 'author') {
+ ($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 'author') {
+ ($uname,$udom,$role,$scope) = split(/\:/,$item);
+ } elsif ($setting eq 'course') {
+ ($uname,$udom,$role,$cid,$sec,$type,$locktype,$credits,$instsec) =
+ split(/\:/,$item,9);
+ $instsec = &unescape($instsec);
+ $scope = '/'.$cid;
+ $scope =~s/\_/\//g;
+ if ($sec ne '') {
+ $scope .= '/'.$sec;
+ }
+ }
+ }
+ my $plrole = &Apache::lonnet::plaintext($role,$crstype);
+ my $start = $env{'form.'.$item.'_start'};
+ my $end = $env{'form.'.$item.'_end'};
+ if ($choice eq 'drop') {
+ # drop students
+ $end = $now;
+ $type = 'manual';
+ $result =
+ &Apache::lonnet::modify_student_enrollment($udom,$uname,undef,undef,undef,undef,undef,$sec,$end,$start,$type,$locktype,$cid,'',$context);
+ } elsif ($choice eq 'revoke') {
+ # revoke or delete user role
+ $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,'',$context,$credits,$instsec);
+ } else {
+ $result =
+ &Apache::lonnet::revokerole($udom,$uname,$scope,$role,
+ '','',$context);
+ }
+ } elsif ($choice eq 'delete') {
+ if ($role eq 'st') {
+ &Apache::lonnet::modify_student_enrollment($udom,$uname,undef,undef,undef,undef,undef,$sec,$now,$start,$type,$locktype,$cid,'',$context,$credits,$instsec);
+ }
+ $result =
+ &Apache::lonnet::assignrole($udom,$uname,$scope,$role,$now,
+ $start,1,'',$context);
+ } 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,'',$context,$credits,$instsec);
+ } else {
+ $result =
+ &Apache::lonnet::assignrole($udom,$uname,$scope,$role,$end,
+ $now,'','',$context);
+ }
+ } 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,'',$context,$credits,$instsec);
+ } else {
+ $result = &Apache::lonnet::assignrole($udom,$uname,$scope,$role,$end,
+ $now,'','',$context);
+ }
+ } 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,'',$context,$credits,$instsec);
+ } else {
+ $result = &Apache::lonnet::assignrole($udom,$uname,$scope,$role,$end,
+ $start,'','',$context);
+ }
+ } 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);
+ }
+ }
+ }
+ # remove existing section if not to be retained.
+ if (!$env{'form.retainsec'} || ($role eq 'st')) {
+ if ($sec eq '') {
+ if (@newsecs == 0) {
+ $result = 'ok';
+ $nochg = 1;
+ $nothingtodo = 1;
+ } else {
+ $revresult =
+ &Apache::lonnet::revokerole($udom,$uname,
+ $scope,$role,
+ '','',$context);
+ }
+ } else {
+ if (@newsecs > 0) {
+ if (grep(/^\Q$sec\E$/,@newsecs)) {
+ push(@retained,$sec);
+ } else {
+ $revresult =
+ &Apache::lonnet::revokerole($udom,$uname,
+ $scope,$role,
+ '','',$context);
+ }
+ } else {
+ $revresult =
+ &Apache::lonnet::revokerole($udom,$uname,
+ $scope,$role,
+ '','',$context);
+ }
+ }
+ } 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 ($role eq 'st') {
+ $result =
+ &Apache::lonnet::modify_student_enrollment($udom,$uname,undef,undef,undef,undef,undef,undef,$end,$start,$type,$locktype,$cid,'',$context,$credits,$instsec);
+ } else {
+ my $newscope = $scopestem;
+ $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,$credits,$instsec);
+ 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);
+
+ }
+ }
+ }
+ }
+ unless ($role eq 'st') {
+ unless ($showsecs) {
+ my @tolist = sort(@shownew,@retained);
+ if ($keepnosection) {
+ push(@tolist,&mt('No section'));
+ }
+ $showsecs = join(', ',@tolist);
+ }
+ }
+ }
+ }
+ my $extent = $scope;
+ if ($choice eq 'drop' || $context eq 'course') {
+ my ($cnum,$cdom,$cdesc) = &get_course_identity($cid);
+ if ($cdesc) {
+ $extent = $cdesc;
+ }
+ }
if ($result eq 'ok' || $result eq 'ok:') {
- $r->print(&mt('Dropped [_1]',$uname.'@'.$udom).' ');
- $count++;
+ 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 ++;
+ }
} else {
$r->print(
- &mt('Error dropping [_1]:[_2]',$uname.'@'.$udom,$result).
- ' ');
+ &mt("Error $result_text{'error'}{$choice} [_1] in [_2] for '[_3]': [_4].",
+ $plrole,$extent,
+ ''.&Apache::loncommon::plainname($uname,$udom).'',
+ $result).' ');
}
}
- $r->print('
'.&mt('Dropped [_1] user(s).',$count).'
');
- $r->print('
'.&mt('Re-enrollment will re-activate data.')) if ($count);
+ $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 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) = @_;
+ my ($cdom,$cnum) = ($scope=~m{^/($match_domain)/($match_courseid)});
+ if (&Apache::lonnet::is_course($cdom,$cnum)) {
+ if (!&active_student_roles($cnum,$cdom,$uname,$udom)) {
+ my %user;
+ my $result = &update_classlist($cdom,$cnum,$udom,$uname,\%user,$now);
+ 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();
+ my %js_lt = &Apache::lonlocal::texthash(
+ mayn => 'may not be used as the name for a section, as it is a reserved word.',
+ 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.',
+ );
+ &js_escape(\%js_lt);
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.");
+ alert("'"+secname+"' $js_lt{'mayn'}\\n$js_lt{'plch'}");
return 'error';
}
if (secname != '') {
for (var k=0; k $b} keys(%{$sections_count}));
+ my $numsec = scalar(@sections);
+ my $is_selected = ' selected="selected"';
+ if ($numsec <= 1) {
+ $output = ''."\n".
+ '