--- loncom/interface/loncoursegroups.pm 2006/02/18 01:27:07 1.5
+++ loncom/interface/loncoursegroups.pm 2006/05/09 15:09:27 1.16
@@ -37,7 +37,7 @@ sub handler {
&Apache::loncommon::content_type($r,'text/html');
$r->send_http_header;
-
+
if ($r->header_only) {
return OK;
}
@@ -88,8 +88,8 @@ sub handler {
\%functions,\%idx,$view_permission,
$manage_permission,$rowColor1,$rowColor2);
} else {
- $r->print('You do not have group administration '.
- 'privileges in this course');
+ $r->print(&mt('You do not have group administration '.
+ 'privileges in this course'));
}
} else {
&print_main_menu($r,$cdom,$cnum,$function,$tabcol,\%functions,\%idx,
@@ -102,13 +102,11 @@ sub handler {
sub print_main_menu {
my ($r,$cdom,$cnum,$function,$tabcol,$functions,$idx,$view_permission,
$manage_permission,$action,$rowColor1,$rowColor2) = @_;
- $r->print(&header('Course Groups',&mt('LON-CAPA Course Groups'),
- undef,undef,undef,undef,$function));
+ $r->print(&header('Course Groups',undef,undef,undef,undef,$function));
&Apache::lonhtmlcommon::add_breadcrumb
({href=>"/adm/coursegroups",
text=>"Course Groups",});
- $r->print(&Apache::lonhtmlcommon::breadcrumbs
- (undef,'Course Groups'));
+ $r->print(&Apache::lonhtmlcommon::breadcrumbs('Course Groups'));
&display_groups($r,$cdom,$cnum,$function,$tabcol,$functions,$idx,
$view_permission,$manage_permission,$action,$rowColor1,
$rowColor2);
@@ -129,38 +127,56 @@ sub display_groups {
delete => '
- Action |
- Group Name |
- Description |
- Creator
+ | $lt{'act'} |
+ $lt{'gname'} |
+ $lt{'desc'} |
+ $lt{'crea'}
|
- Created
+ | $lt{'crtd'}
|
- Last Modified
+ | $lt{'last'}
|
- Functionality
+ | $lt{'func'}
|
- Quota (Mb) |
- Members |
- Files |
- Discussion boards |
- Disk use |
+ $lt{'quot'} |
+ $lt{'memb'} |
+ $lt{'file'} |
+ $lt{'dibd'} |
+ $lt{'dius'} |
END
my %Sortby = ();
@@ -218,12 +234,12 @@ END
my $diskuse = $grp_info{$group}{'diskuse'};
my $functionality;
foreach my $tool (sort(keys(%{$functions}))) {
- if (defined($grp_info{$group}{functions}{$tool})) {
+ if ($grp_info{$group}{functions}{$tool} eq 'on') {
$functionality .= ' '.$tool;
}
}
if (!$functionality) {
- $functionality = 'None available';
+ $functionality = &mt('None available');
}
my $link = $actionlinks{$action};
if ($action eq 'modify' || $action eq 'delete') {
@@ -231,7 +247,7 @@ END
} else {
$link .= $group.'/grppg?register=1';
}
- $link .= '">'.$actiontext{$action}.'';
+ $link .= '">'.$lt{$action}.'';
$r->print('
'.$link.' | '.$group.' | '.$description.' | '.$creator.' | '. &Apache::lonnavmaps::timeToHumanString($creation).' | '. &Apache::lonnavmaps::timeToHumanString($modified).' | '.$functionality.' | '.$quota.' | '.$totalmembers.' | '.$totalfiles.' | '.$boards.' | '.$diskuse.' |
');
$rowNum ++;
}
@@ -239,13 +255,20 @@ END
$r->print('');
$r->print(&Apache::lonhtmlcommon::end_pick_box());
} else {
- $r->print('No groups exist');
+ $r->print($lt{'nogr'});
+ if ($manage_permission) {
+ $r->print('
'.$lt{'crng'}.'');
+ } else {
+ $r->print('
'.$lt{'crng'});
+
+ }
}
} else {
my @coursegroups = split(/:/,$env{'request.course.groups'});
if (@coursegroups > 0) {
- my %curr_groups;
- if (&Apache::loncommon::coursegroups(\%curr_groups,$cdom,$cnum)) {
+ $r->print('
');
+ my %curr_groups = &Apache::loncommon::coursegroups($cdom,$cnum);
+ if (%curr_groups) {
foreach my $group (@coursegroups) {
my %group_info = &Apache::loncommon::get_group_settings(
$curr_groups{$group});
@@ -256,7 +279,8 @@ END
}
}
} else {
- $r->print('You are not currently a member of any active groups in this course');
+ $r->print(&mt('You are not currently a member of any '.
+ 'active groups in this course'));
}
}
return;
@@ -276,7 +300,7 @@ sub group_administration {
my %usertools = ();
my %stored = ();
my %memchg;
- my @member_changes = ('delete','expire','activate','reenable',
+ my @member_changes = ('deletion','expire','activate','reenable',
'changefunc','changepriv');
my $state = $env{'form.state'};
my ($groupname,$description,$startdate,$enddate,$granularity,$specificity);
@@ -315,23 +339,6 @@ sub group_administration {
}
}
- if (($action eq 'modify') && (($state eq 'change_privs') || ($state eq 'memresult'))) {
- foreach my $chg (@member_changes) {
- if (defined($env{'form.'.$chg})) {
- @{$memchg{$chg}} = &Apache::loncommon::get_env_multiple('form.'.$chg);
- }
- }
- &check_changes(\@member_changes,\%memchg);
- foreach my $change (@member_changes) {
- if (($change eq 'delete') || ($change eq 'expire')) {
- next;
- }
- foreach my $user (@{$memchg{$change}}) {
- %{$usertools{$user}} = ();
- }
- }
- }
-
if ($action eq 'modify') {
if ($state eq '') {
$state = 'pick_group';
@@ -447,16 +454,16 @@ sub group_administration {
(($state eq 'pick_name') || ($state eq 'pick_privs'))) ||
(($action eq 'modify') && (($state eq 'change_settings') ||
($state eq 'add_members')))) {
- my $numsections = &Apache::loncommon::get_sections($cdom,$cnum,
- \%sectioncount);
- if ($numsections > 0) {
+ %sectioncount = &Apache::loncommon::get_sections($cdom,$cnum);
+ if (%sectioncount) {
$elements{'create'}{'pick_name'}{'sectionpick'} = 'selectbox';
$elements{'modify'}{'change_mapping'}{'sectionpick'} = 'selectbox';
$elements{'modify'}{'add_members'}{'sectionpick'} = 'selectbox';
}
}
- if ($action eq 'create') {
+ if (($action eq 'create') ||
+ ($action eq 'modify' && $state eq 'pick_members')) {
if (defined($env{'form.types'})) {
@types=&Apache::loncommon::get_env_multiple('form.types');
}
@@ -471,10 +478,15 @@ sub group_administration {
}
}
- if (($state eq 'pick_members') || ($state eq 'pick_privs')) {
- &build_members_list($cdom,$cnum,\@types,\@roles,
- \@sections,\%users,\%userdata);
+ if (($state eq 'pick_members') || ($state eq 'pick_privs') || ($state eq 'change_privs')) {
+ &build_members_list($cdom,$cnum,\@types,\@roles,\@sections,\%users,
+ \%userdata);
+ }
+ if ($state eq 'pick_members') {
if ((keys(%users) > 0) && (@tools > 0)) {
+ if ($granularity eq 'Yes') {
+ $elements{$action}{'pick_members'}{'togglefunc'} = 'checkbox';
+ }
foreach my $tool (@tools) {
if ($granularity eq 'Yes') {
$elements{$action}{'pick_members'}{'user_'.$tool} = 'checkbox';
@@ -483,6 +495,65 @@ sub group_administration {
$elements{$action}{'pick_members'}{'specificity'} = 'radio';
}
}
+ if ($state eq 'change_members') {
+ my %membership = &Apache::lonnet::get_group_membership($cdom,$cnum,
+ $groupname);
+ my $now = time;
+ my $num_expire = 0;
+ my $num_activate = 0;
+ my $num_reenable = 0;
+ my $num_deletion = 0;
+ my $numusers = 0;
+ foreach my $key (sort(keys(%membership))) {
+ if ($key =~ /^\Q$groupname\E:([^:]+:[^:]+)$/) {
+ my $user = $1;
+ my($end,$start,@userprivs) = split(/:/,$membership{$key});
+ unless ($start == -1) {
+ $numusers ++;
+ $num_deletion ++;
+ if (($end > 0) && ($end < $now)) {
+ $num_reenable ++;
+ next;
+ } elsif (($start > $now)) {
+ $num_activate = 1;
+ next;
+ } else {
+ $num_expire ++;
+ next;
+ }
+ next;
+ }
+ if ($num_reenable && $num_activate && $num_expire) {
+ last;
+ }
+ }
+ }
+ if ($num_deletion) {
+ $elements{$action}{'change_members'}{'deletion'} = 'checkbox';
+ }
+ if ($num_expire) {
+ $elements{$action}{'change_members'}{'expire'} = 'checkbox';
+ }
+ if ($num_activate) {
+ $elements{$action}{'change_members'}{'activate'} = 'checkbox';
+ }
+ if ($num_reenable) {
+ $elements{$action}{'change_members'}{'reenable'} = 'checkbox';
+ }
+ if ($numusers) {
+ if ($granularity eq 'Yes') {
+ $elements{$action}{'change_members'}{'togglefunc'} = 'checkbox';
+ }
+ foreach my $tool (@tools) {
+ if ($granularity eq 'Yes') {
+ $elements{$action}{'change_members'}{'user_'.$tool} = 'checkbox';
+ }
+ }
+ if ($specificity eq 'Yes') {
+ $elements{$action}{'change_members'}{'changepriv'} = 'checkbox';
+ }
+ }
+ }
if (($state eq 'pick_privs') || ($state eq 'change_privs') ||
(($specificity eq 'No') &&
@@ -495,17 +566,109 @@ sub group_administration {
}
}
}
- if ((($state eq 'pick_privs') || ($state eq 'change_privs'))
- && ($specificity eq 'Yes')) {
- foreach my $user (sort(keys(%usertools))) {
- foreach my $tool (keys(%{$usertools{$user}})) {
- foreach my $priv (keys(%{$toolprivs{$tool}})) {
- unless (exists($fixedprivs{$tool}{$priv})) {
- $elements{$action}{$state}{'userpriv_'.$priv} = 'checkbox';
+ }
+
+ if (($action eq 'modify') && (($state eq 'change_privs') || ($state eq 'memresult'))) {
+ foreach my $chg (@member_changes) {
+ if (defined($env{'form.'.$chg})) {
+ @{$memchg{$chg}} = &Apache::loncommon::get_env_multiple('form.'.$chg);
+ }
+ }
+
+ if ($state eq 'change_privs') {
+ my %membership = &Apache::lonnet::get_group_membership($cdom,$cnum,
+ $groupname);
+ my $now = time;
+ foreach my $key (sort(keys(%membership))) {
+ if ($key =~ /^\Q$groupname\E:([^:]+:[^:]+)$/) {
+ my $user = $1;
+ my $changefunc = 0;
+ my ($end,$start,@userprivs) = split(/:/,$membership{$key});
+ unless ($start == -1) {
+ if (($end > 0) && ($end < $now)) {
+ unless (grep/^$user$/,$memchg{'reenable'}) {
+ next;
+ }
+ }
+ my @currtools = ();
+ if (@userprivs > 0) {
+ foreach my $tool (sort(keys(%fixedprivs))) {
+ foreach my $priv (keys(%{$fixedprivs{$tool}})) {
+ if (grep/^$priv$/,@userprivs) {
+ push(@currtools,$tool);
+ last;
+ }
+ }
+ }
+ }
+ foreach my $tool (@currtools) {
+ if (keys(%{$usertools{$user}}) > 0) {
+ if (!$usertools{$user}{$tool}) {
+ push(@{$memchg{'changefunc'}},$user);
+ $changefunc = 1;
+ last;
+ }
+ } else {
+ push(@{$memchg{'changefunc'}},$user);
+ $changefunc = 1;
+ }
+ }
+ if ($changefunc) {
+ next;
+ }
+ if (keys(%{$usertools{$user}}) > 0) {
+ foreach my $tool (keys(%{$usertools{$user}})) {
+ if (!grep/^$tool$/,@currtools) {
+ push(@{$memchg{'changefunc'}},$user);
+ $changefunc = 1;
+ last;
+ }
+ }
}
}
}
}
+ &check_changes(\@member_changes,\%memchg);
+ my %temptools;
+ foreach my $change (@member_changes) {
+ if (($change eq 'deletion') || ($change eq 'expire')) {
+ next;
+ }
+ foreach my $user (@{$memchg{$change}}) {
+ unless (exists($usertools{$user})) {
+ %{$usertools{$user}} = ();
+ }
+ %{$temptools{$user}} = %{$usertools{$user}};
+ }
+ }
+ %usertools = %temptools;
+ } elsif ($state eq 'memresult') {
+ foreach my $change (@member_changes) {
+ if ($change eq 'expire' || $change eq 'deletion') {
+ next;
+ }
+ if (ref($memchg{$change}) eq 'ARRAY') {
+ my @users = @{$memchg{$change}};
+ foreach my $user (@users) {
+ unless (exists($usertools{$user})) {
+ %{$usertools{$user}} = ();
+ }
+ }
+ }
+ }
+ }
+ }
+
+ if ((($state eq 'pick_privs') || ($state eq 'change_privs'))
+ && ($specificity eq 'Yes')) {
+ foreach my $user (sort(keys(%usertools))) {
+ foreach my $tool (keys(%{$usertools{$user}})) {
+ foreach my $priv (keys(%{$toolprivs{$tool}})) {
+ unless (exists($fixedprivs{$tool}{$priv})) {
+ $elements{$action}{$state}{'userpriv_'.$priv} = 'checkbox';
+ }
+ }
+ }
}
}
@@ -519,7 +682,12 @@ function backPage(formname,prevstate) {
formname.state.value = prevstate;
formname.submit();
}
-
+function changeSort(caller) {
+ document.$state.state.value = '$state';
+ document.$state.sortby.value = caller;
+ document.$state.submit();
+}
+
|;
$jscript .= &Apache::lonhtmlcommon::set_form_elements(
\%{$elements{$action}{$state}},\%stored);
@@ -551,8 +719,8 @@ function backPage(formname,prevstate) {
}
my $loaditems = &onload_action($action,$state);
- $r->print(&header('Course Groups Manager',&mt('LON-CAPA Groups Manager'),
- $jscript,$action,$state,$page,$function,$loaditems));
+ $r->print(&header('Course Groups Manager',
+ $jscript,$action,$state,$page,$function,$loaditems));
if ($env{'form.refpage'} eq 'enrl') {
&Apache::lonhtmlcommon::add_breadcrumb
@@ -602,7 +770,7 @@ function backPage(formname,prevstate) {
&Apache::lonhtmlcommon::add_breadcrumb(
{text=>"$trail{$action}{$state}"});
$r->print(&Apache::lonhtmlcommon::breadcrumbs
- (undef,'Course Groups Manager'));
+ ('Course Groups Manager'));
&display_control($r,$cdom,$cnum,$tabcol,$action,$state,$page,
\%sectioncount,$groupname,$description,$functions,
\@tools,\%toolprivs,\%fixedprivs,$startdate,$enddate,
@@ -612,7 +780,7 @@ function backPage(formname,prevstate) {
\@sections,\%states,\%navbuttons,$rowColor1,$rowColor2);
last;
} else {
- if (($state =~ /^\w+result$/) && ($i > 0)) {
+ if (($state eq 'result') && ($i > 0)) {
&Apache::lonhtmlcommon::add_breadcrumb(
{href=>"javascript:backPage(document.$state,'$states{$action}[0]')",
text=>"$trail{$action}{$states{$action}[$i]}"});
@@ -627,7 +795,7 @@ function backPage(formname,prevstate) {
&Apache::lonhtmlcommon::add_breadcrumb(
{text=>"View groups"});
$r->print(&Apache::lonhtmlcommon::breadcrumbs
- (undef,'Course Groups Manager'));
+ ('Course Groups Manager'));
&display_groups($r,$cdom,$cnum,$function,$tabcol,$functions,$idx,
$view_permission,$manage_permission,$action,
$rowColor1,$rowColor2);
@@ -639,55 +807,55 @@ function backPage(formname,prevstate) {
sub retrieve_settings {
my ($cdom,$cnum,$groupname) = @_;
- my %groupinfo;
+ my %curr_groups = &Apache::loncommon::coursegroups($cdom,$cnum,$groupname);
+
+ return if (!%curr_groups);
+
+ my %groupinfo =
+ &Apache::loncommon::get_group_settings($curr_groups{$groupname});
+
my %stored;
- my %curr_groups;
- my $numgroups = &Apache::loncommon::coursegroups(\%curr_groups,$cdom,
- $cnum,$groupname);
- if ($numgroups > 0) {
- %groupinfo = &Apache::loncommon::get_group_settings(
- $curr_groups{$groupname});
- $stored{'description'} = &Apache::lonnet::unescape(
- $groupinfo{'description'});
- $stored{'startdate'} = $groupinfo{'startdate'};
- $stored{'enddate'} = $groupinfo{'enddate'};
- if ($stored{'enddate'} == 0) {
- $stored{'no_end_date'} = 1;
- }
- $stored{'granularity'} = $groupinfo{'granularity'};
- $stored{'specificity'} = $groupinfo{'specificity'};
- $stored{'creation'} = $groupinfo{'creation'};
- $stored{'creator'} = $groupinfo{'creator'};
-
- foreach my $tool (sort(keys(%{$groupinfo{'functions'}}))) {
- if ($groupinfo{functions}{$tool} eq 'on') {
- push(@{$stored{tool}},$tool);
- }
- }
- foreach my $role (@{$groupinfo{'roles'}}) {
- push(@{$stored{roles}},$role);
- }
- foreach my $type (@{$groupinfo{'types'}}) {
- push(@{$stored{types}},$type);
- }
- foreach my $section (@{$groupinfo{'sectionpick'}}) {
- push(@{$stored{sectionpick}},$section);
- }
- foreach my $defpriv (@{$groupinfo{'defpriv'}}) {
- push(@{$stored{defpriv}},$defpriv);
- }
- $stored{'autoadd'} = $groupinfo{'autoadd'};
- $stored{'autodrop'} = $groupinfo{'autodrop'};
- if (exists($groupinfo{'autosec'})) {
- foreach my $role (sort(keys(%{$groupinfo{'autosec'}}))) {
- foreach my $section (@{$groupinfo{'autosec'}{$role}}) {
- push (@{$stored{'sec_'.$role}},$section);
- }
- if (@{$groupinfo{'autosec'}{$role}} > 0) {
- push(@{$stored{'autorole'}},$role);
- }
- }
- }
+
+ $stored{'description'} =
+ &Apache::lonnet::unescape($groupinfo{'description'});
+ $stored{'startdate'} = $groupinfo{'startdate'};
+ $stored{'enddate'} = $groupinfo{'enddate'};
+ if ($stored{'enddate'} == 0) {
+ $stored{'no_end_date'} = 1;
+ }
+ $stored{'granularity'} = $groupinfo{'granularity'};
+ $stored{'specificity'} = $groupinfo{'specificity'};
+ $stored{'creation'} = $groupinfo{'creation'};
+ $stored{'creator'} = $groupinfo{'creator'};
+
+ foreach my $tool (sort(keys(%{$groupinfo{'functions'}}))) {
+ if ($groupinfo{functions}{$tool} eq 'on') {
+ push(@{$stored{tool}},$tool);
+ }
+ }
+ foreach my $role (@{$groupinfo{'roles'}}) {
+ push(@{$stored{roles}},$role);
+ }
+ foreach my $type (@{$groupinfo{'types'}}) {
+ push(@{$stored{types}},$type);
+ }
+ foreach my $section (@{$groupinfo{'sectionpick'}}) {
+ push(@{$stored{sectionpick}},$section);
+ }
+ foreach my $defpriv (@{$groupinfo{'defpriv'}}) {
+ push(@{$stored{defpriv}},$defpriv);
+ }
+ $stored{'autoadd'} = $groupinfo{'autoadd'};
+ $stored{'autodrop'} = $groupinfo{'autodrop'};
+ if (exists($groupinfo{'autosec'})) {
+ foreach my $role (sort(keys(%{$groupinfo{'autosec'}}))) {
+ foreach my $section (@{$groupinfo{'autosec'}{$role}}) {
+ push (@{$stored{'sec_'.$role}},$section);
+ }
+ if (@{$groupinfo{'autosec'}{$role}} > 0) {
+ push(@{$stored{'autorole'}},$role);
+ }
+ }
}
return %stored;
}
@@ -767,7 +935,7 @@ sub display_control {
$startdate,$enddate,$tools,$functions,
$toolprivs,$fixedprivs,$userdata,$usertools,
$memchg,$idx,$states,$stored,$sectioncount,
- $navbuttons,$rowColor1,$rowColor2) = @_;
+ $navbuttons,$rowColor1,$rowColor2);
} elsif ($state eq 'chgresult' || $state eq 'memresult' ||
$state eq 'addresult') {
&process_request($r,$cdom,$cnum,$tabcol,$action,$state,$page,
@@ -781,19 +949,16 @@ sub display_control {
}
sub header {
- my ($bodytitle,$title,$jscript,$action,$state,$page,$function,$loaditems) = @_;
- my $html=&Apache::lonxml::xmlbegin();
- my $bodytag=&Apache::loncommon::bodytag($bodytitle,$function,$loaditems);
+ my ($bodytitle,$jscript,$action,$state,$page,$function,$loaditems) = @_;
+ my $start_page=
+ &Apache::loncommon::start_page($bodytitle,
+ '',
+ {'function' => $function,
+ 'add_entries' => $loaditems,});
my $output = <<"END";
-$html
-
-$title
-
-
-$bodytag
-
-