--- loncom/interface/lonuserutils.pm 2013/07/15 14:55:14 1.153
+++ loncom/interface/lonuserutils.pm 2014/02/16 15:38:53 1.163
@@ -1,7 +1,7 @@
# The LearningOnline Network with CAPA
# Utility functions for managing LON-CAPA user accounts
#
-# $Id: lonuserutils.pm,v 1.153 2013/07/15 14:55:14 bisitz Exp $
+# $Id: lonuserutils.pm,v 1.163 2014/02/16 15:38:53 raeburn Exp $
#
# Copyright Michigan State University Board of Trustees
#
@@ -401,7 +401,7 @@ sub javascript_validations {
my $showcredits;
my %domdefaults = &Apache::lonnet::get_domain_defaults($domain);
- if ($domdefaults{'officialcredits'} || $domdefaults{'unofficialcredits'}) {
+ if ($domdefaults{'officialcredits'} || $domdefaults{'unofficialcredits'} || $domdefaults{'textbookcredits'}) {
$showcredits = 1;
}
@@ -642,7 +642,7 @@ sub upload_manager_javascript_forward_as
$numbuttons ++;
}
if (!$can_assign->{'int'}) {
- my $warning = &mt('You may not specify an initial password for each user, as this is only available when new users use LON-CAPA internal authentication.').'\n'
+ my $warning = &mt('You may not specify an initial password for each user, as this is only available when new users use LON-CAPA internal authentication.').'\n'.
&mt('Your current role does not have rights to create users with that authentication type.');
$auth_update = <<"END";
// Currently the initial password field is only supported for internal auth
@@ -1013,7 +1013,9 @@ sub print_upload_manager_footer {
.&Apache::lonhtmlcommon::row_closure();
}
if ($context eq 'course' || $context eq 'domain') {
- $Str .= &forceid_change($context);
+ $Str .= &Apache::lonhtmlcommon::row_title(&mt('Student/Employee ID'))
+ .&forceid_change($context)
+ .&Apache::lonhtmlcommon::row_closure(1); # last row in pick_box
}
$Str .= &Apache::lonhtmlcommon::end_pick_box();
@@ -1047,10 +1049,12 @@ sub get_defaultcredits {
return unless(($cdom =~ /^$match_domain$/) && ($cnum =~ /^$match_courseid$/));
my ($defaultcredits,$domdefcredits);
my %domdefaults = &Apache::lonnet::get_domain_defaults($cdom);
- if ($domdefaults{'officialcredits'} || $domdefaults{'unofficialcredits'}) {
+ if ($domdefaults{'officialcredits'} || $domdefaults{'unofficialcredits'} || $domdefaults{'textbookcredits'}) {
my $instcode = $env{'course.'.$cdom.'_'.$cnum.'.internal.coursecode'};
if ($instcode) {
$domdefcredits = $domdefaults{'officialcredits'};
+ } elsif ($env{'course.'.$cdom.'_'.$cnum.'.internal.textbook'}) {
+ $domdefcredits = $domdefaults{'textbookcredits'};
} else {
$domdefcredits = $domdefaults{'unofficialcredits'};
}
@@ -1076,18 +1080,15 @@ sub get_defaultcredits {
sub forceid_change {
my ($context) = @_;
my $output =
- &Apache::lonhtmlcommon::row_title(&mt('Student/Employee ID'))
- .' '
- .&mt('Disable Student/Employee ID Safeguard and force change of conflicting IDs')
- .' '."\n"
- .&mt('(only do if you know what you are doing.)')."\n";
+ ' '
+ .&mt('Force change of exising ID')
+ .' '.&Apache::loncommon::help_open_topic('ForceIDChange')."\n";
if ($context eq 'domain') {
- $output .= ' '.
- &mt('Update student/employee ID in courses in which user is active/future student,[_1](if forcing change).',' ').
- ' '."\n";
+ $output .=
+ ' '
+ .' '
+ .&mt("Update ID in user's course(s).").' '."\n";
}
- $output .= &Apache::lonhtmlcommon::row_closure(1); # last row in pick_box
return $output;
}
@@ -1392,9 +1393,9 @@ sub default_role_selector {
&default_course_roles($context,$checkpriv,'Course',%customroles)."\n".
'
'.
''.
- ''.
+ ' '.
$lt{'exs'}.''.
- ' <--'.&mt('Pick course first').
+ ' <--'.&mt('Pick course first').
' '.
' '.
''.$lt{'new'}.' '.
@@ -1637,7 +1638,7 @@ sub print_userlist {
return;
}
my ($indexhash,$keylist) = &make_keylist_array();
- my (%userlist,%userinfo,$clearcoursepick);
+ my (%userlist,%userinfo,$clearcoursepick,$needauthorquota,$needauthorusage);
if (($context eq 'domain') &&
($env{'form.roletype'} eq 'course') ||
($env{'form.roletype'} eq 'community')) {
@@ -1709,6 +1710,12 @@ sub print_userlist {
\%cstr_roles,$permission);
} elsif ($context eq 'domain') {
if ($env{'form.roletype'} eq 'domain') {
+ if (grep(/^authorusage$/,@cols)) {
+ $needauthorusage = 1;
+ }
+ if (grep(/^authorquota$/,@cols)) {
+ $needauthorquota = 1;
+ }
%dom_roles = &Apache::lonnet::get_domain_roles($env{'request.role.domain'});
foreach my $key (keys(%dom_roles)) {
if (ref($dom_roles{$key}) eq 'HASH') {
@@ -1821,7 +1828,7 @@ sub print_userlist {
} else {
($usercount) = &show_users_list($r,$context,$env{'form.output'},
$permission,$env{'form.Status'},\%userlist,
- $keylist,'',$showcredits);
+ $keylist,'',$showcredits,$needauthorquota,$needauthorusage);
}
if (!$usercount) {
$r->print(''
@@ -1988,10 +1995,10 @@ sub get_cols_array {
}
if (($context eq 'course') && ($mode ne 'autoenroll') &&
($env{'course.'.$env{'request.course.id'}.'.internal.showphoto'})) {
- push(@cols,'photos');
+ push(@cols,'photo');
}
if ($context eq 'domain') {
- push (@cols,'extent');
+ push (@cols,('authorusage','authorquota','extent'));
}
}
return @cols;
@@ -2027,6 +2034,8 @@ sub column_checkboxes {
if (($env{'form.roletype'} eq 'course') ||
($env{'form.roletype'} eq 'community')) {
$disabledchk{'status'} = 1;
+ $disabledchk{'authorusage'} = 1;
+ $disabledchk{'authorquota'} = 1;
} elsif ($env{'form.roletype'} eq 'domain') {
$disabledchk{'extent'} = 1;
}
@@ -2078,7 +2087,11 @@ sub column_checkboxes {
if (($env{'form.roletype'} eq 'domain') || ($env{'form.roletype'} eq '')) {
$style = ' style="display: none;"';
}
- }
+ } elsif (($cols[$i] eq 'authorusage') || ($cols[$i] eq 'authorquota')) {
+ if ($env{'form.roletype'} ne 'domain') {
+ $style = ' style="display: none;"';
+ }
+ }
$output .= ''.
''.
$lt{$cols[$i]}.' '.
@@ -2112,6 +2125,8 @@ sub get_column_names {
'photo' => "photo",
'lastlogin' => "last login",
'extent' => "extent",
+ 'authorusage' => "disk usage (%)",
+ 'authorquota' => "disk quota (MB)",
'ca' => "check all",
'ua' => "uncheck all",
'clicker' => "clicker-ID",
@@ -2119,7 +2134,7 @@ sub get_column_names {
if ($context eq 'domain' && $env{'form.roletype'} eq 'course') {
$lt{'extent'} = &mt('course(s): description, section(s), status');
} elsif ($context eq 'domain' && $env{'form.roletype'} eq 'community') {
- $lt{'extent'} = &mt('communities: description, section(s), status');
+ $lt{'extent'} = &mt('community(s): description, section(s), status');
} elsif (($context eq 'author') ||
($context eq 'domain' && $env{'form.roletype'} eq 'author')) {
$lt{'extent'} = &mt('author');
@@ -2395,6 +2410,8 @@ sub make_keylist_array {
$index->{'photo'} = &Apache::loncoursedata::CL_PHOTO();
$index->{'thumbnail'} = &Apache::loncoursedata::CL_THUMBNAIL();
$index->{'credits'} = &Apache::loncoursedata::CL_CREDITS();
+ $index->{'authorquota'} = &Apache::loncoursedata::CL_AUTHORQUOTA();
+ $index->{'authorusage'} = &Apache::loncoursedata::CL_AUTHORUSAGE();
foreach my $key (keys(%{$index})) {
$keylist->[$index->{$key}] = $key;
}
@@ -2444,10 +2461,11 @@ sub process_date_info {
sub show_users_list {
my ($r,$context,$mode,$permission,$statusmode,$userlist,$keylist,$formname,
- $showcredits)=@_;
+ $showcredits,$needauthorquota,$needauthorusage)=@_;
if ($formname eq '') {
$formname = 'studentform';
}
+ my $londocroot = $Apache::lonnet::perlvar{'lonDocRoot'};
#
# Variables for excel output
my ($excel_workbook, $excel_sheet, $excel_filename,$row,$format);
@@ -2464,11 +2482,17 @@ sub show_users_list {
}
} else {
push(@sortable,'extent');
+ if (($context eq 'domain') && ($env{'form.roletype'} eq 'domain') &&
+ (($env{'form.showrole'} eq 'Any') || ($env{'form.showrole'} eq 'au'))) {
+ push(@sortable,('authorusage','authorquota'));
+ }
}
if ($mode eq 'pickauthor') {
@sortable = ('username','fullname','email','status');
}
- if (!grep(/^\Q$sortby\E$/,@sortable)) {
+ my %is_sortable;
+ map { $is_sortable{$_} = 1; } @sortable;
+ unless ($is_sortable{$sortby}) {
$sortby = 'username';
}
my $setting = $env{'form.roletype'};
@@ -2708,11 +2732,17 @@ END
} else {
$output .= "\n".' '."\n";
if ($actionselect) {
- $output .= ''.&mt('Select').' '."\n";
+ $output .= ''.&mt('Select').' '."\n";
}
}
foreach my $item (@cols) {
- $output .= "$lt{$item} \n";
+ $output .= '';
+ if ($is_sortable{$item}) {
+ $output .= "$lt{$item} ▼ ";
+ } else {
+ $output .= $lt{$item};
+ }
+ $output .= " \n";
}
my %role_types = &role_type_names();
$output .= &Apache::loncommon::end_data_table_header_row();
@@ -2883,6 +2913,26 @@ END
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 ++;
}
my $autocount = 0;
@@ -2903,12 +2953,20 @@ END
my $index = $index{$sortby};
my $second = $index{'username'};
my $third = $index{'domain'};
- my @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 @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;
foreach my $user (@sorted_users) {
my %in;
@@ -2919,7 +2977,7 @@ END
}
my $clickers = (&Apache::lonnet::userenvironment($in{'domain'},$in{'username'},'clickers'))[1];
if ($clickers!~/\w/) { $clickers='-'; }
- $in{'clicker'} = $clickers;
+ $in{'clicker'} = $clickers;
my $role = $in{'role'};
$in{'role'}=&Apache::lonnet::plaintext($sdata->[$index{'role'}],$crstype);
unless ($mode eq 'excel') {
@@ -2946,10 +3004,10 @@ END
if ($mode eq 'autoenroll') {
my $cellentry;
if ($in{'type'} eq 'auto') {
- $cellentry = ''.&mt('auto').' Change ';
+ $cellentry = ''.&mt('auto').' '.&mt('Change').' ';
$autocount ++;
} else {
- $cellentry = ''.&mt('manual').' Change';
+ $cellentry = ''.&mt('manual').' '.&mt('Change').'';
$manualcount ++;
if ($in{'lockedtype'}) {
$cellentry .= ' '.&mt('Unlock').' ';
@@ -3043,6 +3101,8 @@ END
$r->print(' '."\n");
}
}
+ } elsif (($item eq 'authorquota') || ($item eq 'authorusage')) {
+ $r->print(''.$in{$item}.' '."\n");
} else {
$r->print(''.$in{$item}.' '."\n");
}
@@ -3078,10 +3138,10 @@ END
$r->print(&Apache::loncommon::end_data_table().' ');
} elsif ($mode eq 'excel') {
$excel_workbook->close();
- $r->print(&mt('[_1]Your Excel spreadsheet[_2] 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('[_1]Your CSV file[_2] is ready for download.', '',' ')."
\n");
+ $r->print(''.&mt('[_1]Your CSV file[_2] is ready for download.', '',' ')."
\n");
$r->rflush();
}
if ($mode eq 'autoenroll') {
@@ -3779,7 +3839,6 @@ sub show_drop_list {
$check_uncheck_js
// ]]>
-
END
my ($indexhash,$keylist) = &make_keylist_array();
@@ -3816,6 +3875,7 @@ END
$classlist,$keylist,$cdom,$cnum);
my %lt=&Apache::lonlocal::texthash('usrn' => "username",
'dom' => "domain",
+ 'id' => "ID",
'sn' => "student name",
'mn' => "member name",
'sec' => "section",
@@ -3834,7 +3894,7 @@ END
$lt{'usrn'}
$lt{'dom'}
- ID
+ $lt{'id'}
$nametitle
$lt{'sec'}
$lt{'start'}
@@ -3848,21 +3908,21 @@ END
$r->print(<
- $lt{'usrn'}
+ $lt{'usrn'}
- $lt{'dom'}
+ $lt{'dom'}
- ID
+ $lt{'id'}
- $nametitle
+ $nametitle
- $lt{'sec'}
+ $lt{'sec'}
- $lt{'start'}
+ $lt{'start'}
- $lt{'end'}
+ $lt{'end'}
- $lt{'groups'}
+ $lt{'groups'}
END
$r->print(&Apache::loncommon::end_data_table_header_row());
@@ -3933,7 +3993,6 @@ END
$btn = $lt{'dm'};
}
$r->print(<<"END");
-
@@ -4263,18 +4322,23 @@ sub upfile_drop_add {
if ($entries{$fields{'username'}} =~ /\s/) {
$nowhitespace = ' - '.&mt('usernames may not contain spaces.');
}
- $r->print(' '.
- &mt('[_1]: Unacceptable username for user [_2] [_3] [_4] [_5]',
- ''.$entries{$fields{'username'}}.' ',$fname,$mname,$lname,$gen).
- $nowhitespace);
+ $r->print(
+ ' '.
+ &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'}})) {
- $r->print(' '. ''.$entries{$fields{'domain'}}.
- ' : '.&mt('Unacceptable domain for user [_1] [_2] [_3] [_4]',$fname,$mname,$lname,$gen));
- next;
+ $r->print(
+ ' '.
+ &mt('Unacceptable domain [_1] for user [_2] [_3] [_4] [_5]',
+ '"'.$entries{$fields{'domain'}}.' "',
+ $fname,$mname,$lname,$gen));
+ next;
}
my $username = $entries{$fields{'username'}};
my $userdomain = $entries{$fields{'domain'}};
@@ -4754,7 +4818,7 @@ sub print_drop_menu {
} else {
&show_drop_list($r,$classlist,'nosort',$permission,$crstype);
}
- $r->print(''. &Apache::loncommon::end_page());
+ $r->print('');
return;
}