');
}
}
} else {
- $r->print(&mt('You are not currently a member of any '.
- 'active [_1]s in this [_2]',$gpterm,
- lc($crstype)));
+ $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,$state,$cdom,$cnum,$function,$tabcol,$functions,$idx,
- $view_permission,$manage_permission,$rowColor1,$rowColor2,$gpterm,
- $ucgpterm,$crstype) = @_;
+ my ($r,$action,$state,$cdom,$cnum,$functions,$idx,$view_permission,
+ $manage_permission,$gpterm,$ucgpterm,$crstype) = @_;
my %sectioncount = ();
my @tools = ();
my @types = ();
@@ -407,11 +460,9 @@ sub group_administration {
if ($state eq '') {
if (defined($env{'form.groupname'})) {
$state = 'pick_task';
- } else {
- $state = 'pick_group';
}
} else {
- %stored = &retrieve_settings($cdom,$cnum,$groupname);
+ %stored = &retrieve_settings($cdom,$cnum,$groupname,$action);
if (ref($stored{'types'}) eq 'ARRAY') {
@types = @{$stored{'types'}};
}
@@ -486,7 +537,7 @@ sub group_administration {
if (ref($stored{'autorole'}) eq 'ARRAY') {
foreach my $role (@{$stored{'autorole'}}) {
- unless ($role eq 'cc') {
+ unless (($role eq 'cc') || ($role eq 'co')) {
$elements{'modify'}{'change_settings'}{'sec_'.$role} =
'selectbox';
}
@@ -502,11 +553,9 @@ sub group_administration {
(($action eq 'modify') && (($state eq 'change_settings') ||
($state eq 'add_members')))) {
%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';
- }
+ $elements{'create'}{'pick_name'}{'sectionpick'} = 'selectbox';
+ $elements{'modify'}{'change_mapping'}{'sectionpick'} = 'selectbox';
+ $elements{'modify'}{'add_members'}{'sectionpick'} = 'selectbox';
}
if (($action eq 'create') ||
@@ -519,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);
- }
}
}
@@ -562,7 +608,7 @@ sub group_administration {
$num_reenable ++;
next;
} elsif (($start > $now)) {
- $num_activate = 1;
+ $num_activate ++;
next;
} else {
$num_expire ++;
@@ -731,15 +777,15 @@ sub group_administration {
my $space_trim = '/^\s*|\s*\$/g,""';
my $float_check = '/^([0-9]*\.?[0-9]*)$/';
$validate_script = '
- var newquota = document.'.$state.'.quota.value;
+ var newquota = new String(document.'.$state.'.quota.value);
newquota.replace('.$space_trim.');
if (newquota == "" ) {
document.'.$state.'.quota.value = 0;
- newquota = 0;
+ newquota = "0";
}
- var maxposs = '.$maxposs.';
+ 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.");
+ alert("The group portfolio 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.';
@@ -758,7 +804,7 @@ sub group_administration {
}
}
if (warn_zero == 1) {
- alert("You have indicated that the file repository should be enabled, but you have set the respository quota to 0 Mb.\nThis will prevent any upload of files.\nPlease set a value or disable the repository feature.");
+ alert("You have indicated that the group portfolio should be enabled, but you have set the respository quota to 0 Mb.\nThis will prevent any upload of files.\nPlease set a value or disable the repository feature.");
return;
}
}
@@ -788,7 +834,9 @@ function changeSort(caller) {
my %states = ();
my %branchstates = ();
@{$states{'create'}} = ('pick_name','pick_members','pick_privs','result');
- @{$states{'modify'}} = ('pick_group','pick_task');
+ @{$states{'modify'}} = ('pick_task');
+ @{$states{'delete'}} = ('verify','result');
+ @{$states{'reenable'}} = ('verify','result');
@{$branchstates{'noprivs'}} = ('result');
@{$branchstates{'settings'}} = ('change_settings','chgresult');
@{$branchstates{'members'}} = ('change_members','change_privs','memresult');
@@ -799,7 +847,7 @@ function changeSort(caller) {
push (@{$states{$action}},@{$branchstates{$env{'form.branch'}}});
}
- if (($action eq 'create') || ($action eq 'modify')) {
+ if (($action eq 'create') || ($action eq 'modify') || ($action eq 'delete') || ($action eq 'reenable')) {
my $done = 0;
my $i=0;
while ($i<@{$states{$action}} && !$done) {
@@ -812,20 +860,30 @@ function changeSort(caller) {
}
my $loaditems = &onload_action($action,$state);
- my $crumbtitle = "$crstype $ucgpterm".'s';
- $r->print(&header("$crumbtitle Manager",
+ $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=>"$crumbtitle",
- 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 = ();
@@ -836,7 +894,6 @@ function changeSort(caller) {
result => 'Creation Complete',
);
%{$trail{'modify'}} = &Apache::lonlocal::texthash(
- pick_group => $ucgpterm.'s',
pick_task => 'Choose Task',
change_settings => "$ucgpterm Settings",
change_members => 'Modify/Delete Members',
@@ -849,61 +906,77 @@ 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',
+ gtns => 'Next',#'Go to next step',
+ gtps => 'Back',#'Go to previous step',
crgr => 'Create '.$gpterm,
- mose => 'Modify settings',
- gtpp => 'Go to previous page',
+ mose => 'Save',#'Modify settings',
+ gtpp => 'Back',#'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
- ("$crumbtitle 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,
\%users,\%userdata,$idx,\%memchg,\%usertools,
- $function,$view_permission,$manage_permission,
+ $view_permission,$manage_permission,
\%stored,$granularity,$quota,$specificity,\@types,\@roles,
- \@sections,\%states,\%navbuttons,$rowColor1,$rowColor2,
- $gpterm,$ucgpterm,$crstype);
+ \@sections,\%states,\%navbuttons,$gpterm,$ucgpterm,
+ $crstype);
last;
} else {
- if (($state eq '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 $gpterm".'s'});
- my $crumbtitle = "$crstype $ucgpterm".'s Manager';
$r->print(&Apache::lonhtmlcommon::breadcrumbs
- (&mt($crumbtitle)));
+ ('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 %curr_groups = &Apache::longroup::coursegroups($cdom,$cnum,$groupname);
+ my ($cdom,$cnum,$groupname,$action) = @_;
+ my %curr_groups;
+ 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);
@@ -948,6 +1021,7 @@ sub retrieve_settings {
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) {
@@ -960,100 +1034,427 @@ sub retrieve_settings {
}
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,
+ $enddate,$users,$userdata,$idx,$memchg,$usertools,
$view_permission,$manage_permission,$stored,$granularity,$quota,
- $specificity,$types,$roles,$sections,$states,$navbuttons,$rowColor1,
- $rowColor2,$gpterm,$ucgpterm,$crstype) = @_;
+ $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);
+ $gpterm,$ucgpterm,$crstype);
} elsif ($state eq 'pick_members') {
- &choose_members_form($r,$cdom,$cnum,$tabcol,$action,$state,$page,
+ &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,$gpterm,$ucgpterm,$crstype);
+ $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);
+ $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,
- $gpterm,$ucgpterm,$crstype);
+ $sectioncount,$stored,$gpterm,$ucgpterm,$crstype);
}
} elsif ($action eq 'modify') {
my $groupname = $env{'form.groupname'};
- if ($state eq 'pick_group') {
- &display_groups($r,$cdom,$cnum,$functions,$idx,$view_permission,
- $manage_permission,$action,$state,$gpterm,
- $ucgpterm,$crstype);
- } elsif ($state eq 'pick_task') {
+ 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);
+ $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,$quota,$specificity,
- $idx,$states,$navbuttons,$rowColor1,$rowColor2,
- $gpterm,$ucgpterm);
+ $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,
$quota,$sectioncount,$tools,$functions,$stored,
- $states,$navbuttons,$rowColor1,$rowColor2,$gpterm,
- $ucgpterm);
+ $states,$navbuttons,$gpterm,$ucgpterm,$crstype);
} elsif ($state eq 'pick_members') {
- &choose_members_form($r,$cdom,$cnum,$tabcol,$action,$state,$page,
+ &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,$gpterm,$ucgpterm,$crstype);
+ $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);
+ $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,$gpterm,
- $ucgpterm);
+ $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,
- $gpterm,$ucgpterm,$crstype);
+ $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,$crstype);
+ } elsif ($state eq 'result') {
+ &delete_group($r,$cdom,$cnum,$groupname,$crstype);
+ }
+ } 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,$crstype);
+ } elsif ($state eq 'result') {
+ &reenable_group($r,$cdom,$cnum,$groupname,$crstype);
+ }
+ }
+}
+
+sub verify_delete {
+ my ($r,$groupname,$formname,$action,$page,$states,$stored,$crstype) = @_;
+ $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.').'
');
+ if ($crstype eq 'Community') {
+ $r->print( '
'.&mt("The group folder is removed from the folder containing it - normally this is the 'Community Groups' folder which contains folders for all groups in the community.").'
'.
+ '
'.&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 community in the future."));
+ } else {
+ $r->print( '
'.&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,$crstype) = @_;
+ 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,$crstype);
+ if ($outcome eq '') {
+ my $message = &Apache::lonhtmlcommon::confirm_success(&mt('Group successfully deleted.'));
+ $message = &Apache::loncommon::confirmwrapper($message);
+ $r->print($message);
+ } else {
+ $r->print('
');
+ if ($crstype eq 'Community') {
+ $r->print(&mt("Although the group was deleted, an error occurred when removing the group's folder from the 'Community Groups' folder: [_1]",$outcome));
+ } 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));
+ }
+ $r->print('
');
+ }
+ } else {
+ my $msg = &Apache::lonhtmlcommon::confirm_success(&mt('Group deletion failed.'),1);
+ $msg = &Apache::loncommon::confirmwrapper($msg);
+ $r->print($msg);
}
}
+ return;
+}
+
+sub reenable_folder {
+ my ($cdom,$cnum,$groupname,$description,$crstype) = @_;
+ my $outcome;
+ my $crspath = '/uploaded/'.$cdom.'/'.$cnum.'/';
+ my $allgrpsmap = $crspath.'group_allfolders.sequence';
+ my $foldertitle;
+ if ($crstype eq 'Community') {
+ $foldertitle = &mt("Community Folder -[_1]",$description);
+ } else {
+ $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,$crstype) = @_;
+ my ($outcome,$groupmap,$groupmapres,$map,$id,$src);
+ my $navmap = Apache::lonnavmaps::navmap->new();
+ if (!defined($navmap)) {
+ $outcome = '
';
+ if ($crstype eq 'Community') {
+ $outcome .= &mt("Error reading community contents.").' '.
+ &mt("You need to re-initialize the community.");
+ } else {
+ $outcome .= &mt("Error reading course contents.").' '.
+ &mt("You need to re-initialize the course.");
+ }
+ $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,$crstype) = @_;
+ $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.').'
');
+ if ($crstype eq 'Community') {
+ $r->print(&mt("A group folder is added to the 'Community Groups' folder which contains folders for all groups in the community."));
+ } else {
+ $r->print(&mt("A group folder is added to the 'Course Groups' folder which contains folders for all groups in the course."));
+ }
+ $r->print('
');
+ 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,$crstype) = @_;
+ 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.')
+ .'
');
+ if ($crstype eq 'Community') {
+ $r->print(&mt("Although the group was re-enabled, an error occurred when adding the group's folder to the 'Community Groups' folder: [_1]",$outcome));
+ } 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));
+ }
+ $r->print('
');
+ }
+ } else {
+ my $message = &Apache::lonhtmlcommon::confirm_success(&mt('Re-enabling group failed.'),1);
+ $message = &Apache::loncommon::confirmwrapper($message);
+ $r->print($message);
+ }
+ return;
}
sub header {
@@ -1065,7 +1466,7 @@ sub header {
{'add_entries' => $loaditems,});
my $output = <<"END";
$start_page
-