Annotation of loncom/interface/loncoursegroups.pm, revision 1.128
1.24 www 1: # The LearningOnline Network with CAPA
2: #
1.128 ! raeburn 3: # $Id: loncoursegroups.pm,v 1.127 2014/12/11 01:19:07 raeburn Exp $
1.1 raeburn 4: #
5: # Copyright Michigan State University Board of Trustees
6: #
7: # This file is part of the LearningOnline Network with CAPA (LON-CAPA).
8: #
9: # LON-CAPA is free software; you can redistribute it and/or modify
10: # it under the terms of the GNU General Public License as published by
11: # the Free Software Foundation; either version 2 of the License, or
12: # (at your option) any later version.
13: #
14: # LON-CAPA is distributed in the hope that it will be useful,
15: # but WITHOUT ANY WARRANTY; without even the implied warranty of
16: # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17: # GNU General Public License for more details.
18: #
19: # You should have received a copy of the GNU General Public License
20: # along with LON-CAPA; if not, write to the Free Software
21: # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
22: #
23: # /home/httpd/html/adm/gpl.txt
24: #
25: # http://www.lon-capa.org/
26: #
27:
28: package Apache::loncoursegroups;
29:
30: use strict;
31: use Apache::lonnet;
1.63 albertel 32: use Apache::loncommon();
33: use Apache::lonhtmlcommon();
1.121 raeburn 34: use Apache::lonhtmlgateway;
1.1 raeburn 35: use Apache::lonlocal;
1.63 albertel 36: use Apache::lonnavmaps();
37: use Apache::longroup();
38: use Apache::portfolio();
1.1 raeburn 39: use Apache::Constants qw(:common :http);
1.63 albertel 40: use LONCAPA::map();
1.24 www 41: use lib '/home/httpd/lib/perl/';
42: use LONCAPA;
1.1 raeburn 43:
44: sub handler {
45: my ($r) = @_;
1.3 raeburn 46:
1.1 raeburn 47: &Apache::loncommon::content_type($r,'text/html');
48: $r->send_http_header;
1.15 albertel 49:
1.1 raeburn 50: if ($r->header_only) {
51: return OK;
52: }
53:
54: # Needs to be in a course
55: if (! ($env{'request.course.fn'})) {
56: # Not in a course
57: $env{'user.error.msg'}=
1.104 raeburn 58: "/adm/coursegroups:mdg:0:0:Cannot edit or view course/community groups";
1.1 raeburn 59: return HTTP_NOT_ACCEPTABLE;
60: }
61:
1.3 raeburn 62: &Apache::loncommon::get_unprocessed_cgi($ENV{'QUERY_STRING'},
1.5 raeburn 63: ['action','refpage','state','groupname','branch']);
1.3 raeburn 64: my $cdom = $env{'course.'.$env{'request.course.id'}.'.domain'};
65: my $cnum = $env{'course.'.$env{'request.course.id'}.'.num'};
66:
1.1 raeburn 67: my $view_permission =
1.52 raeburn 68: &Apache::lonnet::allowed('vcg',$env{'request.course.id'}.($env{'request.course.sec'}?'/'.$env{'request.course.sec'}:''));
1.1 raeburn 69: my $manage_permission =
1.52 raeburn 70: &Apache::lonnet::allowed('mdg',$env{'request.course.id'}.($env{'request.course.sec'}?'/'.$env{'request.course.sec'}:''));
1.3 raeburn 71: &Apache::lonhtmlcommon::clear_breadcrumbs();
72:
1.29 raeburn 73: my $gpterm = &Apache::loncommon::group_term();
74: my $ucgpterm = $gpterm;
75: $ucgpterm =~ s/^(\w)/uc($1)/e;
76: my $crstype = &Apache::loncommon::course_type();
77:
1.3 raeburn 78: my %functions = (
1.92 schafran 79: email => 'Send Messages',
1.81 schafran 80: discussion => 'Discussion Boards',
1.94 hauer 81: chat => 'Chat Room',
1.96 weissno 82: files => 'Group Portfolio',
1.81 schafran 83: roster => 'Membership Roster',
1.29 raeburn 84: homepage => $ucgpterm.' home page',
1.3 raeburn 85: );
86:
87: my %idx = ();
88: $idx{id} = &Apache::loncoursedata::CL_ID();
89: $idx{fullname} = &Apache::loncoursedata::CL_FULLNAME();
90: $idx{udom} = &Apache::loncoursedata::CL_SDOM();
91: $idx{uname} = &Apache::loncoursedata::CL_SNAME();
1.31 albertel 92: $idx{section} = &Apache::loncoursedata::CL_SECTION();
1.3 raeburn 93:
94: my $action = $env{'form.action'};
1.21 raeburn 95: my $state = $env{'form.state'};
1.65 raeburn 96: if ((!defined($action)) || ($action eq 'view') || ($action eq 'modify') || ($action eq 'delete') || ($action eq 'reenable')) {
1.21 raeburn 97: if (!defined($state)) {
98: $state = 'view';
99: }
100: }
1.64 raeburn 101: if ($action eq 'create' || $action eq 'modify' || $action eq 'view' ||
1.65 raeburn 102: $action eq 'delete' || $action eq 'reenable') {
1.3 raeburn 103: if ($view_permission || $manage_permission) {
1.53 raeburn 104: if ($state eq 'view') {
105: &print_main_menu($r,$cdom,$cnum,\%functions,\%idx,
106: $view_permission,$manage_permission,
107: $action,$state,$gpterm,$ucgpterm,$crstype);
108: } else {
109: &group_administration($r,$action,$state,$cdom,$cnum,
110: \%functions,\%idx,$view_permission,
111: $manage_permission,$gpterm,$ucgpterm,
112: $crstype);
113: }
1.3 raeburn 114: } else {
1.79 bisitz 115: $r->print('<div class="LC_warning">'
116: .&mt('You do not have '.$gpterm.' administration '
117: .'privileges in this '.lc($crstype).'.')
118: .'</div>');
1.3 raeburn 119: }
120: } else {
1.39 albertel 121: &print_main_menu($r,$cdom,$cnum,\%functions,\%idx,$view_permission,
122: $manage_permission,$action,$state,$gpterm,$ucgpterm,
123: $crstype);
1.3 raeburn 124: }
125: return OK;
126: }
127:
128: sub print_main_menu {
1.39 albertel 129: my ($r,$cdom,$cnum,$functions,$idx,$view_permission,$manage_permission,
130: $action,$state,$gpterm,$ucgpterm,$crstype) = @_;
1.21 raeburn 131: my $jscript = qq|
132: function changeSort(caller) {
133: document.$state.sortby.value = caller;
134: document.$state.submit();
1.60 raeburn 135: }
136: function openGroupRoster(group,status) {
137: var url = '/adm/grouproster?';
138: url += 'group='+group+'&status='+status+'&ref=popup';
1.112 raeburn 139: var title = 'Group_Membership';
1.60 raeburn 140: var options = 'scrollbars=1,resizable=1,menubar=0';
141: options += ',width=700,height=600';
142: rosterbrowser = open(url,title,options,'1');
143: rosterbrowser.focus();
1.21 raeburn 144: }\n|;
1.95 schafran 145: $r->print(&header('My Space',$jscript,$action,$state));
1.71 raeburn 146: if ($env{'form.refpage'} eq 'cusr') {
1.53 raeburn 147: &Apache::lonhtmlcommon::add_breadcrumb
1.71 raeburn 148: ({href=>"/adm/createuser",
149: text=>"User Management"});
1.53 raeburn 150: }
1.3 raeburn 151: &Apache::lonhtmlcommon::add_breadcrumb
152: ({href=>"/adm/coursegroups",
1.53 raeburn 153: text=>"Groups"});
1.72 raeburn 154: my $helpitem;
155: if ($manage_permission) {
156: $helpitem = 'Creating_Groups';
157: }
158: $r->print(&Apache::lonhtmlcommon::breadcrumbs('Groups',$helpitem));
1.39 albertel 159: &display_groups($r,$cdom,$cnum,$functions,$idx,$view_permission,
160: $manage_permission,$action,$state,$gpterm,$ucgpterm,
161: $crstype);
1.3 raeburn 162: $r->print(&footer());
163: return;
164: }
165:
166: sub display_groups {
1.39 albertel 167: my ($r,$cdom,$cnum,$functions,$idx,$view_permission,
168: $manage_permission,$action,$state,$gpterm,$ucgpterm,$crstype) = @_;
1.3 raeburn 169: my %curr_groups = ();
170: my %grp_info = ();
1.5 raeburn 171: my %actionlinks = (
1.21 raeburn 172: modify => '<a href="/adm/coursegroups?action=modify&refpage='.
1.53 raeburn 173: $env{'form.refpage'}.'&state=pick_task&groupname=',
1.110 raeburn 174: view => '<a href="',
1.5 raeburn 175: delete => '<a href="/adm/coursegroups?action=delete&refpage='.
1.64 raeburn 176: $env{'form.refpage'}.'&state=verify&groupname=',
1.65 raeburn 177: reenable => '<a href="/adm/coursegroups?action=reenable&refpage='.
178: $env{'form.refpage'}.'&state=verify&groupname=',
1.5 raeburn 179: );
1.6 raeburn 180: my %lt = &Apache::lonlocal::texthash(
1.5 raeburn 181: modify => 'Modify',
1.6 raeburn 182: view => 'View',
1.5 raeburn 183: delete => 'Delete',
1.65 raeburn 184: reenable => 'Re-enable',
1.6 raeburn 185: act => 'Action',
1.53 raeburn 186: gname => 'Group Name',
187: desc => 'Group Title',
1.6 raeburn 188: crea => 'Creator',
189: crtd => 'Created',
190: last => 'Last Modified',
1.53 raeburn 191: func => 'Collaborative Tools',
1.122 raeburn 192: quot => 'Quota (MB)',
1.6 raeburn 193: memb => 'Members',
194: file => 'Files',
195: dibd => 'Discussion Boards',
1.29 raeburn 196: dius => 'Disk Use (%)',
1.53 raeburn 197: nogr => 'No groups exist.',
198: crng => 'Create a new group',
1.71 raeburn 199: redg => 'Re-enable a deleted group',
1.7 raeburn 200: alth => 'Although your current role has privileges'.
1.62 banghart 201: ' to view any existing groups in this '.
202: lc($crstype).', you do not have privileges '.
1.53 raeburn 203: 'to create new groups.',
1.7 raeburn 204: );
1.3 raeburn 205: if ($view_permission) {
1.5 raeburn 206: if (!defined($action)) {
207: $action = 'view';
208: }
1.71 raeburn 209: my ($status,$reenable_link);
1.65 raeburn 210: if ($action eq 'reenable') {
211: $status = 'deleted_groups';
1.71 raeburn 212: } else {
213: if ($manage_permission) {
214: my %deleted_groups =
215: &Apache::longroup::coursegroups($cdom,$cnum,undef,'deleted_groups');
216: if (keys(%deleted_groups) > 0) {
217: $reenable_link = ' <a href="/adm/coursegroups?action=reenable&refpage='.$env{'form.refpage'}.'">'.$lt{'redg'}.'</a>';
218: }
219: }
1.65 raeburn 220: }
221: my %curr_groups = &Apache::longroup::coursegroups($cdom,$cnum,undef,
222: $status);
1.71 raeburn 223:
1.15 albertel 224: if (%curr_groups) {
1.110 raeburn 225: my $navmap=Apache::lonnavmaps::navmap->new();
226: if (!defined($navmap)) {
227: $r->print('<div class="LC_error">'.
228: &mt('An error occurred retrieving information about resources in the course.').'<br />'.
229: &mt('It is recommended that you [_1]re-initialize the course[_2] and then return to this page.','<a href="/adm/roles?selectrole=1&newrole='.$env{'request.role'}.'&orgurl=%2fadm%2fcoursegroups">','</a>').
230: '</div>');
231: return;
232: }
1.29 raeburn 233: if ($manage_permission) {
1.71 raeburn 234: if ($action ne 'reenable') {
235: $r->print('<br /><a href="/adm/coursegroups?action=create&refpage='.$env{'form.refpage'}.'">'.$lt{'crng'}.'</a>');
236: }
237: if ($reenable_link) {
238: $r->print($reenable_link);
1.53 raeburn 239: }
1.29 raeburn 240: }
1.7 raeburn 241: $r->print('<br /><br />');
1.39 albertel 242: $r->print(&Apache::loncommon::start_data_table().
243: &Apache::loncommon::start_data_table_header_row());
244:
1.4 raeburn 245: $r->print(<<"END");
1.39 albertel 246: <th>$lt{'act'}</th>
247: <th><a href="javascript:changeSort('groupname')">$lt{'gname'}</a></th>
248: <th><a href="javascript:changeSort('description')">$lt{'desc'}</a></th>
249: <th><a href="javascript:changeSort('creator')">$lt{'crea'}</a></th>
250: <th><a href="javascript:changeSort('creation')">$lt{'crtd'}</a></th>
251: <th><a href="javascript:changeSort('modified')">$lt{'last'}</a></th>
252: <th>$lt{'func'}</b></td>
253: <th><a href="javascript:changeSort('quota')">$lt{'quot'}</a></th>
254: <th><a href="javascript:changeSort('totalmembers')">$lt{'memb'}</a></th>
255: <th><a href="javascript:changeSort('totalfiles')">$lt{'file'}</a></th>
256: <th><a href="javascript:changeSort('boards')">$lt{'dibd'}</a></th>
257: <th><a href="javascript:changeSort('diskuse')">$lt{'dius'}</a></th>
1.3 raeburn 258: END
1.39 albertel 259: $r->print(&Apache::loncommon::end_data_table_header_row());
1.4 raeburn 260: my %Sortby = ();
261: foreach my $group (sort(keys(%curr_groups))) {
262: %{$grp_info{$group}} =
1.17 raeburn 263: &Apache::longroup::get_group_settings(
1.3 raeburn 264: $curr_groups{$group});
1.5 raeburn 265: my $members_result = &group_members($cdom,$cnum,$group,
266: \%grp_info);
1.29 raeburn 267: my $port_path = '/userfiles/groups/'.$group.'/portfolio';
268: my $totaldirs = 0;
269: my $totalfiles = 0;
1.74 raeburn 270: &group_files($group,$port_path,\$totalfiles,\$totaldirs);
1.29 raeburn 271: $grp_info{$group}{'totalfiles'} = $totalfiles;
272: $grp_info{$group}{'totaldirs'} = $totaldirs;
1.74 raeburn 273: my $getpropath = 1;
274: my $diskuse = &Apache::lonnet::diskusage($cdom,$cnum,$port_path, $getpropath);
1.29 raeburn 275: if ($grp_info{$group}{'quota'} > 0) {
276: my $pct_use = 0.1 * $diskuse/$grp_info{$group}{'quota'};
277: $grp_info{$group}{'diskuse'} = sprintf("%.0f",$pct_use);
278: } else {
279: $grp_info{$group}{'diskuse'} = 'N/A';
1.33 raeburn 280: }
281: my ($groupboards,$boardshash)=&Apache::longroup::get_group_bbinfo(
282: $cdom,$cnum,$group);
283: $grp_info{$group}{'boards'} = scalar(@{$groupboards});
1.4 raeburn 284: if ($env{'form.sortby'} eq 'groupname') {
285: push(@{$Sortby{$group}},$group);
286: } elsif ($env{'form.sortby'} eq 'description') {
1.29 raeburn 287: push(@{$Sortby{$grp_info{$group}{'description'}}},$group);
1.4 raeburn 288: } elsif ($env{'form.sortby'} eq 'creator') {
289: push(@{$Sortby{$grp_info{$group}{'creator'}}},$group);
290: } elsif ($env{'form.sortby'} eq 'creation') {
291: push(@{$Sortby{$grp_info{$group}{'creation'}}},$group);
292: } elsif ($env{'form.sortby'} eq 'modified') {
293: push(@{$Sortby{$grp_info{$group}{'modified'}}},$group);
294: } elsif ($env{'form.sortby'} eq 'quota') {
295: push(@{$Sortby{$grp_info{$group}{'quota'}}},$group);
296: } elsif ($env{'form.sortby'} eq 'totalmembers') {
297: push(@{$Sortby{$grp_info{$group}{'totalmembers'}}},
1.3 raeburn 298: $group);
1.4 raeburn 299: } elsif ($env{'form.sortby'} eq 'totalfiles') {
1.5 raeburn 300: push(@{$Sortby{$grp_info{$group}{'totalfiles'}}},$group);
1.4 raeburn 301: } elsif ($env{'form.sortby'} eq 'boards') {
302: push(@{$Sortby{$grp_info{$group}{'boards'}}},$group);
303: } elsif ($env{'form.sortby'} eq 'diskuse') {
304: push(@{$Sortby{$grp_info{$group}{'diskuse'}}},$group);
305: } else {
306: push(@{$Sortby{$group}},$group);
307: }
308: }
309: foreach my $key (sort(keys(%Sortby))) {
310: foreach my $group (@{$Sortby{$key}}) {
311: my $description =
1.39 albertel 312: &unescape($grp_info{$group}{'description'});
1.4 raeburn 313: my $creator = $grp_info{$group}{'creator'};
314: my $creation = $grp_info{$group}{'creation'};
315: my $modified = $grp_info{$group}{'modified'};
316: my $quota = $grp_info{$group}{'quota'};
317: my $totalmembers = $grp_info{$group}{'totalmembers'};
318: my $totalfiles = $grp_info{$group}{'totalfiles'};
1.29 raeburn 319: my $totaldirs = $grp_info{$group}{'totaldirs'};
1.4 raeburn 320: my $boards = $grp_info{$group}{'boards'};
321: my $diskuse = $grp_info{$group}{'diskuse'};
322: my $functionality;
1.5 raeburn 323: foreach my $tool (sort(keys(%{$functions}))) {
1.6 raeburn 324: if ($grp_info{$group}{functions}{$tool} eq 'on') {
1.4 raeburn 325: $functionality .= ' '.$tool;
1.3 raeburn 326: }
327: }
1.4 raeburn 328: if (!$functionality) {
1.6 raeburn 329: $functionality = &mt('None available');
1.4 raeburn 330: }
1.128 ! raeburn 331: my $link;
1.65 raeburn 332: if ($action eq 'modify' || $action eq 'delete' ||
333: $action eq 'reenable') {
1.128 ! raeburn 334: $link = $actionlinks{$action}.$group.'">'.$lt{$action}.'</a>';
1.5 raeburn 335: } else {
1.128 ! raeburn 336: $link =
! 337: &Apache::longroup::get_group_link($cdom,$cnum,$group,$navmap,$view_permission);
! 338: print STDERR "link is ||$link||\n";
! 339: if ($link) {
! 340: $link = $actionlinks{$action}.$link;
! 341: $link .= (($link=~/\?/)?'&':'?').'ref=grouplist';
! 342: if (exists($env{'form.refpage'})) {
! 343: $link .= '&refpage='.$env{'form.refpage'};
! 344: }
! 345: $link .= '">'.$lt{$action}.'</a>';
! 346: }
1.5 raeburn 347: }
1.21 raeburn 348: if ($action eq 'view') {
1.71 raeburn 349: if ($manage_permission) {
1.21 raeburn 350: $link .= ' '.$actionlinks{'modify'}.
1.64 raeburn 351: $group.'">'.$lt{'modify'}.'</a>'.
352: ' '.$actionlinks{'delete'}.
353: $group.'">'.$lt{'delete'}.'</a>';
1.21 raeburn 354: }
355: }
1.39 albertel 356: $r->print(&Apache::loncommon::start_data_table_row('LC_data_table_dense').
357: '<td>'.$link.'</td>'.
358: '<td>'.$group.'</td>'.
359: '<td>'.$description.'</td>'.
360: '<td>'.$creator.'</td>'.
361: '<td>'. &Apache::lonnavmaps::timeToHumanString($creation).'</td>'.
362: '<td>'. &Apache::lonnavmaps::timeToHumanString($modified).'</td>'.
363: '<td>'.$functionality.'</td>'.
364: '<td align="right">'.$quota.'</td>'.
365: '<td align="right">'.$totalmembers.'</td>'.
1.79 bisitz 366: '<td align="right">'.
1.88 raeburn 367: '<span class="LC_nobreak">'.&mt('Files: [_1]',$totalfiles).'</span><br />'.
368: '<span class="LC_nobreak">'.&mt('Folders: [_1]',$totaldirs).'</span>'.
1.79 bisitz 369: '</td>'.
1.39 albertel 370: '<td align="right">'.$boards.'</td>'.
371: '<td align="right">'.$diskuse.'</td>'.
372: &Apache::loncommon::end_data_table_row());
1.3 raeburn 373: }
1.4 raeburn 374: }
1.39 albertel 375: $r->print(&Apache::loncommon::end_data_table());
1.21 raeburn 376: $r->print('<input type="hidden" name="refpage" '.
377: 'value="'.$env{'form.refpage'}.'" />');
378: if ($action eq 'view') {
379: if (!defined($state)) {
380: $state = 'view';
381: }
382: $r->print('<input type="hidden" name="state" value="'.
383: $state.'" />');
384: }
1.3 raeburn 385: } else {
1.7 raeburn 386: $r->print($lt{'nogr'});
387: if ($manage_permission) {
1.71 raeburn 388: $r->print('<br /><br /><a href="/adm/coursegroups?action=create&refpage='.$env{'form.refpage'}.'">'.$lt{'crng'}.'</a>');
389: if ($action ne 'reenable') {
390: if ($reenable_link) {
391: $r->print($reenable_link);
392: }
1.53 raeburn 393: }
1.7 raeburn 394: } else {
1.29 raeburn 395: $r->print('<br /><br />'.$lt{'alth'});
1.7 raeburn 396: }
1.3 raeburn 397: }
398: } else {
1.4 raeburn 399: my @coursegroups = split(/:/,$env{'request.course.groups'});
400: if (@coursegroups > 0) {
1.128 ! raeburn 401: my $numlinks = 0;
1.7 raeburn 402: $r->print('<br /><br />');
1.17 raeburn 403: my %curr_groups = &Apache::longroup::coursegroups($cdom,$cnum);
1.15 albertel 404: if (%curr_groups) {
1.110 raeburn 405: my $navmap=Apache::lonnavmaps::navmap->new();
406: if (!defined($navmap)) {
407: $r->print('<div class="LC_error">'.
408: &mt('An error occurred retrieving information about resources in the course.').'<br />'.
409: &mt('It is recommended that you [_1]re-initialize the course[_2] and then return to this page.','<a href="/adm/roles?selectrole=1&newrole='.$env{'request.role'}.'&orgurl=%2fadm%2fcoursegroups">','</a>').
410: '</div>');
411: return;
412: }
1.4 raeburn 413: foreach my $group (@coursegroups) {
1.17 raeburn 414: my %group_info = &Apache::longroup::get_group_settings(
1.5 raeburn 415: $curr_groups{$group});
1.24 www 416: my $description = &unescape(
1.5 raeburn 417: $group_info{description});
1.128 ! raeburn 418: my ($link,$hidden) =
! 419: &Apache::longroup::get_group_link($cdom,$cnum,$group,$navmap,$view_permission);
! 420: print STDERR "link is ||$link||\n";
! 421: if ($link) {
! 422: $link .= '&ref=grouplist';
! 423: $r->print('<span style="font-size: larger"><a href="'.$link.'">'.
! 424: $description.'</a></span><br /><br />');
! 425: $numlinks ++;
! 426: } elsif ($hidden) {
! 427: my $numtools = 0;
! 428: my $refarg = '&ref=grouplist';
! 429: my $output =
! 430: &Apache::longroup::display_group_links($r,$env{'form.grade_target'},$group,'view',
! 431: $refarg,\$numtools,$hidden,%group_info);
! 432: if ($numtools) {
! 433: $r->print('<span style="font-size: larger">'.$description.'</a></span>'.
! 434: '<br />'.$output.'<br /><br />');
! 435: $numlinks ++;
! 436: }
! 437: }
1.4 raeburn 438: }
439: }
1.128 ! raeburn 440: if (!$numlinks) {
! 441: $r->print(
! 442: '<p class="LC_info">'
! 443: .&mt('You do not currently have access to any '.$gpterm.'s'
! 444: .' in this '.lc($crstype).'.')
! 445: .'</p>'
! 446: );
! 447: }
1.4 raeburn 448: } else {
1.115 bisitz 449: $r->print(
450: '<p class="LC_info">'
451: .&mt('You are not currently a member of any active '.$gpterm.'s'
452: .' in this '.lc($crstype).'.')
453: .'</p>'
454: );
1.4 raeburn 455: }
1.3 raeburn 456: }
457: return;
458: }
459:
460: sub group_administration {
1.48 albertel 461: my ($r,$action,$state,$cdom,$cnum,$functions,$idx,$view_permission,
462: $manage_permission,$gpterm,$ucgpterm,$crstype) = @_;
1.3 raeburn 463: my %sectioncount = ();
464: my @tools = ();
465: my @types = ();
466: my @roles = ();
467: my @sections = ();
468: my %users = ();
469: my %userdata = ();
470: my @members = ();
471: my %usertools = ();
1.5 raeburn 472: my %stored = ();
473: my %memchg;
1.6 raeburn 474: my @member_changes = ('deletion','expire','activate','reenable',
1.5 raeburn 475: 'changefunc','changepriv');
1.29 raeburn 476: my ($groupname,$description,$startdate,$enddate,$granularity,$specificity,
1.37 raeburn 477: $quota,$validate_script);
1.5 raeburn 478:
479: if (defined($env{'form.groupname'})) {
480: $groupname = $env{'form.groupname'};
481: }
482:
483: if (($action eq 'create') && ($state eq '')) {
484: $state = 'pick_name';
485: }
486: if (($action eq 'create') ||
487: (($action eq 'modify') && ($state eq 'chgresult'))) {
488: ($startdate,$enddate) = &get_dates_from_form();
489: if (defined($env{'form.description'})) {
490: $description = $env{'form.description'};
491: }
492: if (defined($env{'form.tool'})) {
493: @tools=&Apache::loncommon::get_env_multiple('form.tool');
494: }
495: if (defined($env{'form.granularity'})) {
496: $granularity=$env{'form.granularity'};
497: }
498: if (defined($env{'form.specificity'})) {
499: $specificity=$env{'form.specificity'};
500: }
1.29 raeburn 501: if (defined($env{'form.quota'})) {
502: $quota=$env{'form.quota'};
503: }
1.5 raeburn 504: }
505: if (($action eq 'create') || (($action eq 'modify')
506: && (($state eq 'pick_privs') || ($state eq 'addresult')))) {
507: if (defined($env{'form.member'})) {
508: @members = &Apache::loncommon::get_env_multiple('form.member');
509: foreach my $user (@members) {
510: %{$usertools{$user}} = ();
511: }
512: }
513: }
1.3 raeburn 514:
1.5 raeburn 515: if ($action eq 'modify') {
1.3 raeburn 516: if ($state eq '') {
1.21 raeburn 517: if (defined($env{'form.groupname'})) {
518: $state = 'pick_task';
519: }
1.3 raeburn 520: } else {
1.65 raeburn 521: %stored = &retrieve_settings($cdom,$cnum,$groupname,$action);
1.5 raeburn 522: if (ref($stored{'types'}) eq 'ARRAY') {
523: @types = @{$stored{'types'}};
524: }
525: if (ref($stored{'roles'}) eq 'ARRAY') {
526: @roles = @{$stored{'roles'}};
527: }
528: if (ref($stored{'sectionpick'}) eq 'ARRAY') {
529: @sections = @{$stored{'sectionpick'}};
530: }
531: unless ($state eq 'chgresult') {
532: if (ref($stored{'tool'}) eq 'ARRAY') {
533: @tools = @{$stored{'tool'}};
1.3 raeburn 534: }
1.5 raeburn 535: $startdate = $stored{'startdate'};
536: $enddate = $stored{'enddate'};
537: $description = $stored{'description'};
538: $granularity = $stored{'granularity'};
539: $specificity = $stored{'specificity'};
1.29 raeburn 540: $quota = $stored{'quota'};
1.3 raeburn 541: }
542: }
543: }
544:
1.36 raeburn 545: my $toolprivs = &Apache::longroup::get_tool_privs($gpterm);
1.22 albertel 546:
1.36 raeburn 547: my $fixedprivs = &Apache::longroup::get_fixed_privs();
1.22 albertel 548:
549: my %elements =
550: (
551: create => {
552: pick_name => {
553: startdate_month => 'selectbox',
554: startdate_hour => 'selectbox',
555: enddate_month => 'selectbox',
556: enddate_hour => 'selectbox',
557: startdate_day => 'text',
558: startdate_year => 'text',
559: startdate_minute => 'text',
560: startdate_second => 'text',
561: enddate_day => 'text',
562: enddate_year => 'text',
563: enddate_minute => 'text',
564: enddate_second => 'text',
565: groupname => 'text',
566: description => 'text',
1.29 raeburn 567: quota => 'text',
1.22 albertel 568: tool => 'checkbox',
569: granularity => 'radio',
570: no_end_date => 'checkbox',
571: },
572: pick_members => {
573: member => 'checkbox',
574: defpriv => 'checkbox',
575: },
576: },
577: );
578:
579: $elements{'modify'} = {
580: change_settings => {
581: %{$elements{'create'}{'pick_name'}},
582: specificity => 'radio',
583: defpriv => 'checkbox',
584: autorole => 'checkbox',
585: autoadd => 'radio',
586: autodrop => 'radio',
587: },
588: add_members => {
589: types => 'selectbox',
590: roles => 'selectbox',
591: },
592: };
593:
1.5 raeburn 594: if (ref($stored{'autorole'}) eq 'ARRAY') {
595: foreach my $role (@{$stored{'autorole'}}) {
1.104 raeburn 596: unless (($role eq 'cc') || ($role eq 'co')) {
1.17 raeburn 597: $elements{'modify'}{'change_settings'}{'sec_'.$role} =
598: 'selectbox';
599: }
1.5 raeburn 600: }
601: }
602:
1.3 raeburn 603: if (($action eq 'create') && ($state eq 'pick_name')) {
1.5 raeburn 604: $elements{'create'}{'pick_name'}{'types'} = 'selectbox';
605: $elements{'create'}{'pick_name'}{'roles'} = 'selectbox';
606: }
607: if ((($action eq 'create') &&
608: (($state eq 'pick_name') || ($state eq 'pick_privs'))) ||
609: (($action eq 'modify') && (($state eq 'change_settings') ||
610: ($state eq 'add_members')))) {
1.16 albertel 611: %sectioncount = &Apache::loncommon::get_sections($cdom,$cnum);
1.53 raeburn 612: $elements{'create'}{'pick_name'}{'sectionpick'} = 'selectbox';
613: $elements{'modify'}{'change_mapping'}{'sectionpick'} = 'selectbox';
614: $elements{'modify'}{'add_members'}{'sectionpick'} = 'selectbox';
1.3 raeburn 615: }
1.5 raeburn 616:
1.12 raeburn 617: if (($action eq 'create') ||
618: ($action eq 'modify' && $state eq 'pick_members')) {
1.3 raeburn 619: if (defined($env{'form.types'})) {
620: @types=&Apache::loncommon::get_env_multiple('form.types');
621: }
622: if (defined($env{'form.roles'})) {
623: @roles=&Apache::loncommon::get_env_multiple('form.roles');
624: }
625: if (defined($env{'form.sectionpick'})) {
626: @sections=&Apache::loncommon::get_env_multiple('form.sectionpick');
627: }
1.5 raeburn 628: }
629:
1.6 raeburn 630: if (($state eq 'pick_members') || ($state eq 'pick_privs') || ($state eq 'change_privs')) {
1.78 raeburn 631: &build_members_list($cdom,$cnum,\@types,\@roles,\@sections,\%users,
1.6 raeburn 632: \%userdata);
633: }
634: if ($state eq 'pick_members') {
1.3 raeburn 635: if ((keys(%users) > 0) && (@tools > 0)) {
1.7 raeburn 636: if ($granularity eq 'Yes') {
637: $elements{$action}{'pick_members'}{'togglefunc'} = 'checkbox';
638: }
1.3 raeburn 639: foreach my $tool (@tools) {
1.5 raeburn 640: if ($granularity eq 'Yes') {
641: $elements{$action}{'pick_members'}{'user_'.$tool} = 'checkbox';
1.3 raeburn 642: }
643: }
1.5 raeburn 644: $elements{$action}{'pick_members'}{'specificity'} = 'radio';
1.3 raeburn 645: }
646: }
1.6 raeburn 647: if ($state eq 'change_members') {
648: my %membership = &Apache::lonnet::get_group_membership($cdom,$cnum,
649: $groupname);
650: my $now = time;
651: my $num_expire = 0;
652: my $num_activate = 0;
653: my $num_reenable = 0;
654: my $num_deletion = 0;
655: my $numusers = 0;
656: foreach my $key (sort(keys(%membership))) {
657: if ($key =~ /^\Q$groupname\E:([^:]+:[^:]+)$/) {
658: my $user = $1;
659: my($end,$start,@userprivs) = split(/:/,$membership{$key});
660: unless ($start == -1) {
661: $numusers ++;
662: $num_deletion ++;
663: if (($end > 0) && ($end < $now)) {
664: $num_reenable ++;
665: next;
666: } elsif (($start > $now)) {
1.52 raeburn 667: $num_activate ++;
1.6 raeburn 668: next;
669: } else {
670: $num_expire ++;
671: next;
672: }
673: next;
674: }
675: if ($num_reenable && $num_activate && $num_expire) {
676: last;
677: }
678: }
679: }
680: if ($num_deletion) {
681: $elements{$action}{'change_members'}{'deletion'} = 'checkbox';
682: }
683: if ($num_expire) {
684: $elements{$action}{'change_members'}{'expire'} = 'checkbox';
685: }
686: if ($num_activate) {
687: $elements{$action}{'change_members'}{'activate'} = 'checkbox';
688: }
689: if ($num_reenable) {
690: $elements{$action}{'change_members'}{'reenable'} = 'checkbox';
691: }
692: if ($numusers) {
1.7 raeburn 693: if ($granularity eq 'Yes') {
694: $elements{$action}{'change_members'}{'togglefunc'} = 'checkbox';
695: }
1.6 raeburn 696: foreach my $tool (@tools) {
697: if ($granularity eq 'Yes') {
698: $elements{$action}{'change_members'}{'user_'.$tool} = 'checkbox';
699: }
700: }
701: if ($specificity eq 'Yes') {
702: $elements{$action}{'change_members'}{'changepriv'} = 'checkbox';
703: }
704: }
705: }
1.3 raeburn 706:
1.5 raeburn 707: if (($state eq 'pick_privs') || ($state eq 'change_privs') ||
1.21 raeburn 708: (($specificity eq 'No') &&
709: ($state eq 'memresult' || $state eq 'result' || $state eq 'addresult'))) {
1.3 raeburn 710: foreach my $tool (@tools) {
711: my @values = &Apache::loncommon::get_env_multiple('form.user_'.$tool);
712: foreach my $user (@values) {
1.21 raeburn 713: if ($state eq 'pick_privs' || $state eq 'result'
714: || $state eq 'addresult') {
715: if (!grep(/^\Q$user\E$/,@members)) {
716: next;
717: }
718: }
1.3 raeburn 719: unless(exists($usertools{$user}{$tool})) {
720: $usertools{$user}{$tool} = 1;
721: }
722: }
723: }
1.6 raeburn 724: }
725:
726: if (($action eq 'modify') && (($state eq 'change_privs') || ($state eq 'memresult'))) {
727: foreach my $chg (@member_changes) {
728: if (defined($env{'form.'.$chg})) {
729: @{$memchg{$chg}} = &Apache::loncommon::get_env_multiple('form.'.$chg);
730: }
731: }
732:
733: if ($state eq 'change_privs') {
734: my %membership = &Apache::lonnet::get_group_membership($cdom,$cnum,
735: $groupname);
736: my $now = time;
737: foreach my $key (sort(keys(%membership))) {
738: if ($key =~ /^\Q$groupname\E:([^:]+:[^:]+)$/) {
739: my $user = $1;
740: my $changefunc = 0;
741: my ($end,$start,@userprivs) = split(/:/,$membership{$key});
742: unless ($start == -1) {
743: if (($end > 0) && ($end < $now)) {
744: unless (grep/^$user$/,$memchg{'reenable'}) {
745: next;
746: }
747: }
748: my @currtools = ();
749: if (@userprivs > 0) {
1.36 raeburn 750: foreach my $tool (sort(keys(%{$fixedprivs}))) {
751: foreach my $priv (keys(%{$$fixedprivs{$tool}})) {
1.6 raeburn 752: if (grep/^$priv$/,@userprivs) {
753: push(@currtools,$tool);
754: last;
755: }
756: }
757: }
1.3 raeburn 758: }
1.6 raeburn 759: foreach my $tool (@currtools) {
760: if (keys(%{$usertools{$user}}) > 0) {
761: if (!$usertools{$user}{$tool}) {
762: push(@{$memchg{'changefunc'}},$user);
763: $changefunc = 1;
764: last;
765: }
766: } else {
767: push(@{$memchg{'changefunc'}},$user);
768: $changefunc = 1;
769: }
770: }
771: if ($changefunc) {
772: next;
773: }
774: if (keys(%{$usertools{$user}}) > 0) {
775: foreach my $tool (keys(%{$usertools{$user}})) {
776: if (!grep/^$tool$/,@currtools) {
777: push(@{$memchg{'changefunc'}},$user);
778: $changefunc = 1;
779: last;
780: }
781: }
782: }
783: }
784: }
785: }
786: &check_changes(\@member_changes,\%memchg);
787: my %temptools;
788: foreach my $change (@member_changes) {
789: if (($change eq 'deletion') || ($change eq 'expire')) {
790: next;
791: }
792: foreach my $user (@{$memchg{$change}}) {
793: unless (exists($usertools{$user})) {
794: %{$usertools{$user}} = ();
795: }
796: %{$temptools{$user}} = %{$usertools{$user}};
797: }
798: }
799: %usertools = %temptools;
800: } elsif ($state eq 'memresult') {
801: foreach my $change (@member_changes) {
802: if ($change eq 'expire' || $change eq 'deletion') {
803: next;
804: }
805: if (ref($memchg{$change}) eq 'ARRAY') {
806: my @users = @{$memchg{$change}};
807: foreach my $user (@users) {
808: unless (exists($usertools{$user})) {
809: %{$usertools{$user}} = ();
810: }
811: }
812: }
813: }
814: }
815: }
816:
817: if ((($state eq 'pick_privs') || ($state eq 'change_privs'))
818: && ($specificity eq 'Yes')) {
819: foreach my $user (sort(keys(%usertools))) {
820: foreach my $tool (keys(%{$usertools{$user}})) {
1.36 raeburn 821: foreach my $priv (keys(%{$$toolprivs{$tool}})) {
822: unless (exists($$fixedprivs{$tool}{$priv})) {
1.6 raeburn 823: $elements{$action}{$state}{'userpriv_'.$priv} = 'checkbox';
1.3 raeburn 824: }
825: }
826: }
827: }
828: }
1.37 raeburn 829:
830: if (($action eq 'create' && $state eq 'pick_name') ||
831: ($action eq 'modify' && $state eq 'change_settings')) {
832: my ($crsquota,$freespace,$maxposs) = &get_quota_constraints($action,\%stored);
833: my $space_trim = '/^\s*|\s*\$/g,""';
834: my $float_check = '/^([0-9]*\.?[0-9]*)$/';
835: $validate_script = '
1.53 raeburn 836: var newquota = new String(document.'.$state.'.quota.value);
1.37 raeburn 837: newquota.replace('.$space_trim.');
838: if (newquota == "" ) {
839: document.'.$state.'.quota.value = 0;
1.53 raeburn 840: newquota = "0";
1.37 raeburn 841: }
1.53 raeburn 842: var maxposs = '.sprintf("%.2f",$maxposs).';
1.37 raeburn 843: if (newquota > maxposs) {
1.122 raeburn 844: alert("The group portfolio quota you entered for this group ("+newquota+" MB) exceeds the maximum possible ("+maxposs+" MB). Please enter a smaller number.");
1.37 raeburn 845: return;
846: }
847: var re_quota = '.$float_check.';
848: var check_quota = newquota.match(re_quota);
849: if (check_quota == null) {
850: alert("The quota you entered contains invalid characters, the quota should only include numbers, with or without a decimal point.");
851: return;
852: }
853: if (newquota == 0) {
854: var warn_zero = 0;
855: for (var i=0; i<document.'.$state.'.tool.length; i++) {
856: if (document.'.$state.'.tool[i].value == "files") {
857: if (document.'.$state.'.tool[i].checked) {
858: warn_zero = 1;
859: }
860: }
861: }
862: if (warn_zero == 1) {
1.125 bisitz 863: alert("You have indicated that the group portfolio should be enabled, but you have set the repository quota to 0 MB.\nThis will prevent any upload of files.\nPlease set a value or disable the repository feature.");
1.37 raeburn 864: return;
865: }
866: }
867: ';
868: }
1.5 raeburn 869: my $jscript = &Apache::loncommon::check_uncheck_jscript();
1.3 raeburn 870: $jscript .= qq|
871: function nextPage(formname,nextstate) {
872: formname.state.value= nextstate;
1.37 raeburn 873: $validate_script
1.3 raeburn 874: formname.submit();
875: }
876: function backPage(formname,prevstate) {
877: formname.state.value = prevstate;
878: formname.submit();
879: }
1.6 raeburn 880: function changeSort(caller) {
881: document.$state.state.value = '$state';
882: document.$state.sortby.value = caller;
883: document.$state.submit();
884: }
1.15 albertel 885:
1.3 raeburn 886: |;
887: $jscript .= &Apache::lonhtmlcommon::set_form_elements(
1.5 raeburn 888: \%{$elements{$action}{$state}},\%stored);
889: my $page = 0;
890: my %states = ();
891: my %branchstates = ();
892: @{$states{'create'}} = ('pick_name','pick_members','pick_privs','result');
1.53 raeburn 893: @{$states{'modify'}} = ('pick_task');
1.64 raeburn 894: @{$states{'delete'}} = ('verify','result');
1.65 raeburn 895: @{$states{'reenable'}} = ('verify','result');
1.5 raeburn 896: @{$branchstates{'noprivs'}} = ('result');
897: @{$branchstates{'settings'}} = ('change_settings','chgresult');
898: @{$branchstates{'members'}} = ('change_members','change_privs','memresult');
899: @{$branchstates{'adds'}} = ('add_members','pick_members','pick_privs',
900: 'addresult');
1.21 raeburn 901:
1.5 raeburn 902: if (defined($env{'form.branch'})) {
903: push (@{$states{$action}},@{$branchstates{$env{'form.branch'}}});
904: }
905:
1.65 raeburn 906: if (($action eq 'create') || ($action eq 'modify') || ($action eq 'delete') || ($action eq 'reenable')) {
1.5 raeburn 907: my $done = 0;
908: my $i=0;
909: while ($i<@{$states{$action}} && !$done) {
910: if ($states{$action}[$i] eq $state) {
911: $page = $i;
912: $done = 1;
913: }
914: $i++;
915: }
916: }
1.3 raeburn 917:
918: my $loaditems = &onload_action($action,$state);
1.53 raeburn 919: $r->print(&header("Groups Manager",
1.39 albertel 920: $jscript,$action,$state,$page,$loaditems));
1.1 raeburn 921:
1.71 raeburn 922: if ($env{'form.refpage'} eq 'cusr') {
1.3 raeburn 923: &Apache::lonhtmlcommon::add_breadcrumb
1.71 raeburn 924: ({href=>"/adm/createuser",
925: text=>"User Management",
1.3 raeburn 926: faq=>9,bug=>'Instructor Interface',});
1.64 raeburn 927: if ($action eq 'modify' || $action eq 'delete') {
1.53 raeburn 928: &Apache::lonhtmlcommon::add_breadcrumb
1.71 raeburn 929: ({href=>"/adm/coursegroups?refpage=cusr&action=$action",
1.53 raeburn 930: text=>"Groups",
931: faq=>9,bug=>'Instructor Interface',});
932: }
933: } else {
1.1 raeburn 934: &Apache::lonhtmlcommon::add_breadcrumb
1.53 raeburn 935: ({href=>"/adm/coursegroups",
936: text=>"Groups",
937: faq=>9,bug=>'Instructor Interface',});
1.54 raeburn 938: if ($env{'form.refpage'} eq 'grouplist') {
939: &Apache::lonhtmlcommon::add_breadcrumb
940: ({href=>"/adm/$cdom/$cnum/$env{'form.groupname'}/smppg?ref=grouplist",
941: text=>"Group: $description",});
942: }
1.3 raeburn 943: }
944:
945: my %trail = ();
1.5 raeburn 946: %{$trail{'create'}} = &Apache::lonlocal::texthash (
1.29 raeburn 947: pick_name => $ucgpterm.' Settings',
1.3 raeburn 948: pick_members => 'Select Members',
949: pick_privs => 'Choose Privileges',
950: result => 'Creation Complete',
951: );
1.5 raeburn 952: %{$trail{'modify'}} = &Apache::lonlocal::texthash(
953: pick_task => 'Choose Task',
1.29 raeburn 954: change_settings => "$ucgpterm Settings",
1.5 raeburn 955: change_members => 'Modify/Delete Members',
956: change_privs => 'Change Privileges',
957: change_mapping => 'Membership Mapping',
958: add_members => 'Add Members',
959: pick_members => 'Select Members',
960: pick_privs => 'Choose Privileges',
961: chgresult => 'Setting Changes Complete',
962: memresult => 'Modifications Complete',
963: addresult => 'Additions Complete',
964: );
1.64 raeburn 965: %{$trail{'delete'}} = &Apache::lonlocal::texthash(
966: verify => 'Verify deletion',
967: result => 'Deletion Complete'
968: );
1.65 raeburn 969: %{$trail{'reenable'}} = &Apache::lonlocal::texthash(
970: verify => 'Verify Re-enable',
971: result => 'Re-enabled'
972: );
1.5 raeburn 973: my %navbuttons = &Apache::lonlocal::texthash(
1.91 schafran 974: gtns => 'Next',#'Go to next step',
1.93 schafran 975: gtps => 'Back',#'Go to previous step',
1.29 raeburn 976: crgr => 'Create '.$gpterm,
1.91 schafran 977: mose => 'Save',#'Modify settings',
1.93 schafran 978: gtpp => 'Back',#'Go to previous page',
1.5 raeburn 979: adme => 'Add members',
980: );
1.65 raeburn 981: if ((($action eq 'create') || ($action eq 'modify') || ($action eq 'delete') || ($action eq 'reenable')) &&
1.3 raeburn 982: ($manage_permission)) {
983: for (my $i=0; $i<@{$states{$action}}; $i++) {
984: if ($state eq $states{$action}[$i]) {
985: &Apache::lonhtmlcommon::add_breadcrumb(
986: {text=>"$trail{$action}{$state}"});
987: $r->print(&Apache::lonhtmlcommon::breadcrumbs
1.61 raeburn 988: ("Groups Manager","Creating_Groups"));
1.48 albertel 989: &display_control($r,$cdom,$cnum,$action,$state,$page,
1.5 raeburn 990: \%sectioncount,$groupname,$description,$functions,
1.36 raeburn 991: \@tools,$toolprivs,$fixedprivs,$startdate,$enddate,
1.5 raeburn 992: \%users,\%userdata,$idx,\%memchg,\%usertools,
1.45 albertel 993: $view_permission,$manage_permission,
1.29 raeburn 994: \%stored,$granularity,$quota,$specificity,\@types,\@roles,
1.48 albertel 995: \@sections,\%states,\%navbuttons,$gpterm,$ucgpterm,
996: $crstype);
1.3 raeburn 997: last;
998: } else {
1.64 raeburn 999: if (($action eq 'create') || ($action eq 'modify')) {
1000: if (($state eq 'result') && ($i > 0)) {
1001: &Apache::lonhtmlcommon::add_breadcrumb(
1.3 raeburn 1002: {href=>"javascript:backPage(document.$state,'$states{$action}[0]')",
1003: text=>"$trail{$action}{$states{$action}[$i]}"});
1.64 raeburn 1004: } else {
1005: &Apache::lonhtmlcommon::add_breadcrumb(
1.3 raeburn 1006: {href=>"javascript:backPage(document.$state,'$states{$action}[$i]')",
1007: text=>"$trail{$action}{$states{$action}[$i]}"});
1.64 raeburn 1008: }
1.3 raeburn 1009: }
1.64 raeburn 1010: }
1.3 raeburn 1011: }
1012: } elsif (($action eq 'view') && ($view_permission)) {
1013: &Apache::lonhtmlcommon::add_breadcrumb(
1.29 raeburn 1014: {text=>"View $gpterm".'s'});
1.1 raeburn 1015: $r->print(&Apache::lonhtmlcommon::breadcrumbs
1.53 raeburn 1016: ('Groups Manager'));
1.39 albertel 1017: &display_groups($r,$cdom,$cnum,$functions,$idx,$view_permission,
1018: $manage_permission,$action,$state,$gpterm,$ucgpterm,
1019: $crstype);
1.3 raeburn 1020: }
1021: $r->print(&footer());
1022: return;
1023: }
1024:
1.5 raeburn 1025: sub retrieve_settings {
1.65 raeburn 1026: my ($cdom,$cnum,$groupname,$action) = @_;
1027: my %curr_groups;
1028: my $namespace;
1029: if ($action eq 'reenable') {
1030: $namespace = 'deleted_groups';
1031: } else {
1032: $namespace = 'coursegroups';
1033: }
1034: %curr_groups = &Apache::longroup::coursegroups($cdom,$cnum,$groupname,
1035: $namespace);
1.15 albertel 1036:
1037: return if (!%curr_groups);
1038:
1039: my %groupinfo =
1.17 raeburn 1040: &Apache::longroup::get_group_settings($curr_groups{$groupname});
1.15 albertel 1041:
1.5 raeburn 1042: my %stored;
1.15 albertel 1043:
1044: $stored{'description'} =
1.24 www 1045: &unescape($groupinfo{'description'});
1.15 albertel 1046: $stored{'startdate'} = $groupinfo{'startdate'};
1047: $stored{'enddate'} = $groupinfo{'enddate'};
1048: if ($stored{'enddate'} == 0) {
1049: $stored{'no_end_date'} = 1;
1050: }
1051: $stored{'granularity'} = $groupinfo{'granularity'};
1052: $stored{'specificity'} = $groupinfo{'specificity'};
1053: $stored{'creation'} = $groupinfo{'creation'};
1054: $stored{'creator'} = $groupinfo{'creator'};
1.29 raeburn 1055: $stored{'quota'} = $groupinfo{'quota'};
1.15 albertel 1056:
1057: foreach my $tool (sort(keys(%{$groupinfo{'functions'}}))) {
1058: if ($groupinfo{functions}{$tool} eq 'on') {
1059: push(@{$stored{tool}},$tool);
1060: }
1061: }
1062: foreach my $role (@{$groupinfo{'roles'}}) {
1063: push(@{$stored{roles}},$role);
1064: }
1065: foreach my $type (@{$groupinfo{'types'}}) {
1066: push(@{$stored{types}},$type);
1067: }
1068: foreach my $section (@{$groupinfo{'sectionpick'}}) {
1069: push(@{$stored{sectionpick}},$section);
1070: }
1071: foreach my $defpriv (@{$groupinfo{'defpriv'}}) {
1072: push(@{$stored{defpriv}},$defpriv);
1073: }
1074: $stored{'autoadd'} = $groupinfo{'autoadd'};
1075: $stored{'autodrop'} = $groupinfo{'autodrop'};
1076: if (exists($groupinfo{'autosec'})) {
1077: foreach my $role (sort(keys(%{$groupinfo{'autosec'}}))) {
1.17 raeburn 1078: if (ref($groupinfo{'autosec'}{$role}) eq 'ARRAY') {
1079: foreach my $section (@{$groupinfo{'autosec'}{$role}}) {
1.58 raeburn 1080:
1.17 raeburn 1081: push (@{$stored{'sec_'.$role}},$section);
1082: }
1083: if (@{$groupinfo{'autosec'}{$role}} > 0) {
1084: push(@{$stored{'autorole'}},$role);
1085: }
1086: }
1.15 albertel 1087: }
1.5 raeburn 1088: }
1089: return %stored;
1090: }
1091:
1.3 raeburn 1092: sub display_control {
1.48 albertel 1093: my ($r,$cdom,$cnum,$action,$state,$page,$sectioncount,$groupname,
1.3 raeburn 1094: $description,$functions,$tools,$toolprivs,$fixedprivs,$startdate,
1.45 albertel 1095: $enddate,$users,$userdata,$idx,$memchg,$usertools,
1.29 raeburn 1096: $view_permission,$manage_permission,$stored,$granularity,$quota,
1.48 albertel 1097: $specificity,$types,$roles,$sections,$states,$navbuttons,
1098: $gpterm,$ucgpterm,$crstype) = @_;
1.3 raeburn 1099: if ($action eq 'create') {
1100: if ($state eq 'pick_name') {
1.46 albertel 1101: &general_settings_form($r,$cdom,$cnum,$action,$state,$page,
1.5 raeburn 1102: $functions,$tools,$toolprivs,$fixedprivs,
1103: $sectioncount,$stored,$states,$navbuttons,
1.46 albertel 1104: $gpterm,$ucgpterm,$crstype);
1.3 raeburn 1105: } elsif ($state eq 'pick_members') {
1.46 albertel 1106: &choose_members_form($r,$cdom,$cnum,$action,$state,$page,
1.29 raeburn 1107: $groupname,$description,$granularity,$quota,
1.5 raeburn 1108: $startdate,$enddate,$tools,$fixedprivs,
1109: $toolprivs,$functions,$users,$userdata,$idx,
1.46 albertel 1110: $stored,$states,$navbuttons,$gpterm,$ucgpterm,
1111: $crstype);
1.3 raeburn 1112: } elsif ($state eq 'pick_privs') {
1.45 albertel 1113: &choose_privs_form($r,$cdom,$cnum,$action,$state,$page,
1.5 raeburn 1114: $startdate,$enddate,$tools,$functions,
1115: $toolprivs,$fixedprivs,$userdata,$usertools,
1116: $idx,$states,$stored,$sectioncount,$navbuttons,
1.45 albertel 1117: $gpterm,$ucgpterm,$crstype);
1.3 raeburn 1118: } elsif ($state eq 'result') {
1.45 albertel 1119: &process_request($r,$cdom,$cnum,$action,$state,$page,
1.5 raeburn 1120: $groupname,$description,$specificity,$userdata,
1121: $startdate,$enddate,$tools,$functions,
1122: $toolprivs,$usertools,$idx,$types,$roles,
1123: $sections,$states,$navbuttons,$memchg,
1.45 albertel 1124: $sectioncount,$stored,$gpterm,$ucgpterm,$crstype);
1.5 raeburn 1125: }
1126: } elsif ($action eq 'modify') {
1127: my $groupname = $env{'form.groupname'};
1.53 raeburn 1128: if ($state eq 'pick_task') {
1.29 raeburn 1129: &modify_menu($r,$groupname,$page,$gpterm);
1.5 raeburn 1130: } elsif ($state eq 'change_settings') {
1.46 albertel 1131: &general_settings_form($r,$cdom,$cnum,$action,$state,$page,
1.5 raeburn 1132: $functions,$tools,$toolprivs,$fixedprivs,
1133: $sectioncount,$stored,$states,$navbuttons,
1.46 albertel 1134: $gpterm,$ucgpterm,$crstype);
1.5 raeburn 1135: } elsif ($state eq 'change_members') {
1.48 albertel 1136: &change_members_form($r,$cdom,$cnum,$action,$state,$page,
1.5 raeburn 1137: $groupname,$description,$startdate,$enddate,
1138: $tools,$fixedprivs,$functions,$users,
1.29 raeburn 1139: $userdata,$granularity,$quota,$specificity,
1.48 albertel 1140: $idx,$states,$navbuttons,$gpterm,$ucgpterm);
1.5 raeburn 1141: } elsif ($state eq 'add_members') {
1.59 raeburn 1142: &add_members_form($r,$cdom,$cnum,$action,$state,$page,$startdate,
1.5 raeburn 1143: $enddate,$groupname,$description,$granularity,
1.29 raeburn 1144: $quota,$sectioncount,$tools,$functions,$stored,
1.104 raeburn 1145: $states,$navbuttons,$gpterm,$ucgpterm,$crstype);
1.5 raeburn 1146: } elsif ($state eq 'pick_members') {
1.46 albertel 1147: &choose_members_form($r,$cdom,$cnum,$action,$state,$page,
1.29 raeburn 1148: $groupname,$description,$granularity,$quota,
1.5 raeburn 1149: $startdate,$enddate,$tools,$fixedprivs,
1150: $toolprivs,$functions,$users,$userdata,$idx,
1.46 albertel 1151: $stored,$states,$navbuttons,$gpterm,$ucgpterm,
1152: $crstype);
1.5 raeburn 1153: } elsif ($state eq 'pick_privs') {
1.46 albertel 1154: &choose_privs_form($r,$cdom,$cnum,$action,$state,$page,
1.5 raeburn 1155: $startdate,$enddate,$tools,$functions,
1156: $toolprivs,$fixedprivs,$userdata,$usertools,
1157: $idx,$states,$stored,$sectioncount,$navbuttons,
1.46 albertel 1158: $gpterm,$ucgpterm,$crstype);
1.5 raeburn 1159: } elsif ($state eq 'change_privs') {
1.45 albertel 1160: &change_privs_form($r,$cdom,$cnum,$action,$state,$page,
1.5 raeburn 1161: $startdate,$enddate,$tools,$functions,
1162: $toolprivs,$fixedprivs,$userdata,$usertools,
1163: $memchg,$idx,$states,$stored,$sectioncount,
1.45 albertel 1164: $navbuttons,$gpterm,$ucgpterm);
1.5 raeburn 1165: } elsif ($state eq 'chgresult' || $state eq 'memresult' ||
1166: $state eq 'addresult') {
1.45 albertel 1167: &process_request($r,$cdom,$cnum,$action,$state,$page,
1.5 raeburn 1168: $groupname,$description,$specificity,$userdata,
1169: $startdate,$enddate,$tools,$functions,
1170: $toolprivs,$usertools,$idx,$types,$roles,
1171: $sections,$states,$navbuttons,$memchg,
1.45 albertel 1172: $sectioncount,$stored,$gpterm,$ucgpterm,$crstype);
1.1 raeburn 1173: }
1.64 raeburn 1174: } elsif ($action eq 'delete') {
1.65 raeburn 1175: my %stored = &retrieve_settings($cdom,$cnum,$groupname,$action);
1.64 raeburn 1176: if ($state eq 'verify') {
1177: &verify_delete($r,$groupname,$state,$action,$page,$states,
1.104 raeburn 1178: \%stored,$crstype);
1.64 raeburn 1179: } elsif ($state eq 'result') {
1.104 raeburn 1180: &delete_group($r,$cdom,$cnum,$groupname,$crstype);
1.64 raeburn 1181: }
1.65 raeburn 1182: } elsif ($action eq 'reenable') {
1183: my %stored = &retrieve_settings($cdom,$cnum,$groupname,$action);
1184: if ($state eq 'verify') {
1185: &verify_reenable($r,$groupname,$state,$action,$page,$states,
1.104 raeburn 1186: \%stored,$crstype);
1.65 raeburn 1187: } elsif ($state eq 'result') {
1.104 raeburn 1188: &reenable_group($r,$cdom,$cnum,$groupname,$crstype);
1.65 raeburn 1189: }
1.64 raeburn 1190: }
1191: }
1192:
1193: sub verify_delete {
1.104 raeburn 1194: my ($r,$groupname,$formname,$action,$page,$states,$stored,$crstype) = @_;
1.64 raeburn 1195: $r->print(&Apache::lonhtmlcommon::echo_form_input([]));
1.79 bisitz 1196: $r->print(&mt('You have requested deletion of the group [_1].'
1197: ,'<i>'.$stored->{'description'}.'</i>').
1.64 raeburn 1198: '<br /><br />'.&mt('When a group is deleted the following occurs:').'<ul>'.
1199: '<li>'.&mt('All group membership is terminated.').'</li>'.
1.104 raeburn 1200: '<li>'.&mt('The group ceases to be available either for viewing or for modification of group settings and membership.').'</li>');
1201: if ($crstype eq 'Community') {
1202: $r->print( '<li>'.&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.").'</li>'.
1203: '</ul>'.&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."));
1204: } else {
1205: $r->print( '<li>'.&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.").'</li>'.
1206: '</ul>'.&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."));
1207: }
1.64 raeburn 1208: my $prevtext = &mt('Go back');
1209: my $nexttext = &mt('Delete group');
1210: my $prev;
1.71 raeburn 1211: if ($env{'form.refpage'} eq 'cusr') {
1.64 raeburn 1212: $prev = 'view';
1213: }
1214: &display_navbuttons($r,$formname,$prev,$prevtext,
1215: $$states{$action}[$page+1],$nexttext);
1216: return;
1217: }
1218:
1219: sub delete_group {
1.104 raeburn 1220: my ($r,$cdom,$cnum,$groupname,$crstype) = @_;
1.64 raeburn 1221: my %membership = &Apache::lonnet::get_group_membership($cdom,$cnum,
1222: $groupname);
1223: my $now = time;
1224: my $num_users = 0;
1225: my $num_fail = 0;
1226: my $num_ok = 0;
1227: my @deleted;
1228: my @undeleted;
1229: my %usersettings;
1.77 raeburn 1230: my $context = 'deletegroup';
1.64 raeburn 1231: foreach my $key (sort(keys(%membership))) {
1232: if ($key =~ /^\Q$groupname\E:([^:]+:[^:]+)$/) {
1233: my $user = $1;
1.65 raeburn 1234: my($end,$start,$userprivs) = split(/:/,$membership{$key},3);
1.64 raeburn 1235: if ($start != -1) {
1236: $num_users ++;
1.65 raeburn 1237: $usersettings{$groupname.':'.$user} = $now.':-1:'.$userprivs;
1.64 raeburn 1238: if (&Apache::lonnet::modify_group_roles($cdom,$cnum,
1239: $groupname,$user,
1.76 raeburn 1240: $now,'-1',$userprivs,
1241: '',$context)
1.64 raeburn 1242: eq 'ok') {
1243: $num_ok ++;
1244: push(@deleted,$user);
1245: } else {
1246: push(@undeleted,$user);
1247: $num_fail ++;
1248: }
1249: }
1250: }
1251: }
1252: if ($num_ok > 0) {
1253: my $roster_result =
1254: &Apache::lonnet::modify_coursegroup_membership($cdom,$cnum,
1255: \%usersettings);
1256: }
1257: if ($num_fail > 0) {
1.79 bisitz 1258: $r->print('<div class="LC_error">'
1259: .&mt('Group deletion failed because deletion of [_1] out of [_2] members failed.'
1260: ,$num_fail,$num_users)
1261: .'</div>');
1.64 raeburn 1262: } else {
1263: my ($result,$message) =
1.65 raeburn 1264: &Apache::lonnet::toggle_coursegroup_status($cdom,$cnum,
1265: $groupname,'delete');
1.64 raeburn 1266: if ($result eq 'ok') {
1.104 raeburn 1267: my $outcome = &modify_folders($cdom,$cnum,$groupname,$crstype);
1.64 raeburn 1268: if ($outcome eq '') {
1.109 wenzelju 1269: my $message = &Apache::lonhtmlcommon::confirm_success(&mt('Group successfully deleted.'));
1270: $message = &Apache::loncommon::confirmwrapper($message);
1271: $r->print($message);
1.64 raeburn 1272: } else {
1.104 raeburn 1273: $r->print('<div class="LC_error">');
1.105 bisitz 1274: if ($crstype eq 'Community') {
1.104 raeburn 1275: $r->print(&mt("Although the group was deleted, an error occurred when removing the group's folder from the 'Community Groups' folder: [_1]",$outcome));
1276: } else {
1277: $r->print(&mt("Although the group was deleted, an error occurred when removing the group's folder from the 'Course Groups' folder: [_1]",$outcome));
1278: }
1279: $r->print('</div>');
1.64 raeburn 1280: }
1281: } else {
1.109 wenzelju 1282: my $msg = &Apache::lonhtmlcommon::confirm_success(&mt('Group deletion failed.'),1);
1283: $msg = &Apache::loncommon::confirmwrapper($msg);
1284: $r->print($msg);
1.64 raeburn 1285: }
1.1 raeburn 1286: }
1.64 raeburn 1287: return;
1288: }
1289:
1.65 raeburn 1290: sub reenable_folder {
1.104 raeburn 1291: my ($cdom,$cnum,$groupname,$description,$crstype) = @_;
1.65 raeburn 1292: my $outcome;
1293: my $crspath = '/uploaded/'.$cdom.'/'.$cnum.'/';
1294: my $allgrpsmap = $crspath.'group_allfolders.sequence';
1.104 raeburn 1295: my $foldertitle;
1296: if ($crstype eq 'Community') {
1297: $foldertitle = &mt("Community Folder -[_1]",$description);
1298: } else {
1299: $foldertitle = &mt("Course Folder -[_1]",$description);
1300: }
1.65 raeburn 1301: my $mapurl = $crspath.'group_folder_'.
1302: $groupname.'.sequence';
1303: my ($errtext,$fatal)=&LONCAPA::map::mapread($allgrpsmap);
1304: if ($fatal) {
1.79 bisitz 1305: $outcome='<div class="LC_error">'
1306: .&mt('An error occurred when reading contents of parent folder to group:')
1307: ."<br />($allgrpsmap): $errtext"
1308: .'</div>';
1.65 raeburn 1309: } else {
1310: my $idx=&LONCAPA::map::getresidx($mapurl);
1311: $LONCAPA::map::resources[$idx] = $foldertitle.':'.$mapurl.
1312: ':false:normal:res';
1313: $LONCAPA::map::order[1+$#LONCAPA::map::order]=$idx;
1.114 raeburn 1314: my ($outtext,$errtext) = &LONCAPA::map::storemap($allgrpsmap,1,1);
1.65 raeburn 1315: if ($errtext) {
1.79 bisitz 1316: $outcome='<div class="LC_error">'
1317: .&mt('An error occurred when saving updated parent folder to group:'
1318: ,"<br />$allgrpsmap - $errtext")
1319: .'</div>';
1.65 raeburn 1320: } else {
1321: my ($furl,$ferr) =
1322: &Apache::lonuserstate::readmap($cdom.'/'.$cnum);
1323: }
1324: }
1325: return $outcome;
1326: }
1327:
1.64 raeburn 1328: sub modify_folders {
1.104 raeburn 1329: my ($cdom,$cnum,$groupname,$crstype) = @_;
1.85 raeburn 1330: my ($outcome,$groupmap,$groupmapres,$map,$id,$src);
1.64 raeburn 1331: my $navmap = Apache::lonnavmaps::navmap->new();
1.85 raeburn 1332: if (!defined($navmap)) {
1.104 raeburn 1333: $outcome = '<div class="LC_error">';
1334: if ($crstype eq 'Community') {
1335: $outcome .= &mt("Error reading community contents.").' '.
1336: &mt("You need to re-initialize the community.");
1337: } else {
1338: $outcome .= &mt("Error reading course contents.").' '.
1339: &mt("You need to re-initialize the course.");
1340: }
1341: $outcome .= '</div>';
1.85 raeburn 1342: return $outcome;
1343: }
1344: $groupmap = '/uploaded/'.$cdom.'/'.$cnum.'/'.'group_folder_'.
1.64 raeburn 1345: $groupname.'.sequence';
1.85 raeburn 1346: $groupmapres = $navmap->getResourceByUrl($groupmap);
1.64 raeburn 1347: if ($groupmapres) {
1.65 raeburn 1348: ($map,$id,$src)=&Apache::lonnet::decode_symb($groupmapres->symb());
1349: }
1350: undef($navmap);
1351: if ($map) {
1.64 raeburn 1352: $map = '/'.$map;
1353: my ($errtext,$fatal) = &LONCAPA::map::mapread($map);
1354: if ($fatal) {
1.79 bisitz 1355: $outcome='<div class="LC_error">'
1356: .&mt('An error occurred when reading contents of parent folder to group:')
1357: ."<br />($map): $errtext"
1358: .'</div>';
1.64 raeburn 1359: } else {
1360: my $idx = 0;
1361: my $grpidx;
1362: foreach my $item (@LONCAPA::map::order) {
1363: my ($name,$url)=split(/\:/,$LONCAPA::map::resources[$item]);
1364: $url=&LONCAPA::map::qtescape($url);
1365: if ($url eq $groupmap) {
1366: $grpidx = $idx;
1367: last;
1368: } else {
1369: $idx++;
1370: }
1371: }
1372:
1373: if ($grpidx ne '') {
1374: &LONCAPA::map::makezombie($LONCAPA::map::order[$grpidx]);
1375: for (my $i=$grpidx;$i<$#LONCAPA::map::order;$i++) {
1376: $LONCAPA::map::order[$i] = $LONCAPA::map::order[$i+1];
1377: }
1378: $#LONCAPA::map::order--;
1.114 raeburn 1379: my ($outtext,$errtext) = &LONCAPA::map::storemap($map,1,1);
1.65 raeburn 1380: if ($errtext) {
1.79 bisitz 1381: $outcome='<div class="LC_error">'
1382: .&mt('An error occurred when saving updated parent folder to group:')
1383: ."<br />$map - $errtext"
1384: .'</div>';
1.65 raeburn 1385: } else {
1386: my ($furl,$ferr) =
1387: &Apache::lonuserstate::readmap($cdom.'/'.$cnum);
1388: }
1389: }
1390: }
1391: }
1392: return $outcome;
1393: }
1394:
1395: sub verify_reenable {
1.104 raeburn 1396: my ($r,$groupname,$formname,$action,$page,$states,$stored,$crstype) = @_;
1.65 raeburn 1397: $r->print(&Apache::lonhtmlcommon::echo_form_input([]));
1.79 bisitz 1398: $r->print(&mt('You have requested enabling the previously deleted group [_1].'
1399: ,'<i>'.$stored->{'description'}.'</i>').
1.65 raeburn 1400: '<br /><br />'.&mt('When a deleted group is re-enabled the following occurs:').'<ul>'.
1.104 raeburn 1401: '<li>'.&mt('Group settings and membership at the time the group was deleted are reinstated.').'</li><li>');
1402: if ($crstype eq 'Community') {
1403: $r->print(&mt("A group folder is added to the 'Community Groups' folder which contains folders for all groups in the community."));
1404: } else {
1405: $r->print(&mt("A group folder is added to the 'Course Groups' folder which contains folders for all groups in the course."));
1406: }
1407: $r->print('</li></ul>');
1.65 raeburn 1408: my $prevtext = &mt('Go back');
1409: my $nexttext = &mt('Reenable group');
1410: my $prev;
1.71 raeburn 1411: if ($env{'form.refpage'} eq 'cusr') {
1.65 raeburn 1412: $prev = 'view';
1413: }
1414: &display_navbuttons($r,$formname,$prev,$prevtext,
1415: $$states{$action}[$page+1],$nexttext);
1416: return;
1417: }
1418:
1419: sub reenable_group {
1.104 raeburn 1420: my ($r,$cdom,$cnum,$groupname,$crstype) = @_;
1.65 raeburn 1421: my %groups =
1422: &Apache::longroup::coursegroups($cdom,$cnum,$groupname,
1423: 'deleted_groups');
1.66 raeburn 1424: if (keys(%groups) == 0) {
1.79 bisitz 1425: $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?','<i>'.$groupname.'</i>'),'<br />');
1.66 raeburn 1426: return;
1427: }
1.65 raeburn 1428: my %groupinfo =
1429: &Apache::longroup::get_group_settings($groups{$groupname});
1430: my $defstart = $groupinfo{'startdate'};
1431: my $defend = $groupinfo{'enddate'};
1432: my $showstart = &Apache::lonlocal::locallocaltime($defstart);
1433: my $showend;
1434: if ($defend == 0) {
1435: $showend = &mt('No end date set');
1436: } else {
1437: $showend = &Apache::lonlocal::locallocaltime($defend);
1438: }
1439: my $description = &unescape($groupinfo{'description'});
1440: my $num_users = 0;
1441: my $num_ok = 0;
1442: my $num_fail = 0;
1.77 raeburn 1443: my $context = 'reenablegroup';
1.65 raeburn 1444: my (%usersettings,@enabled,@unenabled);
1445: my ($result,$message) =
1446: &Apache::lonnet::toggle_coursegroup_status($cdom,$cnum,$groupname,
1447: 'reenable');
1448: if ($result eq 'ok') {
1449: my %membership = &Apache::lonnet::get_group_membership($cdom,$cnum,
1450: $groupname);
1451: foreach my $key (sort(keys(%membership))) {
1452: if ($key =~ /^\Q$groupname\E:([^:]+:[^:]+)$/) {
1453: my $user = $1;
1454: my($end,$start,$userprivs) = split(/:/,$membership{$key},3);
1455: if (($start == -1) && ($end == $groupinfo{'modified'})) {
1456: $num_users ++;
1457: $usersettings{$groupname.':'.$user} = $defend.':'.
1458: $defstart.':'.
1459: $userprivs;
1460: if (&Apache::lonnet::modify_group_roles($cdom,$cnum,
1461: $groupname,$user,
1462: $defend,$defstart,
1.76 raeburn 1463: $userprivs,'',
1464: $context) eq 'ok') {
1.65 raeburn 1465: $num_ok ++;
1466: push(@enabled,$user);
1467: } else {
1468: push(@unenabled,$user);
1469: $num_fail ++;
1470: }
1.64 raeburn 1471: }
1472: }
1473: }
1.65 raeburn 1474: if ($num_users > 0) {
1475: if ($num_ok > 0) {
1476: my $roster_result =
1477: &Apache::lonnet::modify_coursegroup_membership($cdom,$cnum,
1478: \%usersettings);
1479: if ($roster_result eq 'ok') {
1.79 bisitz 1480: $r->print('<div class="LC_success">'
1481: .&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)
1482: .'</div>');
1.65 raeburn 1483: }
1484: } else {
1.79 bisitz 1485: $r->print('<div class="LC_error">'
1486: .&mt('A problem occurred when trying to reinstate [_1] of the [_2] members of the pre-existing group.',$num_fail,$num_users)
1487: .'</div>');
1.65 raeburn 1488: }
1489: } else {
1.79 bisitz 1490: $r->print('<div class="LC_info">'
1491: .&mt('There were no group members to reinstate, as none were removed when the group was deleted.')
1492: .'</div>');
1.65 raeburn 1493: }
1.104 raeburn 1494: my $outcome = &reenable_folder($cdom,$cnum,$groupname,$description,$crstype);
1.65 raeburn 1495: if ($outcome eq '') {
1.109 wenzelju 1496: my $message = &Apache::lonhtmlcommon::confirm_success(&mt('Group successfully re-enabled.'));
1497: $message = &Apache::loncommon::confirmwrapper($message);
1498: $r->print($message);
1.79 bisitz 1499: } else {
1.104 raeburn 1500: $r->print('<div class="LC_error">');
1.105 bisitz 1501: if ($crstype eq 'Community') {
1.104 raeburn 1502: $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));
1503: } else {
1504: $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));
1505: }
1506: $r->print('</div>');
1.65 raeburn 1507: }
1508: } else {
1.109 wenzelju 1509: my $message = &Apache::lonhtmlcommon::confirm_success(&mt('Re-enabling group failed.'),1);
1510: $message = &Apache::loncommon::confirmwrapper($message);
1511: $r->print($message);
1.64 raeburn 1512: }
1.66 raeburn 1513: return;
1.1 raeburn 1514: }
1515:
1516: sub header {
1.39 albertel 1517: my ($bodytitle,$jscript,$action,$state,$page,$loaditems) = @_;
1.9 albertel 1518: my $start_page=
1.11 albertel 1519: &Apache::loncommon::start_page($bodytitle,
1520: '<script type="text/javascript">'.
1521: $jscript.'</script>',
1.39 albertel 1522: {'add_entries' => $loaditems,});
1.3 raeburn 1523: my $output = <<"END";
1.11 albertel 1524: $start_page
1.117 bisitz 1525: <form method="post" name="$state" action="">
1.3 raeburn 1526:
1527: END
1528: if ($action eq 'create' || $action eq 'modify') {
1529: $output .= <<"END";
1530: <input type="hidden" name="action" value="$action" />
1531: <input type="hidden" name="state" value="" />
1532: <input type="hidden" name="origin" value="$state" />
1.5 raeburn 1533: <input type="hidden" name="page" value="$page" />
1.3 raeburn 1534: END
1535: }
1536: return $output;
1.1 raeburn 1537: }
1538:
1.3 raeburn 1539: sub onload_action {
1540: my ($action,$state) = @_;
1.13 albertel 1541: my %loaditems;
1.3 raeburn 1542: if ((defined($env{'form.origin'})) && ($action eq 'create') &&
1543: ($state eq 'pick_name' || $state eq 'pick_members' ||
1544: $state eq 'pick_privs')) {
1545: unless ($env{'form.origin'} eq '') {
1.13 albertel 1546: $loaditems{'onload'} =
1547: 'javascript:setFormElements(document.'.$state.')';
1.1 raeburn 1548: }
1549: }
1.5 raeburn 1550: if (($action eq 'modify') &&
1551: ($state eq 'change_settings' || $state eq 'change_members' ||
1.53 raeburn 1552: $state eq 'change_privs' || $state eq 'add_members')) {
1.13 albertel 1553: $loaditems{'onload'} =
1554: 'javascript:setFormElements(document.'.$state.')';
1.5 raeburn 1555: }
1.13 albertel 1556: return \%loaditems;
1.1 raeburn 1557: }
1558:
1559: sub footer {
1.9 albertel 1560: my $end_page = &Apache::loncommon::end_page();
1.1 raeburn 1561: return(<<ENDFOOT);
1.6 raeburn 1562: <input type="hidden" name="sortby" value="$env{'form.sortby'}" />
1.1 raeburn 1563: </form>
1.9 albertel 1564: $end_page
1.1 raeburn 1565: ENDFOOT
1566: }
1567:
1.3 raeburn 1568: sub build_members_list {
1569: my ($cdom,$cnum,$types,$roles,$sections,$users,$userdata) = @_;
1570: my %access = ();
1571: foreach my $role (@{$roles}) {
1572: %{$$users{$role}} = ();
1573: }
1574: foreach my $type (@{$types}) {
1575: $access{$type} = $type;
1576: }
1577: &Apache::loncommon::get_course_users($cdom,$cnum,\%access,$roles,
1.5 raeburn 1578: $sections,$users,$userdata);
1.3 raeburn 1579: return;
1580: }
1581:
1582: sub group_files {
1.74 raeburn 1583: my ($group,$portpath,$numfiles,$numdirs) = @_;
1.29 raeburn 1584: my $dirptr=16384;
1.113 raeburn 1585: my ($dirlistref,$listerror) =
1586: &Apache::portfolio::get_dir_list($portpath,undef,$group);
1587: if (ref($dirlistref) eq 'ARRAY') {
1588: foreach my $line (@{$dirlistref}) {
1589: my ($filename,$dom,undef,$testdir,undef,undef,undef,undef,$size,undef,$mtime,undef,undef,undef,$obs,undef)=split(/\&/,$line,16);
1590: if (($filename !~ /^\.\.?$/) && ($filename !~ /\.meta$/ ) && ($filename !~ /(.*)\.(\d+)\.([^\.]*)$/) && ($filename ne 'no_such_dir')) {
1591: if ($dirptr&$testdir) {
1592: $portpath .= '/'.$filename;
1593: $$numdirs ++;
1594: &group_files($group,$portpath,$numfiles,$numdirs)
1595: } else {
1596: $$numfiles ++;
1597: }
1.29 raeburn 1598: }
1599: }
1600: }
1.3 raeburn 1601: return;
1602: }
1603:
1604: sub group_members {
1.4 raeburn 1605: my ($cdom,$cnum,$group,$group_info) = @_;
1606: my %memberhash = &Apache::lonnet::get_group_membership($cdom,$cnum,$group);
1607: my $now = time;
1.60 raeburn 1608: my %lt = &Apache::lonlocal::texthash (
1609: active => 'active',
1610: previous => 'previous',
1611: future => 'future',
1612: );
1613: my %membercounts = (
1614: active => 0,
1615: previous => 0,
1616: future => 0,
1617: );
1.4 raeburn 1618: my $totalmembers = 0;
1.127 raeburn 1619: foreach my $member (keys(%memberhash)) {
1.4 raeburn 1620: $totalmembers ++;
1621: my ($end,$start) = split(/:/,$memberhash{$member});
1.6 raeburn 1622: unless ($start == -1) {
1623: if (($end!=0) && ($end<$now)) {
1.60 raeburn 1624: $membercounts{previous} ++;
1.6 raeburn 1625: } elsif (($start!=0) && ($start>$now)) {
1.60 raeburn 1626: $membercounts{future} ++;
1.6 raeburn 1627: } else {
1.60 raeburn 1628: $membercounts{active} ++;
1.6 raeburn 1629: }
1.4 raeburn 1630: }
1631: }
1632: if ($totalmembers == 0) {
1633: $$group_info{$group}{'totalmembers'} = 'None';
1634: } else {
1.60 raeburn 1635: foreach my $type ('active','previous','future') {
1636: $$group_info{$group}{'totalmembers'} .=
1637: &open_list_window($group,$type,$membercounts{$type},$lt{$type});
1638: }
1.4 raeburn 1639: }
1640: return 'ok';
1.3 raeburn 1641: }
1642:
1.60 raeburn 1643: sub open_list_window {
1644: my ($group,$status,$count,$text) = @_;
1645: my $entry;
1646: if ($count > 0) {
1.83 bisitz 1647: $entry = '<span class="LC_nobreak"><a href="javascript:openGroupRoster('.
1.60 raeburn 1648: "'$group','$status'".')">'.$text.'</a> - '.$count.
1.83 bisitz 1649: '</span><br />';
1.60 raeburn 1650: } else {
1.83 bisitz 1651: $entry = '<span class="LC_nobreak">'.$text.' - '.$count.'</span><br />';
1.60 raeburn 1652: }
1653: return $entry;
1654: }
1655:
1.3 raeburn 1656:
1.5 raeburn 1657: sub general_settings_form {
1.46 albertel 1658: my ($r,$cdom,$cnum,$action,$formname,$page,$functions,$tools,
1.5 raeburn 1659: $toolprivs,$fixedprivs,$sectioncount,$stored,$states,$navbuttons,
1.46 albertel 1660: $gpterm,$ucgpterm,$crstype) = @_;
1.5 raeburn 1661: my ($nexttext,$prevtext);
1.42 albertel 1662: &groupsettings_options($r,$functions,$action,$formname,$stored,1,
1.29 raeburn 1663: $gpterm,$ucgpterm,$crstype);
1.41 albertel 1664: &access_date_settings($r,$action,$formname,$stored,2,$gpterm,$ucgpterm);
1.5 raeburn 1665: if ($action eq 'create') {
1.59 raeburn 1666: &membership_options($r,$cdom,$cnum,$action,$formname,$sectioncount,3,
1.104 raeburn 1667: $gpterm,$ucgpterm,$crstype);
1.5 raeburn 1668: $nexttext = $$navbuttons{'gtns'};
1669: } else {
1670: my @available = ();
1671: my @unavailable = ();
1672: &check_tools($functions,$tools,\@available,\@unavailable);
1673: @{$tools} = sort(keys(%{$functions}));
1.46 albertel 1674: &privilege_specificity($r,$action,3,$tools,$stored,$toolprivs,
1675: $fixedprivs,\@available,$formname,
1.104 raeburn 1676: $gpterm,$ucgpterm,$functions,$crstype);
1.44 albertel 1677: &mapping_options($r,$action,$formname,$page,$sectioncount,
1678: $states,$stored,$navbuttons,4,5,
1.58 raeburn 1679: $gpterm,$ucgpterm,$crstype,$cdom,$cnum);
1.5 raeburn 1680: $nexttext = $$navbuttons{'mose'};
1681: }
1682: $prevtext = $$navbuttons{'gtpp'};
1683: &display_navbuttons($r,$formname,$$states{$action}[$page-1],$prevtext,
1684: $$states{$action}[$page+1],$nexttext);
1685: return;
1686: }
1687:
1688: sub groupsettings_options {
1.42 albertel 1689: my ($r,$functions,$action,$formname,$stored,$image,$gpterm,
1.29 raeburn 1690: $ucgpterm,$crstype) = @_;
1.1 raeburn 1691: my %lt = &Apache::lonlocal::texthash(
1.53 raeburn 1692: 'gdat' => "Group access start and end dates",
1693: 'gnde' => "Group name, title and available collaborative tools",
1694: 'desc' => 'Group Title',
1695: 'func' => 'Collaborative Tools',
1696: 'gnam' => 'Group Name',
1697: 'lett' => 'Letters, numbers and underscore only',
1698: 'doyo' => 'Different subsets of the chosen collaborative tools '.
1699: 'for different group members?',
1.97 bisitz 1700: 'gran' => 'Granularity',
1701: 'dquo' => 'Disk quota',
1.1 raeburn 1702: );
1.37 raeburn 1703: my ($crsquota,$freespace,$maxposs) = &get_quota_constraints($action,$stored);
1.97 bisitz 1704: $r->print(&Apache::lonhtmlcommon::topic_bar($image,$lt{'gnde'}));
1705:
1706: # Group Name
1707: $r->print(&Apache::lonhtmlcommon::start_pick_box()
1708: .&Apache::lonhtmlcommon::row_title($lt{'gnam'})
1709: );
1.5 raeburn 1710: if ($action eq 'create') {
1.97 bisitz 1711: $r->print('<input type="text" name="groupname" size="25" />'
1712: .' <span class="LC_nobreak">('
1713: .$lt{'lett'}.')</span>'
1714: );
1.5 raeburn 1715: } else {
1716: $r->print('<input type="hidden" name="groupname" value="'.
1717: $env{'form.groupname'}.'" />'.$env{'form.groupname'});
1718: }
1.97 bisitz 1719: $r->print(&Apache::lonhtmlcommon::row_closure());
1720:
1721: # Group Title
1722: $r->print(&Apache::lonhtmlcommon::row_title($lt{'desc'})
1723: .'<input type="text" name="description" size="40" value="" />'
1724: .&Apache::lonhtmlcommon::row_closure()
1725: );
1726:
1727: # Collaborative Tools
1.3 raeburn 1728: my $numitems = keys(%{$functions});
1729: my $halfnum = int($numitems/2);
1730: my $remnum = $numitems%2;
1731: if ($remnum) {
1732: $halfnum ++;
1733: }
1.127 raeburn 1734: my @allfunctions = sort(keys(%{$functions}));
1.97 bisitz 1735:
1736: $r->print(&Apache::lonhtmlcommon::row_title($lt{'func'})
1737: .'<div>'
1738: .'<input type="button" value="'.&mt('check all').'"'
1739: .' onclick="javascript:checkAll(document.'.$formname.'.tool)" />'
1740: .' <input type="button" value="'.&mt('uncheck all').'"'
1741: .' onclick="javascript:uncheckAll(document.'.$formname.'.tool)" />'
1742: .'</div>'
1743: .'<table cellpadding="5px"><tr>' # FIXME Get rid of inflexible table (-> float)
1744: );
1745: for (my $i=0; $i<@allfunctions; $i++) {
1746: $r->print('<td><label><span class="LC_nobreak">'
1747: .'<input type="checkbox" name="tool" value="'
1748: .$allfunctions[$i].'" /> '
1749: .&mt($$functions{$allfunctions[$i]})
1750: .'</span></label></td>'
1751: );
1752: if ($i == $halfnum - 1) {
1753: $r->print('</tr><tr>');
1754: }
1.3 raeburn 1755: }
1.97 bisitz 1756: $r->print('</tr></table>'
1757: .&Apache::lonhtmlcommon::row_closure()
1758: );
1759:
1760: # Granularity
1761: $r->print(&Apache::lonhtmlcommon::row_title($lt{'gran'})
1762: .$lt{'doyo'}.'<br />'
1763: .'<label>'
1764: .'<input type="radio" name="granularity" value="Yes" />'.&mt('Yes')
1765: .'</label> <label>'
1766: .'<input type="radio" name="granularity" value="No" checked="checked" />'.&mt('No')
1767: .'</label>'
1768: );
1.5 raeburn 1769: if ($action eq 'modify') {
1.97 bisitz 1770: $r->print(' <span class="LC_nobreak">('
1771: .&mt('Currently set to [_1].'
1772: ,'"'.&mt($$stored{'granularity'}).'"')
1773: .')</span>'
1774: );
1.5 raeburn 1775: }
1.97 bisitz 1776: $r->print(&Apache::lonhtmlcommon::row_closure());
1777:
1778: # Disk Quota
1779: $r->print(&Apache::lonhtmlcommon::row_title($lt{'dquo'}));
1.29 raeburn 1780: if ($action eq 'create') {
1.97 bisitz 1781: $r->print('<span class="LC_info">'
1782: .&mt('If you enable the group portfolio for the '.$gpterm
1783: .', allocate a disk quota.')
1784: .'</span>'
1785: );
1.29 raeburn 1786: } else {
1.96 weissno 1787: $r->print(&mt('Quota allocated to group portfolio:'));
1.29 raeburn 1788: }
1.122 raeburn 1789: $r->print(' '.&mt('[_1] MB','<input type="text" name="quota" size="4" />'));
1.29 raeburn 1790: if ($action eq 'create') {
1.79 bisitz 1791: $r->print('<br />'
1.122 raeburn 1792: .&mt('A total of [_1] MB can be divided amongst all '.$gpterm.'s in the '
1793: .lc($crstype).', and [_2] MB are currently unallocated.'
1.79 bisitz 1794: ,$crsquota,sprintf("%.2f",$freespace))
1795: );
1.29 raeburn 1796: } else {
1.122 raeburn 1797: $r->print(' ('.&mt('The quota is currently [_1] MB',
1.29 raeburn 1798: $$stored{'quota'}).').');
1799:
1.79 bisitz 1800: $r->print('<br />'
1.122 raeburn 1801: .&mt('The quota can be increased to [_1] MB, '
1.79 bisitz 1802: .'by adding all unallocated space for '.$gpterm.'s in the '.lc($crstype).'.'
1803: ,sprintf("%.2f",$maxposs)));
1.29 raeburn 1804: }
1.97 bisitz 1805: $r->print(&Apache::lonhtmlcommon::row_closure(1));
1806:
1807: $r->print(&Apache::lonhtmlcommon::end_pick_box());
1808:
1.5 raeburn 1809: return;
1810: }
1811:
1.37 raeburn 1812: sub get_quota_constraints {
1813: my ($action,$stored) = @_;
1814: my ($crsquota,$freespace,$maxposs);
1815: $crsquota = $env{'course.'.$env{'request.course.id'}.'.internal.coursequota'};
1816: if ($crsquota eq '') {
1817: $crsquota = 20;
1818: }
1819: $freespace = $crsquota - &Apache::longroup::sum_quotas();
1820: if ($action eq 'create') {
1821: $maxposs = $freespace;
1822: } else {
1823: $maxposs = $$stored{'quota'} + $freespace;
1824: }
1825: return ($crsquota,$freespace,$maxposs);
1826: }
1827:
1.5 raeburn 1828: sub membership_options {
1.104 raeburn 1829: my ($r,$cdom,$cnum,$action,$state,$sectioncount,$image,$gpterm,$ucgpterm,$crstype)=@_;
1.5 raeburn 1830: my %lt = &Apache::lonlocal::texthash(
1.53 raeburn 1831: 'pipa' => 'Build a list of users for selection of group members',
1.104 raeburn 1832: 'gmem' => 'Group membership selection list criteria:',
1833: 'picr' => 'Pick the criteria to use to build a list of course users from which you will select members of the new group.',
1834: 'pica' => 'Pick the criteria to use to build a list of course users from which you will select additional members of the group.',
1835: 'ifno' => 'If you do not wish to add members when you first create the group, there is no need to pick any criteria.',
1.5 raeburn 1836: 'acty' => 'Access types',
1.104 raeburn 1837: 'coro' => 'Course roles',
1838: 'cose' => 'Course sections',
1.5 raeburn 1839: );
1.104 raeburn 1840: if ($crstype eq 'Community') {
1841: $lt{'picr'} = &mt('Pick the criteria to use to build a list of community participants from which you will select ');
1842: $lt{'asub'} = &mt('A subsequent step will also allow you to specify automatic adding/dropping of group members triggered by specified user role and section [_1]changes[_2] in the course.','<i>','</i>');
1843: $lt{'coro'} = &mt('Community roles');
1844: $lt{'cose'} = &mt('Community sections');
1845: } else {
1846: $lt{'asub'} = &mt('A subsequent step will also allow you to specify automatic adding/dropping of group members triggered by specified user role and section [_1]changes[_2] in the course.','<i>','</i>');
1847: }
1.5 raeburn 1848: my %status_types = (
1849: active => &mt('Currently has access'),
1850: previous => &mt('Previously had access'),
1851: future => &mt('Will have future access'),
1852: );
1.15 albertel 1853:
1.104 raeburn 1854: my @roles = ('st');
1855: if ($crstype eq 'Community') {
1856: push(@roles,'co');
1857: } else {
1858: push(@roles,'cc');
1859: }
1860: push (@roles,('in','ta','ep','ad','cr'));
1.5 raeburn 1861:
1862: my @sections = keys(%{$sectioncount});
1863:
1.78 raeburn 1864: $r->print(&Apache::lonhtmlcommon::topic_bar($image,$lt{'pipa'}).'
1.104 raeburn 1865: <b>'.$lt{'gmem'}.'</b><br />');
1.5 raeburn 1866: if ($action eq 'create') {
1.104 raeburn 1867: $r->print($lt{'picr'}.'<br />'.$lt{'ifno'}.'<br />'.$lt{'asub'});
1.5 raeburn 1868: } else {
1.104 raeburn 1869: $r->print($lt{'pica'});
1.5 raeburn 1870: }
1871: $r->print('
1872: <br />
1873: <br />
1.40 albertel 1874: <table class="LC_status_selector">
1.3 raeburn 1875: <tr>
1.40 albertel 1876: <th>'.$lt{'acty'}.'</th>
1.53 raeburn 1877: <th>'.$lt{'coro'}.'</th>
1878: <th>'.$lt{'cose'}.'</th>
1879: </tr><tr><td>');
1.3 raeburn 1880: $r->print(&Apache::lonhtmlcommon::status_select_row(\%status_types));
1.40 albertel 1881: $r->print('</td><td>');
1.59 raeburn 1882: $r->print(&Apache::lonhtmlcommon::role_select_row(\@roles,undef,undef,1,$cdom,$cnum));
1.3 raeburn 1883: if (@sections > 0) {
1.5 raeburn 1884: @sections = sort {$a cmp $b} @sections;
1.31 albertel 1885: unshift(@sections,'none'); # Put 'no sections' next
1.17 raeburn 1886: unshift(@sections,'all'); # Put 'all' at the front of the list
1.53 raeburn 1887: } else {
1888: @sections = ('all','none');
1.3 raeburn 1889: }
1.53 raeburn 1890: $r->print('</td><td>'.
1891: §ions_selection(\@sections,'sectionpick').'</td>
1.3 raeburn 1892: </tr>
1.40 albertel 1893: </table>');
1.5 raeburn 1894: return;
1895: }
1896:
1897: sub sections_selection {
1898: my ($sections,$elementname) = @_;
1899: my $section_sel;
1900: my $numvisible = 4;
1901: if (@{$sections} < 4) {
1902: $numvisible = @{$sections};
1903: }
1904: foreach my $sec (@{$sections}) {
1.17 raeburn 1905: if ($sec eq 'all') {
1.53 raeburn 1906: $section_sel .= ' <option value="'.$sec.'">'.&mt('all sections').'</option>'."\n";
1.17 raeburn 1907: } elsif ($sec eq 'none') {
1.31 albertel 1908: $section_sel .= ' <option value="'.$sec.'">'.&mt('no section').'</option>'."\n";
1.5 raeburn 1909: } else {
1.31 albertel 1910: $section_sel .= ' <option value="'.$sec.'">'.$sec."</option>\n";
1.5 raeburn 1911: }
1912: }
1913: my $output = '
1.89 bisitz 1914: <select name="'.$elementname.'" multiple="multiple" size="'.$numvisible.'">
1.5 raeburn 1915: '.$section_sel.'
1916: </select>';
1917: return $output;
1918: }
1919:
1920: sub access_date_settings {
1.41 albertel 1921: my ($r,$action,$formname,$stored,$image,$gpterm,$ucgpterm) = @_;
1.80 bisitz 1922: my $sten = &mt("Default start and end dates for $gpterm access");
1.5 raeburn 1923: my $starttime = time;
1924: my $endtime = time+(6*30*24*60*60); # 6 months from now, approx
1925: if ($action eq 'modify') {
1926: $starttime = $$stored{'startdate'};
1927: unless ($$stored{'enddate'} == 0) {
1928: $endtime = $$stored{'enddate'};
1929: }
1930: }
1.41 albertel 1931: my ($table) = &date_setting_table($starttime,$endtime,$formname);
1.80 bisitz 1932: $r->print(&Apache::lonhtmlcommon::topic_bar($image,$sten).'
1.41 albertel 1933: '.$table.'
1934: ');
1.3 raeburn 1935: return;
1936: }
1937:
1.5 raeburn 1938: sub choose_members_form {
1.46 albertel 1939: my ($r,$cdom,$cnum,$action,$formname,$page,$groupname,$description,
1.29 raeburn 1940: $granularity,$quota,$startdate,$enddate,$tools,$fixedprivs,$toolprivs,
1.5 raeburn 1941: $functions,$users,$userdata,$idx,$stored,$states,$navbuttons,
1.46 albertel 1942: $gpterm,$ucgpterm,$crstype) = @_;
1.5 raeburn 1943: my @regexps = ('user_','userpriv_','sec_');
1944: my %origmembers;
1.3 raeburn 1945: $r->print(&Apache::lonhtmlcommon::echo_form_input(
1.5 raeburn 1946: ['origin','action','state','page','member','specificity','branch',
1.7 raeburn 1947: 'defpriv','autorole','autoadd','autodrop','sortby','togglefunc'],
1.5 raeburn 1948: \@regexps));
1.29 raeburn 1949: my $earlyout = &validate_groupname($groupname,$action,$cdom,$cnum,$gpterm,
1950: $ucgpterm,$crstype);
1.5 raeburn 1951: if ($earlyout) {
1.47 raeburn 1952: $r->print($earlyout);
1.5 raeburn 1953: &display_navbuttons($r,$formname,$$states{$action}[$page-1],
1954: $$navbuttons{'gtps'});
1.3 raeburn 1955: return;
1.5 raeburn 1956: }
1957: my ($specimg,$memimg);
1958: my @available = ();
1959: my @unavailable = ();
1960: &check_tools($functions,$tools,\@available,\@unavailable);
1961: if ($action eq 'create') {
1.40 albertel 1962: &print_current_settings($r,$action,$functions,$startdate,$enddate,
1963: $groupname,$description,$granularity,$quota,
1964: \@available,\@unavailable,$gpterm,$ucgpterm);
1.5 raeburn 1965: $specimg = 4;
1966: $memimg = 5;
1967: } else {
1968: $specimg = 2;
1969: $memimg = 3;
1970: my %membership = &Apache::lonnet::get_group_membership($cdom,$cnum,
1971: $groupname);
1972: foreach my $key (sort(keys(%membership))) {
1973: if ($key =~ /^\Q$groupname\E:([^:]+):([^:]+)$/) {
1.6 raeburn 1974: my ($end,$start,@userprivs) = split(/:/,$membership{$key});
1975: unless ($start == -1) {
1976: my $uname = $1;
1977: my $udom = $2;
1978: my $user = $uname.':'.$udom;
1979: $origmembers{$user} = 1;
1980: }
1.5 raeburn 1981: }
1982: }
1983: }
1.46 albertel 1984: &privilege_specificity($r,$action,$specimg,$tools,$stored,$toolprivs,
1.103 raeburn 1985: $fixedprivs,\@available,$formname,$gpterm,$ucgpterm,
1.104 raeburn 1986: $functions,$crstype);
1.44 albertel 1987: my $newusers = &pick_new_members($r,$action,$formname,\@available,$idx,
1988: $stored,$memimg,$users,$userdata,
1989: $granularity,\%origmembers,$gpterm,
1990: $ucgpterm);
1.5 raeburn 1991: if ($newusers || $action eq 'create') {
1992: &display_navbuttons($r,$formname,$$states{$action}[$page-1],
1993: $$navbuttons{'gtps'},$$states{$action}[$page+1],
1994: $$navbuttons{'gtns'});
1995: } else {
1996: &display_navbuttons($r,$formname,$$states{$action}[$page-1],
1997: $$navbuttons{'gtps'});
1.3 raeburn 1998: }
1.5 raeburn 1999: return;
2000: }
2001:
2002: sub display_navbuttons {
2003: my ($r,$formname,$prev,$prevtext,$next,$nexttext) = @_;
1.42 albertel 2004: $r->print('<div class="LC_navbuttons">');
1.5 raeburn 2005: if ($prev) {
2006: $r->print('
2007: <input type="button" name="previous" value = "'.$prevtext.'"
2008: onclick="javascript:backPage(document.'.$formname.','."'".$prev."'".')"/>
2009: ');
1.64 raeburn 2010: } elsif ($prevtext) {
2011: $r->print('
2012: <input type="button" name="previous" value = "'.$prevtext.'"
2013: onclick="javascript:history.back()"/>
2014: ');
1.5 raeburn 2015: }
2016: if ($next) {
2017: $r->print('
2018: <input type="button" name="next" value="'.$nexttext.'"
2019: onclick="javascript:nextPage(document.'.$formname.','."'".$next."'".')" />');
2020: }
1.42 albertel 2021: $r->print('</div>');
1.5 raeburn 2022: }
2023:
2024: sub check_tools {
2025: my ($functions,$tools,$available,$unavailable) = @_;
2026: foreach my $item (sort(keys(%{$functions}))) {
2027: if (grep/^$item$/,@{$tools}) {
2028: push(@{$available},$item);
2029: } else {
2030: push(@{$unavailable},$item);
2031: }
2032: }
2033: return;
2034: }
2035:
2036: sub print_current_settings {
1.40 albertel 2037: my ($r,$action,$functions,$startdate,$enddate,$groupname,$description,
2038: $granularity,$quota,$available,$unavailable,$gpterm,$ucgpterm) = @_;
1.5 raeburn 2039:
2040: my %lt = &Apache::lonlocal::texthash(
1.53 raeburn 2041: grna => 'Group Name',
2042: desc => 'Group Title',
2043: grfn => "Collaborative Tools",
1.5 raeburn 2044: gran => 'Granularity',
1.29 raeburn 2045: quot => 'File quota',
1.5 raeburn 2046: dfac => 'Default access dates',
1.53 raeburn 2047: ygrs => "Your group selections - ",
2048: tfwa => "The following settings will apply to the group:",
1.80 bisitz 2049: stda => 'Start date:',
1.5 raeburn 2050: enda => 'End date:',
2051: );
1.118 bisitz 2052: $lt{'difn'} = &mt('Different collaborative tools[_1]for different members:','<br />');
1.3 raeburn 2053: my $showstart = &Apache::lonlocal::locallocaltime($startdate);
1.5 raeburn 2054: my $showend;
2055: if ($enddate == 0) {
2056: $showend = &mt('No end date set');
2057: } else {
2058: $showend = &Apache::lonlocal::locallocaltime($enddate);
2059: }
2060: if ($action eq 'create') {
2061: $r->print('
1.42 albertel 2062: <div><span style="font-size: larger">'.$lt{'ygrs'}.'</span>
1.5 raeburn 2063: <br />'.$lt{'tfwa'}.'
1.40 albertel 2064: </div>');
1.5 raeburn 2065: }
1.40 albertel 2066: $r->print(&Apache::loncommon::start_data_table('LC_course_group_status').
2067: &Apache::loncommon::start_data_table_header_row());
2068: $r->print('
2069: <th>'.$lt{'grna'}.'</th>
2070: <th>'.$lt{'desc'}.'</th>
2071: <th>'.$lt{'grfn'}.'</th>
2072: <th>'.$lt{'gran'}.'</th>
2073: <th>'.$lt{'quot'}.'</th>
2074: <th>'.$lt{'dfac'}.'</th>
2075: ');
2076: $r->print(&Apache::loncommon::end_data_table_header_row().
2077: &Apache::loncommon::start_data_table_row('LC_data_table_dense'));
1.3 raeburn 2078: $r->print('
1.40 albertel 2079: <td valign="top">'.$groupname.'</td>
2080: <td valign="top">'.$description.'</td>
1.3 raeburn 2081: <td>
2082: ');
1.99 bisitz 2083:
1.5 raeburn 2084: if (@{$available} > 0) {
1.99 bisitz 2085: $r->print('<b>'.&mt('Available for assignment to members:').'</b>');
2086: $r->print('<ul>');
1.5 raeburn 2087: for (my $i=0; $i<@{$available}; $i++) {
1.99 bisitz 2088: $r->print('<li>'.&mt($$functions{$$available[$i]}).'</li>');
1.3 raeburn 2089: }
1.99 bisitz 2090: $r->print('</ul>');
1.3 raeburn 2091: }
1.99 bisitz 2092:
1.5 raeburn 2093: if (@{$unavailable} > 0) {
1.99 bisitz 2094: $r->print('<b>'.&mt('Unavailable for assignment:').'</b>');
2095: $r->print('<ul>');
2096: for (my $i=0; $i<@{$unavailable}; $i++) {
2097: $r->print('<li>'.&mt($$functions{$$unavailable[$i]}).'</li>');
1.3 raeburn 2098: }
1.99 bisitz 2099: $r->print('</ul>');
1.3 raeburn 2100: }
1.99 bisitz 2101:
1.122 raeburn 2102: my $quota_text=&mt('[_1] MB',$quota);
1.80 bisitz 2103: my $granu_text=&mt($granularity);
1.3 raeburn 2104: $r->print(<<"END");
2105: </td>
1.80 bisitz 2106: <td valign="top"><b>$lt{'difn'}</b> $granu_text</td>
1.79 bisitz 2107: <td valign="top">$quota_text</td>
1.40 albertel 2108: <td valign="top"><b>$lt{'stda'}</b> $showstart<br />
2109: <b>$lt{'enda'}</b> $showend
1.3 raeburn 2110: </td>
2111: END
1.40 albertel 2112: $r->print(&Apache::loncommon::end_data_table_row().
2113: &Apache::loncommon::end_data_table());
1.5 raeburn 2114: return;
2115: }
2116:
2117: sub pick_new_members {
1.44 albertel 2118: my ($r,$action,$formname,$available,$idx,$stored,$img,$users,$userdata,
2119: $granularity,$origmembers,$gpterm,$ucgpterm) = @_;
1.5 raeburn 2120: my %lt = &Apache::lonlocal::texthash(
1.53 raeburn 2121: 'gpme' => "Group membership",
1.5 raeburn 2122: 'addm' => 'Add members',
1.53 raeburn 2123: 'setf' => 'Assign collaborative tools',
2124: 'func' => 'Tools',
2125: 'nome' => 'No members to add at this time, as there are no users '.
2126: 'matching the specified type(s), role(s) and section(s).',
1.29 raeburn 2127: 'nnew' => "There are no users to add as new members, as all users".
1.53 raeburn 2128: " matching the specified type(s), role(s), and ".
2129: "section(s) are already affiliated with this group.",
1.79 bisitz 2130: 'yoma' => "You may need to use the 'modify existing, past or ".
2131: "future members' page if you need to re-enable ".
2132: "or activate access for previous or future members.",
1.5 raeburn 2133: );
2134: my %members;
2135: my $totalusers = 0;
2136: my $newusers = 0;
1.3 raeburn 2137: foreach my $role (keys(%{$users})) {
2138: foreach my $user (keys(%{$$users{$role}})) {
1.5 raeburn 2139: $totalusers ++;
2140: if (ref($origmembers) eq 'HASH') {
2141: if (exists($$origmembers{$user})) {
2142: next;
2143: }
2144: }
1.3 raeburn 2145: unless (defined($members{$user})) {
2146: @{$members{$user}} = @{$$userdata{$user}};
1.5 raeburn 2147: $newusers ++;
1.3 raeburn 2148: }
2149: }
2150: }
2151: if (keys(%members) > 0) {
1.5 raeburn 2152: if (@{$available} > 0 && $granularity eq 'Yes') {
2153: $r->print(&check_uncheck_tools($r,$available));
2154: }
2155: }
1.78 raeburn 2156: $r->print(&Apache::lonhtmlcommon::topic_bar($img,$lt{'gpme'}));
1.5 raeburn 2157: if (keys(%members) > 0) {
2158: $r->print('
1.3 raeburn 2159: <table>
1.5 raeburn 2160: <tr>');
2161: &check_uncheck_buttons($r,$formname,'member',$lt{'addm'});
2162: if (@{$available} > 0 && $granularity eq 'Yes') {
1.48 albertel 2163: $r->print('<td>
1.102 bisitz 2164: <fieldset><legend>'.$lt{'setf'}.'</legend>
1.83 bisitz 2165: <span class="LC_nobreak">
1.80 bisitz 2166: <input type="button" value="'.&mt('check all').'"
1.5 raeburn 2167: onclick="javascript:checkAllTools(document.'.$formname.')" />
2168:
1.80 bisitz 2169: <input type="button" value="'.&mt('uncheck all').'"
1.3 raeburn 2170: onclick="javascript:uncheckAllTools(document.'.$formname.')" />
1.83 bisitz 2171: </span>
1.48 albertel 2172: </fieldset></td>');
1.3 raeburn 2173: }
2174: $r->print('</tr></table>
2175: ');
1.43 albertel 2176: $r->print(&Apache::loncommon::start_data_table().
2177: &Apache::loncommon::start_data_table_header_row());
1.5 raeburn 2178: $r->print('
1.43 albertel 2179: <th>'.&mt('Add?').'</b></td>
2180: <th><a href="javascript:changeSort('."'fullname'".')">'.&mt('Name').'</a></td>
2181: <th><a href="javascript:changeSort('."'username'".')">'.&mt('Username').'</a></td>
2182: <th><a href="javascript:changeSort('."'domain'".')">'.&mt('Domain').'</a></td>
2183: <th><a href="javascript:changeSort('."'id'".')">'.&mt('ID').'</a></td>
2184: <th><a href="javascript:changeSort('."'section'".')">'.&mt('Section').'</a></td>
1.5 raeburn 2185: ');
2186: if (@{$available} > 0) {
1.43 albertel 2187: $r->print('<th>'.$lt{'func'}.'</th>');
1.3 raeburn 2188: }
1.43 albertel 2189: $r->print(&Apache::loncommon::end_data_table_header_row());
1.5 raeburn 2190: if (@{$available} > 0) {
2191: if ($granularity eq 'Yes') {
1.43 albertel 2192: $r->print(&Apache::loncommon::start_data_table_row('LC_data_table_dense LC_data_table_highlight').'
1.35 raeburn 2193: <td colspan="6"> </td>
1.83 bisitz 2194: <td align="center"><span class="LC_nobreak"><b>'.&mt('All:').'</b> ');
1.5 raeburn 2195: foreach my $tool (@{$available}) {
1.7 raeburn 2196: $r->print('<label><input type="checkbox" name="togglefunc" '.
2197: 'onclick="javascript:toggleTools(document.'.$formname.'.user_'.$tool.',this);"'.
2198: ' value="'.$tool.'">'.'<b>'.$tool.'</b></label> ');
1.5 raeburn 2199: }
1.83 bisitz 2200: $r->print('</span></td></tr>');
1.5 raeburn 2201: }
2202: }
1.3 raeburn 2203: my %Sortby = ();
2204: foreach my $user (sort(keys(%members))) {
2205: if ($env{'form.sortby'} eq 'fullname') {
2206: push(@{$Sortby{$members{$user}[$$idx{fullname}]}},$user);
2207: } elsif ($env{'form.sortby'} eq 'username') {
2208: push(@{$Sortby{$members{$user}[$$idx{uname}]}},$user);
2209: } elsif ($env{'form.sortby'} eq 'domain') {
2210: push(@{$Sortby{$members{$user}[$$idx{udom}]}},$user);
2211: } elsif ($env{'form.sortby'} eq 'id') {
2212: push(@{$Sortby{$members{$user}[$$idx{id}]}},$user);
1.31 albertel 2213: } elsif ($env{'form.sortby'} eq 'section') {
2214: push(@{$Sortby{$members{$user}[$$idx{section}]}},$user);
1.3 raeburn 2215: } else {
2216: push(@{$Sortby{$members{$user}[$$idx{fullname}]}},$user);
2217: }
2218: }
2219: foreach my $key (sort(keys(%Sortby))) {
2220: foreach my $user (@{$Sortby{$key}}) {
2221: my $id = $members{$user}[$$idx{id}];
2222: my $fullname = $members{$user}[$$idx{fullname}];
2223: my $udom = $members{$user}[$$idx{udom}];
2224: my $uname = $members{$user}[$$idx{uname}];
1.31 albertel 2225: my $section = $members{$user}[$$idx{section}];
1.43 albertel 2226: $r->print(&Apache::loncommon::start_data_table_row('LC_data_table_dense').
2227: '<td align="right"><input type="checkbox" name="member" value="'.$user.'" /></td>'.
2228: '<td>'.$fullname.'</td>'.
2229: '<td>'.$uname.'</td>'.
2230: '<td>'.$udom.'</td>'.
2231: '<td>'.$id.'</td>'.
2232: '<td>'.$section.'</td>');
1.5 raeburn 2233: if (@{$available} > 0) {
1.83 bisitz 2234: $r->print('<td align="center"><span class="LC_nobreak">'.
1.5 raeburn 2235: ' ');
2236: foreach my $tool (@{$available}) {
2237: if ($granularity eq 'Yes') {
1.3 raeburn 2238: $r->print('<input type="checkbox" name="user_'.
2239: $tool.'" value="'.$user.'" />'.$tool.' ');
2240: } else {
2241: $r->print('<input type="hidden" name="user_'.
2242: $tool.'" value="'.$user.'" />'.$tool.' ');
2243: }
2244: }
1.83 bisitz 2245: $r->print('</span></td>');
1.3 raeburn 2246: }
1.43 albertel 2247: $r->print(&Apache::loncommon::end_data_table_row()."\n");
1.3 raeburn 2248: }
2249: }
1.43 albertel 2250: $r->print(&Apache::loncommon::end_data_table());
1.5 raeburn 2251: } else {
2252: if ($totalusers > 0) {
2253: $r->print($lt{'nnew'}.'<br /><br />'.$lt{'yoma'});
2254: } else {
2255: $r->print($lt{'nome'});
2256: }
2257: }
2258: return $newusers;
2259: }
2260:
2261: sub privilege_specificity {
1.46 albertel 2262: my ($r,$action,$img,$tools,$stored,$toolprivs,$fixedprivs,$available,
1.104 raeburn 2263: $formname,$gpterm,$ucgpterm,$functions,$crstype) = @_;
1.5 raeburn 2264: my %lt = &Apache::lonlocal::texthash (
1.53 raeburn 2265: 'uprv' => 'User privileges for collaborative tools',
2266: 'frty' => 'For each collaborative tool you have chosen to include, '.
2267: 'there is a set of core privileges which all group members '.
2268: 'assigned use of the tool will receive.',
2269: 'thar' => 'For some tools there are also additional optional '.
2270: 'privileges which can be set.',
2271: 'plch' => 'Choose one of the following:',
2272: 'fort' => 'For the collaborative tools you have chosen to include '.
2273: 'only core privileges are available, '.
2274: 'so there are no optional privileges to assign.',
2275: 'eaty' => 'Each collaborative tool includes core '.
2276: 'privileges assigned to all members with access to the '.
2277: 'tool. Some tools may also feature additional privileges '.
1.5 raeburn 2278: 'which can be set for specific members.',
1.53 raeburn 2279: 'cutg' => 'Currently the group is configured ',
2280: 'sdif' => 'so different members can receive different optional privileges for a particular tool.',
2281: 'sall' => 'so all members will receive the same optional privileges for a particular tool.',
2282: 'algm' => 'All group members will receive the same privileges for any tool assigned to them, including the default set of optional privileges.',
2283: 'smgp' => 'Different group members may receive different privileges from '.
2284: 'others for the tools they have been assigned.',
2285: 'thwi' => 'These will be the privileges all group members receive for a particular assigned tool, '.
2286: 'if you selected the first option above.',
1.29 raeburn 2287: 'thes' => "These will be the privileges given to members assigned ".
1.53 raeburn 2288: "in the future via automatic group assignment ".
2289: "for users who receive specific sections/roles in the course ",
2290: 'asyo' => "As you have chosen not to include any collaborative tools ".
2291: "in the group, no default optional privileges need to be set.",
2292: 'will receive by default for a specific tool.',
1.5 raeburn 2293: 'oppr' => 'Optional privileges',
2294: 'defp' => 'The default privileges new members will receive are:',
2295: );
1.116 raeburn 2296: $lt{'plin'} = &mt('Indicate which [_1]optional[_2] privileges members '.
2297: 'will receive by default for a specific tool.','<b>','</b>');
1.104 raeburn 2298: if ($crstype eq 'Community') {
2299: $lt{'thes'} = &mt('These will be the privileges given to members assigned in the future via automatic group assignment for users who receive specific sections/roles in the community ');
2300: }
1.5 raeburn 2301: my $totaloptionalprivs = 0;
2302: foreach my $tool (@{$tools}) {
2303: foreach my $priv (sort(keys(%{$$toolprivs{$tool}}))) {
2304: if (!exists($$fixedprivs{$tool}{$priv})) {
2305: $totaloptionalprivs ++;
2306: }
2307: }
2308: }
1.78 raeburn 2309: $r->print(&Apache::lonhtmlcommon::topic_bar($img,$lt{'uprv'}));
1.5 raeburn 2310: if ((($action eq 'create') && (@{$available} > 0)) ||
1.55 raeburn 2311: (($action eq 'modify') && ($formname eq 'change_settings'))) {
1.5 raeburn 2312: my %specific = (
2313: 'No' => 'checked="checked"',
2314: 'Yes' => '',
2315: );
2316: if ($action eq 'create') {
2317: $r->print($lt{'frty'}.'<br />');
2318: if ($totaloptionalprivs) {
1.53 raeburn 2319: $r->print($lt{'thar'}.'<br /><br />'.$lt{'plch'});
1.5 raeburn 2320: } else {
2321: $r->print($lt{'fort'});
2322: }
2323: } else {
2324: $r->print($lt{'eaty'}.' '.$lt{cutg});
2325: if ($$stored{'specificity'} eq 'Yes') {
2326: $r->print($lt{'sdif'});
2327: $specific{'Yes'} = $specific{'No'};
2328: $specific{'No'} = '';
2329: } else {
2330: $r->print($lt{'sall'});
2331: }
2332: }
2333: if ($totaloptionalprivs) {
2334: $r->print('
1.53 raeburn 2335: <br />
1.83 bisitz 2336: <label><span class="LC_nobreak"><input type="radio" name="specificity" value="No" '.$specific{'No'}.' /> '.$lt{'algm'}.'</span></label><br />
2337: <label><span class="LC_nobreak"><input type="radio" name="specificity" value="Yes" '.$specific{'Yes'}.' /> '.$lt{'smgp'}.'</span></label><br /><br />');
1.5 raeburn 2338: } else {
2339: $r->print('<input type="hidden" name="specificity" value="No" />');
2340: }
2341: if ($totaloptionalprivs) {
1.40 albertel 2342: $r->print($lt{'plin'});
1.5 raeburn 2343: if ($action eq 'create') {
1.53 raeburn 2344: $r->print('<br />'.$lt{'thwi'});
1.5 raeburn 2345: }
2346: $r->print('<br />'.$lt{'thes'});
2347: if ($action eq 'create') {
2348: $r->print('('.&mt('if enabled on the next page').').');
2349: } else {
2350: $r->print('('.&mt('if enabled below').').');
2351: }
2352: $r->print('<br /><br />
1.40 albertel 2353: <table><tr>');
1.5 raeburn 2354: &check_uncheck_buttons($r,$formname,'defpriv',$lt{'oppr'});
2355: $r->print('
2356: </tr>
2357: </table>
1.3 raeburn 2358: <br />
2359: ');
1.5 raeburn 2360: } else {
1.40 albertel 2361: $r->print($lt{'algm'}.'<br /><br />');
1.3 raeburn 2362: }
1.42 albertel 2363: &default_privileges($r,$action,$tools,$toolprivs,$fixedprivs,
1.92 schafran 2364: $available,$functions);
1.3 raeburn 2365: } else {
1.5 raeburn 2366: if ($action eq 'create') {
2367: $r->print($lt{'asyo'});
1.55 raeburn 2368: $r->print('<input type="hidden" name="specificity" value="No" />');
1.5 raeburn 2369: } elsif ($action eq 'modify' && $formname eq 'pick_members') {
2370: my @defprivs;
2371: if (ref($$stored{'defpriv'}) eq 'ARRAY') {
2372: @defprivs = @{$$stored{'defpriv'}};
2373: }
2374: $r->print($lt{'eaty'}.' '.$lt{cutg});
2375: if ($$stored{'specificity'} eq 'Yes') {
2376: $r->print($lt{'sdif'});
2377: } else {
2378: $r->print($lt{'sall'});
2379: }
2380: $r->print(' '.$lt{'defp'}.'<br /><br />');
1.45 albertel 2381: &display_defprivs($r,$tools,$toolprivs,\@defprivs);
1.5 raeburn 2382: }
1.3 raeburn 2383: }
2384: return;
2385: }
2386:
1.5 raeburn 2387: sub default_privileges {
1.92 schafran 2388: my ($r,$action,$tools,$toolprivs,$fixedprivs,$available,$functions) = @_;
1.5 raeburn 2389: my %lt = &Apache::lonlocal::texthash(
2390: 'addp' => 'Additional privileges',
2391: 'fixp' => 'Fixed privileges',
2392: 'oppr' => 'Optional privileges',
1.53 raeburn 2393: 'func' => 'Collaborative Tool',
1.5 raeburn 2394: );
1.42 albertel 2395: $r->print(&Apache::lonhtmlcommon::start_pick_box('LC_group_priv_box').
2396: &Apache::lonhtmlcommon::row_title($lt{'func'},undef,
1.90 schafran 2397: 'LC_groups_functionality'));
1.92 schafran 2398: my @tableHeader;
1.107 raeburn 2399: if ((ref($functions) eq 'HASH') && (ref($tools) eq 'ARRAY')) {
2400: @tableHeader = map { $functions->{$_}; } @{$tools};
2401: }
1.92 schafran 2402: $r->print(join('</td><td class="LC_groups_functionality">', @tableHeader));
1.42 albertel 2403: $r->print(&Apache::lonhtmlcommon::row_closure(1));
2404: my $fixed = '';
2405: my $dynamic = '';
1.3 raeburn 2406: foreach my $tool (@{$tools}) {
1.5 raeburn 2407: my $privcount = 0;
1.42 albertel 2408: if ($dynamic ne '') {
2409: $dynamic .= '</td><td class="LC_groups_optional">';
2410: }
2411: $dynamic .= '<table class="LC_group_priv"><tr>';
1.5 raeburn 2412: foreach my $priv (sort(keys(%{$$toolprivs{$tool}}))) {
2413: if (exists($$fixedprivs{$tool}{$priv})) {
1.42 albertel 2414: if ($fixed ne '') {
2415: $fixed .= '</td><td class="LC_groups_fixed">';
2416: }
1.79 bisitz 2417: $fixed .= '<input type="hidden" name="defpriv" value="'.$priv.'" />'
1.90 schafran 2418: .'<span class="LC_nobreak">'.&mt($$toolprivs{$tool}{$priv}).' ';
1.5 raeburn 2419: if ($action eq 'modify') {
1.42 albertel 2420: if (grep(/^$tool$/,@{$available})) {
1.5 raeburn 2421: $fixed .= '<small>'.&mt('(on)').'<small> ';
2422: } else {
2423: $fixed .= '<small>'.&mt('(off)').'<small> ';
1.3 raeburn 2424: }
2425: }
1.79 bisitz 2426: $fixed .= '</span>';
1.5 raeburn 2427: } else {
1.42 albertel 2428: $privcount++;
1.5 raeburn 2429: if ($privcount == 3) {
2430: $dynamic .= '</tr>
1.42 albertel 2431: <tr>'."\n";
1.5 raeburn 2432: }
1.90 schafran 2433: $dynamic .= '<td><span class="LC_nobreak"><label><input type="checkbox" name="defpriv" value="'.$priv.'" />'.&mt($$toolprivs{$tool}{$priv}).'</label></span></td>'."\n";
1.3 raeburn 2434: }
2435: }
1.42 albertel 2436: if ($privcount == 0) {
1.79 bisitz 2437: $dynamic .= '<td>'.&mt('None').'</td>'."\n";
1.5 raeburn 2438: }
2439: if ($privcount < 3) {
1.53 raeburn 2440: $dynamic .= '<td> </td>'."\n";
1.5 raeburn 2441: } elsif ($privcount%2) {
2442: $dynamic = '<td> </td>'."\n";
2443: }
1.42 albertel 2444: $dynamic .= '</tr></table>';
1.3 raeburn 2445: }
1.42 albertel 2446: $r->print(&Apache::lonhtmlcommon::row_title($lt{'fixp'},undef,
2447: 'LC_groups_fixed').
2448: $fixed.
2449: &Apache::lonhtmlcommon::row_closure(1));
2450: $r->print(&Apache::lonhtmlcommon::row_title($lt{'oppr'},undef,
2451: 'LC_groups_optional').
2452: $dynamic.
2453: &Apache::lonhtmlcommon::end_pick_box());
1.5 raeburn 2454: $r->print('<br />');
2455: return;
1.42 albertel 2456:
1.5 raeburn 2457: }
2458:
2459: sub display_defprivs {
1.45 albertel 2460: my ($r,$tools,$toolprivs,$defprivs) = @_;
2461: my $function = &Apache::loncommon::get_users_function();
2462: my $tabcol = &Apache::loncommon::designparm($function.'.tabbg');
2463: my $rowColor1 = "#dddddd";
2464: my $rowColor2 = "#eeeeee";
1.5 raeburn 2465: my %lt = &Apache::lonlocal::texthash(
2466: 'priv' => 'Privileges',
1.53 raeburn 2467: 'func' => 'Collaborative Tool',
1.5 raeburn 2468: );
2469: $r->print(&Apache::lonhtmlcommon::start_pick_box());
2470: $r->print('<tr>');
2471: my $numrows = 0;
2472: my %currprivs;
2473: foreach my $tool (@{$tools}) {
2474: @{$currprivs{$tool}} = ();
2475: foreach my $priv (sort(keys(%{$$toolprivs{$tool}}))) {
2476: if (ref($defprivs) eq 'ARRAY') {
1.45 albertel 2477: if (grep(/^\Q$priv\E$/,@{$defprivs})) {
1.5 raeburn 2478: push(@{$currprivs{$tool}},$priv);
2479: }
1.3 raeburn 2480: }
2481: }
1.5 raeburn 2482: my $rowcount = int(@{$currprivs{$tool}}/3);
2483: if (@{$currprivs{$tool}}%3 > 0) {
2484: $rowcount ++;
2485: }
2486: if ($rowcount > $numrows) {
2487: $numrows = $rowcount;
2488: }
2489: }
2490: my @rowCols = ($rowColor1,$rowColor2);
2491: foreach my $tool (@{$tools}) {
2492: $r->print('<td align="center" valign="top">
2493: <table cellspacing="0" cellpadding="5">
2494: <tr bgcolor="#cccccc">
2495: <td colspan="3" align="center"><b>'.$tool.'</b></td>
2496: </tr>
2497: ');
2498: my $rownum = 1;
2499: my $privcount = 0;
2500: $r->print('<tr bgcolor="'.$rowColor1.'">');
2501: foreach my $priv (@{$currprivs{$tool}}) {
2502: $privcount ++;
2503: if ($privcount%4 == 0) {
2504: $rownum ++;
2505: my $bgcol = $rownum%2;
2506: $r->print('</tr>
2507: <tr bgcolor="'.$rowCols[$bgcol].'">'."\n");
2508: }
2509: $r->print('<td>'.$$toolprivs{$tool}{$priv}.'</td>'."\n");
2510: }
2511: if ($privcount%3 > 0) {
2512: my $emptycells = 3-($privcount%3);
2513: while($emptycells > 0) {
2514: $r->print('<td> </td>'."\n");
2515: $emptycells --;
2516: }
2517: }
2518: while ($rownum < $numrows) {
2519: $rownum ++;
2520: my $bgcol = $rownum%2;
2521: $r->print('<tr bgcolor="'.$rowCols[$bgcol].'"><td colspan="3"> </td></tr>');
1.3 raeburn 2522: }
1.5 raeburn 2523: $r->print('</table>'."\n".'</td>');
2524: }
2525: $r->print('</tr>'."\n");
2526: $r->print(&Apache::lonhtmlcommon::end_pick_box());
2527: $r->print('<br />');
2528: return;
1.3 raeburn 2529: }
1.5 raeburn 2530:
2531:
2532: sub change_members_form {
1.48 albertel 2533: my ($r,$cdom,$cnum,$action,$formname,$page,$groupname,$description,
1.5 raeburn 2534: $startdate,$enddate,$tools,$fixedprivs,$functions,$users,$userdata,
1.48 albertel 2535: $granularity,$quota,$specificity,$idx,$states,$navbuttons,$gpterm,
2536: $ucgpterm) = @_;
1.5 raeburn 2537: my %lt = &Apache::lonlocal::texthash(
1.29 raeburn 2538: grse => "$ucgpterm settings",
2539: mogm => "Modify $gpterm membership",
1.5 raeburn 2540: );
2541: my @regexps = ('user_','userpriv_');
2542: $r->print(&Apache::lonhtmlcommon::echo_form_input(
1.6 raeburn 2543: ['origin','action','state','page','expire','deletion',
1.7 raeburn 2544: 'reenable','activate','changepriv','sortby',
2545: 'togglefunc'],\@regexps));
1.5 raeburn 2546: my $rowimg = 1;
2547: my @available = ();
2548: my @unavailable = ();
2549: &check_tools($functions,$tools,\@available,\@unavailable);
2550: my $nexttext = $$navbuttons{'gtns'};
2551: my $prevtext = $$navbuttons{'gtpp'};
2552: $r->print('
1.3 raeburn 2553: <br />
1.5 raeburn 2554: ');
1.78 raeburn 2555: $r->print(&Apache::lonhtmlcommon::topic_bar(1,$lt{'grse'}));
1.40 albertel 2556: &print_current_settings($r,$action,$functions,$startdate,$enddate,
2557: $groupname,$description,$granularity,$quota,
2558: \@available,\@unavailable,$gpterm,$ucgpterm);
1.78 raeburn 2559: $r->print(&Apache::lonhtmlcommon::topic_bar(2,$lt{'mogm'}));
1.53 raeburn 2560: my $numcurrent = ¤t_membership($r,$cdom,$cnum,$formname,$groupname,
2561: \@available,\@unavailable,$fixedprivs,
2562: $granularity,$specificity);
2563: if ($numcurrent > 0) {
2564: &display_navbuttons($r,$formname,$$states{$action}[$page-1],$prevtext,
2565: $$states{$action}[$page+1],$nexttext);
2566: } else {
2567: &display_navbuttons($r,$formname,$$states{$action}[$page-1],$prevtext);
2568: }
1.5 raeburn 2569: return;
2570: }
2571:
2572: sub current_membership {
1.48 albertel 2573: my ($r,$cdom,$cnum,$formname,$groupname,$available,$unavailable,
2574: $fixedprivs,$granularity,$specificity) = @_;
1.5 raeburn 2575: my %membership = &Apache::lonnet::get_group_membership($cdom,$cnum,
2576: $groupname);
2577: my %lt = &Apache::lonlocal::texthash(
1.6 raeburn 2578: 'actn' => 'Action?',
2579: 'name' => 'Name',
2580: 'usnm' => 'Username',
1.123 bisitz 2581: 'stid' => 'ID',
1.6 raeburn 2582: 'doma' => 'Domain',
2583: 'stda' => 'Start Date',
2584: 'enda' => 'End Date',
1.5 raeburn 2585: 'expi' => 'Expire',
2586: 'reen' => 'Re-enable',
2587: 'acti' => 'Activate',
2588: 'dele' => 'Delete',
1.53 raeburn 2589: 'curf' => 'Current Tool Set',
1.5 raeburn 2590: 'chpr' => 'Change Privileges'
2591: );
1.52 raeburn 2592: my ($current,$num_items,$hastools,$addtools) =
1.36 raeburn 2593: &Apache::longroup::group_memberlist($cdom,$cnum,$groupname,$fixedprivs,
2594: $available);
1.53 raeburn 2595: my $numcurrent = scalar(keys(%{$current}));
2596: if ($numcurrent > 0) {
1.36 raeburn 2597: $r->print('
1.5 raeburn 2598: <table>
2599: <tr>');
1.52 raeburn 2600: if ($num_items->{'active'}) {
1.36 raeburn 2601: &check_uncheck_buttons($r,$formname,'expire',$lt{'expi'});
2602: }
1.52 raeburn 2603: if ($num_items->{'previous'}) {
1.36 raeburn 2604: &check_uncheck_buttons($r,$formname,'reenable',$lt{'reen'});
2605: }
1.52 raeburn 2606: if ($num_items->{'future'}) {
1.36 raeburn 2607: &check_uncheck_buttons($r,$formname,'activate',$lt{'acti'});
2608: }
2609: &check_uncheck_buttons($r,$formname,'deletion',$lt{'dele'});
2610: if (@{$available} > 0) {
2611: if ($specificity eq 'Yes') {
2612: &check_uncheck_buttons($r,$formname,'changepriv',$lt{'chpr'});
1.5 raeburn 2613: }
1.36 raeburn 2614: if ($granularity eq 'Yes') {
2615: $r->print(&check_uncheck_tools($r,$available));
2616: $r->print('
1.5 raeburn 2617: <td>
1.83 bisitz 2618: <span class="LC_nobreak">
1.102 bisitz 2619: <fieldset><legend>'.$lt{'curf'}.'</legend>
1.80 bisitz 2620: <input type="button" value="'.&mt('check all').'"
1.5 raeburn 2621: onclick="javascript:checkAllTools(document.'.$formname.')" />
2622:
1.80 bisitz 2623: <input type="button" value="'.&mt('uncheck all').'"
1.5 raeburn 2624: onclick="javascript:uncheckAllTools(document.'.$formname.')" />
2625: </fieldset>
1.83 bisitz 2626: </span>
1.5 raeburn 2627: </td>
2628: ');
1.3 raeburn 2629: }
1.36 raeburn 2630: }
2631: $r->print(<<"END");
1.5 raeburn 2632: </tr>
2633: </table>
1.48 albertel 2634: <br />
1.5 raeburn 2635: END
1.48 albertel 2636: $r->print(&Apache::loncommon::start_data_table().
2637: &Apache::loncommon::start_data_table_header_row());
1.36 raeburn 2638: $r->print(<<"END");
1.48 albertel 2639: <th>$lt{'actn'}</th>
2640: <th><a href="javascript:changeSort('fullname')">$lt{'name'}</a></th>
2641: <th><a href="javascript:changeSort('username')">$lt{'usnm'}</a></th>
2642: <th><a href="javascript:changeSort('domain')">$lt{'doma'}</a></th>
1.123 bisitz 2643: <th><a href="javascript:changeSort('id')">$lt{'ID'}</a></th>
1.48 albertel 2644: <th><a href="javascript:changeSort('start')">$lt{'stda'}</a></th>
2645: <th><a href="javascript:changeSort('end')">$lt{'enda'}</a></th>
1.5 raeburn 2646: END
1.36 raeburn 2647: my $colspan = 0;
2648: if ($hastools) {
1.48 albertel 2649: $r->print('<th>'.$lt{'curf'}.'</th>');
2650: $colspan++;
1.36 raeburn 2651: }
2652: if ($addtools) {
1.53 raeburn 2653: $r->print('<th>'.&mt('Additional Tools').'</th>');
1.48 albertel 2654: $colspan++;
1.36 raeburn 2655: }
1.48 albertel 2656: $r->print(&Apache::loncommon::end_data_table_header_row());
1.36 raeburn 2657: if ($colspan) {
2658: if ($granularity eq 'Yes') {
1.48 albertel 2659: $r->print(&Apache::loncommon::start_data_table_row('LC_data_table_dense LC_data_table_highlight').'
1.6 raeburn 2660: <td colspan="7"> </td>
1.83 bisitz 2661: <td colspan="'.$colspan.'" align="center"><span class="LC_nobreak"><b>'.&mt('All:').
1.6 raeburn 2662: '</b> ');
1.36 raeburn 2663: foreach my $tool (@{$available}) {
2664: $r->print('<label><input type="checkbox" name="togglefunc"'.
1.7 raeburn 2665: ' onclick="javascript:toggleTools(document.'.$formname.'.user_'.$tool.',this);"'.
1.48 albertel 2666: ' value="'.$tool.'" />'.'<b>'.$tool.'</b></label> ');
1.6 raeburn 2667: }
1.83 bisitz 2668: $r->print('</span></td></tr>');
1.6 raeburn 2669: }
1.36 raeburn 2670: }
2671: my %Sortby = ();
2672: foreach my $user (sort(keys(%{$current}))) {
2673: if ($env{'form.sortby'} eq 'fullname') {
2674: push(@{$Sortby{$$current{$user}{fullname}}},$user);
2675: } elsif ($env{'form.sortby'} eq 'username') {
2676: push(@{$Sortby{$$current{$user}{uname}}},$user);
2677: } elsif ($env{'form.sortby'} eq 'domain') {
2678: push(@{$Sortby{$$current{$user}{udom}}},$user);
2679: } elsif ($env{'form.sortby'} eq 'id') {
2680: push(@{$Sortby{$$current{$user}{id}}},$user);
2681: } else {
2682: push(@{$Sortby{$$current{$user}{fullname}}},$user);
2683: }
2684: }
2685: foreach my $key (sort(keys(%Sortby))) {
2686: foreach my $user (@{$Sortby{$key}}) {
2687: my $id = $$current{$user}{id};
2688: my $fullname = $$current{$user}{fullname};
2689: my $udom = $$current{$user}{udom};
2690: my $uname = $$current{$user}{uname};
2691: my $start = $$current{$user}{start};
2692: my $end = $$current{$user}{end};
1.48 albertel 2693: $r->print(&Apache::loncommon::start_data_table_row('LC_data_table_dense').'
2694: <td>');
1.36 raeburn 2695: if ($$current{$user}{changestate} eq 'reenable') {
1.83 bisitz 2696: $r->print('<span class="LC_nobreak"><label>'.
1.5 raeburn 2697: '<input type="checkbox" name="reenable" value="'.$user.'" />'.
1.83 bisitz 2698: $lt{'reen'}.'</label></span><br />');
1.36 raeburn 2699: } elsif ($$current{$user}{changestate} eq 'expire') {
1.83 bisitz 2700: $r->print('<span class="LC_nobreak"><label>'.
1.5 raeburn 2701: '<input type="checkbox" name="expire" value="'.$user.'" />'.
1.83 bisitz 2702: $lt{'expi'}.'</label></span><br />');
1.36 raeburn 2703: } elsif ($$current{$user}{changestate} eq 'activate') {
1.83 bisitz 2704: $r->print('<span class="LC_nobreak"><label>'.
1.5 raeburn 2705: '<input type="checkbox" name="activate" value="'.$user.'" />'.
1.83 bisitz 2706: $lt{'acti'}.'</label></span><br />');
1.36 raeburn 2707: }
1.83 bisitz 2708: $r->print('<span class="LC_nobreak"><label>'.
1.6 raeburn 2709: '<input type="checkbox" name="deletion" value="'.$user.'" />'.
1.83 bisitz 2710: $lt{'dele'}.'</label></span>');
1.36 raeburn 2711: if ($specificity eq 'Yes') {
1.83 bisitz 2712: $r->print('<br /><span class="LC_nobreak"><label>'.
1.5 raeburn 2713: '<input type="checkbox" name="changepriv" value="'.$user.'" />'.$lt{'chpr'}.
1.83 bisitz 2714: '</label></span>');
1.36 raeburn 2715: }
2716: $r->print('
1.48 albertel 2717: </td>'.
2718: '<td>'.$fullname.'</td>'.
2719: '<td>'.$uname.'</td>'.
2720: '<td>'. $udom.'</td>'.
2721: '<td>'.$id.'</td>'.
2722: '<td>'.$start.'</td>'.
2723: '<td>'.$end.'</td>');
1.36 raeburn 2724: if ($hastools) {
1.83 bisitz 2725: $r->print('<td align="left"><span class="LC_nobreak">'.
1.6 raeburn 2726: ' ');
1.36 raeburn 2727: foreach my $tool (@{$$current{$user}{currtools}}) {
2728: if ($granularity eq 'Yes') {
2729: $r->print('<label><input type="checkbox" '.
1.7 raeburn 2730: 'checked="checked" '.
2731: 'name="user_'.$tool.'" value="'.
2732: $user.'" />'.$tool.'</label>');
1.36 raeburn 2733: } else {
2734: $r->print('<input type="hidden" '.
1.7 raeburn 2735: 'checked="checked" '.
2736: 'name="user_'.$tool.'" value="'.
2737: $user.'" />'.$tool);
1.36 raeburn 2738: }
2739: $r->print(' ');
1.5 raeburn 2740: }
1.83 bisitz 2741: $r->print('</span></td>');
1.36 raeburn 2742: }
2743: if ($addtools) {
1.48 albertel 2744: $r->print('<td align="left">');
1.36 raeburn 2745: if ($granularity eq 'Yes') {
2746: foreach my $tool (@{$$current{$user}{newtools}}) {
1.83 bisitz 2747: $r->print('<span class="LC_nobreak"><label><input type="checkbox"
1.5 raeburn 2748: name="user_'.$tool.'" value="'.
2749: $user.'" />'.$tool.
1.83 bisitz 2750: '</label></span> ');
1.36 raeburn 2751: }
2752: } else {
2753: foreach my $tool (@{$$current{$user}{newtools}}) {
1.83 bisitz 2754: $r->print('<span class="LC_nobreak"><input type="hidden"
1.5 raeburn 2755: name="user_'. $tool.'" value="'.
2756: $user.'" />'.$tool.
1.83 bisitz 2757: '</span> ');
1.5 raeburn 2758: }
2759: }
1.48 albertel 2760: $r->print('</td>');
1.5 raeburn 2761: }
1.48 albertel 2762: $r->print(&Apache::loncommon::end_data_table_row()."\n");
1.5 raeburn 2763: }
1.36 raeburn 2764: }
1.48 albertel 2765: $r->print(&Apache::loncommon::end_data_table());
1.53 raeburn 2766: } else {
1.123 bisitz 2767: $r->print(
2768: '<p class="LC_info">'
2769: .&mt('There are no active, future or previous group members to modify.')
2770: .'</p>');
1.5 raeburn 2771: }
1.53 raeburn 2772: return $numcurrent;
1.5 raeburn 2773: }
2774:
2775: sub check_uncheck_buttons {
2776: my ($r,$formname,$field,$title,$colspan) = @_;
2777: $r->print('
2778: <td '.$colspan.'>
2779: <fieldset>
1.102 bisitz 2780: <legend>'.$title.'</legend>
1.83 bisitz 2781: <span class="LC_nobreak">
1.80 bisitz 2782: <input type="button" value="'.&mt('check all').'"
1.5 raeburn 2783: onclick="javascript:checkAll(document.'.$formname.'.'.$field.')" />
2784:
1.80 bisitz 2785: <input type="button" value="'.&mt('uncheck all').'"
1.5 raeburn 2786: onclick="javascript:uncheckAll(document.'.$formname.'.'.$field.')" />
1.83 bisitz 2787: </span>
1.5 raeburn 2788: </fieldset>
2789: </td>
2790: ');
2791: }
2792:
2793:
2794: sub change_privs_form {
1.45 albertel 2795: my ($r,$cdom,$cnum,$action,$formname,$page,$startdate,$enddate,
2796: $tools,$functions,$toolprivs,$fixedprivs,$userdata,$usertools,
2797: $memchg,$idx,$states,$stored,$sectioncount,$navbuttons,$gpterm,
2798: $ucgpterm) = @_;
1.5 raeburn 2799: my @regexps = ('userpriv_');
2800: my $nexttext;
1.6 raeburn 2801: my %lt = &Apache::lonlocal::texthash(
2802: 'tode' => 'To be deleted',
2803: 'toex' => 'To be expired',
1.29 raeburn 2804: 'nome' => "No members to be deleted or expired from the $gpterm.",
1.6 raeburn 2805: );
1.5 raeburn 2806: $r->print(&Apache::lonhtmlcommon::echo_form_input(
1.6 raeburn 2807: ['origin','action','state','page','sortby'],\@regexps));
2808: if ($env{'form.branch'} eq 'adds') {
2809: $nexttext = $$navbuttons{'adme'};
2810: } else {
2811: $nexttext = $$navbuttons{'mose'};
2812: }
1.78 raeburn 2813: $r->print(&Apache::lonhtmlcommon::topic_bar(3,&mt('Members to delete or expire')));
1.6 raeburn 2814: my $exp_or_del = 0;
2815: if (ref($$memchg{'deletion'}) eq 'ARRAY') {
2816: if (@{$$memchg{'deletion'}} > 0) {
1.50 albertel 2817: $r->print('<b>'.$lt{'tode'}.':</b><br /><ul>');
1.6 raeburn 2818: foreach my $user (@{$$memchg{'deletion'}}) {
2819: $r->print('<li>'.$$userdata{$user}[$$idx{fullname}].
2820: ' ('.$user.')</li>');
2821: }
1.45 albertel 2822: $r->print('</ul>');
1.6 raeburn 2823: $exp_or_del += @{$$memchg{'deletion'}};
2824: }
2825: }
2826: if (ref($$memchg{'expire'}) eq 'ARRAY') {
2827: if (@{$$memchg{'expire'}} > 0) {
1.50 albertel 2828: $r->print('<b>'.$lt{'toex'}.':</b><br /><ul>');
1.6 raeburn 2829: foreach my $user (@{$$memchg{'expire'}}) {
2830: $r->print('<li>'.$$userdata{$user}[$$idx{fullname}].
2831: ' ('.$user.')</li>');
2832: }
1.45 albertel 2833: $r->print('</ul>');
1.6 raeburn 2834: $exp_or_del += @{$$memchg{'expire'}};
2835: }
2836: }
2837: if (!$exp_or_del) {
1.123 bisitz 2838: $r->print('<p class="LC_info">'.$lt{'nome'}.'</p>');
1.6 raeburn 2839: }
1.5 raeburn 2840:
1.78 raeburn 2841: $r->print(&Apache::lonhtmlcommon::topic_bar(4,&mt('Setting optional privileges for specific group members')));
1.6 raeburn 2842:
1.45 albertel 2843: my $numchgs = &member_privileges_form($r,$action,$formname,$tools,
1.6 raeburn 2844: $toolprivs,$fixedprivs,$userdata,
2845: $usertools,$idx,$memchg,$states,
1.45 albertel 2846: $stored,$gpterm);
1.5 raeburn 2847: my $prevtext = $$navbuttons{'gtps'};
1.6 raeburn 2848: if ($numchgs || $exp_or_del) {
2849: &display_navbuttons($r,$formname,$$states{$action}[$page-1],$prevtext,
2850: $$states{$action}[$page+1],$nexttext);
2851: } else {
2852: &display_navbuttons($r,$formname,$$states{$action}[$page-1],$prevtext);
2853: }
1.5 raeburn 2854: return;
2855: }
2856:
2857: sub add_members_form {
1.59 raeburn 2858: my ($r,$cdom,$cnum,$action,$formname,$page,$startdate,$enddate,$groupname,
1.29 raeburn 2859: $description,$granularity,$quota,$sectioncount,$tools,$functions,
1.104 raeburn 2860: $stored,$states,$navbuttons,$gpterm,$ucgpterm,$crstype)=@_;
1.40 albertel 2861: $r->print(' <br />');
1.5 raeburn 2862: my @available = ();
2863: my @unavailable = ();
2864: &check_tools($functions,$tools,\@available,\@unavailable);
1.40 albertel 2865: &print_current_settings($r,$action,$functions,$startdate,$enddate,
2866: $groupname,$description,$granularity,$quota,
2867: \@available,\@unavailable,$gpterm,$ucgpterm);
1.59 raeburn 2868: &membership_options($r,$cdom,$cnum,$action,$formname,$sectioncount,1,$gpterm,
1.104 raeburn 2869: $ucgpterm,$crstype);
1.5 raeburn 2870: my $nexttext = $$navbuttons{'gtns'};
2871: my $prevtext = $$navbuttons{'gtpp'};
2872: &display_navbuttons($r,$formname,$$states{$action}[$page-1],$prevtext,
2873: $$states{$action}[$page+1],$nexttext);
2874: return;
2875: }
2876:
2877: sub choose_privs_form {
1.45 albertel 2878: my ($r,$cdom,$cnum,$action,$formname,$page,$startdate,$enddate,
2879: $tools,$functions,$toolprivs,$fixedprivs,$userdata,$usertools,$idx,
2880: $states,$stored,$sectioncount,$navbuttons,$gpterm,$ucgpterm,
2881: $crstype) = @_;
1.5 raeburn 2882:
2883: my @regexps = ('userpriv_');
2884: my $nexttext;
2885:
2886: if ($action eq 'create') {
2887: push(@regexps,'sec_');
2888: $r->print(&Apache::lonhtmlcommon::echo_form_input(
1.6 raeburn 2889: ['origin','action','state','page','sortby','autoadd','autodrop'],
1.5 raeburn 2890: \@regexps));
2891: $nexttext = $$navbuttons{'crgr'};
2892: } else {
2893: $r->print(&Apache::lonhtmlcommon::echo_form_input(
1.6 raeburn 2894: ['origin','action','state','page','sortby'],\@regexps));
1.5 raeburn 2895: $nexttext = $$navbuttons{'adme'};
2896: }
2897:
1.78 raeburn 2898: $r->print(&Apache::lonhtmlcommon::topic_bar(6,&mt('Setting optional privileges for specific group members')));
1.5 raeburn 2899:
1.45 albertel 2900: &member_privileges_form($r,$action,$formname,$tools,$toolprivs,
1.5 raeburn 2901: $fixedprivs,$userdata,$usertools,$idx,undef,
1.45 albertel 2902: $states,$stored,$gpterm);
1.5 raeburn 2903:
2904: if ($action eq 'create') {
1.53 raeburn 2905: my $img1 = 7;
2906: my $img2 = 8;
2907: &mapping_options($r,$action,$formname,$page,$sectioncount,
2908: $states,$stored,$navbuttons,$img1,$img2,
1.58 raeburn 2909: $gpterm,$ucgpterm,$crstype,$cdom,$cnum);
1.5 raeburn 2910: }
2911: my $prevtext = $$navbuttons{'gtps'};
2912: &display_navbuttons($r,$formname,$$states{$action}[$page-1],$prevtext,
2913: $$states{$action}[$page+1],$nexttext);
2914: return;
2915: }
2916:
2917: sub build_boxes {
2918: my ($r,$tools,$usertools,$fixedprivs,$toolprivs,$showtools,
1.6 raeburn 2919: $showboxes,$prefix,$specificity,$excluded) = @_;
1.5 raeburn 2920: my $totalboxes = 0;
2921: if (@{$tools} > 0) {
2922: if ($specificity eq 'Yes') {
2923: foreach my $tool (@{$tools}) {
2924: @{$$showboxes{$tool}} = ();
2925: foreach my $user (sort(keys(%{$usertools}))) {
1.6 raeburn 2926: if (ref($excluded) eq 'ARRAY') {
2927: if (grep/^$user$/,@{$excluded}) {
2928: next;
2929: }
1.5 raeburn 2930: }
1.6 raeburn 2931: if ($$usertools{$user}{$tool}) {
2932: unless (grep/^$tool$/,@{$showtools}) {
2933: push(@{$showtools},$tool);
2934: }
2935: foreach my $priv (sort(keys(%{$$toolprivs{$tool}}))) {
2936: unless (exists($$fixedprivs{$tool}{$priv})) {
2937: unless(grep(/^$priv$/,@{$$showboxes{$tool}})) {
2938: push(@{$$showboxes{$tool}},$priv);
2939: $totalboxes ++;
2940: }
1.5 raeburn 2941: }
2942: }
2943: }
2944: }
2945: }
2946: if ($totalboxes > 0) {
2947: $r->print('
2948: <script type="text/javascript">
2949: function checkAllTools(formname) {
2950: ');
2951: foreach my $tool (sort(keys(%{$showboxes}))) {
2952: foreach my $priv (@{$$showboxes{$tool}}) {
2953: $r->print(' checkAll(formname.'.$prefix.$priv.');'."\n");
2954: }
2955: }
2956: $r->print('
2957: }
2958: function uncheckAllTools(formname) {
2959: ');
2960: foreach my $tool (sort(keys(%{$showboxes}))) {
2961: foreach my $priv (@{$$showboxes{$tool}}) {
2962: $r->print(' uncheckAll(formname'.$prefix.$priv.');'."\n");
2963: }
2964: }
2965: $r->print('
2966: }
2967: </script>
2968: ');
2969: }
2970: }
2971: }
2972: return $totalboxes;
2973: }
2974:
2975: sub member_privileges_form {
1.45 albertel 2976: my ($r,$action,$formname,$tools,$toolprivs,$fixedprivs,$userdata,
2977: $usertools,$idx,$memchg,$states,$stored,$gpterm) = @_;
1.5 raeburn 2978: my %lt = &Apache::lonlocal::texthash(
2979: 'addp' => 'Additional privileges',
1.53 raeburn 2980: 'fixp' => 'Core privileges',
1.5 raeburn 2981: 'oppr' => 'Optional privileges',
1.53 raeburn 2982: 'func' => 'Tool',
2983: 'forf' => 'For the collaborative tools included for group '.
2984: 'members being added or modified, '.
2985: 'there are no optional privileges to set '.
2986: 'for specific members.',
1.80 bisitz 2987: 'algr' => 'All new group members will receive the same privileges.',
2988: 'ifex' => 'If previously expired members are being re-enabled, or '.
1.54 raeburn 2989: 'if access for future members is being activated now, '.
2990: 'previously set privileges will be preserved.',
1.53 raeburn 2991: 'asno' => 'As no group members are being added, '.
2992: 'there are no specific user privileges to set.',
2993: 'asng' => 'As no group tools will be made available to users, '.
2994: 'there are no specific user privileges to set.',
2995: 'nogm' => 'No group member privileges to display or set, '.
2996: 'as you have not indicated that you will be activating,'.
2997: ' re-enabling, changing privileges, or adding/removing '.
2998: 'tools for any current members.',
1.5 raeburn 2999: 'full' => 'Fullname',
3000: 'user' => 'Username',
3001: 'doma' => 'Domain',
3002: );
3003: my @defprivs;
3004: my $specificity;
3005: if ($action eq 'create') {
3006: if (defined($env{'form.defpriv'})) {
3007: @defprivs = &Apache::loncommon::get_env_multiple('form.defpriv');
3008: }
3009: $specificity = $env{'form.specificity'};
3010: } else {
1.17 raeburn 3011: if (defined($$stored{'defpriv'})) {
3012: @defprivs = @{$$stored{'defpriv'}};
3013: }
1.5 raeburn 3014: $specificity = $$stored{'specificity'};
3015: }
3016: my @showtools;
3017: my %showboxes = ();
3018: my $numtools = 1 + @{$tools};
1.3 raeburn 3019:
1.6 raeburn 3020: my @excluded = ();
3021: my $numchgs = 0;
3022: if ($formname eq 'change_privs') {
3023: my @currmembers = ();
3024: if (ref($$memchg{'deletion'}) eq 'ARRAY') {
3025: push(@excluded,@{$$memchg{'deletion'}});
3026: }
3027: if (ref($$memchg{'expire'}) eq 'ARRAY') {
3028: push(@excluded,@{$$memchg{'expire'}});
3029: }
3030: if (@excluded > 0) {
3031: foreach my $user (sort(keys(%{$usertools}))) {
3032: if (grep/^$user$/,@excluded) {
3033: next;
3034: }
3035: push(@currmembers,$user);
3036: }
3037: } else {
3038: @currmembers = sort(keys(%{$usertools}));
3039: }
3040: $numchgs = @currmembers;
3041: if (!$numchgs) {
1.45 albertel 3042: $r->print($lt{'nogm'});
1.6 raeburn 3043: return $numchgs;
3044: }
3045: }
3046:
3047: my $totalboxes = &build_boxes($r,$tools,$usertools,$fixedprivs,
3048: $toolprivs,\@showtools,\%showboxes,
3049: 'userpriv_',$specificity,\@excluded);
1.5 raeburn 3050: if (@{$tools} > 0) {
3051: if ($specificity eq 'Yes') {
3052: if ($totalboxes > 0) {
3053: my $numcells = 2;
3054: my $colspan = $numcells + 1;
3055: my %total;
1.6 raeburn 3056: if (keys(%{$usertools}) > 1) {
3057: $r->print('
1.45 albertel 3058: <table border="0" cellspacing="2" cellpadding="2">
1.5 raeburn 3059: <tr>
3060: ');
1.6 raeburn 3061: foreach my $tool (@{$tools}) {
3062: if (@{$showboxes{$tool}} > 0) {
3063: $r->print('<td valign="top">');
1.100 bisitz 3064: $r->print('<fieldset><legend>'.&mt($tool).'</legend>');
3065: $r->print('<table><tr>');
1.6 raeburn 3066: my $privcount = 0;
3067: foreach my $priv (@{$showboxes{$tool}}) {
3068: $privcount ++;
3069: if (($privcount == @{$showboxes{$tool}}) &&
3070: ($privcount > 1)) {
3071: if ($privcount%$numcells) {
3072: $r->print('<td colspan="'.$colspan.'">');
3073: } else {
3074: $r->print('<td>');
3075: }
1.5 raeburn 3076: } else {
3077: $r->print('<td>');
3078: }
1.80 bisitz 3079: $r->print(
1.102 bisitz 3080: '<fieldset><legend>'.&mt($$toolprivs{$tool}{$priv}).'</legend>'
1.80 bisitz 3081: .'<span class="LC_nobreak">'
3082: .' <input type="button" value="'.&mt('check all').'"'
3083: .' onclick="javascript:checkAll(document.'.$formname.'.userpriv_'.$priv.')" />'
3084: .' '
3085: .'<input type="button" value="'.&mt('uncheck all').'"'
3086: .' onclick="javascript:uncheckAll(document.'.$formname.'.userpriv_'.$priv.')" />'
3087: .'</span></fieldset><br />'
3088: );
1.6 raeburn 3089: $r->print('</td>');
3090: if ($privcount < @{$showboxes{$tool}}) {
3091: if (@{$showboxes{$tool}} > 2) {
3092: if ($privcount%$numcells == 0) {
3093: $r->print('</tr><tr>');
3094: }
3095: } else {
3096: $r->print('<tr></tr>');
1.5 raeburn 3097: }
3098: }
3099: }
1.100 bisitz 3100: $r->print('</tr></table></fieldset></td><td> </td>');
1.5 raeburn 3101: }
3102: }
1.45 albertel 3103: $r->print('</tr></table>');
1.5 raeburn 3104: }
1.45 albertel 3105: $r->print(&Apache::loncommon::start_data_table().
3106: &Apache::loncommon::start_data_table_header_row());
1.5 raeburn 3107: $r->print(<<"END");
1.45 albertel 3108: <th>$lt{'full'}</th>
3109: <th>$lt{'user'}</th>
1.5 raeburn 3110: <th>$lt{'doma'}</th>
3111: <th colspan="$numtools">$lt{'addp'}</th>
3112: END
1.45 albertel 3113: $r->print(&Apache::loncommon::end_data_table_header_row());
3114: &member_privs_entries($r,$usertools,$toolprivs,$fixedprivs,
1.6 raeburn 3115: $userdata,$idx,\@showtools,\@defprivs,
3116: \@excluded);
1.45 albertel 3117: $r->print(&Apache::loncommon::end_data_table());
1.5 raeburn 3118: } else {
1.43 albertel 3119: $r->print($lt{'forf'}.'<br />');
1.45 albertel 3120: &display_defprivs($r,$tools,$toolprivs,\@defprivs);
1.5 raeburn 3121: }
3122: } else {
3123: if (keys(%{$usertools}) > 0) {
1.54 raeburn 3124: $r->print($lt{'algr'}.'<br />'.$lt{'ifex'}.'<br /><br />');
1.45 albertel 3125: &display_defprivs($r,$tools,$toolprivs,\@defprivs);
1.5 raeburn 3126: } else {
1.43 albertel 3127: $r->print($lt{'asno'}.'<br />');
1.5 raeburn 3128: }
3129: }
3130: } else {
1.43 albertel 3131: $r->print($lt{'asng'});
1.5 raeburn 3132: }
1.6 raeburn 3133: return $numchgs;
1.1 raeburn 3134: }
3135:
1.5 raeburn 3136: sub process_request {
1.45 albertel 3137: my ($r,$cdom,$cnum,$action,$state,$page,$groupname,$description,
1.5 raeburn 3138: $specificity,$userdata,$startdate,$enddate,$tools,$functions,$toolprivs,
3139: $usertools,$idx,$types,$roles,$sections,$states,$navbuttons,$memchg,
1.45 albertel 3140: $sectioncount,$stored,$gpterm,$ucgpterm,$crstype) = @_;
1.3 raeburn 3141:
3142: $r->print(&Apache::lonhtmlcommon::echo_form_input(
1.6 raeburn 3143: ['origin','action','state','page','sortby']));
1.5 raeburn 3144:
1.29 raeburn 3145: my $earlyout = &validate_groupname($groupname,$action,$cdom,$cnum,$gpterm,
3146: $ucgpterm,$crstype);
1.5 raeburn 3147: if ($earlyout) {
3148: $r->print('
3149: <table width="100%" cellpadding="0" cellspacing="0" border="0">
3150: <tr>
3151: <td> </td>
3152: <td colspan="3">
3153: '.$earlyout.'</td></tr>');
3154: &display_navbuttons($r,$state,$$states{$action}[$page-1],
3155: $$navbuttons{'gtps'});
3156: $r->print('</table>');
3157: return;
3158: }
3159:
3160: my @defprivs = ();
3161: if ($action eq 'create' || $state eq 'chgresult') {
3162: if (defined($env{'form.defpriv'})) {
3163: @defprivs = &Apache::loncommon::get_env_multiple('form.defpriv');
3164: }
3165: if ($state eq 'chgresult') {
3166: my @okprivs = ();
3167: foreach my $tool (@{$tools}) {
3168: foreach my $priv (sort(keys(%{$$toolprivs{$tool}}))) {
3169: push(@okprivs,$priv);
3170: }
3171: }
3172: my @temp = ();
3173: foreach my $defpriv (@defprivs) {
3174: if (grep/^$defpriv$/,@okprivs) {
3175: push(@temp,$defpriv);
3176: }
3177: }
3178: @defprivs = @temp;
3179: }
3180: } else {
1.17 raeburn 3181: if (defined($$stored{'defpriv'})) {
3182: @defprivs = @{$$stored{'defpriv'}};
3183: }
1.5 raeburn 3184: }
3185:
3186: my $outcome;
3187: if ($action eq 'create' || $state eq 'chgresult') {
3188: $outcome = &write_group_data($r,$cdom,$cnum,$action,$state,$groupname,
3189: $description,$startdate,$enddate,
3190: $specificity,$functions,$tools,
3191: $sectioncount,$roles,$types,$sections,
1.29 raeburn 3192: \@defprivs,$stored,$gpterm,$ucgpterm,
3193: $crstype);
1.5 raeburn 3194: }
3195: if (($action eq 'create' && $outcome eq 'ok') || (($action eq 'modify') &&
3196: (($state eq 'memresult') || ($state eq 'addresult')))) {
1.6 raeburn 3197: &process_membership($r,$cdom,$cnum,$action,$state,$groupname,$tools,
3198: $enddate,$startdate,$userdata,$idx,$toolprivs,
1.29 raeburn 3199: $usertools,$specificity,\@defprivs,$memchg,$gpterm,
1.104 raeburn 3200: $ucgpterm,$crstype);
1.5 raeburn 3201: }
3202: return;
3203: }
3204:
3205: sub write_group_data {
3206: my ($r,$cdom,$cnum,$action,$state,$groupname,$description,$startdate,
3207: $enddate,$specificity,$functions,$tools,$sectioncount,$roles,$types,
1.29 raeburn 3208: $sections,$defprivs,$stored,$gpterm,$ucgpterm,$crstype) = @_;
1.5 raeburn 3209: my $now = time;
3210: my $creation = $now;
3211: my $creator = $env{'user.name'}.':'.$env{'user.domain'};
3212: if ($state eq 'chgresult') {
3213: $creation = $$stored{'creation'};
3214: $creator = $$stored{'creator'};
3215: }
1.24 www 3216: my $esc_description = &escape($description);
1.5 raeburn 3217: my @single_attributes = ('description','functions','startdate','enddate',
3218: 'creation','modified','creator','granularity',
1.29 raeburn 3219: 'specificity','autoadd','autodrop','quota');
1.5 raeburn 3220: my @mult_attributes = ('roles','types','sectionpick','defpriv');
1.15 albertel 3221:
1.37 raeburn 3222: my ($crsquota,$freespace,$maxposs) = &get_quota_constraints($action,
3223: $stored);
3224: my $quota = $env{'form.quota'};
3225:
3226: $quota =~ s/^\s*([^\s]*)\s*$/$1/;
3227: if ($quota eq '') {
3228: $quota = 0;
3229: }
3230: if ($quota !~ /^\d*\.?\d*$/) {
3231: $quota = 0;
1.79 bisitz 3232: $r->print('<div class="LC_warning">'
1.96 weissno 3233: .&mt('The value you entered for the quota for the group portfolio in this '.$gpterm
1.122 raeburn 3234: .' contained invalid characters, so it has been set to 0 MB. You can change this by'
1.79 bisitz 3235: .' modifying the '.$gpterm.' settings.')
3236: .'</div>');
1.37 raeburn 3237: }
3238: if ($quota > $maxposs) {
3239: $quota = $maxposs;
1.79 bisitz 3240: $r->print('<div class="LC_warning">'
1.96 weissno 3241: .&mt('The value you entered for the quota for the group portfolio in this '.$gpterm
1.122 raeburn 3242: .' exceeded the maximum possible value, so it has been set to [_1] MB '
1.79 bisitz 3243: .'(the maximum possible value).',sprintf("%.2f",$maxposs))
3244: .'</div>');
1.37 raeburn 3245: }
1.5 raeburn 3246: my %groupinfo = (
3247: description => $esc_description,
3248: startdate => $startdate,
3249: enddate => $enddate,
3250: creation => $creation,
3251: modified => $now,
3252: creator => $creator,
3253: granularity => $env{'form.granularity'},
3254: specificity => $specificity,
3255: autoadd => $env{'form.autoadd'},
3256: autodrop => $env{'form.autodrop'},
1.37 raeburn 3257: quota => $quota,
1.5 raeburn 3258: );
1.37 raeburn 3259:
1.5 raeburn 3260: foreach my $func (keys(%{$functions})) {
3261: my $status;
3262: if (grep(/^$func$/,@{$tools})) {
3263: $status = 'on';
3264: } else {
3265: $status = 'off';
3266: }
3267: $groupinfo{'functions'} .= qq|<name id="$func">$status</name>|;
3268: }
3269:
3270: $groupinfo{'roles'} = $roles;
3271: $groupinfo{'types'} = $types;
3272: $groupinfo{'sectionpick'} = $sections;
3273: $groupinfo{'defpriv'} = $defprivs;
3274:
3275: my %groupsettings = ();
3276: foreach my $item (@single_attributes) {
3277: $groupsettings{$groupname} .= qq|<$item>$groupinfo{$item}</$item>|;
3278: }
3279: foreach my $item (@mult_attributes) {
3280: foreach my $entry (@{$groupinfo{$item}}) {
3281: $groupsettings{$groupname} .= qq|<$item>$entry</$item>|;
3282: }
3283: }
3284: my $autosec;
3285: my @autorole = &Apache::loncommon::get_env_multiple('form.autorole');
1.15 albertel 3286:
1.5 raeburn 3287: foreach my $role (@autorole) {
3288: if (defined($env{'form.sec_'.$role})) {
3289: my @autosections=&Apache::loncommon::get_env_multiple('form.sec_'.
3290: $role);
3291: $autosec .= '<role id="'.$role.'">';
3292: foreach my $sec (@autosections) {
3293: $autosec .= '<section>'.$sec.'</section>';
3294: }
3295: $autosec .= '</role>';
3296: }
3297: }
3298: if ($autosec) {
3299: $groupsettings{$groupname} .= qq|<autosec>$autosec</autosec>|;
3300: }
3301: my $result = &Apache::lonnet::modify_coursegroup($cdom,$cnum,
3302: \%groupsettings);
3303:
3304: if ($result eq 'ok') {
3305: if ($action eq 'create') {
1.32 raeburn 3306: my $result = &add_group_folder($cdom,$cnum,$now,$groupname,$action,
3307: $description,$tools,\%groupinfo,
3308: $gpterm,$ucgpterm,$crstype);
1.79 bisitz 3309: if ($result eq 'ok') {
1.109 wenzelju 3310: my $msg = &Apache::lonhtmlcommon::confirm_success(&mt($ucgpterm.' [_1] was created.','<i>'.$groupname.'</i>'));
3311: $msg = &Apache::loncommon::confirmwrapper($msg);
3312: $r->print($msg);
1.79 bisitz 3313: } else {
1.109 wenzelju 3314: my $msg = &Apache::lonhtmlcommon::confirm_success(&mt('A problem occurred when creating folders for the new '.$gpterm.' [_1]:'
3315: ,'<i>'.$groupname.'</i>')
3316: .'<br />'.$result,1);
3317: $msg = &Apache::loncommon::confirmwrapper($msg);
3318: $r->print($msg);
1.32 raeburn 3319: }
1.56 raeburn 3320: } elsif ($action eq 'modify') {
3321: my (@oldtools,@newtools);
3322: if (ref($$stored{'tool'}) eq 'ARRAY') {
3323: @oldtools = @{$$stored{'tool'}};
3324: }
3325: if (ref($tools) eq 'ARRAY') {
3326: @newtools = @{$tools};
3327: }
3328: if (!grep(/^discussion$/,@oldtools) &&
3329: grep(/^discussion$/,@newtools)) {
3330: my $crspath = '/uploaded/'.$cdom.'/'.$cnum.'/';
3331: my $boardsmap = $crspath.'group_boards_'.$groupname.'.sequence';
3332: my $navmap = Apache::lonnavmaps::navmap->new();
1.85 raeburn 3333: my ($bbmapres,$error);
3334: if (defined($navmap)) {
3335: $bbmapres = $navmap->getResourceByUrl($boardsmap);
3336: undef($navmap);
3337: if (!$bbmapres) {
3338: my $grpmap = $crspath.'group_folder_'.$groupname.'.sequence';
3339: my $disctitle = &mt('Discussion Boards');
3340: my $outcome = &map_updater($cdom,$cnum,'group_boards_'.
3341: $groupname.'.sequence','bbseq',
3342: $disctitle,$grpmap);
3343: my ($furl,$ferr) =
3344: &Apache::lonuserstate::readmap($cdom.'/'.$cnum);
3345: # modify parameter
3346: if ($outcome eq 'ok') {
3347: $navmap = Apache::lonnavmaps::navmap->new();
3348: if (defined($navmap)) {
3349: my $parm_result = &parm_setter($navmap,$cdom,$boardsmap,
3350: $groupname);
3351: if ($parm_result) {
3352: $error = &mt('An error occurred while setting parameters '
3353: .'for Discussion Boards folder: '
3354: .'[_1]',$parm_result);
3355: } else {
3356: $r->print('<div class="LC_success">'.
3357: &mt('Discussion Boards Folder created.')
3358: .'</div>');
3359: }
3360: undef($navmap);
3361: } else {
1.104 raeburn 3362: if ($crstype eq 'Community') {
3363: $error = &mt("An error occurred while setting parameters '.
1.85 raeburn 3364: 'for Discussion Boards folder: '.
1.104 raeburn 3365: 'Could not retrieve community information");
3366: } else {
3367: $error = &mt("An error occurred while setting parameters '.
3368: 'for Discussion Boards folder: '.
3369: 'Could not retrieve course information");
3370: }
1.85 raeburn 3371: }
1.56 raeburn 3372: } else {
1.85 raeburn 3373: $r->print($outcome);
1.56 raeburn 3374: }
3375: }
1.85 raeburn 3376: } else {
1.104 raeburn 3377: $error = &mt("An error occurred while retrieving the contents of the group's folder.").'<br />';
3378: if ($crstype eq 'Community') {
3379: $error .= &mt("You need to re-initialize the community.");
3380:
3381: } else {
3382: $error .= &mt("You need to re-initialize the course.");
3383: }
1.85 raeburn 3384: }
3385: if ($error ne '') {
3386: $r->print('<div class="LC_error">'.$error.'</div>');
1.56 raeburn 3387: }
3388: }
1.109 wenzelju 3389: my $message = &Apache::lonhtmlcommon::confirm_success(&mt($ucgpterm.' [_1] was updated.','<i>'.$groupname.'</i>'));
3390: $message = &Apache::loncommon::confirmwrapper($message);
3391: $r->print($message);
1.5 raeburn 3392: }
3393: } else {
3394: my %actiontype = (
3395: 'create' => 'creating',
3396: 'modify' => 'modifying',
3397: );
1.29 raeburn 3398: &Apache::lonnet::logthis("Failed to store $gpterm $groupname ".
3399: 'in '.lc($crstype).': '.$cnum.
3400: ' in domain: '.$cdom);
1.123 bisitz 3401: $r->print('<p class="LC_error">'
3402: .&mt('An error occurred when '.$actiontype{$action}.' the '.$gpterm.'. '
3403: .'Please try again.')
3404: .'</p');
1.5 raeburn 3405: }
3406: return $result;
3407: }
3408:
3409: sub process_membership {
1.6 raeburn 3410: my ($r,$cdom,$cnum,$action,$state,$groupname,$tools,$enddate,$startdate,
1.29 raeburn 3411: $userdata,$idx,$toolprivs,$usertools,$specificity,$defprivs,$memchg,
1.104 raeburn 3412: $gpterm,$ucgpterm,$crstype)=@_;
1.5 raeburn 3413: my %usersettings = ();
1.6 raeburn 3414: my %added= ();
3415: my %failed = ();
3416: my $num_ok = 0;
3417: my $num_fail = 0;
1.3 raeburn 3418: my %group_privs = ();
1.20 raeburn 3419: my %curr_privs = ();
1.21 raeburn 3420: my %curr_start = ();
3421: my %curr_end = ();
1.3 raeburn 3422: my %tooltype = ();
1.77 raeburn 3423: my $context = 'processgroupmembership';
1.5 raeburn 3424:
1.3 raeburn 3425: foreach my $tool (@{$tools}) {
3426: foreach my $priv (sort(keys(%{$$toolprivs{$tool}}))) {
3427: $tooltype{$priv} = $tool;
1.5 raeburn 3428: if ($specificity eq 'Yes') {
1.3 raeburn 3429: my @users =
3430: &Apache::loncommon::get_env_multiple('form.userpriv_'.$priv);
3431: foreach my $user (@users) {
3432: $group_privs{$user} .= $priv.':';
1.8 raeburn 3433: if ($state eq 'memresult') {
3434: unless (exists($$usertools{$user}{$tool})) {
3435: $$usertools{$user}{$tool} = 1;
3436: }
3437: }
1.3 raeburn 3438: }
3439: } else {
1.5 raeburn 3440: if (@{$defprivs} > 0) {
1.26 raeburn 3441: if (grep/^\Q$priv\E$/,@{$defprivs}) {
1.5 raeburn 3442: foreach my $user (sort(keys(%{$usertools}))) {
3443: if ($$usertools{$user}{$tool}) {
3444: $group_privs{$user} .= $priv.':';
3445: }
1.3 raeburn 3446: }
3447: }
3448: }
3449: }
3450: }
3451: }
3452: foreach my $user (keys(%group_privs)) {
3453: $group_privs{$user} =~ s/:$//;
3454: }
1.5 raeburn 3455:
1.6 raeburn 3456: my $now = time;
3457: my @activate = ();
3458: my @expire = ();
3459: my @deletion = ();
3460: my @reenable = ();
1.20 raeburn 3461: my @unchanged = ();
1.6 raeburn 3462: if ($state eq 'memresult') {
3463: if (ref($$memchg{'activate'}) eq 'ARRAY') {
3464: @activate = @{$$memchg{'activate'}};
3465: }
3466: if (ref($$memchg{'expire'}) eq 'ARRAY') {
3467: @expire = @{$$memchg{'expire'}};
3468: }
3469: if (ref($$memchg{'deletion'}) eq 'ARRAY') {
3470: @deletion = @{$$memchg{'deletion'}};
3471: }
3472: if (ref($$memchg{'reenable'}) eq 'ARRAY') {
3473: @reenable = @{$$memchg{'reenable'}};
3474: }
1.20 raeburn 3475: my %membership = &Apache::lonnet::get_group_membership($cdom,$cnum,
3476: $groupname);
3477: foreach my $key (sort(keys(%membership))) {
3478: if ($key =~ /^\Q$groupname\E:([^:]+:[^:]+)$/) {
1.21 raeburn 3479: ($curr_end{$1},$curr_start{$1},$curr_privs{$1}) =
3480: split(/:/,$membership{$key},3);
1.20 raeburn 3481: }
3482: }
1.6 raeburn 3483: if (@expire + @deletion > 0) {
3484: foreach my $user (@expire) {
1.21 raeburn 3485: my $savestart = $curr_start{$user};
3486: if ($savestart > $now) {
3487: $savestart = $now;
1.6 raeburn 3488: }
1.21 raeburn 3489: $usersettings{$groupname.':'.$user} = $now.':'.$savestart.':'.
3490: $curr_privs{$user};
1.6 raeburn 3491: if (&Apache::lonnet::modify_group_roles($cdom,$cnum,$groupname,
1.21 raeburn 3492: $user,$now,$savestart,
1.77 raeburn 3493: $curr_privs{$user},'',$context) eq 'ok') {
1.6 raeburn 3494: push(@{$added{'expired'}},$user);
3495: $num_ok ++;
3496: } else {
3497: push(@{$failed{'expired'}},$user);
3498: $num_fail ++;
3499: }
3500: }
3501: foreach my $user (@deletion) {
3502: $usersettings{$groupname.':'.$user} = $now.':-1:';
3503: if (&Apache::lonnet::modify_group_roles($cdom,$cnum,$groupname,
1.76 raeburn 3504: $user,$now,'-1','','',$context)
1.6 raeburn 3505: eq 'ok') {
3506: push(@{$added{'deleted'}},$user);
3507: $num_ok ++;
3508: } else {
3509: push(@{$failed{'deleted'}},$user);
3510: $num_fail ++;
3511: }
3512: }
3513: }
1.8 raeburn 3514: }
1.6 raeburn 3515:
1.5 raeburn 3516: foreach my $user (sort(keys(%{$usertools}))) {
1.20 raeburn 3517: if ((grep(/^$user$/,@expire)) || (grep(/^$user$/,@deletion))) {
3518: next;
3519: }
1.6 raeburn 3520: my $type;
3521: my $start = $startdate;
3522: my $end = $enddate;
3523: if ($state eq 'memresult') {
3524: if (@activate > 0) {
3525: if (grep/^$user$/,@activate) {
3526: $start = $now;
1.21 raeburn 3527: $end = $enddate;
1.6 raeburn 3528: $type = 'activated';
3529: }
3530: }
3531: if (@reenable > 0) {
3532: if (grep/^$user$/,@reenable) {
1.21 raeburn 3533: $start = $startdate;
3534: $end = $enddate;
1.125 bisitz 3535: $type = 're-enabled';
1.6 raeburn 3536: }
3537: }
1.38 raeburn 3538: if ($type eq '') {
3539: if ($curr_privs{$user} eq $group_privs{$user}) {
3540: push(@unchanged,$user);
3541: next;
3542: }
3543: if (exists($curr_start{$user})) {
3544: $start = $curr_start{$user};
3545: }
3546: if (exists($curr_end{$user})) {
3547: $end = $curr_end{$user};
3548: }
3549: $type = 'modified';
3550: }
1.6 raeburn 3551: } else {
3552: $type = 'added';
3553: }
3554: $usersettings{$groupname.':'.$user} = $end.':'.$start.':'.
1.5 raeburn 3555: $group_privs{$user};
3556: if (&Apache::lonnet::modify_group_roles($cdom,$cnum,$groupname,
1.6 raeburn 3557: $user,$end,$start,
1.76 raeburn 3558: $group_privs{$user},'',$context) eq 'ok') {
1.6 raeburn 3559: push(@{$added{$type}},$user);
3560: $num_ok ++;
1.3 raeburn 3561: } else {
1.6 raeburn 3562: push(@{$failed{$type}},$user);
3563: $num_fail ++;
1.5 raeburn 3564: }
3565: }
3566: my $roster_result = &Apache::lonnet::modify_coursegroup_membership($cdom,
3567: $cnum,\%usersettings);
1.6 raeburn 3568: if ($num_ok) {
1.109 wenzelju 3569: my $msgall ='';
3570: foreach my $type (sort(keys(%added))) {
1.123 bisitz 3571: my $message;
3572: my $tmsg = "The following users were successfully $type";
1.20 raeburn 3573: if (!($type eq 'deleted' || $type eq 'expired')) {
1.123 bisitz 3574: $tmsg .= ' with the following privileges';
1.6 raeburn 3575: }
1.123 bisitz 3576: $message .= &mt($tmsg.':').'<br/>';
1.6 raeburn 3577: foreach my $user (@{$added{$type}}) {
1.8 raeburn 3578: my $privlist = '';
3579: if (!($type eq 'deleted' || $type eq 'expired')) {
3580: $privlist = ': ';
1.6 raeburn 3581: my @privs = split(/:/,$group_privs{$user});
3582: my $curr_tool = '';
3583: foreach my $priv (@privs) {
3584: unless ($curr_tool eq $tooltype{$priv}) {
3585: $curr_tool = $tooltype{$priv};
3586: $privlist .= '<b>'.$curr_tool.'</b>: ';
3587: }
3588: $privlist .= $$toolprivs{$curr_tool}{$priv}.', ';
3589: }
3590: $privlist =~ s/, $//;
3591: }
1.109 wenzelju 3592: $message .= $$userdata{$user}[$$idx{fullname}].' - '.$user.$privlist.'<br />';
1.6 raeburn 3593: }
1.109 wenzelju 3594: $message .= '<br/>';
3595: $message = &Apache::lonhtmlcommon::confirm_success($message);
3596: $msgall .= $message;
1.6 raeburn 3597: }
1.109 wenzelju 3598: $msgall = &Apache::loncommon::confirmwrapper($msgall);
3599: $r->print($msgall);
1.6 raeburn 3600: }
3601: if ($num_fail) {
3602: foreach my $type (sort(keys(%failed))) {
1.79 bisitz 3603: $r->print('<div class="LC_error">'
3604: .&mt("The following users could not be $type, because an error occurred:")
3605: .'</div>');
1.6 raeburn 3606: foreach my $user (@{$failed{$type}}) {
3607: $r->print($$userdata{$user}[$$idx{fullname}].' - '.$user.'<br />');
3608: }
1.5 raeburn 3609: }
1.20 raeburn 3610: $r->print('<br />');
3611: }
1.109 wenzelju 3612: # Is that really needed?
3613: #
3614: # if (@unchanged > 0) {
3615: # $r->print(&mt('No change occurred for the following users:').'<br />');
3616: # foreach my $user (sort(@unchanged)) {
3617: # $r->print($$userdata{$user}[$$idx{fullname}].' - '.$user.'<br />');
3618: # }
3619: # $r->print('<br />');
3620: # }
1.5 raeburn 3621: if ($roster_result eq 'ok') {
1.80 bisitz 3622: $r->print('<div class="LC_success">'
3623: .&mt($ucgpterm.' membership list updated.')
3624: .'</div>');
1.104 raeburn 3625: $r->print('<p class="LC_info">');
3626: if ($crstype eq 'Community') {
3627: $r->print(&mt("Any currently logged in community users affected by the changes you made"
1.80 bisitz 3628: .' to group membership or privileges for the [_1] group will need to log out'
3629: .' and log back in for their LON-CAPA sessions to reflect these changes.'
1.104 raeburn 3630: ,'<i>'.$groupname.'</i>'));
3631:
3632: } else {
3633: $r->print(&mt("Any currently logged in course users affected by the changes you made"
3634: .' to group membership or privileges for the [_1] group will need to log out'
3635: .' and log back in for their LON-CAPA sessions to reflect these changes.'
3636: ,'<i>'.$groupname.'</i>'));
3637: }
3638: $r->print('</p>');
1.5 raeburn 3639: } else {
1.80 bisitz 3640: $r->print('<div class="LC_error">'
3641: .&mt("An error occurred while updating the $gpterm membership list:")
3642: .'<br />'.$roster_result
3643: .'</div>');
1.5 raeburn 3644: }
3645: return;
3646: }
3647:
3648: sub mapping_options {
1.44 albertel 3649: my ($r,$action,$formname,$page,$sectioncount,$states,$stored,
1.58 raeburn 3650: $navbuttons,$img1,$img2,$gpterm,$ucgpterm,$crstype,$cdom,$cnum) = @_;
1.5 raeburn 3651: my %lt = &Apache::lonlocal::texthash(
1.29 raeburn 3652: 'auto' => "Settings for automatic $gpterm enrollment",
3653: 'gmma' => "$ucgpterm membership mapping to specific sections/roles",
3654: 'endi' => "Enable/disable automatic $gpterm enrollment for ".
3655: "users in specified roles and sections",
1.53 raeburn 3656: 'adds' => "If automatic $gpterm enrollment is enabled, when a user is newly assigned a ".lc($crstype)."-wide or section-specific role, he/she will automatically be added as a member of the $gpterm, with start and end access dates defined by the default dates set for the $gpterm, unless he/she is already a $gpterm member, with access dates that permit either current or future $gpterm access.",
1.29 raeburn 3657: 'drops' => "If automatic $gpterm disenrollment is enabled, when a user's role is expired, access to the $gpterm will be terminated unless the user continues to have other ".lc($crstype)."-wide or section-specific active or future roles which receive automatic membership in the $gpterm.",
3658: 'pirs' => "Pick roles and sections for automatic $gpterm enrollment",
1.5 raeburn 3659: 'on' => 'on',
3660: 'off' => 'off',
1.29 raeburn 3661: 'auad' => "Automatically enable $gpterm membership when roles are added?",
3662: 'auex' => "Automatically expire $gpterm membership when roles are removed?",
3663: 'mapr' => "Mapping of roles and sections affected by automatic $gpterm enrollment/disenrollment follows scheme chosen below.",
1.5 raeburn 3664: );
1.44 albertel 3665: &automapping($r,$action,$stored,\%lt,$img1);
1.58 raeburn 3666: &mapping_settings($r,$sectioncount,\%lt,$stored,$img2,$crstype,$cdom,$cnum,
3667: $action);
1.5 raeburn 3668: return;
3669: }
3670:
3671: sub automapping {
1.44 albertel 3672: my ($r,$action,$stored,$lt,$image) = @_;
1.5 raeburn 3673: my $add = 'off';
3674: my $drop = 'off';
3675: if (exists($$stored{'autoadd'})) {
3676: $add = $$stored{'autoadd'};
3677: }
3678: if (exists($$stored{'autodrop'})) {
3679: $drop = $$stored{'autodrop'};
3680: }
1.78 raeburn 3681: $r->print(&Apache::lonhtmlcommon::topic_bar($image,$$lt{'endi'}).'
1.44 albertel 3682: <b>'.$$lt{'gmma'}.':</b><br />'.$$lt{'adds'}.'<br />'.$$lt{'drops'}.'<br /><br />
1.83 bisitz 3683: <span class="LC_nobreak">'.$$lt{'auad'}.':
1.80 bisitz 3684: <label><input type="radio" name="autoadd" value="on" />'.&mt('on').' </label><label><input type="radio" name="autoadd" value="off" checked="checked" />'.&mt('off').'</label>');
1.5 raeburn 3685: if ($action eq 'modify') {
1.82 bisitz 3686: $r->print(' ('.&mt('Currently set to [_1].','<b>'.$$lt{$add}.'</b>').')');
1.5 raeburn 3687: }
3688: $r->print('
1.83 bisitz 3689: </span><br />
3690: <span class="LC_nobreak">'.$$lt{'auex'}.':
1.80 bisitz 3691: <label><input type="radio" name="autodrop" value="on" />'.&mt('on').' </label><label><input type="radio" name="autodrop" value="off" checked="checked" />'.&mt('off').'</label>');
1.5 raeburn 3692: if ($action eq 'modify') {
1.82 bisitz 3693: $r->print(' ('.&mt('Currently set to [_1].','<b>'.$$lt{$drop}.'</b>').')');
1.3 raeburn 3694: }
1.83 bisitz 3695: $r->print('</span><br /><br />'.$$lt{'mapr'});
1.5 raeburn 3696: }
1.3 raeburn 3697:
1.5 raeburn 3698: sub mapping_settings {
1.58 raeburn 3699: my ($r,$sectioncount,$lt,$stored,$image,$crstype,$cdom,$cnum,$action) = @_;
1.5 raeburn 3700: my @sections = keys(%{$sectioncount});
3701: if (@sections > 0) {
3702: @sections = sort {$a cmp $b} @sections;
1.17 raeburn 3703: unshift(@sections,'none'); # Put 'no sections' next
3704: unshift(@sections,'all'); # Put 'all' at the front of the list
1.53 raeburn 3705: } else {
3706: @sections = ('all','none');
1.3 raeburn 3707: }
1.78 raeburn 3708: $r->print(&Apache::lonhtmlcommon::topic_bar($image,$$lt{'pirs'}));
1.104 raeburn 3709: my @roles = &standard_roles($crstype);
1.59 raeburn 3710: my %customroles = &Apache::lonhtmlcommon::course_custom_roles($cdom,$cnum);
1.44 albertel 3711: $r->print(&Apache::loncommon::start_data_table().
3712: &Apache::loncommon::start_data_table_header_row());
1.5 raeburn 3713: $r->print('
3714: <th>'.&mt('Active?').'</th>
3715: <th>'.&mt('Role').'</th>');
3716: if (@sections > 0) {
1.44 albertel 3717: $r->print('<th>'.&mt('Sections').'</th>');
1.3 raeburn 3718: }
1.44 albertel 3719: $r->print(&Apache::loncommon::end_data_table_header_row()."\n");
1.5 raeburn 3720: foreach my $role (@roles) {
1.58 raeburn 3721: my $roletitle=&Apache::lonnet::plaintext($role,$crstype);
3722: $r->print(&print_autorole_item($role,$roletitle,\@sections));
1.5 raeburn 3723: }
1.58 raeburn 3724: my @customs;
1.5 raeburn 3725: foreach my $role (sort(keys(%customroles))) {
1.58 raeburn 3726: my ($roletitle) = ($role =~ m|^cr/[^/]+/[^/]+/(.+)$|);
3727: push (@customs,$role);
3728: $r->print(&print_autorole_item($role,$roletitle,\@sections));
3729: }
3730: if ($action eq 'modify') {
3731: foreach my $role (@{$$stored{'autorole'}}) {
3732: if ((!grep(/^\Q$role\E$/,@customs)) &&
3733: (!grep(/^\Q$role\E$/,@roles))) {
3734: my $roletitle;
3735: if ($role =~ /^cr/) {
3736: ($roletitle) = ($role =~ m|_([^_]+)$|);
3737: } else {
3738: $roletitle = &Apache::lonnet::plaintext($role,$crstype);
3739: }
3740: $r->print(&print_autorole_item($role,$roletitle,\@sections));
3741: }
3742: }
1.5 raeburn 3743: }
1.44 albertel 3744: $r->print(&Apache::loncommon::end_data_table());
1.5 raeburn 3745: return;
3746: }
1.3 raeburn 3747:
1.58 raeburn 3748: sub print_autorole_item {
3749: my ($role,$roletitle,$sections) = @_;
3750: my $sections_sel;
3751: if (@{$sections} > 0) {
1.104 raeburn 3752: if (($role eq 'cc') || ($role eq 'co')) {
1.58 raeburn 3753: $sections_sel = '<td align="right">'.
3754: &mt('all sections').'<input type="hidden" '.
1.104 raeburn 3755: 'name="sec_'.$role.'" value="all" /></td>';
1.58 raeburn 3756: } else {
3757: $sections_sel='<td align="right">'.
3758: §ions_selection($sections,'sec_'.$role).
3759: '</td>';
3760: }
3761: }
3762: my $output = &Apache::loncommon::start_data_table_row().
3763: '<td><input type="checkbox" '.
3764: 'name="autorole" value="'.$role.'" />'.
3765: '</td><td>'.$roletitle.'</td>'.$sections_sel.
3766: &Apache::loncommon::end_data_table_row();
3767: return $output;
3768: }
3769:
1.5 raeburn 3770: sub standard_roles {
1.104 raeburn 3771: my ($crstype) = @_;
3772: my @roles = qw(in ta ep ad st);
3773: if ($crstype eq 'Community') {
3774: unshift(@roles,'co');
3775: } else {
3776: unshift(@roles,'cc');
3777: }
1.5 raeburn 3778: return @roles;
3779: }
3780:
3781: sub modify_menu {
1.29 raeburn 3782: my ($r,$groupname,$page,$gpterm) = @_;
1.5 raeburn 3783: my @menu =
1.106 wenzelju 3784: ( { categorytitle =>'Group Actions',
3785: items => [
3786:
3787: { linktext => "Modify default $gpterm settings",
3788: url => '/adm/coursegroups?action=modify&refpage='.$env{'form.refpage'}.'&groupname='.$groupname.'&state=change_settings&branch=settings',
3789: icon => 'grp_settings.png',
3790: alttext => "Modify default $gpterm settings",
3791: permission => '1',
3792: help => 'Course_Modify_Group',
1.5 raeburn 3793: },
1.106 wenzelju 3794: { linktext => 'Modify access, tools and privileges for members',
3795: url => '/adm/coursegroups?action=modify&refpage='.$env{'form.refpage'}.'&groupname='.$groupname.'&state=change_members&branch=members',
3796: icon => 'grp_tools.png',
3797: alttext => 'Modify access, tools and privileges for members',
3798: permission => '1',
1.5 raeburn 3799: help => 'Course_Modify_Group_Membership',
3800: },
1.106 wenzelju 3801: { linktext => "Add member(s) to the $gpterm",
3802: url => '/adm/coursegroups?action=modify&refpage='.$env{'form.refpage'}.'&groupname='.$groupname.'&state=add_members&branch=adds',
3803: icon => 'grp_add.png',
3804: alttext => "Add member(s) to the $gpterm",
3805: permission => '1',
1.5 raeburn 3806: help => 'Course_Group_Add_Members',
1.106 wenzelju 3807: }]}
3808: );
3809: $r->print(&Apache::lonhtmlcommon::generate_menu(@menu));
1.3 raeburn 3810: return;
3811: }
3812:
3813: sub member_privs_entries {
1.45 albertel 3814: my ($r,$usertools,$toolprivs,$fixedprivs,$userdata,$idx,$showtools,
3815: $defprivs,$excluded) = @_;
1.5 raeburn 3816: foreach my $user (sort(keys(%{$usertools}))) {
1.6 raeburn 3817: if (defined($excluded)) {
3818: if (ref($excluded) eq 'ARRAY') {
3819: if (grep/^$user$/,@{$excluded}) {
3820: next;
3821: }
3822: }
3823: }
1.5 raeburn 3824: my ($uname,$udom) = split(/:/,$user);
1.45 albertel 3825: $r->print(&Apache::loncommon::start_data_table_row().'
1.5 raeburn 3826: <td>'.$$userdata{$user}[$$idx{fullname}].'</td>
1.3 raeburn 3827: <td>'.$uname.'</td>
3828: <td>'.$udom.'</td>
1.53 raeburn 3829: <td valign="top">
3830: <table>
3831: <tr>
3832: <td><b>'.
3833: &mt('Collaborative Tool').'</b></td>
3834: </tr>
3835: <tr>
3836: <td><b>'.&mt('Fixed').'</b></td>
3837: </tr>
3838: <tr>
3839: <td><b>'.&mt('Optional').'</b></td>
3840: </tr>
3841: </table>
3842: </td>');
1.5 raeburn 3843: foreach my $tool (@{$showtools}) {
3844: if (exists($$usertools{$user}{$tool})) {
1.45 albertel 3845: $r->print('<td valign="top"><table><tr><th colspan="2">'.$tool.'</th></tr>');
1.3 raeburn 3846: my $privcount = 0;
3847: my $fixed = '';
3848: my $dynamic = '';
3849: foreach my $priv (sort(keys(%{$$toolprivs{$tool}}))) {
3850: if (exists($$fixedprivs{$tool}{$priv})) {
1.5 raeburn 3851: $fixed .= '<input type="hidden" name="userpriv_'.$priv.'" value="'.$user.'" />'.$$toolprivs{$tool}{$priv}.' ';
1.3 raeburn 3852: } else {
3853: $privcount ++;
3854: if ($privcount == 3) {
3855: $dynamic .= '</tr><tr>';
3856: }
1.83 bisitz 3857: $dynamic .='<td><span class="LC_nobreak"><label><input type="checkbox" '.
1.5 raeburn 3858: 'name="userpriv_'.$priv.'" value="'.$user.'"';
3859: if (grep/^\Q$priv\E$/,@{$defprivs}) {
3860: $dynamic .= ' checked="checked" ';
3861: }
3862: $dynamic .= ' />'.$$toolprivs{$tool}{$priv}.
1.83 bisitz 3863: '</label></span></td>';
1.3 raeburn 3864: }
3865: }
1.83 bisitz 3866: $r->print('<tr><td colspan="2"><span class="LC_nobreak">'.$fixed.'</span></td></tr><tr>'.$dynamic.'</tr></table></td>');
1.3 raeburn 3867: } else {
1.45 albertel 3868: $r->print('<td valign="top"><table width="100%"><tr><th colspan="2">'.$tool.'</th></tr><tr><td> </td></tr><tr><td> </td></tr></table></td>');
1.3 raeburn 3869: }
3870: }
1.45 albertel 3871: $r->print(&Apache::loncommon::end_data_table_row());
1.3 raeburn 3872: }
3873: }
3874:
3875: sub get_dates_from_form {
3876: my $startdate;
3877: my $enddate;
3878: $startdate = &Apache::lonhtmlcommon::get_date_from_form('startdate');
3879: $enddate = &Apache::lonhtmlcommon::get_date_from_form('enddate');
3880: if ( exists ($env{'form.no_end_date'}) ) {
3881: $enddate = 0;
3882: }
3883: return ($startdate,$enddate);
1.5 raeburn 3884: }
3885:
1.3 raeburn 3886: sub date_setting_table {
3887: my ($starttime,$endtime,$formname) = @_;
3888: my $startform = &Apache::lonhtmlcommon::date_setter($formname,
3889: 'startdate',$starttime);
3890: my $endform = &Apache::lonhtmlcommon::date_setter($formname,
3891: 'enddate',$endtime);
1.98 bisitz 3892: my $perpetual = ' <span class="LC_nobreak"><label>'
3893: .'<input type="checkbox" name="no_end_date" />'
3894: .&mt('No end date')
3895: .'</label></span>';
3896: my $table = &Apache::lonhtmlcommon::start_pick_box()
3897: .&Apache::lonhtmlcommon::row_title(&mt('Start Date'))
3898: .$startform
3899: .&Apache::lonhtmlcommon::row_closure()
3900: .&Apache::lonhtmlcommon::row_title(&mt('End Date'))
3901: .$endform
3902: .$perpetual
3903: .&Apache::lonhtmlcommon::row_closure(1)
3904: .&Apache::lonhtmlcommon::end_pick_box();
1.41 albertel 3905: return $table;
1.1 raeburn 3906: }
3907:
1.32 raeburn 3908: sub add_group_folder {
3909: my ($cdom,$cnum,$now,$groupname,$action,$description,$tools,$groupinfo,
3910: $gpterm,$ucgpterm,$crstype) = @_;
3911: if ($cdom eq '' || $cnum eq '') {
1.104 raeburn 3912: my $error = '<span class="LC_error">';
3913: if ($crstype eq 'Community') {
3914: $error .= &mt("Error: invalid community domain or number - group folder creation failed.");
3915: } else {
3916: $error .= &mt("Error: invalid course domain or number - group folder creation failed.");
3917: }
3918: $error .= '</span>';
3919: return $error;
1.32 raeburn 3920: }
1.67 raeburn 3921: my ($outcome,$allgrpsmap,$grpmap,$boardsmap,$grppage,$warning);
1.32 raeburn 3922: my $crspath = '/uploaded/'.$cdom.'/'.$cnum.'/';
1.47 raeburn 3923: $allgrpsmap = $crspath.'group_allfolders.sequence';
1.32 raeburn 3924: if ($action eq 'create') {
1.67 raeburn 3925: if (&get_folder_lock($cdom,$cnum,'group_allfolders',$now) eq 'ok') {
3926: # check if group_allfolders.sequence exists.
1.69 raeburn 3927: my $mapcontents = &Apache::lonnet::getfile($allgrpsmap);
3928: if ($mapcontents eq '-1') { #file does not exist;
1.80 bisitz 3929: my $grpstitle = &mt("$crstype $ucgpterm".'s');
1.67 raeburn 3930: my $topmap_url = '/'.$env{'course.'.$env{'request.course.id'}.'.url'};
3931: $topmap_url =~ s|/+|/|g;
3932: if ($topmap_url =~ m|^/uploaded|) {
3933: $outcome = &map_updater($cdom,$cnum,'group_allfolders.sequence',
3934: 'toplevelgroup',$grpstitle,$topmap_url);
3935: } else {
1.80 bisitz 3936: $outcome = '<span class="LC_warning">'
3937: .&mt('Non-standard course - folder for all groups not added.')
3938: .'</span>';
1.67 raeburn 3939: }
1.32 raeburn 3940: if ($outcome ne 'ok') {
1.67 raeburn 3941: my $delresult = &release_folder_lock($cdom,$cnum,'group_allfolders');
3942: if ($delresult ne 'ok') {
3943: $warning = $delresult;
3944: }
1.84 raeburn 3945: return $outcome.$warning;
1.32 raeburn 3946: }
3947: }
1.67 raeburn 3948: my $delresult = &release_folder_lock($cdom,$cnum,'group_allfolders');
3949: if ($delresult ne 'ok') {
3950: $warning = $delresult ;
3951: }
3952: } else {
1.80 bisitz 3953: $outcome = '<span class="LC_error">'
3954: .&mt('Could not obtain exclusive lock to check status of the folder for all groups. No group folder added.')
1.84 raeburn 3955: .'</span>';
1.67 raeburn 3956: return $outcome;
1.32 raeburn 3957: }
1.75 bisitz 3958: my $grpfolder = &mt($ucgpterm.' Folder - [_1]',$description);
1.49 raeburn 3959: $grppage='/adm/'.$cdom.'/'.$cnum.'/'.$groupname.'/smppg';
1.75 bisitz 3960: my $grptitle = &mt('Group homepage - [_1]',$description);
1.55 raeburn 3961: my ($discussions,$disctitle);
1.47 raeburn 3962: my $outcome = &map_updater($cdom,$cnum,'group_folder_'.$groupname.'.sequence',
1.32 raeburn 3963: 'grpseq',$grpfolder,$allgrpsmap,$grppage,
3964: $grptitle);
3965: if ($outcome ne 'ok') {
1.67 raeburn 3966: return $outcome.$warning;
1.32 raeburn 3967: }
3968: my $pageout = &create_homepage($cdom,$cnum,$groupname,$groupinfo,
3969: $tools,$gpterm,$ucgpterm,$now);
3970: # Link to folder for bulletin boards
1.47 raeburn 3971: $grpmap = $crspath.'group_folder_'.$groupname.'.sequence';
1.32 raeburn 3972: if (grep/^discussion$/,@{$tools}) {
3973: $disctitle = &mt('Discussion Boards');
1.47 raeburn 3974: my $outcome = &map_updater($cdom,$cnum,'group_boards_'.$groupname.
1.32 raeburn 3975: '.sequence','bbseq',$disctitle,$grpmap);
3976: if ($outcome ne 'ok') {
1.67 raeburn 3977: return $outcome.$warning;
1.32 raeburn 3978: }
1.47 raeburn 3979: $boardsmap = $crspath.'group_boards_'.$groupname.'.sequence';
1.32 raeburn 3980: }
3981: } else {
3982: #modify group folder if status of discussions tools is changed
3983: }
3984: my ($furl,$ferr)= &Apache::lonuserstate::readmap($cdom.'/'.$cnum);
1.67 raeburn 3985: my $navmap = Apache::lonnavmaps::navmap->new();
1.85 raeburn 3986: if (!defined($navmap)) {
1.104 raeburn 3987: $warning .= '<span class="LC_error">';
3988: if ($crstype eq 'Community') {
3989: $warning .= &mt("Error retrieving community contents").
3990: ' '.&mt("You need to re-initialize the community.");
3991: } else {
3992: $warning .= &mt("Error retrieving course contents").
3993: ' '.&mt("You need to re-initialize the course.");
3994: }
3995: $warning .= '</span>';
3996: return $warning;
1.85 raeburn 3997: }
1.32 raeburn 3998: # modify parameters
3999: my $parm_result;
4000: if ($action eq 'create') {
4001: if ($grpmap) {
4002: $parm_result .= &parm_setter($navmap,$cdom,$grpmap,$groupname);
4003: }
4004: if ($grppage) {
4005: $parm_result .= &parm_setter($navmap,$cdom,$grppage,$groupname);
4006: }
4007: if ($boardsmap) {
4008: $parm_result .= &parm_setter($navmap,$cdom,$boardsmap,$groupname);
4009: }
4010: }
1.67 raeburn 4011: undef($navmap);
1.32 raeburn 4012: if ($parm_result) {
1.67 raeburn 4013: return $warning.$parm_result;
4014: } else {
4015: return 'ok';
4016: }
4017: }
4018:
4019: sub get_folder_lock {
4020: my ($cdom,$cnum,$folder_name,$now) = @_;
4021: # get lock for folder being edited.
4022: my $lockhash = {
4023: $folder_name."\0".'locked_folder' => $now.':'.$env{'user.name'}.
4024: ':'.$env{'user.domain'},
4025: };
4026: my $tries = 0;
4027: my $gotlock = &Apache::lonnet::newput('coursegroups',$lockhash,$cdom,$cnum);
4028:
4029: while (($gotlock ne 'ok') && $tries <3) {
4030: $tries ++;
1.68 albertel 4031: sleep(1);
1.67 raeburn 4032: $gotlock = &Apache::lonnet::newput('coursegroups',$lockhash,$cdom,$cnum);
4033: }
4034: return $gotlock;
4035: }
4036:
4037: sub release_folder_lock {
4038: my ($cdom,$cnum,$folder_name) = @_;
4039: # remove lock
4040: my @del_lock = ($folder_name."\0".'locked_folder');
4041: my $dellockoutcome=&Apache::lonnet::del('coursegroups',\@del_lock,$cdom,$cnum);
4042: if ($dellockoutcome ne 'ok') {
1.80 bisitz 4043: return ('<div class="LC_error">'
4044: .&mt('Warning: failed to release lock for folder: [_1].','<tt>'.$folder_name.'</tt>')
4045: .'</div>'
4046: );
1.32 raeburn 4047: } else {
4048: return 'ok';
4049: }
4050: }
4051:
4052: sub map_updater {
4053: my ($cdom,$cnum,$newfile,$itemname,$itemtitle,$parentmap,$startsrc,
4054: $starttitle,$endsrc,$endtitle) = @_;
4055: my $outcome;
4056: $env{'form.'.$itemname} = &new_map($startsrc,$starttitle,$endsrc,
4057: $endtitle);
4058: my $newmapurl=&Apache::lonnet::finishuserfileupload($cnum,$cdom,$itemname,
4059: $newfile);
4060: if ($newmapurl !~ m|^/uploaded|) {
1.80 bisitz 4061: $outcome = '<div class="LC_error">'
4062: .&mt('Error uploading new folder.')." ($newfile): $newmapurl"
4063: .'</div>';
1.32 raeburn 4064: return $outcome;
1.67 raeburn 4065: }
1.63 albertel 4066: my ($errtext,$fatal)=&LONCAPA::map::mapread($parentmap);
1.32 raeburn 4067: if ($fatal) {
1.80 bisitz 4068: $outcome = '<div class="LC_error">'
4069: .&mt('Error reading contents of parent folder.')." ($parentmap): $errtext"
4070: .'</div>';
1.32 raeburn 4071: return $outcome;
4072: } else {
1.63 albertel 4073: my $newidx=&LONCAPA::map::getresidx($newmapurl);
4074: $LONCAPA::map::resources[$newidx] = $itemtitle.':'.$newmapurl.
1.32 raeburn 4075: ':false:normal:res';
1.63 albertel 4076: $LONCAPA::map::order[1+$#LONCAPA::map::order]=$newidx;
1.114 raeburn 4077: my ($outtext,$errtext) = &LONCAPA::map::storemap($parentmap,1,1);
1.67 raeburn 4078: if ($errtext) {
1.80 bisitz 4079: $outcome = '<div class="LC_error">'
4080: .&mt('Error saving updated parent folder.')." ($parentmap): $errtext"
4081: .'</div>';
1.32 raeburn 4082: return $outcome;
4083: }
4084: }
4085: return 'ok';
4086: }
4087:
4088: sub new_map {
4089: my ($startsrc,$starttitle,$endsrc,$endtitle) = @_;
4090: my $newmapstr = '
4091: <map>
4092: <resource id="1" src="'.$startsrc.'" type="start" title="'.$starttitle.'"></resource>
4093: <link from="1" to="2" index="1"></link>
4094: <resource id="2" src="'.$endsrc.'" type="finish" title="'.$endtitle.'"></resource>
4095: </map>
4096: ';
4097: return $newmapstr;
4098: }
4099:
4100: sub parm_setter {
1.104 raeburn 4101: my ($navmap,$cdom,$url,$groupname,$crstype) = @_;
1.85 raeburn 4102: if (!defined($navmap)) {
1.104 raeburn 4103: my $allresults;
4104: if ($crstype eq 'Community') {
4105: $allresults = &mt("Parameters not set for [_1] because the contents of the community could not be retrieved.",$url).' '.
4106: &mt("You need to reinitialize the community.");
4107: } else {
4108: $allresults = &mt("Parameters not set for [_1] because the contents of the course could not be retrieved.",$url).' '.
4109: &mt("You need to reinitialize the course.");
4110:
4111: }
4112: return '<div class="LC_warning">'.$allresults.'</div>';
1.85 raeburn 4113: }
1.32 raeburn 4114: my %hide_settings = (
4115: 'course' => {
4116: 'num' => 13,
4117: 'set' => 'yes',
4118: },
4119: 'group' => {
4120: 'num' => 5,
4121: 'set' => 'no',
4122: 'extra' => $groupname,
4123: },
4124: );
4125: my $res = $navmap->getResourceByUrl($url);
1.104 raeburn 4126: my $allresults;
1.67 raeburn 4127: if ($res) {
4128: my $symb = $res->symb();
4129: foreach my $level (keys(%hide_settings)) {
4130: my $parmresult =
4131: &Apache::lonparmset::storeparm_by_symb($symb,
1.32 raeburn 4132: '0_hiddenresource',
4133: $hide_settings{$level}{'num'},
4134: $hide_settings{$level}{'set'},
4135: 'string_yesno',undef,$cdom,
4136: undef,undef,
4137: $hide_settings{$level}{'extra'});
1.67 raeburn 4138: if ($parmresult) {
4139: $allresults .= $level.': '.$parmresult;
4140: }
1.37 raeburn 4141: }
1.67 raeburn 4142: } else {
1.104 raeburn 4143: $allresults = '<div class="LC_warning">';
4144: if ($crstype eq 'Community') {
4145: $allresults .= &mt("Parameters not set for [_1] because the resource was not recognized as part of the community.",'<tt>'.$url.'</tt>');
4146: } else {
4147: $allresults .= &mt('Parameters not set for [_1] because the resource was not recognized as part of the course.','<tt>'.$url.'</tt>');
4148: }
4149: $allresults .= '</div>';
1.32 raeburn 4150: }
1.37 raeburn 4151: return $allresults;
1.32 raeburn 4152: }
4153:
1.3 raeburn 4154: sub create_homepage {
1.32 raeburn 4155: my ($cdom,$cnum,$name,$groupinfo,$tools,$gpterm,$ucgpterm,$now) = @_;
1.3 raeburn 4156: my $functionality = join(',',@{$tools});
1.24 www 4157: my $content = &unescape($$groupinfo{description});
1.121 raeburn 4158: chomp($content);
4159: my $gateway = Apache::lonhtmlgateway->new();
4160: $content = $gateway->process_incoming_html($content,1);
1.3 raeburn 4161:
4162: my %pageinfo = (
1.29 raeburn 4163: 'aaa_title' => "$ucgpterm: $name",
1.3 raeburn 4164: 'abb_links' => $functionality,
4165: 'bbb_content' => $content,
4166: 'ccc_webreferences' => '',
1.32 raeburn 4167: 'uploaded.lastmodified' => $now,
1.3 raeburn 4168: );
4169: my $putresult = &Apache::lonnet::put('grppage_'.$name,\%pageinfo,$cdom,$cnum);
4170: return $putresult;
1.1 raeburn 4171: }
4172:
1.5 raeburn 4173: sub check_uncheck_tools {
4174: my ($r,$available) = @_;
4175: if (ref($available) eq 'ARRAY') {
4176: $r->print('
4177: <script type="text/javascript">
4178: function checkAllTools(formname) {
4179: ');
4180: foreach my $tool (@{$available}) {
4181: $r->print(' checkAll(formname.user_'.$tool.');'."\n");
4182: }
4183: $r->print(' checkAll(formname.togglefunc);'."\n");
4184: $r->print('
4185: }
4186: function uncheckAllTools(formname) {
4187: ');
4188: foreach my $tool (@{$available}) {
4189: $r->print(' uncheckAll(formname.user_'.$tool.');'."\n");
4190: }
4191: $r->print(' uncheckAll(formname.togglefunc);'."\n");
4192: $r->print('
4193: }
4194: function toggleTools(field,caller) {
4195: if (caller.checked) {
4196: checkAll(field);
4197: } else {
4198: uncheckAll(field);
4199: }
4200: return;
4201: }
4202: </script>
4203: ');
4204: }
4205: return;
4206: }
4207:
4208: sub validate_groupname {
1.29 raeburn 4209: my ($groupname,$action,$cdom,$cnum,$gpterm,$ucgpterm,$crstype) = @_;
1.16 albertel 4210: my %sectioncount = &Apache::loncommon::get_sections($cdom,$cnum);
1.17 raeburn 4211: my %curr_groups = &Apache::longroup::coursegroups($cdom,$cnum);
1.65 raeburn 4212: my %deleted_groups = &Apache::longroup::coursegroups($cdom,$cnum,undef,
4213: 'deleted_groups');
1.64 raeburn 4214: if (my $tmp = &Apache::lonnet::error(%deleted_groups)) {
4215: undef(%deleted_groups);
4216: &Apache::lonnet::logthis('Error retrieving groups: '.$tmp.' in '.$cnum.':'.$cdom);
4217: }
1.5 raeburn 4218: my %lt = &Apache::lonlocal::texthash (
1.29 raeburn 4219: igna => "Invalid $gpterm name",
4220: grna => "$ucgpterm names and section names used in a ".
4221: "$crstype must be unique.",
4222: gnmo => "$ucgpterm names may only contain letters, ".
4223: "numbers or underscores.",
1.5 raeburn 4224: );
1.15 albertel 4225:
1.126 raeburn 4226: my $exitmsg = '<span class="LC_error">'.$lt{'igna'}.'</span><br /><br />';
4227: my $nameshown = &Apache::loncommon::cleanup_html($groupname);
1.5 raeburn 4228: if (($groupname eq '') || ($groupname =~ /\W/)) {
1.126 raeburn 4229: return $exitmsg.
4230: &mt("The $gpterm name entered '[_1]' is not a valid name.",$nameshown).
4231: '<br />'.$lt{'gnmo'};
4232: } elsif ($groupname eq 'syllabus') {
4233: return $exitmsg.
4234: &mt("The $gpterm name entered '[_1]' is reserved for use by LON-CAPA.",$nameshown);
1.5 raeburn 4235: }
1.16 albertel 4236: if (exists($sectioncount{$groupname})) {
1.126 raeburn 4237: return $exitmsg.
4238: &mt("The $gpterm name entered '[_1]' can not be used as it is the name of a section in this $crstype.",$nameshown).
4239: '<br />'.$lt{'grna'};
1.5 raeburn 4240: }
1.64 raeburn 4241: if ($action eq 'create') {
4242: if (exists($curr_groups{$groupname})) {
1.126 raeburn 4243: return $exitmsg.
4244: &mt("The $gpterm name entered '[_1]' can not be used as it is the name of an existing $gpterm in this $crstype.",$nameshown).
4245: '<br />'.$lt{'grna'};
1.64 raeburn 4246: } elsif (exists($deleted_groups{$groupname})) {
1.126 raeburn 4247: return $exitmsg.
4248: &mt("The $gpterm name entered '[_1]' can not be used as it is the name of a $gpterm which previously existed in this $crstype.",$nameshown).
4249: '<br />'.$lt{'grna'};
1.64 raeburn 4250: }
1.5 raeburn 4251: } elsif ($action eq 'modify') {
4252: unless(exists($curr_groups{$groupname})) {
1.126 raeburn 4253: return &mt("$ucgpterm name: [_1] does not correspond to the name of an existing $gpterm in this $crstype.",$nameshown);
1.5 raeburn 4254: }
4255: }
4256: return;
4257: }
4258:
4259: sub check_changes {
4260: my ($member_changes,$memchg) = @_;
4261: my %exclusions;
4262: @{$exclusions{'changefunc'}} = ('expire');
4263: @{$exclusions{'changepriv'}} = ('expire','changefunc');
4264:
4265: foreach my $change (@{$member_changes}) {
1.6 raeburn 4266: if ($change eq 'deletion') {
1.5 raeburn 4267: next;
4268: }
1.6 raeburn 4269: my @checks = ('deletion');
1.5 raeburn 4270: if (exists($exclusions{$change})) {
4271: push(@checks,@{$exclusions{$change}});
4272: }
4273: my @temp = ();
4274: foreach my $item (@{$$memchg{$change}}) {
4275: my $match = 0;
4276: foreach my $check (@checks) {
1.6 raeburn 4277: if (defined($$memchg{$check})) {
4278: if (ref(@{$$memchg{$check}}) eq 'ARRAY') {
4279: if (@{$$memchg{$check}} > 0) {
4280: if (grep/^$item$/,@{$$memchg{$check}}) {
4281: $match = 1;
4282: last;
4283: }
4284: }
1.5 raeburn 4285: }
4286: }
4287: }
4288: if ($match) {
4289: next;
4290: }
4291: push(@temp,$item);
4292: }
4293: @{$$memchg{$change}} = @temp;
4294: }
4295: }
1.3 raeburn 4296:
1.1 raeburn 4297: 1;
1.106 wenzelju 4298:
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>