Annotation of loncom/interface/loncoursegroups.pm, revision 1.122
1.24 www 1: # The LearningOnline Network with CAPA
2: #
1.122 ! raeburn 3: # $Id: loncoursegroups.pm,v 1.121 2013/09/17 15:04:30 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',
2552: 'doma' => 'Domain',
2553: 'stda' => 'Start Date',
2554: 'enda' => 'End Date',
1.5 raeburn 2555: 'expi' => 'Expire',
2556: 'reen' => 'Re-enable',
2557: 'acti' => 'Activate',
2558: 'dele' => 'Delete',
1.53 raeburn 2559: 'curf' => 'Current Tool Set',
1.5 raeburn 2560: 'chpr' => 'Change Privileges'
2561: );
1.52 raeburn 2562: my ($current,$num_items,$hastools,$addtools) =
1.36 raeburn 2563: &Apache::longroup::group_memberlist($cdom,$cnum,$groupname,$fixedprivs,
2564: $available);
1.53 raeburn 2565: my $numcurrent = scalar(keys(%{$current}));
2566: if ($numcurrent > 0) {
1.36 raeburn 2567: $r->print('
1.5 raeburn 2568: <table>
2569: <tr>');
1.52 raeburn 2570: if ($num_items->{'active'}) {
1.36 raeburn 2571: &check_uncheck_buttons($r,$formname,'expire',$lt{'expi'});
2572: }
1.52 raeburn 2573: if ($num_items->{'previous'}) {
1.36 raeburn 2574: &check_uncheck_buttons($r,$formname,'reenable',$lt{'reen'});
2575: }
1.52 raeburn 2576: if ($num_items->{'future'}) {
1.36 raeburn 2577: &check_uncheck_buttons($r,$formname,'activate',$lt{'acti'});
2578: }
2579: &check_uncheck_buttons($r,$formname,'deletion',$lt{'dele'});
2580: if (@{$available} > 0) {
2581: if ($specificity eq 'Yes') {
2582: &check_uncheck_buttons($r,$formname,'changepriv',$lt{'chpr'});
1.5 raeburn 2583: }
1.36 raeburn 2584: if ($granularity eq 'Yes') {
2585: $r->print(&check_uncheck_tools($r,$available));
2586: $r->print('
1.5 raeburn 2587: <td>
1.83 bisitz 2588: <span class="LC_nobreak">
1.102 bisitz 2589: <fieldset><legend>'.$lt{'curf'}.'</legend>
1.80 bisitz 2590: <input type="button" value="'.&mt('check all').'"
1.5 raeburn 2591: onclick="javascript:checkAllTools(document.'.$formname.')" />
2592:
1.80 bisitz 2593: <input type="button" value="'.&mt('uncheck all').'"
1.5 raeburn 2594: onclick="javascript:uncheckAllTools(document.'.$formname.')" />
2595: </fieldset>
1.83 bisitz 2596: </span>
1.5 raeburn 2597: </td>
2598: ');
1.3 raeburn 2599: }
1.36 raeburn 2600: }
2601: $r->print(<<"END");
1.5 raeburn 2602: </tr>
2603: </table>
1.48 albertel 2604: <br />
1.5 raeburn 2605: END
1.48 albertel 2606: $r->print(&Apache::loncommon::start_data_table().
2607: &Apache::loncommon::start_data_table_header_row());
1.36 raeburn 2608: $r->print(<<"END");
1.48 albertel 2609: <th>$lt{'actn'}</th>
2610: <th><a href="javascript:changeSort('fullname')">$lt{'name'}</a></th>
2611: <th><a href="javascript:changeSort('username')">$lt{'usnm'}</a></th>
2612: <th><a href="javascript:changeSort('domain')">$lt{'doma'}</a></th>
2613: <th><a href="javascript:changeSort('id')">ID</a></th>
2614: <th><a href="javascript:changeSort('start')">$lt{'stda'}</a></th>
2615: <th><a href="javascript:changeSort('end')">$lt{'enda'}</a></th>
1.5 raeburn 2616: END
1.36 raeburn 2617: my $colspan = 0;
2618: if ($hastools) {
1.48 albertel 2619: $r->print('<th>'.$lt{'curf'}.'</th>');
2620: $colspan++;
1.36 raeburn 2621: }
2622: if ($addtools) {
1.53 raeburn 2623: $r->print('<th>'.&mt('Additional Tools').'</th>');
1.48 albertel 2624: $colspan++;
1.36 raeburn 2625: }
1.48 albertel 2626: $r->print(&Apache::loncommon::end_data_table_header_row());
1.36 raeburn 2627: if ($colspan) {
2628: if ($granularity eq 'Yes') {
1.48 albertel 2629: $r->print(&Apache::loncommon::start_data_table_row('LC_data_table_dense LC_data_table_highlight').'
1.6 raeburn 2630: <td colspan="7"> </td>
1.83 bisitz 2631: <td colspan="'.$colspan.'" align="center"><span class="LC_nobreak"><b>'.&mt('All:').
1.6 raeburn 2632: '</b> ');
1.36 raeburn 2633: foreach my $tool (@{$available}) {
2634: $r->print('<label><input type="checkbox" name="togglefunc"'.
1.7 raeburn 2635: ' onclick="javascript:toggleTools(document.'.$formname.'.user_'.$tool.',this);"'.
1.48 albertel 2636: ' value="'.$tool.'" />'.'<b>'.$tool.'</b></label> ');
1.6 raeburn 2637: }
1.83 bisitz 2638: $r->print('</span></td></tr>');
1.6 raeburn 2639: }
1.36 raeburn 2640: }
2641: my %Sortby = ();
2642: foreach my $user (sort(keys(%{$current}))) {
2643: if ($env{'form.sortby'} eq 'fullname') {
2644: push(@{$Sortby{$$current{$user}{fullname}}},$user);
2645: } elsif ($env{'form.sortby'} eq 'username') {
2646: push(@{$Sortby{$$current{$user}{uname}}},$user);
2647: } elsif ($env{'form.sortby'} eq 'domain') {
2648: push(@{$Sortby{$$current{$user}{udom}}},$user);
2649: } elsif ($env{'form.sortby'} eq 'id') {
2650: push(@{$Sortby{$$current{$user}{id}}},$user);
2651: } else {
2652: push(@{$Sortby{$$current{$user}{fullname}}},$user);
2653: }
2654: }
2655: foreach my $key (sort(keys(%Sortby))) {
2656: foreach my $user (@{$Sortby{$key}}) {
2657: my $id = $$current{$user}{id};
2658: my $fullname = $$current{$user}{fullname};
2659: my $udom = $$current{$user}{udom};
2660: my $uname = $$current{$user}{uname};
2661: my $start = $$current{$user}{start};
2662: my $end = $$current{$user}{end};
1.48 albertel 2663: $r->print(&Apache::loncommon::start_data_table_row('LC_data_table_dense').'
2664: <td>');
1.36 raeburn 2665: if ($$current{$user}{changestate} eq 'reenable') {
1.83 bisitz 2666: $r->print('<span class="LC_nobreak"><label>'.
1.5 raeburn 2667: '<input type="checkbox" name="reenable" value="'.$user.'" />'.
1.83 bisitz 2668: $lt{'reen'}.'</label></span><br />');
1.36 raeburn 2669: } elsif ($$current{$user}{changestate} eq 'expire') {
1.83 bisitz 2670: $r->print('<span class="LC_nobreak"><label>'.
1.5 raeburn 2671: '<input type="checkbox" name="expire" value="'.$user.'" />'.
1.83 bisitz 2672: $lt{'expi'}.'</label></span><br />');
1.36 raeburn 2673: } elsif ($$current{$user}{changestate} eq 'activate') {
1.83 bisitz 2674: $r->print('<span class="LC_nobreak"><label>'.
1.5 raeburn 2675: '<input type="checkbox" name="activate" value="'.$user.'" />'.
1.83 bisitz 2676: $lt{'acti'}.'</label></span><br />');
1.36 raeburn 2677: }
1.83 bisitz 2678: $r->print('<span class="LC_nobreak"><label>'.
1.6 raeburn 2679: '<input type="checkbox" name="deletion" value="'.$user.'" />'.
1.83 bisitz 2680: $lt{'dele'}.'</label></span>');
1.36 raeburn 2681: if ($specificity eq 'Yes') {
1.83 bisitz 2682: $r->print('<br /><span class="LC_nobreak"><label>'.
1.5 raeburn 2683: '<input type="checkbox" name="changepriv" value="'.$user.'" />'.$lt{'chpr'}.
1.83 bisitz 2684: '</label></span>');
1.36 raeburn 2685: }
2686: $r->print('
1.48 albertel 2687: </td>'.
2688: '<td>'.$fullname.'</td>'.
2689: '<td>'.$uname.'</td>'.
2690: '<td>'. $udom.'</td>'.
2691: '<td>'.$id.'</td>'.
2692: '<td>'.$start.'</td>'.
2693: '<td>'.$end.'</td>');
1.36 raeburn 2694: if ($hastools) {
1.83 bisitz 2695: $r->print('<td align="left"><span class="LC_nobreak">'.
1.6 raeburn 2696: ' ');
1.36 raeburn 2697: foreach my $tool (@{$$current{$user}{currtools}}) {
2698: if ($granularity eq 'Yes') {
2699: $r->print('<label><input type="checkbox" '.
1.7 raeburn 2700: 'checked="checked" '.
2701: 'name="user_'.$tool.'" value="'.
2702: $user.'" />'.$tool.'</label>');
1.36 raeburn 2703: } else {
2704: $r->print('<input type="hidden" '.
1.7 raeburn 2705: 'checked="checked" '.
2706: 'name="user_'.$tool.'" value="'.
2707: $user.'" />'.$tool);
1.36 raeburn 2708: }
2709: $r->print(' ');
1.5 raeburn 2710: }
1.83 bisitz 2711: $r->print('</span></td>');
1.36 raeburn 2712: }
2713: if ($addtools) {
1.48 albertel 2714: $r->print('<td align="left">');
1.36 raeburn 2715: if ($granularity eq 'Yes') {
2716: foreach my $tool (@{$$current{$user}{newtools}}) {
1.83 bisitz 2717: $r->print('<span class="LC_nobreak"><label><input type="checkbox"
1.5 raeburn 2718: name="user_'.$tool.'" value="'.
2719: $user.'" />'.$tool.
1.83 bisitz 2720: '</label></span> ');
1.36 raeburn 2721: }
2722: } else {
2723: foreach my $tool (@{$$current{$user}{newtools}}) {
1.83 bisitz 2724: $r->print('<span class="LC_nobreak"><input type="hidden"
1.5 raeburn 2725: name="user_'. $tool.'" value="'.
2726: $user.'" />'.$tool.
1.83 bisitz 2727: '</span> ');
1.5 raeburn 2728: }
2729: }
1.48 albertel 2730: $r->print('</td>');
1.5 raeburn 2731: }
1.48 albertel 2732: $r->print(&Apache::loncommon::end_data_table_row()."\n");
1.5 raeburn 2733: }
1.36 raeburn 2734: }
1.48 albertel 2735: $r->print(&Apache::loncommon::end_data_table());
1.53 raeburn 2736: } else {
2737: $r->print(&mt('There are no active, future or previous group members to modify.'));
1.5 raeburn 2738: }
1.53 raeburn 2739: return $numcurrent;
1.5 raeburn 2740: }
2741:
2742: sub check_uncheck_buttons {
2743: my ($r,$formname,$field,$title,$colspan) = @_;
2744: $r->print('
2745: <td '.$colspan.'>
2746: <fieldset>
1.102 bisitz 2747: <legend>'.$title.'</legend>
1.83 bisitz 2748: <span class="LC_nobreak">
1.80 bisitz 2749: <input type="button" value="'.&mt('check all').'"
1.5 raeburn 2750: onclick="javascript:checkAll(document.'.$formname.'.'.$field.')" />
2751:
1.80 bisitz 2752: <input type="button" value="'.&mt('uncheck all').'"
1.5 raeburn 2753: onclick="javascript:uncheckAll(document.'.$formname.'.'.$field.')" />
1.83 bisitz 2754: </span>
1.5 raeburn 2755: </fieldset>
2756: </td>
2757: ');
2758: }
2759:
2760:
2761: sub change_privs_form {
1.45 albertel 2762: my ($r,$cdom,$cnum,$action,$formname,$page,$startdate,$enddate,
2763: $tools,$functions,$toolprivs,$fixedprivs,$userdata,$usertools,
2764: $memchg,$idx,$states,$stored,$sectioncount,$navbuttons,$gpterm,
2765: $ucgpterm) = @_;
1.5 raeburn 2766: my @regexps = ('userpriv_');
2767: my $nexttext;
1.6 raeburn 2768: my %lt = &Apache::lonlocal::texthash(
2769: 'tode' => 'To be deleted',
2770: 'toex' => 'To be expired',
1.29 raeburn 2771: 'nome' => "No members to be deleted or expired from the $gpterm.",
1.6 raeburn 2772: );
1.5 raeburn 2773: $r->print(&Apache::lonhtmlcommon::echo_form_input(
1.6 raeburn 2774: ['origin','action','state','page','sortby'],\@regexps));
2775: if ($env{'form.branch'} eq 'adds') {
2776: $nexttext = $$navbuttons{'adme'};
2777: } else {
2778: $nexttext = $$navbuttons{'mose'};
2779: }
1.78 raeburn 2780: $r->print(&Apache::lonhtmlcommon::topic_bar(3,&mt('Members to delete or expire')));
1.6 raeburn 2781: my $exp_or_del = 0;
2782: if (ref($$memchg{'deletion'}) eq 'ARRAY') {
2783: if (@{$$memchg{'deletion'}} > 0) {
1.50 albertel 2784: $r->print('<b>'.$lt{'tode'}.':</b><br /><ul>');
1.6 raeburn 2785: foreach my $user (@{$$memchg{'deletion'}}) {
2786: $r->print('<li>'.$$userdata{$user}[$$idx{fullname}].
2787: ' ('.$user.')</li>');
2788: }
1.45 albertel 2789: $r->print('</ul>');
1.6 raeburn 2790: $exp_or_del += @{$$memchg{'deletion'}};
2791: }
2792: }
2793: if (ref($$memchg{'expire'}) eq 'ARRAY') {
2794: if (@{$$memchg{'expire'}} > 0) {
1.50 albertel 2795: $r->print('<b>'.$lt{'toex'}.':</b><br /><ul>');
1.6 raeburn 2796: foreach my $user (@{$$memchg{'expire'}}) {
2797: $r->print('<li>'.$$userdata{$user}[$$idx{fullname}].
2798: ' ('.$user.')</li>');
2799: }
1.45 albertel 2800: $r->print('</ul>');
1.6 raeburn 2801: $exp_or_del += @{$$memchg{'expire'}};
2802: }
2803: }
2804: if (!$exp_or_del) {
1.45 albertel 2805: $r->print($lt{'nome'}.'<br />');
1.6 raeburn 2806: }
1.5 raeburn 2807:
1.78 raeburn 2808: $r->print(&Apache::lonhtmlcommon::topic_bar(4,&mt('Setting optional privileges for specific group members')));
1.6 raeburn 2809:
1.45 albertel 2810: my $numchgs = &member_privileges_form($r,$action,$formname,$tools,
1.6 raeburn 2811: $toolprivs,$fixedprivs,$userdata,
2812: $usertools,$idx,$memchg,$states,
1.45 albertel 2813: $stored,$gpterm);
1.5 raeburn 2814: my $prevtext = $$navbuttons{'gtps'};
1.6 raeburn 2815: if ($numchgs || $exp_or_del) {
2816: &display_navbuttons($r,$formname,$$states{$action}[$page-1],$prevtext,
2817: $$states{$action}[$page+1],$nexttext);
2818: } else {
2819: &display_navbuttons($r,$formname,$$states{$action}[$page-1],$prevtext);
2820: }
1.5 raeburn 2821: return;
2822: }
2823:
2824: sub add_members_form {
1.59 raeburn 2825: my ($r,$cdom,$cnum,$action,$formname,$page,$startdate,$enddate,$groupname,
1.29 raeburn 2826: $description,$granularity,$quota,$sectioncount,$tools,$functions,
1.104 raeburn 2827: $stored,$states,$navbuttons,$gpterm,$ucgpterm,$crstype)=@_;
1.40 albertel 2828: $r->print(' <br />');
1.5 raeburn 2829: my @available = ();
2830: my @unavailable = ();
2831: &check_tools($functions,$tools,\@available,\@unavailable);
1.40 albertel 2832: &print_current_settings($r,$action,$functions,$startdate,$enddate,
2833: $groupname,$description,$granularity,$quota,
2834: \@available,\@unavailable,$gpterm,$ucgpterm);
1.59 raeburn 2835: &membership_options($r,$cdom,$cnum,$action,$formname,$sectioncount,1,$gpterm,
1.104 raeburn 2836: $ucgpterm,$crstype);
1.5 raeburn 2837: my $nexttext = $$navbuttons{'gtns'};
2838: my $prevtext = $$navbuttons{'gtpp'};
2839: &display_navbuttons($r,$formname,$$states{$action}[$page-1],$prevtext,
2840: $$states{$action}[$page+1],$nexttext);
2841: return;
2842: }
2843:
2844: sub choose_privs_form {
1.45 albertel 2845: my ($r,$cdom,$cnum,$action,$formname,$page,$startdate,$enddate,
2846: $tools,$functions,$toolprivs,$fixedprivs,$userdata,$usertools,$idx,
2847: $states,$stored,$sectioncount,$navbuttons,$gpterm,$ucgpterm,
2848: $crstype) = @_;
1.5 raeburn 2849:
2850: my @regexps = ('userpriv_');
2851: my $nexttext;
2852:
2853: if ($action eq 'create') {
2854: push(@regexps,'sec_');
2855: $r->print(&Apache::lonhtmlcommon::echo_form_input(
1.6 raeburn 2856: ['origin','action','state','page','sortby','autoadd','autodrop'],
1.5 raeburn 2857: \@regexps));
2858: $nexttext = $$navbuttons{'crgr'};
2859: } else {
2860: $r->print(&Apache::lonhtmlcommon::echo_form_input(
1.6 raeburn 2861: ['origin','action','state','page','sortby'],\@regexps));
1.5 raeburn 2862: $nexttext = $$navbuttons{'adme'};
2863: }
2864:
1.78 raeburn 2865: $r->print(&Apache::lonhtmlcommon::topic_bar(6,&mt('Setting optional privileges for specific group members')));
1.5 raeburn 2866:
1.45 albertel 2867: &member_privileges_form($r,$action,$formname,$tools,$toolprivs,
1.5 raeburn 2868: $fixedprivs,$userdata,$usertools,$idx,undef,
1.45 albertel 2869: $states,$stored,$gpterm);
1.5 raeburn 2870:
2871: if ($action eq 'create') {
1.53 raeburn 2872: my $img1 = 7;
2873: my $img2 = 8;
2874: &mapping_options($r,$action,$formname,$page,$sectioncount,
2875: $states,$stored,$navbuttons,$img1,$img2,
1.58 raeburn 2876: $gpterm,$ucgpterm,$crstype,$cdom,$cnum);
1.5 raeburn 2877: }
2878: my $prevtext = $$navbuttons{'gtps'};
2879: &display_navbuttons($r,$formname,$$states{$action}[$page-1],$prevtext,
2880: $$states{$action}[$page+1],$nexttext);
2881: return;
2882: }
2883:
2884: sub build_boxes {
2885: my ($r,$tools,$usertools,$fixedprivs,$toolprivs,$showtools,
1.6 raeburn 2886: $showboxes,$prefix,$specificity,$excluded) = @_;
1.5 raeburn 2887: my $totalboxes = 0;
2888: if (@{$tools} > 0) {
2889: if ($specificity eq 'Yes') {
2890: foreach my $tool (@{$tools}) {
2891: @{$$showboxes{$tool}} = ();
2892: foreach my $user (sort(keys(%{$usertools}))) {
1.6 raeburn 2893: if (ref($excluded) eq 'ARRAY') {
2894: if (grep/^$user$/,@{$excluded}) {
2895: next;
2896: }
1.5 raeburn 2897: }
1.6 raeburn 2898: if ($$usertools{$user}{$tool}) {
2899: unless (grep/^$tool$/,@{$showtools}) {
2900: push(@{$showtools},$tool);
2901: }
2902: foreach my $priv (sort(keys(%{$$toolprivs{$tool}}))) {
2903: unless (exists($$fixedprivs{$tool}{$priv})) {
2904: unless(grep(/^$priv$/,@{$$showboxes{$tool}})) {
2905: push(@{$$showboxes{$tool}},$priv);
2906: $totalboxes ++;
2907: }
1.5 raeburn 2908: }
2909: }
2910: }
2911: }
2912: }
2913: if ($totalboxes > 0) {
2914: $r->print('
2915: <script type="text/javascript">
2916: function checkAllTools(formname) {
2917: ');
2918: foreach my $tool (sort(keys(%{$showboxes}))) {
2919: foreach my $priv (@{$$showboxes{$tool}}) {
2920: $r->print(' checkAll(formname.'.$prefix.$priv.');'."\n");
2921: }
2922: }
2923: $r->print('
2924: }
2925: function uncheckAllTools(formname) {
2926: ');
2927: foreach my $tool (sort(keys(%{$showboxes}))) {
2928: foreach my $priv (@{$$showboxes{$tool}}) {
2929: $r->print(' uncheckAll(formname'.$prefix.$priv.');'."\n");
2930: }
2931: }
2932: $r->print('
2933: }
2934: </script>
2935: ');
2936: }
2937: }
2938: }
2939: return $totalboxes;
2940: }
2941:
2942: sub member_privileges_form {
1.45 albertel 2943: my ($r,$action,$formname,$tools,$toolprivs,$fixedprivs,$userdata,
2944: $usertools,$idx,$memchg,$states,$stored,$gpterm) = @_;
1.5 raeburn 2945: my %lt = &Apache::lonlocal::texthash(
2946: 'addp' => 'Additional privileges',
1.53 raeburn 2947: 'fixp' => 'Core privileges',
1.5 raeburn 2948: 'oppr' => 'Optional privileges',
1.53 raeburn 2949: 'func' => 'Tool',
2950: 'forf' => 'For the collaborative tools included for group '.
2951: 'members being added or modified, '.
2952: 'there are no optional privileges to set '.
2953: 'for specific members.',
1.80 bisitz 2954: 'algr' => 'All new group members will receive the same privileges.',
2955: 'ifex' => 'If previously expired members are being re-enabled, or '.
1.54 raeburn 2956: 'if access for future members is being activated now, '.
2957: 'previously set privileges will be preserved.',
1.53 raeburn 2958: 'asno' => 'As no group members are being added, '.
2959: 'there are no specific user privileges to set.',
2960: 'asng' => 'As no group tools will be made available to users, '.
2961: 'there are no specific user privileges to set.',
2962: 'nogm' => 'No group member privileges to display or set, '.
2963: 'as you have not indicated that you will be activating,'.
2964: ' re-enabling, changing privileges, or adding/removing '.
2965: 'tools for any current members.',
1.5 raeburn 2966: 'full' => 'Fullname',
2967: 'user' => 'Username',
2968: 'doma' => 'Domain',
2969: );
2970: my @defprivs;
2971: my $specificity;
2972: if ($action eq 'create') {
2973: if (defined($env{'form.defpriv'})) {
2974: @defprivs = &Apache::loncommon::get_env_multiple('form.defpriv');
2975: }
2976: $specificity = $env{'form.specificity'};
2977: } else {
1.17 raeburn 2978: if (defined($$stored{'defpriv'})) {
2979: @defprivs = @{$$stored{'defpriv'}};
2980: }
1.5 raeburn 2981: $specificity = $$stored{'specificity'};
2982: }
2983: my @showtools;
2984: my %showboxes = ();
2985: my $numtools = 1 + @{$tools};
1.3 raeburn 2986:
1.6 raeburn 2987: my @excluded = ();
2988: my $numchgs = 0;
2989: if ($formname eq 'change_privs') {
2990: my @currmembers = ();
2991: if (ref($$memchg{'deletion'}) eq 'ARRAY') {
2992: push(@excluded,@{$$memchg{'deletion'}});
2993: }
2994: if (ref($$memchg{'expire'}) eq 'ARRAY') {
2995: push(@excluded,@{$$memchg{'expire'}});
2996: }
2997: if (@excluded > 0) {
2998: foreach my $user (sort(keys(%{$usertools}))) {
2999: if (grep/^$user$/,@excluded) {
3000: next;
3001: }
3002: push(@currmembers,$user);
3003: }
3004: } else {
3005: @currmembers = sort(keys(%{$usertools}));
3006: }
3007: $numchgs = @currmembers;
3008: if (!$numchgs) {
1.45 albertel 3009: $r->print($lt{'nogm'});
1.6 raeburn 3010: return $numchgs;
3011: }
3012: }
3013:
3014: my $totalboxes = &build_boxes($r,$tools,$usertools,$fixedprivs,
3015: $toolprivs,\@showtools,\%showboxes,
3016: 'userpriv_',$specificity,\@excluded);
1.5 raeburn 3017: if (@{$tools} > 0) {
3018: if ($specificity eq 'Yes') {
3019: if ($totalboxes > 0) {
3020: my $numcells = 2;
3021: my $colspan = $numcells + 1;
3022: my %total;
1.6 raeburn 3023: if (keys(%{$usertools}) > 1) {
3024: $r->print('
1.45 albertel 3025: <table border="0" cellspacing="2" cellpadding="2">
1.5 raeburn 3026: <tr>
3027: ');
1.6 raeburn 3028: foreach my $tool (@{$tools}) {
3029: if (@{$showboxes{$tool}} > 0) {
3030: $r->print('<td valign="top">');
1.100 bisitz 3031: $r->print('<fieldset><legend>'.&mt($tool).'</legend>');
3032: $r->print('<table><tr>');
1.6 raeburn 3033: my $privcount = 0;
3034: foreach my $priv (@{$showboxes{$tool}}) {
3035: $privcount ++;
3036: if (($privcount == @{$showboxes{$tool}}) &&
3037: ($privcount > 1)) {
3038: if ($privcount%$numcells) {
3039: $r->print('<td colspan="'.$colspan.'">');
3040: } else {
3041: $r->print('<td>');
3042: }
1.5 raeburn 3043: } else {
3044: $r->print('<td>');
3045: }
1.80 bisitz 3046: $r->print(
1.102 bisitz 3047: '<fieldset><legend>'.&mt($$toolprivs{$tool}{$priv}).'</legend>'
1.80 bisitz 3048: .'<span class="LC_nobreak">'
3049: .' <input type="button" value="'.&mt('check all').'"'
3050: .' onclick="javascript:checkAll(document.'.$formname.'.userpriv_'.$priv.')" />'
3051: .' '
3052: .'<input type="button" value="'.&mt('uncheck all').'"'
3053: .' onclick="javascript:uncheckAll(document.'.$formname.'.userpriv_'.$priv.')" />'
3054: .'</span></fieldset><br />'
3055: );
1.6 raeburn 3056: $r->print('</td>');
3057: if ($privcount < @{$showboxes{$tool}}) {
3058: if (@{$showboxes{$tool}} > 2) {
3059: if ($privcount%$numcells == 0) {
3060: $r->print('</tr><tr>');
3061: }
3062: } else {
3063: $r->print('<tr></tr>');
1.5 raeburn 3064: }
3065: }
3066: }
1.100 bisitz 3067: $r->print('</tr></table></fieldset></td><td> </td>');
1.5 raeburn 3068: }
3069: }
1.45 albertel 3070: $r->print('</tr></table>');
1.5 raeburn 3071: }
1.45 albertel 3072: $r->print(&Apache::loncommon::start_data_table().
3073: &Apache::loncommon::start_data_table_header_row());
1.5 raeburn 3074: $r->print(<<"END");
1.45 albertel 3075: <th>$lt{'full'}</th>
3076: <th>$lt{'user'}</th>
1.5 raeburn 3077: <th>$lt{'doma'}</th>
3078: <th colspan="$numtools">$lt{'addp'}</th>
3079: END
1.45 albertel 3080: $r->print(&Apache::loncommon::end_data_table_header_row());
3081: &member_privs_entries($r,$usertools,$toolprivs,$fixedprivs,
1.6 raeburn 3082: $userdata,$idx,\@showtools,\@defprivs,
3083: \@excluded);
1.45 albertel 3084: $r->print(&Apache::loncommon::end_data_table());
1.5 raeburn 3085: } else {
1.43 albertel 3086: $r->print($lt{'forf'}.'<br />');
1.45 albertel 3087: &display_defprivs($r,$tools,$toolprivs,\@defprivs);
1.5 raeburn 3088: }
3089: } else {
3090: if (keys(%{$usertools}) > 0) {
1.54 raeburn 3091: $r->print($lt{'algr'}.'<br />'.$lt{'ifex'}.'<br /><br />');
1.45 albertel 3092: &display_defprivs($r,$tools,$toolprivs,\@defprivs);
1.5 raeburn 3093: } else {
1.43 albertel 3094: $r->print($lt{'asno'}.'<br />');
1.5 raeburn 3095: }
3096: }
3097: } else {
1.43 albertel 3098: $r->print($lt{'asng'});
1.5 raeburn 3099: }
1.6 raeburn 3100: return $numchgs;
1.1 raeburn 3101: }
3102:
1.5 raeburn 3103: sub process_request {
1.45 albertel 3104: my ($r,$cdom,$cnum,$action,$state,$page,$groupname,$description,
1.5 raeburn 3105: $specificity,$userdata,$startdate,$enddate,$tools,$functions,$toolprivs,
3106: $usertools,$idx,$types,$roles,$sections,$states,$navbuttons,$memchg,
1.45 albertel 3107: $sectioncount,$stored,$gpterm,$ucgpterm,$crstype) = @_;
1.3 raeburn 3108:
3109: $r->print(&Apache::lonhtmlcommon::echo_form_input(
1.6 raeburn 3110: ['origin','action','state','page','sortby']));
1.5 raeburn 3111:
1.29 raeburn 3112: my $earlyout = &validate_groupname($groupname,$action,$cdom,$cnum,$gpterm,
3113: $ucgpterm,$crstype);
1.5 raeburn 3114: if ($earlyout) {
3115: $r->print('
3116: <table width="100%" cellpadding="0" cellspacing="0" border="0">
3117: <tr>
3118: <td> </td>
3119: <td colspan="3">
3120: '.$earlyout.'</td></tr>');
3121: &display_navbuttons($r,$state,$$states{$action}[$page-1],
3122: $$navbuttons{'gtps'});
3123: $r->print('</table>');
3124: return;
3125: }
3126:
3127: my @defprivs = ();
3128: if ($action eq 'create' || $state eq 'chgresult') {
3129: if (defined($env{'form.defpriv'})) {
3130: @defprivs = &Apache::loncommon::get_env_multiple('form.defpriv');
3131: }
3132: if ($state eq 'chgresult') {
3133: my @okprivs = ();
3134: foreach my $tool (@{$tools}) {
3135: foreach my $priv (sort(keys(%{$$toolprivs{$tool}}))) {
3136: push(@okprivs,$priv);
3137: }
3138: }
3139: my @temp = ();
3140: foreach my $defpriv (@defprivs) {
3141: if (grep/^$defpriv$/,@okprivs) {
3142: push(@temp,$defpriv);
3143: }
3144: }
3145: @defprivs = @temp;
3146: }
3147: } else {
1.17 raeburn 3148: if (defined($$stored{'defpriv'})) {
3149: @defprivs = @{$$stored{'defpriv'}};
3150: }
1.5 raeburn 3151: }
3152:
3153: my $outcome;
3154: if ($action eq 'create' || $state eq 'chgresult') {
3155: $outcome = &write_group_data($r,$cdom,$cnum,$action,$state,$groupname,
3156: $description,$startdate,$enddate,
3157: $specificity,$functions,$tools,
3158: $sectioncount,$roles,$types,$sections,
1.29 raeburn 3159: \@defprivs,$stored,$gpterm,$ucgpterm,
3160: $crstype);
1.5 raeburn 3161: }
3162: if (($action eq 'create' && $outcome eq 'ok') || (($action eq 'modify') &&
3163: (($state eq 'memresult') || ($state eq 'addresult')))) {
1.6 raeburn 3164: &process_membership($r,$cdom,$cnum,$action,$state,$groupname,$tools,
3165: $enddate,$startdate,$userdata,$idx,$toolprivs,
1.29 raeburn 3166: $usertools,$specificity,\@defprivs,$memchg,$gpterm,
1.104 raeburn 3167: $ucgpterm,$crstype);
1.5 raeburn 3168: }
3169: return;
3170: }
3171:
3172: sub write_group_data {
3173: my ($r,$cdom,$cnum,$action,$state,$groupname,$description,$startdate,
3174: $enddate,$specificity,$functions,$tools,$sectioncount,$roles,$types,
1.29 raeburn 3175: $sections,$defprivs,$stored,$gpterm,$ucgpterm,$crstype) = @_;
1.5 raeburn 3176: my $now = time;
3177: my $creation = $now;
3178: my $creator = $env{'user.name'}.':'.$env{'user.domain'};
3179: if ($state eq 'chgresult') {
3180: $creation = $$stored{'creation'};
3181: $creator = $$stored{'creator'};
3182: }
1.24 www 3183: my $esc_description = &escape($description);
1.5 raeburn 3184: my @single_attributes = ('description','functions','startdate','enddate',
3185: 'creation','modified','creator','granularity',
1.29 raeburn 3186: 'specificity','autoadd','autodrop','quota');
1.5 raeburn 3187: my @mult_attributes = ('roles','types','sectionpick','defpriv');
1.15 albertel 3188:
1.37 raeburn 3189: my ($crsquota,$freespace,$maxposs) = &get_quota_constraints($action,
3190: $stored);
3191: my $quota = $env{'form.quota'};
3192:
3193: $quota =~ s/^\s*([^\s]*)\s*$/$1/;
3194: if ($quota eq '') {
3195: $quota = 0;
3196: }
3197: if ($quota !~ /^\d*\.?\d*$/) {
3198: $quota = 0;
1.79 bisitz 3199: $r->print('<div class="LC_warning">'
1.96 weissno 3200: .&mt('The value you entered for the quota for the group portfolio in this '.$gpterm
1.122 ! raeburn 3201: .' contained invalid characters, so it has been set to 0 MB. You can change this by'
1.79 bisitz 3202: .' modifying the '.$gpterm.' settings.')
3203: .'</div>');
1.37 raeburn 3204: }
3205: if ($quota > $maxposs) {
3206: $quota = $maxposs;
1.79 bisitz 3207: $r->print('<div class="LC_warning">'
1.96 weissno 3208: .&mt('The value you entered for the quota for the group portfolio in this '.$gpterm
1.122 ! raeburn 3209: .' exceeded the maximum possible value, so it has been set to [_1] MB '
1.79 bisitz 3210: .'(the maximum possible value).',sprintf("%.2f",$maxposs))
3211: .'</div>');
1.37 raeburn 3212: }
1.5 raeburn 3213: my %groupinfo = (
3214: description => $esc_description,
3215: startdate => $startdate,
3216: enddate => $enddate,
3217: creation => $creation,
3218: modified => $now,
3219: creator => $creator,
3220: granularity => $env{'form.granularity'},
3221: specificity => $specificity,
3222: autoadd => $env{'form.autoadd'},
3223: autodrop => $env{'form.autodrop'},
1.37 raeburn 3224: quota => $quota,
1.5 raeburn 3225: );
1.37 raeburn 3226:
1.5 raeburn 3227: foreach my $func (keys(%{$functions})) {
3228: my $status;
3229: if (grep(/^$func$/,@{$tools})) {
3230: $status = 'on';
3231: } else {
3232: $status = 'off';
3233: }
3234: $groupinfo{'functions'} .= qq|<name id="$func">$status</name>|;
3235: }
3236:
3237: $groupinfo{'roles'} = $roles;
3238: $groupinfo{'types'} = $types;
3239: $groupinfo{'sectionpick'} = $sections;
3240: $groupinfo{'defpriv'} = $defprivs;
3241:
3242: my %groupsettings = ();
3243: foreach my $item (@single_attributes) {
3244: $groupsettings{$groupname} .= qq|<$item>$groupinfo{$item}</$item>|;
3245: }
3246: foreach my $item (@mult_attributes) {
3247: foreach my $entry (@{$groupinfo{$item}}) {
3248: $groupsettings{$groupname} .= qq|<$item>$entry</$item>|;
3249: }
3250: }
3251: my $autosec;
3252: my @autorole = &Apache::loncommon::get_env_multiple('form.autorole');
1.15 albertel 3253:
1.5 raeburn 3254: foreach my $role (@autorole) {
3255: if (defined($env{'form.sec_'.$role})) {
3256: my @autosections=&Apache::loncommon::get_env_multiple('form.sec_'.
3257: $role);
3258: $autosec .= '<role id="'.$role.'">';
3259: foreach my $sec (@autosections) {
3260: $autosec .= '<section>'.$sec.'</section>';
3261: }
3262: $autosec .= '</role>';
3263: }
3264: }
3265: if ($autosec) {
3266: $groupsettings{$groupname} .= qq|<autosec>$autosec</autosec>|;
3267: }
3268: my $result = &Apache::lonnet::modify_coursegroup($cdom,$cnum,
3269: \%groupsettings);
3270:
3271: if ($result eq 'ok') {
3272: if ($action eq 'create') {
1.32 raeburn 3273: my $result = &add_group_folder($cdom,$cnum,$now,$groupname,$action,
3274: $description,$tools,\%groupinfo,
3275: $gpterm,$ucgpterm,$crstype);
1.79 bisitz 3276: if ($result eq 'ok') {
1.109 wenzelju 3277: my $msg = &Apache::lonhtmlcommon::confirm_success(&mt($ucgpterm.' [_1] was created.','<i>'.$groupname.'</i>'));
3278: $msg = &Apache::loncommon::confirmwrapper($msg);
3279: $r->print($msg);
1.79 bisitz 3280: } else {
1.109 wenzelju 3281: my $msg = &Apache::lonhtmlcommon::confirm_success(&mt('A problem occurred when creating folders for the new '.$gpterm.' [_1]:'
3282: ,'<i>'.$groupname.'</i>')
3283: .'<br />'.$result,1);
3284: $msg = &Apache::loncommon::confirmwrapper($msg);
3285: $r->print($msg);
1.32 raeburn 3286: }
1.56 raeburn 3287: } elsif ($action eq 'modify') {
3288: my (@oldtools,@newtools);
3289: if (ref($$stored{'tool'}) eq 'ARRAY') {
3290: @oldtools = @{$$stored{'tool'}};
3291: }
3292: if (ref($tools) eq 'ARRAY') {
3293: @newtools = @{$tools};
3294: }
3295: if (!grep(/^discussion$/,@oldtools) &&
3296: grep(/^discussion$/,@newtools)) {
3297: my $crspath = '/uploaded/'.$cdom.'/'.$cnum.'/';
3298: my $boardsmap = $crspath.'group_boards_'.$groupname.'.sequence';
3299: my $navmap = Apache::lonnavmaps::navmap->new();
1.85 raeburn 3300: my ($bbmapres,$error);
3301: if (defined($navmap)) {
3302: $bbmapres = $navmap->getResourceByUrl($boardsmap);
3303: undef($navmap);
3304: if (!$bbmapres) {
3305: my $grpmap = $crspath.'group_folder_'.$groupname.'.sequence';
3306: my $disctitle = &mt('Discussion Boards');
3307: my $outcome = &map_updater($cdom,$cnum,'group_boards_'.
3308: $groupname.'.sequence','bbseq',
3309: $disctitle,$grpmap);
3310: my ($furl,$ferr) =
3311: &Apache::lonuserstate::readmap($cdom.'/'.$cnum);
3312: # modify parameter
3313: if ($outcome eq 'ok') {
3314: $navmap = Apache::lonnavmaps::navmap->new();
3315: if (defined($navmap)) {
3316: my $parm_result = &parm_setter($navmap,$cdom,$boardsmap,
3317: $groupname);
3318: if ($parm_result) {
3319: $error = &mt('An error occurred while setting parameters '
3320: .'for Discussion Boards folder: '
3321: .'[_1]',$parm_result);
3322: } else {
3323: $r->print('<div class="LC_success">'.
3324: &mt('Discussion Boards Folder created.')
3325: .'</div>');
3326: }
3327: undef($navmap);
3328: } else {
1.104 raeburn 3329: if ($crstype eq 'Community') {
3330: $error = &mt("An error occurred while setting parameters '.
1.85 raeburn 3331: 'for Discussion Boards folder: '.
1.104 raeburn 3332: 'Could not retrieve community information");
3333: } else {
3334: $error = &mt("An error occurred while setting parameters '.
3335: 'for Discussion Boards folder: '.
3336: 'Could not retrieve course information");
3337: }
1.85 raeburn 3338: }
1.56 raeburn 3339: } else {
1.85 raeburn 3340: $r->print($outcome);
1.56 raeburn 3341: }
3342: }
1.85 raeburn 3343: } else {
1.104 raeburn 3344: $error = &mt("An error occurred while retrieving the contents of the group's folder.").'<br />';
3345: if ($crstype eq 'Community') {
3346: $error .= &mt("You need to re-initialize the community.");
3347:
3348: } else {
3349: $error .= &mt("You need to re-initialize the course.");
3350: }
1.85 raeburn 3351: }
3352: if ($error ne '') {
3353: $r->print('<div class="LC_error">'.$error.'</div>');
1.56 raeburn 3354: }
3355: }
1.109 wenzelju 3356: my $message = &Apache::lonhtmlcommon::confirm_success(&mt($ucgpterm.' [_1] was updated.','<i>'.$groupname.'</i>'));
3357: $message = &Apache::loncommon::confirmwrapper($message);
3358: $r->print($message);
1.5 raeburn 3359: }
3360: } else {
3361: my %actiontype = (
3362: 'create' => 'creating',
3363: 'modify' => 'modifying',
3364: );
1.29 raeburn 3365: &Apache::lonnet::logthis("Failed to store $gpterm $groupname ".
3366: 'in '.lc($crstype).': '.$cnum.
3367: ' in domain: '.$cdom);
1.79 bisitz 3368: $r->print('<div class="LC_error">'
3369: .&mt('An error occurred when [_1] the '.$gpterm.'. '
3370: .'Please try again.',$actiontype{$action})
3371: .'</div>');
1.5 raeburn 3372: }
3373: return $result;
3374: }
3375:
3376: sub process_membership {
1.6 raeburn 3377: my ($r,$cdom,$cnum,$action,$state,$groupname,$tools,$enddate,$startdate,
1.29 raeburn 3378: $userdata,$idx,$toolprivs,$usertools,$specificity,$defprivs,$memchg,
1.104 raeburn 3379: $gpterm,$ucgpterm,$crstype)=@_;
1.5 raeburn 3380: my %usersettings = ();
1.6 raeburn 3381: my %added= ();
3382: my %failed = ();
3383: my $num_ok = 0;
3384: my $num_fail = 0;
1.3 raeburn 3385: my %group_privs = ();
1.20 raeburn 3386: my %curr_privs = ();
1.21 raeburn 3387: my %curr_start = ();
3388: my %curr_end = ();
1.3 raeburn 3389: my %tooltype = ();
1.77 raeburn 3390: my $context = 'processgroupmembership';
1.5 raeburn 3391:
1.3 raeburn 3392: foreach my $tool (@{$tools}) {
3393: foreach my $priv (sort(keys(%{$$toolprivs{$tool}}))) {
3394: $tooltype{$priv} = $tool;
1.5 raeburn 3395: if ($specificity eq 'Yes') {
1.3 raeburn 3396: my @users =
3397: &Apache::loncommon::get_env_multiple('form.userpriv_'.$priv);
3398: foreach my $user (@users) {
3399: $group_privs{$user} .= $priv.':';
1.8 raeburn 3400: if ($state eq 'memresult') {
3401: unless (exists($$usertools{$user}{$tool})) {
3402: $$usertools{$user}{$tool} = 1;
3403: }
3404: }
1.3 raeburn 3405: }
3406: } else {
1.5 raeburn 3407: if (@{$defprivs} > 0) {
1.26 raeburn 3408: if (grep/^\Q$priv\E$/,@{$defprivs}) {
1.5 raeburn 3409: foreach my $user (sort(keys(%{$usertools}))) {
3410: if ($$usertools{$user}{$tool}) {
3411: $group_privs{$user} .= $priv.':';
3412: }
1.3 raeburn 3413: }
3414: }
3415: }
3416: }
3417: }
3418: }
3419: foreach my $user (keys(%group_privs)) {
3420: $group_privs{$user} =~ s/:$//;
3421: }
1.5 raeburn 3422:
1.6 raeburn 3423: my $now = time;
3424: my @activate = ();
3425: my @expire = ();
3426: my @deletion = ();
3427: my @reenable = ();
1.20 raeburn 3428: my @unchanged = ();
1.6 raeburn 3429: if ($state eq 'memresult') {
3430: if (ref($$memchg{'activate'}) eq 'ARRAY') {
3431: @activate = @{$$memchg{'activate'}};
3432: }
3433: if (ref($$memchg{'expire'}) eq 'ARRAY') {
3434: @expire = @{$$memchg{'expire'}};
3435: }
3436: if (ref($$memchg{'deletion'}) eq 'ARRAY') {
3437: @deletion = @{$$memchg{'deletion'}};
3438: }
3439: if (ref($$memchg{'reenable'}) eq 'ARRAY') {
3440: @reenable = @{$$memchg{'reenable'}};
3441: }
1.20 raeburn 3442: my %membership = &Apache::lonnet::get_group_membership($cdom,$cnum,
3443: $groupname);
3444: foreach my $key (sort(keys(%membership))) {
3445: if ($key =~ /^\Q$groupname\E:([^:]+:[^:]+)$/) {
1.21 raeburn 3446: ($curr_end{$1},$curr_start{$1},$curr_privs{$1}) =
3447: split(/:/,$membership{$key},3);
1.20 raeburn 3448: }
3449: }
1.6 raeburn 3450: if (@expire + @deletion > 0) {
3451: foreach my $user (@expire) {
1.21 raeburn 3452: my $savestart = $curr_start{$user};
3453: if ($savestart > $now) {
3454: $savestart = $now;
1.6 raeburn 3455: }
1.21 raeburn 3456: $usersettings{$groupname.':'.$user} = $now.':'.$savestart.':'.
3457: $curr_privs{$user};
1.6 raeburn 3458: if (&Apache::lonnet::modify_group_roles($cdom,$cnum,$groupname,
1.21 raeburn 3459: $user,$now,$savestart,
1.77 raeburn 3460: $curr_privs{$user},'',$context) eq 'ok') {
1.6 raeburn 3461: push(@{$added{'expired'}},$user);
3462: $num_ok ++;
3463: } else {
3464: push(@{$failed{'expired'}},$user);
3465: $num_fail ++;
3466: }
3467: }
3468: foreach my $user (@deletion) {
3469: $usersettings{$groupname.':'.$user} = $now.':-1:';
3470: if (&Apache::lonnet::modify_group_roles($cdom,$cnum,$groupname,
1.76 raeburn 3471: $user,$now,'-1','','',$context)
1.6 raeburn 3472: eq 'ok') {
3473: push(@{$added{'deleted'}},$user);
3474: $num_ok ++;
3475: } else {
3476: push(@{$failed{'deleted'}},$user);
3477: $num_fail ++;
3478: }
3479: }
3480: }
1.8 raeburn 3481: }
1.6 raeburn 3482:
1.5 raeburn 3483: foreach my $user (sort(keys(%{$usertools}))) {
1.20 raeburn 3484: if ((grep(/^$user$/,@expire)) || (grep(/^$user$/,@deletion))) {
3485: next;
3486: }
1.6 raeburn 3487: my $type;
3488: my $start = $startdate;
3489: my $end = $enddate;
3490: if ($state eq 'memresult') {
3491: if (@activate > 0) {
3492: if (grep/^$user$/,@activate) {
3493: $start = $now;
1.21 raeburn 3494: $end = $enddate;
1.6 raeburn 3495: $type = 'activated';
3496: }
3497: }
3498: if (@reenable > 0) {
3499: if (grep/^$user$/,@reenable) {
1.21 raeburn 3500: $start = $startdate;
3501: $end = $enddate;
1.6 raeburn 3502: $type = 'reenabled';
3503: }
3504: }
1.38 raeburn 3505: if ($type eq '') {
3506: if ($curr_privs{$user} eq $group_privs{$user}) {
3507: push(@unchanged,$user);
3508: next;
3509: }
3510: if (exists($curr_start{$user})) {
3511: $start = $curr_start{$user};
3512: }
3513: if (exists($curr_end{$user})) {
3514: $end = $curr_end{$user};
3515: }
3516: $type = 'modified';
3517: }
1.6 raeburn 3518: } else {
3519: $type = 'added';
3520: }
3521: $usersettings{$groupname.':'.$user} = $end.':'.$start.':'.
1.5 raeburn 3522: $group_privs{$user};
3523: if (&Apache::lonnet::modify_group_roles($cdom,$cnum,$groupname,
1.6 raeburn 3524: $user,$end,$start,
1.76 raeburn 3525: $group_privs{$user},'',$context) eq 'ok') {
1.6 raeburn 3526: push(@{$added{$type}},$user);
3527: $num_ok ++;
1.3 raeburn 3528: } else {
1.6 raeburn 3529: push(@{$failed{$type}},$user);
3530: $num_fail ++;
1.5 raeburn 3531: }
3532: }
3533: my $roster_result = &Apache::lonnet::modify_coursegroup_membership($cdom,
3534: $cnum,\%usersettings);
1.6 raeburn 3535: if ($num_ok) {
1.109 wenzelju 3536: my $msgall ='';
3537: foreach my $type (sort(keys(%added))) {
1.120 raeburn 3538: my $message = &mt("The following users were successfully $type");
1.20 raeburn 3539: if (!($type eq 'deleted' || $type eq 'expired')) {
1.109 wenzelju 3540: $message .= &mt(' with the following privileges');
1.6 raeburn 3541: }
1.109 wenzelju 3542: $message .= ':<br/>';
1.6 raeburn 3543: foreach my $user (@{$added{$type}}) {
1.8 raeburn 3544: my $privlist = '';
3545: if (!($type eq 'deleted' || $type eq 'expired')) {
3546: $privlist = ': ';
1.6 raeburn 3547: my @privs = split(/:/,$group_privs{$user});
3548: my $curr_tool = '';
3549: foreach my $priv (@privs) {
3550: unless ($curr_tool eq $tooltype{$priv}) {
3551: $curr_tool = $tooltype{$priv};
3552: $privlist .= '<b>'.$curr_tool.'</b>: ';
3553: }
3554: $privlist .= $$toolprivs{$curr_tool}{$priv}.', ';
3555: }
3556: $privlist =~ s/, $//;
3557: }
1.109 wenzelju 3558: $message .= $$userdata{$user}[$$idx{fullname}].' - '.$user.$privlist.'<br />';
1.6 raeburn 3559: }
1.109 wenzelju 3560: $message .= '<br/>';
3561: $message = &Apache::lonhtmlcommon::confirm_success($message);
3562: $msgall .= $message;
1.6 raeburn 3563: }
1.109 wenzelju 3564: $msgall = &Apache::loncommon::confirmwrapper($msgall);
3565: $r->print($msgall);
1.6 raeburn 3566: }
3567: if ($num_fail) {
3568: foreach my $type (sort(keys(%failed))) {
1.79 bisitz 3569: $r->print('<div class="LC_error">'
3570: .&mt("The following users could not be $type, because an error occurred:")
3571: .'</div>');
1.6 raeburn 3572: foreach my $user (@{$failed{$type}}) {
3573: $r->print($$userdata{$user}[$$idx{fullname}].' - '.$user.'<br />');
3574: }
1.5 raeburn 3575: }
1.20 raeburn 3576: $r->print('<br />');
3577: }
1.109 wenzelju 3578: # Is that really needed?
3579: #
3580: # if (@unchanged > 0) {
3581: # $r->print(&mt('No change occurred for the following users:').'<br />');
3582: # foreach my $user (sort(@unchanged)) {
3583: # $r->print($$userdata{$user}[$$idx{fullname}].' - '.$user.'<br />');
3584: # }
3585: # $r->print('<br />');
3586: # }
1.5 raeburn 3587: if ($roster_result eq 'ok') {
1.80 bisitz 3588: $r->print('<div class="LC_success">'
3589: .&mt($ucgpterm.' membership list updated.')
3590: .'</div>');
1.104 raeburn 3591: $r->print('<p class="LC_info">');
3592: if ($crstype eq 'Community') {
3593: $r->print(&mt("Any currently logged in community users affected by the changes you made"
1.80 bisitz 3594: .' to group membership or privileges for the [_1] group will need to log out'
3595: .' and log back in for their LON-CAPA sessions to reflect these changes.'
1.104 raeburn 3596: ,'<i>'.$groupname.'</i>'));
3597:
3598: } else {
3599: $r->print(&mt("Any currently logged in course users affected by the changes you made"
3600: .' to group membership or privileges for the [_1] group will need to log out'
3601: .' and log back in for their LON-CAPA sessions to reflect these changes.'
3602: ,'<i>'.$groupname.'</i>'));
3603: }
3604: $r->print('</p>');
1.5 raeburn 3605: } else {
1.80 bisitz 3606: $r->print('<div class="LC_error">'
3607: .&mt("An error occurred while updating the $gpterm membership list:")
3608: .'<br />'.$roster_result
3609: .'</div>');
1.5 raeburn 3610: }
3611: return;
3612: }
3613:
3614: sub mapping_options {
1.44 albertel 3615: my ($r,$action,$formname,$page,$sectioncount,$states,$stored,
1.58 raeburn 3616: $navbuttons,$img1,$img2,$gpterm,$ucgpterm,$crstype,$cdom,$cnum) = @_;
1.5 raeburn 3617: my %lt = &Apache::lonlocal::texthash(
1.29 raeburn 3618: 'auto' => "Settings for automatic $gpterm enrollment",
3619: 'gmma' => "$ucgpterm membership mapping to specific sections/roles",
3620: 'endi' => "Enable/disable automatic $gpterm enrollment for ".
3621: "users in specified roles and sections",
1.53 raeburn 3622: '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 3623: '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.",
3624: 'pirs' => "Pick roles and sections for automatic $gpterm enrollment",
1.5 raeburn 3625: 'on' => 'on',
3626: 'off' => 'off',
1.29 raeburn 3627: 'auad' => "Automatically enable $gpterm membership when roles are added?",
3628: 'auex' => "Automatically expire $gpterm membership when roles are removed?",
3629: 'mapr' => "Mapping of roles and sections affected by automatic $gpterm enrollment/disenrollment follows scheme chosen below.",
1.5 raeburn 3630: );
1.44 albertel 3631: &automapping($r,$action,$stored,\%lt,$img1);
1.58 raeburn 3632: &mapping_settings($r,$sectioncount,\%lt,$stored,$img2,$crstype,$cdom,$cnum,
3633: $action);
1.5 raeburn 3634: return;
3635: }
3636:
3637: sub automapping {
1.44 albertel 3638: my ($r,$action,$stored,$lt,$image) = @_;
1.5 raeburn 3639: my $add = 'off';
3640: my $drop = 'off';
3641: if (exists($$stored{'autoadd'})) {
3642: $add = $$stored{'autoadd'};
3643: }
3644: if (exists($$stored{'autodrop'})) {
3645: $drop = $$stored{'autodrop'};
3646: }
1.78 raeburn 3647: $r->print(&Apache::lonhtmlcommon::topic_bar($image,$$lt{'endi'}).'
1.44 albertel 3648: <b>'.$$lt{'gmma'}.':</b><br />'.$$lt{'adds'}.'<br />'.$$lt{'drops'}.'<br /><br />
1.83 bisitz 3649: <span class="LC_nobreak">'.$$lt{'auad'}.':
1.80 bisitz 3650: <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 3651: if ($action eq 'modify') {
1.82 bisitz 3652: $r->print(' ('.&mt('Currently set to [_1].','<b>'.$$lt{$add}.'</b>').')');
1.5 raeburn 3653: }
3654: $r->print('
1.83 bisitz 3655: </span><br />
3656: <span class="LC_nobreak">'.$$lt{'auex'}.':
1.80 bisitz 3657: <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 3658: if ($action eq 'modify') {
1.82 bisitz 3659: $r->print(' ('.&mt('Currently set to [_1].','<b>'.$$lt{$drop}.'</b>').')');
1.3 raeburn 3660: }
1.83 bisitz 3661: $r->print('</span><br /><br />'.$$lt{'mapr'});
1.5 raeburn 3662: }
1.3 raeburn 3663:
1.5 raeburn 3664: sub mapping_settings {
1.58 raeburn 3665: my ($r,$sectioncount,$lt,$stored,$image,$crstype,$cdom,$cnum,$action) = @_;
1.5 raeburn 3666: my @sections = keys(%{$sectioncount});
3667: if (@sections > 0) {
3668: @sections = sort {$a cmp $b} @sections;
1.17 raeburn 3669: unshift(@sections,'none'); # Put 'no sections' next
3670: unshift(@sections,'all'); # Put 'all' at the front of the list
1.53 raeburn 3671: } else {
3672: @sections = ('all','none');
1.3 raeburn 3673: }
1.78 raeburn 3674: $r->print(&Apache::lonhtmlcommon::topic_bar($image,$$lt{'pirs'}));
1.104 raeburn 3675: my @roles = &standard_roles($crstype);
1.59 raeburn 3676: my %customroles = &Apache::lonhtmlcommon::course_custom_roles($cdom,$cnum);
1.44 albertel 3677: $r->print(&Apache::loncommon::start_data_table().
3678: &Apache::loncommon::start_data_table_header_row());
1.5 raeburn 3679: $r->print('
3680: <th>'.&mt('Active?').'</th>
3681: <th>'.&mt('Role').'</th>');
3682: if (@sections > 0) {
1.44 albertel 3683: $r->print('<th>'.&mt('Sections').'</th>');
1.3 raeburn 3684: }
1.44 albertel 3685: $r->print(&Apache::loncommon::end_data_table_header_row()."\n");
1.5 raeburn 3686: foreach my $role (@roles) {
1.58 raeburn 3687: my $roletitle=&Apache::lonnet::plaintext($role,$crstype);
3688: $r->print(&print_autorole_item($role,$roletitle,\@sections));
1.5 raeburn 3689: }
1.58 raeburn 3690: my @customs;
1.5 raeburn 3691: foreach my $role (sort(keys(%customroles))) {
1.58 raeburn 3692: my ($roletitle) = ($role =~ m|^cr/[^/]+/[^/]+/(.+)$|);
3693: push (@customs,$role);
3694: $r->print(&print_autorole_item($role,$roletitle,\@sections));
3695: }
3696: if ($action eq 'modify') {
3697: foreach my $role (@{$$stored{'autorole'}}) {
3698: if ((!grep(/^\Q$role\E$/,@customs)) &&
3699: (!grep(/^\Q$role\E$/,@roles))) {
3700: my $roletitle;
3701: if ($role =~ /^cr/) {
3702: ($roletitle) = ($role =~ m|_([^_]+)$|);
3703: } else {
3704: $roletitle = &Apache::lonnet::plaintext($role,$crstype);
3705: }
3706: $r->print(&print_autorole_item($role,$roletitle,\@sections));
3707: }
3708: }
1.5 raeburn 3709: }
1.44 albertel 3710: $r->print(&Apache::loncommon::end_data_table());
1.5 raeburn 3711: return;
3712: }
1.3 raeburn 3713:
1.58 raeburn 3714: sub print_autorole_item {
3715: my ($role,$roletitle,$sections) = @_;
3716: my $sections_sel;
3717: if (@{$sections} > 0) {
1.104 raeburn 3718: if (($role eq 'cc') || ($role eq 'co')) {
1.58 raeburn 3719: $sections_sel = '<td align="right">'.
3720: &mt('all sections').'<input type="hidden" '.
1.104 raeburn 3721: 'name="sec_'.$role.'" value="all" /></td>';
1.58 raeburn 3722: } else {
3723: $sections_sel='<td align="right">'.
3724: §ions_selection($sections,'sec_'.$role).
3725: '</td>';
3726: }
3727: }
3728: my $output = &Apache::loncommon::start_data_table_row().
3729: '<td><input type="checkbox" '.
3730: 'name="autorole" value="'.$role.'" />'.
3731: '</td><td>'.$roletitle.'</td>'.$sections_sel.
3732: &Apache::loncommon::end_data_table_row();
3733: return $output;
3734: }
3735:
1.5 raeburn 3736: sub standard_roles {
1.104 raeburn 3737: my ($crstype) = @_;
3738: my @roles = qw(in ta ep ad st);
3739: if ($crstype eq 'Community') {
3740: unshift(@roles,'co');
3741: } else {
3742: unshift(@roles,'cc');
3743: }
1.5 raeburn 3744: return @roles;
3745: }
3746:
3747: sub modify_menu {
1.29 raeburn 3748: my ($r,$groupname,$page,$gpterm) = @_;
1.5 raeburn 3749: my @menu =
1.106 wenzelju 3750: ( { categorytitle =>'Group Actions',
3751: items => [
3752:
3753: { linktext => "Modify default $gpterm settings",
3754: url => '/adm/coursegroups?action=modify&refpage='.$env{'form.refpage'}.'&groupname='.$groupname.'&state=change_settings&branch=settings',
3755: icon => 'grp_settings.png',
3756: alttext => "Modify default $gpterm settings",
3757: permission => '1',
3758: help => 'Course_Modify_Group',
1.5 raeburn 3759: },
1.106 wenzelju 3760: { linktext => 'Modify access, tools and privileges for members',
3761: url => '/adm/coursegroups?action=modify&refpage='.$env{'form.refpage'}.'&groupname='.$groupname.'&state=change_members&branch=members',
3762: icon => 'grp_tools.png',
3763: alttext => 'Modify access, tools and privileges for members',
3764: permission => '1',
1.5 raeburn 3765: help => 'Course_Modify_Group_Membership',
3766: },
1.106 wenzelju 3767: { linktext => "Add member(s) to the $gpterm",
3768: url => '/adm/coursegroups?action=modify&refpage='.$env{'form.refpage'}.'&groupname='.$groupname.'&state=add_members&branch=adds',
3769: icon => 'grp_add.png',
3770: alttext => "Add member(s) to the $gpterm",
3771: permission => '1',
1.5 raeburn 3772: help => 'Course_Group_Add_Members',
1.106 wenzelju 3773: }]}
3774: );
3775: $r->print(&Apache::lonhtmlcommon::generate_menu(@menu));
1.3 raeburn 3776: return;
3777: }
3778:
3779: sub member_privs_entries {
1.45 albertel 3780: my ($r,$usertools,$toolprivs,$fixedprivs,$userdata,$idx,$showtools,
3781: $defprivs,$excluded) = @_;
1.5 raeburn 3782: foreach my $user (sort(keys(%{$usertools}))) {
1.6 raeburn 3783: if (defined($excluded)) {
3784: if (ref($excluded) eq 'ARRAY') {
3785: if (grep/^$user$/,@{$excluded}) {
3786: next;
3787: }
3788: }
3789: }
1.5 raeburn 3790: my ($uname,$udom) = split(/:/,$user);
1.45 albertel 3791: $r->print(&Apache::loncommon::start_data_table_row().'
1.5 raeburn 3792: <td>'.$$userdata{$user}[$$idx{fullname}].'</td>
1.3 raeburn 3793: <td>'.$uname.'</td>
3794: <td>'.$udom.'</td>
1.53 raeburn 3795: <td valign="top">
3796: <table>
3797: <tr>
3798: <td><b>'.
3799: &mt('Collaborative Tool').'</b></td>
3800: </tr>
3801: <tr>
3802: <td><b>'.&mt('Fixed').'</b></td>
3803: </tr>
3804: <tr>
3805: <td><b>'.&mt('Optional').'</b></td>
3806: </tr>
3807: </table>
3808: </td>');
1.5 raeburn 3809: foreach my $tool (@{$showtools}) {
3810: if (exists($$usertools{$user}{$tool})) {
1.45 albertel 3811: $r->print('<td valign="top"><table><tr><th colspan="2">'.$tool.'</th></tr>');
1.3 raeburn 3812: my $privcount = 0;
3813: my $fixed = '';
3814: my $dynamic = '';
3815: foreach my $priv (sort(keys(%{$$toolprivs{$tool}}))) {
3816: if (exists($$fixedprivs{$tool}{$priv})) {
1.5 raeburn 3817: $fixed .= '<input type="hidden" name="userpriv_'.$priv.'" value="'.$user.'" />'.$$toolprivs{$tool}{$priv}.' ';
1.3 raeburn 3818: } else {
3819: $privcount ++;
3820: if ($privcount == 3) {
3821: $dynamic .= '</tr><tr>';
3822: }
1.83 bisitz 3823: $dynamic .='<td><span class="LC_nobreak"><label><input type="checkbox" '.
1.5 raeburn 3824: 'name="userpriv_'.$priv.'" value="'.$user.'"';
3825: if (grep/^\Q$priv\E$/,@{$defprivs}) {
3826: $dynamic .= ' checked="checked" ';
3827: }
3828: $dynamic .= ' />'.$$toolprivs{$tool}{$priv}.
1.83 bisitz 3829: '</label></span></td>';
1.3 raeburn 3830: }
3831: }
1.83 bisitz 3832: $r->print('<tr><td colspan="2"><span class="LC_nobreak">'.$fixed.'</span></td></tr><tr>'.$dynamic.'</tr></table></td>');
1.3 raeburn 3833: } else {
1.45 albertel 3834: $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 3835: }
3836: }
1.45 albertel 3837: $r->print(&Apache::loncommon::end_data_table_row());
1.3 raeburn 3838: }
3839: }
3840:
3841: sub get_dates_from_form {
3842: my $startdate;
3843: my $enddate;
3844: $startdate = &Apache::lonhtmlcommon::get_date_from_form('startdate');
3845: $enddate = &Apache::lonhtmlcommon::get_date_from_form('enddate');
3846: if ( exists ($env{'form.no_end_date'}) ) {
3847: $enddate = 0;
3848: }
3849: return ($startdate,$enddate);
1.5 raeburn 3850: }
3851:
1.3 raeburn 3852: sub date_setting_table {
3853: my ($starttime,$endtime,$formname) = @_;
3854: my $startform = &Apache::lonhtmlcommon::date_setter($formname,
3855: 'startdate',$starttime);
3856: my $endform = &Apache::lonhtmlcommon::date_setter($formname,
3857: 'enddate',$endtime);
1.98 bisitz 3858: my $perpetual = ' <span class="LC_nobreak"><label>'
3859: .'<input type="checkbox" name="no_end_date" />'
3860: .&mt('No end date')
3861: .'</label></span>';
3862: my $table = &Apache::lonhtmlcommon::start_pick_box()
3863: .&Apache::lonhtmlcommon::row_title(&mt('Start Date'))
3864: .$startform
3865: .&Apache::lonhtmlcommon::row_closure()
3866: .&Apache::lonhtmlcommon::row_title(&mt('End Date'))
3867: .$endform
3868: .$perpetual
3869: .&Apache::lonhtmlcommon::row_closure(1)
3870: .&Apache::lonhtmlcommon::end_pick_box();
1.41 albertel 3871: return $table;
1.1 raeburn 3872: }
3873:
1.32 raeburn 3874: sub add_group_folder {
3875: my ($cdom,$cnum,$now,$groupname,$action,$description,$tools,$groupinfo,
3876: $gpterm,$ucgpterm,$crstype) = @_;
3877: if ($cdom eq '' || $cnum eq '') {
1.104 raeburn 3878: my $error = '<span class="LC_error">';
3879: if ($crstype eq 'Community') {
3880: $error .= &mt("Error: invalid community domain or number - group folder creation failed.");
3881: } else {
3882: $error .= &mt("Error: invalid course domain or number - group folder creation failed.");
3883: }
3884: $error .= '</span>';
3885: return $error;
1.32 raeburn 3886: }
1.67 raeburn 3887: my ($outcome,$allgrpsmap,$grpmap,$boardsmap,$grppage,$warning);
1.32 raeburn 3888: my $crspath = '/uploaded/'.$cdom.'/'.$cnum.'/';
1.47 raeburn 3889: $allgrpsmap = $crspath.'group_allfolders.sequence';
1.32 raeburn 3890: if ($action eq 'create') {
1.67 raeburn 3891: if (&get_folder_lock($cdom,$cnum,'group_allfolders',$now) eq 'ok') {
3892: # check if group_allfolders.sequence exists.
1.69 raeburn 3893: my $mapcontents = &Apache::lonnet::getfile($allgrpsmap);
3894: if ($mapcontents eq '-1') { #file does not exist;
1.80 bisitz 3895: my $grpstitle = &mt("$crstype $ucgpterm".'s');
1.67 raeburn 3896: my $topmap_url = '/'.$env{'course.'.$env{'request.course.id'}.'.url'};
3897: $topmap_url =~ s|/+|/|g;
3898: if ($topmap_url =~ m|^/uploaded|) {
3899: $outcome = &map_updater($cdom,$cnum,'group_allfolders.sequence',
3900: 'toplevelgroup',$grpstitle,$topmap_url);
3901: } else {
1.80 bisitz 3902: $outcome = '<span class="LC_warning">'
3903: .&mt('Non-standard course - folder for all groups not added.')
3904: .'</span>';
1.67 raeburn 3905: }
1.32 raeburn 3906: if ($outcome ne 'ok') {
1.67 raeburn 3907: my $delresult = &release_folder_lock($cdom,$cnum,'group_allfolders');
3908: if ($delresult ne 'ok') {
3909: $warning = $delresult;
3910: }
1.84 raeburn 3911: return $outcome.$warning;
1.32 raeburn 3912: }
3913: }
1.67 raeburn 3914: my $delresult = &release_folder_lock($cdom,$cnum,'group_allfolders');
3915: if ($delresult ne 'ok') {
3916: $warning = $delresult ;
3917: }
3918: } else {
1.80 bisitz 3919: $outcome = '<span class="LC_error">'
3920: .&mt('Could not obtain exclusive lock to check status of the folder for all groups. No group folder added.')
1.84 raeburn 3921: .'</span>';
1.67 raeburn 3922: return $outcome;
1.32 raeburn 3923: }
1.75 bisitz 3924: my $grpfolder = &mt($ucgpterm.' Folder - [_1]',$description);
1.49 raeburn 3925: $grppage='/adm/'.$cdom.'/'.$cnum.'/'.$groupname.'/smppg';
1.75 bisitz 3926: my $grptitle = &mt('Group homepage - [_1]',$description);
1.55 raeburn 3927: my ($discussions,$disctitle);
1.47 raeburn 3928: my $outcome = &map_updater($cdom,$cnum,'group_folder_'.$groupname.'.sequence',
1.32 raeburn 3929: 'grpseq',$grpfolder,$allgrpsmap,$grppage,
3930: $grptitle);
3931: if ($outcome ne 'ok') {
1.67 raeburn 3932: return $outcome.$warning;
1.32 raeburn 3933: }
3934: my $pageout = &create_homepage($cdom,$cnum,$groupname,$groupinfo,
3935: $tools,$gpterm,$ucgpterm,$now);
3936: # Link to folder for bulletin boards
1.47 raeburn 3937: $grpmap = $crspath.'group_folder_'.$groupname.'.sequence';
1.32 raeburn 3938: if (grep/^discussion$/,@{$tools}) {
3939: $disctitle = &mt('Discussion Boards');
1.47 raeburn 3940: my $outcome = &map_updater($cdom,$cnum,'group_boards_'.$groupname.
1.32 raeburn 3941: '.sequence','bbseq',$disctitle,$grpmap);
3942: if ($outcome ne 'ok') {
1.67 raeburn 3943: return $outcome.$warning;
1.32 raeburn 3944: }
1.47 raeburn 3945: $boardsmap = $crspath.'group_boards_'.$groupname.'.sequence';
1.32 raeburn 3946: }
3947: } else {
3948: #modify group folder if status of discussions tools is changed
3949: }
3950: my ($furl,$ferr)= &Apache::lonuserstate::readmap($cdom.'/'.$cnum);
1.67 raeburn 3951: my $navmap = Apache::lonnavmaps::navmap->new();
1.85 raeburn 3952: if (!defined($navmap)) {
1.104 raeburn 3953: $warning .= '<span class="LC_error">';
3954: if ($crstype eq 'Community') {
3955: $warning .= &mt("Error retrieving community contents").
3956: ' '.&mt("You need to re-initialize the community.");
3957: } else {
3958: $warning .= &mt("Error retrieving course contents").
3959: ' '.&mt("You need to re-initialize the course.");
3960: }
3961: $warning .= '</span>';
3962: return $warning;
1.85 raeburn 3963: }
1.32 raeburn 3964: # modify parameters
3965: my $parm_result;
3966: if ($action eq 'create') {
3967: if ($grpmap) {
3968: $parm_result .= &parm_setter($navmap,$cdom,$grpmap,$groupname);
3969: }
3970: if ($grppage) {
3971: $parm_result .= &parm_setter($navmap,$cdom,$grppage,$groupname);
3972: }
3973: if ($boardsmap) {
3974: $parm_result .= &parm_setter($navmap,$cdom,$boardsmap,$groupname);
3975: }
3976: }
1.67 raeburn 3977: undef($navmap);
1.32 raeburn 3978: if ($parm_result) {
1.67 raeburn 3979: return $warning.$parm_result;
3980: } else {
3981: return 'ok';
3982: }
3983: }
3984:
3985: sub get_folder_lock {
3986: my ($cdom,$cnum,$folder_name,$now) = @_;
3987: # get lock for folder being edited.
3988: my $lockhash = {
3989: $folder_name."\0".'locked_folder' => $now.':'.$env{'user.name'}.
3990: ':'.$env{'user.domain'},
3991: };
3992: my $tries = 0;
3993: my $gotlock = &Apache::lonnet::newput('coursegroups',$lockhash,$cdom,$cnum);
3994:
3995: while (($gotlock ne 'ok') && $tries <3) {
3996: $tries ++;
1.68 albertel 3997: sleep(1);
1.67 raeburn 3998: $gotlock = &Apache::lonnet::newput('coursegroups',$lockhash,$cdom,$cnum);
3999: }
4000: return $gotlock;
4001: }
4002:
4003: sub release_folder_lock {
4004: my ($cdom,$cnum,$folder_name) = @_;
4005: # remove lock
4006: my @del_lock = ($folder_name."\0".'locked_folder');
4007: my $dellockoutcome=&Apache::lonnet::del('coursegroups',\@del_lock,$cdom,$cnum);
4008: if ($dellockoutcome ne 'ok') {
1.80 bisitz 4009: return ('<div class="LC_error">'
4010: .&mt('Warning: failed to release lock for folder: [_1].','<tt>'.$folder_name.'</tt>')
4011: .'</div>'
4012: );
1.32 raeburn 4013: } else {
4014: return 'ok';
4015: }
4016: }
4017:
4018: sub map_updater {
4019: my ($cdom,$cnum,$newfile,$itemname,$itemtitle,$parentmap,$startsrc,
4020: $starttitle,$endsrc,$endtitle) = @_;
4021: my $outcome;
4022: $env{'form.'.$itemname} = &new_map($startsrc,$starttitle,$endsrc,
4023: $endtitle);
4024: my $newmapurl=&Apache::lonnet::finishuserfileupload($cnum,$cdom,$itemname,
4025: $newfile);
4026: if ($newmapurl !~ m|^/uploaded|) {
1.80 bisitz 4027: $outcome = '<div class="LC_error">'
4028: .&mt('Error uploading new folder.')." ($newfile): $newmapurl"
4029: .'</div>';
1.32 raeburn 4030: return $outcome;
1.67 raeburn 4031: }
1.63 albertel 4032: my ($errtext,$fatal)=&LONCAPA::map::mapread($parentmap);
1.32 raeburn 4033: if ($fatal) {
1.80 bisitz 4034: $outcome = '<div class="LC_error">'
4035: .&mt('Error reading contents of parent folder.')." ($parentmap): $errtext"
4036: .'</div>';
1.32 raeburn 4037: return $outcome;
4038: } else {
1.63 albertel 4039: my $newidx=&LONCAPA::map::getresidx($newmapurl);
4040: $LONCAPA::map::resources[$newidx] = $itemtitle.':'.$newmapurl.
1.32 raeburn 4041: ':false:normal:res';
1.63 albertel 4042: $LONCAPA::map::order[1+$#LONCAPA::map::order]=$newidx;
1.114 raeburn 4043: my ($outtext,$errtext) = &LONCAPA::map::storemap($parentmap,1,1);
1.67 raeburn 4044: if ($errtext) {
1.80 bisitz 4045: $outcome = '<div class="LC_error">'
4046: .&mt('Error saving updated parent folder.')." ($parentmap): $errtext"
4047: .'</div>';
1.32 raeburn 4048: return $outcome;
4049: }
4050: }
4051: return 'ok';
4052: }
4053:
4054: sub new_map {
4055: my ($startsrc,$starttitle,$endsrc,$endtitle) = @_;
4056: my $newmapstr = '
4057: <map>
4058: <resource id="1" src="'.$startsrc.'" type="start" title="'.$starttitle.'"></resource>
4059: <link from="1" to="2" index="1"></link>
4060: <resource id="2" src="'.$endsrc.'" type="finish" title="'.$endtitle.'"></resource>
4061: </map>
4062: ';
4063: return $newmapstr;
4064: }
4065:
4066: sub parm_setter {
1.104 raeburn 4067: my ($navmap,$cdom,$url,$groupname,$crstype) = @_;
1.85 raeburn 4068: if (!defined($navmap)) {
1.104 raeburn 4069: my $allresults;
4070: if ($crstype eq 'Community') {
4071: $allresults = &mt("Parameters not set for [_1] because the contents of the community could not be retrieved.",$url).' '.
4072: &mt("You need to reinitialize the community.");
4073: } else {
4074: $allresults = &mt("Parameters not set for [_1] because the contents of the course could not be retrieved.",$url).' '.
4075: &mt("You need to reinitialize the course.");
4076:
4077: }
4078: return '<div class="LC_warning">'.$allresults.'</div>';
1.85 raeburn 4079: }
1.32 raeburn 4080: my %hide_settings = (
4081: 'course' => {
4082: 'num' => 13,
4083: 'set' => 'yes',
4084: },
4085: 'group' => {
4086: 'num' => 5,
4087: 'set' => 'no',
4088: 'extra' => $groupname,
4089: },
4090: );
4091: my $res = $navmap->getResourceByUrl($url);
1.104 raeburn 4092: my $allresults;
1.67 raeburn 4093: if ($res) {
4094: my $symb = $res->symb();
4095: foreach my $level (keys(%hide_settings)) {
4096: my $parmresult =
4097: &Apache::lonparmset::storeparm_by_symb($symb,
1.32 raeburn 4098: '0_hiddenresource',
4099: $hide_settings{$level}{'num'},
4100: $hide_settings{$level}{'set'},
4101: 'string_yesno',undef,$cdom,
4102: undef,undef,
4103: $hide_settings{$level}{'extra'});
1.67 raeburn 4104: if ($parmresult) {
4105: $allresults .= $level.': '.$parmresult;
4106: }
1.37 raeburn 4107: }
1.67 raeburn 4108: } else {
1.104 raeburn 4109: $allresults = '<div class="LC_warning">';
4110: if ($crstype eq 'Community') {
4111: $allresults .= &mt("Parameters not set for [_1] because the resource was not recognized as part of the community.",'<tt>'.$url.'</tt>');
4112: } else {
4113: $allresults .= &mt('Parameters not set for [_1] because the resource was not recognized as part of the course.','<tt>'.$url.'</tt>');
4114: }
4115: $allresults .= '</div>';
1.32 raeburn 4116: }
1.37 raeburn 4117: return $allresults;
1.32 raeburn 4118: }
4119:
1.3 raeburn 4120: sub create_homepage {
1.32 raeburn 4121: my ($cdom,$cnum,$name,$groupinfo,$tools,$gpterm,$ucgpterm,$now) = @_;
1.3 raeburn 4122: my $functionality = join(',',@{$tools});
1.24 www 4123: my $content = &unescape($$groupinfo{description});
1.121 raeburn 4124: chomp($content);
4125: my $gateway = Apache::lonhtmlgateway->new();
4126: $content = $gateway->process_incoming_html($content,1);
1.3 raeburn 4127:
4128: my %pageinfo = (
1.29 raeburn 4129: 'aaa_title' => "$ucgpterm: $name",
1.3 raeburn 4130: 'abb_links' => $functionality,
4131: 'bbb_content' => $content,
4132: 'ccc_webreferences' => '',
1.32 raeburn 4133: 'uploaded.lastmodified' => $now,
1.3 raeburn 4134: );
4135: my $putresult = &Apache::lonnet::put('grppage_'.$name,\%pageinfo,$cdom,$cnum);
4136: return $putresult;
1.1 raeburn 4137: }
4138:
1.5 raeburn 4139: sub check_uncheck_tools {
4140: my ($r,$available) = @_;
4141: if (ref($available) eq 'ARRAY') {
4142: $r->print('
4143: <script type="text/javascript">
4144: function checkAllTools(formname) {
4145: ');
4146: foreach my $tool (@{$available}) {
4147: $r->print(' checkAll(formname.user_'.$tool.');'."\n");
4148: }
4149: $r->print(' checkAll(formname.togglefunc);'."\n");
4150: $r->print('
4151: }
4152: function uncheckAllTools(formname) {
4153: ');
4154: foreach my $tool (@{$available}) {
4155: $r->print(' uncheckAll(formname.user_'.$tool.');'."\n");
4156: }
4157: $r->print(' uncheckAll(formname.togglefunc);'."\n");
4158: $r->print('
4159: }
4160: function toggleTools(field,caller) {
4161: if (caller.checked) {
4162: checkAll(field);
4163: } else {
4164: uncheckAll(field);
4165: }
4166: return;
4167: }
4168: </script>
4169: ');
4170: }
4171: return;
4172: }
4173:
4174: sub validate_groupname {
1.29 raeburn 4175: my ($groupname,$action,$cdom,$cnum,$gpterm,$ucgpterm,$crstype) = @_;
1.16 albertel 4176: my %sectioncount = &Apache::loncommon::get_sections($cdom,$cnum);
1.17 raeburn 4177: my %curr_groups = &Apache::longroup::coursegroups($cdom,$cnum);
1.65 raeburn 4178: my %deleted_groups = &Apache::longroup::coursegroups($cdom,$cnum,undef,
4179: 'deleted_groups');
1.64 raeburn 4180: if (my $tmp = &Apache::lonnet::error(%deleted_groups)) {
4181: undef(%deleted_groups);
4182: &Apache::lonnet::logthis('Error retrieving groups: '.$tmp.' in '.$cnum.':'.$cdom);
4183: }
1.5 raeburn 4184: my %lt = &Apache::lonlocal::texthash (
1.29 raeburn 4185: igna => "Invalid $gpterm name",
4186: tgne => "The $gpterm name entered ",
4187: grna => "$ucgpterm names and section names used in a ".
4188: "$crstype must be unique.",
4189: isno => "is not a valid name.",
4190: gnmo => "$ucgpterm names may only contain letters, ".
4191: "numbers or underscores.",
4192: cnnb => "can not be used as it is the name of ",
4193: inth => " in this $crstype",
4194: thgr => "- does not correspond to the name of an ".
4195: "existing $gpterm",
1.5 raeburn 4196: );
1.15 albertel 4197:
1.42 albertel 4198: my $exitmsg = '<span class="LC_error">'.$lt{'igna'}.'</span><br /><br />'.
4199: $lt{'tgne'}.' "'.$groupname.'" ';
1.5 raeburn 4200: my $dupmsg = $lt{'grna'};
4201: my $earlyout;
4202: if (($groupname eq '') || ($groupname =~ /\W/)) {
4203: $earlyout = $exitmsg.$lt{'isno'}.'<br />'.$lt{'gnmo'};
4204: return $earlyout;
4205: }
1.16 albertel 4206: if (exists($sectioncount{$groupname})) {
4207: return $exitmsg.$lt{'cnnb'}.&mt('a section').$lt{'inth'}.
4208: '<br />'.$lt{'grna'};
1.5 raeburn 4209: }
1.64 raeburn 4210: if ($action eq 'create') {
4211: if (exists($curr_groups{$groupname})) {
1.119 raeburn 4212: return $exitmsg.$lt{'cnnb'}.&mt("an existing $gpterm").
1.64 raeburn 4213: $lt{'inth'}.'.<br />'.$lt{'grna'};
4214: } elsif (exists($deleted_groups{$groupname})) {
1.119 raeburn 4215: return $exitmsg.$lt{'cnnb'}.&mt("a $gpterm which previously existed").
1.64 raeburn 4216: $lt{'inth'}.'.<br />'.$lt{'grna'};
4217: }
1.5 raeburn 4218: } elsif ($action eq 'modify') {
4219: unless(exists($curr_groups{$groupname})) {
1.119 raeburn 4220: $earlyout = &mt("$ucgpterm name:").' '.$groupname.$lt{'thgr'}.
1.29 raeburn 4221: $lt{'inth'};
1.5 raeburn 4222: return $earlyout;
4223: }
4224: }
4225: return;
4226: }
4227:
4228: sub check_changes {
4229: my ($member_changes,$memchg) = @_;
4230: my %exclusions;
4231: @{$exclusions{'changefunc'}} = ('expire');
4232: @{$exclusions{'changepriv'}} = ('expire','changefunc');
4233:
4234: foreach my $change (@{$member_changes}) {
1.6 raeburn 4235: if ($change eq 'deletion') {
1.5 raeburn 4236: next;
4237: }
1.6 raeburn 4238: my @checks = ('deletion');
1.5 raeburn 4239: if (exists($exclusions{$change})) {
4240: push(@checks,@{$exclusions{$change}});
4241: }
4242: my @temp = ();
4243: foreach my $item (@{$$memchg{$change}}) {
4244: my $match = 0;
4245: foreach my $check (@checks) {
1.6 raeburn 4246: if (defined($$memchg{$check})) {
4247: if (ref(@{$$memchg{$check}}) eq 'ARRAY') {
4248: if (@{$$memchg{$check}} > 0) {
4249: if (grep/^$item$/,@{$$memchg{$check}}) {
4250: $match = 1;
4251: last;
4252: }
4253: }
1.5 raeburn 4254: }
4255: }
4256: }
4257: if ($match) {
4258: next;
4259: }
4260: push(@temp,$item);
4261: }
4262: @{$$memchg{$change}} = @temp;
4263: }
4264: }
1.3 raeburn 4265:
1.1 raeburn 4266: 1;
1.106 wenzelju 4267:
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>