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