--- loncom/interface/lonuserutils.pm 2007/12/12 23:59:41 1.15
+++ loncom/interface/lonuserutils.pm 2007/12/21 20:34:26 1.21
@@ -1,7 +1,7 @@
# The LearningOnline Network with CAPA
# Utility functions for managing LON-CAPA user accounts
#
-# $Id: lonuserutils.pm,v 1.15 2007/12/12 23:59:41 raeburn Exp $
+# $Id: lonuserutils.pm,v 1.21 2007/12/21 20:34:26 raeburn Exp $
#
# Copyright Michigan State University Board of Trustees
#
@@ -46,8 +46,7 @@ sub modifystudent {
# if $csec is undefined, drop the student from all the courses matching
# this one. If $csec is defined, drop them from all other sections of
# this course and add them to section $csec
- my $cdom = $env{'course.'.$courseid.'.domain'};
- my $cnum = $env{'course.'.$courseid.'.num'};
+ my ($cnum,$cdom) = &get_course_identity($courseid);
my %roles = &Apache::lonnet::dump('roles',$udom,$unam);
my ($tmp) = keys(%roles);
# Bail out if we were unable to get the students roles
@@ -236,8 +235,8 @@ sub domain_roles_select {
} elsif ($roletype eq 'author') {
@roles = &construction_space_roles();
} else {
- @roles = &course_roles('domain');
- unshift(@roles,'cr');
+ my $custom = 1;
+ @roles = &course_roles('domain',undef,$custom);
}
my $order = ['Any',@roles];
$select_menus{$roletype}->{'order'} = $order;
@@ -772,7 +771,7 @@ sub forceid_change {
###############################################################
###############################################################
sub print_upload_manager_form {
- my ($r,$context) = @_;
+ my ($r,$context,$permission) = @_;
my $firstLine;
my $datatoken;
if (!$env{'form.datatoken'}) {
@@ -962,11 +961,10 @@ sub make_dates_default {
my ($startdate,$enddate,$context) = @_;
my $result = '';
if ($context eq 'course') {
- my $dom = $env{'course.'.$env{'request.course.id'}.'.domain'};
- my $crs = $env{'course.'.$env{'request.course.id'}.'.num'};
+ my ($cnum,$cdom) = &get_course_identity();
my $put_result = &Apache::lonnet::put('environment',
{'default_enrollment_start_date'=>$startdate,
- 'default_enrollment_end_date' =>$enddate},$dom,$crs);
+ 'default_enrollment_end_date' =>$enddate},$cdom,$cnum);
if ($put_result eq 'ok') {
$result .= &mt('Set default start and end dates for course').
' ';
- 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().
@@ -1980,7 +1984,7 @@ END
$output .= "
'."\n";
@@ -1048,7 +1046,8 @@ sub default_role_selector {
sub default_course_roles {
my ($context,$checkpriv,%customroles) = @_;
my $output;
- my @roles = &course_roles($context,$checkpriv);
+ my $custom = 1;
+ my @roles = &course_roles($context,$checkpriv,$custom);
foreach my $role (@roles) {
my $plrole=&Apache::lonnet::plaintext($role);
$output .= ' ';
@@ -1066,7 +1065,7 @@ sub default_course_roles {
sub construction_space_roles {
my ($checkpriv) = @_;
- my @allroles = ('ca','aa');
+ my @allroles = &roles_by_context('author');
my @roles;
if ($checkpriv) {
foreach my $role (@allroles) {
@@ -1082,7 +1081,7 @@ sub construction_space_roles {
sub domain_roles {
my ($checkpriv) = @_;
- my @allroles = ('dc','li','dg','au','sc');
+ my @allroles = &roles_by_context('domain');
my @roles;
if ($checkpriv) {
foreach my $role (@allroles) {
@@ -1097,8 +1096,8 @@ sub domain_roles {
}
sub course_roles {
- my ($context,$checkpriv) = @_;
- my @allroles = ('st','ta','ep','in','cc');
+ my ($context,$checkpriv,$custom) = @_;
+ my @allroles = &roles_by_context('course',$custom);
my @roles;
if ($context eq 'domain') {
@roles = @allroles;
@@ -1128,17 +1127,18 @@ sub course_roles {
sub curr_role_permissions {
my ($context,$setting,$checkpriv) = @_;
+ my $custom = 1;
my @roles;
if ($context eq 'author') {
@roles = &construction_space_roles($checkpriv);
} elsif ($context eq 'domain') {
if ($setting eq 'course') {
- @roles = &course_roles($context,$checkpriv);
+ @roles = &course_roles($context,$checkpriv,$custom);
} else {
@roles = &domain_roles($checkpriv);
}
} elsif ($context eq 'course') {
- @roles = &course_roles($context,$checkpriv);
+ @roles = &course_roles($context,$checkpriv,$custom);
}
return @roles;
}
@@ -1287,8 +1287,7 @@ sub print_userlist {
}
}
my $cid =$env{'request.course.id'};
- my $cdom=$env{'course.'.$cid.'.domain'};
- my $cnum=$env{'course.'.$cid.'.num'};
+ my ($cnum,$cdom) = &get_course_identity($cid);
my $showroles;
if ($env{'form.showrole'} ne 'Any') {
$showroles = [$env{'form.showrole'}];
@@ -1303,7 +1302,7 @@ sub print_userlist {
my (%cstr_roles,%dom_roles);
if ($context eq 'author') {
# List co-authors and assistant co-authors
- my @possroles = ('ca','aa');
+ my @possroles = &roles_by_context($context);
%cstr_roles = &Apache::lonnet::get_my_roles(undef,undef,undef,
\@statuses,\@possroles);
&gather_userinfo($context,$format,\%userlist,$indexhash,\%userinfo,
@@ -1328,7 +1327,7 @@ sub print_userlist {
} else {
my @possroles;
if ($env{'form.showrole'} eq 'Any') {
- @possroles = ('ca','aa');
+ my @possroles = &roles_by_context($context);
} else {
@possroles = ($env{'form.showrole'});
}
@@ -1351,14 +1350,13 @@ sub print_userlist {
foreach my $cid (keys(%courses)) {
my %coursehash =
&Apache::lonnet::coursedescription($cid,{'one_time' => 1});
- my $cdom = $coursehash{'domain'};
- my $cnum = $coursehash{'num'};
+ my ($cnum,$cdom,$cdesc) = &get_course_identity($cid);
next if ($cnum eq '' || $cdom eq '');
- my $cdesc = $coursehash{'description'};
+ my $custom = 1;
my (@roles,@sections,%access,%users,%userdata,
%statushash);
if ($env{'form.showrole'} eq 'Any') {
- @roles = &course_roles($context);
+ @roles = &course_roles($context,undef,$custom);
unshift(@roles,'cr');
} else {
@roles = ($env{'form.showrole'});
@@ -1760,20 +1758,22 @@ sub show_users_list {
my ($cid,$cdom,$cnum,$classgroups,$displayphotos,$displayclickers);
if ($context eq 'course') {
$cid=$env{'request.course.id'};
- $cdom = $env{'course.'.$cid.'.domain'};
- $cnum = $env{'course.'.$cid.'.num'};
+ ($cnum,$cdom) = &get_course_identity($cid);
($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(<
';
- } else {
- $output .= &mt("Click on a username to view the user's personal page.").'
';
- }
- if ($actionselect) {
- $output .= <<"END";
+ $output = '
';
+ } else {
+ $output .= &mt("Click on a username to view the user's personal page.").'
';
+ }
+ if ($actionselect) {
+ $output .= <<"END";
$lt{'ac'}: $actionselect $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(
@@ -2014,8 +2018,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') {
#
@@ -2151,32 +2155,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 = '
';
+ }
+ $r->print("'.&mt('manual').' $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 =
@@ -2256,9 +2282,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'});
@@ -2395,7 +2423,7 @@ ENDTWO
}
sub date_section_selector {
- my ($context) = @_;
+ my ($context,$permission) = @_;
my $callingform = $env{'form.callingform'};
my $formname = 'dateselect';
my $groupslist = &get_groupslist();
@@ -2474,14 +2502,14 @@ END
$starttime = time;
}
$date_items = &date_setting_table($starttime,undef,$context,
- $env{'form.bulkaction'});
+ $env{'form.bulkaction'},$formname,
+ $permission);
}
$output .= ''.$headertext.'
'.
'
'. @@ -2529,6 +2548,36 @@ END return $output; } +sub section_picker { + my ($cdom,$cnum,$role,$rowtitle,$permission,$context,$mode) = @_; + my %sections_count = &Apache::loncommon::get_sections($cdom,$cnum); + my $sections_select .= &course_sections(\%sections_count,$role); + my $secbox = '
'.&Apache::lonhtmlcommon::start_pick_box()."\n"; + if ($mode eq 'upload') { + my ($options,$cb_script,$coursepick) = + &default_role_selector($context,1); + $secbox .= &Apache::lonhtmlcommon::row_title('role','LC_oddrow_value'). + $options. &Apache::lonhtmlcommon::row_closure(1)."\n"; + } + $secbox .= &Apache::lonhtmlcommon::row_title($rowtitle,'LC_oddrow_value')."\n"; + if ($env{'request.course.sec'} eq '') { + $secbox .= '
'.&mt('Existing sections')."\n".
+ ' '.$sections_select.' | '.
+ &mt('New section').' '."\n". + ''."\n". + ''."\n". + ' |
@@ -2684,9 +2725,9 @@ my %lt=&Apache::lonlocal::texthash('usrn
'groups' => "active groups",
);
if ($nosort) {
- $r->print(&Apache::loncommon::start_data_table());
+ $r->print(&Apache::loncommon::start_data_table().
+ &Apache::loncommon::start_data_table_header_row());
$r->print(< '.&mt("$result_text{'ok'}{$choice} role(s) for [quant,_1,user,users,users].",$count).' '.&mt('Re-enabling will re-activate data for the role.
$lt{'usrn'}
$lt{'dom'}
@@ -2696,32 +2737,32 @@ my %lt=&Apache::lonlocal::texthash('usrn
$lt{'start'}
$lt{'end'}
$lt{'groups'}
-
END
-
+ $r->print(&Apache::loncommon::end_data_table_header_row());
} else {
- $r->print(&Apache::loncommon::start_data_table());
+ $r->print(&Apache::loncommon::start_data_table().
+ &Apache::loncommon::start_data_table_header_row());
$r->print(<
+
- $lt{'usrn'}
+ $lt{'usrn'}
- $lt{'dom'}
+ $lt{'dom'}
- ID
+ ID
- $lt{'sn'}
+ $lt{'sn'}
- $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());
}
#
# Sort the students
@@ -2768,6 +2809,13 @@ END
}
my $status = $sdata->[$index{'status'}];
next if ($status ne 'Active');
+ if ($env{'request.course.sec'} ne '') {
+ if ($section ne $env{'request.course.sec'}) {
+ next;
+ }
+ }
+ my $studentkey = $student.':'.$section;
+ my $startitem = '';
#
$r->print(&Apache::loncommon::start_data_table_row());
$r->print(<<"END");
@@ -2827,7 +2875,7 @@ sub print_first_users_upload_form {
# ================================================= Drop/Add from uploaded file
sub upfile_drop_add {
- my ($r,$context) = @_;
+ my ($r,$context,$permission) = @_;
&Apache::loncommon::load_tmp_file($r);
my @userdata=&Apache::loncommon::upfile_record_sep();
if($env{'form.noFirstLine'}){shift(@userdata);}
@@ -3278,9 +3326,10 @@ sub user_change_result {
}
# ========================================================= Menu Phase Two Drop
-sub print_expire_menu {
- my ($r,$context) = @_;
- $r->print("".&mt("Expire Users' Roles")."
");
+sub print_drop_menu {
+ my ($r,$context,$permission) = @_;
+ $r->print(''.&mt("Drop Students").'
'."\n".
+ ''. &Apache::loncommon::end_page());
return;
}
-
# ================================================================== Phase four
sub update_user_list {
@@ -3308,12 +3357,18 @@ sub update_user_list {
my %result_text = ( ok => { 'revoke' => 'Revoked',
'delete' => 'Deleted',
'reenable' => 'Re-enabled',
- 'activate' => 'Activated',
+ 'activate' => 'Activated',
+ 'chgdates' => 'Changed Access Dates for',
+ 'chgsec' => 'Changed section for',
+ 'drop' => 'Dropped',
},
error => {'revoke' => 'revoking',
'delete' => 'deleting',
'reenable' => 're-enabling',
'activate' => 'activating',
+ 'chgdates' => 'changing access dates for',
+ 'chgsec' => 'changing section for',
+ 'drop' => 'dropping',
},
);
my ($startdate,$enddate);
@@ -3323,7 +3378,18 @@ sub update_user_list {
foreach my $item (@changelist) {
my ($role,$uname,$udom,$cid,$sec,$scope,$result,$type,$locktype,@sections,
$scopestem);
- if ($context eq 'course') {
+ if ($choice eq 'drop') {
+ ($uname,$udom,$sec) = split(/:/,$item,-1);
+ $role = 'st';
+ $cid = $env{'request.course.id'};
+ $scopestem = '/'.$cid;
+ $scopestem =~s/\_/\//g;
+ if ($sec eq '') {
+ $scope = $scopestem;
+ } else {
+ $scope = $scopestem.'/'.$sec;
+ }
+ } elsif ($context eq 'course') {
($uname,$udom,$role,$sec,$type,$locktype) = split(/\:/,$item,-1);
$cid = $env{'request.course.id'};
$scopestem = '/'.$cid;
@@ -3356,8 +3422,14 @@ sub update_user_list {
my ($uid,$first,$middle,$last,$gene,$sec);
my $start = $env{'form.'.$item.'_start'};
my $end = $env{'form.'.$item.'_end'};
- # revoke or delete user role
- if ($choice eq 'revoke') {
+ if ($choice eq 'drop') {
+ # drop students
+ $end = $now;
+ $type = 'manual';
+ $result =
+ &Apache::lonnet::modify_student_enrollment($udom,$uname,undef,undef,undef,undef,undef,$sec,$end,$start,$type,$locktype,$cid);
+ } elsif ($choice eq 'revoke') {
+ # revoke or delete user role
$end = $now;
if ($role eq 'st') {
$result =
@@ -3459,19 +3531,26 @@ sub update_user_list {
}
}
}
+ my $extent = $scope;
+ if ($choice eq 'drop' || $context eq 'course') {
+ my ($cnum,$cdom,$cdesc) = &get_course_identity($cid);
+ if ($cdesc) {
+ $extent = $cdesc;
+ }
+ }
if ($result eq 'ok' || $result eq 'ok:') {
$r->print(&mt("$result_text{'ok'}{$choice} role of '[_1]' in [_2] for [_3]",
- $plrole,$scope,$uname.':'.$udom).'
');
+ $plrole,$extent,$uname.':'.$udom).'
');
$count++;
} else {
$r->print(
&mt("Error $result_text{'error'}{$choice} [_1] in [_2] for [_3]:[_4]",
- $plrole,$scope,$uname.':'.$udom,$result).'
');
+ $plrole,$extent,$uname.':'.$udom,$result).'
');
}
}
$r->print('