--- loncom/interface/loncoursegroups.pm 2006/02/21 18:56:00 1.6
+++ loncom/interface/loncoursegroups.pm 2008/12/16 23:52:08 1.80.2.3
@@ -1,3 +1,6 @@
+# The LearningOnline Network with CAPA
+#
+# $Id: loncoursegroups.pm,v 1.80.2.3 2008/12/16 23:52:08 raeburn Exp $
#
# Copyright Michigan State University Board of Trustees
#
@@ -26,18 +29,23 @@ package Apache::loncoursegroups;
use strict;
use Apache::lonnet;
-use Apache::loncommon;
-use Apache::lonhtmlcommon;
+use Apache::loncommon();
+use Apache::lonhtmlcommon();
use Apache::lonlocal;
-use Apache::lonnavmaps;
+use Apache::lonnavmaps();
+use Apache::longroup();
+use Apache::portfolio();
use Apache::Constants qw(:common :http);
+use LONCAPA::map();
+use lib '/home/httpd/lib/perl/';
+use LONCAPA;
sub handler {
my ($r) = @_;
&Apache::loncommon::content_type($r,'text/html');
$r->send_http_header;
-
+
if ($r->header_only) {
return OK;
}
@@ -52,24 +60,27 @@ sub handler {
&Apache::loncommon::get_unprocessed_cgi($ENV{'QUERY_STRING'},
['action','refpage','state','groupname','branch']);
- my $function = &Apache::loncommon::get_users_function();
- my $tabcol = &Apache::loncommon::designparm($function.'.tabbg');
my $cdom = $env{'course.'.$env{'request.course.id'}.'.domain'};
my $cnum = $env{'course.'.$env{'request.course.id'}.'.num'};
my $view_permission =
- &Apache::lonnet::allowed('vcg',$env{'request.course.id'});
+ &Apache::lonnet::allowed('vcg',$env{'request.course.id'}.($env{'request.course.sec'}?'/'.$env{'request.course.sec'}:''));
my $manage_permission =
- &Apache::lonnet::allowed('mdg',$env{'request.course.id'});
+ &Apache::lonnet::allowed('mdg',$env{'request.course.id'}.($env{'request.course.sec'}?'/'.$env{'request.course.sec'}:''));
&Apache::lonhtmlcommon::clear_breadcrumbs();
+ my $gpterm = &Apache::loncommon::group_term();
+ my $ucgpterm = $gpterm;
+ $ucgpterm =~ s/^(\w)/uc($1)/e;
+ my $crstype = &Apache::loncommon::course_type();
+
my %functions = (
email => 'E-mail',
discussion => 'Discussion boards',
chat => 'Chat',
files => 'File repository',
roster => 'Membership roster',
- homepage => 'Group home page',
+ homepage => $ucgpterm.' home page',
);
my %idx = ();
@@ -77,117 +88,194 @@ sub handler {
$idx{fullname} = &Apache::loncoursedata::CL_FULLNAME();
$idx{udom} = &Apache::loncoursedata::CL_SDOM();
$idx{uname} = &Apache::loncoursedata::CL_SNAME();
-
- my $rowColor1 = "#dddddd";
- my $rowColor2 = "#eeeeee";
+ $idx{section} = &Apache::loncoursedata::CL_SECTION();
my $action = $env{'form.action'};
- if ($action eq 'create' || $action eq 'modify' || $action eq 'view') {
+ my $state = $env{'form.state'};
+ if ((!defined($action)) || ($action eq 'view') || ($action eq 'modify') || ($action eq 'delete') || ($action eq 'reenable')) {
+ if (!defined($state)) {
+ $state = 'view';
+ }
+ }
+ if ($action eq 'create' || $action eq 'modify' || $action eq 'view' ||
+ $action eq 'delete' || $action eq 'reenable') {
if ($view_permission || $manage_permission) {
- &group_administration($r,$action,$cdom,$cnum,$function,$tabcol,
- \%functions,\%idx,$view_permission,
- $manage_permission,$rowColor1,$rowColor2);
+ if ($state eq 'view') {
+ &print_main_menu($r,$cdom,$cnum,\%functions,\%idx,
+ $view_permission,$manage_permission,
+ $action,$state,$gpterm,$ucgpterm,$crstype);
+ } else {
+ &group_administration($r,$action,$state,$cdom,$cnum,
+ \%functions,\%idx,$view_permission,
+ $manage_permission,$gpterm,$ucgpterm,
+ $crstype);
+ }
} else {
- $r->print(&mt('You do not have group administration '.
- 'privileges in this course'));
+ $r->print('
'
+ .&mt('You do not have '.$gpterm.' administration '
+ .'privileges in this '.lc($crstype).'.')
+ .'
');
}
} else {
- &print_main_menu($r,$cdom,$cnum,$function,$tabcol,\%functions,\%idx,
- $view_permission,$manage_permission,$action,
- $rowColor1,$rowColor2);
+ &print_main_menu($r,$cdom,$cnum,\%functions,\%idx,$view_permission,
+ $manage_permission,$action,$state,$gpterm,$ucgpterm,
+ $crstype);
}
return OK;
}
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));
+ my ($r,$cdom,$cnum,$functions,$idx,$view_permission,$manage_permission,
+ $action,$state,$gpterm,$ucgpterm,$crstype) = @_;
+ my $jscript = qq|
+function changeSort(caller) {
+ document.$state.sortby.value = caller;
+ document.$state.submit();
+}
+function openGroupRoster(group,status) {
+ var url = '/adm/grouproster?';
+ url += 'group='+group+'&status='+status+'&ref=popup';
+ var title = 'Group Membership';
+ var options = 'scrollbars=1,resizable=1,menubar=0';
+ options += ',width=700,height=600';
+ rosterbrowser = open(url,title,options,'1');
+ rosterbrowser.focus();
+}\n|;
+ $r->print(&header('Groups',$jscript,$action,$state));
+ if ($env{'form.refpage'} eq 'cusr') {
+ &Apache::lonhtmlcommon::add_breadcrumb
+ ({href=>"/adm/createuser",
+ text=>"User Management"});
+ }
&Apache::lonhtmlcommon::add_breadcrumb
({href=>"/adm/coursegroups",
- text=>"Course Groups",});
- $r->print(&Apache::lonhtmlcommon::breadcrumbs
- (undef,'Course Groups'));
- &display_groups($r,$cdom,$cnum,$function,$tabcol,$functions,$idx,
- $view_permission,$manage_permission,$action,$rowColor1,
- $rowColor2);
+ text=>"Groups"});
+ my $helpitem;
+ if ($manage_permission) {
+ $helpitem = 'Creating_Groups';
+ }
+ $r->print(&Apache::lonhtmlcommon::breadcrumbs('Groups',$helpitem));
+ &display_groups($r,$cdom,$cnum,$functions,$idx,$view_permission,
+ $manage_permission,$action,$state,$gpterm,$ucgpterm,
+ $crstype);
$r->print(&footer());
return;
}
sub display_groups {
- my ($r,$cdom,$cnum,$function,$tabcol,$functions,$idx,$view_permission,
- $manage_permission,$action,$rowColor1,$rowColor2) = @_;
+ my ($r,$cdom,$cnum,$functions,$idx,$view_permission,
+ $manage_permission,$action,$state,$gpterm,$ucgpterm,$crstype) = @_;
my %curr_groups = ();
my %grp_info = ();
-
my %actionlinks = (
- modify => ' ' ' '.$lt{'redg'}.' ';
+ }
+ }
+ }
+ my %curr_groups = &Apache::longroup::coursegroups($cdom,$cnum,undef,
+ $status);
+
+ if (%curr_groups) {
+ if ($manage_permission) {
+ if ($action ne 'reenable') {
+ $r->print(''.$lt{'crng'}.' ');
+ }
+ if ($reenable_link) {
+ $r->print($reenable_link);
+ }
+ }
+ $r->print(' ');
+ $r->print(&Apache::loncommon::start_data_table().
+ &Apache::loncommon::start_data_table_header_row());
+
$r->print(<<"END");
-
-
- $lt{'act'}
- $lt{'gname'}
- $lt{'desc'}
- $lt{'crea'}
-
- $lt{'crtd'}
-
- $lt{'last'}
-
- $lt{'func'}
-
- $lt{'quot'}
- $lt{'memb'}
- $lt{'file'}
- $lt{'dibd'}
- $lt{'dius'}
-
+ $lt{'act'}
+ $lt{'gname'}
+ $lt{'desc'}
+ $lt{'crea'}
+ $lt{'crtd'}
+ $lt{'last'}
+ $lt{'func'}
+ $lt{'quot'}
+ $lt{'memb'}
+ $lt{'file'}
+ $lt{'dibd'}
+ $lt{'dius'}
END
+ $r->print(&Apache::loncommon::end_data_table_header_row());
my %Sortby = ();
foreach my $group (sort(keys(%curr_groups))) {
%{$grp_info{$group}} =
- &Apache::loncommon::get_group_settings(
+ &Apache::longroup::get_group_settings(
$curr_groups{$group});
my $members_result = &group_members($cdom,$cnum,$group,
\%grp_info);
- my $files_result = &group_files($group,\%grp_info);
+ my $port_path = '/userfiles/groups/'.$group.'/portfolio';
+ my $totaldirs = 0;
+ my $totalfiles = 0;
+ &group_files($group,$port_path,\$totalfiles,\$totaldirs);
+ $grp_info{$group}{'totalfiles'} = $totalfiles;
+ $grp_info{$group}{'totaldirs'} = $totaldirs;
+ my $getpropath = 1;
+ my $diskuse = &Apache::lonnet::diskusage($cdom,$cnum,$port_path, $getpropath);
+ if ($grp_info{$group}{'quota'} > 0) {
+ my $pct_use = 0.1 * $diskuse/$grp_info{$group}{'quota'};
+ $grp_info{$group}{'diskuse'} = sprintf("%.0f",$pct_use);
+ } else {
+ $grp_info{$group}{'diskuse'} = 'N/A';
+ }
+ my ($groupboards,$boardshash)=&Apache::longroup::get_group_bbinfo(
+ $cdom,$cnum,$group);
+ $grp_info{$group}{'boards'} = scalar(@{$groupboards});
if ($env{'form.sortby'} eq 'groupname') {
push(@{$Sortby{$group}},$group);
} elsif ($env{'form.sortby'} eq 'description') {
- push(@{$Sortby{$grp_info{$group}{'description'}}},
- $group);
+ push(@{$Sortby{$grp_info{$group}{'description'}}},$group);
} elsif ($env{'form.sortby'} eq 'creator') {
push(@{$Sortby{$grp_info{$group}{'creator'}}},$group);
} elsif ($env{'form.sortby'} eq 'creation') {
@@ -209,23 +297,17 @@ END
push(@{$Sortby{$group}},$group);
}
}
- my $rowNum = 0;
- my $rowColor;
foreach my $key (sort(keys(%Sortby))) {
foreach my $group (@{$Sortby{$key}}) {
- if ($rowNum %2 == 1) {
- $rowColor = $rowColor1;
- } else {
- $rowColor = $rowColor2;
- }
my $description =
- &Apache::lonnet::unescape($grp_info{$group}{'description'});
+ &unescape($grp_info{$group}{'description'});
my $creator = $grp_info{$group}{'creator'};
my $creation = $grp_info{$group}{'creation'};
my $modified = $grp_info{$group}{'modified'};
my $quota = $grp_info{$group}{'quota'};
my $totalmembers = $grp_info{$group}{'totalmembers'};
my $totalfiles = $grp_info{$group}{'totalfiles'};
+ my $totaldirs = $grp_info{$group}{'totaldirs'};
my $boards = $grp_info{$group}{'boards'};
my $diskuse = $grp_info{$group}{'diskuse'};
my $functionality;
@@ -238,46 +320,90 @@ END
$functionality = &mt('None available');
}
my $link = $actionlinks{$action};
- if ($action eq 'modify' || $action eq 'delete') {
+ if ($action eq 'modify' || $action eq 'delete' ||
+ $action eq 'reenable') {
$link .= $group;
} else {
- $link .= $group.'/grppg?register=1';
+ $link .= $group.'/smppg?ref=grouplist';
+ if (exists($env{'form.refpage'})) {
+ $link .= '&refpage='.$env{'form.refpage'};
+ }
+ }
+ $link .= '">'.$lt{$action}.'';
+ if ($action eq 'view') {
+ if ($manage_permission) {
+ $link .= ' '.$actionlinks{'modify'}.
+ $group.'">'.$lt{'modify'}.''.
+ ' '.$actionlinks{'delete'}.
+ $group.'">'.$lt{'delete'}.'';
+ }
}
- $link .= '">'.$lt{$action}.'';
- $r->print(''.$link.' '.$group.' '.$description.' '.$creator.' '. &Apache::lonnavmaps::timeToHumanString($creation).' '. &Apache::lonnavmaps::timeToHumanString($modified).' '.$functionality.' '.$quota.' '.$totalmembers.' '.$totalfiles.' '.$boards.' '.$diskuse.' ');
- $rowNum ++;
+ $r->print(&Apache::loncommon::start_data_table_row('LC_data_table_dense').
+ ''.$link.' '.
+ ''.$group.' '.
+ ''.$description.' '.
+ ''.$creator.' '.
+ ''. &Apache::lonnavmaps::timeToHumanString($creation).' '.
+ ''. &Apache::lonnavmaps::timeToHumanString($modified).' '.
+ ''.$functionality.' '.
+ ''.$quota.' '.
+ ''.$totalmembers.' '.
+ ''.
+ ''.&mt('Files: [_1]',$totalfiles).'
'.
+ ''.&mt('Folders: [_1]',$totaldirs).'
'.
+ ' '.
+ ''.$boards.' '.
+ ''.$diskuse.' '.
+ &Apache::loncommon::end_data_table_row());
+ }
+ }
+ $r->print(&Apache::loncommon::end_data_table());
+ $r->print(' ');
+ if ($action eq 'view') {
+ if (!defined($state)) {
+ $state = 'view';
}
+ $r->print(' ');
}
- $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'}.' ');
+ if ($action ne 'reenable') {
+ if ($reenable_link) {
+ $r->print($reenable_link);
+ }
+ }
+ } else {
+ $r->print(' '.$lt{'alth'});
+ }
}
} 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::longroup::coursegroups($cdom,$cnum);
+ if (%curr_groups) {
foreach my $group (@coursegroups) {
- my %group_info = &Apache::loncommon::get_group_settings(
+ my %group_info = &Apache::longroup::get_group_settings(
$curr_groups{$group});
- my $description = &Apache::lonnet::unescape(
+ my $description = &unescape(
$group_info{description});
- my ($uname,$udom) = split(/:/,$group_info{creator});
- $r->print(''.$group,' '.$description.' ');
+ $r->print(''.$group,' '.$description.' ');
}
}
} else {
- $r->print(&mt('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 '.$gpterm.'s in this '.lc($crstype).'.'));
}
}
return;
}
sub group_administration {
- my ($r,$action,$cdom,$cnum,$function,$tabcol,$functions,$idx,
- $view_permission,$manage_permission,$rowColor1,$rowColor2) = @_;
+ my ($r,$action,$state,$cdom,$cnum,$functions,$idx,$view_permission,
+ $manage_permission,$gpterm,$ucgpterm,$crstype) = @_;
my %sectioncount = ();
my @tools = ();
my @types = ();
@@ -291,8 +417,8 @@ sub group_administration {
my %memchg;
my @member_changes = ('deletion','expire','activate','reenable',
'changefunc','changepriv');
- my $state = $env{'form.state'};
- my ($groupname,$description,$startdate,$enddate,$granularity,$specificity);
+ my ($groupname,$description,$startdate,$enddate,$granularity,$specificity,
+ $quota,$validate_script);
if (defined($env{'form.groupname'})) {
$groupname = $env{'form.groupname'};
@@ -316,7 +442,9 @@ sub group_administration {
if (defined($env{'form.specificity'})) {
$specificity=$env{'form.specificity'};
}
-
+ if (defined($env{'form.quota'})) {
+ $quota=$env{'form.quota'};
+ }
}
if (($action eq 'create') || (($action eq 'modify')
&& (($state eq 'pick_privs') || ($state eq 'addresult')))) {
@@ -330,9 +458,11 @@ sub group_administration {
if ($action eq 'modify') {
if ($state eq '') {
- $state = 'pick_group';
+ if (defined($env{'form.groupname'})) {
+ $state = 'pick_task';
+ }
} else {
- %stored = &retrieve_settings($cdom,$cnum,$groupname);
+ %stored = &retrieve_settings($cdom,$cnum,$groupname,$action);
if (ref($stored{'types'}) eq 'ARRAY') {
@types = @{$stored{'types'}};
}
@@ -351,89 +481,68 @@ sub group_administration {
$description = $stored{'description'};
$granularity = $stored{'granularity'};
$specificity = $stored{'specificity'};
+ $quota = $stored{'quota'};
}
}
}
- my %toolprivs = ();
- %{$toolprivs{'email'}} = (
- sgm => 'Send group mail',
- sgb => 'Broadcast mail',
- );
- %{$toolprivs{'discussion'}} = (
- cgb => 'Create boards',
- pgd => 'Post',
- pag => 'Anon. posts',
- rgi => 'Get identities',
- vgb => 'View boards',
- );
- %{$toolprivs{'chat'}} = (
- pgc => 'Chat',
- );
- %{$toolprivs{'files'}} = (
- rgf => 'Retrieve',
- ugf => 'Upload',
- dgf => 'Delete',
- );
- %{$toolprivs{'roster'}} = (
- vgm => 'View',
- );
- %{$toolprivs{'homepage'}} = (
- vgh => 'View page',
- mgh => 'Modify page',
- );
- my %fixedprivs = ();
- %{$fixedprivs{'email'}} = ('sgm' => 1);
- %{$fixedprivs{'discussion'}} = ('vgb' => 1);
- %{$fixedprivs{'chat'}} = ('pgc' => 1);
- %{$fixedprivs{'files'}} = ('rgf' => 1);
- %{$fixedprivs{'roster'}} = ('vgm' => 1);
- %{$fixedprivs{'homepage'}} = ('vgh' => 1);
-
- my %elements = ();
- %{$elements{'create'}} = ();
- %{$elements{'modify'}} = ();
- %{$elements{'create'}{'pick_name'}} = (
- startdate_month => 'selectbox',
- startdate_hour => 'selectbox',
- enddate_month => 'selectbox',
- enddate_hour => 'selectbox',
- startdate_day => 'text',
- startdate_year => 'text',
- startdate_minute => 'text',
- startdate_second => 'text',
- enddate_day => 'text',
- enddate_year => 'text',
- enddate_minute => 'text',
- enddate_second => 'text',
- groupname => 'text',
- description => 'text',
- tool => 'checkbox',
- granularity => 'radio',
- no_end_date => 'checkbox',
- );
- %{$elements{'modify'}{'change_settings'}} = (
- %{$elements{'create'}{'pick_name'}},
- specificity => 'radio',
- defpriv => 'checkbox',
- autorole => 'checkbox',
- autoadd => 'radio',
- autodrop => 'radio',
- );
+ my $toolprivs = &Apache::longroup::get_tool_privs($gpterm);
+
+ my $fixedprivs = &Apache::longroup::get_fixed_privs();
+
+ my %elements =
+ (
+ create => {
+ pick_name => {
+ startdate_month => 'selectbox',
+ startdate_hour => 'selectbox',
+ enddate_month => 'selectbox',
+ enddate_hour => 'selectbox',
+ startdate_day => 'text',
+ startdate_year => 'text',
+ startdate_minute => 'text',
+ startdate_second => 'text',
+ enddate_day => 'text',
+ enddate_year => 'text',
+ enddate_minute => 'text',
+ enddate_second => 'text',
+ groupname => 'text',
+ description => 'text',
+ quota => 'text',
+ tool => 'checkbox',
+ granularity => 'radio',
+ no_end_date => 'checkbox',
+ },
+ pick_members => {
+ member => 'checkbox',
+ defpriv => 'checkbox',
+ },
+ },
+ );
+
+ $elements{'modify'} = {
+ change_settings => {
+ %{$elements{'create'}{'pick_name'}},
+ specificity => 'radio',
+ defpriv => 'checkbox',
+ autorole => 'checkbox',
+ autoadd => 'radio',
+ autodrop => 'radio',
+ },
+ add_members => {
+ types => 'selectbox',
+ roles => 'selectbox',
+ },
+ };
+
if (ref($stored{'autorole'}) eq 'ARRAY') {
foreach my $role (@{$stored{'autorole'}}) {
- $elements{'modify'}{'change_settings'}{'sec_'.$role} = 'selectbox';
+ unless ($role eq 'cc') {
+ $elements{'modify'}{'change_settings'}{'sec_'.$role} =
+ 'selectbox';
+ }
}
}
- %{$elements{'create'}{'pick_members'}} = (
- member => 'checkbox',
- defpriv => 'checkbox',
- );
-
- %{$elements{'modify'}{'add_members'}} = (
- types => 'selectbox',
- roles => 'selectbox',
- );
if (($action eq 'create') && ($state eq 'pick_name')) {
$elements{'create'}{'pick_name'}{'types'} = 'selectbox';
@@ -443,16 +552,14 @@ 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) {
- $elements{'create'}{'pick_name'}{'sectionpick'} = 'selectbox';
- $elements{'modify'}{'change_mapping'}{'sectionpick'} = 'selectbox';
- $elements{'modify'}{'add_members'}{'sectionpick'} = 'selectbox';
- }
+ %sectioncount = &Apache::loncommon::get_sections($cdom,$cnum);
+ $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');
}
@@ -461,9 +568,6 @@ sub group_administration {
}
if (defined($env{'form.sectionpick'})) {
@sections=&Apache::loncommon::get_env_multiple('form.sectionpick');
- if (grep/^_all$/,@sections) {
- @sections = sort {$a cmp $b} keys(%sectioncount);
- }
}
}
@@ -473,6 +577,9 @@ sub group_administration {
}
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';
@@ -501,7 +608,7 @@ sub group_administration {
$num_reenable ++;
next;
} elsif (($start > $now)) {
- $num_activate = 1;
+ $num_activate ++;
next;
} else {
$num_expire ++;
@@ -527,6 +634,9 @@ sub group_administration {
$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';
@@ -539,11 +649,17 @@ sub group_administration {
}
if (($state eq 'pick_privs') || ($state eq 'change_privs') ||
- (($specificity eq 'No') &&
- (($state eq 'result') || ($state eq 'memresult')))) {
+ (($specificity eq 'No') &&
+ ($state eq 'memresult' || $state eq 'result' || $state eq 'addresult'))) {
foreach my $tool (@tools) {
my @values = &Apache::loncommon::get_env_multiple('form.user_'.$tool);
foreach my $user (@values) {
+ if ($state eq 'pick_privs' || $state eq 'result'
+ || $state eq 'addresult') {
+ if (!grep(/^\Q$user\E$/,@members)) {
+ next;
+ }
+ }
unless(exists($usertools{$user}{$tool})) {
$usertools{$user}{$tool} = 1;
}
@@ -575,8 +691,8 @@ sub group_administration {
}
my @currtools = ();
if (@userprivs > 0) {
- foreach my $tool (sort(keys(%fixedprivs))) {
- foreach my $priv (keys(%{$fixedprivs{$tool}})) {
+ foreach my $tool (sort(keys(%{$fixedprivs}))) {
+ foreach my $priv (keys(%{$$fixedprivs{$tool}})) {
if (grep/^$priv$/,@userprivs) {
push(@currtools,$tool);
last;
@@ -646,19 +762,59 @@ sub group_administration {
&& ($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})) {
+ foreach my $priv (keys(%{$$toolprivs{$tool}})) {
+ unless (exists($$fixedprivs{$tool}{$priv})) {
$elements{$action}{$state}{'userpriv_'.$priv} = 'checkbox';
}
}
}
}
}
-
+
+ if (($action eq 'create' && $state eq 'pick_name') ||
+ ($action eq 'modify' && $state eq 'change_settings')) {
+ my ($crsquota,$freespace,$maxposs) = &get_quota_constraints($action,\%stored);
+ my $space_trim = '/^\s*|\s*\$/g,""';
+ my $float_check = '/^([0-9]*\.?[0-9]*)$/';
+ $validate_script = '
+ var newquota = new String(document.'.$state.'.quota.value);
+ newquota.replace('.$space_trim.');
+ if (newquota == "" ) {
+ document.'.$state.'.quota.value = 0;
+ newquota = "0";
+ }
+ var maxposs = '.sprintf("%.2f",$maxposs).';
+ if (newquota > maxposs) {
+ alert("The file repository quota you entered for this group ("+newquota+" Mb) exceeds the maximum possible ("+maxposs+" Mb). Please enter a smaller number.");
+ return;
+ }
+ var re_quota = '.$float_check.';
+ var check_quota = newquota.match(re_quota);
+ if (check_quota == null) {
+ alert("The quota you entered contains invalid characters, the quota should only include numbers, with or without a decimal point.");
+ return;
+ }
+ if (newquota == 0) {
+ var warn_zero = 0;
+ for (var i=0; iprint(&header('Course Groups Manager',&mt('LON-CAPA Groups Manager'),
- $jscript,$action,$state,$page,$function,$loaditems));
+ $r->print(&header("Groups Manager",
+ $jscript,$action,$state,$page,$loaditems));
- if ($env{'form.refpage'} eq 'enrl') {
+ if ($env{'form.refpage'} eq 'cusr') {
&Apache::lonhtmlcommon::add_breadcrumb
- ({href=>"/adm/dropadd",
- text=>"Enrollment Manager",
+ ({href=>"/adm/createuser",
+ text=>"User Management",
faq=>9,bug=>'Instructor Interface',});
- } else {
+ if ($action eq 'modify' || $action eq 'delete') {
+ &Apache::lonhtmlcommon::add_breadcrumb
+ ({href=>"/adm/coursegroups?refpage=cusr&action=$action",
+ text=>"Groups",
+ faq=>9,bug=>'Instructor Interface',});
+ }
+ } else {
&Apache::lonhtmlcommon::add_breadcrumb
- ({href=>"/adm/coursegroups",
- text=>"Course Groups",
- faq=>9,bug=>'Instructor Interface',});
+ ({href=>"/adm/coursegroups",
+ text=>"Groups",
+ faq=>9,bug=>'Instructor Interface',});
+ if ($env{'form.refpage'} eq 'grouplist') {
+ &Apache::lonhtmlcommon::add_breadcrumb
+ ({href=>"/adm/$cdom/$cnum/$env{'form.groupname'}/smppg?ref=grouplist",
+ text=>"Group: $description",});
+ }
}
my %trail = ();
%{$trail{'create'}} = &Apache::lonlocal::texthash (
- pick_name => 'Group Settings',
+ pick_name => $ucgpterm.' Settings',
pick_members => 'Select Members',
pick_privs => 'Choose Privileges',
result => 'Creation Complete',
);
%{$trail{'modify'}} = &Apache::lonlocal::texthash(
- pick_group => 'Groups',
pick_task => 'Choose Task',
- change_settings => 'Group Settings',
+ change_settings => "$ucgpterm Settings",
change_members => 'Modify/Delete Members',
change_privs => 'Change Privileges',
change_mapping => 'Membership Mapping',
@@ -738,213 +906,541 @@ function changeSort(caller) {
memresult => 'Modifications Complete',
addresult => 'Additions Complete',
);
+ %{$trail{'delete'}} = &Apache::lonlocal::texthash(
+ verify => 'Verify deletion',
+ result => 'Deletion Complete'
+ );
+ %{$trail{'reenable'}} = &Apache::lonlocal::texthash(
+ verify => 'Verify Re-enable',
+ result => 'Re-enabled'
+ );
my %navbuttons = &Apache::lonlocal::texthash(
gtns => 'Go to next step',
gtps => 'Go to previous step',
- crgr => 'Create group',
+ crgr => 'Create '.$gpterm,
mose => 'Modify settings',
gtpp => 'Go to previous page',
adme => 'Add members',
);
- if ((($action eq 'create') || ($action eq 'modify')) &&
+ if ((($action eq 'create') || ($action eq 'modify') || ($action eq 'delete') || ($action eq 'reenable')) &&
($manage_permission)) {
for (my $i=0; $i<@{$states{$action}}; $i++) {
if ($state eq $states{$action}[$i]) {
&Apache::lonhtmlcommon::add_breadcrumb(
{text=>"$trail{$action}{$state}"});
$r->print(&Apache::lonhtmlcommon::breadcrumbs
- (undef,'Course Groups Manager'));
- &display_control($r,$cdom,$cnum,$tabcol,$action,$state,$page,
+ ("Groups Manager","Creating_Groups"));
+ &display_control($r,$cdom,$cnum,$action,$state,$page,
\%sectioncount,$groupname,$description,$functions,
- \@tools,\%toolprivs,\%fixedprivs,$startdate,$enddate,
+ \@tools,$toolprivs,$fixedprivs,$startdate,$enddate,
\%users,\%userdata,$idx,\%memchg,\%usertools,
- $function,$view_permission,$manage_permission,
- \%stored,$granularity,$specificity,\@types,\@roles,
- \@sections,\%states,\%navbuttons,$rowColor1,$rowColor2);
+ $view_permission,$manage_permission,
+ \%stored,$granularity,$quota,$specificity,\@types,\@roles,
+ \@sections,\%states,\%navbuttons,$gpterm,$ucgpterm,
+ $crstype);
last;
} else {
- if (($state =~ /^\w+result$/) && ($i > 0)) {
- &Apache::lonhtmlcommon::add_breadcrumb(
+ if (($action eq 'create') || ($action eq 'modify')) {
+ if (($state eq 'result') && ($i > 0)) {
+ &Apache::lonhtmlcommon::add_breadcrumb(
{href=>"javascript:backPage(document.$state,'$states{$action}[0]')",
text=>"$trail{$action}{$states{$action}[$i]}"});
- } else {
- &Apache::lonhtmlcommon::add_breadcrumb(
+ } else {
+ &Apache::lonhtmlcommon::add_breadcrumb(
{href=>"javascript:backPage(document.$state,'$states{$action}[$i]')",
text=>"$trail{$action}{$states{$action}[$i]}"});
+ }
}
- }
+ }
}
} elsif (($action eq 'view') && ($view_permission)) {
&Apache::lonhtmlcommon::add_breadcrumb(
- {text=>"View groups"});
+ {text=>"View $gpterm".'s'});
$r->print(&Apache::lonhtmlcommon::breadcrumbs
- (undef,'Course Groups Manager'));
- &display_groups($r,$cdom,$cnum,$function,$tabcol,$functions,$idx,
- $view_permission,$manage_permission,$action,
- $rowColor1,$rowColor2);
-
+ ('Groups Manager'));
+ &display_groups($r,$cdom,$cnum,$functions,$idx,$view_permission,
+ $manage_permission,$action,$state,$gpterm,$ucgpterm,
+ $crstype);
}
$r->print(&footer());
return;
}
sub retrieve_settings {
- my ($cdom,$cnum,$groupname) = @_;
- my %groupinfo;
- my %stored;
+ my ($cdom,$cnum,$groupname,$action) = @_;
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);
- }
+ my $namespace;
+ if ($action eq 'reenable') {
+ $namespace = 'deleted_groups';
+ } else {
+ $namespace = 'coursegroups';
+ }
+ %curr_groups = &Apache::longroup::coursegroups($cdom,$cnum,$groupname,
+ $namespace);
+
+ return if (!%curr_groups);
+
+ my %groupinfo =
+ &Apache::longroup::get_group_settings($curr_groups{$groupname});
+
+ my %stored;
+
+ $stored{'description'} =
+ &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'};
+ $stored{'quota'} = $groupinfo{'quota'};
+
+ 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'}}))) {
+ if (ref($groupinfo{'autosec'}{$role}) eq 'ARRAY') {
+ foreach my $section (@{$groupinfo{'autosec'}{$role}}) {
+
+ push (@{$stored{'sec_'.$role}},$section);
+ }
+ if (@{$groupinfo{'autosec'}{$role}} > 0) {
+ push(@{$stored{'autorole'}},$role);
+ }
}
- }
+ }
}
return %stored;
}
sub display_control {
- my ($r,$cdom,$cnum,$tabcol,$action,$state,$page,$sectioncount,$groupname,
+ my ($r,$cdom,$cnum,$action,$state,$page,$sectioncount,$groupname,
$description,$functions,$tools,$toolprivs,$fixedprivs,$startdate,
- $enddate,$users,$userdata,$idx,$memchg,$usertools,$function,
- $view_permission,$manage_permission,$stored,$granularity,$specificity,
- $types,$roles,$sections,$states,$navbuttons,$rowColor1,$rowColor2)=@_;
+ $enddate,$users,$userdata,$idx,$memchg,$usertools,
+ $view_permission,$manage_permission,$stored,$granularity,$quota,
+ $specificity,$types,$roles,$sections,$states,$navbuttons,
+ $gpterm,$ucgpterm,$crstype) = @_;
if ($action eq 'create') {
if ($state eq 'pick_name') {
- &general_settings_form($r,$cdom,$cnum,$action,$tabcol,$state,$page,
+ &general_settings_form($r,$cdom,$cnum,$action,$state,$page,
$functions,$tools,$toolprivs,$fixedprivs,
$sectioncount,$stored,$states,$navbuttons,
- $rowColor1,$rowColor2);
+ $gpterm,$ucgpterm,$crstype);
} elsif ($state eq 'pick_members') {
- &choose_members_form($r,$cdom,$cnum,$tabcol,$action,$state,$page,
- $groupname,$description,$granularity,
+ &choose_members_form($r,$cdom,$cnum,$action,$state,$page,
+ $groupname,$description,$granularity,$quota,
$startdate,$enddate,$tools,$fixedprivs,
$toolprivs,$functions,$users,$userdata,$idx,
- $stored,$states,$navbuttons,$rowColor1,
- $rowColor2);
+ $stored,$states,$navbuttons,$gpterm,$ucgpterm,
+ $crstype);
} elsif ($state eq 'pick_privs') {
- &choose_privs_form($r,$cdom,$cnum,$tabcol,$action,$state,$page,
+ &choose_privs_form($r,$cdom,$cnum,$action,$state,$page,
$startdate,$enddate,$tools,$functions,
$toolprivs,$fixedprivs,$userdata,$usertools,
$idx,$states,$stored,$sectioncount,$navbuttons,
- $rowColor1,$rowColor2);
+ $gpterm,$ucgpterm,$crstype);
} elsif ($state eq 'result') {
- &process_request($r,$cdom,$cnum,$tabcol,$action,$state,$page,
+ &process_request($r,$cdom,$cnum,$action,$state,$page,
$groupname,$description,$specificity,$userdata,
$startdate,$enddate,$tools,$functions,
$toolprivs,$usertools,$idx,$types,$roles,
$sections,$states,$navbuttons,$memchg,
- $sectioncount,$stored,$rowColor1,$rowColor2);
+ $sectioncount,$stored,$gpterm,$ucgpterm,$crstype);
}
} elsif ($action eq 'modify') {
my $groupname = $env{'form.groupname'};
- if ($state eq 'pick_group') {
- &display_groups($r,$cdom,$cnum,$function,$tabcol,$functions,$idx,
- $view_permission,$manage_permission,$action,
- $rowColor1,$rowColor2);
- } elsif ($state eq 'pick_task') {
- &modify_menu($r,$groupname,$page);
+ if ($state eq 'pick_task') {
+ &modify_menu($r,$groupname,$page,$gpterm);
} elsif ($state eq 'change_settings') {
- &general_settings_form($r,$cdom,$cnum,$action,$tabcol,$state,$page,
+ &general_settings_form($r,$cdom,$cnum,$action,$state,$page,
$functions,$tools,$toolprivs,$fixedprivs,
$sectioncount,$stored,$states,$navbuttons,
- $rowColor1,$rowColor2);
+ $gpterm,$ucgpterm,$crstype);
} elsif ($state eq 'change_members') {
- &change_members_form($r,$cdom,$cnum,$tabcol,$action,$state,$page,
+ &change_members_form($r,$cdom,$cnum,$action,$state,$page,
$groupname,$description,$startdate,$enddate,
$tools,$fixedprivs,$functions,$users,
- $userdata,$granularity,$specificity,$idx,
- $states,$navbuttons,$rowColor1,$rowColor2);
+ $userdata,$granularity,$quota,$specificity,
+ $idx,$states,$navbuttons,$gpterm,$ucgpterm);
} elsif ($state eq 'add_members') {
- &add_members_form($r,$tabcol,$action,$state,$page,$startdate,
+ &add_members_form($r,$cdom,$cnum,$action,$state,$page,$startdate,
$enddate,$groupname,$description,$granularity,
- $sectioncount,$tools,$functions,$stored,$states,
- $navbuttons,$rowColor1,$rowColor2);
+ $quota,$sectioncount,$tools,$functions,$stored,
+ $states,$navbuttons,$gpterm,$ucgpterm);
} elsif ($state eq 'pick_members') {
- &choose_members_form($r,$cdom,$cnum,$tabcol,$action,$state,$page,
- $groupname,$description,$granularity,
+ &choose_members_form($r,$cdom,$cnum,$action,$state,$page,
+ $groupname,$description,$granularity,$quota,
$startdate,$enddate,$tools,$fixedprivs,
$toolprivs,$functions,$users,$userdata,$idx,
- $stored,$states,$navbuttons,$rowColor1,
- $rowColor2);
+ $stored,$states,$navbuttons,$gpterm,$ucgpterm,
+ $crstype);
} elsif ($state eq 'pick_privs') {
- &choose_privs_form($r,$cdom,$cnum,$tabcol,$action,$state,$page,
+ &choose_privs_form($r,$cdom,$cnum,$action,$state,$page,
$startdate,$enddate,$tools,$functions,
$toolprivs,$fixedprivs,$userdata,$usertools,
$idx,$states,$stored,$sectioncount,$navbuttons,
- $rowColor1,$rowColor2);
+ $gpterm,$ucgpterm,$crstype);
} elsif ($state eq 'change_privs') {
- &change_privs_form($r,$cdom,$cnum,$tabcol,$action,$state,$page,
+ &change_privs_form($r,$cdom,$cnum,$action,$state,$page,
$startdate,$enddate,$tools,$functions,
$toolprivs,$fixedprivs,$userdata,$usertools,
$memchg,$idx,$states,$stored,$sectioncount,
- $navbuttons,$rowColor1,$rowColor2);
+ $navbuttons,$gpterm,$ucgpterm);
} elsif ($state eq 'chgresult' || $state eq 'memresult' ||
$state eq 'addresult') {
- &process_request($r,$cdom,$cnum,$tabcol,$action,$state,$page,
+ &process_request($r,$cdom,$cnum,$action,$state,$page,
$groupname,$description,$specificity,$userdata,
$startdate,$enddate,$tools,$functions,
$toolprivs,$usertools,$idx,$types,$roles,
$sections,$states,$navbuttons,$memchg,
- $sectioncount,$stored,$rowColor1,$rowColor2);
+ $sectioncount,$stored,$gpterm,$ucgpterm,$crstype);
+ }
+ } elsif ($action eq 'delete') {
+ my %stored = &retrieve_settings($cdom,$cnum,$groupname,$action);
+ if ($state eq 'verify') {
+ &verify_delete($r,$groupname,$state,$action,$page,$states,
+ \%stored);
+ } elsif ($state eq 'result') {
+ &delete_group($r,$cdom,$cnum,$groupname);
+ }
+ } elsif ($action eq 'reenable') {
+ my %stored = &retrieve_settings($cdom,$cnum,$groupname,$action);
+ if ($state eq 'verify') {
+ &verify_reenable($r,$groupname,$state,$action,$page,$states,
+ \%stored);
+ } elsif ($state eq 'result') {
+ &reenable_group($r,$cdom,$cnum,$groupname);
+ }
+ }
+}
+
+sub verify_delete {
+ my ($r,$groupname,$formname,$action,$page,$states,$stored) = @_;
+ $r->print(&Apache::lonhtmlcommon::echo_form_input([]));
+ $r->print(&mt('You have requested deletion of the group [_1].'
+ ,''.$stored->{'description'}.' ').
+ ' '.&mt('When a group is deleted the following occurs:').''.
+ ''.&mt('All group membership is terminated.').' '.
+ ''.&mt('The group ceases to be available either for viewing or for modification of group settings and membership.').' '.
+ ''.&mt('The group folder is removed from the folder containing it - normally this is the "Course Groups" folder which contains folders for all groups in the course.').' '.
+ ' '.&mt('Although a deleted group is no longer accessible, the group name used for the group will be reserved, and will not be available for assignment to a new group in the same course in the future.'));
+ my $prevtext = &mt('Go back');
+ my $nexttext = &mt('Delete group');
+ my $prev;
+ if ($env{'form.refpage'} eq 'cusr') {
+ $prev = 'view';
+ }
+ &display_navbuttons($r,$formname,$prev,$prevtext,
+ $$states{$action}[$page+1],$nexttext);
+ return;
+}
+
+sub delete_group {
+ my ($r,$cdom,$cnum,$groupname) = @_;
+ my %membership = &Apache::lonnet::get_group_membership($cdom,$cnum,
+ $groupname);
+ my $now = time;
+ my $num_users = 0;
+ my $num_fail = 0;
+ my $num_ok = 0;
+ my @deleted;
+ my @undeleted;
+ my %usersettings;
+ my $context = 'deletegroup';
+ foreach my $key (sort(keys(%membership))) {
+ if ($key =~ /^\Q$groupname\E:([^:]+:[^:]+)$/) {
+ my $user = $1;
+ my($end,$start,$userprivs) = split(/:/,$membership{$key},3);
+ if ($start != -1) {
+ $num_users ++;
+ $usersettings{$groupname.':'.$user} = $now.':-1:'.$userprivs;
+ if (&Apache::lonnet::modify_group_roles($cdom,$cnum,
+ $groupname,$user,
+ $now,'-1',$userprivs,
+ '',$context)
+ eq 'ok') {
+ $num_ok ++;
+ push(@deleted,$user);
+ } else {
+ push(@undeleted,$user);
+ $num_fail ++;
+ }
+ }
+ }
+ }
+ if ($num_ok > 0) {
+ my $roster_result =
+ &Apache::lonnet::modify_coursegroup_membership($cdom,$cnum,
+ \%usersettings);
+ }
+ if ($num_fail > 0) {
+ $r->print(''
+ .&mt('Group deletion failed because deletion of [_1] out of [_2] members failed.'
+ ,$num_fail,$num_users)
+ .'
');
+
+ } else {
+ my ($result,$message) =
+ &Apache::lonnet::toggle_coursegroup_status($cdom,$cnum,
+ $groupname,'delete');
+ if ($result eq 'ok') {
+ my $outcome = &modify_folders($cdom,$cnum,$groupname);
+ if ($outcome eq '') {
+ $r->print(''
+ .&mt('Group successfully deleted.')
+ .'
');
+ } else {
+ $r->print(''
+ .&mt("Although the group was deleted, an error occurred when removing"
+ ." the group's folder from the 'Course Groups' folder: [_1]",$outcome)
+ .'
');
+ }
+ } else {
+ $r->print(''
+ .&mt('Group deletion failed.')
+ .'
');
+ }
+ }
+ return;
+}
+
+sub reenable_folder {
+ my ($cdom,$cnum,$groupname,$description) = @_;
+ my $outcome;
+ my $crspath = '/uploaded/'.$cdom.'/'.$cnum.'/';
+ my $allgrpsmap = $crspath.'group_allfolders.sequence';
+ my $foldertitle = &mt('Course Folder -[_1]',$description);
+ my $mapurl = $crspath.'group_folder_'.
+ $groupname.'.sequence';
+ my ($errtext,$fatal)=&LONCAPA::map::mapread($allgrpsmap);
+ if ($fatal) {
+ $outcome=''
+ .&mt('An error occurred when reading contents of parent folder to group:')
+ ." ($allgrpsmap): $errtext"
+ .'
';
+ } else {
+ my $idx=&LONCAPA::map::getresidx($mapurl);
+ $LONCAPA::map::resources[$idx] = $foldertitle.':'.$mapurl.
+ ':false:normal:res';
+ $LONCAPA::map::order[1+$#LONCAPA::map::order]=$idx;
+ my ($outtext,$errtext) = &LONCAPA::map::storemap($allgrpsmap,1);
+ if ($errtext) {
+ $outcome=''
+ .&mt('An error occurred when saving updated parent folder to group:'
+ ," $allgrpsmap - $errtext")
+ .'
';
+ } else {
+ my ($furl,$ferr) =
+ &Apache::lonuserstate::readmap($cdom.'/'.$cnum);
+ }
+ }
+ return $outcome;
+}
+
+sub modify_folders {
+ my ($cdom,$cnum,$groupname) = @_;
+ my ($outcome,$groupmap,$groupmapres,$map,$id,$src);
+ my $navmap = Apache::lonnavmaps::navmap->new();
+ if (!defined($navmap)) {
+ $outcome = ''.
+ &mt('Error reading course contents.').' '.
+ &mt('You need to re-initialize the course.').
+ '
';
+ return $outcome;
+ }
+ $groupmap = '/uploaded/'.$cdom.'/'.$cnum.'/'.'group_folder_'.
+ $groupname.'.sequence';
+ $groupmapres = $navmap->getResourceByUrl($groupmap);
+ if ($groupmapres) {
+ ($map,$id,$src)=&Apache::lonnet::decode_symb($groupmapres->symb());
+ }
+ undef($navmap);
+ if ($map) {
+ $map = '/'.$map;
+ my ($errtext,$fatal) = &LONCAPA::map::mapread($map);
+ if ($fatal) {
+ $outcome=''
+ .&mt('An error occurred when reading contents of parent folder to group:')
+ ." ($map): $errtext"
+ .'
';
+ } else {
+ my $idx = 0;
+ my $grpidx;
+ foreach my $item (@LONCAPA::map::order) {
+ my ($name,$url)=split(/\:/,$LONCAPA::map::resources[$item]);
+ $url=&LONCAPA::map::qtescape($url);
+ if ($url eq $groupmap) {
+ $grpidx = $idx;
+ last;
+ } else {
+ $idx++;
+ }
+ }
+
+ if ($grpidx ne '') {
+ &LONCAPA::map::makezombie($LONCAPA::map::order[$grpidx]);
+ for (my $i=$grpidx;$i<$#LONCAPA::map::order;$i++) {
+ $LONCAPA::map::order[$i] = $LONCAPA::map::order[$i+1];
+ }
+ $#LONCAPA::map::order--;
+ my ($outtext,$errtext) = &LONCAPA::map::storemap($map,1);
+ if ($errtext) {
+ $outcome=''
+ .&mt('An error occurred when saving updated parent folder to group:')
+ ." $map - $errtext"
+ .'
';
+ } else {
+ my ($furl,$ferr) =
+ &Apache::lonuserstate::readmap($cdom.'/'.$cnum);
+ }
+ }
}
}
+ return $outcome;
+}
+
+sub verify_reenable {
+ my ($r,$groupname,$formname,$action,$page,$states,$stored) = @_;
+ $r->print(&Apache::lonhtmlcommon::echo_form_input([]));
+ $r->print(&mt('You have requested enabling the previously deleted group [_1].'
+ ,''.$stored->{'description'}.' ').
+ ' '.&mt('When a deleted group is re-enabled the following occurs:').''.
+ ''.&mt('Group settings and membership at the time the group was deleted are reinstated.').' '.
+ ''.&mt('A group folder is added to the "Course Groups" folder which contains folders for all groups in the course.').' ');
+ my $prevtext = &mt('Go back');
+ my $nexttext = &mt('Reenable group');
+ my $prev;
+ if ($env{'form.refpage'} eq 'cusr') {
+ $prev = 'view';
+ }
+ &display_navbuttons($r,$formname,$prev,$prevtext,
+ $$states{$action}[$page+1],$nexttext);
+ return;
+}
+
+sub reenable_group {
+ my ($r,$cdom,$cnum,$groupname) = @_;
+ my %groups =
+ &Apache::longroup::coursegroups($cdom,$cnum,$groupname,
+ 'deleted_groups');
+ if (keys(%groups) == 0) {
+ $r->print(&mt('The group [_1] was not re-enabled, because it is not a deleted group.[_2]Perhaps it has already been re-enabled?',''.$groupname.' '),' ');
+ return;
+ }
+ my %groupinfo =
+ &Apache::longroup::get_group_settings($groups{$groupname});
+ my $defstart = $groupinfo{'startdate'};
+ my $defend = $groupinfo{'enddate'};
+ my $showstart = &Apache::lonlocal::locallocaltime($defstart);
+ my $showend;
+ if ($defend == 0) {
+ $showend = &mt('No end date set');
+ } else {
+ $showend = &Apache::lonlocal::locallocaltime($defend);
+ }
+ my $description = &unescape($groupinfo{'description'});
+ my $num_users = 0;
+ my $num_ok = 0;
+ my $num_fail = 0;
+ my $context = 'reenablegroup';
+ my (%usersettings,@enabled,@unenabled);
+ my ($result,$message) =
+ &Apache::lonnet::toggle_coursegroup_status($cdom,$cnum,$groupname,
+ 'reenable');
+ if ($result eq 'ok') {
+ my %membership = &Apache::lonnet::get_group_membership($cdom,$cnum,
+ $groupname);
+ foreach my $key (sort(keys(%membership))) {
+ if ($key =~ /^\Q$groupname\E:([^:]+:[^:]+)$/) {
+ my $user = $1;
+ my($end,$start,$userprivs) = split(/:/,$membership{$key},3);
+ if (($start == -1) && ($end == $groupinfo{'modified'})) {
+ $num_users ++;
+ $usersettings{$groupname.':'.$user} = $defend.':'.
+ $defstart.':'.
+ $userprivs;
+ if (&Apache::lonnet::modify_group_roles($cdom,$cnum,
+ $groupname,$user,
+ $defend,$defstart,
+ $userprivs,'',
+$context) eq 'ok') {
+ $num_ok ++;
+ push(@enabled,$user);
+ } else {
+ push(@unenabled,$user);
+ $num_fail ++;
+ }
+ }
+ }
+ }
+ if ($num_users > 0) {
+ if ($num_ok > 0) {
+ my $roster_result =
+ &Apache::lonnet::modify_coursegroup_membership($cdom,$cnum,
+ \%usersettings);
+ if ($roster_result eq 'ok') {
+ $r->print(''
+ .&mt('Membership reinstated for [quant,_1,user], each with start and end dates for group access set to defaults: [_2] and [_3]',$num_ok,$showstart,$showend)
+ .'
');
+ }
+ } else {
+ $r->print(''
+ .&mt('A problem occurred when trying to reinstate [_1] of the [_2] members of the pre-existing group.',$num_fail,$num_users)
+ .'
');
+ }
+ } else {
+ $r->print(''
+ .&mt('There were no group members to reinstate, as none were removed when the group was deleted.')
+ .'
');
+ }
+ my $outcome = &reenable_folder($cdom,$cnum,$groupname,$description);
+ if ($outcome eq '') {
+ $r->print(''
+ .&mt('Group successfully re-enabled.')
+ .'
');
+ } else {
+ $r->print(''
+ .&mt("Although the group was re-enabled, an error occurred when adding the group's folder to the 'Course Groups' folder: [_1]",$outcome)
+ .'
');
+ }
+ } else {
+ $r->print(''
+ .&mt('Re-enabling group failed.')
+ .'
');
+ }
+ return;
}
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,$loaditems) = @_;
+ my $start_page=
+ &Apache::loncommon::start_page($bodytitle,
+ '',
+ {'add_entries' => $loaditems,});
my $output = <<"END";
-$html
-
-$title
-
-
-$bodytag
-
-