[LON-CAPA-cvs] cvs: loncom /interface lonuserutils.pm
raeburn
lon-capa-cvs-allow@mail.lon-capa.org
Mon, 24 Dec 2007 05:26:32 -0000
This is a MIME encoded message
--raeburn1198473992
Content-Type: text/plain
raeburn Mon Dec 24 00:26:32 2007 EDT
Modified files:
/loncom/interface lonuserutils.pm
Log:
- Eliminate $permission as 7th arg to &javascript_validations() as it is not used.
Display User Lists in course context.
- Additional filters:
- Dropdown box to select section if the course has at least one section, unless viewer has a section-specific role.
- Dropdown box to select group if the course has at least one group
- Results screen after updating multiple users:
- "Display User Lists" link returns viewer to User Listing page,
- after drop students, displays current class roster
- otherwise displays lists subject to previous filters (status, role, section, etc.).
--raeburn1198473992
Content-Type: text/plain
Content-Disposition: attachment; filename="raeburn-20071224002632.txt"
Index: loncom/interface/lonuserutils.pm
diff -u loncom/interface/lonuserutils.pm:1.32 loncom/interface/lonuserutils.pm:1.33
--- loncom/interface/lonuserutils.pm:1.32 Sun Dec 23 10:50:24 2007
+++ loncom/interface/lonuserutils.pm Mon Dec 24 00:26:31 2007
@@ -1,7 +1,7 @@
# The LearningOnline Network with CAPA
# Utility functions for managing LON-CAPA user accounts
#
-# $Id: lonuserutils.pm,v 1.32 2007/12/23 15:50:24 raeburn Exp $
+# $Id: lonuserutils.pm,v 1.33 2007/12/24 05:26:31 raeburn Exp $
#
# Copyright Michigan State University Board of Trustees
#
@@ -304,7 +304,7 @@
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: <b>[_1]</b>.',$distotal).
"<br />\n");
@@ -332,7 +332,7 @@
###############################################################
sub javascript_validations {
my ($mode,$krbdefdom,$curr_authtype,$curr_authfield,$domain,
- $context,$permission,$groupslist)=@_;
+ $context,$groupslist)=@_;
my %param = (
kerb_def_dom => $krbdefdom,
@@ -1264,7 +1264,7 @@
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('<label>'.&mt('Role Type: [_1]',$role_select).'</label>');
@@ -1288,6 +1288,10 @@
}
$role_select .= '</select>';
$r->print('<label>'.&mt('Role: [_1]',$role_select).'</label>');
+ 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')).
@@ -1331,8 +1335,6 @@
$userlist{$student} = $classlist->{$student};
}
}
- 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'}];
@@ -1468,6 +1470,62 @@
$env{'form.phase'}.'" /></form>');
}
+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,@options);
+ foreach my $item (@filters) {
+ my $markup;
+ 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 = '<select name="'.$name{$item}.'" />'."\n";
+ foreach my $option ('all','none',@options) {
+ $currsel = '';
+ if ($env{'form.'.$name{$item}} eq $option) {
+ $currsel = ' selected="selected" ';
+ }
+ $markup .= ' <option value="'.$option.'"'.$currsel.'>';
+ if (($option eq 'all') || ($option eq 'none')) {
+ $markup .= $title{$option};
+ } else {
+ $markup .= $option;
+ }
+ $markup .= '</option>'."\n";
+ }
+ $markup .= '</select>'."\n";
+ $output .= (' 'x3).'<label>'.$title{$item}.': '.$markup.'</label>';
+ }
+ }
+ return $output;
+}
+
sub list_submit_button {
my ($text) = @_;
return '<input type="button" name="updatedisplay" value="'.$text.'" onclick="javascript:display_update()" />';
@@ -1819,7 +1877,7 @@
$sortby = 'username';
}
my $setting = $env{'form.roletype'};
- my ($cid,$cdom,$cnum,$classgroups,$displayphotos,$displayclickers);
+ my ($cid,$cdom,$cnum,$classgroups,$displayphotos,$displayclickers,$secfilter,$grpfilter);
if ($context eq 'course') {
$cid = $env{'request.course.id'};
($cnum,$cdom) = &get_course_identity($cid);
@@ -2163,6 +2221,17 @@
$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})) {
@@ -2200,11 +2269,40 @@
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/) {
@@ -2741,14 +2839,48 @@
$description .= &mt('All users in course with [_1] roles',$rolefilter);
}
}
+ my $constraint;
my $viewablesec = &viewable_section($permission);
if ($viewablesec ne '') {
if ($env{'form.showrole'} eq 'st') {
- $description .= ' '.&mt('(section [_1] only)',$viewablesec);
+ $constraint = &mt('only users in section "[_1]"',$viewablesec);
} elsif ($env{'form.showrole'} ne 'cc') {
- $description .= ' '.&mt('(only users affiliated with no section or section [_1])',$viewablesec);
+ $constraint = &mt('only users affiliated with no section or section "[_1]"',$viewablesec);
+ }
+ if (($env{'form.grpfilter'} ne 'all') && ($env{'form.grpfilter'} ne '')) {
+ if ($env{'form.grpfilter'} eq 'none') {
+ $constraint .= &mt(' and not in any group');
+ } else {
+ $constraint .= &mt(' and members of group: "[_1]"',$env{'form.grpfilter'});
+ }
+ }
+ } else {
+ if (($env{'form.secfilter'} ne 'all') && ($env{'form.secfilter'} ne '')) {
+ if ($env{'form.secfilter'} eq 'none') {
+ $constraint = &mt('only users affiliated with no section');
+ } else {
+ $constraint = &mt('only users affiliated with section "[_1]"',$env{'form.secfilter'});
+ }
+ }
+ if (($env{'form.grpfilter'} ne 'all') && ($env{'form.grpfilter'} ne '')) {
+ if ($env{'form.grpfilter'} eq 'none') {
+ if ($constraint eq '') {
+ $constraint = &mt('only users not in any group');
+ } else {
+ $constraint .= &mt(' and also not in any group');
+ }
+ } else {
+ if ($constraint eq '') {
+ $constraint = &mt('only members of group: "[_1]"',$env{'form.grpfilter'});
+ } else {
+ $constraint .= &mt(' and also members of group: "[_1]"'.$env{'form.grpfilter'});
+ }
+ }
}
}
+ if ($constraint ne '') {
+ $description .= ' ('.$constraint.')';
+ }
} elsif ($context eq 'author') {
$description =
&mt('Author space for <span class="LC_cusr_emph">[_1]</span>',
@@ -3889,9 +4021,16 @@
}
}
$r->print('<form name="studentform" method="post" action="/adm/createuser">'."\n");
- foreach my $item ('action','sortby','roletype','showrole','Status') {
- if ($env{'form.'.$item} ne '') {
- $r->print('<input type="hidden" name="'.$item.'" value="'.$env{'form.'.$item}.'" />'."\n");
+ if ($choice eq 'drop') {
+ $r->print('<input type="hidden" name="action" value="listusers" />'."\n".
+ '<input type="hidden" name="Status" value="Active" />'."\n".
+ '<input type="hidden" name="showrole" value="st" />'."\n");
+ } else {
+ foreach my $item ('action','sortby','roletype','showrole','Status','secfilter','grpfilter') {
+ if ($env{'form.'.$item} ne '') {
+ $r->print('<input type="hidden" name="'.$item.'" value="'.$env{'form.'.$item}.
+ '" />'."\n");
+ }
}
}
$r->print('<p><b>'.&mt("$result_text{'ok'}{$choice} role(s) for [quant,_1,user,users,no users].",$count).'</b></p>');
@@ -3907,7 +4046,11 @@
$r->print(&make_dates_default($startdate,$enddate,$context));
}
}
- $r->print('<a href="javascript:document.studentform.submit()">'.&mt('Display User Lists').'</a></form>'."\n");
+ my $linktext = &mt('Display User Lists');
+ if ($choice eq 'drop') {
+ $linktext = &mt('Display current class roster');
+ }
+ $r->print('<a href="javascript:document.studentform.submit()">'.$linktext.'</a></form>'."\n");
}
sub classlist_drop {
--raeburn1198473992--