'.
+ &mt("The following roles could not be assigned because the user is from another domain, and that domain's policies require approval by the user themselves or by a domain coordinator in that domain, and approval has been withheld.").'
'.
+ &mt("The following role assignments have been queued because the user is from another domain, and that domain's policies require approval by the user themselves or by a domain coordinator in that domain").'
';
+ my (%todom,%touser,%crsqueue,%caqueue,%domqueue);
+ my $requester = $env{'user.name'}.':'.$env{'user.domain'};
+ foreach my $key (sort(keys(%{$pending}))) {
+ if (ref($pending->{$key}) eq 'HASH') {
+ foreach my $user (sort(keys(%{$pending->{$key}}))) {
+ if (ref($pending->{$key}->{$user}) eq 'HASH') {
+ my $role = $pending->{$key}->{$user}{'role'};
+ my $uname = $pending->{$key}->{$user}{'uname'};
+ my $udom = $pending->{$key}->{$user}{'udom'};
+ my $csec = $pending->{$key}->{$user}{'csec'};
+ my $cdom = $pending->{$key}->{$user}{'cdom'};
+ my $cnum = $pending->{$key}->{$user}{'cnum'};
+ my $adj = $pending->{$key}->{$user}{'adj'};
+ my $start = $pending->{$key}->{$user}{'start'};
+ my $end = $pending->{$key}->{$user}{'end'};
+ my $credits = $pending->{$key}->{$user}{'credits'};
+ my $now = time;
+ my ($crstype,$title,$plainrole,$extent,$id,$status);
+ if ($context eq 'course') {
+ $crstype = &Apache::loncommon::course_type();
+ $title = $env{'course.'.$env{'request.course.id'}.'.description'};
+ } elsif ($context eq 'domain') {
+ if (&Apache::lonnet::is_course($cdom,$cnum)) {
+ my %coursedata = &Apache::lonnet::coursedescription($cdom.'_'.$cnum);
+ $crstype = $coursedata{'type'};
+ $title = $coursedata{'description'};
+ } elsif (($role eq 'ca') || ($role eq 'aa')) {
+ $title = &Apache::loncommon::plainname($cnum,$cdom);
+ }
+ }
+ $plainrole = &Apache::lonnet::plaintext($role,$crstype);
+ $extent = "/$cdom/$cnum";
+ $id = $uname.':'.$udom.':'.$role;
+ if (($context eq 'course') || ($crstype)) {
+ $id .= ':'.$csec;
+ }
+ $output .= '
';
+ if (keys(%touser)) {
+ foreach my $key (keys(%touser)) {
+ my ($uname,$udom) = split(/:/,$touser{$key});
+ if (&Apache::lonnet::put('nohist_queuedrolereqs',$touser{$key},$udom,$uname) eq 'ok') {
+ my $owndomdesc = &Apache::lonnet::domain($udom);
+ &Apache::loncoursequeueadmin::send_selfserve_notification($uname.':'.$udom,
+ '','',$owndomdesc,$now,'othdomroleuser',$requester);
+ }
+ }
+ }
+ if (keys(%todom)) {
+ foreach my $dom (keys(%todom)) {
+ if (ref($todom{$dom}) eq 'HASH') {
+ my $confname = &Apache::lonnet::get_domainconfiguser($dom);
+ if (&Apache::lonnet::put('nohist_queuedrolereqs',$todom{$dom},$dom,$confname) eq 'ok') {
+ if (ref($notifydc->{$dom}) eq 'ARRAY') {
+ if (@{$notifydc->{$dom}} > 0) {
+ my $notifylist = join(',',@{$notifydc->{$dom}});
+ &Apache::loncoursequeueadmin::send_selfserve_notification($notifylist,
+ '','','',$now,'othdomroledc',$requester);
+ }
+ }
+ }
+ }
+ }
+ }
+ if (keys(%crsqueue)) {
+ foreach my $key (keys(%crsqueue)) {
+ my ($cdom,$cnum) = split(/_/,$key);
+ if (ref($crsqueue{$key}) eq 'HASH') {
+ &Apache::lonnet::put('nohist_othdomqueued',$crsqueue{$key},$cdom,$cnum);
+ }
+ }
+ }
+ if (keys(%caqueue)) {
+ foreach my $key (keys(%caqueue)) {
+ my ($auname,$audom) = split(/:/,$key);
+ if (ref($caqueue{$key}) eq 'HASH') {
+ &Apache::lonnet::put('nohist_othdomqueued',$caqueue{$key},$audom,$auname);
+ }
+ }
+ }
+ if (keys(%domqueue)) {
+ my $confname = &Apache::lonnet::get_domainconfiguser($env{'request.role.domain'});
+ &Apache::lonnet::put('nohist_othdomqueued',\%domqueue,$env{'request.role.domain'},$confname);
+ }
+ }
+ if (keys(%{$currqueued}) > 0) {
+ $output = '
'.
+ &mt("The following role assignments were already queued because the user is from another domain, and that domain's policies require approval by the user themselves or by a domain coordinator in that domain").'
';
+ my $requester = $env{'user.name'}.':'.$env{'user.domain'};
+ foreach my $key (sort(keys(%{$currqueued}))) {
+ if (ref($currqueued->{$key}) eq 'HASH') {
+ foreach my $user (sort(keys(%{$currqueued->{$key}}))) {
+ if (ref($currqueued->{$key}->{$user}) eq 'HASH') {
+ my $role = $currqueued->{$key}->{$user}{'role'};
+ my $csec = $currqueued->{$key}->{$user}{'csec'};
+ my $cdom = $currqueued->{$key}->{$user}{'cdom'};
+ my $cnum = $currqueued->{$key}->{$user}{'cnum'};
+ my ($crstype,$title,$plainrole);
+ if ($context eq 'course') {
+ $crstype = &Apache::loncommon::course_type();
+ } elsif (($context eq 'domain') && ($cnum ne '')) {
+ if (($role eq 'ca') || ($role eq 'aa')) {
+ $title = &mt('Authoring Space belonging to: [_1]',
+ &Apache::loncommon::plainname($cnum,$cdom));
+ } elsif (&Apache::lonnet::is_course($cdom,$cnum)) {
+ my %coursedata = &Apache::lonnet::coursedescription($cdom.'_'.$cnum);
+ $crstype = $coursedata{'type'};
+ $title = &mt("$crstype: [_1]",$coursedata{'description'});
+ }
+ }
+ $plainrole = &Apache::lonnet::plaintext($role,$crstype);
+ $output .= '
';
+ }
+ return $output;
+}
+
sub propagate_id_change {
my ($uname,$udom,$user) = @_;
my (@types,@roles);
@@ -145,7 +720,7 @@ sub propagate_id_change {
one_time => 1,
);
foreach my $item (keys(%roleshash)) {
- my ($cnum,$cdom,$role) = split(/:/,$item);
+ 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);
@@ -166,7 +741,7 @@ sub propagate_id_change {
}
sub update_classlist {
- my ($cdom,$cnum,$udom,$uname,$user) = @_;
+ my ($cdom,$cnum,$udom,$uname,$user,$newend) = @_;
my ($uid,$classlistentry);
my $fullname =
&Apache::lonnet::format_name($user->{'firstname'},$user->{'middlename'},
@@ -177,15 +752,37 @@ sub update_classlist {
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 == $ididx) {
+ 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) {
- $classlistentry .= $fullname.':';
+ if (defined($user->{'lastname'})) {
+ $classlistentry .= $fullname.':';
+ } else {
+ $classlistentry .= $classinfo[$i].':';
+ }
} else {
$classlistentry .= $classinfo[$i].':';
}
@@ -210,8 +807,10 @@ sub domain_roles_select {
# domain context
#
# Role types
- my @roletypes = ('domain','author','course');
+ my @roletypes = ('domain','author','course','community');
my %lt = &role_type_names();
+ my $onchangefirst = "updateCols('showrole')";
+ my $onchangesecond = "updateCols('showrole')";
#
# build up the menu information to be passed to
# &Apache::loncommon::linked_select_forms
@@ -222,6 +821,10 @@ sub domain_roles_select {
foreach my $roletype (@roletypes) {
# set up the text for this domain
$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
if ($env{'form.roletype'} ne '') {
$select_menus{$roletype}->{'default'} = $env{'form.showrole'};
@@ -236,7 +839,7 @@ sub domain_roles_select {
@roles = &construction_space_roles();
} else {
my $custom = 1;
- @roles = &course_roles('domain',undef,$custom);
+ @roles = &course_roles('domain',undef,$custom,$roletype);
}
my $order = ['Any',@roles];
$select_menus{$roletype}->{'order'} = $order;
@@ -246,14 +849,16 @@ sub domain_roles_select {
&mt('Custom role');
} else {
$select_menus{$roletype}->{'select2'}->{$role} =
- &Apache::lonnet::plaintext($role);
+ &Apache::lonnet::plaintext($role,$crstype);
}
}
$select_menus{$roletype}->{'select2'}->{'Any'} = &mt('Any');
}
my $result = &Apache::loncommon::linked_select_forms
('studentform',(' 'x3).&mt('Role: '),$env{'form.roletype'},
- 'roletype','showrole',\%select_menus,['domain','author','course']);
+ 'roletype','showrole',\%select_menus,
+ ['domain','author','course','community'],$onchangefirst,
+ $onchangesecond);
return $result;
}
@@ -265,7 +870,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'})) {
@@ -279,9 +885,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
@@ -295,15 +901,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 'author') {
- $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 .= $options;
+ $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 .= '
'.&mt('role').': '.
- $options.'
'.
- ''.&mt('section').':
';
- }
- if ($context eq 'course') {
- $Str .= "
".&mt('Full Update')."
\n".
- '\n";
+ $Str .= &Apache::lonhtmlcommon::row_title(
+ &mt('Default role and/or section(s)'))
+ .&mt('Role and/or section(s) for users without values specified in the uploaded file.');
+ }
+ if (($context eq 'domain') || ($context eq 'author')) {
+ $Str .= ' ';
+ my ($options,$cb_script,$coursepick) =
+ &default_role_selector($context,1,'',$showcredits);
+ if ($context eq 'domain') {
+ $Str .= '
'
+ .''.&mt('Domain Level').' '
+ .$options
+ .'
'
+ .''.&mt('Course Level').''
+ .'
'
+ .$cb_script.$coursepick
+ .&Apache::lonhtmlcommon::row_closure();
+ } elsif ($context eq 'author') {
+ $Str .= $options
+ .&Apache::lonhtmlcommon::row_closure(1); # last row in pick_box
+ }
+ } else {
+ my ($cnum,$cdom) = &get_course_identity();
+ my $rowtitle = &mt('section');
+ my $defaultcredits;
+ if ($showcredits) {
+ $defaultcredits = &get_defaultcredits();
+ }
+ my $secbox = §ion_picker($cdom,$cnum,'Any',$rowtitle,$permission,
+ $context,'upload',$crstype,$showcredits,
+ $defaultcredits);
+ $Str .= $secbox
+ .&Apache::lonhtmlcommon::row_closure();
+ my %lt;
+ if ($crstype eq 'Community') {
+ %lt = &Apache::lonlocal::texthash (
+ disp => 'Display members with current/future access who are not in the uploaded file',
+ stus => 'Members selected from this list can be dropped.'
+ );
+ } else {
+ %lt = &Apache::lonlocal::texthash (
+ disp => 'Display students with current/future access who are not in the uploaded file',
+ stus => 'Students selected from this list can be dropped.'
+ );
+ }
+ $Str .= &Apache::lonhtmlcommon::row_title(&mt('Full Update'))
+ .' '
+ .$lt{'stus'}
+ .&Apache::lonhtmlcommon::row_closure();
}
if ($context eq 'course' || $context eq 'domain') {
- $Str .= &forceid_change($context);
- }
- $Str .= '
\n".' '."\n".
- &mt('(only do if you know what you are doing.)')." \n";
+ ''.&Apache::loncommon::help_open_topic('ForceIDChange')."\n";
if ($context eq 'domain') {
- $output .= '
'."\n";
+ $output .=
+ ' '
+ .''."\n";
}
return $output;
}
@@ -771,14 +1689,21 @@ sub forceid_change {
###############################################################
###############################################################
sub print_upload_manager_form {
- my ($r,$context) = @_;
+ my ($r,$context,$permission,$crstype,$showcredits) = @_;
my $firstLine;
my $datatoken;
if (!$env{'form.datatoken'}) {
$datatoken=&Apache::loncommon::upfile_store($r);
} else {
- $datatoken=$env{'form.datatoken'};
- &Apache::loncommon::load_tmp_file($r);
+ $datatoken=&Apache::loncommon::valid_datatoken($env{'form.datatoken'});
+ if ($datatoken ne '') {
+ &Apache::loncommon::load_tmp_file($r,$datatoken);
+ }
+ }
+ if ($datatoken eq '') {
+ $r->print('
\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') {
@@ -2029,9 +3374,13 @@ END
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;
}
#
@@ -2039,7 +3388,7 @@ END
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) =
@@ -2049,20 +3398,45 @@ END
$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
-
my %index;
my $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;
@@ -2083,7 +3457,8 @@ END
}
} elsif ($env{'form.roletype'} eq 'author') {
($uname,$udom,$role) = split(/:/,$user,-1);
- } elsif ($env{'form.roletype'} eq 'course') {
+ } elsif (($env{'form.roletype'} eq 'course') ||
+ ($env{'form.roletype'} eq 'community')) {
($uname,$udom,$role) = split(/:/,$user);
}
} else {
@@ -2097,16 +3472,86 @@ 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 (($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 ++;
}
my $autocount = 0;
@@ -2127,13 +3572,27 @@ END
my $index = $index{$sortby};
my $second = $index{'username'};
my $third = $index{'domain'};
- my @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 @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};
@@ -2141,115 +3600,160 @@ END
foreach my $item (@{$keylist}) {
$in{$item} = $sdata->[$index{$item}];
}
- my $role = $in{'role'};
- $in{'role'}=&Apache::lonnet::plaintext($sdata->[$index{'role'}]);
- if (! defined($in{'start'}) || $in{'start'} == 0) {
- $in{'start'} = &mt('none');
- } else {
- $in{'start'} = &Apache::lonlocal::locallocaltime($in{'start'});
+ 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 (! 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') {
+ 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').' ';
+ $cellentry = ''.&mt('auto').' ';
$autocount ++;
} else {
- $cellentry = '
\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"
+ .'
');
+ for (my $i=0; $i<=$counter; $i++) {
+ if ($disallow{$i}) {
+ $r->print('
'.$disallow{$i}.'
');
+ } elsif (ref($userinfo{$i}) eq 'HASH') {
+ my $password = $userinfo{$i}{'password'};
+ my $newuser = $userinfo{$i}{'newuser'};
+ my $checkid = $userinfo{$i}{'checkid'};
+ my $id = $userinfo{$i}{'id'};
+ my $role = $userinfo{$i}{'role'};
+ my @secs;
+ if (ref($userinfo{$i}{'sections'}) eq 'ARRAY') {
+ @secs = @{$userinfo{$i}{'sections'}};
+ }
+ my $fname = $userinfo{$i}{'fname'};
+ my $mname = $userinfo{$i}{'mname'};
+ my $lname = $userinfo{$i}{'lname'};
+ my $gen = $userinfo{$i}{'gen'};
+ my $email = $userinfo{$i}{'email'};
+ my $inststatus = $userinfo{$i}{'inststatus'};
+ my $credits = $userinfo{$i}{'credits'};
+ my $username = $userinfo{$i}{'username'};
+ my $userdomain = $userinfo{$i}{'domain'};
+ my $user = $username.':'.$userdomain;
+ if ($newuser) {
+ if (ref($alerts{'username'}) eq 'HASH') {
+ if (ref($alerts{'username'}{$userdomain}) eq 'HASH') {
+ if ($alerts{'username'}{$userdomain}{$username}) {
+ $r->print('
'.
+ &mt('[_1]: matches the username format at your institution, but is not known to your directory service.',''.$username.'').' '.
+ &mt('Consequently, the user was not created.').'
');
+ next;
+ }
+ }
+ }
+ if (ref($inst_results{$user}) eq 'HASH') {
+ if ($inst_results{$user}{'firstname'} ne '') {
+ $fname = $inst_results{$user}{'firstname'};
+ }
+ if ($inst_results{$user}{'middlename'} ne '') {
+ $mname = $inst_results{$user}{'middlename'};
+ }
+ if ($inst_results{$user}{'lasttname'} ne '') {
+ $lname = $inst_results{$user}{'lastname'};
+ }
+ if ($inst_results{$user}{'permanentemail'} ne '') {
+ $email = $inst_results{$user}{'permanentemail'};
+ }
+ if ($inst_results{$user}{'id'} ne '') {
+ $id = $inst_results{$user}{'id'};
+ $checkid = 0;
+ }
+ if (ref($inst_results{$user}{'inststatus'}) eq 'ARRAY') {
+ $inststatus = join(':',@{$inst_results{$user}{'inststatus'}});
}
}
- if ($checkid) {
- my $checkhash;
- my $checks = { 'id' => 1 };
- $checkhash->{$username.':'.$domain} = { 'newuser' => $newuser,
- 'id' => $id };
- &Apache::loncommon::user_rule_check($checkhash,$checks,
- \%alerts,\%rulematch,\%idinst_results,\%curr_rules,
- \%got_rules);
+ if (($checkid) && ($id ne '')) {
if (ref($alerts{'id'}) eq 'HASH') {
- if (ref($alerts{'id'}{$domain}) eq 'HASH') {
- next if ($alerts{'id'}{$domain}{$id});
+ if (ref($alerts{'id'}{$userdomain}) eq 'HASH') {
+ if ($alerts{'id'}{$userdomain}{$username}) {
+ $r->print('
'.
+ &mt('[_1]: has a student/employee ID matching the format at your institution, but the ID is not found by your directory service.',
+ ''.$username.'').' '.
+ &mt('Consequently, the user was not created.').'
'.
+ &mt('[_1]: The user does not exist, and you are not permitted to create users of type: [_2].',''.$username.'',$showtype).'
');
+ next;
+ }
+ } elsif ($id ne '') {
+ if (exists($checkids{$user})) {
+ $checkid = 1;
+ if (ref($alerts{'id'}) eq 'HASH') {
+ if (ref($alerts{'id'}{$userdomain}) eq 'HASH') {
+ if ($alerts{'id'}{$userdomain}{$username}) {
+ $r->print('
'.
+ &mt('[_1]: has a student/employee ID matching the format at your institution, but the ID is not found by your directory service.',
+ ''.$username.'').' '.
+ &mt('Consequently, the ID was not changed.').'
');
+ $id = '';
+ }
}
}
}
}
- if ($password || $env{'form.login'} eq 'loc') {
- my ($userresult,$authresult,$roleresult);
- if ($role eq 'st') {
- &modifystudent($domain,$username,$cid,$sec,
- $desiredhost);
- $roleresult =
- &Apache::lonnet::modifystudent
- ($domain,$username,$id,$amode,$password,
- $fname,$mname,$lname,$gen,$sec,$enddate,
- $startdate,$env{'form.forceid'},
- $desiredhost,$email);
- } else {
- ($userresult,$authresult,$roleresult) =
+ my $multiple = 0;
+ my ($userresult,$authresult,$roleresult,$idresult);
+ my (%userres,%authres,%roleres,%idres);
+ my $singlesec = '';
+ if ($role eq 'st') {
+ if (($context eq 'domain') && ($changeauth eq 'Yes') && (!$newuser)) {
+ if ((&Apache::lonnet::allowed('mau',$userdomain)) &&
+ (&Apache::lonnet::homeserver($username,$userdomain) ne 'no_host')) {
+ if ((($amode =~ /^krb4|krb5|internal$/) && $password ne '') ||
+ ($amode eq 'localauth')) {
+ $authresult =
+ &Apache::lonnet::modifyuserauth($userdomain,$username,$amode,$password);
+ }
+ }
+ }
+ my $sec;
+ if (ref($userinfo{$i}{'sections'}) eq 'ARRAY') {
+ if (@secs > 0) {
+ $sec = $secs[0];
+ }
+ }
+ if ($userdomain ne $env{'request.role.domain'}) {
+ my $item = "/$crsdom/$crsnum" ;
+ if ($sec ne '') {
+ $item .= "/$sec";
+ }
+ $item .= '_st';
+ next if (&restricted_dom($context,$item,$userdomain,$username,$role,$startdate,
+ $enddate,$crsdom,$crsnum,$sec,$credits,\%process_by,
+ \%instdoms,\%got_role_approvals,\%got_instdoms,\%reject,
+ \%pending,\%notifydc,\%status,\%unauthorized,\%currqueued));
+ }
+ &modifystudent($userdomain,$username,$cid,$sec,
+ $desiredhost,$context);
+ $roleresult =
+ &Apache::lonnet::modifystudent
+ ($userdomain,$username,$id,$amode,$password,
+ $fname,$mname,$lname,$gen,$sec,$enddate,
+ $startdate,$env{'form.forceid'},
+ $desiredhost,$email,'manual','',$cid,
+ '',$context,$inststatus,$credits);
+ $userresult = $roleresult;
+ } else {
+ my $possrole;
+ if ($role ne '') {
+ if ($context eq 'course' || $setting eq 'course') {
+ if ($customroles{$role}) {
+ $role = 'cr_'.$env{'user.domain'}.'_'.
+ $env{'user.name'}.'_'.$role;
+ }
+ $possrole = $role;
+ if ($possrole =~ /^cr_/) {
+ $possrole =~ s{_}{/}g;
+ }
+ if (($role ne 'cc') && ($role ne 'co')) {
+ if (@secs > 1) {
+ $multiple = 1;
+ my $prefix = "/$crsdom/$crsnum";
+ foreach my $sec (@secs) {
+ if ($userdomain ne $env{'request.role.domain'}) {
+ my $item = $prefix;
+ if ($sec ne '') {
+ $item .= "/$sec";
+ }
+ $item .= '_'.$possrole;
+ next if (&restricted_dom($context,$item,$userdomain,$username,$possrole,
+ $startdate,$enddate,$crsdom,$crsnum,$sec,
+ $credits,\%process_by,\%instdoms,\%got_role_approvals,
+ \%got_instdoms,\%reject,\%pending,\%notifydc,
+ \%status,\%unauthorized,\%currqueued));
+ }
+ ($userres{$sec},$authres{$sec},$roleres{$sec},$idres{$sec}) =
+ &modifyuserrole($context,$setting,
+ $changeauth,$cid,$userdomain,$username,
+ $id,$amode,$password,$fname,
+ $mname,$lname,$gen,$sec,
+ $env{'form.forceid'},$desiredhost,
+ $email,$role,$enddate,
+ $startdate,$checkid,$inststatus);
+ }
+ } elsif (@secs > 0) {
+ $singlesec = $secs[0];
+ }
+ }
+ } else {
+ $possrole = $role;
+ }
+ }
+ if (!$multiple) {
+ if (($userdomain ne $env{'request.role.domain'}) && ($role ne '')) {
+ my $item = "/$crsdom/$crsnum";
+ if ($singlesec ne '') {
+ $item .= "/$singlesec";
+ }
+ $item .= '_'.$possrole;
+ next if (&restricted_dom($context,$item,$userdomain,$username,$possrole,$startdate,$enddate,
+ $crsdom,$crsnum,$singlesec,$credits,\%process_by,\%instdoms,
+ \%got_role_approvals,\%got_instdoms,\%reject,\%pending,\%notifydc,
+ \%status,\%unauthorized,\%currqueued));
+ }
+ ($userresult,$authresult,$roleresult,$idresult) =
&modifyuserrole($context,$setting,
- $changeauth,$cid,$domain,$username,
- $id,$amode,$password,$fname,
- $mname,$lname,$gen,$sec,
- $env{'form.forceid'},$desiredhost,
- $email,$role,$enddate,$startdate,$checkid);
+ $changeauth,$cid,$userdomain,$username,
+ $id,$amode,$password,$fname,
+ $mname,$lname,$gen,$singlesec,
+ $env{'form.forceid'},$desiredhost,
+ $email,$role,$enddate,$startdate,
+ $checkid,$inststatus);
+ }
+ }
+ if ($multiple) {
+ foreach my $sec (sort(keys(%userres))) {
+ $flushc =
+ &user_change_result($r,$userres{$sec},$authres{$sec},
+ $roleres{$sec},$idres{$sec},\%counts,$flushc,
+ $username,$userdomain,\%userchg);
+
}
+ } else {
$flushc =
&user_change_result($r,$userresult,$authresult,
- $roleresult,\%counts,$flushc,
- $username,%userchg);
- } else {
- if ($context eq 'course') {
- $r->print(' '.
- &mt('[_1]: Unable to enroll. No password specified.',$username)
- );
- } elsif ($context eq 'author') {
- $r->print(' '.
- &mt('[_1]: Unable to add co-author. No password specified.',$username)
- );
- } else {
- $r->print(' '.
- &mt('[_1]: Unable to add user. No password specified.',$username)
- );
- }
+ $roleresult,$idresult,\%counts,$flushc,
+ $username,$userdomain,\%userchg);
}
}
- }
- } # end of foreach (@userdata)
+ &Apache::lonhtmlcommon::Increment_PrgWin($r,\%prog_state,'last user');
+ } # end of loop
+ $r->print('
');
+ &Apache::lonhtmlcommon::Close_PrgWin($r,\%prog_state);
+ }
# Flush the course logs so reverse user roles immediately updated
- &Apache::lonnet::flushcourselogs();
- $r->print("\n
\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".
@@ -3217,23 +5583,28 @@ sub upfile_drop_add {
$counts{'auth'})."
\n");
}
$r->print(&print_namespacing_alerts($domain,\%alerts,\%curr_rules));
- $r->print('');
+ $r->print(&passwdrule_alerts($domain,\%showpasswdrules));
+ if ((keys(%reject)) || (keys(%unauthorized))) {
+ $r->print(&print_roles_rejected($context,\%reject,\%unauthorized));
+ }
+ if ((keys(%pending)) || (keys(%currqueued))) {
+ $r->print(&print_roles_queued($context,\%pending,\%notifydc,\%currqueued));
+ }
#####################################
- # 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('
'.
+ &mt('There are no students with current/future access to the course.').
+ '
'."\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'}}.
@@ -3241,10 +5612,11 @@ 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
+ return 'ok';
}
sub print_namespacing_alerts {
@@ -3287,15 +5659,52 @@ sub print_namespacing_alerts {
}
}
+sub passwdrule_alerts {
+ my ($domain,$passwdrules) = @_;
+ my $warning;
+ if (ref($passwdrules) eq 'HASH') {
+ my %showrules = %{$passwdrules};
+ if (keys(%showrules)) {
+ my %passwdconf = &Apache::lonnet::get_passwdconf($domain);
+ $warning = ''.&mt('Password requirement(s) unmet for one or more users:').'
';
+ if ($showrules{'min'}) {
+ my $min = $passwdconf{'min'};
+ if ($min eq '') {
+ $min = $Apache::lonnet::passwdmin;
+ }
+ $warning .= '
';
+ }
+ }
+ return $warning;
+}
+
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'} ++;
@@ -3304,8 +5713,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'} ++;
@@ -3314,8 +5723,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'} ++;
@@ -3323,51 +5732,70 @@ 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_drop_menu {
- my ($r,$context,$permission) = @_;
- $r->print('
'.&mt("Drop Students").'
'."\n".
- ''. &Apache::loncommon::end_page());
+ $r->print('');
return;
}
# ================================================================== Phase four
sub update_user_list {
- my ($r,$context,$setting,$choice) = @_;
+ my ($r,$context,$setting,$choice,$crstype) = @_;
my $now = time;
my $count=0;
- my @changelist;
- if ($choice ne '') {
- @changelist = &Apache::loncommon::get_env_multiple('form.actionlist');
- } else {
+ if ($context eq 'course') {
+ $crstype = &Apache::loncommon::course_type();
+ }
+ my (@changelist,%got_role_approvals,%got_instdoms,%process_by,%instdoms,
+ %pending,%reject,%notifydc,%status,%unauthorized,%currqueued);
+ 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 for',
+ 'chgsec' => 'Changed section(s) for',
'drop' => 'Dropped',
},
error => {'revoke' => 'revoking',
@@ -3384,8 +5812,9 @@ 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);
+ my ($role,$uname,$udom,$cid,$sec,$scope,$result,$type,$locktype,
+ @sections,$scopestem,$singlesec,$showsecs,$warn_singlesec,
+ $nothingtodo,$keepnosection,$credits,$instsec,$cdom,$cnum);
if ($choice eq 'drop') {
($uname,$udom,$sec) = split(/:/,$item,-1);
$role = 'st';
@@ -3398,8 +5827,12 @@ sub update_user_list {
$scope = $scopestem.'/'.$sec;
}
} elsif ($context eq 'course') {
- ($uname,$udom,$role,$sec,$type,$locktype) = split(/\:/,$item,-1);
+ ($uname,$udom,$role,$sec,$type,$locktype,$credits,$instsec) =
+ split(/\:/,$item,8);
+ $instsec = &unescape($instsec);
$cid = $env{'request.course.id'};
+ $cdom = $env{'course.'.$env{'request.course.id'}.'.domain'};
+ $cnum = $env{'course.'.$env{'request.course.id'}.'.num'};
$scopestem = '/'.$cid;
$scopestem =~s/\_/\//g;
if ($sec eq '') {
@@ -3410,15 +5843,21 @@ sub update_user_list {
} elsif ($context eq 'author') {
($uname,$udom,$role) = split(/\:/,$item,-1);
$scope = '/'.$env{'user.domain'}.'/'.$env{'user.name'};
+ $cdom = $env{'user.domain'};
+ $cnum = $env{'user.name'};
} elsif ($context eq 'domain') {
if ($setting eq 'domain') {
($role,$uname,$udom) = split(/\:/,$item,-1);
$scope = '/'.$env{'request.role.domain'}.'/';
+ $cdom = $env{'request.role.domain'};
} elsif ($setting eq 'author') {
($uname,$udom,$role,$scope) = split(/\:/,$item);
+ (undef,$cdom,$cnum) = split(/\//,$scope);
} elsif ($setting eq 'course') {
- ($uname,$udom,$role,$cid,$sec,$type,$locktype) =
- split(/\:/,$item);
+ ($uname,$udom,$role,$cid,$sec,$type,$locktype,$credits,$instsec) =
+ split(/\:/,$item,9);
+ ($cdom,$cnum) = split('_',$cid);
+ $instsec = &unescape($instsec);
$scope = '/'.$cid;
$scope =~s/\_/\//g;
if ($sec ne '') {
@@ -3426,8 +5865,7 @@ sub update_user_list {
}
}
}
- my $plrole = &Apache::lonnet::plaintext($role);
- my ($uid,$first,$middle,$last,$gene,$sec);
+ my $plrole = &Apache::lonnet::plaintext($role,$crstype);
my $start = $env{'form.'.$item.'_start'};
my $end = $env{'form.'.$item.'_end'};
if ($choice eq 'drop') {
@@ -3435,108 +5873,189 @@ sub update_user_list {
$end = $now;
$type = 'manual';
$result =
- &Apache::lonnet::modify_student_enrollment($udom,$uname,undef,undef,undef,undef,undef,$sec,$end,$start,$type,$locktype,$cid);
+ &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);
+ &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);
+ &Apache::lonnet::revokerole($udom,$uname,$scope,$role,
+ '','',$context);
}
} 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,'',$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;
}
+ my $id = $scope.'_'.$role;
if ($choice eq 'reenable') {
+ next if (&restricted_dom($context,$id,$udom,$uname,$role,$now,$end,$cdom,$cnum,
+ $sec,$credits,\%process_by,\%instdoms,\%got_role_approvals,
+ \%got_instdoms,\%reject,\%pending,\%notifydc,
+ \%status,\%unauthorized,\%currqueued));
if ($role eq 'st') {
- $result = &Apache::lonnet::modify_student_enrollment($udom,$uname,undef,undef,undef,undef,undef,$sec,$end,$start,$type,$locktype,$cid);
+ $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);
+ $now,'','',$context);
}
} elsif ($choice eq 'activate') {
+ next if (&restricted_dom($context,$id,$udom,$uname,$role,$now,$end,$cdom,$cnum,
+ $sec,$credits,\%process_by,\%instdoms,\%got_role_approvals,
+ \%got_instdoms,\%reject,\%pending,\%notifydc,
+ \%status,\%unauthorized,\%currqueued));
if ($role eq 'st') {
- $result = &Apache::lonnet::modify_student_enrollment($udom,$uname,undef,undef,undef,undef,undef,$sec,$end,$start,$type,$locktype,$cid);
+ $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);
+ $now,'','',$context);
}
} elsif ($choice eq 'chgdates') {
+ next if (&restricted_dom($context,$id,$udom,$uname,$role,$start,$end,$cdom,$cnum,
+ $sec,$credits,\%process_by,\%instdoms,\%got_role_approvals,
+ \%got_instdoms,\%reject,\%pending,\%notifydc,
+ \%status,\%unauthorized,\%currqueued));
if ($role eq 'st') {
- $result = &Apache::lonnet::modify_student_enrollment($udom,$uname,undef,undef,undef,undef,undef,$sec,$end,$start,$type,$locktype,$cid);
+ $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);
+ $start,'','',$context);
}
} elsif ($choice eq 'chgsec') {
my (@newsecs,$revresult,$nochg,@retained);
- if ($role ne 'cc') {
- @newsecs = split(/,/,$env{'form.newsecs'});
+ 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'}) {
+ if (!$env{'form.retainsec'} || ($role eq 'st')) {
if ($sec eq '') {
if (@newsecs == 0) {
- $result = &mt('No change in section assignment (none)');
+ $result = 'ok';
$nochg = 1;
- }
- } else {
- if (!grep(/^\Q$sec\E$/,@newsecs)) {
+ $nothingtodo = 1;
+ } else {
$revresult =
- &Apache::lonnet::revokerole($udom,$uname,$scope,$role);
+ &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 {
- push(@retained,$sec);
+ $revresult =
+ &Apache::lonnet::revokerole($udom,$uname,
+ $scope,$role,
+ '','',$context);
}
}
} else {
- push(@retained,$sec);
+ 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) {
- 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 ($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) {
+ 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);
+ $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;
@@ -3547,42 +6066,120 @@ sub update_user_list {
}
}
if ($result eq 'ok' || $result eq 'ok:') {
- $r->print(&mt("$result_text{'ok'}{$choice} role of '[_1]' in [_2] for [_3]",
- $plrole,$extent,$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 $result_text{'error'}{$choice} [_1] in [_2] for [_3]:[_4]",
- $plrole,$extent,$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(''."\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,$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)) {
if (!&active_student_roles($cnum,$cdom,$uname,$udom)) {
- my $result =
- &Apache::lonnet::cput('classlist',
- { $user => $now },
- $env{'course.'.$cid.'.domain'},
- $env{'course.'.$cid.'.num'});
+ my %user;
+ my $result = &update_classlist($cdom,$cnum,$udom,$uname,\%user,$now);
return &mt('Drop from classlist: [_1]',
''.$result.'').' ';
}
@@ -3599,18 +6196,25 @@ sub active_student_roles {
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 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'.$authformloc.''.
&Apache::loncommon::end_data_table_row()."\n";
}
+ if ($can_assign{'lti'}) {
+ $response .= &Apache::loncommon::start_data_table_row().
+ '
'.$authformlti.'
'.
+ &Apache::loncommon::end_data_table_row()."\n";
+ }
$response .= &Apache::loncommon::end_data_table();
}
return $response;
}
sub course_sections {
- my ($sections_count,$role) = @_;
+ my ($sections_count,$role,$current_sec,$disabled) = @_;
my $output = '';
- my @sections = (sort {$a <=> $b} keys %{$sections_count});
- if (scalar(@sections) == 1) {
- $output = ''."\n".
- '