--- loncom/interface/lonuserutils.pm 2007/12/05 21:23:14 1.11
+++ loncom/interface/lonuserutils.pm 2007/12/14 00:20:53 1.16
@@ -1,7 +1,7 @@
# The LearningOnline Network with CAPA
# Utility functions for managing LON-CAPA user accounts
#
-# $Id: lonuserutils.pm,v 1.11 2007/12/05 21:23:14 raeburn Exp $
+# $Id: lonuserutils.pm,v 1.16 2007/12/14 00:20:53 raeburn Exp $
#
# Copyright Michigan State University Board of Trustees
#
@@ -96,7 +96,7 @@ sub modifyuserrole {
}
} elsif ($context eq 'domain') {
$scope = '/'.$env{'request.role.domain'}.'/';
- } elsif ($context eq 'construction_space') {
+ } elsif ($context eq 'author') {
$scope = '/'.$env{'user.domain'}.'/'.$env{'user.name'};
}
if ($context eq 'domain') {
@@ -136,22 +136,30 @@ sub modifyuserrole {
sub propagate_id_change {
my ($uname,$udom,$user) = @_;
- my (@types,@roles,@cdoms);
+ my (@types,@roles);
@types = ('active','future');
@roles = ('st');
my $idresult;
my %roleshash = &Apache::lonnet::get_my_roles($uname,
- $udom,'userroles',\@types,\@roles,\@cdoms);
+ $udom,'userroles',\@types,\@roles);
+ my %args = (
+ one_time => 1,
+ );
foreach my $item (keys(%roleshash)) {
my ($cnum,$cdom,$role) = split(/:/,$item);
my ($start,$end) = split(/:/,$roleshash{$item});
if (&Apache::lonnet::is_course($cdom,$cnum)) {
- my %userupdate;
- my $result = &update_classlist($cdom,$cnum,$udom,$uname,\%userupdate);
+ 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 .= "Classlist change: $uname:$udom - class -> $cnum:$cdom\n";
+ $idresult .= &mt('Classlist update for "[_1]" in "[_2]".',$uname.':'.$udom,$cdesc).'
'."\n";
} else {
- $idresult .= "Error - $result -during classlist update for $uname:$udom in $cnum:$cdom\n";
+ $idresult .= &mt('Error: "[_1]" during classlist update for "[_2]" in "[_3]".',$result,$uname.':'.$udom,$cdesc).'
'."\n";
}
}
}
@@ -203,7 +211,7 @@ sub domain_roles_select {
# domain context
#
# Role types
- my @roletypes = ('domain','construction_space','course');
+ my @roletypes = ('domain','author','course');
my %lt = &role_type_names();
#
# build up the menu information to be passed to
@@ -225,7 +233,7 @@ sub domain_roles_select {
my @roles;
if ($roletype eq 'domain') {
@roles = &domain_roles();
- } elsif ($roletype eq 'construction_space') {
+ } elsif ($roletype eq 'author') {
@roles = &construction_space_roles();
} else {
@roles = &course_roles('domain');
@@ -246,7 +254,7 @@ sub domain_roles_select {
}
my $result = &Apache::loncommon::linked_select_forms
('studentform',(' 'x3).&mt('Role: '),$env{'form.roletype'},
- 'roletype','showrole',\%select_menus,['domain','construction_space','course']);
+ 'roletype','showrole',\%select_menus,['domain','author','course']);
return $result;
}
@@ -651,7 +659,7 @@ sub print_upload_manager_footer {
my $formname;
if ($context eq 'course') {
$formname = 'document.studentform';
- } elsif ($context eq 'construction_space') {
+ } elsif ($context eq 'author') {
$formname = 'document.studentform';
} elsif ($context eq 'domain') {
$formname = 'document.studentform';
@@ -702,7 +710,7 @@ sub print_upload_manager_footer {
$Str .= '
'.&mt('role').': '.
@@ -755,7 +763,7 @@ sub forceid_change {
if ($context eq 'domain') {
$output .= ''."\n";
}
return $output;
@@ -916,7 +924,7 @@ sub date_setting_table {
my $dateDefault;
if ($mode eq 'create_enrolldates' || $mode eq 'create_defaultdates') {
$dateDefault = ' ';
- } elsif ($mode ne 'construction_space' && $mode ne 'domain') {
+ } elsif ($mode ne 'author' && $mode ne 'domain') {
if (($bulkaction eq 'reenable') ||
($bulkaction eq 'activate') ||
($bulkaction eq 'chgdates')) {
@@ -978,7 +986,7 @@ sub default_role_selector {
my ($context,$checkpriv) = @_;
my %customroles;
my ($options,$coursepick,$cb_jscript);
- if ($context ne 'construction_space') {
+ if ($context ne 'author') {
%customroles = &my_custom_roles();
}
@@ -992,7 +1000,7 @@ sub default_role_selector {
' '."\n";
if ($context eq 'course') {
$options .= &default_course_roles($context,$checkpriv,%customroles);
- } elsif ($context eq 'construction_space') {
+ } elsif ($context eq 'author') {
my @roles = &construction_space_roles($checkpriv);
foreach my $role (@roles) {
my $plrole=&Apache::lonnet::plaintext($role);
@@ -1121,7 +1129,7 @@ sub course_roles {
sub curr_role_permissions {
my ($context,$setting,$checkpriv) = @_;
my @roles;
- if ($context eq 'construction_space') {
+ if ($context eq 'author') {
@roles = &construction_space_roles($checkpriv);
} elsif ($context eq 'domain') {
if ($setting eq 'course') {
@@ -1162,7 +1170,11 @@ sub print_userlist {
($env{'form.Status'});
if ($env{'form.showrole'} eq '') {
- $env{'form.showrole'} = 'Any';
+ if ($context eq 'course') {
+ $env{'form.showrole'} = 'st';
+ } else {
+ $env{'form.showrole'} = 'Any';
+ }
}
if (! defined($env{'form.output'}) ||
$env{'form.output'} !~ /^(csv|excel|html)$/ ) {
@@ -1289,7 +1301,7 @@ sub print_userlist {
\%advrolehash,$permission);
} else {
my (%cstr_roles,%dom_roles);
- if ($context eq 'construction_space') {
+ if ($context eq 'author') {
# List co-authors and assistant co-authors
my @possroles = ('ca','aa');
%cstr_roles = &Apache::lonnet::get_my_roles(undef,undef,undef,
@@ -1305,7 +1317,7 @@ sub print_userlist {
\%userinfo,$dom_roles{$key},$permission);
}
}
- } elsif ($env{'form.roletype'} eq 'construction_space') {
+ } elsif ($env{'form.roletype'} eq 'author') {
my %dom_roles = &Apache::lonnet::get_domain_roles($env{'request.role.domain'},['au']);
my %coauthors;
foreach my $key (keys(%dom_roles)) {
@@ -1384,12 +1396,12 @@ sub print_userlist {
}
}
if (keys(%userlist) == 0) {
- if ($context eq 'construction_space') {
+ if ($context eq 'author') {
$r->print(&mt('There are no co-authors to display.')."\n");
} elsif ($context eq 'domain') {
if ($env{'form.roletype'} eq 'domain') {
$r->print(&mt('There are no users with domain roles to display.')."\n");
- } elsif ($env{'form.roletype'} eq 'construction_space') {
+ } elsif ($env{'form.roletype'} eq 'author') {
$r->print(&mt('There are no authors or co-authors to display.')."\n");
} elsif ($env{'form.roletype'} eq 'course') {
$r->print(&mt('There are no course users to display')."\n");
@@ -1425,7 +1437,7 @@ sub gather_userinfo {
foreach my $item (keys(%{$rolehash})) {
@{$userlist->{$item}} = ();
my %userdata;
- if ($context eq 'construction_space' || $context eq 'course') {
+ if ($context eq 'author' || $context eq 'course') {
($userdata{'username'},$userdata{'domain'},$userdata{'role'}) =
split(/:/,$item);
($userdata{'start'},$userdata{'end'})=split(/:/,$rolehash->{$item});
@@ -1436,7 +1448,7 @@ sub gather_userinfo {
split(/:/,$item);
($userdata{'end'},$userdata{'start'})=split(/:/,$rolehash->{$item});
&build_user_record(\%userdata,$userinfo,$indexhash,$item,$userlist);
- } elsif ($env{'form.roletype'} eq 'construction_space') {
+ } elsif ($env{'form.roletype'} eq 'author') {
if (ref($rolehash->{$item}) eq 'HASH') {
$userdata{'extent'} = $item;
foreach my $key (keys(%{$rolehash->{$item}})) {
@@ -1752,16 +1764,19 @@ sub show_users_list {
$cnum = $env{'course.'.$cid.'.num'};
($classgroups) = &Apache::loncoursedata::get_group_memberships(
$userlist,$keylist,$cdom,$cnum);
- if (! exists($env{'form.displayphotos'})) {
- $env{'form.displayphotos'} = 'off';
- }
- $displayphotos = $env{'form.displayphotos'};
- if (! exists($env{'form.displayclickers'})) {
- $env{'form.displayclickers'} = 'off';
- }
- $displayclickers = $env{'form.displayclickers'};
- if ($env{'course.'.$cid.'.internal.showphoto'}) {
- $r->print('
+ if ($mode eq 'autoenroll') {
+ $env{'form.showrole'} = 'st';
+ } else {
+ if (! exists($env{'form.displayphotos'})) {
+ $env{'form.displayphotos'} = 'off';
+ }
+ $displayphotos = $env{'form.displayphotos'};
+ if (! exists($env{'form.displayclickers'})) {
+ $env{'form.displayclickers'} = 'off';
+ }
+ $displayclickers = $env{'form.displayclickers'};
+ if ($env{'course.'.$cid.'.internal.showphoto'}) {
+ $r->print('
- ');
- }
- $r->print(< '); + my $results_description; + if ($mode ne 'autoenroll') { + $results_description = &results_header_row($rolefilter,$statusmode, + $context,$permission); + $r->print(''.$results_description.' '); + } my ($output,$actionselect); - if ($mode eq 'html' || $mode eq 'view') { - if ($permission->{'cusr'}) { - $actionselect = &select_actions($context,$setting,$statusmode); - } - $r->print(< ';
- my @linkdests = ('aboutme');
- if ($permission->{'cusr'}) {
- push (@linkdests,'modify');
- $output .= ''.$lt{'link'}.': ';
- my $usernamelink = $env{'form.usernamelink'};
- if ($usernamelink eq '') {
- $usernamelink = 'aboutme';
- }
- foreach my $item (@linkdests) {
- my $checkedstr = '';
- if ($item eq $usernamelink) {
- $checkedstr = ' checked="checked" ';
- }
- $output .= ' ';
- }
- $output .= ' ';
+ my @linkdests = ('aboutme');
+ if ($permission->{'cusr'}) {
+ push (@linkdests,'modify');
+ $output .= ''.$lt{'link'}.': ';
+ my $usernamelink = $env{'form.usernamelink'};
+ if ($usernamelink eq '') {
+ $usernamelink = 'aboutme';
+ }
+ foreach my $item (@linkdests) {
+ my $checkedstr = '';
+ if ($item eq $usernamelink) {
+ $checkedstr = ' checked="checked" ';
+ }
+ $output .= ' ';
+ }
+ $output .= ' END - } + } } $output .= "\n \n". &Apache::loncommon::start_data_table(). @@ -1968,7 +1987,7 @@ END $output .= " $lt{$item} | \n";
}
my %role_types = &role_type_names();
- if ($context eq 'course') {
+ if ($context eq 'course' && $mode ne 'autoenroll') {
if ($env{'form.showrole'} eq 'st' || $env{'form.showrole'} eq 'Any') {
# Clicker display on or off?
my %clicker_options = &Apache::lonlocal::texthash(
@@ -2002,8 +2021,8 @@ END
' '."\n";
}
}
- $output .= &Apache::loncommon::end_data_table_header_row();
}
+ $output .= &Apache::loncommon::end_data_table_header_row();
# Done with the HTML header line
} elsif ($mode eq 'csv') {
#
@@ -2065,7 +2084,7 @@ END
delete($userlist->{$user});
next;
}
- } elsif ($env{'form.roletype'} eq 'construction_space') {
+ } elsif ($env{'form.roletype'} eq 'author') {
($uname,$udom,$role) = split(/:/,$user,-1);
} elsif ($env{'form.roletype'} eq 'course') {
($uname,$udom,$role) = split(/:/,$user);
@@ -2139,32 +2158,54 @@ END
}
if ($mode eq 'view' || $mode eq 'html' || $mode eq 'autoenroll') {
$r->print(&Apache::loncommon::start_data_table_row());
- $r->print("$rowcount | \n");
my $checkval;
- if ($mode ne 'autoenroll' && $actionselect) {
- $checkval = $user;
- if ($context eq 'course') {
- if ($role eq 'st') {
- $checkval .= ':st';
- }
- $checkval .= ':'.$in{'section'};
- if ($role eq 'st') {
- $checkval .= ':'.$in{'type'}.':'.$in{'lockedtype'};
+ if ($mode eq 'autoenroll') {
+ my $cellentry;
+ if ($in{'type'} eq 'auto') {
+ $cellentry = ''.&mt('auto').' ';
+ $autocount ++;
+ } else {
+ $cellentry = '
$cellentry | \n");
+ } else {
+ $r->print("$rowcount | \n");
+ $checkval;
+ if ($actionselect) {
+ $checkval = $user;
+ if ($context eq 'course') {
+ if ($role eq 'st') {
+ $checkval .= ':st';
+ }
+ $checkval .= ':'.$in{'section'};
+ if ($role eq 'st') {
+ $checkval .= ':'.$in{'type'}.':'.$in{'lockedtype'};
+ }
+ }
+ $r->print('');
}
- $r->print(' | ');
}
foreach my $item (@cols) {
if ($item eq 'username') {
- $r->print(' | '.&print_username_link($permission,\%in).' | ');
- } elsif (($item eq 'start' || $item eq 'end') && ($mode ne 'autoeroll') && ($actionselect)) {
+ $r->print(''.&print_username_link($mode,$permission,
+ \%in).' | ');
+ } elsif (($item eq 'start' || $item eq 'end') && ($actionselect)) {
$r->print(''.$in{$item}.' | '."\n");
} else {
$r->print(''.$in{$item}.' | '."\n");
}
}
- if ($context eq 'course') {
+ if (($context eq 'course') && ($mode ne 'autoenroll')) {
if ($env{'form.showrole'} eq 'st' || $env{'form.showrole'} eq 'Any') {
if ($displayclickers eq 'on') {
my $clickers =
@@ -2244,9 +2285,11 @@ END
}
sub print_username_link {
- my ($permission,$in) = @_;
+ my ($mode,$permission,$in) = @_;
my $output;
- if (!$permission->{'cusr'}) {
+ if ($mode eq 'autoenroll') {
+ $output = $in->{'username'};
+ } elsif (!$permission->{'cusr'}) {
$output = &Apache::loncommon::aboutmewrapper($in->{'username'},
$in->{'username'},
$in->{'domain'});
@@ -2260,9 +2303,9 @@ sub print_username_link {
sub role_type_names {
my %lt = &Apache::lonlocal::texthash (
- 'domain' => 'Domain Roles',
- 'construction_space' => 'Co-Author Roles',
- 'course' => 'Course Roles',
+ 'domain' => 'Domain Roles',
+ 'author' => 'Co-Author Roles',
+ 'course' => 'Course Roles',
);
return %lt;
}
@@ -2283,10 +2326,6 @@ sub select_actions {
';
$choices{'dates'} = 1;
} else {
- if ($statusmode eq 'Active' || $statusmode eq 'Future') {
- $options .= '
-';
- }
if ($statusmode eq 'Future') {
$options .= '
';
@@ -2296,6 +2335,12 @@ sub select_actions {
';
$choices{'dates'} = 1;
}
+ if ($statusmode eq 'Active' || $statusmode eq 'Future') {
+ $options .= '
+
+';
+ $choices{'dates'} = 1;
+ }
}
if ($context eq 'domain') {
$options .= '
@@ -2516,7 +2561,7 @@ END
}
sub results_header_row {
- my ($rolefilter,$statusmode,$context) = @_;
+ my ($rolefilter,$statusmode,$context,$permission) = @_;
my ($description,$showfilter);
if ($rolefilter ne 'Any') {
$showfilter = $rolefilter;
@@ -2536,8 +2581,17 @@ sub results_header_row {
$description .= &mt('All users in course with [_1] roles',$rolefilter);
}
}
- } elsif ($context eq 'construction_space') {
- $description = &mt('Author space for [_1].').' ';
+ if (exists($permission->{'view_section'})) {
+ if ($env{'form.showrole'} eq 'st') {
+ $description .= ' '.&mt('(section [_1] only)',$permission->{'view_section'});
+ } elsif ($env{'form.showrole'} eq 'any') {
+ $description .= ' '.&mt('(section [_1] only)',$permission->{'view_section'});
+ }
+ }
+ } elsif ($context eq 'author') {
+ $description =
+ &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') {
@@ -2568,7 +2622,7 @@ sub results_header_row {
$description .= &mt('All users in domain with [_1] roles',$rolefilter);
}
}
- } elsif ($env{'form.roletype'} eq 'construction_space') {
+ } elsif ($env{'form.roletype'} eq 'author') {
if ($statusmode eq 'Expired') {
$description .= &mt('Co-authors in domain with expired [_1] roles',$showfilter);
} elsif ($statusmode eq 'Future') {
@@ -2894,7 +2948,7 @@ sub upfile_drop_add {
} elsif ($setting eq 'course') {
$defaultrole = $env{'form.courserole'};
}
- } elsif ($context eq 'construction_space') {
+ } elsif ($context eq 'author') {
$defaultrole = $env{'form.defaultrole'};
}
if ($context eq 'domain' && $setting eq 'course') {
@@ -2917,7 +2971,7 @@ sub upfile_drop_add {
#######################################
if ($context eq 'course') {
$r->print(''.&mt('Enrolling Users')."\n\n"); - } elsif ($context eq 'construction_space') { + } elsif ($context eq 'author') { $r->print(' '.&mt('Updating Co-authors')."\n\n"); } else { $r->print(' '.&mt('Adding/Modifying Users')."\n\n");
@@ -3057,6 +3111,8 @@ sub upfile_drop_add {
next if ($alerts{'username'}{$domain}{$username});
}
}
+ } else {
+# FIXME check if user info can be updated.
}
if ($id ne '') {
if (!$newuser) {
@@ -3109,7 +3165,7 @@ sub upfile_drop_add {
$r->print(' |