--- loncom/interface/lonuserutils.pm 2008/05/30 17:18:21 1.57
+++ loncom/interface/lonuserutils.pm 2009/10/30 03:57:35 1.101
@@ -1,7 +1,7 @@
# The LearningOnline Network with CAPA
# Utility functions for managing LON-CAPA user accounts
#
-# $Id: lonuserutils.pm,v 1.57 2008/05/30 17:18:21 raeburn Exp $
+# $Id: lonuserutils.pm,v 1.101 2009/10/30 03:57:35 raeburn Exp $
#
# Copyright Michigan State University Board of Trustees
#
@@ -86,7 +86,7 @@ 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;
@@ -124,7 +124,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;
@@ -169,7 +169,7 @@ sub propagate_id_change {
}
sub update_classlist {
- my ($cdom,$cnum,$udom,$uname,$user) = @_;
+ my ($cdom,$cnum,$udom,$uname,$user,$newend) = @_;
my ($uid,$classlistentry);
my $fullname =
&Apache::lonnet::format_name($user->{'firstname'},$user->{'middlename'},
@@ -180,15 +180,37 @@ sub update_classlist {
my @classinfo = split(/:/,$classhash{$uname.':'.$udom});
my $ididx=&Apache::loncoursedata::CL_ID() - 2;
my $nameidx=&Apache::loncoursedata::CL_FULLNAME() - 2;
+ my $endidx = &Apache::loncoursedata::CL_END() - 2;
+ my $startidx = &Apache::loncoursedata::CL_START() - 2;
for (my $i=0; $i<@classinfo; $i++) {
- if ($i == $ididx) {
+ if ($i == $endidx) {
+ if ($newend ne '') {
+ $classlistentry .= $newend.':';
+ } else {
+ $classlistentry .= $classinfo[$i].':';
+ }
+ } elsif ($i == $startidx) {
+ if ($newend ne '') {
+ if ($classinfo[$i] > $newend) {
+ $classlistentry .= $newend.':';
+ } else {
+ $classlistentry .= $classinfo[$i].':';
+ }
+ } else {
+ $classlistentry .= $classinfo[$i].':';
+ }
+ } elsif ($i == $ididx) {
if (defined($user->{'id'})) {
$classlistentry .= $user->{'id'}.':';
} else {
$classlistentry .= $classinfo[$i].':';
}
} elsif ($i == $nameidx) {
- $classlistentry .= $fullname.':';
+ if (defined($user->{'lastname'})) {
+ $classlistentry .= $fullname.':';
+ } else {
+ $classlistentry .= $classinfo[$i].':';
+ }
} else {
$classlistentry .= $classinfo[$i].':';
}
@@ -213,7 +235,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
@@ -239,7 +261,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;
@@ -256,7 +278,8 @@ sub domain_roles_select {
}
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;
}
@@ -306,9 +329,11 @@ sub print_upload_manager_header {
&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");
+ 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");
@@ -319,14 +344,17 @@ 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(' ');
- $r->print('');
+ $r->print('
');
+ $r->print(' ');
$r->print("
\n".
'');
+ '// '."\n".
+ '');
}
###############################################################
@@ -379,17 +407,20 @@ sub javascript_validations {
krb => 'You need to specify the Kerberos domain.',
ipass => 'You need to specify the initial password.',
name => 'The optional name field was not specified.',
- snum => 'The optional ID number field was not specified.',
+ snum => 'The optional student/employee ID field was not specified.',
section => 'The optional section field was not specified.',
- email => 'The optional email address field was not specified.',
+ email => 'The optional e-mail address field was not specified.',
role => 'The optional role field was not specified.',
domain => 'The optional domain field was not specified.',
continue => 'Continue adding users?',
);
+ if (($mode eq 'upload') && ($context eq 'domain')) {
+ $alert{'inststatus'} = &mt('The optional affiliation field was not specified');
+ }
my $function_name = <<"END";
$setsections_js
-function verify_message (vf,founduname,foundpwd,foundname,foundid,foundsec,foundemail,foundrole,founddomain) {
+function verify_message (vf,founduname,foundpwd,foundname,foundid,foundsec,foundemail,foundrole,founddomain,foundinststatus) {
END
my ($authnum,%can_assign) = &Apache::loncommon::get_assignable_auth($domain);
my $auth_checks;
@@ -516,6 +547,20 @@ END
}
message+='$alert{'domain'}';
}
+END
+ if (($mode eq 'upload') && ($context eq 'domain')) {
+ $optional_checks .= (<';
$Str .= &hidden_input('nfields',$i);
$Str .= &hidden_input('keyfields',$keyfields);
- $Str .= "
'."\n".
- &mt('Pick the action to take on roles for these users:').' ';
- }
- if ($context eq 'author') {
- $Str .= '
'.&mt('Default role')."
\n".
- &mt('Choose the role to assign to users without a value specified in the uploaded file');
+ $Str .= &Apache::lonhtmlcommon::row_title(
+ &mt('Settings for assigning roles'))
+ .&mt('Pick the action to take on roles for these users:').' '
+ .''
+ .' '
+ .' '
+ .'';
+ } elsif ($context eq 'author') {
+ $Str .= &Apache::lonhtmlcommon::row_title(
+ &mt('Default role'))
+ .&mt('Choose the role to assign to users without a value specified in the uploaded file.')
} elsif ($context eq 'course') {
- $Str .= '
'.&mt('Default role and section')."
\n".
- &mt('Choose the role and/or section(s) to assign to users without values specified in the uploaded file');
- } else {
- $Str .= '
'.&mt('Default role and/or section(s)')." \n".
- &mt('Role and/or section(s) for users without values specified in the uploaded file.');
+ $Str .= &Apache::lonhtmlcommon::row_title(
+ &mt('Default role and section'))
+ .&mt('Choose the role and/or section(s) to assign to users without values specified in the uploaded file.');
+ } else {
+ $Str .= &Apache::lonhtmlcommon::row_title(
+ &mt('Default role and/or section(s)'))
+ .&mt('Role and/or section(s) for users without values specified in the uploaded file.');
}
- $Str .= ' ';
if (($context eq 'domain') || ($context eq 'author')) {
+ $Str .= ' ';
my ($options,$cb_script,$coursepick) = &default_role_selector($context,1);
if ($context eq 'domain') {
- $Str .= ''.&mt('Domain Level').' '.$options.'
'
+ .$cb_script.$coursepick
+ .&Apache::lonhtmlcommon::row_closure();
} elsif ($context eq 'author') {
- $Str .= $options;
+ $Str .= $options
+ .&Apache::lonhtmlcommon::row_closure(1); # last row in pick_box
}
} else {
my ($cnum,$cdom) = &get_course_identity();
my $rowtitle = &mt('section');
my $secbox = §ion_picker($cdom,$cnum,'Any',$rowtitle,
- $permission,$context,'upload');
- $Str .= $secbox."
".&mt('Full Update')."
\n".
- '
'.&mt('Students selected from this list can be dropped.').'
'."\n";
+ $permission,$context,'upload',$crstype);
+ $Str .= $secbox
+ .&Apache::lonhtmlcommon::row_closure();
+ my %lt;
+ if ($crstype eq 'Community') {
+ %lt = &Apache::lonlocal::texthash (
+ disp => 'Display members with current/future access who are not in the uploaded file',
+ stus => 'Members selected from this list can be dropped.'
+ );
+ } else {
+ %lt = &Apache::lonlocal::texthash (
+ disp => 'Display students with current/future access who are not in the uploaded file',
+ stus => 'Students selected from this list can be dropped.'
+ );
+ }
+ $Str .= &Apache::lonhtmlcommon::row_title(&mt('Full Update'))
+ .' '
+ .$lt{'stus'}
+ .&Apache::lonhtmlcommon::row_closure();
}
if ($context eq 'course' || $context eq 'domain') {
$Str .= &forceid_change($context);
}
- $Str .= '
';
+
+ # Footer
+ $Str .= '';
$r->print($Str);
return;
}
@@ -790,25 +910,25 @@ sub print_upload_manager_footer {
sub forceid_change {
my ($context) = @_;
my $output =
- "
".&mt('ID/Student Number')."
\n".
- "
\n".' '."\n".
- &mt('(only do if you know what you are doing.)')."\n";
+ &Apache::lonhtmlcommon::row_title(&mt('Student/Employee ID'))
+ .' '."\n"
+ .&mt('(only do if you know what you are doing.)')."\n";
if ($context eq 'domain') {
$output .= ' '."\n";
}
- $output .= '
';
+ $output .= &Apache::lonhtmlcommon::row_closure(1); # last row in pick_box
return $output;
}
###############################################################
###############################################################
sub print_upload_manager_form {
- my ($r,$context,$permission) = @_;
+ my ($r,$context,$permission,$crstype) = @_;
my $firstLine;
my $datatoken;
if (!$env{'form.datatoken'}) {
@@ -839,6 +959,7 @@ sub print_upload_manager_form {
'email_choice' => 'scalar',
'role_choice' => 'scalar',
'domain_choice' => 'scalar',
+ 'inststatus_choice' => 'scalar',
};
my $defdom = $env{'request.role.domain'};
if ($context eq 'course') {
@@ -865,12 +986,13 @@ 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'}],
- ['domain',&mt('Domain'), $env{'form.domain_choice'}]);
+ ['domain',&mt('Domain'), $env{'form.domain_choice'}],
+ ['inststatus',&mt('Affiliation'), $env{'form.inststatus_choice'}]);
if ($env{'form.upfile_associate'} eq 'reverse') {
&Apache::loncommon::csv_print_samples($r,\@records);
$i=&Apache::loncommon::csv_print_select_table($r,\@records,
@@ -889,7 +1011,7 @@ sub print_upload_manager_form {
}
$r->print('');
&print_upload_manager_footer($r,$i,$keyfields,$defdom,$today,$halfyear,
- $context,$permission);
+ $context,$permission,$crstype);
}
sub setup_date_selectors {
@@ -963,7 +1085,7 @@ sub get_dates_from_form {
}
sub date_setting_table {
- my ($starttime,$endtime,$mode,$bulkaction,$formname,$permission) = @_;
+ my ($starttime,$endtime,$mode,$bulkaction,$formname,$permission,$crstype) = @_;
my $nolink;
if ($bulkaction) {
$nolink = 1;
@@ -980,15 +1102,19 @@ sub date_setting_table {
($env{'form.action'} eq 'upload')) {
if ($env{'request.course.sec'} eq '') {
$dateDefault = ''.
- '';
+ '';
}
}
}
my $perpetual = '';
if ($mode eq 'create_enrolldates') {
@@ -1011,7 +1137,7 @@ sub date_setting_table {
}
sub make_dates_default {
- my ($startdate,$enddate,$context) = @_;
+ my ($startdate,$enddate,$context,$crstype) = @_;
my $result = '';
if ($context eq 'course') {
my ($cnum,$cdom) = &get_course_identity();
@@ -1019,22 +1145,30 @@ sub make_dates_default {
{'default_enrollment_start_date'=>$startdate,
'default_enrollment_end_date' =>$enddate},$cdom,$cnum);
if ($put_result eq 'ok') {
- $result .= &mt('Set default start and end access dates for course.').
- ' '."\n";
+ if ($crstype eq 'Community') {
+ $result .= &mt('Set default start and end access dates for community.');
+ } else {
+ $result .= &mt('Set default start and end access dates for course.');
+ }
+ $result .= ' '."\n";
#
# Refresh the course environment
&Apache::lonnet::coursedescription($env{'request.course.id'},
{'freshen_cache' => 1});
} else {
- $result .= &mt('Unable to set default access dates for course.').":".$put_result.
- ' ';
+ if ($crstype eq 'Community') {
+ $result .= &mt('Unable to set default access dates for community');
+ } else {
+ $result .= &mt('Unable to set default access dates for course');
+ }
+ $result .= ':'.$put_result.' ';
}
}
return $result;
}
sub default_role_selector {
- my ($context,$checkpriv) = @_;
+ my ($context,$checkpriv,$crstype) = @_;
my %customroles;
my ($options,$coursepick,$cb_jscript);
if ($context ne 'author') {
@@ -1050,7 +1184,7 @@ sub default_role_selector {
$options = '