--- loncom/interface/lonuserutils.pm 2007/12/22 00:47:25 1.23
+++ loncom/interface/lonuserutils.pm 2008/01/07 03:00:00 1.47
@@ -1,7 +1,7 @@
# The LearningOnline Network with CAPA
# Utility functions for managing LON-CAPA user accounts
#
-# $Id: lonuserutils.pm,v 1.23 2007/12/22 00:47:25 raeburn Exp $
+# $Id: lonuserutils.pm,v 1.47 2008/01/07 03:00:00 raeburn Exp $
#
# Copyright Michigan State University Board of Trustees
#
@@ -76,7 +76,7 @@ sub modifystudent {
}
}
if ($result eq '') {
- $result = 'Unable to find section for this student';
+ $result = &mt('Unable to find section for this student');
} else {
$result =~ s/(ok:)+/ok/g;
}
@@ -304,7 +304,7 @@ sub print_upload_manager_header {
my $javascript_validations =
&javascript_validations('upload',$krbdefdom,$password_choice,undef,
$env{'request.role.domain'},$context,
- $permission,$groupslist);
+ $groupslist);
my $checked=(($env{'form.noFirstLine'})?' checked="checked" ':'');
$r->print(&mt('Total number of records found in file: [_1].',$distotal).
" \n");
@@ -332,18 +332,13 @@ sub print_upload_manager_header {
###############################################################
sub javascript_validations {
my ($mode,$krbdefdom,$curr_authtype,$curr_authfield,$domain,
- $context,$permission,$groupslist)=@_;
-
+ $context,$groupslist)=@_;
my %param = (
kerb_def_dom => $krbdefdom,
curr_authtype => $curr_authtype,
);
- if ($mode eq 'createuser') {
- $param{'formname'} = 'cu';
- } elsif ($mode eq 'upload') {
+ if ($mode eq 'upload') {
$param{'formname'} = 'studentform';
- } elsif ($mode eq 'singlestudent') {
- $param{'formname'} = 'cu';
} elsif ($mode eq 'createcourse') {
$param{'formname'} = 'ccrs';
} elsif ($mode eq 'modifycourse') {
@@ -367,7 +362,7 @@ sub javascript_validations {
}
} elsif ($context eq 'domain') {
$setsection_call = 'setCourse()';
- $setsections_js = &dc_setcourse_js($param{'formname'},$mode);
+ $setsections_js = &dc_setcourse_js($param{'formname'},$mode,$context);
}
$finish = " var checkSec = $setsection_call\n".
" if (checkSec == 'ok') {\n".
@@ -389,8 +384,7 @@ sub javascript_validations {
role => 'The optional role field was not specified.',
continue => 'Continue adding users?',
);
-
- my $function_name =(<\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 .= ' ';
if (($context eq 'domain') || ($context eq 'author')) {
@@ -761,8 +749,7 @@ sub print_upload_manager_footer {
$permission,$context,'upload');
$Str .= $secbox."
".&mt('Full Update')."
\n".
'\n";
+ ' '.&mt('Display students with current/future access who are not in the uploaded file.').' '.&mt('Students selected from this list can be dropped.').'
\n".' '."\n".
- &mt('(only do if you know what you are doing.)')." \n";
+ &mt('(only do if you know what you are doing.)')."\n";
if ($context eq 'domain') {
- $output .= '
'."\n";
+ ''."\n";
}
+ $output .= '';
return $output;
}
@@ -962,7 +950,7 @@ sub date_setting_table {
($env{'form.action'} eq 'upload')) {
if ($env{'request.course.sec'} eq '') {
$dateDefault = ''.
- '';
}
@@ -1001,14 +989,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.
' ';
}
}
@@ -1263,7 +1251,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(''.&mt('Role Type: [_1]',$role_select).'');
@@ -1287,9 +1275,14 @@ sub print_userlist {
}
$role_select .= '';
$r->print(''.&mt('Role: [_1]',$role_select).'');
+ if ($context eq 'course') {
+ ($cnum,$cdom) = &get_course_identity();
+ $r->print(§ion_group_filter($cnum,$cdom));
+ }
}
if (!(($context eq 'domain') && ($env{'form.roletype'} eq 'course'))) {
- $r->print(&list_submit_button(&mt('Update Display'))."\n\n");
+ $r->print(' '.&list_submit_button(&mt('Update Display')).
+ "\n\n");
}
my ($indexhash,$keylist) = &make_keylist_array();
my (%userlist,%userinfo);
@@ -1305,7 +1298,7 @@ sub print_userlist {
&Apache::lonhtmlcommon::row_closure(1).
&Apache::lonhtmlcommon::end_pick_box().''.
'
\n");
+ "\n".''.&mt('Warning: data retrieval for multiple courses can take considerable time, as this operation is not currently optimized.').''."\n");
if ($env{'form.coursepick'}) {
$r->print(''.&mt('Searching').' ...
');
}
@@ -1314,34 +1307,24 @@ sub print_userlist {
}
$r->rflush();
if ($context eq 'course') {
- my $classlist = &Apache::loncoursedata::get_classlist();
- my $secidx = &Apache::loncoursedata::CL_SECTION();
- my $viewablesec = &viewable_section($permission);
- foreach my $student (keys(%{$classlist})) {
- my $section = $classlist->{$student}[$secidx];
- if ($viewablesec ne '') {
- if ($section ne $viewablesec) {
- next;
- } else {
- $userlist{$student} = $classlist->{$student};
- }
+ if (($env{'form.showrole'} eq 'st') || ($env{'form.showrole'} eq 'Any')) {
+ my $classlist = &Apache::loncoursedata::get_classlist();
+ %userlist = %{$classlist};
+ }
+ if ($env{'form.showrole'} ne 'st') {
+ my $showroles;
+ if ($env{'form.showrole'} ne 'Any') {
+ $showroles = [$env{'form.showrole'}];
} else {
- $userlist{$student} = $classlist->{$student};
+ $showroles = undef;
}
+ my $withsec = 1;
+ my $hidepriv = 1;
+ my %advrolehash = &Apache::lonnet::get_my_roles($cnum,$cdom,undef,
+ \@statuses,$showroles,undef,$withsec,$hidepriv);
+ &gather_userinfo($context,$format,\%userlist,$indexhash,\%userinfo,
+ \%advrolehash,$permission);
}
- my $cid = $env{'request.course.id'};
- my ($cnum,$cdom) = &get_course_identity($cid);
- my $showroles;
- if ($env{'form.showrole'} ne 'Any') {
- $showroles = [$env{'form.showrole'}];
- } else {
- $showroles = undef;
- }
- my $withsec = 1;
- my %advrolehash = &Apache::lonnet::get_my_roles($cnum,$cdom,undef,
- \@statuses,$showroles,undef,$withsec);
- &gather_userinfo($context,$format,\%userlist,$indexhash,\%userinfo,
- \%advrolehash,$permission);
} else {
my (%cstr_roles,%dom_roles);
if ($context eq 'author') {
@@ -1390,7 +1373,8 @@ sub print_userlist {
} elsif ($env{'form.roletype'} eq 'course') {
if ($env{'form.coursepick'}) {
my %courses = &process_coursepick();
- my %allusers;
+ my %allusers;
+ my $hidepriv = 1;
foreach my $cid (keys(%courses)) {
my ($cnum,$cdom,$cdesc) = &get_course_identity($cid);
next if ($cnum eq '' || $cdom eq '');
@@ -1408,7 +1392,7 @@ sub print_userlist {
foreach my $type (@statuses) {
$access{$type} = $type;
}
- &Apache::loncommon::get_course_users($cdom,$cnum,\%access,\@roles,\@sections,\%users,\%userdata,\%statushash);
+ &Apache::loncommon::get_course_users($cdom,$cnum,\%access,\@roles,\@sections,\%users,\%userdata,\%statushash,$hidepriv);
foreach my $user (keys(%userdata)) {
next if (ref($userinfo{$user}) eq 'HASH');
foreach my $item ('fullname','id') {
@@ -1466,6 +1450,62 @@ sub print_userlist {
$env{'form.phase'}.'" />');
}
+sub section_group_filter {
+ my ($cnum,$cdom) = @_;
+ my @filters;
+ if ($env{'request.course.sec'} eq '') {
+ @filters = ('sec');
+ }
+ push(@filters,'grp');
+ my %name = (
+ sec => 'secfilter',
+ grp => 'grpfilter',
+ );
+ my %title = &Apache::lonlocal::texthash (
+ sec => 'Section(s)',
+ grp => 'Group(s)',
+ all => 'all',
+ none => 'none',
+ );
+ my $output;
+ foreach my $item (@filters) {
+ my ($markup,@options);
+ if ($env{'form.'.$name{$item}} eq '') {
+ $env{'form.'.$name{$item}} = 'all';
+ }
+ if ($item eq 'sec') {
+ if ($env{'form.showrole'} eq 'cc') {
+ $env{'form.'.$name{$item}} = 'none';
+ }
+ my %sections_count = &Apache::loncommon::get_sections($cdom,$cnum);
+ @options = sort(keys(%sections_count));
+ } elsif ($item eq 'grp') {
+ my %curr_groups = &Apache::longroup::coursegroups();
+ @options = sort(keys(%curr_groups));
+ }
+ if (@options > 0) {
+ my $currsel;
+ $markup = ''."\n";
+ foreach my $option ('all','none',@options) {
+ $currsel = '';
+ if ($env{'form.'.$name{$item}} eq $option) {
+ $currsel = ' selected="selected" ';
+ }
+ $markup .= ' '."\n";
+ }
+ $markup .= ''."\n";
+ $output .= (' 'x3).''.$title{$item}.': '.$markup.'';
+ }
+ }
+ return $output;
+}
+
sub list_submit_button {
my ($text) = @_;
return '';
@@ -1479,7 +1519,8 @@ sub gather_userinfo {
($userdata{'username'},$userdata{'domain'},$userdata{'role'}) =
split(/:/,$item);
($userdata{'start'},$userdata{'end'})=split(/:/,$rolehash->{$item});
- &build_user_record(\%userdata,$userinfo,$indexhash,$item,$userlist);
+ &build_user_record($context,\%userdata,$userinfo,$indexhash,
+ $item,$userlist);
} elsif ($context eq 'course') {
my $viewablesec = &viewable_section($permission);
($userdata{'username'},$userdata{'domain'},$userdata{'role'},
@@ -1488,13 +1529,15 @@ sub gather_userinfo {
if (($viewablesec ne '') && ($userdata{'section'} ne '')) {
next if ($viewablesec ne $userdata{'section'});
}
- &build_user_record(\%userdata,$userinfo,$indexhash,$item,$userlist);
+ &build_user_record($context,\%userdata,$userinfo,$indexhash,
+ $item,$userlist);
} elsif ($context eq 'domain') {
if ($env{'form.roletype'} eq 'domain') {
($userdata{'role'},$userdata{'username'},$userdata{'domain'}) =
split(/:/,$item);
($userdata{'end'},$userdata{'start'})=split(/:/,$rolehash->{$item});
- &build_user_record(\%userdata,$userinfo,$indexhash,$item,$userlist);
+ &build_user_record($context,\%userdata,$userinfo,$indexhash,
+ $item,$userlist);
} elsif ($env{'form.roletype'} eq 'author') {
if (ref($rolehash->{$item}) eq 'HASH') {
$userdata{'extent'} = $item;
@@ -1503,7 +1546,8 @@ sub gather_userinfo {
($userdata{'start'},$userdata{'end'}) =
split(/:/,$rolehash->{$item}{$key});
my $uniqid = $key.':'.$item;
- &build_user_record(\%userdata,$userinfo,$indexhash,$uniqid,$userlist);
+ &build_user_record($context,\%userdata,$userinfo,
+ $indexhash,$uniqid,$userlist);
}
}
} elsif ($env{'form.roletype'} eq 'course') {
@@ -1521,9 +1565,9 @@ sub gather_userinfo {
# FIXME: actions on courses disabled for now
# if ($permission->{'cusr'}) {
# if ($numcids > 1) {
-# $spanstart .= '';
+# $spanstart .= ' ';
# } else {
-# $spanstart .= '';
+# $spanstart .= ' ';
# }
# }
$spanend = ' ';
@@ -1533,13 +1577,20 @@ sub gather_userinfo {
$rolehash->{$item}{$cid}{'desc'}.$space;
if (ref($rolehash->{$item}{$cid}{'secs'}) eq 'HASH') {
foreach my $sec (sort(keys(%{$rolehash->{$item}{$cid}{'secs'}}))) {
- $userdata{'extent'} .= $sec.$space.$rolehash->{$item}{$cid}{'secs'}{$sec}.$spanend;
+ if (($env{'form.Status'} eq 'Any') ||
+ ($env{'form.Status'} eq $rolehash->{$item}{$cid}{'secs'}{$sec})) {
+ $userdata{'extent'} .= $sec.$space.$rolehash->{$item}{$cid}{'secs'}{$sec}.$spanend;
+ $userdata{'status'} = $rolehash->{$item}{$cid}{'secs'}{$sec};
+ }
}
}
}
}
}
- &build_user_record(\%userdata,$userinfo,$indexhash,$item,$userlist);
+ if ($userdata{'status'} ne '') {
+ &build_user_record($context,\%userdata,$userinfo,
+ $indexhash,$item,$userlist);
+ }
}
}
}
@@ -1547,14 +1598,15 @@ sub gather_userinfo {
}
sub build_user_record {
- my ($userdata,$userinfo,$indexhash,$record_key,$userlist) = @_;
+ my ($context,$userdata,$userinfo,$indexhash,$record_key,$userlist) = @_;
next if ($userdata->{'start'} eq '-1' && $userdata->{'end'} eq '-1');
- &process_date_info($userdata);
+ if (!(($context eq 'domain') && ($env{'form.roletype'} eq 'course'))) {
+ &process_date_info($userdata);
+ }
my $username = $userdata->{'username'};
my $domain = $userdata->{'domain'};
if (ref($userinfo->{$username.':'.$domain}) eq 'HASH') {
- $userdata->{'fullname'} =
- $userinfo->{$username.':'.$domain}{'fullname'};
+ $userdata->{'fullname'} = $userinfo->{$username.':'.$domain}{'fullname'};
$userdata->{'id'} = $userinfo->{$username.':'.$domain}{'id'};
} else {
&aggregate_user_info($domain,$username,$userinfo);
@@ -1738,6 +1790,8 @@ sub make_keylist_array {
$index->{'email'} = &Apache::loncoursedata::CL_PERMANENTEMAIL();
$index->{'role'} = &Apache::loncoursedata::CL_ROLE();
$index->{'extent'} = &Apache::loncoursedata::CL_EXTENT();
+ $index->{'photo'} = &Apache::loncoursedata::CL_PHOTO();
+ $index->{'thumbnail'} = &Apache::loncoursedata::CL_THUMBNAIL();
foreach my $key (keys(%{$index})) {
$keylist->[$index->{$key}] = $key;
}
@@ -1844,9 +1898,21 @@ END
if ($mode ne 'autoenroll') {
my $check_uncheck_js = &Apache::loncommon::check_uncheck_jscript();
my $alert = &mt("You must select at least one user by checking a user's 'Select' checkbox");
- my $singconfirm = &mt(' for a single user');
- my $multconfirm = &mt(' for multiple users');
- my $date_sec_selector = &date_section_javascript($context,$setting,$statusmode);
+ my $singconfirm = &mt(' for a single user?');
+ my $multconfirm = &mt(' for multiple users?');
+ my $date_sec_selector = &date_section_javascript($context,$setting,$statusmode);
+ my %lt = &Apache::lonlocal::texthash(
+ acwi => 'Access will be set to start immediately',
+ asyo => 'as you did not select an end date in the pop-up window',
+ accw => 'Access will be set to continue indefinitely',
+ asyd => 'as you did not select an end date in the pop-up window',
+ sewi => "Sections will be switched to 'No section'",
+ ayes => "as you either selected the 'No section' option",
+ oryo => 'or you did not select a section in the pop-up window',
+ arol => 'A role with no section will be added',
+ swbs => 'Sections will be switched to:',
+ rwba => 'Roles will be added for section(s):',
+ );
$r->print(<
@@ -1872,12 +1938,47 @@ function verify_action (field) {
}
else {
var message = document.studentform.bulkaction[document.studentform.bulkaction.selectedIndex].text;
+ var choice = document.studentform.bulkaction[document.studentform.bulkaction.selectedIndex].value;
if (numchecked == 1) {
message += singconf;
}
else {
message += multconf;
}
+ if (choice == 'chgdates' || choice == 'reenable' || choice == 'activate') {
+ var datemsg = '';
+ if ((document.studentform.startdate_month.value == '') &&
+ (document.studentform.startdate_day.value == '') &&
+ (document.studentform.startdate_year.value == '')) {
+ datemsg = "\\n$lt{'acwi'},\\n$lt{'asyo'}.\\n";
+ }
+ if ((document.studentform.enddate_month.value == '') &&
+ (document.studentform.enddate_day.value == '') &&
+ (document.studentform.enddate_year.value == '')) {
+ datemsg += "\\n$lt{'accw'},\\n$lt{'asyd'}.\\n";
+ }
+ if (datemsg != '') {
+ message += "\\n"+datemsg;
+ }
+ }
+ if (choice == 'chgsec') {
+ var rolefilter = document.studentform.showrole.options[document.studentform.showrole.selectedIndex].value;
+ var retained = document.studentform.retainsec.value;
+ var secshow = document.studentform.newsecs.value;
+ if (secshow == '') {
+ if (rolefilter == 'st' || retained == 0 || retained == "") {
+ message += "\\n\\n$lt{'sewi'},\\n$lt{'ayes'},\\n$lt{'oryo'}.\\n";
+ } else {
+ message += "\\n\\n$lt{'arol'}\\n$lt{'ayes'},\\n$lt{'oryo'}.\\n";
+ }
+ } else {
+ if (rolefilter == 'st' || retained == 0 || retained == "") {
+ message += "\\n\\n$lt{'swbs'} "+secshow+".\\n";
+ } else {
+ message += "\\n\\n$lt{'rwba'} "+secshow+".\\n";
+ }
+ }
+ }
if (confirm(message)) {
document.studentform.phase.value = 'bulkchange';
document.studentform.submit();
@@ -1928,6 +2029,7 @@ END
'clicker' => "clicker id",
'photo' => "photo",
'extent' => "extent",
+ 'go' => "go",
'pr' => "Proceed",
'ca' => "check all",
'ua' => "uncheck all",
@@ -1973,10 +2075,10 @@ END
my $results_description;
if ($mode ne 'autoenroll') {
$results_description = &results_header_row($rolefilter,$statusmode,
- $context,$permission);
+ $context,$permission,$mode);
$r->print(''.$results_description.' ');
}
- my ($output,$actionselect);
+ my ($output,$actionselect,%canchange,%canchangesec);
if ($mode eq 'html' || $mode eq 'view' || $mode eq 'autoenroll') {
if ($mode ne 'autoenroll') {
if ($permission->{'cusr'}) {
@@ -2010,11 +2112,50 @@ END
$output .= &mt("Click on a username to view the user's personal page.").' ';
}
if ($actionselect) {
- $output .= <<"END";
-$lt{'ac'}: $actionselect
+ $output .= <<"END";
+$lt{'ac'}: $actionselect