--- loncom/interface/lonuserutils.pm 2007/12/21 20:34:26 1.21
+++ 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.21 2007/12/21 20:34:26 raeburn Exp $
+# $Id: lonuserutils.pm,v 1.185 2017/08/07 20:22:13 raeburn Exp $
#
# Copyright Michigan State University Board of Trustees
#
@@ -30,19 +30,36 @@
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 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
@@ -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,12 +103,12 @@ 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,$checkid) = @_;
+ $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 ($context eq 'domain') {
@@ -123,11 +141,13 @@ sub modifyuserrole {
$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 '') {
+ $role =~ s/_/\//g;
$roleresult = &Apache::lonnet::assignrole($udom,$uname,$scope,
- $role,$end,$start);
+ $role,$end,$start,'',
+ '',$context);
}
}
return ($userresult,$authresult,$roleresult,$idresult);
@@ -145,7 +165,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 +186,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 +197,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 +252,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 +266,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 +284,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 +294,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 +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'})) {
@@ -279,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
@@ -295,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 '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,7 +1121,7 @@ sub forceid_change {
###############################################################
###############################################################
sub print_upload_manager_form {
- my ($r,$context,$permission) = @_;
+ my ($r,$context,$permission,$crstype,$showcredits) = @_;
my $firstLine;
my $datatoken;
if (!$env{'form.datatoken'}) {
@@ -801,8 +1151,12 @@ sub print_upload_manager_form {
'ipwd_choice' => 'scalar',
'email_choice' => 'scalar',
'role_choice' => 'scalar',
+ 'domain_choice' => 'scalar',
+ 'inststatus_choice' => 'scalar',
};
- my $defdom = $env{'request.role.domain'};
+ if ($showcredits) {
+ $col_setting_names->{'credits_choice'} = 'scalar';
+ }
if ($context eq 'course') {
&Apache::loncommon::restore_course_settings('enrollment_upload',
$col_setting_names);
@@ -810,12 +1164,15 @@ sub print_upload_manager_form {
&Apache::loncommon::restore_settings($context,'user_upload',
$col_setting_names);
}
+ my $defdom = $env{'request.role.domain'};
#
# Determine kerberos parameters as appropriate
my ($krbdef,$krbdefdom) =
&Apache::loncommon::get_kerberos_defaults($defdom);
#
- &print_upload_manager_header($r,$datatoken,$distotal,$krbdefdom,$context);
+ my ($authnum,%can_assign) = &Apache::loncommon::get_assignable_auth($defdom);
+ &print_upload_manager_header($r,$datatoken,$distotal,$krbdefdom,$context,
+ $permission,$crstype,\%can_assign);
my $i;
my $keyfields;
if ($total>=0) {
@@ -826,11 +1183,17 @@ sub print_upload_manager_form {
['mname',&mt('Middle Names/Initials'),$env{'form.mname_choice'}],
['lname',&mt('Last Name'), $env{'form.lname_choice'}],
['gen', &mt('Generation'), $env{'form.gen_choice'}],
- ['id', &mt('ID/Student Number'),$env{'form.id_choice'}],
+ ['id', &mt('Student/Employee ID'),$env{'form.id_choice'}],
['sec', &mt('Section'), $env{'form.sec_choice'}],
['ipwd', &mt('Initial Password'),$env{'form.ipwd_choice'}],
['email',&mt('E-mail Address'), $env{'form.email_choice'}],
- ['role',&mt('Role'), $env{'form.role_choice'}]);
+ ['role',&mt('Role'), $env{'form.role_choice'}],
+ ['domain',&mt('Domain'), $env{'form.domain_choice'}],
+ ['inststatus',&mt('Affiliation'), $env{'form.inststatus_choice'}]);
+ if ($showcredits) {
+ push(@field,
+ ['credits',&mt('Student Credits'), $env{'form.credits_choice'}]);
+ }
if ($env{'form.upfile_associate'} eq 'reverse') {
&Apache::loncommon::csv_print_samples($r,\@records);
$i=&Apache::loncommon::csv_print_select_table($r,\@records,
@@ -847,13 +1210,15 @@ sub print_upload_manager_form {
$keyfields=join(',',sort(keys(%sone)));
}
}
- $r->print('
');
&print_upload_manager_footer($r,$i,$keyfields,$defdom,$today,$halfyear,
- $context);
+ $context,$permission,$crstype,$showcredits);
}
sub setup_date_selectors {
- my ($starttime,$endtime,$mode,$nolink) = @_;
+ my ($starttime,$endtime,$mode,$nolink,$formname) = @_;
+ if ($formname eq '') {
+ $formname = 'studentform';
+ }
if (! defined($starttime)) {
$starttime = time;
unless ($mode eq 'create_enrolldates' || $mode eq 'create_defaultdates') {
@@ -876,11 +1241,11 @@ sub setup_date_selectors {
}
my $startdateform =
- &Apache::lonhtmlcommon::date_setter('studentform','startdate',$starttime,
+ &Apache::lonhtmlcommon::date_setter($formname,'startdate',$starttime,
undef,undef,undef,undef,undef,undef,undef,$nolink);
my $enddateform =
- &Apache::lonhtmlcommon::date_setter('studentform','enddate',$endtime,
+ &Apache::lonhtmlcommon::date_setter($formname,'enddate',$endtime,
undef,undef,undef,undef,undef,undef,undef,$nolink);
if ($mode eq 'create_enrolldates') {
@@ -904,8 +1269,15 @@ sub setup_date_selectors {
sub get_dates_from_form {
- my $startdate = &Apache::lonhtmlcommon::get_date_from_form('startdate');
- my $enddate = &Apache::lonhtmlcommon::get_date_from_form('enddate');
+ my ($startname,$endname) = @_;
+ if ($startname eq '') {
+ $startname = 'startdate';
+ }
+ if ($endname eq '') {
+ $endname = 'enddate';
+ }
+ my $startdate = &Apache::lonhtmlcommon::get_date_from_form($startname);
+ my $enddate = &Apache::lonhtmlcommon::get_date_from_form($endname);
if ($env{'form.no_end_date'}) {
$enddate = 0;
}
@@ -913,29 +1285,36 @@ sub get_dates_from_form {
}
sub date_setting_table {
- my ($starttime,$endtime,$mode,$bulkaction) = @_;
+ my ($starttime,$endtime,$mode,$bulkaction,$formname,$permission,$crstype) = @_;
my $nolink;
if ($bulkaction) {
$nolink = 1;
}
my ($startform,$endform) =
- &setup_date_selectors($starttime,$endtime,$mode,$nolink);
+ &setup_date_selectors($starttime,$endtime,$mode,$nolink,$formname);
my $dateDefault;
if ($mode eq 'create_enrolldates' || $mode eq 'create_defaultdates') {
$dateDefault = ' ';
} elsif ($mode ne 'author' && $mode ne 'domain') {
if (($bulkaction eq 'reenable') ||
($bulkaction eq 'activate') ||
- ($bulkaction eq 'chgdates')) {
- $dateDefault = ''.
- '';
+ ($bulkaction eq 'chgdates') ||
+ ($env{'form.action'} eq 'upload')) {
+ if ($env{'request.course.sec'} eq '') {
+ $dateDefault = ''.
+ '';
+ }
}
}
my $perpetual = '';
if ($mode eq 'create_enrolldates') {
@@ -950,7 +1329,7 @@ sub date_setting_table {
'LC_oddrow_value')."\n".
$endform.' '.$perpetual.
&Apache::lonhtmlcommon::row_closure(1).
- &Apache::lonhtmlcommon::end_pick_box().' ';
+ &Apache::lonhtmlcommon::end_pick_box();
if ($dateDefault) {
$result .= $dateDefault.' '."\n";
}
@@ -958,7 +1337,7 @@ sub date_setting_table {
}
sub make_dates_default {
- my ($startdate,$enddate,$context) = @_;
+ my ($startdate,$enddate,$context,$crstype) = @_;
my $result = '';
if ($context eq 'course') {
my ($cnum,$cdom) = &get_course_identity();
@@ -966,26 +1345,34 @@ sub make_dates_default {
{'default_enrollment_start_date'=>$startdate,
'default_enrollment_end_date' =>$enddate},$cdom,$cnum);
if ($put_result eq 'ok') {
- $result .= &mt('Set default start and end dates for course').
- ' '."\n";
+ if ($crstype eq 'Community') {
+ $result .= &mt('Set default start and end access dates for community.');
+ } else {
+ $result .= &mt('Set default start and end access dates for course.');
+ }
+ $result .= ' '."\n";
#
# Refresh the course environment
&Apache::lonnet::coursedescription($env{'request.course.id'},
{'freshen_cache' => 1});
} else {
- $result .= &mt('Unable to set default dates for course').":".$put_result.
- ' ';
+ if ($crstype eq 'Community') {
+ $result .= &mt('Unable to set default access dates for community');
+ } else {
+ $result .= &mt('Unable to set default access dates for course');
+ }
+ $result .= ':'.$put_result.' ';
}
}
return $result;
}
sub default_role_selector {
- my ($context,$checkpriv) = @_;
+ my ($context,$checkpriv,$crstype,$showcredits) = @_;
my %customroles;
my ($options,$coursepick,$cb_jscript);
if ($context ne 'author') {
- %customroles = &my_custom_roles();
+ %customroles = &my_custom_roles($crstype);
}
my %lt=&Apache::lonlocal::texthash(
@@ -993,11 +1380,12 @@ sub default_role_selector {
'grs' => "Section",
'exs' => "Existing sections",
'new' => "New section",
+ 'crd' => "Credits",
);
$options = '';
return ($options,$cb_jscript,$coursepick);
}
sub default_course_roles {
- my ($context,$checkpriv,%customroles) = @_;
+ my ($context,$checkpriv,$crstype,%customroles) = @_;
my $output;
my $custom = 1;
- my @roles = &course_roles($context,$checkpriv,$custom);
+ my @roles = &course_roles($context,$checkpriv,$custom,lc($crstype));
foreach my $role (@roles) {
- my $plrole=&Apache::lonnet::plaintext($role);
- $output .= '
'.$plrole.'
';
+ if ($role ne 'cr') {
+ my $plrole=&Apache::lonnet::plaintext($role,$crstype);
+ $output .= '
'.$plrole.'
';
+ }
}
if (keys(%customroles) > 0) {
- my %customroles = &my_custom_roles();
- foreach my $cust (sort(keys(%customroles))) {
- my $custrole='cr_cr_'.$env{'user.domain'}.
- '_'.$env{'user.name'}.'_'.$cust;
- $output .= '
'.$cust.'
';
+ if (grep(/^cr$/,@roles)) {
+ foreach my $cust (sort(keys(%customroles))) {
+ my $custrole='cr_'.$env{'user.domain'}.
+ '_'.$env{'user.name'}.'_'.$cust;
+ $output .= '
'.$cust.'
';
+ }
}
}
return $output;
@@ -1096,8 +1497,14 @@ sub domain_roles {
}
sub course_roles {
- my ($context,$checkpriv,$custom) = @_;
- my @allroles = &roles_by_context('course',$custom);
+ my ($context,$checkpriv,$custom,$roletype) = @_;
+ my $crstype;
+ if ($roletype eq 'community') {
+ $crstype = 'Community' ;
+ } else {
+ $crstype = 'Course';
+ }
+ my @allroles = &roles_by_context('course',$custom,$crstype);
my @roles;
if ($context eq 'domain') {
@roles = @allroles;
@@ -1108,10 +1515,10 @@ sub course_roles {
if (&Apache::lonnet::allowed('c'.$role,$env{'request.course.id'})) {
push(@roles,$role);
} else {
- if ($role ne 'cc' && $env{'request.course.section'} ne '') {
- if (!&Apache::lonnet::allowed('c'.$role,
+ if ((($role ne 'cc') && ($role ne 'co')) && ($env{'request.course.sec'} ne '')) {
+ if (&Apache::lonnet::allowed('c'.$role,
$env{'request.course.id'}.'/'.
- $env{'request.course.section'})) {
+ $env{'request.course.sec'})) {
push(@roles,$role);
}
}
@@ -1126,19 +1533,19 @@ sub course_roles {
}
sub curr_role_permissions {
- my ($context,$setting,$checkpriv) = @_;
+ my ($context,$setting,$checkpriv,$type) = @_;
my $custom = 1;
my @roles;
if ($context eq 'author') {
@roles = &construction_space_roles($checkpriv);
} elsif ($context eq 'domain') {
if ($setting eq 'course') {
- @roles = &course_roles($context,$checkpriv,$custom);
+ @roles = &course_roles($context,$checkpriv,$custom,$type);
} else {
@roles = &domain_roles($checkpriv);
}
} elsif ($context eq 'course') {
- @roles = &course_roles($context,$checkpriv,$custom);
+ @roles = &course_roles($context,$checkpriv,$custom,$type);
}
return @roles;
}
@@ -1146,10 +1553,15 @@ sub curr_role_permissions {
# ======================================================= Existing Custom Roles
sub my_custom_roles {
+ my ($crstype,$udom,$uname) = @_;
my %returnhash=();
- my %rolehash=&Apache::lonnet::dump('roles');
- foreach my $key (keys %rolehash) {
+ my $extra = &Apache::lonnet::freeze_escape({'skipcheck' => 1});
+ my %rolehash=&Apache::lonnet::dump('roles',$udom,$uname);
+ foreach my $key (keys(%rolehash)) {
if ($key=~/^rolesdef\_(\w+)$/) {
+ if ($crstype eq 'Community') {
+ next if ($rolehash{$key} =~ /bre\&S/);
+ }
$returnhash{$1}=$1;
}
}
@@ -1158,7 +1570,7 @@ sub my_custom_roles {
sub print_userlist {
my ($r,$mode,$permission,$context,$formname,$totcodes,$codetitles,
- $idlist,$idlist_titles) = @_;
+ $idlist,$idlist_titles,$showcredits) = @_;
my $format = $env{'form.output'};
if (! exists($env{'form.sortby'})) {
$env{'form.sortby'} = 'username';
@@ -1166,8 +1578,9 @@ sub print_userlist {
if ($env{'form.Status'} !~ /^(Any|Expired|Active|Future)$/) {
$env{'form.Status'} = 'Active';
}
+ my $onchange = "javascript:updateCols('Status');";
my $status_select = &Apache::lonhtmlcommon::StatusOptions
- ($env{'form.Status'});
+ ($env{'form.Status'},undef,undef,$onchange);
if ($env{'form.showrole'} eq '') {
if ($context eq 'course') {
@@ -1192,112 +1605,126 @@ sub print_userlist {
@statuses = ('future');
}
-# if ($context eq 'course') {
-# $r->print(&display_adv_courseroles());
-# }
- #
# Interface output
$r->print('');
+ return;
}
- if (!(($context eq 'domain') && ($env{'form.roletype'} eq 'course'))) {
- $r->print(&list_submit_button(&mt('Update Display'))."\n\n");
+ if (!(($context eq 'domain') &&
+ (($env{'form.roletype'} eq 'course') || ($env{'form.roletype'} eq 'community')))) {
+ $r->print(' '.
+ &list_submit_button(&mt('Update Display'))."\n");
+ }
+
+ my @cols = &infocolumns($context,$mode,$showcredits);
+ if (!@cols) {
+ $r->print(''.
+ &mt('No user information selected for display.').''.
+ ''."\n");
+ return;
}
my ($indexhash,$keylist) = &make_keylist_array();
- my (%userlist,%userinfo);
- if ($context eq 'domain' && $env{'form.roletype'} eq 'course') {
+ my (%userlist,%userinfo,$clearcoursepick,$needauthorquota,$needauthorusage);
+ if (($context eq 'domain') &&
+ ($env{'form.roletype'} eq 'course') ||
+ ($env{'form.roletype'} eq 'community')) {
+ my ($crstype,$numcodes,$title,$warning);
+ if ($env{'form.roletype'} eq 'course') {
+ $crstype = 'Course';
+ $numcodes = $totcodes;
+ $title = &mt('Select Courses');
+ $warning = &mt('Warning: data retrieval for multiple courses can take considerable time, as this operation is not currently optimized.');
+ } elsif ($env{'form.roletype'} eq 'community') {
+ $crstype = 'Community';
+ $numcodes = 0;
+ $title = &mt('Select Communities');
+ $warning = &mt('Warning: data retrieval for multiple communities can take considerable time, as this operation is not currently optimized.');
+ }
+ my @standardnames = &Apache::loncommon::get_standard_codeitems();
my $courseform =
- &Apache::lonhtmlcommon::course_selection($formname,$totcodes,
- $codetitles,$idlist,$idlist_titles);
- $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 +2796,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 +2810,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 +2820,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 +2879,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 +2894,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 +2994,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 +3022,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"
+ .'
';
+
$r->print($str);
return;
}
# ================================================= Drop/Add from uploaded file
sub upfile_drop_add {
- my ($r,$context,$permission) = @_;
+ my ($r,$context,$permission,$showcredits) = @_;
&Apache::loncommon::load_tmp_file($r);
my @userdata=&Apache::loncommon::upfile_record_sep();
if($env{'form.noFirstLine'}){shift(@userdata);}
@@ -2890,36 +4127,91 @@ sub upfile_drop_add {
$fields{$env{'form.f'.$i}}=$keyfields[$i];
}
}
+ if ($env{'form.fullup'} ne 'yes') {
+ $r->print('');
#####################################
- # Drop students #
+ # Display list of students to drop #
#####################################
if ($env{'form.fullup'} eq 'yes') {
- $r->print('
'.&mt('Dropping Students')."
\n");
+ $r->print('
'.&mt('Students to Drop')."
\n");
# Get current classlist
- my ($classlist,$keylist)=&Apache::loncoursedata::get_classlist();
+ 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'}}.
@@ -3233,10 +4924,13 @@ sub upfile_drop_add {
}
}
# Print out list of dropped students.
- &show_drop_list($r,$classlist,$keylist,'nosort');
+ &show_drop_list($r,$classlist,'nosort',$permission);
}
}
} # end of unless
+ if ($env{'form.fullup'} ne 'yes') {
+ $r->print('');
+ }
}
sub print_namespacing_alerts {
@@ -3280,14 +4974,15 @@ sub print_namespacing_alerts {
}
sub user_change_result {
- my ($r,$userresult,$authresult,$roleresult,$counts,$flushc,$username,
- $userchg) = @_;
+ my ($r,$userresult,$authresult,$roleresult,$idresult,$counts,$flushc,
+ $username,$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'} ++;
@@ -3296,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'} ++;
@@ -3306,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'} ++;
@@ -3315,51 +5010,69 @@ 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;
+ if ($context eq 'course') {
+ $crstype = &Apache::loncommon::course_type();
+ }
my @changelist;
- if ($choice ne '') {
- @changelist = &Apache::loncommon::get_env_multiple('form.actionlist');
- } else {
+ if ($choice eq 'drop') {
@changelist = &Apache::loncommon::get_env_multiple('form.droplist');
+ } else {
+ @changelist = &Apache::loncommon::get_env_multiple('form.actionlist');
}
my %result_text = ( ok => { 'revoke' => 'Revoked',
'delete' => 'Deleted',
'reenable' => 'Re-enabled',
'activate' => 'Activated',
'chgdates' => 'Changed Access Dates for',
- 'chgsec' => 'Changed section for',
+ 'chgsec' => 'Changed section(s) for',
'drop' => 'Dropped',
},
error => {'revoke' => 'revoking',
@@ -3376,8 +5089,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);
if ($choice eq 'drop') {
($uname,$udom,$sec) = split(/:/,$item,-1);
$role = 'st';
@@ -3390,7 +5104,9 @@ 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'};
$scopestem = '/'.$cid;
$scopestem =~s/\_/\//g;
@@ -3409,8 +5125,9 @@ sub update_user_list {
} elsif ($setting eq 'author') {
($uname,$udom,$role,$scope) = split(/\:/,$item);
} 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);
+ $instsec = &unescape($instsec);
$scope = '/'.$cid;
$scope =~s/\_/\//g;
if ($sec ne '') {
@@ -3418,8 +5135,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') {
@@ -3427,28 +5143,25 @@ 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') {
@@ -3457,78 +5170,149 @@ sub update_user_list {
}
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);
+ $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') {
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') {
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;
@@ -3539,42 +5323,114 @@ 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('
'.&mt("$result_text{'ok'}{$choice} role(s) for [quant,_1,user,users,users].",$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 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.'').' ';
}
@@ -3591,18 +5447,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 $b} keys %{$sections_count});
- if (scalar(@sections) == 1) {
- $output = ''."\n".
- '