--- loncom/interface/lonuserutils.pm 2007/10/22 22:16:38 1.1
+++ loncom/interface/lonuserutils.pm 2019/07/23 13:58:53 1.201
@@ -1,7 +1,7 @@
# The LearningOnline Network with CAPA
# Utility functions for managing LON-CAPA user accounts
#
-# $Id: lonuserutils.pm,v 1.1 2007/10/22 22:16:38 raeburn Exp $
+# $Id: lonuserutils.pm,v 1.201 2019/07/23 13:58:53 raeburn Exp $
#
# Copyright Michigan State University Board of Trustees
#
@@ -30,23 +30,40 @@
package Apache::lonuserutils;
+=pod
+
+=head1 NAME
+
+Apache::lonuserutils.pm
+
+=head1 SYNOPSIS
+
+ Utilities for management of users and custom roles
+
+ Provides subroutines called by loncreateuser.pm
+
+=head1 OVERVIEW
+
+=cut
+
use strict;
use Apache::lonnet;
use Apache::loncommon();
use Apache::lonhtmlcommon;
use Apache::lonlocal;
-use LONCAPA();
+use Apache::longroup;
+use HTML::Entities;
+use LONCAPA qw(:DEFAULT :match);
###############################################################
###############################################################
# Drop student from all sections of a course, except optional $csec
sub modifystudent {
- my ($udom,$unam,$courseid,$csec,$desiredhost)=@_;
+ my ($udom,$unam,$courseid,$csec,$desiredhost,$context)=@_;
# if $csec is undefined, drop the student from all the courses matching
# this one. If $csec is defined, drop them from all other sections of
# this course and add them to section $csec
- my $cdom = $env{'course.'.$courseid.'.domain'};
- my $cnum = $env{'course.'.$courseid.'.num'};
+ my ($cnum,$cdom) = &get_course_identity($courseid);
my %roles = &Apache::lonnet::dump('roles',$udom,$unam);
my ($tmp) = keys(%roles);
# Bail out if we were unable to get the students roles
@@ -68,14 +85,15 @@ sub modifystudent {
my $reply=&Apache::lonnet::modifystudent
# dom name id mode pass f m l g
($udom,$unam,'', '', '',undef,undef,undef,undef,
- $section,time,undef,undef,$desiredhost);
+ $section,time,undef,undef,$desiredhost,'','manual',
+ '',$courseid,'',$context);
$result .= $reply.':';
}
}
}
}
if ($result eq '') {
- $result = 'Unable to find section for this student';
+ $result = &mt('Unable to find section for this student');
} else {
$result =~ s/(ok:)+/ok/g;
}
@@ -85,71 +103,207 @@ sub modifystudent {
sub modifyuserrole {
my ($context,$setting,$changeauth,$cid,$udom,$uname,$uid,$umode,$upass,
$first,$middle,$last,$gene,$sec,$forceid,$desiredhome,$email,$role,
- $end,$start) = @_;
- my ($scope,$userresult,$authresult,$roleresult);
+ $end,$start,$checkid,$inststatus) = @_;
+ my ($scope,$userresult,$authresult,$roleresult,$idresult);
if ($setting eq 'course' || $context eq 'course') {
$scope = '/'.$cid;
$scope =~ s/\_/\//g;
- if ($role ne 'cc' && $sec ne '') {
+ if (($role ne 'cc') && ($role ne 'co') && ($sec ne '')) {
$scope .='/'.$sec;
}
- } elsif ($setting eq 'domain') {
+ } elsif ($context eq 'domain') {
$scope = '/'.$env{'request.role.domain'}.'/';
- } elsif ($setting eq 'construction_space') {
+ } elsif ($context eq 'author') {
$scope = '/'.$env{'user.domain'}.'/'.$env{'user.name'};
}
if ($context eq 'domain') {
my $uhome = &Apache::lonnet::homeserver($uname,$udom);
if ($uhome ne 'no_host') {
- if (($changeauth) && (&Apache::lonnet::allowed('mau',$udom))) {
+ if (($changeauth eq 'Yes') && (&Apache::lonnet::allowed('mau',$udom))) {
if ((($umode =~ /^krb4|krb5|internal$/) && $upass ne '') ||
($umode eq 'localauth')) {
$authresult = &Apache::lonnet::modifyuserauth($udom,$uname,$umode,$upass);
}
}
+ if (($forceid) && (&Apache::lonnet::allowed('mau',$udom)) &&
+ ($env{'form.recurseid'}) && ($checkid)) {
+ my %userupdate = (
+ lastname => $last,
+ middlename => $middle,
+ firstname => $first,
+ generation => $gene,
+ id => $uid,
+ );
+ $idresult = &propagate_id_change($uname,$udom,\%userupdate);
+ }
}
}
$userresult =
&Apache::lonnet::modifyuser($udom,$uname,$uid,$umode,$upass,$first,
$middle,$last,$gene,$forceid,$desiredhome,
- $email,$role,$start,$end);
+ $email,$inststatus);
if ($userresult eq 'ok') {
- if ($role ne '') {
+ if ($role ne '') {
+ $role =~ s/_/\//g;
$roleresult = &Apache::lonnet::assignrole($udom,$uname,$scope,
- $role,$end,$start);
+ $role,$end,$start,'',
+ '',$context);
+ }
+ }
+ return ($userresult,$authresult,$roleresult,$idresult);
+}
+
+sub propagate_id_change {
+ my ($uname,$udom,$user) = @_;
+ my (@types,@roles);
+ @types = ('active','future');
+ @roles = ('st');
+ my $idresult;
+ my %roleshash = &Apache::lonnet::get_my_roles($uname,
+ $udom,'userroles',\@types,\@roles);
+ my %args = (
+ one_time => 1,
+ );
+ foreach my $item (keys(%roleshash)) {
+ my ($cnum,$cdom,$role) = split(/:/,$item,-1);
+ my ($start,$end) = split(/:/,$roleshash{$item});
+ if (&Apache::lonnet::is_course($cdom,$cnum)) {
+ my $result = &update_classlist($cdom,$cnum,$udom,$uname,$user);
+ my %coursehash =
+ &Apache::lonnet::coursedescription($cdom.'_'.$cnum,\%args);
+ my $cdesc = $coursehash{'description'};
+ if ($cdesc eq '') {
+ $cdesc = $cdom.'_'.$cnum;
+ }
+ if ($result eq 'ok') {
+ $idresult .= &mt('Classlist update for "[_1]" in "[_2]".',$uname.':'.$udom,$cdesc).'
'."\n";
+ } else {
+ $idresult .= &mt('Error: "[_1]" during classlist update for "[_2]" in "[_3]".',$result,$uname.':'.$udom,$cdesc).'
'."\n";
+ }
+ }
+ }
+ return $idresult;
+}
+
+sub update_classlist {
+ my ($cdom,$cnum,$udom,$uname,$user,$newend) = @_;
+ my ($uid,$classlistentry);
+ my $fullname =
+ &Apache::lonnet::format_name($user->{'firstname'},$user->{'middlename'},
+ $user->{'lastname'},$user->{'generation'},
+ 'lastname');
+ my %classhash = &Apache::lonnet::get('classlist',[$uname.':'.$udom],
+ $cdom,$cnum);
+ my @classinfo = split(/:/,$classhash{$uname.':'.$udom});
+ my $ididx=&Apache::loncoursedata::CL_ID() - 2;
+ my $nameidx=&Apache::loncoursedata::CL_FULLNAME() - 2;
+ my $endidx = &Apache::loncoursedata::CL_END() - 2;
+ my $startidx = &Apache::loncoursedata::CL_START() - 2;
+ for (my $i=0; $i<@classinfo; $i++) {
+ if ($i == $endidx) {
+ if ($newend ne '') {
+ $classlistentry .= $newend.':';
+ } else {
+ $classlistentry .= $classinfo[$i].':';
+ }
+ } elsif ($i == $startidx) {
+ if ($newend ne '') {
+ if ($classinfo[$i] > $newend) {
+ $classlistentry .= $newend.':';
+ } else {
+ $classlistentry .= $classinfo[$i].':';
+ }
+ } else {
+ $classlistentry .= $classinfo[$i].':';
+ }
+ } elsif ($i == $ididx) {
+ if (defined($user->{'id'})) {
+ $classlistentry .= $user->{'id'}.':';
+ } else {
+ $classlistentry .= $classinfo[$i].':';
+ }
+ } elsif ($i == $nameidx) {
+ if (defined($user->{'lastname'})) {
+ $classlistentry .= $fullname.':';
+ } else {
+ $classlistentry .= $classinfo[$i].':';
+ }
+ } else {
+ $classlistentry .= $classinfo[$i].':';
}
}
- return ($userresult,$authresult,$roleresult);
+ $classlistentry =~ s/:$//;
+ my $reply=&Apache::lonnet::cput('classlist',
+ {"$uname:$udom" => $classlistentry},
+ $cdom,$cnum);
+ if (($reply eq 'ok') || ($reply eq 'delayed')) {
+ return 'ok';
+ } else {
+ return 'error: '.$reply;
+ }
}
+
###############################################################
###############################################################
-# build a domain and server selection form
-sub domain_form {
- my ($defdom) = @_;
- # Set up domain and server selection forms
+# build a role type and role selection form
+sub domain_roles_select {
+ # Set up the role type and role selection boxes when in
+ # domain context
+ #
+ # Role types
+ my @roletypes = ('domain','author','course','community');
+ my %lt = &role_type_names();
+ my $onchangefirst = "updateCols('showrole')";
+ my $onchangesecond = "updateCols('showrole')";
#
- # Get the domains
- my @domains = &Apache::lonnet::all_domains();
# build up the menu information to be passed to
# &Apache::loncommon::linked_select_forms
my %select_menus;
- foreach my $dom (@domains) {
+ if ($env{'form.roletype'} eq '') {
+ $env{'form.roletype'} = 'domain';
+ }
+ foreach my $roletype (@roletypes) {
# set up the text for this domain
- $select_menus{$dom}->{'text'}= $dom;
+ $select_menus{$roletype}->{'text'}= $lt{$roletype};
+ my $crstype;
+ if ($roletype eq 'community') {
+ $crstype = 'Community';
+ }
# we want a choice of 'default' as the default in the second menu
- $select_menus{$dom}->{'default'}= 'default';
- $select_menus{$dom}->{'select2'}->{'default'} = 'default';
+ if ($env{'form.roletype'} ne '') {
+ $select_menus{$roletype}->{'default'} = $env{'form.showrole'};
+ } else {
+ $select_menus{$roletype}->{'default'} = 'Any';
+ }
# Now build up the other items in the second menu
- my %servers = &Apache::lonnet::get_servers($dom,'library');
- foreach my $server (keys(%servers)) {
- $select_menus{$dom}->{'select2'}->{$server}
- = "$server $servers{$server}";
+ my @roles;
+ if ($roletype eq 'domain') {
+ @roles = &domain_roles();
+ } elsif ($roletype eq 'author') {
+ @roles = &construction_space_roles();
+ } else {
+ my $custom = 1;
+ @roles = &course_roles('domain',undef,$custom,$roletype);
}
+ my $order = ['Any',@roles];
+ $select_menus{$roletype}->{'order'} = $order;
+ foreach my $role (@roles) {
+ if ($role eq 'cr') {
+ $select_menus{$roletype}->{'select2'}->{$role} =
+ &mt('Custom role');
+ } else {
+ $select_menus{$roletype}->{'select2'}->{$role} =
+ &Apache::lonnet::plaintext($role,$crstype);
+ }
+ }
+ $select_menus{$roletype}->{'select2'}->{'Any'} = &mt('Any');
}
- my $result = &Apache::loncommon::linked_select_forms
- ('studentform',' with home server ',$defdom,
- 'lcdomain','lcserver',\%select_menus);
+ my $result = &Apache::loncommon::linked_select_forms
+ ('studentform',(' 'x3).&mt('Role: '),$env{'form.roletype'},
+ 'roletype','showrole',\%select_menus,
+ ['domain','author','course','community'],$onchangefirst,
+ $onchangesecond);
return $result;
}
@@ -161,7 +315,8 @@ sub hidden_input {
}
sub print_upload_manager_header {
- my ($r,$datatoken,$distotal,$krbdefdom,$context)=@_;
+ my ($r,$datatoken,$distotal,$krbdefdom,$context,$permission,$crstype,
+ $can_assign)=@_;
my $javascript;
#
if (! exists($env{'form.upfile_associate'})) {
@@ -175,9 +330,9 @@ sub print_upload_manager_header {
}
}
if ($env{'form.upfile_associate'} eq 'reverse') {
- $javascript=&upload_manager_javascript_reverse_associate();
+ $javascript=&upload_manager_javascript_reverse_associate($can_assign);
} else {
- $javascript=&upload_manager_javascript_forward_associate();
+ $javascript=&upload_manager_javascript_forward_associate($can_assign);
}
#
# Deal with restored settings
@@ -191,15 +346,31 @@ sub print_upload_manager_header {
$password_choice = 'int';
}
#
+ my $groupslist;
+ if ($context eq 'course') {
+ $groupslist = &get_groupslist();
+ }
my $javascript_validations =
- &javascript_validations('auth',$krbdefdom,$password_choice,undef,
- $env{'request.role.domain'});
- my $checked=(($env{'form.noFirstLine'})?' checked="checked" ':'');
- $r->print(&mt('Total number of records found in file: [_1].',$distotal).
- "
\n");
- $r->print('
'. + &mt('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.','
').
+ "
'.&mt('Change authentication for existing users to these settings?').'
'; + $Str .= '' + .&mt('Change authentication for existing users in domain "[_1]" to these settings?' + ,$defdom) + .' ' + .' ' + .'
'; } else { - $Str .= "\n". - &mt('Note: this will not take effect if the user already exists'). + $Str .= '
'."\n". + &mt('This will not take effect if the user already exists.'). &Apache::loncommon::help_open_topic('Auth_Options'). "
\n"; } - $Str .= &set_login($defdom,$krbform,$intform,$locform); + $Str .= &set_login($defdom,$krbform,$intform,$locform,$ltiform); + my ($home_server_pick,$numlib) = &Apache::loncommon::home_server_form_item($defdom,'lcserver', 'default','hide'); if ($numlib > 1) { - $Str .= '\n".$date_table."
\n"; - if ($context eq 'domain') { - $Str .= '\n".$date_table."
\n" + .&Apache::lonhtmlcommon::row_closure(); + if ($context eq 'domain') { - $Str .= ''.&mt('Domain Level').'\n".'
'."\n".
- &mt('(only do if you know what you are doing.)')."
\n"; - $Str .= '
'.&mt('Error').': '. + &mt('Invalid datatoken').'
'); + return 'missingdata'; } my @records=&Apache::loncommon::upfile_record_sep(); if($env{'form.noFirstLine'}){ @@ -679,8 +1298,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); @@ -688,12 +1311,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) { @@ -704,11 +1330,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, @@ -725,13 +1357,16 @@ sub print_upload_manager_form { $keyfields=join(',',sort(keys(%sone))); } } - $r->print('\n"); + $r->print('
'. + &list_submit_button(&mt('Update Display')). + "\n".'
'.$warning.''."\n"); + $clearcoursepick = 0; + if (($env{'form.origroletype'} ne '') && + ($env{'form.origroletype'} ne $env{'form.roletype'})) { + $clearcoursepick = 1; + } + if (($env{'form.coursepick'}) && (!$clearcoursepick)) { + $r->print(''.$msg.'
'."\n") if $msg; + } else { + # Print out the available choices + my $usercount; + if ($env{'form.action'} eq 'modifystudent') { + ($usercount) = &show_users_list($r,$context,'view',$permission, + $env{'form.Status'},\%userlist,$keylist,'', + $showcredits); + } else { + ($usercount) = &show_users_list($r,$context,$env{'form.output'}, + $permission,$env{'form.Status'},\%userlist, + $keylist,'',$showcredits,$needauthorquota,$needauthorusage); + } + if (!$usercount) { + $r->print('\n". + if ($actionselect) { + $output .= <<"END"; +
+END + my @allroles; + if ($env{'form.showrole'} eq 'Any') { + my $custom = 1; + if ($context eq 'domain') { + @allroles = &roles_by_context($setting,$custom,$crstype); + } else { + @allroles = &roles_by_context($context,$custom,$crstype); + } + } else { + @allroles = ($env{'form.showrole'}); + } + foreach my $role (@allroles) { + if ($context eq 'domain') { + if ($setting eq 'domain') { + if (&Apache::lonnet::allowed('c'.$role, + $env{'request.role.domain'})) { + $canchange{$role} = 1; + } + } elsif ($setting eq 'author') { + if (&Apache::lonnet::allowed('c'.$role, + $env{'request.role.domain'})) { + $canchange{$role} = 1; + } + } + } elsif ($context eq 'author') { + if (&Apache::lonnet::allowed('c'.$role, + $env{'user.domain'}.'/'.$env{'user.name'})) { + $canchange{$role} = 1; + } + } elsif ($context eq 'course') { + if (&Apache::lonnet::allowed('c'.$role,$env{'request.course.id'})) { + $canchange{$role} = 1; + } elsif ($env{'request.course.sec'} ne '') { + if (&Apache::lonnet::allowed('c'.$role,$env{'request.course.id'}.'/'.$env{'request.course.sec'})) { + $canchangesec{$role} = $env{'request.course.sec'}; + } + } elsif ((($role eq 'co') && ($crstype eq 'Community')) || + (($role eq 'cc') && ($crstype eq 'Course'))) { + if (&is_courseowner($env{'request.course.id'}, + $env{'course.'.$env{'request.course.id'}.'.internal.courseowner'})) { + $canchange{$role} = 1; + } + } + } + } + } + $output .= ''; + } + $output .= "\n".''."\n". &Apache::loncommon::start_data_table(). - &Apache::loncommon::start_data_table_header_row()); + &Apache::loncommon::start_data_table_header_row(); if ($mode eq 'autoenroll') { - $r->print(" -' + .&mt('Problems occurred in writing the CSV file.') + .' '.&mt('This error has been logged.') + .' '.&mt('Please alert your LON-CAPA administrator.') + .'
' + ); $CSVfile = undef; } # # Write headers and data to file - if($statusmode eq 'Expired') { - print $CSVfile '"'.&mt('Users with expired roles').'"'."\n"; } - if($statusmode eq 'Future') { - print $CSVfile '"'.&mt('Users with future roles').'"'."\n"; - } + print $CSVfile '"'.$results_description.'"'."\n"; print $CSVfile '"'.join('","',map { &Apache::loncommon::csv_translate($lt{$_}) - } (@cols)).'"'."\n"; + } (@cols))."\"\n"; } elsif ($mode eq 'excel') { # Create the excel spreadsheet ($excel_workbook,$excel_filename,$format) = &Apache::loncommon::create_workbook($r); return if (! defined($excel_workbook)); $excel_sheet = $excel_workbook->addworksheet('userlist'); - # - my $description; - if ($context eq 'course') { - $description = &mt('Class List for '). - $env{'course.'.$env{'request.course.id'}.'.description'}; - } elsif ($context eq 'construction_space') { - $description = &mt('List of co-authors for construction space for [_1]', - &Apache::loncommon::plainname($env{'user.name'},$env{'user.domain'})); - } else { - $description = &mt('List of users for domain: [_1]',&Apache::lonnet::domain($env{'request.role.domain'},'description')); - } - $excel_sheet->write($row++,0,$description,$format->{'h1'}); + $excel_sheet->write($row++,0,$results_description,$format->{'h2'}); # my @colnames = map {$lt{$_}} (@cols); + $excel_sheet->write($row++,0,\@colnames,$format->{'bold'}); } # Done with header lines in all formats - - # - # Sort the users my %index; my $i; - foreach (@$keylist) { - $index{$_} = $i++; + foreach my $idx (@$keylist) { + $index{$idx} = $i++; + } + my $usercount = 0; + my ($secfilter,$grpfilter); + if ($context eq 'course') { + $secfilter = $env{'form.secfilter'}; + $grpfilter = $env{'form.grpfilter'}; + if ($secfilter eq '') { + $secfilter = 'all'; + } + if ($grpfilter eq '') { + $grpfilter = 'all'; + } + } + my %ltstatus = &Apache::lonlocal::texthash( + Active => 'Active', + Future => 'Future', + Expired => 'Expired', + ); + # If this is for a single course get last course "log-in". + my %crslogins; + if ($context eq 'course') { + %crslogins=&Apache::lonnet::dump('nohist_crslastlogin',$cdom,$cnum); + } + # Get groups, role, permanent e-mail so we can sort on them if + # necessary. + foreach my $user (keys(%{$userlist})) { + if ($user eq '' ) { + delete($userlist->{$user}); + next; + } + if ($context eq 'domain' && $user eq $env{'request.role.domain'}.'-domainconfig:'.$env{'request.role.domain'}) { + delete($userlist->{$user}); + next; + } + my ($uname,$udom,$role,$groups,$email); + if (($statusmode ne 'Any') && + ($userlist->{$user}->[$index{'status'}] ne $statusmode)) { + delete($userlist->{$user}); + next; + } + if ($context eq 'domain') { + if ($env{'form.roletype'} eq 'domain') { + ($role,$uname,$udom) = split(/:/,$user); + if (($uname eq $env{'request.role.domain'}.'-domainconfig') && + ($udom eq $env{'request.role.domain'})) { + delete($userlist->{$user}); + next; + } + } elsif ($env{'form.roletype'} eq 'author') { + ($uname,$udom,$role) = split(/:/,$user,-1); + } elsif (($env{'form.roletype'} eq 'course') || + ($env{'form.roletype'} eq 'community')) { + ($uname,$udom,$role) = split(/:/,$user); + } + } else { + ($uname,$udom,$role) = split(/:/,$user,-1); + if (($context eq 'course') && $role eq '') { + $role = 'st'; + } + } + $userlist->{$user}->[$index{'role'}] = $role; + if (($env{'form.showrole'} ne 'Any') && (!($env{'form.showrole'} eq 'cr' && $role =~ /^cr\//)) && ($role ne $env{'form.showrole'})) { + delete($userlist->{$user}); + next; + } + if ($context eq 'course') { + my @ac_groups; + if (ref($classgroups) eq 'HASH') { + $groups = $classgroups->{$user}; + } + if (ref($groups->{'active'}) eq 'HASH') { + @ac_groups = keys(%{$groups->{'active'}}); + $userlist->{$user}->[$index{'groups'}] = join(', ',@ac_groups); + } + if ($mode ne 'autoenroll') { + my $section = $userlist->{$user}->[$index{'section'}]; + if (($env{'request.course.sec'} ne '') && + ($section ne $env{'request.course.sec'})) { + if ($role eq 'st') { + delete($userlist->{$user}); + next; + } + } + if ($secfilter eq 'none') { + if ($section ne '') { + delete($userlist->{$user}); + next; + } + } elsif ($secfilter ne 'all') { + if ($section ne $secfilter) { + delete($userlist->{$user}); + next; + } + } + if ($grpfilter eq 'none') { + if (@ac_groups > 0) { + delete($userlist->{$user}); + next; + } + } elsif ($grpfilter ne 'all') { + if (!grep(/^\Q$grpfilter\E$/,@ac_groups)) { + delete($userlist->{$user}); + next; + } + } + if ($env{'course.'.$env{'request.course.id'}.'.internal.showphoto'}) { + if ((grep/^photo$/,@cols) && ($role eq 'st')) { + $userlist->{$user}->[$index{'photo'}] = + &Apache::lonnet::retrievestudentphoto($udom,$uname,'jpg'); + $userlist->{$user}->[$index{'thumbnail'}] = + &Apache::lonnet::retrievestudentphoto($udom,$uname, + 'gif','thumbnail'); + } + } + if (($role eq 'st') && ($defaultcredits)) { + if ($userlist->{$user}->[$index{'credits'}] eq '') { + $userlist->{$user}->[$index{'credits'}] = $defaultcredits; + } + } + } + } + my %emails = &Apache::loncommon::getemails($uname,$udom); + if ($emails{'permanentemail'} =~ /\S/) { + $userlist->{$user}->[$index{'email'}] = $emails{'permanentemail'}; + } + if (($context eq 'domain') && ($env{'form.roletype'} eq 'domain') && + ($role eq 'au')) { + my ($disk_quota,$current_disk_usage,$percent); + if (($needauthorusage) || ($needauthorquota)) { + $disk_quota = &Apache::loncommon::get_user_quota($uname,$udom,'author'); + } + if ($needauthorusage) { + $current_disk_usage = + &Apache::lonnet::diskusage($udom,$uname,"$londocroot/priv/$udom/$uname"); + if ($disk_quota == 0) { + $percent = 100.0; + } else { + $percent = $current_disk_usage/(10 * $disk_quota); + } + $userlist->{$user}->[$index{'authorusage'}] = sprintf("%.0f",$percent); + } + if ($needauthorquota) { + $userlist->{$user}->[$index{'authorquota'}] = sprintf("%.2f",$disk_quota); + } + } + $usercount ++; } - $index{'groups'} = scalar(@$keylist); - my $index = $index{$sortby}; - my $second = $index{'username'}; - my $third = $index{'domain'}; - my @Sorted_Students = sort { - lc($classlist->{$a}->[$index]) cmp lc($classlist->{$b}->[$index]) - || - lc($classlist->{$a}->[$second]) cmp lc($classlist->{$b}->[$second]) || - lc($classlist->{$a}->[$third]) cmp lc($classlist->{$b}->[$third]) - } (keys(%$classlist)); - my $studentcount = 0; my $autocount = 0; my $manualcount = 0; - my $unlockcount = 0; my $lockcount = 0; - foreach my $student (@Sorted_Students) { - my $sdata = $classlist->{$student}; - my $groups = $classgroups->{$student}; - my $username = $sdata->[$index{'username'}]; - my $domain = $sdata->[$index{'domain'}]; - my $section = $sdata->[$index{'section'}]; - my $active_groups; - if (ref($groups->{active}) eq 'HASH') { - $active_groups = join(', ',keys(%{$groups->{'active'}})); + my $unlockcount = 0; + if ($usercount) { + $r->print($output); + } else { + if ($mode eq 'autoenroll') { + return ($usercount,$autocount,$manualcount,$lockcount,$unlockcount); + } else { + return; } - my $name = $sdata->[$index{'fullname'}]; - my $id = $sdata->[$index{'id'}]; - my $status = $sdata->[$index{'status'}]; - next if (($statusmode ne 'Any') && ($status ne $statusmode)); - my $start = $sdata->[$index{'start'}]; - my $end = $sdata->[$index{'end'}]; - if (! defined($start) || $start == 0) { - $start = &mt('none'); + } + # + # Sort the users + my $index = $index{$sortby}; + my $second = $index{'username'}; + my $third = $index{'domain'}; + my @sorted_users; + if (($sortby eq 'authorquota') || ($sortby eq 'authorusage')) { + @sorted_users = sort { + $userlist->{$b}->[$index] <=> $userlist->{$a}->[$index] || + lc($userlist->{$a}->[$second]) cmp lc($userlist->{$b}->[$second]) || + lc($userlist->{$a}->[$third]) cmp lc($userlist->{$b}->[$third]) + } (keys(%$userlist)); + } else { + @sorted_users = sort { + lc($userlist->{$a}->[$index]) cmp lc($userlist->{$b}->[$index]) || + lc($userlist->{$a}->[$second]) cmp lc($userlist->{$b}->[$second]) || + lc($userlist->{$a}->[$third]) cmp lc($userlist->{$b}->[$third]) + } (keys(%$userlist)); + } + my $rowcount = 0; + my $disabled; + if ($mode eq 'autoenroll') { + unless ($permission->{'cusr'}) { + $disabled = ' disabled="disabled"'; + } + } + foreach my $user (@sorted_users) { + my %in; + my $sdata = $userlist->{$user}; + $rowcount ++; + foreach my $item (@{$keylist}) { + $in{$item} = $sdata->[$index{$item}]; + } + my $clickers = (&Apache::lonnet::userenvironment($in{'domain'},$in{'username'},'clickers'))[1]; + if ($clickers!~/\w/) { $clickers='-'; } + $in{'clicker'} = $clickers; + my $role = $in{'role'}; + $in{'role'}=&Apache::lonnet::plaintext($sdata->[$index{'role'}],$crstype); + unless ($mode eq 'excel') { + if (! defined($in{'start'}) || $in{'start'} == 0) { + $in{'start'} = &mt('none'); + } else { + $in{'start'} = &Apache::lonlocal::locallocaltime($in{'start'}); + } + if (! defined($in{'end'}) || $in{'end'} == 0) { + $in{'end'} = &mt('none'); + } else { + $in{'end'} = &Apache::lonlocal::locallocaltime($in{'end'}); + } + } + if ($context eq 'course') { + my $lastlogin = $crslogins{$in{'username'}.':'.$in{'domain'}.':'.$in{'section'}.':'.$role}; + if ($lastlogin ne '') { + $in{'lastlogin'} = &Apache::lonlocal::locallocaltime($lastlogin); + } + } + if ($mode eq 'view' || $mode eq 'html' || $mode eq 'autoenroll' || $mode eq 'pickauthor') { + $r->print(&Apache::loncommon::start_data_table_row()); + my $checkval; + if ($mode eq 'autoenroll') { + my $cellentry; + if ($in{'type'} eq 'auto') { + $cellentry = ''.&mt('auto').''.&mt('manual').' | |
';
+ $manualcount ++;
+ if ($in{'lockedtype'}) {
+ $cellentry .= ' |
'.&mt('[_1]Your Excel spreadsheet[_2] is ready for download.', '','')."
\n"); + } elsif ($mode eq 'csv') { + close($CSVfile); + $r->print(''.&mt('[_1]Your CSV file[_2] is ready for download.', '','')."
\n"); + $r->rflush(); + } + if ($mode eq 'autoenroll') { + return ($usercount,$autocount,$manualcount,$lockcount,$unlockcount); + } else { + return ($usercount); + } +} + +sub bulkaction_javascript { + my ($formname,$caller) = @_; + my $docstart = 'document'; + if ($caller eq 'popup') { + $docstart = 'opener.document'; + } + my %lt = &Apache::lonlocal::texthash( + acwi => 'Access will be set to start immediately', + asyo => 'as you did not select an end date in the pop-up window', + accw => 'Access will be set to continue indefinitely', + asyd => 'as you did not select an end date in the pop-up window', + sewi => "Sections will be switched to 'No section'", + ayes => "as you either selected the 'No section' option", + oryo => 'or you did not select a section in the pop-up window', + arol => 'A role with no section will be added', + swbs => 'Sections will be switched to:', + rwba => 'Roles will be added for section(s):', + ); + my $alert = &mt("You must select at least one user by checking a user's 'Select' checkbox"); + my $noaction = &mt("You need to select an action to take for the user(s) you have selected"); + my $singconfirm = &mt(' for a single user?'); + my $multconfirm = &mt(' for multiple users?'); + &js_escape(\$alert); + &js_escape(\$noaction); + &js_escape(\$singconfirm); + &js_escape(\$multconfirm); + my $output = <<"ENDJS"; +function verify_action (field) { + var numchecked = 0; + var singconf = '$singconfirm'; + var multconf = '$multconfirm'; + if ($docstart.$formname.elements[field].length > 0) { + for (i=0; i<$docstart.$formname.elements[field].length; i++) { + if ($docstart.$formname.elements[field][i].checked == true) { + numchecked ++; + } + } + } else { + if ($docstart.$formname.elements[field].checked == true) { + numchecked ++; + } + } + if (numchecked == 0) { + alert("$alert"); + return; + } else { + var message = $docstart.$formname.bulkaction[$docstart.$formname.bulkaction.selectedIndex].text; + var choice = $docstart.$formname.bulkaction[$docstart.$formname.bulkaction.selectedIndex].value; + if (choice == '') { + alert("$noaction"); + return; } else { - $start = &Apache::lonlocal::locallocaltime($start); + if (numchecked == 1) { + message += singconf; + } else { + message += multconf; + } +ENDJS + if ($caller ne 'popup') { + $output .= <<"NEWWIN"; + if (choice == 'chgdates' || choice == 'reenable' || choice == 'activate' || choice == 'chgsec') { + opendatebrowser(document.$formname,'$formname','go'); + return; + + } else { + if (confirm(message)) { + document.$formname.phase.value = 'bulkchange'; + document.$formname.submit(); + return; + } + } +NEWWIN + } else { + $output .= <<"POPUP"; + if (choice == 'chgdates' || choice == 'reenable' || choice == 'activate') { + var datemsg = ''; + if (($docstart.$formname.startdate_month.value == '') && + ($docstart.$formname.startdate_day.value == '') && + ($docstart.$formname.startdate_year.value == '')) { + datemsg = "\\n$lt{'acwi'},\\n$lt{'asyo'}.\\n"; + } + if (($docstart.$formname.enddate_month.value == '') && + ($docstart.$formname.enddate_day.value == '') && + ($docstart.$formname.enddate_year.value == '')) { + datemsg += "\\n$lt{'accw'},\\n$lt{'asyd'}.\\n"; + } + if (datemsg != '') { + message += "\\n"+datemsg; + } + } + if (choice == 'chgsec') { + var rolefilter = $docstart.$formname.showrole.options[$docstart.$formname.showrole.selectedIndex].value; + var retained = $docstart.$formname.retainsec.value; + var secshow = $docstart.$formname.newsecs.value; + if (secshow == '') { + if (rolefilter == 'st' || retained == 0 || retained == "") { + message += "\\n\\n$lt{'sewi'},\\n$lt{'ayes'},\\n$lt{'oryo'}.\\n"; + } else { + message += "\\n\\n$lt{'arol'}\\n$lt{'ayes'},\\n$lt{'oryo'}.\\n"; + } + } else { + if (rolefilter == 'st' || retained == 0 || retained == "") { + message += "\\n\\n$lt{'swbs'} "+secshow+".\\n"; + } else { + message += "\\n\\n$lt{'rwba'} "+secshow+".\\n"; + } + } + } + if (confirm(message)) { + $docstart.$formname.phase.value = 'bulkchange'; + $docstart.$formname.submit(); + window.close(); + } +POPUP + } + $output .= ' } - if (! defined($end) || $end == 0) { - $end = &mt('none'); + } +} +'; + return $output; +} + +sub print_username_link { + my ($mode,$in) = @_; + my $output; + if ($mode eq 'autoenroll') { + $output = $in->{'username'}; + } else { + $output = '{'username'}','$in->{'domain'}'".')">'. + $in->{'username'}.''; + } + return $output; +} + +sub role_type_names { + my %lt = &Apache::lonlocal::texthash ( + 'domain' => 'Domain Roles', + 'author' => 'Co-Author Roles', + 'course' => 'Course Roles', + 'community' => 'Community Roles', + ); + return %lt; +} + +sub select_actions { + my ($context,$setting,$statusmode,$formname) = @_; + my %lt = &Apache::lonlocal::texthash( + revoke => "Revoke user roles", + delete => "Delete user roles", + reenable => "Re-enable expired user roles", + activate => "Make future user roles active now", + chgdates => "Change starting/ending dates", + chgsec => "Change section associated with user roles", + ); + # FIXME Add an option to change credits for student roles. + my ($output,$options,%choices); + # FIXME Disable actions for now for roletype=course in domain context + if ($context eq 'domain' && $setting eq 'course') { + return; + } + if ($context eq 'course') { + if ($env{'form.showrole'} ne 'Any') { + my $showactions; + if (&Apache::lonnet::allowed('c'.$env{'form.showrole'}, + $env{'request.course.id'})) { + $showactions = 1; + } elsif ($env{'request.course.sec'} ne '') { + if (&Apache::lonnet::allowed('c'.$env{'form.showrole'},$env{'request.course.id'}.'/'.$env{'request.course.sec'})) { + $showactions = 1; + } + } + unless ($showactions) { + unless (&is_courseowner($env{'request.course.id'}, + $env{'course.'.$env{'request.course.id'}.'.internal.courseowner'})) { + return; + } + } + } + } + if ($statusmode eq 'Any') { + $options .= ' +'.&mt('Existing sections')."\n".
+ ' '.$sections_select.' | '.
+ &mt('New section').' '."\n". + ''."\n". + ''."\n". + ' |
- + END - -my %lt=&Apache::lonlocal::texthash('usrn' => "username", - 'dom' => "domain", - 'sn' => "student name", - 'sec' => "section", - 'start' => "start date", - 'end' => "end date", - 'groups' => "active groups", - ); + my ($indexhash,$keylist) = &make_keylist_array(); + my $studentcount = 0; + if (ref($classlist) eq 'HASH') { + foreach my $student (keys(%{$classlist})) { + my $sdata = $classlist->{$student}; + my $status = $sdata->[$indexhash->{'status'}]; + my $section = $sdata->[$indexhash->{'section'}]; + if ($status ne 'Active') { + delete($classlist->{$student}); + next; + } + if ($env{'request.course.sec'} ne '') { + if ($section ne $env{'request.course.sec'}) { + delete($classlist->{$student}); + next; + } + } + $studentcount ++; + } + } + if (!$studentcount) { + my $msg = ''; + if ($crstype eq 'Community') { + $msg = &mt('There are no members to drop.'); + } else { + $msg = &mt('There are no students to drop.'); + } + $r->print('
'.$msg.'
'); + return; + } + my ($classgroups) = &Apache::loncoursedata::get_group_memberships( + $classlist,$keylist,$cdom,$cnum); + my %lt=&Apache::lonlocal::texthash('usrn' => "username", + 'dom' => "domain", + 'id' => "ID", + '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()); + $r->print(&Apache::loncommon::start_data_table(). + &Apache::loncommon::start_data_table_header_row()); $r->print(<- - -
++ + +
++ +
END return; } - - # # Print out the initial form to get the file containing a list of users # sub print_first_users_upload_form { my ($r,$context) = @_; my $str; - $str = ''; + $str = ''; $str .= ''; - $str .= ''; - $str .= "\n";
- $str .= ''."\n";
- $str .= '
'."\n" + .&mt('Please upload an UTF8 encoded file to ensure a correct character encoding in your classlist.')."\n" + .'
'."\n"; + } + } + $str .= &Apache::loncommon::upfile_select_html() + .&Apache::lonhtmlcommon::row_closure() + .&Apache::lonhtmlcommon::row_title( + '' + .'' + .'
'; + $r->print($str); return; } # ================================================= Drop/Add from uploaded file sub upfile_drop_add { - my ($r,$context) = @_; - &Apache::loncommon::load_tmp_file($r); + my ($r,$context,$permission,$showcredits) = @_; + my $datatoken = &Apache::loncommon::valid_datatoken($env{'form.datatoken'}); + if ($datatoken ne '') { + &Apache::loncommon::load_tmp_file($r,$datatoken); + } my @userdata=&Apache::loncommon::upfile_record_sep(); if($env{'form.noFirstLine'}){shift(@userdata);} my @keyfields = split(/\,/,$env{'form.keyfields'}); @@ -1609,39 +4281,93 @@ sub upfile_drop_add { } # # Store the field choices away - foreach my $field (qw/username names - fname mname lname gen id sec ipwd email role/) { + my @storefields = qw/username names fname mname lname gen id + sec ipwd email role domain inststatus/; + if ($showcredits) { + push (@storefields,'credits'); + } + my %fieldstype; + foreach my $field (@storefields) { $env{'form.'.$field.'_choice'}=$fields{$field}; + $fieldstype{$field.'_choice'} = 'scalar'; + } + &Apache::loncommon::store_course_settings('enrollment_upload',\%fieldstype); + my ($cid,$crstype,$setting,$crsdom); + if ($context eq 'domain') { + $setting = $env{'form.roleaction'}; + } + if ($env{'request.course.id'} ne '') { + $cid = $env{'request.course.id'}; + $crstype = &Apache::loncommon::course_type(); + $crsdom = $env{'course.'.$env{'request.course.id'}.'.domain'}; + } 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); + $crsdom = $env{'form.dcdomain'}; + } } - &Apache::loncommon::store_course_settings('enrollment_upload', - { 'username_choice' => 'scalar', - 'names_choice' => 'scalar', - 'fname_choice' => 'scalar', - 'mname_choice' => 'scalar', - 'lname_choice' => 'scalar', - 'gen_choice' => 'scalar', - 'id_choice' => 'scalar', - 'sec_choice' => 'scalar', - 'ipwd_choice' => 'scalar', - 'email_choice' => 'scalar', - 'role_choice' => 'scalar' }); - # my ($startdate,$enddate) = &get_dates_from_form(); if ($env{'form.makedatesdefault'}) { - $r->print(&make_dates_default($startdate,$enddate)); + $r->print(&make_dates_default($startdate,$enddate,$context,$crstype)); } # Determine domain and desired host (home server) - my $domain=$env{'request.role.domain'}; + my $defdom=$env{'request.role.domain'}; + my $domain; + if ($env{'form.defaultdomain'} ne '') { + if (($context eq 'course') || ($setting eq 'course')) { + if ($env{'form.defaultdomain'} eq $crsdom) { + $domain = $env{'form.defaultdomain'}; + } else { + if (&Apache::lonnet::will_trust('enroll',$crsdom,$env{'form.defaultdomain'})) { + $domain = $env{'form.defaultdomain'}; + } else { + $r->print(''.&mt('Error').': '. + &mt('Enrollment of users not permitted for specified default domain: [_1].', + &Apache::lonnet::domain($env{'form.defaultdomain'},'description')).''); + return 'untrusted'; + } + } + } elsif ($context eq 'author') { + if ($env{'form.defaultdomain'} eq $defdom) { + $domain = $env{'form.defaultdomain'}; + } else { + if ((&Apache::lonnet::will_trust('othcoau',$defdom,$env{'form.defaultdomain'})) && + (&Apache::lonnet::will_trust('coaurem',$env{'form.defaultdomain'},$defdom))) { + $domain = $env{'form.defaultdomain'}; + } else { + $r->print(''.&mt('Error').': '. + &mt('Addition of users not permitted for specified default domain: [_1].', + &Apache::lonnet::domain($env{'form.defaultdomain'},'description')).''); + return 'untrusted'; + } + } + } elsif (($context eq 'domain') && ($setting eq 'domain')) { + if ($env{'form.defaultdomain'} eq $defdom) { + $domain = $env{'form.defaultdomain'}; + } else { + if (&Apache::lonnet::will_trust('domroles',$defdom,$env{'form.defaultdomain'})) { + $domain = $env{'form.defaultdomain'}; + } else { + $r->print(''.&mt('Error').': '. + &mt('Addition of users not permitted for specified default domain: [_1].', + &Apache::lonnet::domain($env{'form.defaultdomain'},'description')).''); + return 'untrusted'; + } + } + } + } else { + $domain = $defdom; + } my $desiredhost = $env{'form.lcserver'}; if (lc($desiredhost) eq 'default') { $desiredhost = undef; } else { - my %home_servers = &Apache::lonnet::get_servers($domain,'library'); + my %home_servers = &Apache::lonnet::get_servers($defdom,'library'); if (! exists($home_servers{$desiredhost})) { - $r->print(''.&mt('Error'). - &mt('Invalid home server specified').''); - $r->print(&Apache::loncommon::end_page()); - return; + $r->print(''.&mt('Error').': '. + &mt('Invalid home server specified').'
'); + return 'invalidhome'; } } # Determine authentication mechanism @@ -1651,6 +4377,7 @@ sub upfile_drop_add { } my $amode = ''; my $genpwd = ''; + my @genpwdfail; if ($env{'form.login'} eq 'krb') { $amode='krb'; $amode.=$env{'form.krbver'}; @@ -1659,12 +4386,16 @@ sub upfile_drop_add { $amode='internal'; if ((defined($env{'form.intarg'})) && ($env{'form.intarg'})) { $genpwd=$env{'form.intarg'}; + @genpwdfail = + &Apache::loncommon::check_passwd_rules($domain,$genpwd); } } elsif ($env{'form.login'} eq 'loc') { $amode='localauth'; if ((defined($env{'form.locarg'})) && ($env{'form.locarg'})) { $genpwd=$env{'form.locarg'}; } + } elsif ($env{'form.login'} eq 'lti') { + $amode='lti'; } if ($amode =~ /^krb/) { if (! defined($genpwd) || $genpwd eq '') { @@ -1674,29 +4405,76 @@ sub upfile_drop_add { $amode = ''; # This causes the loop below to be skipped } } - my ($cid,$defaultsec,$defaultrole,$setting); + my ($defaultsec,$defaultrole,$defaultcredits,$commoncredits); if ($context eq 'domain') { - $setting = $env{'form.roleaction'}; if ($setting eq 'domain') { $defaultrole = $env{'form.defaultrole'}; } elsif ($setting eq 'course') { $defaultrole = $env{'form.courserole'}; - } - } elsif ($context eq 'construction_space') { + $defaultsec = $env{'form.sections'}; + if ($showcredits) { + $commoncredits = $env{'form.credits'}; + if ($crstype ne 'Community') { + my %coursehash=&Apache::lonnet::coursedescription($cid); + $defaultcredits = $coursehash{'internal.defaultcredits'}; + } + } + } + } elsif ($context eq 'author') { $defaultrole = $env{'form.defaultrole'}; - } - if ($context eq 'domain' && $setting eq 'course') { - if ($env{'form.newsec'} ne '') { - $defaultsec = $env{'form.newsec'}; - } elsif ($env{'form.defaultsec'} ne '') { - $defaultsec = $env{'form.defaultsec'} + } elsif ($context eq 'course') { + $defaultrole = $env{'form.defaultrole'}; + $defaultsec = $env{'form.sections'}; + if ($showcredits) { + $commoncredits = $env{'form.credits'}; + $defaultcredits = $env{'course.'.$cid.'.internal.defaultcredits'}; + } + } + # 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,$crstype); + if (!&Apache::lonnet::allowed('mau',$domain)) { + if ($context eq 'course' || $context eq 'author') { + @poss_roles = &curr_role_permissions($context,'','',$crstype); + my @statuses = ('active','future'); + my ($indexhash,$keylist) = &make_keylist_array(); + my %info; + foreach my $role (@poss_roles) { + %{$modifiable_fields{$role}} = &can_modify_userinfo($context,$domain, + \@userinfo,[$role]); + } + if ($context eq 'course') { + my ($cnum,$cdom) = &get_course_identity(); + my $roster = &Apache::loncoursedata::get_classlist(); + if (ref($roster) eq 'HASH') { + %userlist = %{$roster}; + } + my %advrolehash = &Apache::lonnet::get_my_roles($cnum,$cdom,undef, + \@statuses,\@poss_roles); + &gather_userinfo($context,'view',\%userlist,$indexhash,\%info, + \%advrolehash,$permission); + } elsif ($context eq 'author') { + my %cstr_roles = &Apache::lonnet::get_my_roles(undef,undef,undef, + \@statuses,\@poss_roles); + &gather_userinfo($context,'view',\%userlist,$indexhash,\%info, + \%cstr_roles,$permission); + } } } - if ($env{'request.course.id'} ne '') { - $cid = $env{'request.course.id'}; - } elsif ($env{'form.defaultdomain'} ne '' && $env{'form.defaultcourse'} ne '') { - $cid = $env{'form.defaultdomain'}.'_'. - $env{'form.defaultcourse'}; + if ($datatoken eq '') { + $r->print(''.&mt('Error').': '. + &mt('Invalid datatoken').'
'); + return 'missingdata'; } if ( $domain eq &LONCAPA::clean_domain($domain) && ($amode ne '')) { @@ -1705,11 +4483,13 @@ sub upfile_drop_add { ####################################### if ($context eq 'course') { $r->print('\n"); - } elsif ($context eq 'construction_space') { + } elsif ($context eq 'author') { $r->print('
\n"); } else { $r->print('
\n");
}
+ $r->rflush;
+
my %counts = (
user => 0,
auth => 0,
@@ -1717,16 +4497,64 @@ sub upfile_drop_add {
);
my $flushc=0;
my %student=();
- my %curr_groups;
+ my (%curr_groups,@sections,@cleansec,$defaultwarn,$groupwarn);
my %userchg;
- if ($context eq 'course') {
- # Get information about course groups
- %curr_groups = &Apache::longroup::coursegroups();
+ if ($context eq 'course' || $setting eq 'course') {
+ if ($context eq 'course') {
+ # Get information about course groups
+ %curr_groups = &Apache::longroup::coursegroups();
+ } elsif ($setting eq 'course') {
+ if ($cid) {
+ %curr_groups =
+ &Apache::longroup::coursegroups($env{'form.dcdomain'},
+ $env{'form.dccourse'});
+ }
+ }
+ # determine section number
+ if ($defaultsec =~ /,/) {
+ push(@sections,split(/,/,$defaultsec));
+ } else {
+ push(@sections,$defaultsec);
+ }
+ # remove non alphanumeric values from section
+ foreach my $item (@sections) {
+ $item =~ s/\W//g;
+ if ($item eq "none" || $item eq 'all') {
+ $defaultwarn = &mt('Default section name [_1] could not be used as it is a reserved word.',$item);
+ } elsif ($item ne '' && exists($curr_groups{$item})) {
+ $groupwarn = &mt('Default section name "[_1]" is the name of a course group. Section names and group names must be distinct.',$item);
+ } elsif ($item ne '') {
+ push(@cleansec,$item);
+ }
+ }
+ if ($defaultwarn) {
+ $r->print($defaultwarn.'
');
+ }
+ if ($groupwarn) {
+ $r->print($groupwarn.'
');
+ }
}
+ 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',
+ );
+ my $newuserdom = $env{'request.role.domain'};
+ map { $cancreate{$_} = &can_create_user($newuserdom,$context,$_); } keys(%longtypes);
# Get new users list
- foreach (@userdata) {
- my %entries=&Apache::loncommon::record_sep($_);
+ my (%existinguser,%userinfo,%disallow,%rulematch,%inst_results,%alerts,%checkuname,
+ %showpasswdrules,$haspasswdmap);
+ my $counter = -1;
+ my (%willtrust,%trustchecked);
+ foreach my $line (@userdata) {
+ $counter ++;
+ 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) = ('','','','');
@@ -1747,38 +4575,103 @@ sub upfile_drop_add {
$gen=$entries{$fields{'gen'}};
}
}
+
if ($entries{$fields{'username'}}
ne &LONCAPA::clean_username($entries{$fields{'username'}})) {
- $r->print('
'.
- &mt('[_1]: Unacceptable username for user [_2] [_3] [_4] [_5]',
- $entries{$fields{'username'}},$fname,$mname,$lname,$gen).
- '');
- } else {
- my $username = $entries{$fields{'username'}};
- my $sec;
- if ($context eq 'course' || $setting eq 'course') {
- # determine section number
- if (defined($fields{'sec'})) {
- if (defined($entries{$fields{'sec'}})) {
- $sec=$entries{$fields{'sec'}};
+ my $nowhitespace;
+ if ($entries{$fields{'username'}} =~ /\s/) {
+ $nowhitespace = ' - '.&mt('usernames may not contain spaces.');
+ }
+ $disallow{$counter} =
+ &mt('Unacceptable username [_1] for user [_2] [_3] [_4] [_5]',
+ '"'.$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'}})) {
+ $disallow{$counter} =
+ &mt('Unacceptable domain [_1] for user [_2] [_3] [_4] [_5]',
+ '"'.$entries{$fields{'domain'}}.'"',
+ $fname,$mname,$lname,$gen);
+ next;
+ } elsif ($entries{$fields{'domain'}} ne $domain) {
+ my $possdom = $entries{$fields{'domain'}};
+ if ($context eq 'course' || $setting eq 'course') {
+ unless ($trustchecked{$possdom}) {
+ $willtrust{$possdom} = &Apache::lonnet::will_trust('enroll',$domain,$possdom);
+ $trustchecked{$possdom} = 1;
+ }
+ } elsif ($context eq 'author') {
+ unless ($trustchecked{$possdom}) {
+ $willtrust{$possdom} = &Apache::lonnet::will_trust('othcoau',$domain,$possdom);
+ }
+ if ($willtrust{$possdom}) {
+ $willtrust{$possdom} = &Apache::lonnet::will_trust('coaurem',$possdom,$domain);
}
- } else {
- $sec = $defaultsec;
}
- # remove non alphanumeric values from section
- $sec =~ s/\W//g;
- if ($sec eq "none" || $sec eq 'all') {
- $r->print('
'.
- &mt('[_1]: Unable to enroll: section name "[_2]" for user [_3] [_4] [_5] [_6] is a reserved word.',
- $username,$sec,$fname,$mname,$lname,$gen));
- next;
- } elsif (($sec ne '') && (exists($curr_groups{$sec}))) {
- $r->print('
'.
- &mt('[_1]: Unable to enroll: section name "[_2]" for user [_3] [_4] [_5] [_6] is a course group. Section names and group names must be distinct.',
- $username,$sec,$fname,$mname,$lname,$gen));
+ unless ($willtrust{$possdom}) {
+ $disallow{$counter} =
+ &mt('Unacceptable domain [_1] for user [_2] [_3] [_4] [_5]',
+ '"'.$possdom.'"',
+ $fname,$mname,$lname,$gen);
next;
}
}
+ my $username = $entries{$fields{'username'}};
+ my $userdomain = $entries{$fields{'domain'}};
+ if ($userdomain eq '') {
+ $userdomain = $domain;
+ }
+ if (defined($fields{'sec'})) {
+ if (defined($entries{$fields{'sec'}})) {
+ $entries{$fields{'sec'}} =~ s/\W//g;
+ my $item = $entries{$fields{'sec'}};
+ if ($item eq "none" || $item eq 'all') {
+ $disallow{$counter} =
+ &mt('[_1]: Unable to enroll user [_2] [_3] [_4] [_5] in a section named "[_6]" - this is a reserved word.',
+ ''.$username.'',$fname,$mname,$lname,$gen,$item);
+ next;
+ } elsif (exists($curr_groups{$item})) {
+ $disallow{$counter} =
+ &mt('[_1]: Unable to enroll user [_2] [_3] [_4] [_5] in a section named "[_6]" - this is a course group.',
+ ''.$username.'',$fname,$mname,$lname,$gen,$item).' '.
+ &mt('Section names and group names must be distinct.');
+ next;
+ } else {
+ push(@secs,$item);
+ }
+ }
+ }
+ if ($env{'request.course.sec'} ne '') {
+ @secs = ($env{'request.course.sec'});
+ if (ref($userlist{$username.':'.$userdomain}) eq 'ARRAY') {
+ my $currsec = $userlist{$username.':'.$userdomain}[$secidx];
+ if ($currsec ne $env{'request.course.sec'}) {
+ $disallow{$counter} =
+ &mt('[_1]: Unable to enroll user [_2] [_3] [_4] [_5] in a section named "[_6]".',
+ ''.$username.'',$fname,$mname,$lname,$gen,$secs[0]);
+ if ($currsec eq '') {
+ $disallow{$counter} .=
+ &mt('This user already has an active/future student role in the course, unaffiliated to any section.');
+
+ } else {
+ $disallow{$counter} .=
+ &mt('This user already has an active/future role in section "[_1]" of the course.',$currsec);
+ }
+ $disallow{$counter} .=
+ '
'.
+ &mt('Although your current role has privileges to add students to section "[_1]", you do not have privileges to modify existing enrollments in other sections.',
+ $secs[0]);
+ next;
+ }
+ }
+ } elsif ($context eq 'course' || $setting eq 'course') {
+ if (@secs == 0) {
+ @secs = @cleansec;
+ }
+ }
# determine id number
my $id='';
if (defined($fields{'id'})) {
@@ -1790,29 +4683,76 @@ 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;
+ my $password;
+ my $passwdfromfile;
if (defined($fields{'ipwd'})) {
if ($entries{$fields{'ipwd'}}) {
$password=$entries{$fields{'ipwd'}};
+ $passwdfromfile = 1;
+ if ($env{'form.login'} eq 'int') {
+ my $uhome=&Apache::lonnet::homeserver($username,$userdomain);
+ if (($uhome eq 'no_host') || ($changeauth)) {
+ my @brokepwdrules =
+ &Apache::loncommon::check_passwd_rules($domain,$password);
+ if (@brokepwdrules) {
+ $disallow{$counter} = &mt('[_1]: Password included in file for this user did not meet requirements.',
+ ''.$username.'');
+ map { $showpasswdrules{$_} = 1; } @brokepwdrules;
+ next;
+ }
+ }
+ }
+ }
+ }
+ unless ($passwdfromfile) {
+ if ($env{'form.login'} eq 'int') {
+ if (@genpwdfail) {
+ my $uhome=&Apache::lonnet::homeserver($username,$userdomain);
+ if (($uhome eq 'no_host') || ($changeauth)) {
+ $disallow{$counter} = &mt('[_1]: No specific password in file for this user; default password did not meet requirements',
+ ''.$username.'');
+ unless ($haspasswdmap) {
+ map { $showpasswdrules{$_} = 1; } @genpwdfail;
+ $haspasswdmap = 1;
+ }
+ }
+ next;
+ }
}
+ $password = $genpwd;
}
# determine user role
my $role = '';
if (defined($fields{'role'})) {
if ($entries{$fields{'role'}}) {
- my @poss_roles =
- &curr_role_permissions($context,$setting);
- if (grep(/^\Q$entries{$fields{'role'}}\E/,@poss_roles)) {
- $role=$entries{$fields{'role'}};
- } else {
- my $rolestr = join(', ',@poss_roles);
- $r->print('
'.
- &mt('[_1]: You do not have permission to add the requested role [_2] for the user.',$entries{$fields{'username'}},$entries{$fields{'role'}}).'
'.&mt('Allowable role(s) is/are: [_1].',$rolestr)."\n");
+ $entries{$fields{'role'}} =~ s/(\s+$|^\s+)//g;
+ if ($entries{$fields{'role'}} ne '') {
+ if (grep(/^\Q$entries{$fields{'role'}}\E$/,@permitted_roles)) {
+ $role = $entries{$fields{'role'}};
+ }
+ }
+ if ($role eq '') {
+ my $rolestr = join(', ',@permitted_roles);
+ $disallow{$counter} =
+ &mt('[_1]: You do not have permission to add the requested role [_2] for the user.'
+ ,''.$entries{$fields{'username'}}.''
+ ,$entries{$fields{'role'}})
+ .'
'
+ .&mt('Allowable role(s) is/are: [_1].',$rolestr);
next;
}
}
@@ -1821,84 +4761,357 @@ sub upfile_drop_add {
$role = $defaultrole;
}
# Clean up whitespace
- foreach (\$domain,\$username,\$id,\$fname,\$mname,
- \$lname,\$gen,\$sec,\$role) {
+ foreach (\$id,\$fname,\$mname,\$lname,\$gen,\$inststatus) {
$$_ =~ s/(\s+$|^\s+)//g;
}
- 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);
+ my $credits;
+ if ($showcredits) {
+ if (($role eq 'st') && ($crstype ne 'Community')) {
+ $credits = $entries{$fields{'credits'}};
+ if ($credits ne '') {
+ $credits =~ s/[^\d\.]//g;
+ }
+ if ($credits eq '') {
+ $credits = $commoncredits;
+ }
+ if ($credits eq $defaultcredits) {
+ undef($credits);
+ }
+ }
+ }
+ # check against rules
+ my $checkid = 0;
+ my $newuser = 0;
+ my $uhome=&Apache::lonnet::homeserver($username,$userdomain);
+ if ($uhome eq 'no_host') {
+ if ($userdomain ne $newuserdom) {
+ if ($context eq 'course') {
+ $disallow{$counter} =
+ &mt('[_1]: The domain specified ([_2]) is different to that of the course.',
+ ''.$username.'',$userdomain);
+ } elsif ($context eq 'author') {
+ $disallow{$counter} =
+ &mt('[_1]: The domain specified ([_2]) is different to that of the author.',
+ ''.$username.'',$userdomain);
+ } else {
+ $disallow{$counter} =
+ &mt('[_1]: The domain specified ([_2]) is different to that of your current role.',
+ ''.$username.'',$userdomain);
+ }
+ $disallow{$counter} .=
+ &mt('The user does not already exist, and you may not create a new user in a different domain.');
+ next;
} else {
- ($userresult,$authresult,$roleresult) =
- &modifyuserrole($context,$setting,
- $changeauth,$cid,$domain,$username,
- $id,$amode,$password,$fname,
- $mname,$lname,$gen,$sec,
- $env{'form.forceid'},$desiredhost,
- $email,$role,$enddate,$startdate);
+ unless (($password ne '') || ($env{'form.login'} eq 'loc') || ($env{'form.login'} eq 'lti')) {
+ $disallow{$counter} =
+ &mt('[_1]: This is a new user but no default password was provided, and the authentication type requires one.',
+ ''.$username.'');
+ next;
+ }
}
- $flushc =
- &user_change_result($r,$userresult,$authresult,
- $roleresult,\%counts,$flushc,
- $username,%userchg);
+ $checkid = 1;
+ $newuser = 1;
+ $checkuname{$username.':'.$newuserdom} = { 'newuser' => $newuser, 'id' => $id };
} else {
- if ($context eq 'course') {
- $r->print('
'.
- &mt('[_1]: Unable to enroll. No password specified.',$username)
- );
- } elsif ($context eq 'construction_space') {
- $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)
- );
+ if ($context eq 'course' || $context eq 'author') {
+ if ($userdomain eq $domain ) {
+ if ($role eq '') {
+ my @checkroles;
+ foreach my $role (@poss_roles) {
+ my $endkey;
+ if ($role ne 'st') {
+ $endkey = ':'.$role;
+ }
+ if (exists($userlist{$username.':'.$userdomain.$endkey})) {
+ if (!grep(/^\Q$role\E$/,@checkroles)) {
+ push(@checkroles,$role);
+ }
+ }
+ }
+ if (@checkroles > 0) {
+ %canmodify = &can_modify_userinfo($context,$domain,\@userinfo,\@checkroles);
+ }
+ } elsif (ref($modifiable_fields{$role}) eq 'HASH') {
+ %canmodify = %{$modifiable_fields{$role}};
+ }
+ }
+ my @newinfo = (\$fname,\$mname,\$lname,\$gen,\$email,\$id);
+ for (my $i=0; $i<@newinfo; $i++) {
+ if (${$newinfo[$i]} ne '') {
+ if (!$canmodify{$userinfo[$i]}) {
+ ${$newinfo[$i]} = '';
+ }
+ }
+ }
+ }
+ if ($id) {
+ $existinguser{$userdomain}{$username} = $id;
}
}
+ $userinfo{$counter} = {
+ username => $username,
+ domain => $userdomain,
+ fname => $fname,
+ mname => $mname,
+ lname => $lname,
+ gen => $gen,
+ email => $email,
+ id => $id,
+ password => $password,
+ inststatus => $inststatus,
+ role => $role,
+ sections => \@secs,
+ credits => $credits,
+ newuser => $newuser,
+ checkid => $checkid,
+ };
}
}
} # end of foreach (@userdata)
- # Flush the course logs so reverse user roles immediately updated
- if ($context eq 'course' || ($context eq 'domain' && $setting eq 'course')) {
- &Apache::lonnet::flushcourselogs();
+ if ($counter > -1) {
+ my $total = $counter + 1;
+ my %checkids;
+ if ((keys(%existinguser)) || (keys(%checkuname))) {
+ $r->print(&mt('Please be patient -- checking for institutional data ...'));
+ $r->rflush();
+ if (keys(%existinguser)) {
+ foreach my $dom (keys(%existinguser)) {
+ if (ref($existinguser{$dom}) eq 'HASH') {
+ my %idhash = &Apache::lonnet::idrget($dom,keys(%{$existinguser{$dom}}));
+ foreach my $username (keys(%{$existinguser{$dom}})) {
+ if ($idhash{$username} ne $existinguser{$dom}{$username}) {
+ $checkids{$username.':'.$dom} = {
+ 'id' => $existinguser{$dom}{$username},
+ };
+ }
+ }
+ if (keys(%checkids)) {
+ &Apache::loncommon::user_rule_check(\%checkids,{ 'id' => 1 },
+ \%alerts,\%rulematch,
+ \%inst_results,\%curr_rules,
+ \%got_rules);
+ }
+ }
+ }
+ }
+ if (keys(%checkuname)) {
+ &Apache::loncommon::user_rule_check(\%checkuname,{ 'username' => 1, 'id' => 1, },
+ \%alerts,\%rulematch,\%inst_results,
+ \%curr_rules,\%got_rules);
+ }
+ $r->print(' '.&mt('done').'
');
+ $r->rflush();
+ }
+ my %prog_state = &Apache::lonhtmlcommon::Create_PrgWin($r,$total);
+ $r->print('
\n".&mt('Processed [_1] user(s).',$counts{'user'}). + # Flush the course logs so reverse user roles immediately updated + $r->register_cleanup(\&Apache::lonnet::flushcourselogs); + $r->print("
\n\n".&mt('Processed [quant,_1,user].',$counts{'user'}). "
\n"); if ($counts{'role'} > 0) { $r->print("\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". &mt('Authentication changed for [_1] existing users.', $counts{'auth'})."
\n"); } - $r->print(''); + $r->print(&print_namespacing_alerts($domain,\%alerts,\%curr_rules)); + $r->print(&passwdrule_alerts($domain,\%showpasswdrules)); ##################################### - # Drop students # + # Display list of students to drop # ##################################### if ($env{'form.fullup'} eq 'yes') { - $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'}}. @@ -1906,21 +5119,95 @@ 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 { + my ($domain,$alerts,$curr_rules) = @_; + my $output; + if (ref($alerts) eq 'HASH') { + if (keys(%{$alerts}) > 0) { + if (ref($alerts->{'username'}) eq 'HASH') { + foreach my $dom (sort(keys(%{$alerts->{'username'}}))) { + my $count; + if (ref($alerts->{'username'}{$dom}) eq 'HASH') { + $count = keys(%{$alerts->{'username'}{$dom}}); + } + my $domdesc = &Apache::lonnet::domain($domain,'description'); + if (ref($curr_rules->{$dom}) eq 'HASH') { + $output .= &Apache::loncommon::instrule_disallow_msg( + 'username',$domdesc,$count,'upload'); + } + $output .= &Apache::loncommon::user_rule_formats($dom, + $domdesc,$curr_rules->{$dom}{'username'}, + 'username'); + } + } + if (ref($alerts->{'id'}) eq 'HASH') { + foreach my $dom (sort(keys(%{$alerts->{'id'}}))) { + my $count; + if (ref($alerts->{'id'}{$dom}) eq 'HASH') { + $count = keys(%{$alerts->{'id'}{$dom}}); + } + my $domdesc = &Apache::lonnet::domain($domain,'description'); + if (ref($curr_rules->{$dom}) eq 'HASH') { + $output .= &Apache::loncommon::instrule_disallow_msg( + 'id',$domdesc,$count,'upload'); + } + $output .= &Apache::loncommon::user_rule_formats($dom, + $domdesc,$curr_rules->{$dom}{'id'},'id'); + } + } + } + } +} + +sub 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:').''.&mt('Dropped [_1] user(s).',$count).'
'); - $r->print(''.&mt('Re-enrollment will re-activate data.')) if ($count);
+ return $dates;
}
-sub section_check_js {
- my $groupslist;
- my %curr_groups = &Apache::longroup::coursegroups();
- if (%curr_groups) {
- $groupslist = join('","',sort(keys(%curr_groups)));
+sub classlist_drop {
+ my ($scope,$uname,$udom,$now) = @_;
+ my ($cdom,$cnum) = ($scope=~m{^/($match_domain)/($match_courseid)});
+ if (&Apache::lonnet::is_course($cdom,$cnum)) {
+ if (!&active_student_roles($cnum,$cdom,$uname,$udom)) {
+ my %user;
+ my $result = &update_classlist($cdom,$cnum,$udom,$uname,\%user,$now);
+ return &mt('Drop from classlist: [_1]',
+ ''.$result.'').'
';
+ }
}
+}
+
+sub active_student_roles {
+ my ($cnum,$cdom,$uname,$udom) = @_;
+ my %roles =
+ &Apache::lonnet::get_my_roles($uname,$udom,'userroles',
+ ['future','active'],['st']);
+ return exists($roles{"$cnum:$cdom:st"});
+}
+
+sub section_check_js {
+ my $groupslist= &get_groupslist();
+ my %js_lt = &Apache::lonlocal::texthash(
+ mayn => 'may not be used as the name for a section, as it is a reserved word.',
+ plch => 'Please choose a different section name.',
+ mnot => 'may not be used as a section name, as it is the name of a course group.',
+ secn => 'Section names and group names must be distinct. Please choose a different section name.',
+ );
+ &js_escape(\%js_lt);
return <<"END";
function validate(caller) {
- var groups = new Array("$groupslist");
+ var groups = new Array($groupslist);
var secname = caller.value;
if ((secname == 'all') || (secname == 'none')) {
- alert("'"+secname+"' may not be used as the name for a section, as it is a reserved word.\\nPlease choose a different section name.");
+ alert("'"+secname+"' $js_lt{'mayn'}\\n$js_lt{'plch'}");
return 'error';
}
if (secname != '') {
for (var k=0; k'.$authformlti.' '.
+ &Apache::loncommon::end_data_table_row()."\n";
+ }
$response .= &Apache::loncommon::end_data_table();
}
return $response;
}
+sub course_sections {
+ my ($sections_count,$role,$current_sec,$disabled) = @_;
+ my $output = '';
+ my @sections = (sort {$a <=> $b} keys(%{$sections_count}));
+ my $numsec = scalar(@sections);
+ my $is_selected = ' selected="selected"';
+ if ($numsec <= 1) {
+ $output = '
+END
+}
+
+sub custom_coursetype_switch {
+ my ($crstype,$prefix) = @_;
+ my ($checkedcourse,$checkedcommunity);
+ if ($crstype eq 'Community') {
+ $checkedcommunity = ' checked="checked"';
+ } else {
+ $checkedcourse = ' checked="checked"';
+ }
+ my %lt = &Apache::lonlocal::texthash(
+ cont => 'Context',
+ cour => 'Course',
+ comm => 'Community',
+ );
+ return <<"END";
+'.$lt{'prv'}.' '.$lt{'crl'}.' '.$lt{'dml'}.
+ ' '.$lt{'ssl'}.' '.
+ &Apache::loncommon::end_data_table_header_row();
+ foreach my $priv (sort(keys(%{$full}))) {
+ my $privtext = &Apache::lonnet::plaintext($priv,$crstype);
+ $output .= &Apache::loncommon::start_data_table_row().
+ ''.$privtext.' ';
+ foreach my $type ('course','domain','system') {
+ if (($type eq 'system') && ($priv eq 'bre') && ($crstype eq 'Community')) {
+ $output .= ' ';
+ } else {
+ $output .= ''.
+ ($levels->{$type}{$priv}?'{$type}{$priv}?' checked="checked"':'').' />':' ').
+ ' ';
+ }
+ }
+ $output .= &Apache::loncommon::end_data_table_row();
+ }
+ $output .= &Apache::loncommon::end_data_table();
+ return $output;
+}
+
+sub custom_role_privs {
+ my ($privs,$full,$levels,$levelscurrent)= @_;
+ return unless ((ref($privs) eq 'HASH') && (ref($full) eq 'HASH') &&
+ (ref($levels) eq 'HASH') && (ref($levelscurrent) eq 'HASH'));
+ my %cr = (
+ course => 'cr:c',
+ domain => 'cr:d',
+ system => 'cr:s',
+ );
+ foreach my $type ('course','domain','system') {
+ foreach my $item (split(/\:/,$Apache::lonnet::pr{$cr{$type}})) {
+ my ($priv,$restrict)=split(/\&/,$item);
+ if (!$restrict) { $restrict='F'; }
+ $levels->{$type}->{$priv}=$restrict;
+ if ($privs->{$type}=~/\:$priv/) {
+ $levelscurrent->{$type}->{$priv}=1;
+ }
+ $full->{$priv}=1;
+ }
+ }
+ return;
+}
+
+sub custom_template_roles {
+ my ($context,$crstype) = @_;
+ my @template_roles = ("in","ta","ep");
+ if (($context eq 'domain') || ($context eq 'domprefs')) {
+ push(@template_roles,"ad");
+ }
+ push(@template_roles,"st");
+ if ($context eq 'domain') {
+ unshift(@template_roles,('co','cc'));
+ } else {
+ if ($crstype eq 'Community') {
+ unshift(@template_roles,'co');
+ } else {
+ unshift(@template_roles,'cc');
+ }
+ }
+ return @template_roles;
+}
+
+sub custom_roledefs_js {
+ my ($context,$crstype,$formname,$full,$templaterolesref,$jsback) = @_;
+ my $button_code = "\n";
+ my $head_script = "\n";
+ my (%roletitlestr,$rolenamestr);
+ my %role_titles = (
+ Course => [],
+ Community => [],
+ );
+ $head_script .= ''."\n";
+ return $head_script;
+}
+
+# --------------------------------------------------------
+sub make_script_template {
+ my ($role,$crstype,$formname) = @_;
+ my $return_script = 'function set_'.$role.'(prefix) {'."\n";
+ my (%full_by_level,%role_priv);
+ foreach my $level ('c','d','s') {
+ foreach my $item (split(/\:/,$Apache::lonnet::pr{'cr:'.$level})) {
+ next if (($level eq 's') && ($crstype eq 'Community') && ($item eq 'bre&S'));
+ my ($priv,$restrict)=split(/\&/,$item);
+ $full_by_level{$level}{$priv}=1;
+ }
+ $role_priv{$level} = {};
+ my @temp = split(/:/,$Apache::lonnet::pr{$role.':'.$level});
+ foreach my $priv (@temp) {
+ my ($priv_item, $dummy) = split(/\&/,$priv);
+ $role_priv{$level}{$priv_item} = 1;
+ }
+ }
+ my %to_check = (
+ c => ['c','d','s'],
+ d => ['d','s'],
+ s => ['s'],
+ );
+ foreach my $level ('c','d','s') {
+ if (ref($full_by_level{$level}) eq 'HASH') {
+ foreach my $priv (keys(%{$full_by_level{$level}})) {
+ my $value = 'false';
+ if (ref($to_check{$level}) eq 'ARRAY') {
+ foreach my $lett (@{$to_check{$level}}) {
+ if (exists($role_priv{$lett}{$priv})) {
+ $value = 'true';
+ last;
+ }
+ }
+ $return_script .= "document.$formname.elements[prefix+'".$priv."_".$level."'].checked = $value;\n";
+ }
+ }
+ }
+ }
+ $return_script .= '}'."\n";
+ return ($return_script);
+}
+# ----------------------------------------------------------
+sub make_button_code {
+ my ($role,$crstype,$display,$prefix) = @_;
+ my $label = &Apache::lonnet::plaintext($role,$crstype);
+ my $button_code = '';
+ return ($button_code);
+}
+
+sub custom_role_update {
+ my ($rolename,$prefix) = @_;
+# ------------------------------------------------------- What can be assigned?
+ my %privs = (
+ c => '',
+ d => '',
+ s => '',
+ );
+ foreach my $level (keys(%privs)) {
+ foreach my $item (split(/\:/,$Apache::lonnet::pr{'cr:'.$level})) {
+ my ($priv,$restrict)=split(/\&/,$item);
+ if (!$restrict) { $restrict=''; }
+ if ($env{'form.'.$prefix.$priv.'_'.$level}) {
+ $privs{$level} .=':'.$item;
+ }
+ }
+ }
+ return %privs;
+}
+
+sub adhoc_status_types {
+ my ($cdom,$context,$role,$selectedref,$othertitle,$usertypes,$types,$disabled) = @_;
+ my $output = &Apache::loncommon::start_data_table();
+ my $numinrow = 3;
+ my $rem;
+ if (ref($types) eq 'ARRAY') {
+ for (my $i=0; $i<@{$types}; $i++) {
+ if (defined($usertypes->{$types->[$i]})) {
+ my $rem = $i%($numinrow);
+ if ($rem == 0) {
+ if ($i > 0) {
+ $output .= &Apache::loncommon::end_data_table_row();
+ }
+ $output .= &Apache::loncommon::start_data_table_row();
+ }
+ my $check;
+ if (ref($selectedref) eq 'ARRAY') {
+ if (grep(/^\Q$types->[$i]\E$/,@{$selectedref})) {
+ $check = ' checked="checked"';
+ }
+ }
+ $output .= ''.
+ ' ';
+ }
+ }
+ $rem = @{$types}%($numinrow);
+ }
+ my $colsleft = $numinrow - $rem;
+ if (($rem == 0) && (@{$types} > 0)) {
+ $output .= &Apache::loncommon::start_data_table_row();
+ }
+ if ($colsleft > 1) {
+ $output .= '';
+ } else {
+ $output .= ' ';
+ }
+ my $defcheck;
+ if (ref($selectedref) eq 'ARRAY') {
+ if (grep(/^default$/,@{$selectedref})) {
+ $defcheck = ' checked="checked"';
+ }
+ }
+ $output .= ' '.
+ &Apache::loncommon::end_data_table_row().
+ &Apache::loncommon::end_data_table();
+ return $output;
+}
+
+sub adhoc_staff {
+ my ($access,$context,$role,$selectedref,$adhocref,$disabled) = @_;
+ my $output;
+ if (ref($adhocref) eq 'HASH') {
+ my %by_fullname;
+ my $numinrow = 4;
+ my $rem;
+ my @personnel = keys(%{$adhocref});
+ if (@personnel) {
+ foreach my $person (@personnel) {
+ my ($uname,$udom) = split(/:/,$person);
+ my $fullname = &Apache::loncommon::plainname($uname,$udom,'lastname');
+ $by_fullname{$fullname} = $person;
+ }
+ my @sorted = sort(keys(%by_fullname));
+ my $count = scalar(@sorted);
+ $output = &Apache::loncommon::start_data_table();
+ for (my $i=0; $i<$count; $i++) {
+ my $rem = $i%($numinrow);
+ if ($rem == 0) {
+ if ($i > 0) {
+ $output .= &Apache::loncommon::end_data_table_row();
+ }
+ $output .= &Apache::loncommon::start_data_table_row();
+ }
+ my $check;
+ my $user = $by_fullname{$sorted[$i]};
+ if (ref($selectedref) eq 'ARRAY') {
+ if (grep(/^\Q$user\E$/,@{$selectedref})) {
+ $check = ' checked="checked"';
+ }
+ }
+ if ($i == $count-1) {
+ my $colsleft = $numinrow - $rem;
+ if ($colsleft > 1) {
+ $output .= '';
+ } else {
+ $output .= ' ';
+ }
+ } else {
+ $output .= ' ';
+ }
+ $output .= ' ';
+ if ($i == $count-1) {
+ $output .= &Apache::loncommon::end_data_table_row();
+ }
+ }
+ $output .= &Apache::loncommon::end_data_table();
+ }
+ }
+ return $output;
+}
+
+
1;