--- loncom/interface/lonuserutils.pm 2008/12/12 16:50:53 1.77
+++ loncom/interface/lonuserutils.pm 2010/11/15 18:50:37 1.97.2.25
@@ -1,7 +1,7 @@
# The LearningOnline Network with CAPA
# Utility functions for managing LON-CAPA user accounts
#
-# $Id: lonuserutils.pm,v 1.77 2008/12/12 16:50:53 raeburn Exp $
+# $Id: lonuserutils.pm,v 1.97.2.25 2010/11/15 18:50:37 raeburn Exp $
#
# Copyright Michigan State University Board of Trustees
#
@@ -47,7 +47,8 @@ sub modifystudent {
# this one. If $csec is defined, drop them from all other sections of
# this course and add them to section $csec
my ($cnum,$cdom) = &get_course_identity($courseid);
- my %roles = &Apache::lonnet::dump('roles',$udom,$unam);
+ my $extra = &Apache::lonnet::freeze_escape({'skipcheck' => 1});
+ my %roles = &Apache::lonnet::dump('roles',$udom,$unam,'.',undef,$extra);
my ($tmp) = keys(%roles);
# Bail out if we were unable to get the students roles
return "$1" if ($tmp =~ /^(con_lost|error|no_such_host)/i);
@@ -86,12 +87,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') {
@@ -124,7 +125,7 @@ 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;
@@ -235,7 +236,7 @@ sub domain_roles_select {
# domain context
#
# Role types
- my @roletypes = ('domain','author','course');
+ my @roletypes = ('domain','author','course','community');
my %lt = &role_type_names();
#
# build up the menu information to be passed to
@@ -247,6 +248,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'};
@@ -261,7 +266,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;
@@ -271,14 +276,15 @@ 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']);
return $result;
}
@@ -290,7 +296,8 @@ sub hidden_input {
}
sub print_upload_manager_header {
- my ($r,$datatoken,$distotal,$krbdefdom,$context,$permission)=@_;
+ my ($r,$datatoken,$distotal,$krbdefdom,$context,$permission,$crstype,
+ $can_assign)=@_;
my $javascript;
#
if (! exists($env{'form.upfile_associate'})) {
@@ -304,9 +311,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
@@ -327,10 +334,12 @@ sub print_upload_manager_header {
my $javascript_validations =
&javascript_validations('upload',$krbdefdom,$password_choice,undef,
$env{'request.role.domain'},$context,
- $groupslist);
- my $checked=(($env{'form.noFirstLine'})?' checked="checked" ':'');
- $r->print(&mt('Total number of records found in file: [_1]',''.$distotal.'').
- " \n");
+ $groupslist,$crstype);
+ 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");
@@ -341,21 +350,24 @@ sub print_upload_manager_header {
&hidden_input('fileupload',$env{'form.fileupload'}).
&hidden_input('upfiletype',$env{'form.upfiletype'}).
&hidden_input('upfile_associate',$env{'form.upfile_associate'}));
- $r->print(' '.(' 'x3)."\n");
my $roleselected = '';
if ($env{'form.showrole'} eq 'Any') {
- $roleselected = ' selected="selected" ';
+ $roleselected = ' selected="selected"';
}
my ($cnum,$cdom);
$r->print(&role_filter($context));
@@ -1316,26 +1510,56 @@ sub print_userlist {
($cnum,$cdom) = &get_course_identity();
$r->print(§ion_group_filter($cnum,$cdom));
}
- if (!(($context eq 'domain') && ($env{'form.roletype'} eq 'course'))) {
- $r->print(' '.&list_submit_button(&mt('Update Display')).
- "\n\n");
+ if ($env{'form.phase'} eq '') {
+ $r->print('
\n"
+ );
}
my ($indexhash,$keylist) = &make_keylist_array();
- my (%userlist,%userinfo);
- if ($context eq 'domain' && $env{'form.roletype'} eq 'course') {
+ my (%userlist,%userinfo,$clearcoursepick);
+ 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 $courseform =
- &Apache::lonhtmlcommon::course_selection($formname,$totcodes,
- $codetitles,$idlist,$idlist_titles);
+ &Apache::lonhtmlcommon::course_selection($formname,$numcodes,
+ $codetitles,$idlist,$idlist_titles,$crstype);
$r->print('
'.&mt('Warning: data retrieval for multiple courses can take considerable time, as this operation is not currently optimized.').''."\n");
- if ($env{'form.coursepick'}) {
+ '
'."\n";
}
@@ -2259,9 +2538,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(&mt('Problems occurred 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;
}
#
@@ -2303,6 +2586,11 @@ END
$grpfilter = 'all';
}
}
+ my %ltstatus = &Apache::lonlocal::texthash(
+ Active => 'Active',
+ Future => 'Future',
+ Expired => 'Expired',
+ );
# Get groups, role, permanent e-mail so we can sort on them if
# necessary.
foreach my $user (keys(%{$userlist})) {
@@ -2330,7 +2618,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 {
@@ -2437,7 +2726,7 @@ END
if ($clickers!~/\w/) { $clickers='-'; }
$in{'clicker'} = $clickers;
my $role = $in{'role'};
- $in{'role'}=&Apache::lonnet::plaintext($sdata->[$index{'role'}]);
+ $in{'role'}=&Apache::lonnet::plaintext($sdata->[$index{'role'}],$crstype);
if (! defined($in{'start'}) || $in{'start'} == 0) {
$in{'start'} = &mt('none');
} else {
@@ -2502,7 +2791,7 @@ END
}
}
$r->print('
'."\n");
}
@@ -2531,7 +2826,7 @@ END
}
if ($env{'course.'.$env{'request.course.id'}.'.internal.showphoto'}) {
if ($displayphotos eq 'on' && $role eq 'st' && $in{'photo'} ne '') {
- $r->print('
');
+ $r->print('
');
} else {
$r->print('
');
}
@@ -2718,7 +3013,7 @@ sub print_username_link {
$output = $in->{'username'};
} else {
$output = '{'username'}','$in->{'domain'}'".')" />'.
+ "'$in->{'username'}','$in->{'domain'}'".')">'.
$in->{'username'}.'';
}
return $output;
@@ -2729,6 +3024,7 @@ sub role_type_names {
'domain' => 'Domain Roles',
'author' => 'Co-Author Roles',
'course' => 'Course Roles',
+ 'community' => 'Community Roles',
);
return %lt;
}
@@ -2818,8 +3114,8 @@ sub select_actions {
}
}
if ($choices{'sections'}) {
- $output .= ''."\n".
- ''."\n";
+ $output .= ''."\n".
+ ''."\n";
}
}
return $output;
@@ -2833,9 +3129,9 @@ sub date_section_javascript {
delete => "Check the boxes for any users for whom roles are to be deleted, and click 'Proceed'",
none => "Choose an action to take for selected users",
);
- my $output = '
-
ENDTWO
return $output;
}
sub date_section_selector {
- my ($context,$permission) = @_;
+ my ($context,$permission,$crstype) = @_;
my $callingform = $env{'form.callingform'};
my $formname = 'dateselect';
my $groupslist = &get_groupslist();
my $sec_js = &setsections_javascript($formname,$groupslist);
my $output = <<"END";
ENDJS
my %lt = &Apache::lonlocal::texthash (
chac => 'Access dates to apply for selected users',
chse => 'Changes in section affiliation to apply to selected users',
- fors => 'For student roles changing the section, will result in a section switch as students may only be in one section of a course at a time.',
- forn => 'For a role in a course that is not a student role, a user may have roles in more than one section of a course at a time.',
+ fors => 'For student roles, changing the section will result in a section switch as students may only be in one section of a course at a time.',
+ forn => 'For a course role that is not "student", users may have roles in more than one section at a time.',
reta => "Retain each user's current section affiliations?",
- dnap => '(Does not apply to student roles).',
+ dnap => '(Does not apply to student roles).',
);
my ($date_items,$headertext);
if ($env{'form.bulkaction'} eq 'chgsec') {
@@ -2961,13 +3260,18 @@ ENDJS
}
$date_items = &date_setting_table($starttime,undef,$context,
$env{'form.bulkaction'},$formname,
- $permission);
+ $permission,$crstype);
}
$output .= '
'.$headertext.'
'.
- '';
return $output;
}
sub section_picker {
- my ($cdom,$cnum,$role,$rowtitle,$permission,$context,$mode) = @_;
+ my ($cdom,$cnum,$role,$rowtitle,$permission,$context,$mode,$crstype) = @_;
my %sections_count = &Apache::loncommon::get_sections($cdom,$cnum);
my $sections_select .= &course_sections(\%sections_count,$role);
- my $secbox = '
'.&Apache::lonhtmlcommon::start_pick_box()."\n";
+ my $secbox = '
'.&Apache::lonhtmlcommon::start_pick_box()."\n";
if ($mode eq 'upload') {
my ($options,$cb_script,$coursepick) =
- &default_role_selector($context,1);
+ &default_role_selector($context,1,$crstype);
$secbox .= &Apache::lonhtmlcommon::row_title(&mt('role'),'LC_oddrow_value').
$options. &Apache::lonhtmlcommon::row_closure(1)."\n";
}
@@ -3019,7 +3323,7 @@ sub section_picker {
'
';
return $secbox;
}
sub results_header_row {
- my ($rolefilter,$statusmode,$context,$permission,$mode) = @_;
+ my ($rolefilter,$statusmode,$context,$permission,$mode,$crstype) = @_;
my ($description,$showfilter);
if ($rolefilter ne 'Any') {
$showfilter = $rolefilter;
}
if ($context eq 'course') {
if ($mode eq 'csv' || $mode eq 'excel') {
- $description = &mt('Course - [_1]:',$env{'course.'.$env{'request.course.id'}.'.description'}).' ';
+ if ($crstype eq 'Community') {
+ $description = &mt('Community - [_1]:',$env{'course.'.$env{'request.course.id'}.'.description'}).' ';
+ } else {
+ $description = &mt('Course - [_1]:',$env{'course.'.$env{'request.course.id'}.'.description'}).' ';
+ }
}
if ($statusmode eq 'Expired') {
- $description .= &mt('Users in course with expired [_1] roles',$showfilter);
+ if ($crstype eq 'Community') {
+ $description .= &mt('Users in community with expired [_1] roles',$showfilter);
+ } else {
+ $description .= &mt('Users in course with expired [_1] roles',$showfilter);
+ }
} elsif ($statusmode eq 'Future') {
- $description .= &mt('Users in course with future [_1] roles',$showfilter);
+ if ($crstype eq 'Community') {
+ $description .= &mt('Users in community with future [_1] roles',$showfilter);
+ } else {
+ $description .= &mt('Users in course with future [_1] roles',$showfilter);
+ }
} elsif ($statusmode eq 'Active') {
- $description .= &mt('Users in course with active [_1] roles',$showfilter);
+ if ($crstype eq 'Community') {
+ $description .= &mt('Users in community with active [_1] roles',$showfilter);
+ } else {
+ $description .= &mt('Users in course with active [_1] roles',$showfilter);
+ }
} else {
if ($rolefilter eq 'Any') {
- $description .= &mt('All users in course');
+ if ($crstype eq 'Community') {
+ $description .= &mt('All users in community');
+ } else {
+ $description .= &mt('All users in course');
+ }
} else {
- $description .= &mt('All users in course with [_1] roles',$rolefilter);
+ if ($crstype eq 'Community') {
+ $description .= &mt('All users in community with [_1] roles',$rolefilter);
+ } else {
+ $description .= &mt('All users in course with [_1] roles',$rolefilter);
+ }
}
}
my $constraint;
@@ -3060,7 +3388,7 @@ sub results_header_row {
if ($viewablesec ne '') {
if ($env{'form.showrole'} eq 'st') {
$constraint = &mt('only users in section "[_1]"',$viewablesec);
- } elsif ($env{'form.showrole'} ne 'cc') {
+ } elsif (($env{'form.showrole'} ne 'cc') && ($env{'form.showrole'} ne 'co')) {
$constraint = &mt('only users affiliated with no section or section "[_1]"',$viewablesec);
}
if (($env{'form.grpfilter'} ne 'all') && ($env{'form.grpfilter'} ne '')) {
@@ -3145,22 +3473,32 @@ sub results_header_row {
if ($rolefilter eq 'Any') {
$description .= &mt('All users with co-author roles in domain',$showfilter);
} else {
- $description .= &mt('All co-authors in domain with [_1] roles',$rolefilter);
+ $description .= &mt('All co-authors in domain with [_1] roles',$rolefilter);
}
}
- } elsif ($env{'form.roletype'} eq 'course') {
+ } elsif (($env{'form.roletype'} eq 'course') ||
+ ($env{'form.roletype'} eq 'community')) {
+
my $coursefilter = $env{'form.coursepick'};
- if ($coursefilter eq 'category') {
- my $instcode = &instcode_from_coursefilter();
- if ($instcode eq '.') {
+ if ($env{'form.roletype'} eq 'course') {
+ if ($coursefilter eq 'category') {
+ my $instcode = &instcode_from_coursefilter();
+ if ($instcode eq '.') {
+ $description .= &mt('All courses in domain').' - ';
+ } else {
+ $description .= &mt('Courses in domain with institutional code: [_1]',$instcode).' - ';
+ }
+ } elsif ($coursefilter eq 'selected') {
+ $description .= &mt('Selected courses in domain').' - ';
+ } elsif ($coursefilter eq 'all') {
$description .= &mt('All courses in domain').' - ';
- } else {
- $description .= &mt('Courses in domain with institutional code: [_1]',$instcode).' - ';
}
- } elsif ($coursefilter eq 'selected') {
- $description .= &mt('Selected courses in domain').' - ';
- } elsif ($coursefilter eq 'all') {
- $description .= &mt('All courses in domain').' - ';
+ } elsif ($env{'form.roletype'} eq 'community') {
+ if ($coursefilter eq 'selected') {
+ $description .= &mt('Selected communities in domain').' - ';
+ } elsif ($coursefilter eq 'all') {
+ $description .= &mt('All communities in domain').' - ';
+ }
}
if ($statusmode eq 'Expired') {
$description .= &mt('users with expired [_1] roles',$showfilter);
@@ -3197,7 +3535,7 @@ sub viewable_section {
#################################################
#################################################
sub show_drop_list {
- my ($r,$classlist,$nosort,$permission) = @_;
+ my ($r,$classlist,$nosort,$permission,$crstype) = @_;
my $cid = $env{'request.course.id'};
my ($cnum,$cdom) = &get_course_identity($cid);
if (! exists($env{'form.sortby'})) {
@@ -3215,10 +3553,12 @@ sub show_drop_list {
-
+
END
my ($indexhash,$keylist) = &make_keylist_array();
my $studentcount = 0;
@@ -3241,7 +3581,11 @@ END
}
}
if (!$studentcount) {
- $r->print(&mt('There are no students to drop.'));
+ if ($crstype eq 'Community') {
+ $r->print(&mt('There are no members to drop.'));
+ } else {
+ $r->print(&mt('There are no students to drop.'));
+ }
return;
}
my ($classgroups) = &Apache::loncoursedata::get_group_memberships(
@@ -3249,11 +3593,16 @@ END
my %lt=&Apache::lonlocal::texthash('usrn' => "username",
'dom' => "domain",
'sn' => "student name",
+ 'mn' => "member name",
'sec' => "section",
'start' => "start date",
'end' => "end date",
'groups' => "active groups",
);
+ my $nametitle = $lt{'sn'};
+ if ($crstype eq 'Community') {
+ $nametitle = $lt{'mn'};
+ }
if ($nosort) {
$r->print(&Apache::loncommon::start_data_table().
&Apache::loncommon::start_data_table_header_row());
@@ -3262,7 +3611,7 @@ END
';
- $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"));
- $str .= "
';
+
$r->print($str);
return;
}
@@ -3430,11 +3800,25 @@ sub upfile_drop_add {
'ipwd_choice' => 'scalar',
'email_choice' => 'scalar',
'role_choice' => 'scalar',
- 'domain_choice' => 'scalar'});
+ 'domain_choice' => 'scalar',
+ 'inststatus_choice' => 'scalar'});
#
+ my ($cid,$crstype,$setting);
+ if ($context eq 'domain') {
+ $setting = $env{'form.roleaction'};
+ }
+ if ($env{'request.course.id'} ne '') {
+ $cid = $env{'request.course.id'};
+ $crstype = &Apache::loncommon::course_type();
+ } elsif ($setting eq 'course') {
+ if (&Apache::lonnet::is_course($env{'form.dcdomain'},$env{'form.dccourse'})) {
+ $cid = $env{'form.dcdomain'}.'_'.$env{'form.dccourse'};
+ $crstype = &Apache::loncommon::course_type($cid);
+ }
+ }
my ($startdate,$enddate) = &get_dates_from_form();
if ($env{'form.makedatesdefault'}) {
- $r->print(&make_dates_default($startdate,$enddate,$context));
+ $r->print(&make_dates_default($startdate,$enddate,$context,$crstype));
}
# Determine domain and desired host (home server)
my $defdom=$env{'request.role.domain'};
@@ -3486,43 +3870,36 @@ sub upfile_drop_add {
$amode = ''; # This causes the loop below to be skipped
}
}
- my ($cid,$defaultsec,$defaultrole,$setting);
+ my ($defaultsec,$defaultrole);
if ($context eq 'domain') {
- $setting = $env{'form.roleaction'};
if ($setting eq 'domain') {
$defaultrole = $env{'form.defaultrole'};
} elsif ($setting eq 'course') {
$defaultrole = $env{'form.courserole'};
$defaultsec = $env{'form.sections'};
- }
+ }
} elsif ($context eq 'author') {
$defaultrole = $env{'form.defaultrole'};
} elsif ($context eq 'course') {
$defaultrole = $env{'form.defaultrole'};
$defaultsec = $env{'form.sections'};
}
- if ($env{'request.course.id'} ne '') {
- $cid = $env{'request.course.id'};
- } elsif ($setting eq 'course') {
- if (&Apache::lonnet::is_course($env{'form.dcdomain'},$env{'form.dccourse'})) {
- $cid = $env{'form.dcdomain'}.'_'.$env{'form.dccourse'};
- }
- }
# Check to see if user information can be changed
my @userinfo = ('firstname','middlename','lastname','generation',
'permanentemail','id');
my %canmodify;
if (&Apache::lonnet::allowed('mau',$domain)) {
+ push(@userinfo,'inststatus');
foreach my $field (@userinfo) {
$canmodify{$field} = 1;
}
}
my (%userlist,%modifiable_fields,@poss_roles);
my $secidx = &Apache::loncoursedata::CL_SECTION();
- my @courseroles = &roles_by_context('course',1);
+ my @courseroles = &roles_by_context('course',1,$crstype);
if (!&Apache::lonnet::allowed('mau',$domain)) {
if ($context eq 'course' || $context eq 'author') {
- @poss_roles = &curr_role_permissions($context);
+ @poss_roles = &curr_role_permissions($context,'','',$crstype);
my @statuses = ('active','future');
my ($indexhash,$keylist) = &make_keylist_array();
my %info;
@@ -3561,6 +3938,8 @@ sub upfile_drop_add {
} else {
$r->print('
'.&mt('Adding/Modifying Users')."
\n
\n");
}
+ $r->rflush;
+
my %counts = (
user => 0,
auth => 0,
@@ -3605,14 +3984,21 @@ sub upfile_drop_add {
$r->print($groupwarn.' ');
}
}
- my (%curr_rules,%got_rules,%alerts);
- my %customroles = &my_custom_roles();
- my @permitted_roles = &roles_on_upload($context,$setting,%customroles);
+ my (%curr_rules,%got_rules,%alerts,%cancreate);
+ my %customroles = &my_custom_roles($crstype);
+ my @permitted_roles =
+ &roles_on_upload($context,$setting,$crstype,%customroles);
+ my %longtypes = &Apache::lonlocal::texthash(
+ official => 'Institutional',
+ unofficial => 'Non-institutional',
+ );
+ map { $cancreate{$_} = &can_create_user($domain,$context,$_); } keys(%longtypes);
# Get new users list
foreach my $line (@userdata) {
my @secs;
my %entries=&Apache::loncommon::record_sep($line);
# Determine user name
+ $entries{$fields{'username'}} =~ s/^\s+|\s+$//g;
unless (($entries{$fields{'username'}} eq '') ||
(!defined($entries{$fields{'username'}}))) {
my ($fname, $mname, $lname,$gen) = ('','','','');
@@ -3635,11 +4021,17 @@ sub upfile_drop_add {
}
if ($entries{$fields{'username'}}
ne &LONCAPA::clean_username($entries{$fields{'username'}})) {
+ my $nowhitespace;
+ if ($entries{$fields{'username'}} =~ /\s/) {
+ $nowhitespace = ' - '.&mt('usernames may not contain spaces.');
+ }
$r->print(' '.
&mt('[_1]: Unacceptable username for user [_2] [_3] [_4] [_5]',
- ''.$entries{$fields{'username'}}.'',$fname,$mname,$lname,$gen));
+ ''.$entries{$fields{'username'}}.'',$fname,$mname,$lname,$gen).
+ $nowhitespace);
next;
} else {
+ $entries{$fields{'domain'}} =~ s/^\s+|\s+$//g;
if ($entries{$fields{'domain'}}
ne &LONCAPA::clean_domain($entries{$fields{'domain'}})) {
$r->print(' '. ''.$entries{$fields{'domain'}}.
@@ -3698,9 +4090,18 @@ sub upfile_drop_add {
# determine email address
my $email='';
if (defined($fields{'email'})) {
+ $entries{$fields{'email'}} =~ s/^\s+|\s+$//g;
if (defined($entries{$fields{'email'}})) {
$email=$entries{$fields{'email'}};
- unless ($email=~/^[^\@]+\@[^\@]+$/) { $email=''; } }
+ unless ($email=~/^[^\@]+\@[^\@]+$/) { $email=''; }
+ }
+ }
+ # determine affiliation
+ my $inststatus='';
+ if (defined($fields{'inststatus'})) {
+ if (defined($entries{$fields{'inststatus'}})) {
+ $inststatus=$entries{$fields{'inststatus'}};
+ }
}
# determine user password
my $password = $genpwd;
@@ -3736,7 +4137,7 @@ sub upfile_drop_add {
$role = $defaultrole;
}
# Clean up whitespace
- foreach (\$id,\$fname,\$mname,\$lname,\$gen) {
+ foreach (\$id,\$fname,\$mname,\$lname,\$gen,\$inststatus) {
$$_ =~ s/(\s+$|^\s+)//g;
}
# check against rules
@@ -3745,9 +4146,16 @@ sub upfile_drop_add {
my (%rulematch,%inst_results,%idinst_results);
my $uhome=&Apache::lonnet::homeserver($username,$userdomain);
if ($uhome eq 'no_host') {
- next if ($userdomain ne $domain);
+ if ($userdomain ne $domain) {
+ $r->print(' '.
+ &mt('[_1]: The domain specified ([_2]) is different to that of the course.',
+ ''.$username.'',$userdomain).' '.
+ &mt('The user does not already exist, and you may not create a new user in a different domain.'));
+ next;
+ }
$checkid = 1;
$newuser = 1;
+ my $user = $username.':'.$domain;
my $checkhash;
my $checks = { 'username' => 1 };
$checkhash->{$username.':'.$domain} = { 'newuser' => 1, };
@@ -3756,9 +4164,26 @@ sub upfile_drop_add {
\%got_rules);
if (ref($alerts{'username'}) eq 'HASH') {
if (ref($alerts{'username'}{$domain}) eq 'HASH') {
- next if ($alerts{'username'}{$domain}{$username});
+ if ($alerts{'username'}{$domain}{$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;
+ }
+ }
+ }
+ my $usertype = 'unofficial';
+ if (ref($rulematch{$user}) eq 'HASH') {
+ if ($rulematch{$user}{'username'}) {
+ $usertype = 'official';
}
}
+ unless ($cancreate{$usertype}) {
+ my $showtype = $longtypes{$usertype};
+ $r->print(' '.
+ &mt('[_1]: The user does not exist, and you are not permitted to create users of type: [_2].',''.$username.'',$showtype));
+ next;
+ }
} else {
if ($context eq 'course' || $context eq 'author') {
if ($userdomain eq $domain ) {
@@ -3783,7 +4208,7 @@ sub upfile_drop_add {
}
}
my @newinfo = (\$fname,\$mname,\$lname,\$gen,\$email,\$id);
- for (my $i=0; $i<@userinfo; $i++) {
+ for (my $i=0; $i<@newinfo; $i++) {
if (${$newinfo[$i]} ne '') {
if (!$canmodify{$userinfo[$i]}) {
${$newinfo[$i]} = '';
@@ -3809,7 +4234,12 @@ sub upfile_drop_add {
\%got_rules);
if (ref($alerts{'id'}) eq 'HASH') {
if (ref($alerts{'id'}{$userdomain}) eq 'HASH') {
- next if ($alerts{'id'}{$userdomain}{$id});
+ if ($alerts{'id'}{$userdomain}{$id}) {
+ $r->print(&mt('[_1]: has a student/employee ID matching the format at your institution, but the ID is found by your directory service.',
+ ''.$username.'').' '.
+ &mt('Consequently, the user was not created.'));
+ next;
+ }
}
}
}
@@ -3832,7 +4262,7 @@ sub upfile_drop_add {
$fname,$mname,$lname,$gen,$sec,$enddate,
$startdate,$env{'form.forceid'},
$desiredhost,$email,'manual','',$cid,
- '',$context);
+ '',$context,$inststatus);
$userresult = $roleresult;
} else {
if ($role ne '') {
@@ -3841,7 +4271,7 @@ sub upfile_drop_add {
$role = 'cr_'.$env{'user.domain'}.'_'.
$env{'user.name'}.'_'.$role;
}
- if ($role ne 'cc') {
+ if (($role ne 'cc') && ($role ne 'co')) {
if (@secs > 1) {
$multiple = 1;
foreach my $sec (@secs) {
@@ -3852,7 +4282,7 @@ sub upfile_drop_add {
$mname,$lname,$gen,$sec,
$env{'form.forceid'},$desiredhost,
$email,$role,$enddate,
- $startdate,$checkid);
+ $startdate,$checkid,$inststatus);
}
} elsif (@secs > 0) {
$singlesec = $secs[0];
@@ -3867,7 +4297,8 @@ sub upfile_drop_add {
$id,$amode,$password,$fname,
$mname,$lname,$gen,$singlesec,
$env{'form.forceid'},$desiredhost,
- $email,$role,$enddate,$startdate,$checkid);
+ $email,$role,$enddate,$startdate,
+ $checkid,$inststatus);
}
}
if ($multiple) {
@@ -3903,7 +4334,7 @@ sub upfile_drop_add {
}
} # end of foreach (@userdata)
# Flush the course logs so reverse user roles immediately updated
- &Apache::lonnet::flushcourselogs();
+ $r->register_cleanup(\&Apache::lonnet::flushcourselogs);
$r->print("
\n");
if ($counts{'role'} > 0) {
@@ -4041,14 +4472,24 @@ sub user_change_result {
# ========================================================= Menu Phase Two Drop
sub print_drop_menu {
- my ($r,$context,$permission) = @_;
- $r->print('
'."\n".
''. &Apache::loncommon::end_page());
return;
@@ -4057,9 +4498,12 @@ sub print_drop_menu {
# ================================================================== 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 eq 'drop') {
@changelist = &Apache::loncommon::get_env_multiple('form.droplist');
@@ -4071,7 +4515,7 @@ sub update_user_list {
'reenable' => 'Re-enabled',
'activate' => 'Activated',
'chgdates' => 'Changed Access Dates for',
- 'chgsec' => 'Changed section for',
+ 'chgsec' => 'Changed section(s) for',
'drop' => 'Dropped',
},
error => {'revoke' => 'revoking',
@@ -4088,8 +4532,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);
if ($choice eq 'drop') {
($uname,$udom,$sec) = split(/:/,$item,-1);
$role = 'st';
@@ -4130,7 +4575,7 @@ sub update_user_list {
}
}
}
- my $plrole = &Apache::lonnet::plaintext($role);
+ my $plrole = &Apache::lonnet::plaintext($role,$crstype);
my $start = $env{'form.'.$item.'_start'};
my $end = $env{'form.'.$item.'_end'};
if ($choice eq 'drop') {
@@ -4187,15 +4632,24 @@ sub update_user_list {
}
} 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;
+ $nothingtodo = 1;
} else {
$revresult =
&Apache::lonnet::revokerole($udom,$uname,
@@ -4222,13 +4676,23 @@ sub update_user_list {
} else {
if ($sec eq '') {
$nochg = 1;
+ $keepnosection = 1;
} else {
push(@retained,$sec);
}
}
# add new sections
+ my (@diffs,@shownew);
+ if (@retained) {
+ @diffs = &Apache::loncommon::compare_arrays(\@retained,\@newsecs);
+ } else {
+ @diffs = @newsecs;
+ }
if (@newsecs == 0) {
- if (!$nochg) {
+ 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);
@@ -4237,15 +4701,41 @@ sub update_user_list {
$result = &Apache::lonnet::assignrole($udom,$uname,$newscope,$role,$end,$start,'','',$context);
}
}
+ $showsecs = &mt('No section');
+ } elsif (@diffs == 0) {
+ $result = 'ok';
+ $nothingtodo = 1;
} else {
foreach my $newsec (@newsecs) {
if (!grep(/^\Q$newsec\E$/,@retained)) {
if ($role eq 'st') {
$result = &Apache::lonnet::modify_student_enrollment($udom,$uname,undef,undef,undef,undef,undef,$newsec,$end,$start,$type,$locktype,$cid,'',$context);
+ 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);
@@ -4253,6 +4743,15 @@ sub update_user_list {
}
}
}
+ unless ($role eq 'st') {
+ unless ($showsecs) {
+ my @tolist = sort(@shownew,@retained);
+ if ($keepnosection) {
+ push(@tolist,&mt('No section'));
+ }
+ $showsecs = join(', ',@tolist);
+ }
+ }
}
}
my $extent = $scope;
@@ -4263,13 +4762,48 @@ 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) = @_;
my ($cdom,$cnum) = ($scope=~m{^/($match_domain)/($match_courseid)});
@@ -4382,7 +4937,7 @@ sub course_sections {
my $output = '';
my @sections = (sort {$a <=> $b} keys %{$sections_count});
my $numsec = scalar(@sections);
- my $is_selected = ' selected="selected" ';
+ my $is_selected = ' selected="selected"';
if ($numsec <= 1) {
$output = ''."\n".
' '."\n";
@@ -4442,7 +4997,7 @@ sub get_groupslist {
}
sub setsections_javascript {
- my ($formname,$groupslist,$mode,$checkauth) = @_;
+ my ($formname,$groupslist,$mode,$checkauth,$crstype) = @_;
my ($checkincluded,$finish,$rolecode,$setsection_js);
if ($mode eq 'upload') {
$checkincluded = 'formname.name == "'.$formname.'"';
@@ -4481,8 +5036,11 @@ sub setsections_javascript {
}
my %alerts = &Apache::lonlocal::texthash(
secd => 'Section designations do not apply to Course Coordinator roles.',
+ sedn => 'Section designations do not apply to Coordinator roles.',
accr => 'A course coordinator role will be added with access to all sections.',
+ acor => 'A coordinator role will be added with access to all sections',
inea => 'In each course, each user may only have one student role at a time.',
+ inco => 'In each community, each user may only have one member role at a time.',
youh => 'You had selected ',
secs => 'sections.',
plmo => 'Please modify your selections so they include no more than one section.',
@@ -4490,78 +5048,123 @@ sub setsections_javascript {
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.',
+ nonw => 'Section names may only contain letters or numbers.',
);
$setsection_js .= <<"ENDSECCODE";
-function setSections(formname) {
+function setSections(formname,crstype) {
var re1 = /^currsec_/;
+ var re2 =/\\W/;
+ var trimleading = /^\\s+/;
+ var trimtrailing = /\\s+\$/;
var groups = new Array($groupslist);
for (var i=0;i 0) {
- if (formname.elements[i+1].value != "" && formname.elements[i+1].value != null) {
- sections = sections + "," + formname.elements[i+1].value;
- }
- }
- else {
- sections = formname.elements[i+1].value;
- }
- var newsecs = formname.elements[i+1].value;
- var numsplit;
+ var newsecs = formname.elements[num+1].value;
+ var validsecs = new Array();
+ var validsecstr = '';
+ var badsecs = new Array();
if (newsecs != null && newsecs != "") {
- numsplit = newsecs.split(/,/g);
- numsec = numsec + numsplit.length;
+ var numsplit;
+ if (newsecs.indexOf(',') == -1) {
+ numsplit = new Array(newsecs);
+ } else {
+ numsplit = newsecs.split(/,/g);
+ }
+ for (var m=0; m 0) {
+ alert("$alerts{'nonw'}\\n$alerts{'plch'}");
+ return;
+ }
+ numsec = numsec + validsecs.length;
}
-
if ((role == 'st') && (numsec > 1)) {
- alert("$alerts{'inea'} $alerts{'youh'} "+numsec+" $alerts{'secs'}\\n$alerts{'plmo'}")
+ if (crstype == 'Community') {
+ alert("$alerts{'inea'} $alerts{'youh'} "+numsec+" $alerts{'secs'}\\n$alerts{'plmo'}");
+ } else {
+ alert("$alerts{'inco'} $alerts{'youh'} "+numsec+" $alerts{'secs'}\\n$alerts{'plmo'}");
+ }
return;
- }
- else {
- if (numsplit != null) {
- for (var j=0; j 1)) {
- alert("$alerts{'inea'}. $alerts{'youh'} "+numsections+" $alerts{'sect'}.\\n$alerts{'plsm'}.")
+ if (document.$formname.crstype.value == 'Community') {
+ alert("$alerts{'inco'}. $alerts{'youh'} "+numsections+" $alerts{'sect'}.\\n$alerts{'plsm'}.")
+ } else {
+ alert("$alerts{'inea'}. $alerts{'youh'} "+numsections+" $alerts{'sect'}.\\n$alerts{'plsm'}.")
+ }
return;
}
for (var j=0; j 0)) {
+ alert("$alerts{'secd'} $cotext $alerts{'role'}.\\n$alerts{'accr'}.");
+ section = "";
+ }
SCRIPTTOP
if ($mode ne 'upload') {
$dc_setcourse_code .= (<<"ENDSCRIPT");
var coursename = "_$env{'request.role.domain'}"+"_"+course+"_"+userrole
var numcourse = getIndex(document.$formname.dccourse);
if (numcourse == "-1") {
- alert("$alerts{'thwa'}");
+ if (document.$formname.type == 'Community') {
+ alert("$alerts{'thwc'}");
+ } else {
+ alert("$alerts{'thwa'}");
+ }
return;
}
else {
@@ -4989,19 +5618,22 @@ ENDSCRIPT
sub sectioncheck_alerts {
my %alerts = &Apache::lonlocal::texthash(
- curd => 'You must select a course in the current domain',
+ curd => 'You must select a course or community in the current domain',
inea => 'In each course, each user may only have one student role at a time',
+ inco => 'In each community, each user may only have one member role at a time',
youh => 'You had selected',
sect => 'sections',
plsm => 'Please modify your selections so they include no more than one section',
mayn => 'may not be used as the name for a section, as it is a reserved word',
plsc => 'Please choose a different section name',
mayt => 'may not be used as the name for a section, as it is the name of a course group',
+ mayc => 'may not be used as the name for a section, as it is the name of a community group',
secn => 'Section names and group names must be distinct',
secd => 'Section designations do not apply to ',
role => 'roles',
accr => 'role will be added with access to all sections',
- thwa => 'There was a problem with your course selection'
+ thwa => 'There was a problem with your course selection',
+ thwc => 'There was a problem with your community selection',
);
return %alerts;
}