--- loncom/interface/lonuserutils.pm 2007/10/22 22:16:38 1.1
+++ loncom/interface/lonuserutils.pm 2007/12/23 03:21:28 1.31
@@ -1,7 +1,7 @@
# The LearningOnline Network with CAPA
# Utility functions for managing LON-CAPA user accounts
#
-# $Id: lonuserutils.pm,v 1.1 2007/10/22 22:16:38 raeburn Exp $
+# $Id: lonuserutils.pm,v 1.31 2007/12/23 03:21:28 raeburn Exp $
#
# Copyright Michigan State University Board of Trustees
#
@@ -35,7 +35,8 @@ use Apache::lonnet;
use Apache::loncommon();
use Apache::lonhtmlcommon;
use Apache::lonlocal;
-use LONCAPA();
+use Apache::longroup;
+use LONCAPA qw(:DEFAULT :match);
###############################################################
###############################################################
@@ -45,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
@@ -68,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.':';
}
}
@@ -85,28 +86,39 @@ 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) = @_;
- my ($scope,$userresult,$authresult,$roleresult);
+ $end,$start,$checkid) = @_;
+ my ($scope,$userresult,$authresult,$roleresult,$idresult);
if ($setting eq 'course' || $context eq 'course') {
$scope = '/'.$cid;
$scope =~ s/\_/\//g;
if ($role ne 'cc' && $sec ne '') {
$scope .='/'.$sec;
}
- } elsif ($setting eq 'domain') {
+ } elsif ($context eq 'domain') {
$scope = '/'.$env{'request.role.domain'}.'/';
- } elsif ($setting eq 'construction_space') {
+ } elsif ($context eq 'author') {
$scope = '/'.$env{'user.domain'}.'/'.$env{'user.name'};
}
if ($context eq 'domain') {
my $uhome = &Apache::lonnet::homeserver($uname,$udom);
if ($uhome ne 'no_host') {
- if (($changeauth) && (&Apache::lonnet::allowed('mau',$udom))) {
+ if (($changeauth eq 'Yes') && (&Apache::lonnet::allowed('mau',$udom))) {
if ((($umode =~ /^krb4|krb5|internal$/) && $upass ne '') ||
($umode eq 'localauth')) {
$authresult = &Apache::lonnet::modifyuserauth($udom,$uname,$umode,$upass);
}
}
+ if (($forceid) && (&Apache::lonnet::allowed('mau',$udom)) &&
+ ($env{'form.recurseid'}) && ($checkid)) {
+ my %userupdate = (
+ lastname => $last,
+ middlename => $middle,
+ firstname => $first,
+ generation => $gene,
+ id => $uid,
+ );
+ $idresult = &propagate_id_change($uname,$udom,\%userupdate);
+ }
}
}
$userresult =
@@ -114,42 +126,136 @@ sub modifyuserrole {
$middle,$last,$gene,$forceid,$desiredhome,
$email,$role,$start,$end);
if ($userresult eq 'ok') {
- if ($role ne '') {
+ if ($role ne '') {
+ $role =~ s/_/\//g;
$roleresult = &Apache::lonnet::assignrole($udom,$uname,$scope,
$role,$end,$start);
}
}
- return ($userresult,$authresult,$roleresult);
+ return ($userresult,$authresult,$roleresult,$idresult);
+}
+
+sub propagate_id_change {
+ my ($uname,$udom,$user) = @_;
+ my (@types,@roles);
+ @types = ('active','future');
+ @roles = ('st');
+ my $idresult;
+ my %roleshash = &Apache::lonnet::get_my_roles($uname,
+ $udom,'userroles',\@types,\@roles);
+ my %args = (
+ one_time => 1,
+ );
+ foreach my $item (keys(%roleshash)) {
+ 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);
+ my %coursehash =
+ &Apache::lonnet::coursedescription($cdom.'_'.$cnum,\%args);
+ my $cdesc = $coursehash{'description'};
+ if ($cdesc eq '') {
+ $cdesc = $cdom.'_'.$cnum;
+ }
+ if ($result eq 'ok') {
+ $idresult .= &mt('Classlist update for "[_1]" in "[_2]".',$uname.':'.$udom,$cdesc).' \n");
if ($env{'form.action'} ne 'modifystudent') {
@@ -1066,71 +1259,548 @@ sub print_html_classlist {
$output_selector .= '';
$r->print('
'."\n";
+ } else {
+ $idresult .= &mt('Error: "[_1]" during classlist update for "[_2]" in "[_3]".',$result,$uname.':'.$udom,$cdesc).'
'."\n";
+ }
+ }
+ }
+ return $idresult;
+}
+
+sub update_classlist {
+ my ($cdom,$cnum,$udom,$uname,$user) = @_;
+ my ($uid,$classlistentry);
+ my $fullname =
+ &Apache::lonnet::format_name($user->{'firstname'},$user->{'middlename'},
+ $user->{'lastname'},$user->{'generation'},
+ 'lastname');
+ my %classhash = &Apache::lonnet::get('classlist',[$uname.':'.$udom],
+ $cdom,$cnum);
+ my @classinfo = split(/:/,$classhash{$uname.':'.$udom});
+ my $ididx=&Apache::loncoursedata::CL_ID() - 2;
+ my $nameidx=&Apache::loncoursedata::CL_FULLNAME() - 2;
+ for (my $i=0; $i<@classinfo; $i++) {
+ if ($i == $ididx) {
+ if (defined($user->{'id'})) {
+ $classlistentry .= $user->{'id'}.':';
+ } else {
+ $classlistentry .= $classinfo[$i].':';
+ }
+ } elsif ($i == $nameidx) {
+ $classlistentry .= $fullname.':';
+ } else {
+ $classlistentry .= $classinfo[$i].':';
+ }
+ }
+ $classlistentry =~ s/:$//;
+ my $reply=&Apache::lonnet::cput('classlist',
+ {"$uname:$udom" => $classlistentry},
+ $cdom,$cnum);
+ if (($reply eq 'ok') || ($reply eq 'delayed')) {
+ return 'ok';
+ } else {
+ return 'error: '.$reply;
+ }
}
+
###############################################################
###############################################################
-# build a domain and server selection form
-sub domain_form {
- my ($defdom) = @_;
- # Set up domain and server selection forms
+# build a role type and role selection form
+sub domain_roles_select {
+ # Set up the role type and role selection boxes when in
+ # domain context
+ #
+ # Role types
+ my @roletypes = ('domain','author','course');
+ my %lt = &role_type_names();
#
- # Get the domains
- my @domains = &Apache::lonnet::all_domains();
# build up the menu information to be passed to
# &Apache::loncommon::linked_select_forms
my %select_menus;
- foreach my $dom (@domains) {
+ if ($env{'form.roletype'} eq '') {
+ $env{'form.roletype'} = 'domain';
+ }
+ foreach my $roletype (@roletypes) {
# set up the text for this domain
- $select_menus{$dom}->{'text'}= $dom;
+ $select_menus{$roletype}->{'text'}= $lt{$roletype};
# we want a choice of 'default' as the default in the second menu
- $select_menus{$dom}->{'default'}= 'default';
- $select_menus{$dom}->{'select2'}->{'default'} = 'default';
+ if ($env{'form.roletype'} ne '') {
+ $select_menus{$roletype}->{'default'} = $env{'form.showrole'};
+ } else {
+ $select_menus{$roletype}->{'default'} = 'Any';
+ }
# Now build up the other items in the second menu
- my %servers = &Apache::lonnet::get_servers($dom,'library');
- foreach my $server (keys(%servers)) {
- $select_menus{$dom}->{'select2'}->{$server}
- = "$server $servers{$server}";
+ my @roles;
+ if ($roletype eq 'domain') {
+ @roles = &domain_roles();
+ } elsif ($roletype eq 'author') {
+ @roles = &construction_space_roles();
+ } else {
+ my $custom = 1;
+ @roles = &course_roles('domain',undef,$custom);
}
+ my $order = ['Any',@roles];
+ $select_menus{$roletype}->{'order'} = $order;
+ foreach my $role (@roles) {
+ if ($role eq 'cr') {
+ $select_menus{$roletype}->{'select2'}->{$role} =
+ &mt('Custom role');
+ } else {
+ $select_menus{$roletype}->{'select2'}->{$role} =
+ &Apache::lonnet::plaintext($role);
+ }
+ }
+ $select_menus{$roletype}->{'select2'}->{'Any'} = &mt('Any');
}
- my $result = &Apache::loncommon::linked_select_forms
- ('studentform',' with home server ',$defdom,
- 'lcdomain','lcserver',\%select_menus);
+ my $result = &Apache::loncommon::linked_select_forms
+ ('studentform',(' 'x3).&mt('Role: '),$env{'form.roletype'},
+ 'roletype','showrole',\%select_menus,['domain','author','course']);
return $result;
}
@@ -161,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'})) {
@@ -191,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).
"
\n");
@@ -220,27 +331,52 @@ 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.',
authen => 'You must choose an authentication type.',
@@ -254,8 +390,9 @@ sub javascript_validations {
continue => 'Continue adding users?',
);
-# my $pjump_def = &Apache::lonhtmlcommon::pjump_javascript_definition();
my $function_name =(<'.&mt('Settings for assigning roles:').'
'."\n".
&mt('Pick the action to take on roles for these users:').'
';
}
- if ($context eq 'construction_space') {
+ if ($context eq 'author') {
$Str .= ''.&mt('Default role')."
\n".
- &mt('Choose the role to assign to users without one specified in the uploaded file');
+ &mt('Choose the role to assign to users without a value specified in the uploaded file');
} elsif ($context eq 'course') {
$Str .= ''.&mt('Default role and section')."
\n".
- &mt('Choose the role and/or section to assign to users without one specified in the uploaded file');
+ &mt('Choose the role and/or section(s) to assign to users without values specified in the uploaded file');
} else {
- $Str .= '
'.&mt('Default role and/or section')."
\n".
- &mt('Role and/or section for users without one in the uploaded file.');
+ $Str .= '
'.&mt('Default role and/or section(s)')."
\n".
+ &mt('Role and/or section(s) for users without values specified in the uploaded file.');
}
- $Str .= '
';
- my ($options,$cb_script,$coursepick) = &default_role_selector($context);
- if ($context eq 'domain') {
- $Str .= ''.&mt('Domain Level').'
'.$options.'
'.&mt('Course Level').'
'.$cb_script.$coursepick;
+ $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 .= $options;
- }
- if ($context eq 'course') {
- $Str .= "".&mt('Full Update')."
\n".
- '
';
+ my $result = &Apache::lonhtmlcommon::start_pick_box()."\n";
+ $result .= &Apache::lonhtmlcommon::row_title(&mt('Starting Date'),
+ 'LC_oddrow_value')."\n".
+ $startform."\n".
+ &Apache::lonhtmlcommon::row_closure(1).
+ &Apache::lonhtmlcommon::row_title(&mt('Ending Date'),
+ 'LC_oddrow_value')."\n".
+ $endform.' '.$perpetual.
+ &Apache::lonhtmlcommon::row_closure(1).
+ &Apache::lonhtmlcommon::end_pick_box();
if ($dateDefault) {
$result .= $dateDefault.'
'."\n";
}
@@ -827,19 +997,19 @@ 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 .= "Set default start and end dates for course
";
+ $result .= &mt('Set default start and end access dates for course.').
+ '
'."\n";
#
# Refresh the course environment
&Apache::lonnet::coursedescription($env{'request.course.id'},
{'freshen_cache' => 1});
} else {
- $result .= &mt('Unable to set default dates for course').":".$put_result.
+ $result .= &mt('Unable to set default access dates for course.').":".$put_result.
'
';
}
}
@@ -847,10 +1017,10 @@ sub make_dates_default {
}
sub default_role_selector {
- my ($context) = @_;
+ my ($context,$checkpriv) = @_;
my %customroles;
my ($options,$coursepick,$cb_jscript);
- if ($context ne 'construction_space') {
+ if ($context ne 'author') {
%customroles = &my_custom_roles();
}
@@ -863,112 +1033,134 @@ sub default_role_selector {
$options = '';
return ($options,$cb_jscript,$coursepick);
}
sub default_course_roles {
- my ($context,%customroles) = @_;
+ my ($context,$checkpriv,%customroles) = @_;
my $output;
- my @roles = &course_roles($context);
+ 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) {
- 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;
}
sub construction_space_roles {
- my @allroles = ('ca','aa');
+ my ($checkpriv) = @_;
+ my @allroles = &roles_by_context('author');
my @roles;
- foreach my $role (@allroles) {
- if (&Apache::lonnet::allowed('c'.$role,$env{'user.domain'}.'/'.$env{'user.name'})) {
- push(@roles,$role);
+ if ($checkpriv) {
+ foreach my $role (@allroles) {
+ if (&Apache::lonnet::allowed('c'.$role,$env{'user.domain'}.'/'.$env{'user.name'})) {
+ push(@roles,$role);
+ }
}
+ return @roles;
+ } else {
+ return @allroles;
}
- return @roles;
}
sub domain_roles {
- my @allroles = ('dc','li','dg','au','sc');
+ my ($checkpriv) = @_;
+ my @allroles = &roles_by_context('domain');
my @roles;
- foreach my $role (@allroles) {
- if (&Apache::lonnet::allowed('c'.$role,$env{'request.role.domain'})) {
- push(@roles,$role);
+ if ($checkpriv) {
+ foreach my $role (@allroles) {
+ if (&Apache::lonnet::allowed('c'.$role,$env{'request.role.domain'})) {
+ push(@roles,$role);
+ }
}
+ return @roles;
+ } else {
+ return @allroles;
}
- return @roles;
}
sub course_roles {
- my ($context) = @_;
- 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;
} elsif ($context eq 'course') {
if ($env{'request.course.id'}) {
- foreach my $role (@allroles) {
- 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,
- $env{'request.course.id'}.'/'.
- $env{'request.course.section'})) {
- push(@roles,$role);
+ if ($checkpriv) {
+ foreach my $role (@allroles) {
+ if (&Apache::lonnet::allowed('c'.$role,$env{'request.course.id'})) {
+ push(@roles,$role);
+ } else {
+ if ($role ne 'cc' && $env{'request.course.sec'} ne '') {
+ if (&Apache::lonnet::allowed('c'.$role,
+ $env{'request.course.id'}.'/'.
+ $env{'request.course.sec'})) {
+ push(@roles,$role);
+ }
}
}
}
+ } else {
+ @roles = @allroles;
}
}
}
@@ -976,18 +1168,19 @@ sub course_roles {
}
sub curr_role_permissions {
- my ($context,$setting) = @_;
+ my ($context,$setting,$checkpriv) = @_;
+ my $custom = 1;
my @roles;
- if ($context eq 'construction_space') {
- @roles = &construction_space_roles();
+ if ($context eq 'author') {
+ @roles = &construction_space_roles($checkpriv);
} elsif ($context eq 'domain') {
if ($setting eq 'course') {
- @roles = &course_roles($context);
+ @roles = &course_roles($context,$checkpriv,$custom);
} else {
- @roles = &domain_roles();
+ @roles = &domain_roles($checkpriv);
}
} elsif ($context eq 'course') {
- @roles = &course_roles($context);
+ @roles = &course_roles($context,$checkpriv,$custom);
}
return @roles;
}
@@ -1005,49 +1198,49 @@ sub my_custom_roles {
return %returnhash;
}
-sub print_html_classlist {
- my ($r,$mode,$permission,$context) = @_;
+sub print_userlist {
+ my ($r,$mode,$permission,$context,$formname,$totcodes,$codetitles,
+ $idlist,$idlist_titles) = @_;
+ my $format = $env{'form.output'};
if (! exists($env{'form.sortby'})) {
$env{'form.sortby'} = 'username';
}
- if ($env{'form.status'} !~ /^(Any|Expired|Active|Future)$/) {
- $env{'form.status'} = 'Active';
+ if ($env{'form.Status'} !~ /^(Any|Expired|Active|Future)$/) {
+ $env{'form.Status'} = 'Active';
}
my $status_select = &Apache::lonhtmlcommon::StatusOptions
- ($env{'form.status'});
+ ($env{'form.Status'});
+ if ($env{'form.showrole'} eq '') {
+ if ($context eq 'course') {
+ $env{'form.showrole'} = 'st';
+ } else {
+ $env{'form.showrole'} = 'Any';
+ }
+ }
if (! defined($env{'form.output'}) ||
$env{'form.output'} !~ /^(csv|excel|html)$/ ) {
$env{'form.output'} = 'html';
}
- if ($context eq 'course') {
- my $cid =$env{'request.course.id'};
- my $cdom=$env{'course.'.$cid.'.domain'};
- my $cnum=$env{'course.'.$cid.'.num'};
- #
- # List course personnel
- my %coursepersonnel=&Apache::lonnet::get_course_adv_roles($cdom.'/'.$cnum);
- #
-
- $r->print('
'.&Apache::loncommon::start_data_table());
- foreach my $role (sort keys %coursepersonnel) {
- next if ($role =~ /^\s*$/);
- $r->print(&Apache::loncommon::start_data_table_row().
- ''.$role.' ');
- foreach my $user (split(',',$coursepersonnel{$role})) {
- my ($puname,$pudom)=split(':',$user);
- $r->print(' '.&Apache::loncommon::aboutmewrapper(
- &Apache::loncommon::plainname($puname,$pudom),
- $puname,$pudom));
- }
- $r->print(' '.&Apache::loncommon::end_data_table_row());
- }
- $r->print(&Apache::loncommon::end_data_table());
+ my @statuses;
+ if ($env{'form.Status'} eq 'Any') {
+ @statuses = ('previous','active','future');
+ } elsif ($env{'form.Status'} eq 'Expired') {
+ @statuses = ('previous');
+ } elsif ($env{'form.Status'} eq 'Active') {
+ @statuses = ('active');
+ } elsif ($env{'form.Status'} eq 'Future') {
+ @statuses = ('future');
}
+
+# if ($context eq 'course') {
+# $r->print(&display_adv_courseroles());
+# }
#
# Interface output
- $r->print(''."\n".
+ '');
$r->print("
'.&Apache::lonhtmlcommon::start_pick_box()."\n". + &Apache::lonhtmlcommon::start_pick_box()."\n". + &Apache::lonhtmlcommon::row_title(&mt('Select Course(s)'), + 'LC_oddrow_value')."\n". + $courseform."\n". + &Apache::lonhtmlcommon::row_closure(1). + &Apache::lonhtmlcommon::end_pick_box().'
'. + ''.&list_submit_button(&mt('Update Display')). + "\n
\n"); + if ($env{'form.coursepick'}) { + $r->print('\n". + $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 .= '
';
+ } else {
+ $output .= &mt("Click on a username to view the user's personal page.").'
';
+ }
+ if ($actionselect) {
+ $output .= <<"END";
+$lt{'ac'}: $actionselect
+ +END + my @allroles; + if ($env{'form.showrole'} eq 'Any') { + my $custom = 1; + if ($context eq 'domain') { + @allroles = &roles_by_context($setting,$custom); + } else { + @allroles = &roles_by_context($context,$custom); + } + } else { + @allroles = ($env{'form.showrole'}); + } + foreach my $role (@allroles) { + if ($context eq 'domain') { + if ($setting eq 'domain') { + if (&Apache::lonnet::allowed('c'.$role, + $env{'request.role.domain'})) { + $canchange{$role} = 1; + } + } elsif ($setting eq 'author') { + if (&Apache::lonnet::allowed('c'.$role, + $env{'request.role.domain'})) { + $canchange{$role} = 1; + } + } + } elsif ($context eq 'author') { + if (&Apache::lonnet::allowed('c'.$role, + $env{'user.domain'}.'/'.$env{'user.name'})) { + $canchange{$role} = 1; + } + } elsif ($context eq 'course') { + if (&Apache::lonnet::allowed('c'.$role,$env{'request.course.id'})) { + $canchange{$role} = 1; + } elsif ($env{'request.course.sec'} ne '') { + if (&Apache::lonnet::allowed('c'.$role,$env{'request.course.id'}.'/'.$env{'request.course.sec'})) { + $canchangesec{$role} = $env{'request.course.sec'}; + } + } + } + } + } + } + $output .= "\n
\n". &Apache::loncommon::start_data_table(). - &Apache::loncommon::start_data_table_header_row()); + &Apache::loncommon::start_data_table_header_row(); if ($mode eq 'autoenroll') { - $r->print(" + $output .= "
'.&mt('manual').' | |
- - -
+ if ($mode eq 'view' || $mode eq 'html' || $mode eq 'autoenroll') { + $r->print(&Apache::loncommon::end_data_table().''. + &mt('Your Excel spreadsheet').' '.&mt('is ready for download').'.
'."\n"); + } elsif ($mode eq 'csv') { + close($CSVfile); + $r->print(''. + &mt('Your CSV file').' is ready for download.'. + "\n"); + $r->rflush(); + } + if ($mode eq 'autoenroll') { + return ($usercount,$autocount,$manualcount,$lockcount,$unlockcount); + } else { + return ($usercount); + } +} + +sub print_username_link { + my ($mode,$permission,$in) = @_; + my $output; + if ($mode eq 'autoenroll') { + $output = $in->{'username'}; + } elsif (!$permission->{'cusr'}) { + $output = &Apache::loncommon::aboutmewrapper($in->{'username'}, + $in->{'username'}, + $in->{'domain'}); + } else { + $output = '{'username'}','$in->{'domain'}'".')" />'. + $in->{'username'}.''; + } + return $output; +} + +sub role_type_names { + my %lt = &Apache::lonlocal::texthash ( + 'domain' => 'Domain Roles', + 'author' => 'Co-Author Roles', + 'course' => 'Course Roles', + ); + return %lt; +} + +sub select_actions { + my ($context,$setting,$statusmode) = @_; + my %lt = &Apache::lonlocal::texthash( + revoke => "Revoke user roles", + delete => "Delete user roles", + reenable => "Re-enable expired user roles", + activate => "Make future user roles active now", + chgdates => "Change starting/ending dates", + 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 ($context eq 'course') { + if ($env{'form.showrole'} ne 'Any') { + if (!&Apache::lonnet::allowed('c'.$env{'form.showrole'}, + $env{'request.course.id'})) { + if ($env{'request.course.sec'} eq '') { + return; + } else { + if (!&Apache::lonnet::allowed('c'.$env{'form.showrole'},$env{'request.course.id'}.'/'.$env{'request.course.sec'})) { + return; + } + } + } + } + } + if ($statusmode eq 'Any') { + $options .= ' +'; + $choices{'dates'} = 1; + } else { + if ($statusmode eq 'Future') { + $options .= ' +'; + $choices{'dates'} = 1; + } elsif ($statusmode eq 'Expired') { + $options .= ' +'; + $choices{'dates'} = 1; + } + if ($statusmode eq 'Active' || $statusmode eq 'Future') { + $options .= ' + +'; + $choices{'dates'} = 1; + } + } + if ($context eq 'domain') { + $options .= ' +'; + } + if (($context eq 'course') || ($context eq 'domain' && $setting eq 'course')) { + if (($statusmode ne 'Expired') && ($env{'request.course.sec'} eq '')) { + $options .= ' +'; + $choices{'sections'} = 1; + } + } + if ($options) { + $output = ''.&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". + ' |
END
-
-my %lt=&Apache::lonlocal::texthash('usrn' => "username",
- 'dom' => "domain",
- 'sn' => "student name",
- 'sec' => "section",
- 'start' => "start date",
- 'end' => "end date",
- 'groups' => "active groups",
- );
+ my ($indexhash,$keylist) = &make_keylist_array();
+ my $studentcount = 0;
+ if (ref($classlist) eq 'HASH') {
+ foreach my $student (keys(%{$classlist})) {
+ my $sdata = $classlist->{$student};
+ my $status = $sdata->[$indexhash->{'status'}];
+ my $section = $sdata->[$indexhash->{'section'}];
+ if ($status ne 'Active') {
+ delete($classlist->{$student});
+ next;
+ }
+ if ($env{'request.course.sec'} ne '') {
+ if ($section ne $env{'request.course.sec'}) {
+ delete($classlist->{$student});
+ next;
+ }
+ }
+ $studentcount ++;
+ }
+ }
+ if (!$studentcount) {
+ $r->print(&mt('There are no students to drop.'));
+ return;
+ }
+ my ($classgroups) = &Apache::loncoursedata::get_group_memberships(
+ $classlist,$keylist,$cdom,$cnum);
+ my %lt=&Apache::lonlocal::texthash('usrn' => "username",
+ 'dom' => "domain",
+ 'sn' => "student name",
+ 'sec' => "section",
+ 'start' => "start date",
+ 'end' => "end date",
+ '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(< \n";
$str .= ''."\n";
+ &mt('Upload file of users').'">'."\n";
$str .= '
$lt{'usrn'}
$lt{'dom'}
@@ -1459,61 +2916,55 @@ 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
- my %index;
- my $i;
- foreach (@$keylist) {
- $index{$_} = $i++;
- }
- $index{'groups'} = scalar(@$keylist);
- my $index = $index{$sortby};
- my $second = $index{'username'};
- my $third = $index{'domain'};
+ my $index = $indexhash->{$sortby};
+ my $second = $indexhash->{'username'};
+ my $third = $indexhash->{'domain'};
my @Sorted_Students = sort {
lc($classlist->{$a}->[$index]) cmp lc($classlist->{$b}->[$index])
||
lc($classlist->{$a}->[$second]) cmp lc($classlist->{$b}->[$second])
||
lc($classlist->{$a}->[$third]) cmp lc($classlist->{$b}->[$third])
- } (keys(%$classlist));
+ } (keys(%{$classlist}));
foreach my $student (@Sorted_Students) {
my $error;
my $sdata = $classlist->{$student};
- my $username = $sdata->[$index{'username'}];
- my $domain = $sdata->[$index{'domain'}];
- my $section = $sdata->[$index{'section'}];
- my $name = $sdata->[$index{'fullname'}];
- my $id = $sdata->[$index{'id'}];
- my $start = $sdata->[$index{'start'}];
- my $end = $sdata->[$index{'end'}];
+ my $username = $sdata->[$indexhash->{'username'}];
+ my $domain = $sdata->[$indexhash->{'domain'}];
+ my $section = $sdata->[$indexhash->{'section'}];
+ my $name = $sdata->[$indexhash->{'fullname'}];
+ my $id = $sdata->[$indexhash->{'id'}];
+ my $start = $sdata->[$indexhash->{'start'}];
+ my $end = $sdata->[$indexhash->{'end'}];
my $groups = $classgroups->{$student};
my $active_groups;
if (ref($groups->{active}) eq 'HASH') {
@@ -1529,18 +2980,18 @@ END
} else {
$end = &Apache::lonlocal::locallocaltime($end);
}
- my $status = $sdata->[$index{'status'}];
- next if ($status ne 'Active');
+ my $studentkey = $student.':'.$section;
+ my $startitem = '';
#
$r->print(&Apache::loncommon::start_data_table_row());
$r->print(<<"END");
-
+
$username
$domain
$id
$name
$section
- $start
+ $start $startitem
$end
$active_groups
END
@@ -1548,7 +2999,7 @@ END
}
$r->print(&Apache::loncommon::end_data_table().'
');
%lt=&Apache::lonlocal::texthash(
- 'dp' => "Expire Users' Roles",
+ 'dp' => "Drop Students",
'ca' => "check all",
'ua' => "uncheck all",
);
@@ -1561,8 +3012,6 @@ END
return;
}
-
-
#
# Print out the initial form to get the file containing a list of users
#
@@ -1572,11 +3021,11 @@ sub print_first_users_upload_form {
$str = '';
$str .= '';
$str .= '';
- $str .= "".&mt('Upload a list of users')."
\n";
+ $str .= "".&mt('Upload a file containing information about users')."
\n";
$str .= &Apache::loncommon::upfile_select_html();
$str .= "
'.&mt('No roles added').'
'); } if ($counts{'auth'} > 0) { $r->print("\n". &mt('Authentication changed for [_1] existing users.', $counts{'auth'})."
\n"); } - $r->print(''); + $r->print(&print_namespacing_alerts($domain,\%alerts,\%curr_rules)); ##################################### - # Drop students # + # Display list of students to drop # ##################################### if ($env{'form.fullup'} eq 'yes') { - $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.
')); + } + # Flush the course logs so reverse user roles immediately updated + &Apache::lonnet::flushcourselogs(); + } + if ($env{'form.makedatesdefault'}) { + if ($choice eq 'chgdates' || $choice eq 'reenable' || $choice eq 'activate') { + $r->print(&make_dates_default($startdate,$enddate,$context)); } } - $r->print(''.&mt('Dropped [_1] user(s).',$count).'
'); - $r->print(''.&mt('Re-enrollment will re-activate data.')) if ($count);
}
-sub section_check_js {
- my $groupslist;
- my %curr_groups = &Apache::longroup::coursegroups();
- if (%curr_groups) {
- $groupslist = join('","',sort(keys(%curr_groups)));
+sub classlist_drop {
+ my ($scope,$uname,$udom,$now) = @_;
+ my ($cdom,$cnum) = ($scope=~m{^/($match_domain)/($match_courseid)});
+ if (&Apache::lonnet::is_course($cdom,$cnum)) {
+ my $user = $uname.':'.$udom;
+ if (!&active_student_roles($cnum,$cdom,$uname,$udom)) {
+ my $result =
+ &Apache::lonnet::cput('classlist',
+ { $user => $now },$cdom,$cnum);
+ return &mt('Drop from classlist: [_1]',
+ ''.$result.'').'
';
+ }
}
+}
+
+sub active_student_roles {
+ my ($cnum,$cdom,$uname,$udom) = @_;
+ my %roles =
+ &Apache::lonnet::get_my_roles($uname,$udom,'userroles',
+ ['future','active'],['st']);
+ return exists($roles{"$cnum:$cdom:st"});
+}
+
+sub section_check_js {
+ my $groupslist= &get_groupslist();
return <<"END";
function validate(caller) {
- var groups = new Array("$groupslist");
+ var groups = new Array($groupslist);
var secname = caller.value;
if ((secname == 'all') || (secname == 'none')) {
alert("'"+secname+"' may not be used as the name for a section, as it is a reserved word.\\nPlease choose a different section name.");
@@ -2052,5 +3977,535 @@ sub set_login {
return $response;
}
+sub course_sections {
+ my ($sections_count,$role) = @_;
+ my $output = '';
+ my @sections = (sort {$a <=> $b} keys %{$sections_count});
+ my $numsec = scalar(@sections);
+ if ($numsec <= 1) {
+ $output = '