--- loncom/interface/lonuserutils.pm 2008/09/11 19:42:28 1.65
+++ loncom/interface/lonuserutils.pm 2009/09/12 17:10:44 1.97.2.3
@@ -1,7 +1,7 @@
# The LearningOnline Network with CAPA
# Utility functions for managing LON-CAPA user accounts
#
-# $Id: lonuserutils.pm,v 1.65 2008/09/11 19:42:28 droeschl Exp $
+# $Id: lonuserutils.pm,v 1.97.2.3 2009/09/12 17:10:44 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('Change authentication for existing users in domain "[_1]" to these settings?',$defdom).'
'; + $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); + my ($home_server_pick,$numlib) = &Apache::loncommon::home_server_form_item($defdom,'lcserver', 'default','hide'); if ($numlib > 1) { - $Str .= '\n".$date_table."
\n"; + $Str .= &Apache::lonhtmlcommon::row_closure() + .&Apache::lonhtmlcommon::row_title( + &mt('LON-CAPA Home Server for New Users')) + .&mt('LON-CAPA domain: [_1] with home server:','"'.$defdom.'"') + .$home_server_pick + .&Apache::lonhtmlcommon::row_closure(); + } else { + $Str .= $home_server_pick. + &Apache::lonhtmlcommon::row_closure(); + } + + $Str .= &Apache::lonhtmlcommon::row_title(&mt('Default domain')) + .&Apache::loncommon::select_dom_form($defdom,'defaultdomain',undef,1) + .&Apache::lonhtmlcommon::row_closure(); + + $Str .= &Apache::lonhtmlcommon::row_title(&mt('Starting and Ending Dates')) + ."\n".$date_table."
\n" + .&Apache::lonhtmlcommon::row_closure(); + if ($context eq 'domain') { - $Str .= ''
+ .''.&mt('Domain Level').'
'
+ .$options
+ .'
' + .''.&mt('Course Level').'' + .'
' + .$cb_script.$coursepick + .&Apache::lonhtmlcommon::row_closure(); } elsif ($context eq 'author') { - $Str .= $options; + $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('Students selected from this list can be dropped.').'
\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 .= '
'.&mt('manual').' | |||
|
'. - &mt('Your Excel spreadsheet').' '.&mt('is ready for download').'.
'."\n"); + $r->print(&mt('[_1]Your Excel spreadsheet[_2] is ready for download.', '','')."
\n"); } elsif ($mode eq 'csv') { close($CSVfile); - $r->print(''. - &mt('Your CSV file').' '.&mt('is ready for download').'.
'."\n"); + $r->print(&mt('[_1]Your CSV file[_2] is ready for download.', '','')."
\n"); $r->rflush(); } if ($mode eq 'autoenroll') { @@ -2796,8 +2941,8 @@ sub select_actions { } } if ($choices{'sections'}) { - $output .= ''."\n". - ''."\n"; + $output .= ''."\n". + ''."\n"; } } return $output; @@ -2811,9 +2956,9 @@ sub date_section_javascript { delete => "Check the boxes for any users for whom roles are to be deleted, and click 'Proceed'", none => "Choose an action to take for selected users", ); - my $output = ' - ENDTWO return $output; @@ -2849,6 +2995,7 @@ sub date_section_selector { my $sec_js = &setsections_javascript($formname,$groupslist); my $output = <<"END"; ENDJS my %lt = &Apache::lonlocal::texthash ( @@ -2975,7 +3123,7 @@ ENDJS $output .= $info.$secbox; } $output .= ''. -'
'."\n". +''."\n". ''; return $output; } @@ -3018,7 +3166,7 @@ sub results_header_row { } if ($context eq 'course') { if ($mode eq 'csv' || $mode eq 'excel') { - $description = &mt('Course - ').$env{'course.'.$env{'request.course.id'}.'.description'}.': '; + $description = &mt('Course - [_1]:',$env{'course.'.$env{'request.course.id'}.'.description'}).' '; } if ($statusmode eq 'Expired') { $description .= &mt('Users in course with expired [_1] roles',$showfilter); @@ -3077,8 +3225,11 @@ sub results_header_row { } } elsif ($context eq 'author') { $description = - &mt('Author space for [_1]', - &Apache::loncommon::plainname($env{'user.name'},$env{'user.domain'})).': '; + &mt('Author space for [_1]' + ,'' + .&Apache::loncommon::plainname($env{'user.name'},$env{'user.domain'}) + .'') + .': '; if ($statusmode eq 'Expired') { $description .= &mt('Co-authors with expired [_1] roles',$showfilter); } elsif ($statusmode eq 'Future') { @@ -3094,7 +3245,7 @@ sub results_header_row { } } elsif ($context eq 'domain') { my $domdesc = &Apache::lonnet::domain($env{'request.role.domain'},'description'); - $description = &mt('Domain - ').$domdesc.': '; + $description = &mt('Domain - [_1]:',$domdesc).' '; if ($env{'form.roletype'} eq 'domain') { if ($statusmode eq 'Expired') { $description .= &mt('Users in domain with expired [_1] roles',$showfilter); @@ -3190,10 +3341,12 @@ sub show_drop_list {- + END my ($indexhash,$keylist) = &make_keylist_array(); my $studentcount = 0; @@ -3311,7 +3464,7 @@ END # $r->print(&Apache::loncommon::start_data_table_row()); $r->print(<<"END"); -
- - -
+ ++ + +
++ +
END return; } @@ -3344,23 +3501,42 @@ END sub print_first_users_upload_form { my ($r,$context) = @_; my $str; - $str = ''; + $str = ''; $str .= ''; $str .= ''; - $str .= "\n"; - $str .= ''."\n"; - $str .= '
\n"; - $str .= &Apache::loncommon::help_open_topic("Course_Create_Class_List", - &mt("How do I create a users list from a spreadsheet")). - "'
+ .&Apache::loncommon::help_open_topic("Course_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( + '') + .'' + .&Apache::lonhtmlcommon::row_closure(1) + .&Apache::lonhtmlcommon::end_pick_box(); + + $str .= '' + .'' + .'
'; + $str .= &Apache::loncommon::end_page(); + $r->print($str); return; } @@ -3404,7 +3580,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'}) { @@ -3487,6 +3664,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; } @@ -3507,7 +3685,9 @@ sub upfile_drop_add { if ($context eq 'course') { my ($cnum,$cdom) = &get_course_identity(); my $roster = &Apache::loncoursedata::get_classlist(); - %userlist = %{$roster}; + 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, @@ -3533,6 +3713,8 @@ sub upfile_drop_add { } else { $r->print('\n");
}
+ $r->rflush;
+
my %counts = (
user => 0,
auth => 0,
@@ -3608,15 +3790,14 @@ 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{'dom'}}
+ if ($entries{$fields{'domain'}}
ne &LONCAPA::clean_domain($entries{$fields{'domain'}})) {
$r->print('
'. ''.$entries{$fields{'domain'}}.
- ': '.&mt('Unacceptable domain for user [_2] [_3] [_4] [_5]',$fname,$mname,$lname,$gen).'');
+ ': '.&mt('Unacceptable domain for user [_2] [_3] [_4] [_5]',$fname,$mname,$lname,$gen));
next;
}
my $username = $entries{$fields{'username'}};
@@ -3629,10 +3810,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);
@@ -3644,7 +3825,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.'));
@@ -3673,7 +3854,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;
@@ -3694,8 +3883,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;
}
}
@@ -3751,7 +3945,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]} = '';
@@ -3800,7 +3994,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 '') {
@@ -3820,7 +4014,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];
@@ -3835,7 +4029,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) {
@@ -3855,15 +4050,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.'')
);
}
}
@@ -3898,7 +4093,7 @@ sub upfile_drop_add {
''.
&mt('There are no students with current/future access to the course.').
''."\n");
- } else {
+ } elsif (ref($classlist) eq 'HASH') {
# Remove the students we just added from the list of students.
foreach my $line (@userdata) {
my %entries=&Apache::loncommon::record_sep($line);
@@ -3966,7 +4161,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'} ++;
@@ -3976,7 +4171,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'} ++;
@@ -3986,7 +4181,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'} ++;
@@ -4256,7 +4451,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(); @@ -4350,7 +4545,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 = '