--- loncom/interface/lonuserutils.pm 2008/12/12 16:53:37 1.73.2.1
+++ loncom/interface/lonuserutils.pm 2009/08/14 10:37:22 1.97
@@ -1,7 +1,7 @@
# The LearningOnline Network with CAPA
# Utility functions for managing LON-CAPA user accounts
#
-# $Id: lonuserutils.pm,v 1.73.2.1 2008/12/12 16:53:37 raeburn Exp $
+# $Id: lonuserutils.pm,v 1.97 2009/08/14 10:37:22 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;
@@ -328,9 +328,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('manual').' | |||
|
'. -'
'."\n". +''."\n". ''; return $output; } @@ -3215,10 +3324,12 @@ sub show_drop_list {- + END my ($indexhash,$keylist) = &make_keylist_array(); my $studentcount = 0; @@ -3336,7 +3447,7 @@ END # $r->print(&Apache::loncommon::start_data_table_row()); $r->print(<<"END"); -
- - -
+ ++ + +
++ +
END return; } @@ -3369,24 +3484,42 @@ END sub print_first_users_upload_form { my ($r,$context) = @_; my $str; - $str = ''; + $str = ''; $str .= ''; $str .= ''; - $str .= "';
- $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 .= "
\n";
- $str .= '
'
+ .&Apache::loncommon::help_open_topic("Course_Create_Class_List",
+ &mt("How do I create a users list from a spreadsheet"))
+ ."
\n"
+ .&Apache::loncommon::help_open_topic("Course_Convert_To_CSV",
+ &mt("How do I create a CSV file from a spreadsheet"))
+ ."
'."\n" + .&mt('Please upload an UTF8 encoded file to ensure a correct character encoding in your classlist.')."\n" + .'
'."\n" + .&Apache::loncommon::upfile_select_html() + .&Apache::lonhtmlcommon::row_closure() + .&Apache::lonhtmlcommon::row_title( + '' + .'' + .'
'; + $str .= &Apache::loncommon::end_page(); + $r->print($str); return; } @@ -3430,7 +3563,8 @@ sub upfile_drop_add { 'ipwd_choice' => 'scalar', 'email_choice' => 'scalar', 'role_choice' => 'scalar', - 'domain_choice' => 'scalar'}); + 'domain_choice' => 'scalar', + 'inststatus_choice' => 'scalar'}); # my ($startdate,$enddate) = &get_dates_from_form(); if ($env{'form.makedatesdefault'}) { @@ -3513,6 +3647,7 @@ sub upfile_drop_add { 'permanentemail','id'); my %canmodify; if (&Apache::lonnet::allowed('mau',$domain)) { + push(@userinfo,'inststatus'); foreach my $field (@userinfo) { $canmodify{$field} = 1; } @@ -3561,6 +3696,8 @@ sub upfile_drop_add { } else { $r->print('\n");
}
+ $r->rflush;
+
my %counts = (
user => 0,
auth => 0,
@@ -3636,8 +3773,8 @@ sub upfile_drop_add {
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));
+ &mt('[_1]: Unacceptable username for user [_2] [_3] [_4] [_5]',
+ ''.$entries{$fields{'username'}}.'',$fname,$mname,$lname,$gen));
next;
} else {
if ($entries{$fields{'domain'}}
@@ -3656,10 +3793,10 @@ sub upfile_drop_add {
$entries{$fields{'sec'}} =~ s/\W//g;
my $item = $entries{$fields{'sec'}};
if ($item eq "none" || $item eq 'all') {
- $r->print('
'.&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));
+ $r->print('
'.&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})) {
- $r->print('
'.&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.'));
+ $r->print('
'.&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);
@@ -3671,7 +3808,7 @@ sub upfile_drop_add {
if (ref($userlist{$username.':'.$userdomain}) eq 'ARRAY') {
my $currsec = $userlist{$username.':'.$userdomain}[$secidx];
if ($currsec ne $env{'request.course.sec'}) {
- $r->print('
'.&mt('[_1]: Unable to enroll user [_2] [_3] [_4] [_5] in a section named "[_6]".',$username,$fname,$mname,$lname,$gen,$secs[0]).'
');
+ $r->print('
'.&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 '') {
$r->print(&mt('This user already has an active/future student role in the course, unaffiliated to any section.'));
@@ -3700,7 +3837,15 @@ sub upfile_drop_add {
if (defined($fields{'email'})) {
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;
@@ -3721,8 +3866,13 @@ sub upfile_drop_add {
}
if ($role eq '') {
my $rolestr = join(', ',@permitted_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");
+ $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"
+ );
next;
}
}
@@ -3778,7 +3928,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]} = '';
@@ -3827,7 +3977,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 '') {
@@ -3847,7 +3997,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];
@@ -3862,7 +4012,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) {
@@ -3882,15 +4033,15 @@ sub upfile_drop_add {
} else {
if ($context eq 'course') {
$r->print('
'.
- &mt('[_1]: Unable to enroll. No password specified.',$username)
+ &mt('[_1]: Unable to enroll. No password specified.',''.$username.'')
);
} elsif ($context eq 'author') {
$r->print('
'.
- &mt('[_1]: Unable to add co-author. No password specified.',$username)
+ &mt('[_1]: Unable to add co-author. No password specified.',''.$username.'')
);
} else {
$r->print('
'.
- &mt('[_1]: Unable to add user. No password specified.',$username)
+ &mt('[_1]: Unable to add user. No password specified.',''.$username.'')
);
}
}
@@ -3993,7 +4144,7 @@ sub user_change_result {
if ($userresult =~ /^error:(.+)$/) {
my $error = $1;
$r->print('
'.
- &mt('[_1]: Unable to add/modify: [_2]',$username.':'.$userdomain,$error));
+ &mt('[_1]: Unable to add/modify: [_2]',''.$username.':'.$userdomain.'',$error));
}
} else {
$counts->{'user'} ++;
@@ -4003,7 +4154,7 @@ sub user_change_result {
if ($authresult =~ /^error:(.+)$/) {
my $error = $1;
$r->print('
'.
- &mt('[_1]: Unable to modify authentication: [_2]',$username.':'.$userdomain,$error));
+ &mt('[_1]: Unable to modify authentication: [_2]',''.$username.':'.$userdomain.'',$error));
}
} else {
$counts->{'auth'} ++;
@@ -4013,7 +4164,7 @@ sub user_change_result {
if ($roleresult =~ /^error:(.+)$/) {
my $error = $1;
$r->print('
'.
- &mt('[_1]: Unable to add role: [_2]',$username.':'.$userdomain,$error));
+ &mt('[_1]: Unable to add role: [_2]',''.$username.':'.$userdomain.'',$error));
}
} else {
$counts->{'role'} ++;
@@ -4283,7 +4434,7 @@ sub update_user_list {
$r->print('
'.&mt("$result_text{'ok'}{$choice} role(s) for [quant,_1,user,users,no users].",$count).'
'); if ($count > 0) { if ($choice eq 'revoke' || $choice eq 'drop') { - $r->print(''.&mt('Re-enabling will re-activate data for the role.
')); + $r->print(''.&mt('Re-enabling will re-activate data for the role.').'
'); } # Flush the course logs so reverse user roles immediately updated &Apache::lonnet::flushcourselogs(); @@ -4377,7 +4528,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 = '