--- loncom/interface/lonuserutils.pm 2007/12/21 17:27:57 1.20
+++ loncom/interface/lonuserutils.pm 2007/12/24 05:26:31 1.33
@@ -1,7 +1,7 @@
# The LearningOnline Network with CAPA
# Utility functions for managing LON-CAPA user accounts
#
-# $Id: lonuserutils.pm,v 1.20 2007/12/21 17:27:57 raeburn Exp $
+# $Id: lonuserutils.pm,v 1.33 2007/12/24 05:26:31 raeburn Exp $
#
# Copyright Michigan State University Board of Trustees
#
@@ -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.':';
}
}
@@ -126,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);
}
@@ -145,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);
@@ -265,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'})) {
@@ -295,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,
+ $groupslist);
my $checked=(($env{'form.noFirstLine'})?' checked="checked" ':'');
$r->print(&mt('Total number of records found in file: [_1].',$distotal).
"
\n");
@@ -324,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,$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.',
@@ -358,8 +390,9 @@ sub javascript_validations {
continue => 'Continue adding users?',
);
-# my $pjump_def = &Apache::lonhtmlcommon::pjump_javascript_definition();
my $function_name =(<'.&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,'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";
}
+ $output .= '';
return $output;
}
###############################################################
###############################################################
sub print_upload_manager_form {
- my ($r,$context) = @_;
+ my ($r,$context,$permission) = @_;
my $firstLine;
my $datatoken;
if (!$env{'form.datatoken'}) {
@@ -815,7 +844,8 @@ sub print_upload_manager_form {
my ($krbdef,$krbdefdom) =
&Apache::loncommon::get_kerberos_defaults($defdom);
#
- &print_upload_manager_header($r,$datatoken,$distotal,$krbdefdom,$context);
+ &print_upload_manager_header($r,$datatoken,$distotal,$krbdefdom,$context,
+ $permission);
my $i;
my $keyfields;
if ($total>=0) {
@@ -849,11 +879,14 @@ sub print_upload_manager_form {
}
$r->print('
'."\n";
}
@@ -966,14 +1002,14 @@ sub make_dates_default {
{'default_enrollment_start_date'=>$startdate,
'default_enrollment_end_date' =>$enddate},$cdom,$cnum);
if ($put_result eq 'ok') {
- $result .= &mt('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.
'
';
}
}
@@ -1011,33 +1047,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);
@@ -1049,15 +1088,18 @@ sub default_course_roles {
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;
@@ -1108,10 +1150,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);
}
}
@@ -1222,7 +1264,7 @@ sub print_userlist {
if ($env{'form.showrole'} eq 'Any') {
$roleselected = ' selected="selected" ';
}
- my $role_select;
+ my ($role_select,$cnum,$cdom);
if ($context eq 'domain') {
$role_select = &domain_roles_select();
$r->print(''.
'
'.
- $lt{'exs'}.' '.
' '.
''.$lt{'new'}.' '.
- '
'.
''.
- '
\n". @@ -2060,6 +2221,17 @@ END $index{$idx} = $i++; } my $usercount = 0; + my ($secfilter,$grpfilter); + if ($context eq 'course') { + $secfilter = $env{'form.secfilter'}; + $grpfilter = $env{'form.grpfilter'}; + if ($secfilter eq '') { + $secfilter = 'all'; + } + if ($grpfilter eq '') { + $grpfilter = 'all'; + } + } # Get groups, role, permanent e-mail so we can sort on them if # necessary. foreach my $user (keys(%{$userlist})) { @@ -2097,11 +2269,40 @@ END delete($userlist->{$user}); next; } - if (ref($classgroups) eq 'HASH') { - $groups = $classgroups->{$user}; - } - if (ref($groups->{active}) eq 'HASH') { - $userlist->{$user}->[$index{'groups'}] = join(', ',keys(%{$groups->{'active'}})); + if ($context eq 'course') { + my @ac_groups; + if (ref($classgroups) eq 'HASH') { + $groups = $classgroups->{$user}; + } + if (ref($groups->{'active'}) eq 'HASH') { + @ac_groups = keys(%{$groups->{'active'}}); + $userlist->{$user}->[$index{'groups'}] = join(', ',@ac_groups); + } + if ($mode ne 'autoenroll') { + my $section = $userlist->{$user}->[$index{'section'}]; + if ($secfilter eq 'none') { + if ($section ne '') { + delete($userlist->{$user}); + next; + } + } elsif ($secfilter ne 'all') { + if ($section ne $secfilter) { + delete($userlist->{$user}); + next; + } + } + if ($grpfilter eq 'none') { + if (@ac_groups > 0) { + delete($userlist->{$user}); + next; + } + } elsif ($grpfilter ne 'all') { + if (!grep(/^\Q$grpfilter\E$/,@ac_groups)) { + delete($userlist->{$user}); + next; + } + } + } } my %emails = &Apache::loncommon::getemails($uname,$udom); if ($emails{'permanentemail'} =~ /\S/) { @@ -2178,18 +2379,38 @@ END $r->print("
'.&mt("$result_text{'ok'}{$choice} role(s) for [quant,_1,user,users,users].",$count).'
'); + $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.
')); @@ -3566,23 +4043,25 @@ sub update_user_list { } if ($env{'form.makedatesdefault'}) { if ($choice eq 'chgdates' || $choice eq 'reenable' || $choice eq 'activate') { - $r->print(&make_dates_default($startdate,$enddate)); + $r->print(&make_dates_default($startdate,$enddate,$context)); } } + my $linktext = &mt('Display User Lists'); + if ($choice eq 'drop') { + $linktext = &mt('Display current class roster'); + } + $r->print(''.$linktext.'