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