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