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