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