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