--- loncom/interface/lonuserutils.pm 2007/12/22 22:42:58 1.29
+++ loncom/interface/lonuserutils.pm 2008/05/19 17:10:19 1.55
@@ -1,7 +1,7 @@
# The LearningOnline Network with CAPA
# Utility functions for managing LON-CAPA user accounts
#
-# $Id: lonuserutils.pm,v 1.29 2007/12/22 22:42:58 raeburn Exp $
+# $Id: lonuserutils.pm,v 1.55 2008/05/19 17:10:19 raeburn Exp $
#
# Copyright Michigan State University Board of Trustees
#
@@ -42,7 +42,7 @@ use LONCAPA qw(:DEFAULT :match);
###############################################################
# Drop student from all sections of a course, except optional $csec
sub modifystudent {
- my ($udom,$unam,$courseid,$csec,$desiredhost)=@_;
+ my ($udom,$unam,$courseid,$csec,$desiredhost,$context)=@_;
# 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
@@ -69,14 +69,14 @@ sub modifystudent {
# dom name id mode pass f m l g
($udom,$unam,'', '', '',undef,undef,undef,undef,
$section,time,undef,undef,$desiredhost,'','manual',
- '',$courseid);
+ '',$courseid,'',$context);
$result .= $reply.':';
}
}
}
}
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;
}
@@ -129,7 +129,8 @@ sub modifyuserrole {
if ($role ne '') {
$role =~ s/_/\//g;
$roleresult = &Apache::lonnet::assignrole($udom,$uname,$scope,
- $role,$end,$start);
+ $role,$end,$start,'',
+ '',$context);
}
}
return ($userresult,$authresult,$roleresult,$idresult);
@@ -304,7 +305,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 +333,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 +363,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 +385,7 @@ sub javascript_validations {
role => 'The optional role field was not specified.',
continue => 'Continue adding users?',
);
-
- my $function_name =(<".&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";
}
if ($context eq 'course' || $context eq 'domain') {
$Str .= &forceid_change($context);
@@ -937,8 +925,15 @@ sub setup_date_selectors {
sub get_dates_from_form {
- my $startdate = &Apache::lonhtmlcommon::get_date_from_form('startdate');
- my $enddate = &Apache::lonhtmlcommon::get_date_from_form('enddate');
+ my ($startname,$endname) = @_;
+ if ($startname eq '') {
+ $startname = 'startdate';
+ }
+ if ($endname eq '') {
+ $endname = 'enddate';
+ }
+ my $startdate = &Apache::lonhtmlcommon::get_date_from_form($startname);
+ my $enddate = &Apache::lonhtmlcommon::get_date_from_form($endname);
if ($env{'form.no_end_date'}) {
$enddate = 0;
}
@@ -1264,30 +1259,11 @@ sub print_userlist {
if ($env{'form.showrole'} eq 'Any') {
$roleselected = ' selected="selected" ';
}
- my $role_select;
- if ($context eq 'domain') {
- $role_select = &domain_roles_select();
- $r->print('');
- } else {
- $role_select = '';
- $r->print('');
+ my ($cnum,$cdom);
+ $r->print(&role_filter($context));
+ 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')).
@@ -1307,7 +1283,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').' ...
');
}
@@ -1316,34 +1292,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') {
@@ -1392,7 +1358,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 '');
@@ -1410,7 +1377,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') {
@@ -1468,6 +1435,97 @@ sub print_userlist {
$env{'form.phase'}.'" />');
}
+sub role_filter {
+ my ($context) = @_;
+ my $output;
+ my $roleselected = '';
+ if ($env{'form.showrole'} eq 'Any') {
+ $roleselected = ' selected="selected" ';
+ }
+ my ($role_select);
+ if ($context eq 'domain') {
+ $role_select = &domain_roles_select();
+ $output = '';
+ } else {
+ $role_select = '';
+ $output = '';
+ }
+ return $output;
+}
+
+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).'';
+ }
+ }
+ return $output;
+}
+
sub list_submit_button {
my ($text) = @_;
return '';
@@ -1475,6 +1533,10 @@ sub list_submit_button {
sub gather_userinfo {
my ($context,$format,$userlist,$indexhash,$userinfo,$rolehash,$permission) = @_;
+ my $viewablesec;
+ if ($context eq 'course') {
+ $viewablesec = &viewable_section($permission);
+ }
foreach my $item (keys(%{$rolehash})) {
my %userdata;
if ($context eq 'author') {
@@ -1484,7 +1546,6 @@ sub gather_userinfo {
&build_user_record($context,\%userdata,$userinfo,$indexhash,
$item,$userlist);
} elsif ($context eq 'course') {
- my $viewablesec = &viewable_section($permission);
($userdata{'username'},$userdata{'domain'},$userdata{'role'},
$userdata{'section'}) = split(/:/,$item,-1);
($userdata{'start'},$userdata{'end'})=split(/:/,$rolehash->{$item});
@@ -1752,6 +1813,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;
}
@@ -1800,7 +1863,10 @@ sub process_date_info {
}
sub show_users_list {
- my ($r,$context,$mode,$permission,$statusmode,$userlist,$keylist)=@_;
+ my ($r,$context,$mode,$permission,$statusmode,$userlist,$keylist,$formname)=@_;
+ if ($formname eq '') {
+ $formname = 'studentform';
+ }
#
# Variables for excel output
my ($excel_workbook, $excel_sheet, $excel_filename,$row,$format);
@@ -1815,6 +1881,9 @@ sub show_users_list {
} else {
push(@sortable,'extent');
}
+ if ($mode eq 'pickauthor') {
+ @sortable = ('username','fullname','email','status');
+ }
if (!grep(/^\Q$sortby\E$/,@sortable)) {
$sortby = 'username';
}
@@ -1855,12 +1924,24 @@ function photowindow(photolink) {
END
}
}
- if ($mode ne 'autoenroll') {
+ if ($mode ne 'autoenroll' && $mode ne 'pickauthor') {
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 $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(<
@@ -1885,36 +1966,87 @@ function verify_action (field) {
alert("$alert");
}
else {
- var message = document.studentform.bulkaction[document.studentform.bulkaction.selectedIndex].text;
+ var message = document.$formname.bulkaction[document.$formname.bulkaction.selectedIndex].text;
+ var choice = document.$formname.bulkaction[document.$formname.bulkaction.selectedIndex].value;
if (numchecked == 1) {
message += singconf;
}
else {
message += multconf;
}
+ if (choice == 'chgdates' || choice == 'reenable' || choice == 'activate') {
+ var datemsg = '';
+ if ((document.$formname.startdate_month.value == '') &&
+ (document.$formname.startdate_day.value == '') &&
+ (document.$formname.startdate_year.value == '')) {
+ datemsg = "\\n$lt{'acwi'},\\n$lt{'asyo'}.\\n";
+ }
+ if ((document.$formname.enddate_month.value == '') &&
+ (document.$formname.enddate_day.value == '') &&
+ (document.$formname.enddate_year.value == '')) {
+ datemsg += "\\n$lt{'accw'},\\n$lt{'asyd'}.\\n";
+ }
+ if (datemsg != '') {
+ message += "\\n"+datemsg;
+ }
+ }
+ if (choice == 'chgsec') {
+ var rolefilter = document.$formname.showrole.options[document.$formname.showrole.selectedIndex].value;
+ var retained = document.$formname.retainsec.value;
+ var secshow = document.$formname.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();
+ document.$formname.phase.value = 'bulkchange';
+ document.$formname.submit();
}
}
}
function username_display_launch(username,domain) {
var target;
- for (var i=0; i
@@ -1942,12 +2074,14 @@ END
'clicker' => "clicker id",
'photo' => "photo",
'extent' => "extent",
+ 'go' => "go",
'pr' => "Proceed",
'ca' => "check all",
'ua' => "uncheck all",
'ac' => "Action to take for selected users",
'link' => "Behavior of username links",
'aboutme' => "Display a user's personal page",
+ 'owin' => "Open in a new window",
'modify' => "Modify a user's information",
);
if ($context eq 'domain' && $env{'form.roletype'} eq 'course') {
@@ -1955,28 +2089,33 @@ END
} elsif ($context eq 'author') {
$lt{'extent'} = &mt('Author');
}
- my @cols = ('username','domain','id','fullname');
- if ($context eq 'course') {
- push(@cols,'section');
- }
- if (!($context eq 'domain' && $env{'form.roletype'} eq 'course')) {
- push(@cols,('start','end'));
- }
- if ($env{'form.showrole'} eq 'Any' || $env{'form.showrole'} eq 'cr') {
- push(@cols,'role');
- }
- if ($context eq 'domain' && ($env{'form.roletype'} eq 'author' ||
- $env{'form.roletype'} eq 'course')) {
- push (@cols,'extent');
- }
- if (($statusmode eq 'Any') &&
- (!($context eq 'domain' && $env{'form.roletype'} eq 'course'))) {
- push(@cols,'status');
- }
- if ($context eq 'course') {
- push(@cols,'groups');
+ my @cols;
+ if ($mode eq 'pickauthor') {
+ @cols = ('username','fullname','status','email');
+ } else {
+ @cols = ('username','domain','id','fullname');
+ if ($context eq 'course') {
+ push(@cols,'section');
+ }
+ if (!($context eq 'domain' && $env{'form.roletype'} eq 'course')) {
+ push(@cols,('start','end'));
+ }
+ if ($env{'form.showrole'} eq 'Any' || $env{'form.showrole'} eq 'cr') {
+ push(@cols,'role');
+ }
+ if ($context eq 'domain' && ($env{'form.roletype'} eq 'author' ||
+ $env{'form.roletype'} eq 'course')) {
+ push (@cols,'extent');
+ }
+ if (($statusmode eq 'Any') &&
+ (!($context eq 'domain' && $env{'form.roletype'} eq 'course'))) {
+ push(@cols,'status');
+ }
+ if ($context eq 'course') {
+ push(@cols,'groups');
+ }
+ push(@cols,'email');
}
- push(@cols,'email');
my $rolefilter = $env{'form.showrole'};
if ($env{'form.showrole'} eq 'cr') {
@@ -1991,10 +2130,10 @@ END
$r->print(''.$results_description.' ');
}
my ($output,$actionselect,%canchange,%canchangesec);
- if ($mode eq 'html' || $mode eq 'view' || $mode eq 'autoenroll') {
- if ($mode ne 'autoenroll') {
+ if ($mode eq 'html' || $mode eq 'view' || $mode eq 'autoenroll' || $mode eq 'pickauthor') {
+ if ($mode ne 'autoenroll' && $mode ne 'pickauthor') {
if ($permission->{'cusr'}) {
- $actionselect = &select_actions($context,$setting,$statusmode);
+ $actionselect = &select_actions($context,$setting,$statusmode,$formname);
}
$r->print(<
@@ -2006,28 +2145,30 @@ END
$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 .= ' ';
+ unshift (@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.").' ';
+ $output .= ' ';
+ }
+ my $checkwin;
+ if ($env{'form.userwin'}) {
+ $checkwin = 'checked = "checked"';
}
+ $output .= ' '.$lt{'owin'}.' ';
if ($actionselect) {
- $output .= <<"END";
-$lt{'ac'}: $actionselect
-
-
+ $output .= <<"END";
+$lt{'ac'}: $actionselect
+
+
END
my @allroles;
if ($env{'form.showrole'} eq 'Any') {
@@ -2047,6 +2188,11 @@ END
$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,
@@ -2070,16 +2216,20 @@ END
&Apache::loncommon::start_data_table_header_row();
if ($mode eq 'autoenroll') {
$output .= "
-