--- loncom/interface/lonuserutils.pm 2007/12/12 19:47:56 1.14
+++ loncom/interface/lonuserutils.pm 2007/12/22 00:47:25 1.23
@@ -1,7 +1,7 @@
# The LearningOnline Network with CAPA
# Utility functions for managing LON-CAPA user accounts
#
-# $Id: lonuserutils.pm,v 1.14 2007/12/12 19:47:56 raeburn Exp $
+# $Id: lonuserutils.pm,v 1.23 2007/12/22 00:47:25 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
@@ -69,7 +68,8 @@ sub modifystudent {
my $reply=&Apache::lonnet::modifystudent
# dom name id mode pass f m l g
($udom,$unam,'', '', '',undef,undef,undef,undef,
- $section,time,undef,undef,$desiredhost);
+ $section,time,undef,undef,$desiredhost,'','manual',
+ '',$courseid);
$result .= $reply.':';
}
}
@@ -127,6 +127,7 @@ sub modifyuserrole {
$email,$role,$start,$end);
if ($userresult eq 'ok') {
if ($role ne '') {
+ $role =~ s/_/\//g;
$roleresult = &Apache::lonnet::assignrole($udom,$uname,$scope,
$role,$end,$start);
}
@@ -146,7 +147,7 @@ sub propagate_id_change {
one_time => 1,
);
foreach my $item (keys(%roleshash)) {
- my ($cnum,$cdom,$role) = split(/:/,$item);
+ my ($cnum,$cdom,$role) = split(/:/,$item,-1);
my ($start,$end) = split(/:/,$roleshash{$item});
if (&Apache::lonnet::is_course($cdom,$cnum)) {
my $result = &update_classlist($cdom,$cnum,$udom,$uname,$user);
@@ -236,8 +237,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;
@@ -266,7 +267,7 @@ sub hidden_input {
}
sub print_upload_manager_header {
- my ($r,$datatoken,$distotal,$krbdefdom,$context)=@_;
+ my ($r,$datatoken,$distotal,$krbdefdom,$context,$permission)=@_;
my $javascript;
#
if (! exists($env{'form.upfile_associate'})) {
@@ -296,9 +297,14 @@ sub print_upload_manager_header {
$password_choice = 'int';
}
#
+ my $groupslist;
+ if ($context eq 'course') {
+ $groupslist = &get_groupslist();
+ }
my $javascript_validations =
- &javascript_validations('auth',$krbdefdom,$password_choice,undef,
- $env{'request.role.domain'});
+ &javascript_validations('upload',$krbdefdom,$password_choice,undef,
+ $env{'request.role.domain'},$context,
+ $permission,$groupslist);
my $checked=(($env{'form.noFirstLine'})?' checked="checked" ':'');
$r->print(&mt('Total number of records found in file: [_1].',$distotal).
" ';
- 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 .= ' ';
+ 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 .= '
END
- }
+ }
}
$output .= "\n \n".
&Apache::loncommon::start_data_table().
@@ -1980,7 +2034,7 @@ END
$output .= "
\n");
@@ -325,26 +331,51 @@ sub print_upload_manager_header {
###############################################################
###############################################################
sub javascript_validations {
- my ($mode,$krbdefdom,$curr_authtype,$curr_authfield,$domain)=@_;
- my $authheader;
- if ($mode eq 'auth') {
- my %param = ( formname => 'studentform',
- kerb_def_dom => $krbdefdom,
- curr_authtype => $curr_authtype);
- $authheader = &Apache::loncommon::authform_header(%param);
- } elsif ($mode eq 'createcourse') {
- my %param = ( formname => 'ccrs',
- kerb_def_dom => $krbdefdom,
- curr_authtype => $curr_authtype );
- $authheader = &Apache::loncommon::authform_header(%param);
- } elsif ($mode eq 'modifycourse') {
- my %param = ( formname => 'cmod',
+ my ($mode,$krbdefdom,$curr_authtype,$curr_authfield,$domain,
+ $context,$permission,$groupslist)=@_;
+
+ my %param = (
kerb_def_dom => $krbdefdom,
- mode => 'modifycourse',
curr_authtype => $curr_authtype,
- curr_autharg => $curr_authfield );
- $authheader = &Apache::loncommon::authform_header(%param);
+ );
+ if ($mode eq 'createuser') {
+ $param{'formname'} = 'cu';
+ } elsif ($mode eq 'upload') {
+ $param{'formname'} = 'studentform';
+ } elsif ($mode eq 'singlestudent') {
+ $param{'formname'} = 'cu';
+ } elsif ($mode eq 'createcourse') {
+ $param{'formname'} = 'ccrs';
+ } elsif ($mode eq 'modifycourse') {
+ $param{'formname'} = 'cmod';
+ $param{'mode'} = 'modifycourse',
+ $param{'curr_autharg'} = $curr_authfield;
+ }
+
+ my ($setsection_call,$setsections_js);
+ my $finish = " vf.submit();\n";
+ if ($mode eq 'upload') {
+ if (($context eq 'course') || ($context eq 'domain')) {
+ if ($context eq 'course') {
+ if ($env{'request.course.sec'} eq '') {
+ $setsection_call = 'setSections(document.'.$param{'formname'}.');';
+ $setsections_js =
+ &setsections_javascript($param{'formname'},$groupslist,
+ $mode);
+ } else {
+ $setsection_call = "'ok'";
+ }
+ } elsif ($context eq 'domain') {
+ $setsection_call = 'setCourse()';
+ $setsections_js = &dc_setcourse_js($param{'formname'},$mode);
+ }
+ $finish = " var checkSec = $setsection_call\n".
+ " if (checkSec == 'ok') {\n".
+ " vf.submit();\n".
+ " }\n";
+ }
}
+ my $authheader = &Apache::loncommon::authform_header(%param);
my %alert = &Apache::lonlocal::texthash
(username => 'You need to specify the username field.',
@@ -359,8 +390,9 @@ sub javascript_validations {
continue => 'Continue adding users?',
);
-# my $pjump_def = &Apache::lonhtmlcommon::pjump_javascript_definition();
my $function_name =(<
'.&mt('Default role and/or section')."
\n".
&mt('Role and/or section for users without one in the uploaded file.');
}
- $Str .= '
';
- my ($options,$cb_script,$coursepick) = &default_role_selector($context,'defaultrole',1);
- if ($context eq 'domain') {
- $Str .= ''.&mt('Domain Level').'
'.$options.'
'.&mt('Course Level').'
'.$cb_script.$coursepick;
- } elsif ($context eq 'author') {
- $Str .= $options;
+ $Str .= '
';
+ if (($context eq 'domain') || ($context eq 'author')) {
+ my ($options,$cb_script,$coursepick) = &default_role_selector($context,1);
+ if ($context eq 'domain') {
+ $Str .= ''.&mt('Domain Level').'
'.$options.'
'.&mt('Course Level').'
'.$cb_script.$coursepick;
+ } elsif ($context eq 'author') {
+ $Str .= $options;
+ }
} else {
- $Str .= '
';
- }
- if ($context eq 'course') {
- $Str .= "'.&mt('role').': '.
- $options.' '.
- ''.&mt('section').': ".&mt('Full Update')."
\n".
- '
'."\n";
}
@@ -962,11 +996,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').
'
'."\n";
@@ -1013,33 +1046,36 @@ sub default_role_selector {
$options .= ' ';
}
my $courseform = &Apache::loncommon::selectcourse_link
- ('studentform','defaultcourse','defaultdomain','defaultdesc',"$env{'request.role.domain'}",undef,'Course');
+ ('studentform','dccourse','dcdomain','coursedesc',"$env{'request.role.domain'}",undef,'Course');
$cb_jscript =
- &Apache::loncommon::coursebrowser_javascript($env{'request.role.domain'},'defaultsec','studentform');
+ &Apache::loncommon::coursebrowser_javascript($env{'request.role.domain'},'currsec','studentform');
$coursepick = &Apache::loncommon::start_data_table().
&Apache::loncommon::start_data_table_header_row().
''.$courseform.' '.$lt{'rol'}.' '.
''.$lt{'grs'}.' '.
&Apache::loncommon::end_data_table_header_row().
&Apache::loncommon::start_data_table_row()."\n".
- ''."\n".
+ ' '."\n".
' '.
' '.
+ ''.
+ ''.
+ ''.
+ ''.
+ ''.
+ ''.
&Apache::loncommon::end_data_table_row().
- &Apache::loncommon::end_data_table()."\n".
- ''.
- '';
+ &Apache::loncommon::end_data_table()."\n";
}
$options .= '';
return ($options,$cb_jscript,$coursepick);
@@ -1048,17 +1084,21 @@ 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 .= ' ';
+ if ($role ne 'cr') {
+ my $plrole=&Apache::lonnet::plaintext($role);
+ $output .= ' ';
+ }
}
if (keys(%customroles) > 0) {
- my %customroles = &my_custom_roles();
- foreach my $cust (sort(keys(%customroles))) {
- my $custrole='cr_cr_'.$env{'user.domain'}.
- '_'.$env{'user.name'}.'_'.$cust;
- $output .= ' ';
+ if (grep(/^cr$/,@roles)) {
+ foreach my $cust (sort(keys(%customroles))) {
+ my $custrole='cr_'.$env{'user.domain'}.
+ '_'.$env{'user.name'}.'_'.$cust;
+ $output .= ' ';
+ }
}
}
return $output;
@@ -1066,7 +1106,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 +1122,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 +1137,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;
@@ -1109,10 +1149,10 @@ sub course_roles {
if (&Apache::lonnet::allowed('c'.$role,$env{'request.course.id'})) {
push(@roles,$role);
} else {
- if ($role ne 'cc' && $env{'request.course.section'} ne '') {
- if (!&Apache::lonnet::allowed('c'.$role,
+ if ($role ne 'cc' && $env{'request.course.sec'} ne '') {
+ if (&Apache::lonnet::allowed('c'.$role,
$env{'request.course.id'}.'/'.
- $env{'request.course.section'})) {
+ $env{'request.course.sec'})) {
push(@roles,$role);
}
}
@@ -1128,17 +1168,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;
}
@@ -1236,15 +1277,15 @@ sub print_userlist {
if ($role eq $env{'form.showrole'}) {
$roleselected = ' selected="selected" ';
}
- my $plrole=&Apache::lonnet::plaintext($role);
+ my $plrole;
+ if ($role eq 'cr') {
+ $plrole = &mt('Custom role');
+ } else {
+ $plrole=&Apache::lonnet::plaintext($role);
+ }
$role_select .= '';
}
- $roleselected = '';
- if ($env{'form.showrole'} eq 'cr') {
- $roleselected = ' selected="selected" ';
- }
- $role_select .= ''.
- '';
+ $role_select .= '';
$r->print(''.
'
'.
- $lt{'exs'}.' '.
' '.
''.$lt{'new'}.' '.
- '
'.
''.
- '
';
$space = ', ';
}
@@ -1756,24 +1804,26 @@ sub show_users_list {
if (!grep(/^\Q$sortby\E$/,@sortable)) {
$sortby = 'username';
}
- my $setting = $env{'form.roleaction'};
+ my $setting = $env{'form.roletype'};
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'};
+ $cid = $env{'request.course.id'};
+ ($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 +2068,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 +2205,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').'
';
+ }
+ $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 +2332,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'});
@@ -2290,6 +2368,10 @@ sub select_actions {
chgsec => "Change section associated with user roles",
);
my ($output,$options,%choices);
+ # FIXME Disable actions for now for roletype=course in domain context
+ if ($context eq 'domain' && $setting eq 'course') {
+ return;
+ }
if ($statusmode eq 'Any') {
$options .= '
';
@@ -2395,7 +2477,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 +2556,14 @@ END
$starttime = time;
}
$date_items = &date_setting_table($starttime,undef,$context,
- $env{'form.bulkaction'});
+ $env{'form.bulkaction'},$formname,
+ $permission);
}
$output .= ''.$headertext.'
'.
'
'. @@ -2529,8 +2602,38 @@ 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". + ' |
@@ -2677,9 +2793,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'}
@@ -2689,32 +2805,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
@@ -2761,6 +2877,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");
@@ -2820,7 +2943,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);}
@@ -3271,9 +3394,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 {
@@ -3301,12 +3425,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);
@@ -3316,7 +3446,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;
@@ -3349,8 +3490,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 =
@@ -3452,19 +3599,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('