Annotation of loncom/interface/loncoursegroups.pm, revision 1.112
1.24 www 1: # The LearningOnline Network with CAPA
2: #
1.112 ! raeburn 3: # $Id: loncoursegroups.pm,v 1.111 2010/08/29 22:59:49 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.74 raeburn 1550: my @dir_list=&Apache::portfolio::get_dir_list($portpath,undef,$group);
1.29 raeburn 1551: foreach my $line (@dir_list) {
1552: my ($filename,$dom,undef,$testdir,undef,undef,undef,undef,$size,undef,$mtime,undef,undef,undef,$obs,undef)=split(/\&/,$line,16);
1553: if (($filename !~ /^\.\.?$/) && ($filename !~ /\.meta$/ ) && ($filename !~ /(.*)\.(\d+)\.([^\.]*)$/) && ($filename ne 'no_such_dir')) {
1554: if ($dirptr&$testdir) {
1.74 raeburn 1555: $portpath .= '/'.$filename;
1.29 raeburn 1556: $$numdirs ++;
1.74 raeburn 1557: &group_files($group,$portpath,$numfiles,$numdirs)
1.29 raeburn 1558: } else {
1559: $$numfiles ++;
1560: }
1561: }
1562: }
1.3 raeburn 1563: return;
1564: }
1565:
1566: sub group_members {
1.4 raeburn 1567: my ($cdom,$cnum,$group,$group_info) = @_;
1568: my %memberhash = &Apache::lonnet::get_group_membership($cdom,$cnum,$group);
1569: my $now = time;
1.60 raeburn 1570: my %lt = &Apache::lonlocal::texthash (
1571: active => 'active',
1572: previous => 'previous',
1573: future => 'future',
1574: );
1575: my %membercounts = (
1576: active => 0,
1577: previous => 0,
1578: future => 0,
1579: );
1.4 raeburn 1580: my $totalmembers = 0;
1581: foreach my $member (keys %memberhash) {
1582: $totalmembers ++;
1583: my ($end,$start) = split(/:/,$memberhash{$member});
1.6 raeburn 1584: unless ($start == -1) {
1585: if (($end!=0) && ($end<$now)) {
1.60 raeburn 1586: $membercounts{previous} ++;
1.6 raeburn 1587: } elsif (($start!=0) && ($start>$now)) {
1.60 raeburn 1588: $membercounts{future} ++;
1.6 raeburn 1589: } else {
1.60 raeburn 1590: $membercounts{active} ++;
1.6 raeburn 1591: }
1.4 raeburn 1592: }
1593: }
1594: if ($totalmembers == 0) {
1595: $$group_info{$group}{'totalmembers'} = 'None';
1596: } else {
1.60 raeburn 1597: foreach my $type ('active','previous','future') {
1598: $$group_info{$group}{'totalmembers'} .=
1599: &open_list_window($group,$type,$membercounts{$type},$lt{$type});
1600: }
1.4 raeburn 1601: }
1602: return 'ok';
1.3 raeburn 1603: }
1604:
1.60 raeburn 1605: sub open_list_window {
1606: my ($group,$status,$count,$text) = @_;
1607: my $entry;
1608: if ($count > 0) {
1.83 bisitz 1609: $entry = '<span class="LC_nobreak"><a href="javascript:openGroupRoster('.
1.60 raeburn 1610: "'$group','$status'".')">'.$text.'</a> - '.$count.
1.83 bisitz 1611: '</span><br />';
1.60 raeburn 1612: } else {
1.83 bisitz 1613: $entry = '<span class="LC_nobreak">'.$text.' - '.$count.'</span><br />';
1.60 raeburn 1614: }
1615: return $entry;
1616: }
1617:
1.3 raeburn 1618:
1.5 raeburn 1619: sub general_settings_form {
1.46 albertel 1620: my ($r,$cdom,$cnum,$action,$formname,$page,$functions,$tools,
1.5 raeburn 1621: $toolprivs,$fixedprivs,$sectioncount,$stored,$states,$navbuttons,
1.46 albertel 1622: $gpterm,$ucgpterm,$crstype) = @_;
1.5 raeburn 1623: my ($nexttext,$prevtext);
1.42 albertel 1624: &groupsettings_options($r,$functions,$action,$formname,$stored,1,
1.29 raeburn 1625: $gpterm,$ucgpterm,$crstype);
1.41 albertel 1626: &access_date_settings($r,$action,$formname,$stored,2,$gpterm,$ucgpterm);
1.5 raeburn 1627: if ($action eq 'create') {
1.59 raeburn 1628: &membership_options($r,$cdom,$cnum,$action,$formname,$sectioncount,3,
1.104 raeburn 1629: $gpterm,$ucgpterm,$crstype);
1.5 raeburn 1630: $nexttext = $$navbuttons{'gtns'};
1631: } else {
1632: my @available = ();
1633: my @unavailable = ();
1634: &check_tools($functions,$tools,\@available,\@unavailable);
1635: @{$tools} = sort(keys(%{$functions}));
1.46 albertel 1636: &privilege_specificity($r,$action,3,$tools,$stored,$toolprivs,
1637: $fixedprivs,\@available,$formname,
1.104 raeburn 1638: $gpterm,$ucgpterm,$functions,$crstype);
1.44 albertel 1639: &mapping_options($r,$action,$formname,$page,$sectioncount,
1640: $states,$stored,$navbuttons,4,5,
1.58 raeburn 1641: $gpterm,$ucgpterm,$crstype,$cdom,$cnum);
1.5 raeburn 1642: $nexttext = $$navbuttons{'mose'};
1643: }
1644: $prevtext = $$navbuttons{'gtpp'};
1645: &display_navbuttons($r,$formname,$$states{$action}[$page-1],$prevtext,
1646: $$states{$action}[$page+1],$nexttext);
1647: return;
1648: }
1649:
1650: sub groupsettings_options {
1.42 albertel 1651: my ($r,$functions,$action,$formname,$stored,$image,$gpterm,
1.29 raeburn 1652: $ucgpterm,$crstype) = @_;
1.1 raeburn 1653: my %lt = &Apache::lonlocal::texthash(
1.53 raeburn 1654: 'gdat' => "Group access start and end dates",
1655: 'gnde' => "Group name, title and available collaborative tools",
1656: 'desc' => 'Group Title',
1657: 'func' => 'Collaborative Tools',
1658: 'gnam' => 'Group Name',
1659: 'lett' => 'Letters, numbers and underscore only',
1660: 'doyo' => 'Different subsets of the chosen collaborative tools '.
1661: 'for different group members?',
1.97 bisitz 1662: 'gran' => 'Granularity',
1663: 'dquo' => 'Disk quota',
1.1 raeburn 1664: );
1.37 raeburn 1665: my ($crsquota,$freespace,$maxposs) = &get_quota_constraints($action,$stored);
1.97 bisitz 1666: $r->print(&Apache::lonhtmlcommon::topic_bar($image,$lt{'gnde'}));
1667:
1668: # Group Name
1669: $r->print(&Apache::lonhtmlcommon::start_pick_box()
1670: .&Apache::lonhtmlcommon::row_title($lt{'gnam'})
1671: );
1.5 raeburn 1672: if ($action eq 'create') {
1.97 bisitz 1673: $r->print('<input type="text" name="groupname" size="25" />'
1674: .' <span class="LC_nobreak">('
1675: .$lt{'lett'}.')</span>'
1676: );
1.5 raeburn 1677: } else {
1678: $r->print('<input type="hidden" name="groupname" value="'.
1679: $env{'form.groupname'}.'" />'.$env{'form.groupname'});
1680: }
1.97 bisitz 1681: $r->print(&Apache::lonhtmlcommon::row_closure());
1682:
1683: # Group Title
1684: $r->print(&Apache::lonhtmlcommon::row_title($lt{'desc'})
1685: .'<input type="text" name="description" size="40" value="" />'
1686: .&Apache::lonhtmlcommon::row_closure()
1687: );
1688:
1689: # Collaborative Tools
1.3 raeburn 1690: my $numitems = keys(%{$functions});
1691: my $halfnum = int($numitems/2);
1692: my $remnum = $numitems%2;
1693: if ($remnum) {
1694: $halfnum ++;
1695: }
1.5 raeburn 1696: my @allfunctions = sort(keys (%{$functions}));
1.97 bisitz 1697:
1698: $r->print(&Apache::lonhtmlcommon::row_title($lt{'func'})
1699: .'<div>'
1700: .'<input type="button" value="'.&mt('check all').'"'
1701: .' onclick="javascript:checkAll(document.'.$formname.'.tool)" />'
1702: .' <input type="button" value="'.&mt('uncheck all').'"'
1703: .' onclick="javascript:uncheckAll(document.'.$formname.'.tool)" />'
1704: .'</div>'
1705: .'<table cellpadding="5px"><tr>' # FIXME Get rid of inflexible table (-> float)
1706: );
1707: for (my $i=0; $i<@allfunctions; $i++) {
1708: $r->print('<td><label><span class="LC_nobreak">'
1709: .'<input type="checkbox" name="tool" value="'
1710: .$allfunctions[$i].'" /> '
1711: .&mt($$functions{$allfunctions[$i]})
1712: .'</span></label></td>'
1713: );
1714: if ($i == $halfnum - 1) {
1715: $r->print('</tr><tr>');
1716: }
1.3 raeburn 1717: }
1.97 bisitz 1718: $r->print('</tr></table>'
1719: .&Apache::lonhtmlcommon::row_closure()
1720: );
1721:
1722: # Granularity
1723: $r->print(&Apache::lonhtmlcommon::row_title($lt{'gran'})
1724: .$lt{'doyo'}.'<br />'
1725: .'<label>'
1726: .'<input type="radio" name="granularity" value="Yes" />'.&mt('Yes')
1727: .'</label> <label>'
1728: .'<input type="radio" name="granularity" value="No" checked="checked" />'.&mt('No')
1729: .'</label>'
1730: );
1.5 raeburn 1731: if ($action eq 'modify') {
1.97 bisitz 1732: $r->print(' <span class="LC_nobreak">('
1733: .&mt('Currently set to [_1].'
1734: ,'"'.&mt($$stored{'granularity'}).'"')
1735: .')</span>'
1736: );
1.5 raeburn 1737: }
1.97 bisitz 1738: $r->print(&Apache::lonhtmlcommon::row_closure());
1739:
1740: # Disk Quota
1741: $r->print(&Apache::lonhtmlcommon::row_title($lt{'dquo'}));
1.29 raeburn 1742: if ($action eq 'create') {
1.97 bisitz 1743: $r->print('<span class="LC_info">'
1744: .&mt('If you enable the group portfolio for the '.$gpterm
1745: .', allocate a disk quota.')
1746: .'</span>'
1747: );
1.29 raeburn 1748: } else {
1.96 weissno 1749: $r->print(&mt('Quota allocated to group portfolio:'));
1.29 raeburn 1750: }
1.97 bisitz 1751: $r->print(' '.&mt('[_1] Mb','<input type="text" name="quota" size="4" />'));
1.29 raeburn 1752: if ($action eq 'create') {
1.79 bisitz 1753: $r->print('<br />'
1754: .&mt('A total of [_1] Mb can be divided amongst all '.$gpterm.'s in the '
1755: .lc($crstype).', and [_2] Mb are currently unallocated.'
1756: ,$crsquota,sprintf("%.2f",$freespace))
1757: );
1.29 raeburn 1758: } else {
1759: $r->print(' ('.&mt('The quota is currently [_1] Mb',
1760: $$stored{'quota'}).').');
1761:
1.79 bisitz 1762: $r->print('<br />'
1763: .&mt('The quota can be increased to [_1] Mb, '
1764: .'by adding all unallocated space for '.$gpterm.'s in the '.lc($crstype).'.'
1765: ,sprintf("%.2f",$maxposs)));
1.29 raeburn 1766: }
1.97 bisitz 1767: $r->print(&Apache::lonhtmlcommon::row_closure(1));
1768:
1769: $r->print(&Apache::lonhtmlcommon::end_pick_box());
1770:
1.5 raeburn 1771: return;
1772: }
1773:
1.37 raeburn 1774: sub get_quota_constraints {
1775: my ($action,$stored) = @_;
1776: my ($crsquota,$freespace,$maxposs);
1777: $crsquota = $env{'course.'.$env{'request.course.id'}.'.internal.coursequota'};
1778: if ($crsquota eq '') {
1779: $crsquota = 20;
1780: }
1781: $freespace = $crsquota - &Apache::longroup::sum_quotas();
1782: if ($action eq 'create') {
1783: $maxposs = $freespace;
1784: } else {
1785: $maxposs = $$stored{'quota'} + $freespace;
1786: }
1787: return ($crsquota,$freespace,$maxposs);
1788: }
1789:
1.5 raeburn 1790: sub membership_options {
1.104 raeburn 1791: my ($r,$cdom,$cnum,$action,$state,$sectioncount,$image,$gpterm,$ucgpterm,$crstype)=@_;
1.5 raeburn 1792: my %lt = &Apache::lonlocal::texthash(
1.53 raeburn 1793: 'pipa' => 'Build a list of users for selection of group members',
1.104 raeburn 1794: 'gmem' => 'Group membership selection list criteria:',
1795: 'picr' => 'Pick the criteria to use to build a list of course users from which you will select members of the new group.',
1796: 'pica' => 'Pick the criteria to use to build a list of course users from which you will select additional members of the group.',
1797: '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 1798: 'acty' => 'Access types',
1.104 raeburn 1799: 'coro' => 'Course roles',
1800: 'cose' => 'Course sections',
1.5 raeburn 1801: );
1.104 raeburn 1802: if ($crstype eq 'Community') {
1803: $lt{'picr'} = &mt('Pick the criteria to use to build a list of community participants from which you will select ');
1804: $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>');
1805: $lt{'coro'} = &mt('Community roles');
1806: $lt{'cose'} = &mt('Community sections');
1807: } else {
1808: $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>');
1809: }
1.5 raeburn 1810: my %status_types = (
1811: active => &mt('Currently has access'),
1812: previous => &mt('Previously had access'),
1813: future => &mt('Will have future access'),
1814: );
1.15 albertel 1815:
1.104 raeburn 1816: my @roles = ('st');
1817: if ($crstype eq 'Community') {
1818: push(@roles,'co');
1819: } else {
1820: push(@roles,'cc');
1821: }
1822: push (@roles,('in','ta','ep','ad','cr'));
1.5 raeburn 1823:
1824: my @sections = keys(%{$sectioncount});
1825:
1.78 raeburn 1826: $r->print(&Apache::lonhtmlcommon::topic_bar($image,$lt{'pipa'}).'
1.104 raeburn 1827: <b>'.$lt{'gmem'}.'</b><br />');
1.5 raeburn 1828: if ($action eq 'create') {
1.104 raeburn 1829: $r->print($lt{'picr'}.'<br />'.$lt{'ifno'}.'<br />'.$lt{'asub'});
1.5 raeburn 1830: } else {
1.104 raeburn 1831: $r->print($lt{'pica'});
1.5 raeburn 1832: }
1833: $r->print('
1834: <br />
1835: <br />
1.40 albertel 1836: <table class="LC_status_selector">
1.3 raeburn 1837: <tr>
1.40 albertel 1838: <th>'.$lt{'acty'}.'</th>
1.53 raeburn 1839: <th>'.$lt{'coro'}.'</th>
1840: <th>'.$lt{'cose'}.'</th>
1841: </tr><tr><td>');
1.3 raeburn 1842: $r->print(&Apache::lonhtmlcommon::status_select_row(\%status_types));
1.40 albertel 1843: $r->print('</td><td>');
1.59 raeburn 1844: $r->print(&Apache::lonhtmlcommon::role_select_row(\@roles,undef,undef,1,$cdom,$cnum));
1.3 raeburn 1845: if (@sections > 0) {
1.5 raeburn 1846: @sections = sort {$a cmp $b} @sections;
1.31 albertel 1847: unshift(@sections,'none'); # Put 'no sections' next
1.17 raeburn 1848: unshift(@sections,'all'); # Put 'all' at the front of the list
1.53 raeburn 1849: } else {
1850: @sections = ('all','none');
1.3 raeburn 1851: }
1.53 raeburn 1852: $r->print('</td><td>'.
1853: §ions_selection(\@sections,'sectionpick').'</td>
1.3 raeburn 1854: </tr>
1.40 albertel 1855: </table>');
1.5 raeburn 1856: return;
1857: }
1858:
1859: sub sections_selection {
1860: my ($sections,$elementname) = @_;
1861: my $section_sel;
1862: my $numvisible = 4;
1863: if (@{$sections} < 4) {
1864: $numvisible = @{$sections};
1865: }
1866: foreach my $sec (@{$sections}) {
1.17 raeburn 1867: if ($sec eq 'all') {
1.53 raeburn 1868: $section_sel .= ' <option value="'.$sec.'">'.&mt('all sections').'</option>'."\n";
1.17 raeburn 1869: } elsif ($sec eq 'none') {
1.31 albertel 1870: $section_sel .= ' <option value="'.$sec.'">'.&mt('no section').'</option>'."\n";
1.5 raeburn 1871: } else {
1.31 albertel 1872: $section_sel .= ' <option value="'.$sec.'">'.$sec."</option>\n";
1.5 raeburn 1873: }
1874: }
1875: my $output = '
1.89 bisitz 1876: <select name="'.$elementname.'" multiple="multiple" size="'.$numvisible.'">
1.5 raeburn 1877: '.$section_sel.'
1878: </select>';
1879: return $output;
1880: }
1881:
1882: sub access_date_settings {
1.41 albertel 1883: my ($r,$action,$formname,$stored,$image,$gpterm,$ucgpterm) = @_;
1.80 bisitz 1884: my $sten = &mt("Default start and end dates for $gpterm access");
1.5 raeburn 1885: my $starttime = time;
1886: my $endtime = time+(6*30*24*60*60); # 6 months from now, approx
1887: if ($action eq 'modify') {
1888: $starttime = $$stored{'startdate'};
1889: unless ($$stored{'enddate'} == 0) {
1890: $endtime = $$stored{'enddate'};
1891: }
1892: }
1.41 albertel 1893: my ($table) = &date_setting_table($starttime,$endtime,$formname);
1.80 bisitz 1894: $r->print(&Apache::lonhtmlcommon::topic_bar($image,$sten).'
1.41 albertel 1895: '.$table.'
1896: ');
1.3 raeburn 1897: return;
1898: }
1899:
1.5 raeburn 1900: sub choose_members_form {
1.46 albertel 1901: my ($r,$cdom,$cnum,$action,$formname,$page,$groupname,$description,
1.29 raeburn 1902: $granularity,$quota,$startdate,$enddate,$tools,$fixedprivs,$toolprivs,
1.5 raeburn 1903: $functions,$users,$userdata,$idx,$stored,$states,$navbuttons,
1.46 albertel 1904: $gpterm,$ucgpterm,$crstype) = @_;
1.5 raeburn 1905: my @regexps = ('user_','userpriv_','sec_');
1906: my %origmembers;
1.3 raeburn 1907: $r->print(&Apache::lonhtmlcommon::echo_form_input(
1.5 raeburn 1908: ['origin','action','state','page','member','specificity','branch',
1.7 raeburn 1909: 'defpriv','autorole','autoadd','autodrop','sortby','togglefunc'],
1.5 raeburn 1910: \@regexps));
1.29 raeburn 1911: my $earlyout = &validate_groupname($groupname,$action,$cdom,$cnum,$gpterm,
1912: $ucgpterm,$crstype);
1.5 raeburn 1913: if ($earlyout) {
1.47 raeburn 1914: $r->print($earlyout);
1.5 raeburn 1915: &display_navbuttons($r,$formname,$$states{$action}[$page-1],
1916: $$navbuttons{'gtps'});
1.3 raeburn 1917: return;
1.5 raeburn 1918: }
1919: my ($specimg,$memimg);
1920: my @available = ();
1921: my @unavailable = ();
1922: &check_tools($functions,$tools,\@available,\@unavailable);
1923: if ($action eq 'create') {
1.40 albertel 1924: &print_current_settings($r,$action,$functions,$startdate,$enddate,
1925: $groupname,$description,$granularity,$quota,
1926: \@available,\@unavailable,$gpterm,$ucgpterm);
1.5 raeburn 1927: $specimg = 4;
1928: $memimg = 5;
1929: } else {
1930: $specimg = 2;
1931: $memimg = 3;
1932: my %membership = &Apache::lonnet::get_group_membership($cdom,$cnum,
1933: $groupname);
1934: foreach my $key (sort(keys(%membership))) {
1935: if ($key =~ /^\Q$groupname\E:([^:]+):([^:]+)$/) {
1.6 raeburn 1936: my ($end,$start,@userprivs) = split(/:/,$membership{$key});
1937: unless ($start == -1) {
1938: my $uname = $1;
1939: my $udom = $2;
1940: my $user = $uname.':'.$udom;
1941: $origmembers{$user} = 1;
1942: }
1.5 raeburn 1943: }
1944: }
1945: }
1.46 albertel 1946: &privilege_specificity($r,$action,$specimg,$tools,$stored,$toolprivs,
1.103 raeburn 1947: $fixedprivs,\@available,$formname,$gpterm,$ucgpterm,
1.104 raeburn 1948: $functions,$crstype);
1.44 albertel 1949: my $newusers = &pick_new_members($r,$action,$formname,\@available,$idx,
1950: $stored,$memimg,$users,$userdata,
1951: $granularity,\%origmembers,$gpterm,
1952: $ucgpterm);
1.5 raeburn 1953: if ($newusers || $action eq 'create') {
1954: &display_navbuttons($r,$formname,$$states{$action}[$page-1],
1955: $$navbuttons{'gtps'},$$states{$action}[$page+1],
1956: $$navbuttons{'gtns'});
1957: } else {
1958: &display_navbuttons($r,$formname,$$states{$action}[$page-1],
1959: $$navbuttons{'gtps'});
1.3 raeburn 1960: }
1.5 raeburn 1961: return;
1962: }
1963:
1964: sub display_navbuttons {
1965: my ($r,$formname,$prev,$prevtext,$next,$nexttext) = @_;
1.42 albertel 1966: $r->print('<div class="LC_navbuttons">');
1.5 raeburn 1967: if ($prev) {
1968: $r->print('
1969: <input type="button" name="previous" value = "'.$prevtext.'"
1970: onclick="javascript:backPage(document.'.$formname.','."'".$prev."'".')"/>
1971: ');
1.64 raeburn 1972: } elsif ($prevtext) {
1973: $r->print('
1974: <input type="button" name="previous" value = "'.$prevtext.'"
1975: onclick="javascript:history.back()"/>
1976: ');
1.5 raeburn 1977: }
1978: if ($next) {
1979: $r->print('
1980: <input type="button" name="next" value="'.$nexttext.'"
1981: onclick="javascript:nextPage(document.'.$formname.','."'".$next."'".')" />');
1982: }
1.42 albertel 1983: $r->print('</div>');
1.5 raeburn 1984: }
1985:
1986: sub check_tools {
1987: my ($functions,$tools,$available,$unavailable) = @_;
1988: foreach my $item (sort(keys(%{$functions}))) {
1989: if (grep/^$item$/,@{$tools}) {
1990: push(@{$available},$item);
1991: } else {
1992: push(@{$unavailable},$item);
1993: }
1994: }
1995: return;
1996: }
1997:
1998: sub print_current_settings {
1.40 albertel 1999: my ($r,$action,$functions,$startdate,$enddate,$groupname,$description,
2000: $granularity,$quota,$available,$unavailable,$gpterm,$ucgpterm) = @_;
1.5 raeburn 2001:
2002: my %lt = &Apache::lonlocal::texthash(
1.53 raeburn 2003: grna => 'Group Name',
2004: desc => 'Group Title',
2005: grfn => "Collaborative Tools",
1.5 raeburn 2006: gran => 'Granularity',
1.29 raeburn 2007: quot => 'File quota',
1.5 raeburn 2008: dfac => 'Default access dates',
1.53 raeburn 2009: ygrs => "Your group selections - ",
2010: tfwa => "The following settings will apply to the group:",
2011: difn => 'Different collaborative tools<br />for different members:',
1.80 bisitz 2012: stda => 'Start date:',
1.5 raeburn 2013: enda => 'End date:',
2014: );
1.3 raeburn 2015: my $showstart = &Apache::lonlocal::locallocaltime($startdate);
1.5 raeburn 2016: my $showend;
2017: if ($enddate == 0) {
2018: $showend = &mt('No end date set');
2019: } else {
2020: $showend = &Apache::lonlocal::locallocaltime($enddate);
2021: }
2022: if ($action eq 'create') {
2023: $r->print('
1.42 albertel 2024: <div><span style="font-size: larger">'.$lt{'ygrs'}.'</span>
1.5 raeburn 2025: <br />'.$lt{'tfwa'}.'
1.40 albertel 2026: </div>');
1.5 raeburn 2027: }
1.40 albertel 2028: $r->print(&Apache::loncommon::start_data_table('LC_course_group_status').
2029: &Apache::loncommon::start_data_table_header_row());
2030: $r->print('
2031: <th>'.$lt{'grna'}.'</th>
2032: <th>'.$lt{'desc'}.'</th>
2033: <th>'.$lt{'grfn'}.'</th>
2034: <th>'.$lt{'gran'}.'</th>
2035: <th>'.$lt{'quot'}.'</th>
2036: <th>'.$lt{'dfac'}.'</th>
2037: ');
2038: $r->print(&Apache::loncommon::end_data_table_header_row().
2039: &Apache::loncommon::start_data_table_row('LC_data_table_dense'));
1.3 raeburn 2040: $r->print('
1.40 albertel 2041: <td valign="top">'.$groupname.'</td>
2042: <td valign="top">'.$description.'</td>
1.3 raeburn 2043: <td>
2044: ');
1.99 bisitz 2045:
1.5 raeburn 2046: if (@{$available} > 0) {
1.99 bisitz 2047: $r->print('<b>'.&mt('Available for assignment to members:').'</b>');
2048: $r->print('<ul>');
1.5 raeburn 2049: for (my $i=0; $i<@{$available}; $i++) {
1.99 bisitz 2050: $r->print('<li>'.&mt($$functions{$$available[$i]}).'</li>');
1.3 raeburn 2051: }
1.99 bisitz 2052: $r->print('</ul>');
1.3 raeburn 2053: }
1.99 bisitz 2054:
1.5 raeburn 2055: if (@{$unavailable} > 0) {
1.99 bisitz 2056: $r->print('<b>'.&mt('Unavailable for assignment:').'</b>');
2057: $r->print('<ul>');
2058: for (my $i=0; $i<@{$unavailable}; $i++) {
2059: $r->print('<li>'.&mt($$functions{$$unavailable[$i]}).'</li>');
1.3 raeburn 2060: }
1.99 bisitz 2061: $r->print('</ul>');
1.3 raeburn 2062: }
1.99 bisitz 2063:
1.79 bisitz 2064: my $quota_text=&mt('[_1] Mb',$quota);
1.80 bisitz 2065: my $granu_text=&mt($granularity);
1.3 raeburn 2066: $r->print(<<"END");
2067: </td>
1.80 bisitz 2068: <td valign="top"><b>$lt{'difn'}</b> $granu_text</td>
1.79 bisitz 2069: <td valign="top">$quota_text</td>
1.40 albertel 2070: <td valign="top"><b>$lt{'stda'}</b> $showstart<br />
2071: <b>$lt{'enda'}</b> $showend
1.3 raeburn 2072: </td>
2073: END
1.40 albertel 2074: $r->print(&Apache::loncommon::end_data_table_row().
2075: &Apache::loncommon::end_data_table());
1.5 raeburn 2076: return;
2077: }
2078:
2079: sub pick_new_members {
1.44 albertel 2080: my ($r,$action,$formname,$available,$idx,$stored,$img,$users,$userdata,
2081: $granularity,$origmembers,$gpterm,$ucgpterm) = @_;
1.5 raeburn 2082: my %lt = &Apache::lonlocal::texthash(
1.53 raeburn 2083: 'gpme' => "Group membership",
1.5 raeburn 2084: 'addm' => 'Add members',
1.53 raeburn 2085: 'setf' => 'Assign collaborative tools',
2086: 'func' => 'Tools',
2087: 'nome' => 'No members to add at this time, as there are no users '.
2088: 'matching the specified type(s), role(s) and section(s).',
1.29 raeburn 2089: 'nnew' => "There are no users to add as new members, as all users".
1.53 raeburn 2090: " matching the specified type(s), role(s), and ".
2091: "section(s) are already affiliated with this group.",
1.79 bisitz 2092: 'yoma' => "You may need to use the 'modify existing, past or ".
2093: "future members' page if you need to re-enable ".
2094: "or activate access for previous or future members.",
1.5 raeburn 2095: );
2096: my %members;
2097: my $totalusers = 0;
2098: my $newusers = 0;
1.3 raeburn 2099: foreach my $role (keys(%{$users})) {
2100: foreach my $user (keys(%{$$users{$role}})) {
1.5 raeburn 2101: $totalusers ++;
2102: if (ref($origmembers) eq 'HASH') {
2103: if (exists($$origmembers{$user})) {
2104: next;
2105: }
2106: }
1.3 raeburn 2107: unless (defined($members{$user})) {
2108: @{$members{$user}} = @{$$userdata{$user}};
1.5 raeburn 2109: $newusers ++;
1.3 raeburn 2110: }
2111: }
2112: }
2113: if (keys(%members) > 0) {
1.5 raeburn 2114: if (@{$available} > 0 && $granularity eq 'Yes') {
2115: $r->print(&check_uncheck_tools($r,$available));
2116: }
2117: }
1.78 raeburn 2118: $r->print(&Apache::lonhtmlcommon::topic_bar($img,$lt{'gpme'}));
1.5 raeburn 2119: if (keys(%members) > 0) {
2120: $r->print('
1.3 raeburn 2121: <table>
1.5 raeburn 2122: <tr>');
2123: &check_uncheck_buttons($r,$formname,'member',$lt{'addm'});
2124: if (@{$available} > 0 && $granularity eq 'Yes') {
1.48 albertel 2125: $r->print('<td>
1.102 bisitz 2126: <fieldset><legend>'.$lt{'setf'}.'</legend>
1.83 bisitz 2127: <span class="LC_nobreak">
1.80 bisitz 2128: <input type="button" value="'.&mt('check all').'"
1.5 raeburn 2129: onclick="javascript:checkAllTools(document.'.$formname.')" />
2130:
1.80 bisitz 2131: <input type="button" value="'.&mt('uncheck all').'"
1.3 raeburn 2132: onclick="javascript:uncheckAllTools(document.'.$formname.')" />
1.83 bisitz 2133: </span>
1.48 albertel 2134: </fieldset></td>');
1.3 raeburn 2135: }
2136: $r->print('</tr></table>
2137: ');
1.43 albertel 2138: $r->print(&Apache::loncommon::start_data_table().
2139: &Apache::loncommon::start_data_table_header_row());
1.5 raeburn 2140: $r->print('
1.43 albertel 2141: <th>'.&mt('Add?').'</b></td>
2142: <th><a href="javascript:changeSort('."'fullname'".')">'.&mt('Name').'</a></td>
2143: <th><a href="javascript:changeSort('."'username'".')">'.&mt('Username').'</a></td>
2144: <th><a href="javascript:changeSort('."'domain'".')">'.&mt('Domain').'</a></td>
2145: <th><a href="javascript:changeSort('."'id'".')">'.&mt('ID').'</a></td>
2146: <th><a href="javascript:changeSort('."'section'".')">'.&mt('Section').'</a></td>
1.5 raeburn 2147: ');
2148: if (@{$available} > 0) {
1.43 albertel 2149: $r->print('<th>'.$lt{'func'}.'</th>');
1.3 raeburn 2150: }
1.43 albertel 2151: $r->print(&Apache::loncommon::end_data_table_header_row());
1.5 raeburn 2152: if (@{$available} > 0) {
2153: if ($granularity eq 'Yes') {
1.43 albertel 2154: $r->print(&Apache::loncommon::start_data_table_row('LC_data_table_dense LC_data_table_highlight').'
1.35 raeburn 2155: <td colspan="6"> </td>
1.83 bisitz 2156: <td align="center"><span class="LC_nobreak"><b>'.&mt('All:').'</b> ');
1.5 raeburn 2157: foreach my $tool (@{$available}) {
1.7 raeburn 2158: $r->print('<label><input type="checkbox" name="togglefunc" '.
2159: 'onclick="javascript:toggleTools(document.'.$formname.'.user_'.$tool.',this);"'.
2160: ' value="'.$tool.'">'.'<b>'.$tool.'</b></label> ');
1.5 raeburn 2161: }
1.83 bisitz 2162: $r->print('</span></td></tr>');
1.5 raeburn 2163: }
2164: }
1.3 raeburn 2165: my %Sortby = ();
2166: foreach my $user (sort(keys(%members))) {
2167: if ($env{'form.sortby'} eq 'fullname') {
2168: push(@{$Sortby{$members{$user}[$$idx{fullname}]}},$user);
2169: } elsif ($env{'form.sortby'} eq 'username') {
2170: push(@{$Sortby{$members{$user}[$$idx{uname}]}},$user);
2171: } elsif ($env{'form.sortby'} eq 'domain') {
2172: push(@{$Sortby{$members{$user}[$$idx{udom}]}},$user);
2173: } elsif ($env{'form.sortby'} eq 'id') {
2174: push(@{$Sortby{$members{$user}[$$idx{id}]}},$user);
1.31 albertel 2175: } elsif ($env{'form.sortby'} eq 'section') {
2176: push(@{$Sortby{$members{$user}[$$idx{section}]}},$user);
1.3 raeburn 2177: } else {
2178: push(@{$Sortby{$members{$user}[$$idx{fullname}]}},$user);
2179: }
2180: }
2181: foreach my $key (sort(keys(%Sortby))) {
2182: foreach my $user (@{$Sortby{$key}}) {
2183: my $id = $members{$user}[$$idx{id}];
2184: my $fullname = $members{$user}[$$idx{fullname}];
2185: my $udom = $members{$user}[$$idx{udom}];
2186: my $uname = $members{$user}[$$idx{uname}];
1.31 albertel 2187: my $section = $members{$user}[$$idx{section}];
1.43 albertel 2188: $r->print(&Apache::loncommon::start_data_table_row('LC_data_table_dense').
2189: '<td align="right"><input type="checkbox" name="member" value="'.$user.'" /></td>'.
2190: '<td>'.$fullname.'</td>'.
2191: '<td>'.$uname.'</td>'.
2192: '<td>'.$udom.'</td>'.
2193: '<td>'.$id.'</td>'.
2194: '<td>'.$section.'</td>');
1.5 raeburn 2195: if (@{$available} > 0) {
1.83 bisitz 2196: $r->print('<td align="center"><span class="LC_nobreak">'.
1.5 raeburn 2197: ' ');
2198: foreach my $tool (@{$available}) {
2199: if ($granularity eq 'Yes') {
1.3 raeburn 2200: $r->print('<input type="checkbox" name="user_'.
2201: $tool.'" value="'.$user.'" />'.$tool.' ');
2202: } else {
2203: $r->print('<input type="hidden" name="user_'.
2204: $tool.'" value="'.$user.'" />'.$tool.' ');
2205: }
2206: }
1.83 bisitz 2207: $r->print('</span></td>');
1.3 raeburn 2208: }
1.43 albertel 2209: $r->print(&Apache::loncommon::end_data_table_row()."\n");
1.3 raeburn 2210: }
2211: }
1.43 albertel 2212: $r->print(&Apache::loncommon::end_data_table());
1.5 raeburn 2213: } else {
2214: if ($totalusers > 0) {
2215: $r->print($lt{'nnew'}.'<br /><br />'.$lt{'yoma'});
2216: } else {
2217: $r->print($lt{'nome'});
2218: }
2219: }
2220: return $newusers;
2221: }
2222:
2223: sub privilege_specificity {
1.46 albertel 2224: my ($r,$action,$img,$tools,$stored,$toolprivs,$fixedprivs,$available,
1.104 raeburn 2225: $formname,$gpterm,$ucgpterm,$functions,$crstype) = @_;
1.5 raeburn 2226: my %lt = &Apache::lonlocal::texthash (
1.53 raeburn 2227: 'uprv' => 'User privileges for collaborative tools',
2228: 'frty' => 'For each collaborative tool you have chosen to include, '.
2229: 'there is a set of core privileges which all group members '.
2230: 'assigned use of the tool will receive.',
2231: 'thar' => 'For some tools there are also additional optional '.
2232: 'privileges which can be set.',
2233: 'plch' => 'Choose one of the following:',
2234: 'fort' => 'For the collaborative tools you have chosen to include '.
2235: 'only core privileges are available, '.
2236: 'so there are no optional privileges to assign.',
2237: 'eaty' => 'Each collaborative tool includes core '.
2238: 'privileges assigned to all members with access to the '.
2239: 'tool. Some tools may also feature additional privileges '.
1.5 raeburn 2240: 'which can be set for specific members.',
1.53 raeburn 2241: 'cutg' => 'Currently the group is configured ',
2242: 'sdif' => 'so different members can receive different optional privileges for a particular tool.',
2243: 'sall' => 'so all members will receive the same optional privileges for a particular tool.',
2244: 'algm' => 'All group members will receive the same privileges for any tool assigned to them, including the default set of optional privileges.',
2245: 'smgp' => 'Different group members may receive different privileges from '.
2246: 'others for the tools they have been assigned.',
2247: 'thwi' => 'These will be the privileges all group members receive for a particular assigned tool, '.
2248: 'if you selected the first option above.',
1.29 raeburn 2249: 'thes' => "These will be the privileges given to members assigned ".
1.53 raeburn 2250: "in the future via automatic group assignment ".
2251: "for users who receive specific sections/roles in the course ",
2252: 'asyo' => "As you have chosen not to include any collaborative tools ".
2253: "in the group, no default optional privileges need to be set.",
2254: 'plin' => 'Indicate which <b>optional</b> privileges members '.
2255: 'will receive by default for a specific tool.',
1.5 raeburn 2256: 'oppr' => 'Optional privileges',
2257: 'defp' => 'The default privileges new members will receive are:',
2258: );
1.104 raeburn 2259: if ($crstype eq 'Community') {
2260: $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 ');
2261: }
1.5 raeburn 2262: my $totaloptionalprivs = 0;
2263: foreach my $tool (@{$tools}) {
2264: foreach my $priv (sort(keys(%{$$toolprivs{$tool}}))) {
2265: if (!exists($$fixedprivs{$tool}{$priv})) {
2266: $totaloptionalprivs ++;
2267: }
2268: }
2269: }
1.78 raeburn 2270: $r->print(&Apache::lonhtmlcommon::topic_bar($img,$lt{'uprv'}));
1.5 raeburn 2271: if ((($action eq 'create') && (@{$available} > 0)) ||
1.55 raeburn 2272: (($action eq 'modify') && ($formname eq 'change_settings'))) {
1.5 raeburn 2273: my %specific = (
2274: 'No' => 'checked="checked"',
2275: 'Yes' => '',
2276: );
2277: if ($action eq 'create') {
2278: $r->print($lt{'frty'}.'<br />');
2279: if ($totaloptionalprivs) {
1.53 raeburn 2280: $r->print($lt{'thar'}.'<br /><br />'.$lt{'plch'});
1.5 raeburn 2281: } else {
2282: $r->print($lt{'fort'});
2283: }
2284: } else {
2285: $r->print($lt{'eaty'}.' '.$lt{cutg});
2286: if ($$stored{'specificity'} eq 'Yes') {
2287: $r->print($lt{'sdif'});
2288: $specific{'Yes'} = $specific{'No'};
2289: $specific{'No'} = '';
2290: } else {
2291: $r->print($lt{'sall'});
2292: }
2293: }
2294: if ($totaloptionalprivs) {
2295: $r->print('
1.53 raeburn 2296: <br />
1.83 bisitz 2297: <label><span class="LC_nobreak"><input type="radio" name="specificity" value="No" '.$specific{'No'}.' /> '.$lt{'algm'}.'</span></label><br />
2298: <label><span class="LC_nobreak"><input type="radio" name="specificity" value="Yes" '.$specific{'Yes'}.' /> '.$lt{'smgp'}.'</span></label><br /><br />');
1.5 raeburn 2299: } else {
2300: $r->print('<input type="hidden" name="specificity" value="No" />');
2301: }
2302: if ($totaloptionalprivs) {
1.40 albertel 2303: $r->print($lt{'plin'});
1.5 raeburn 2304: if ($action eq 'create') {
1.53 raeburn 2305: $r->print('<br />'.$lt{'thwi'});
1.5 raeburn 2306: }
2307: $r->print('<br />'.$lt{'thes'});
2308: if ($action eq 'create') {
2309: $r->print('('.&mt('if enabled on the next page').').');
2310: } else {
2311: $r->print('('.&mt('if enabled below').').');
2312: }
2313: $r->print('<br /><br />
1.40 albertel 2314: <table><tr>');
1.5 raeburn 2315: &check_uncheck_buttons($r,$formname,'defpriv',$lt{'oppr'});
2316: $r->print('
2317: </tr>
2318: </table>
1.3 raeburn 2319: <br />
2320: ');
1.5 raeburn 2321: } else {
1.40 albertel 2322: $r->print($lt{'algm'}.'<br /><br />');
1.3 raeburn 2323: }
1.42 albertel 2324: &default_privileges($r,$action,$tools,$toolprivs,$fixedprivs,
1.92 schafran 2325: $available,$functions);
1.3 raeburn 2326: } else {
1.5 raeburn 2327: if ($action eq 'create') {
2328: $r->print($lt{'asyo'});
1.55 raeburn 2329: $r->print('<input type="hidden" name="specificity" value="No" />');
1.5 raeburn 2330: } elsif ($action eq 'modify' && $formname eq 'pick_members') {
2331: my @defprivs;
2332: if (ref($$stored{'defpriv'}) eq 'ARRAY') {
2333: @defprivs = @{$$stored{'defpriv'}};
2334: }
2335: $r->print($lt{'eaty'}.' '.$lt{cutg});
2336: if ($$stored{'specificity'} eq 'Yes') {
2337: $r->print($lt{'sdif'});
2338: } else {
2339: $r->print($lt{'sall'});
2340: }
2341: $r->print(' '.$lt{'defp'}.'<br /><br />');
1.45 albertel 2342: &display_defprivs($r,$tools,$toolprivs,\@defprivs);
1.5 raeburn 2343: }
1.3 raeburn 2344: }
2345: return;
2346: }
2347:
1.5 raeburn 2348: sub default_privileges {
1.92 schafran 2349: my ($r,$action,$tools,$toolprivs,$fixedprivs,$available,$functions) = @_;
1.5 raeburn 2350: my %lt = &Apache::lonlocal::texthash(
2351: 'addp' => 'Additional privileges',
2352: 'fixp' => 'Fixed privileges',
2353: 'oppr' => 'Optional privileges',
1.53 raeburn 2354: 'func' => 'Collaborative Tool',
1.5 raeburn 2355: );
1.42 albertel 2356: $r->print(&Apache::lonhtmlcommon::start_pick_box('LC_group_priv_box').
2357: &Apache::lonhtmlcommon::row_title($lt{'func'},undef,
1.90 schafran 2358: 'LC_groups_functionality'));
1.92 schafran 2359: my @tableHeader;
1.107 raeburn 2360: if ((ref($functions) eq 'HASH') && (ref($tools) eq 'ARRAY')) {
2361: @tableHeader = map { $functions->{$_}; } @{$tools};
2362: }
1.92 schafran 2363: $r->print(join('</td><td class="LC_groups_functionality">', @tableHeader));
1.42 albertel 2364: $r->print(&Apache::lonhtmlcommon::row_closure(1));
2365: my $fixed = '';
2366: my $dynamic = '';
1.3 raeburn 2367: foreach my $tool (@{$tools}) {
1.5 raeburn 2368: my $privcount = 0;
1.42 albertel 2369: if ($dynamic ne '') {
2370: $dynamic .= '</td><td class="LC_groups_optional">';
2371: }
2372: $dynamic .= '<table class="LC_group_priv"><tr>';
1.5 raeburn 2373: foreach my $priv (sort(keys(%{$$toolprivs{$tool}}))) {
2374: if (exists($$fixedprivs{$tool}{$priv})) {
1.42 albertel 2375: if ($fixed ne '') {
2376: $fixed .= '</td><td class="LC_groups_fixed">';
2377: }
1.79 bisitz 2378: $fixed .= '<input type="hidden" name="defpriv" value="'.$priv.'" />'
1.90 schafran 2379: .'<span class="LC_nobreak">'.&mt($$toolprivs{$tool}{$priv}).' ';
1.5 raeburn 2380: if ($action eq 'modify') {
1.42 albertel 2381: if (grep(/^$tool$/,@{$available})) {
1.5 raeburn 2382: $fixed .= '<small>'.&mt('(on)').'<small> ';
2383: } else {
2384: $fixed .= '<small>'.&mt('(off)').'<small> ';
1.3 raeburn 2385: }
2386: }
1.79 bisitz 2387: $fixed .= '</span>';
1.5 raeburn 2388: } else {
1.42 albertel 2389: $privcount++;
1.5 raeburn 2390: if ($privcount == 3) {
2391: $dynamic .= '</tr>
1.42 albertel 2392: <tr>'."\n";
1.5 raeburn 2393: }
1.90 schafran 2394: $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 2395: }
2396: }
1.42 albertel 2397: if ($privcount == 0) {
1.79 bisitz 2398: $dynamic .= '<td>'.&mt('None').'</td>'."\n";
1.5 raeburn 2399: }
2400: if ($privcount < 3) {
1.53 raeburn 2401: $dynamic .= '<td> </td>'."\n";
1.5 raeburn 2402: } elsif ($privcount%2) {
2403: $dynamic = '<td> </td>'."\n";
2404: }
1.42 albertel 2405: $dynamic .= '</tr></table>';
1.3 raeburn 2406: }
1.42 albertel 2407: $r->print(&Apache::lonhtmlcommon::row_title($lt{'fixp'},undef,
2408: 'LC_groups_fixed').
2409: $fixed.
2410: &Apache::lonhtmlcommon::row_closure(1));
2411: $r->print(&Apache::lonhtmlcommon::row_title($lt{'oppr'},undef,
2412: 'LC_groups_optional').
2413: $dynamic.
2414: &Apache::lonhtmlcommon::end_pick_box());
1.5 raeburn 2415: $r->print('<br />');
2416: return;
1.42 albertel 2417:
1.5 raeburn 2418: }
2419:
2420: sub display_defprivs {
1.45 albertel 2421: my ($r,$tools,$toolprivs,$defprivs) = @_;
2422: my $function = &Apache::loncommon::get_users_function();
2423: my $tabcol = &Apache::loncommon::designparm($function.'.tabbg');
2424: my $rowColor1 = "#dddddd";
2425: my $rowColor2 = "#eeeeee";
1.5 raeburn 2426: my %lt = &Apache::lonlocal::texthash(
2427: 'priv' => 'Privileges',
1.53 raeburn 2428: 'func' => 'Collaborative Tool',
1.5 raeburn 2429: );
2430: $r->print(&Apache::lonhtmlcommon::start_pick_box());
2431: $r->print('<tr>');
2432: my $numrows = 0;
2433: my %currprivs;
2434: foreach my $tool (@{$tools}) {
2435: @{$currprivs{$tool}} = ();
2436: foreach my $priv (sort(keys(%{$$toolprivs{$tool}}))) {
2437: if (ref($defprivs) eq 'ARRAY') {
1.45 albertel 2438: if (grep(/^\Q$priv\E$/,@{$defprivs})) {
1.5 raeburn 2439: push(@{$currprivs{$tool}},$priv);
2440: }
1.3 raeburn 2441: }
2442: }
1.5 raeburn 2443: my $rowcount = int(@{$currprivs{$tool}}/3);
2444: if (@{$currprivs{$tool}}%3 > 0) {
2445: $rowcount ++;
2446: }
2447: if ($rowcount > $numrows) {
2448: $numrows = $rowcount;
2449: }
2450: }
2451: my @rowCols = ($rowColor1,$rowColor2);
2452: foreach my $tool (@{$tools}) {
2453: $r->print('<td align="center" valign="top">
2454: <table cellspacing="0" cellpadding="5">
2455: <tr bgcolor="#cccccc">
2456: <td colspan="3" align="center"><b>'.$tool.'</b></td>
2457: </tr>
2458: ');
2459: my $rownum = 1;
2460: my $privcount = 0;
2461: $r->print('<tr bgcolor="'.$rowColor1.'">');
2462: foreach my $priv (@{$currprivs{$tool}}) {
2463: $privcount ++;
2464: if ($privcount%4 == 0) {
2465: $rownum ++;
2466: my $bgcol = $rownum%2;
2467: $r->print('</tr>
2468: <tr bgcolor="'.$rowCols[$bgcol].'">'."\n");
2469: }
2470: $r->print('<td>'.$$toolprivs{$tool}{$priv}.'</td>'."\n");
2471: }
2472: if ($privcount%3 > 0) {
2473: my $emptycells = 3-($privcount%3);
2474: while($emptycells > 0) {
2475: $r->print('<td> </td>'."\n");
2476: $emptycells --;
2477: }
2478: }
2479: while ($rownum < $numrows) {
2480: $rownum ++;
2481: my $bgcol = $rownum%2;
2482: $r->print('<tr bgcolor="'.$rowCols[$bgcol].'"><td colspan="3"> </td></tr>');
1.3 raeburn 2483: }
1.5 raeburn 2484: $r->print('</table>'."\n".'</td>');
2485: }
2486: $r->print('</tr>'."\n");
2487: $r->print(&Apache::lonhtmlcommon::end_pick_box());
2488: $r->print('<br />');
2489: return;
1.3 raeburn 2490: }
1.5 raeburn 2491:
2492:
2493: sub change_members_form {
1.48 albertel 2494: my ($r,$cdom,$cnum,$action,$formname,$page,$groupname,$description,
1.5 raeburn 2495: $startdate,$enddate,$tools,$fixedprivs,$functions,$users,$userdata,
1.48 albertel 2496: $granularity,$quota,$specificity,$idx,$states,$navbuttons,$gpterm,
2497: $ucgpterm) = @_;
1.5 raeburn 2498: my %lt = &Apache::lonlocal::texthash(
1.29 raeburn 2499: grse => "$ucgpterm settings",
2500: mogm => "Modify $gpterm membership",
1.5 raeburn 2501: );
2502: my @regexps = ('user_','userpriv_');
2503: $r->print(&Apache::lonhtmlcommon::echo_form_input(
1.6 raeburn 2504: ['origin','action','state','page','expire','deletion',
1.7 raeburn 2505: 'reenable','activate','changepriv','sortby',
2506: 'togglefunc'],\@regexps));
1.5 raeburn 2507: my $rowimg = 1;
2508: my @available = ();
2509: my @unavailable = ();
2510: &check_tools($functions,$tools,\@available,\@unavailable);
2511: my $nexttext = $$navbuttons{'gtns'};
2512: my $prevtext = $$navbuttons{'gtpp'};
2513: $r->print('
1.3 raeburn 2514: <br />
1.5 raeburn 2515: ');
1.78 raeburn 2516: $r->print(&Apache::lonhtmlcommon::topic_bar(1,$lt{'grse'}));
1.40 albertel 2517: &print_current_settings($r,$action,$functions,$startdate,$enddate,
2518: $groupname,$description,$granularity,$quota,
2519: \@available,\@unavailable,$gpterm,$ucgpterm);
1.78 raeburn 2520: $r->print(&Apache::lonhtmlcommon::topic_bar(2,$lt{'mogm'}));
1.53 raeburn 2521: my $numcurrent = ¤t_membership($r,$cdom,$cnum,$formname,$groupname,
2522: \@available,\@unavailable,$fixedprivs,
2523: $granularity,$specificity);
2524: if ($numcurrent > 0) {
2525: &display_navbuttons($r,$formname,$$states{$action}[$page-1],$prevtext,
2526: $$states{$action}[$page+1],$nexttext);
2527: } else {
2528: &display_navbuttons($r,$formname,$$states{$action}[$page-1],$prevtext);
2529: }
1.5 raeburn 2530: return;
2531: }
2532:
2533: sub current_membership {
1.48 albertel 2534: my ($r,$cdom,$cnum,$formname,$groupname,$available,$unavailable,
2535: $fixedprivs,$granularity,$specificity) = @_;
1.5 raeburn 2536: my %membership = &Apache::lonnet::get_group_membership($cdom,$cnum,
2537: $groupname);
2538: my %lt = &Apache::lonlocal::texthash(
1.6 raeburn 2539: 'actn' => 'Action?',
2540: 'name' => 'Name',
2541: 'usnm' => 'Username',
2542: 'doma' => 'Domain',
2543: 'stda' => 'Start Date',
2544: 'enda' => 'End Date',
1.5 raeburn 2545: 'expi' => 'Expire',
2546: 'reen' => 'Re-enable',
2547: 'acti' => 'Activate',
2548: 'dele' => 'Delete',
1.53 raeburn 2549: 'curf' => 'Current Tool Set',
1.5 raeburn 2550: 'chpr' => 'Change Privileges'
2551: );
1.52 raeburn 2552: my ($current,$num_items,$hastools,$addtools) =
1.36 raeburn 2553: &Apache::longroup::group_memberlist($cdom,$cnum,$groupname,$fixedprivs,
2554: $available);
1.53 raeburn 2555: my $numcurrent = scalar(keys(%{$current}));
2556: if ($numcurrent > 0) {
1.36 raeburn 2557: $r->print('
1.5 raeburn 2558: <table>
2559: <tr>');
1.52 raeburn 2560: if ($num_items->{'active'}) {
1.36 raeburn 2561: &check_uncheck_buttons($r,$formname,'expire',$lt{'expi'});
2562: }
1.52 raeburn 2563: if ($num_items->{'previous'}) {
1.36 raeburn 2564: &check_uncheck_buttons($r,$formname,'reenable',$lt{'reen'});
2565: }
1.52 raeburn 2566: if ($num_items->{'future'}) {
1.36 raeburn 2567: &check_uncheck_buttons($r,$formname,'activate',$lt{'acti'});
2568: }
2569: &check_uncheck_buttons($r,$formname,'deletion',$lt{'dele'});
2570: if (@{$available} > 0) {
2571: if ($specificity eq 'Yes') {
2572: &check_uncheck_buttons($r,$formname,'changepriv',$lt{'chpr'});
1.5 raeburn 2573: }
1.36 raeburn 2574: if ($granularity eq 'Yes') {
2575: $r->print(&check_uncheck_tools($r,$available));
2576: $r->print('
1.5 raeburn 2577: <td>
1.83 bisitz 2578: <span class="LC_nobreak">
1.102 bisitz 2579: <fieldset><legend>'.$lt{'curf'}.'</legend>
1.80 bisitz 2580: <input type="button" value="'.&mt('check all').'"
1.5 raeburn 2581: onclick="javascript:checkAllTools(document.'.$formname.')" />
2582:
1.80 bisitz 2583: <input type="button" value="'.&mt('uncheck all').'"
1.5 raeburn 2584: onclick="javascript:uncheckAllTools(document.'.$formname.')" />
2585: </fieldset>
1.83 bisitz 2586: </span>
1.5 raeburn 2587: </td>
2588: ');
1.3 raeburn 2589: }
1.36 raeburn 2590: }
2591: $r->print(<<"END");
1.5 raeburn 2592: </tr>
2593: </table>
1.48 albertel 2594: <br />
1.5 raeburn 2595: END
1.48 albertel 2596: $r->print(&Apache::loncommon::start_data_table().
2597: &Apache::loncommon::start_data_table_header_row());
1.36 raeburn 2598: $r->print(<<"END");
1.48 albertel 2599: <th>$lt{'actn'}</th>
2600: <th><a href="javascript:changeSort('fullname')">$lt{'name'}</a></th>
2601: <th><a href="javascript:changeSort('username')">$lt{'usnm'}</a></th>
2602: <th><a href="javascript:changeSort('domain')">$lt{'doma'}</a></th>
2603: <th><a href="javascript:changeSort('id')">ID</a></th>
2604: <th><a href="javascript:changeSort('start')">$lt{'stda'}</a></th>
2605: <th><a href="javascript:changeSort('end')">$lt{'enda'}</a></th>
1.5 raeburn 2606: END
1.36 raeburn 2607: my $colspan = 0;
2608: if ($hastools) {
1.48 albertel 2609: $r->print('<th>'.$lt{'curf'}.'</th>');
2610: $colspan++;
1.36 raeburn 2611: }
2612: if ($addtools) {
1.53 raeburn 2613: $r->print('<th>'.&mt('Additional Tools').'</th>');
1.48 albertel 2614: $colspan++;
1.36 raeburn 2615: }
1.48 albertel 2616: $r->print(&Apache::loncommon::end_data_table_header_row());
1.36 raeburn 2617: if ($colspan) {
2618: if ($granularity eq 'Yes') {
1.48 albertel 2619: $r->print(&Apache::loncommon::start_data_table_row('LC_data_table_dense LC_data_table_highlight').'
1.6 raeburn 2620: <td colspan="7"> </td>
1.83 bisitz 2621: <td colspan="'.$colspan.'" align="center"><span class="LC_nobreak"><b>'.&mt('All:').
1.6 raeburn 2622: '</b> ');
1.36 raeburn 2623: foreach my $tool (@{$available}) {
2624: $r->print('<label><input type="checkbox" name="togglefunc"'.
1.7 raeburn 2625: ' onclick="javascript:toggleTools(document.'.$formname.'.user_'.$tool.',this);"'.
1.48 albertel 2626: ' value="'.$tool.'" />'.'<b>'.$tool.'</b></label> ');
1.6 raeburn 2627: }
1.83 bisitz 2628: $r->print('</span></td></tr>');
1.6 raeburn 2629: }
1.36 raeburn 2630: }
2631: my %Sortby = ();
2632: foreach my $user (sort(keys(%{$current}))) {
2633: if ($env{'form.sortby'} eq 'fullname') {
2634: push(@{$Sortby{$$current{$user}{fullname}}},$user);
2635: } elsif ($env{'form.sortby'} eq 'username') {
2636: push(@{$Sortby{$$current{$user}{uname}}},$user);
2637: } elsif ($env{'form.sortby'} eq 'domain') {
2638: push(@{$Sortby{$$current{$user}{udom}}},$user);
2639: } elsif ($env{'form.sortby'} eq 'id') {
2640: push(@{$Sortby{$$current{$user}{id}}},$user);
2641: } else {
2642: push(@{$Sortby{$$current{$user}{fullname}}},$user);
2643: }
2644: }
2645: foreach my $key (sort(keys(%Sortby))) {
2646: foreach my $user (@{$Sortby{$key}}) {
2647: my $id = $$current{$user}{id};
2648: my $fullname = $$current{$user}{fullname};
2649: my $udom = $$current{$user}{udom};
2650: my $uname = $$current{$user}{uname};
2651: my $start = $$current{$user}{start};
2652: my $end = $$current{$user}{end};
1.48 albertel 2653: $r->print(&Apache::loncommon::start_data_table_row('LC_data_table_dense').'
2654: <td>');
1.36 raeburn 2655: if ($$current{$user}{changestate} eq 'reenable') {
1.83 bisitz 2656: $r->print('<span class="LC_nobreak"><label>'.
1.5 raeburn 2657: '<input type="checkbox" name="reenable" value="'.$user.'" />'.
1.83 bisitz 2658: $lt{'reen'}.'</label></span><br />');
1.36 raeburn 2659: } elsif ($$current{$user}{changestate} eq 'expire') {
1.83 bisitz 2660: $r->print('<span class="LC_nobreak"><label>'.
1.5 raeburn 2661: '<input type="checkbox" name="expire" value="'.$user.'" />'.
1.83 bisitz 2662: $lt{'expi'}.'</label></span><br />');
1.36 raeburn 2663: } elsif ($$current{$user}{changestate} eq 'activate') {
1.83 bisitz 2664: $r->print('<span class="LC_nobreak"><label>'.
1.5 raeburn 2665: '<input type="checkbox" name="activate" value="'.$user.'" />'.
1.83 bisitz 2666: $lt{'acti'}.'</label></span><br />');
1.36 raeburn 2667: }
1.83 bisitz 2668: $r->print('<span class="LC_nobreak"><label>'.
1.6 raeburn 2669: '<input type="checkbox" name="deletion" value="'.$user.'" />'.
1.83 bisitz 2670: $lt{'dele'}.'</label></span>');
1.36 raeburn 2671: if ($specificity eq 'Yes') {
1.83 bisitz 2672: $r->print('<br /><span class="LC_nobreak"><label>'.
1.5 raeburn 2673: '<input type="checkbox" name="changepriv" value="'.$user.'" />'.$lt{'chpr'}.
1.83 bisitz 2674: '</label></span>');
1.36 raeburn 2675: }
2676: $r->print('
1.48 albertel 2677: </td>'.
2678: '<td>'.$fullname.'</td>'.
2679: '<td>'.$uname.'</td>'.
2680: '<td>'. $udom.'</td>'.
2681: '<td>'.$id.'</td>'.
2682: '<td>'.$start.'</td>'.
2683: '<td>'.$end.'</td>');
1.36 raeburn 2684: if ($hastools) {
1.83 bisitz 2685: $r->print('<td align="left"><span class="LC_nobreak">'.
1.6 raeburn 2686: ' ');
1.36 raeburn 2687: foreach my $tool (@{$$current{$user}{currtools}}) {
2688: if ($granularity eq 'Yes') {
2689: $r->print('<label><input type="checkbox" '.
1.7 raeburn 2690: 'checked="checked" '.
2691: 'name="user_'.$tool.'" value="'.
2692: $user.'" />'.$tool.'</label>');
1.36 raeburn 2693: } else {
2694: $r->print('<input type="hidden" '.
1.7 raeburn 2695: 'checked="checked" '.
2696: 'name="user_'.$tool.'" value="'.
2697: $user.'" />'.$tool);
1.36 raeburn 2698: }
2699: $r->print(' ');
1.5 raeburn 2700: }
1.83 bisitz 2701: $r->print('</span></td>');
1.36 raeburn 2702: }
2703: if ($addtools) {
1.48 albertel 2704: $r->print('<td align="left">');
1.36 raeburn 2705: if ($granularity eq 'Yes') {
2706: foreach my $tool (@{$$current{$user}{newtools}}) {
1.83 bisitz 2707: $r->print('<span class="LC_nobreak"><label><input type="checkbox"
1.5 raeburn 2708: name="user_'.$tool.'" value="'.
2709: $user.'" />'.$tool.
1.83 bisitz 2710: '</label></span> ');
1.36 raeburn 2711: }
2712: } else {
2713: foreach my $tool (@{$$current{$user}{newtools}}) {
1.83 bisitz 2714: $r->print('<span class="LC_nobreak"><input type="hidden"
1.5 raeburn 2715: name="user_'. $tool.'" value="'.
2716: $user.'" />'.$tool.
1.83 bisitz 2717: '</span> ');
1.5 raeburn 2718: }
2719: }
1.48 albertel 2720: $r->print('</td>');
1.5 raeburn 2721: }
1.48 albertel 2722: $r->print(&Apache::loncommon::end_data_table_row()."\n");
1.5 raeburn 2723: }
1.36 raeburn 2724: }
1.48 albertel 2725: $r->print(&Apache::loncommon::end_data_table());
1.53 raeburn 2726: } else {
2727: $r->print(&mt('There are no active, future or previous group members to modify.'));
1.5 raeburn 2728: }
1.53 raeburn 2729: return $numcurrent;
1.5 raeburn 2730: }
2731:
2732: sub check_uncheck_buttons {
2733: my ($r,$formname,$field,$title,$colspan) = @_;
2734: $r->print('
2735: <td '.$colspan.'>
2736: <fieldset>
1.102 bisitz 2737: <legend>'.$title.'</legend>
1.83 bisitz 2738: <span class="LC_nobreak">
1.80 bisitz 2739: <input type="button" value="'.&mt('check all').'"
1.5 raeburn 2740: onclick="javascript:checkAll(document.'.$formname.'.'.$field.')" />
2741:
1.80 bisitz 2742: <input type="button" value="'.&mt('uncheck all').'"
1.5 raeburn 2743: onclick="javascript:uncheckAll(document.'.$formname.'.'.$field.')" />
1.83 bisitz 2744: </span>
1.5 raeburn 2745: </fieldset>
2746: </td>
2747: ');
2748: }
2749:
2750:
2751: sub change_privs_form {
1.45 albertel 2752: my ($r,$cdom,$cnum,$action,$formname,$page,$startdate,$enddate,
2753: $tools,$functions,$toolprivs,$fixedprivs,$userdata,$usertools,
2754: $memchg,$idx,$states,$stored,$sectioncount,$navbuttons,$gpterm,
2755: $ucgpterm) = @_;
1.5 raeburn 2756: my @regexps = ('userpriv_');
2757: my $nexttext;
1.6 raeburn 2758: my %lt = &Apache::lonlocal::texthash(
2759: 'tode' => 'To be deleted',
2760: 'toex' => 'To be expired',
1.29 raeburn 2761: 'nome' => "No members to be deleted or expired from the $gpterm.",
1.6 raeburn 2762: );
1.5 raeburn 2763: $r->print(&Apache::lonhtmlcommon::echo_form_input(
1.6 raeburn 2764: ['origin','action','state','page','sortby'],\@regexps));
2765: if ($env{'form.branch'} eq 'adds') {
2766: $nexttext = $$navbuttons{'adme'};
2767: } else {
2768: $nexttext = $$navbuttons{'mose'};
2769: }
1.78 raeburn 2770: $r->print(&Apache::lonhtmlcommon::topic_bar(3,&mt('Members to delete or expire')));
1.6 raeburn 2771: my $exp_or_del = 0;
2772: if (ref($$memchg{'deletion'}) eq 'ARRAY') {
2773: if (@{$$memchg{'deletion'}} > 0) {
1.50 albertel 2774: $r->print('<b>'.$lt{'tode'}.':</b><br /><ul>');
1.6 raeburn 2775: foreach my $user (@{$$memchg{'deletion'}}) {
2776: $r->print('<li>'.$$userdata{$user}[$$idx{fullname}].
2777: ' ('.$user.')</li>');
2778: }
1.45 albertel 2779: $r->print('</ul>');
1.6 raeburn 2780: $exp_or_del += @{$$memchg{'deletion'}};
2781: }
2782: }
2783: if (ref($$memchg{'expire'}) eq 'ARRAY') {
2784: if (@{$$memchg{'expire'}} > 0) {
1.50 albertel 2785: $r->print('<b>'.$lt{'toex'}.':</b><br /><ul>');
1.6 raeburn 2786: foreach my $user (@{$$memchg{'expire'}}) {
2787: $r->print('<li>'.$$userdata{$user}[$$idx{fullname}].
2788: ' ('.$user.')</li>');
2789: }
1.45 albertel 2790: $r->print('</ul>');
1.6 raeburn 2791: $exp_or_del += @{$$memchg{'expire'}};
2792: }
2793: }
2794: if (!$exp_or_del) {
1.45 albertel 2795: $r->print($lt{'nome'}.'<br />');
1.6 raeburn 2796: }
1.5 raeburn 2797:
1.78 raeburn 2798: $r->print(&Apache::lonhtmlcommon::topic_bar(4,&mt('Setting optional privileges for specific group members')));
1.6 raeburn 2799:
1.45 albertel 2800: my $numchgs = &member_privileges_form($r,$action,$formname,$tools,
1.6 raeburn 2801: $toolprivs,$fixedprivs,$userdata,
2802: $usertools,$idx,$memchg,$states,
1.45 albertel 2803: $stored,$gpterm);
1.5 raeburn 2804: my $prevtext = $$navbuttons{'gtps'};
1.6 raeburn 2805: if ($numchgs || $exp_or_del) {
2806: &display_navbuttons($r,$formname,$$states{$action}[$page-1],$prevtext,
2807: $$states{$action}[$page+1],$nexttext);
2808: } else {
2809: &display_navbuttons($r,$formname,$$states{$action}[$page-1],$prevtext);
2810: }
1.5 raeburn 2811: return;
2812: }
2813:
2814: sub add_members_form {
1.59 raeburn 2815: my ($r,$cdom,$cnum,$action,$formname,$page,$startdate,$enddate,$groupname,
1.29 raeburn 2816: $description,$granularity,$quota,$sectioncount,$tools,$functions,
1.104 raeburn 2817: $stored,$states,$navbuttons,$gpterm,$ucgpterm,$crstype)=@_;
1.40 albertel 2818: $r->print(' <br />');
1.5 raeburn 2819: my @available = ();
2820: my @unavailable = ();
2821: &check_tools($functions,$tools,\@available,\@unavailable);
1.40 albertel 2822: &print_current_settings($r,$action,$functions,$startdate,$enddate,
2823: $groupname,$description,$granularity,$quota,
2824: \@available,\@unavailable,$gpterm,$ucgpterm);
1.59 raeburn 2825: &membership_options($r,$cdom,$cnum,$action,$formname,$sectioncount,1,$gpterm,
1.104 raeburn 2826: $ucgpterm,$crstype);
1.5 raeburn 2827: my $nexttext = $$navbuttons{'gtns'};
2828: my $prevtext = $$navbuttons{'gtpp'};
2829: &display_navbuttons($r,$formname,$$states{$action}[$page-1],$prevtext,
2830: $$states{$action}[$page+1],$nexttext);
2831: return;
2832: }
2833:
2834: sub choose_privs_form {
1.45 albertel 2835: my ($r,$cdom,$cnum,$action,$formname,$page,$startdate,$enddate,
2836: $tools,$functions,$toolprivs,$fixedprivs,$userdata,$usertools,$idx,
2837: $states,$stored,$sectioncount,$navbuttons,$gpterm,$ucgpterm,
2838: $crstype) = @_;
1.5 raeburn 2839:
2840: my @regexps = ('userpriv_');
2841: my $nexttext;
2842:
2843: if ($action eq 'create') {
2844: push(@regexps,'sec_');
2845: $r->print(&Apache::lonhtmlcommon::echo_form_input(
1.6 raeburn 2846: ['origin','action','state','page','sortby','autoadd','autodrop'],
1.5 raeburn 2847: \@regexps));
2848: $nexttext = $$navbuttons{'crgr'};
2849: } else {
2850: $r->print(&Apache::lonhtmlcommon::echo_form_input(
1.6 raeburn 2851: ['origin','action','state','page','sortby'],\@regexps));
1.5 raeburn 2852: $nexttext = $$navbuttons{'adme'};
2853: }
2854:
1.78 raeburn 2855: $r->print(&Apache::lonhtmlcommon::topic_bar(6,&mt('Setting optional privileges for specific group members')));
1.5 raeburn 2856:
1.45 albertel 2857: &member_privileges_form($r,$action,$formname,$tools,$toolprivs,
1.5 raeburn 2858: $fixedprivs,$userdata,$usertools,$idx,undef,
1.45 albertel 2859: $states,$stored,$gpterm);
1.5 raeburn 2860:
2861: if ($action eq 'create') {
1.53 raeburn 2862: my $img1 = 7;
2863: my $img2 = 8;
2864: &mapping_options($r,$action,$formname,$page,$sectioncount,
2865: $states,$stored,$navbuttons,$img1,$img2,
1.58 raeburn 2866: $gpterm,$ucgpterm,$crstype,$cdom,$cnum);
1.5 raeburn 2867: }
2868: my $prevtext = $$navbuttons{'gtps'};
2869: &display_navbuttons($r,$formname,$$states{$action}[$page-1],$prevtext,
2870: $$states{$action}[$page+1],$nexttext);
2871: return;
2872: }
2873:
2874: sub build_boxes {
2875: my ($r,$tools,$usertools,$fixedprivs,$toolprivs,$showtools,
1.6 raeburn 2876: $showboxes,$prefix,$specificity,$excluded) = @_;
1.5 raeburn 2877: my $totalboxes = 0;
2878: if (@{$tools} > 0) {
2879: if ($specificity eq 'Yes') {
2880: foreach my $tool (@{$tools}) {
2881: @{$$showboxes{$tool}} = ();
2882: foreach my $user (sort(keys(%{$usertools}))) {
1.6 raeburn 2883: if (ref($excluded) eq 'ARRAY') {
2884: if (grep/^$user$/,@{$excluded}) {
2885: next;
2886: }
1.5 raeburn 2887: }
1.6 raeburn 2888: if ($$usertools{$user}{$tool}) {
2889: unless (grep/^$tool$/,@{$showtools}) {
2890: push(@{$showtools},$tool);
2891: }
2892: foreach my $priv (sort(keys(%{$$toolprivs{$tool}}))) {
2893: unless (exists($$fixedprivs{$tool}{$priv})) {
2894: unless(grep(/^$priv$/,@{$$showboxes{$tool}})) {
2895: push(@{$$showboxes{$tool}},$priv);
2896: $totalboxes ++;
2897: }
1.5 raeburn 2898: }
2899: }
2900: }
2901: }
2902: }
2903: if ($totalboxes > 0) {
2904: $r->print('
2905: <script type="text/javascript">
2906: function checkAllTools(formname) {
2907: ');
2908: foreach my $tool (sort(keys(%{$showboxes}))) {
2909: foreach my $priv (@{$$showboxes{$tool}}) {
2910: $r->print(' checkAll(formname.'.$prefix.$priv.');'."\n");
2911: }
2912: }
2913: $r->print('
2914: }
2915: function uncheckAllTools(formname) {
2916: ');
2917: foreach my $tool (sort(keys(%{$showboxes}))) {
2918: foreach my $priv (@{$$showboxes{$tool}}) {
2919: $r->print(' uncheckAll(formname'.$prefix.$priv.');'."\n");
2920: }
2921: }
2922: $r->print('
2923: }
2924: </script>
2925: ');
2926: }
2927: }
2928: }
2929: return $totalboxes;
2930: }
2931:
2932: sub member_privileges_form {
1.45 albertel 2933: my ($r,$action,$formname,$tools,$toolprivs,$fixedprivs,$userdata,
2934: $usertools,$idx,$memchg,$states,$stored,$gpterm) = @_;
1.5 raeburn 2935: my %lt = &Apache::lonlocal::texthash(
2936: 'addp' => 'Additional privileges',
1.53 raeburn 2937: 'fixp' => 'Core privileges',
1.5 raeburn 2938: 'oppr' => 'Optional privileges',
1.53 raeburn 2939: 'func' => 'Tool',
2940: 'forf' => 'For the collaborative tools included for group '.
2941: 'members being added or modified, '.
2942: 'there are no optional privileges to set '.
2943: 'for specific members.',
1.80 bisitz 2944: 'algr' => 'All new group members will receive the same privileges.',
2945: 'ifex' => 'If previously expired members are being re-enabled, or '.
1.54 raeburn 2946: 'if access for future members is being activated now, '.
2947: 'previously set privileges will be preserved.',
1.53 raeburn 2948: 'asno' => 'As no group members are being added, '.
2949: 'there are no specific user privileges to set.',
2950: 'asng' => 'As no group tools will be made available to users, '.
2951: 'there are no specific user privileges to set.',
2952: 'nogm' => 'No group member privileges to display or set, '.
2953: 'as you have not indicated that you will be activating,'.
2954: ' re-enabling, changing privileges, or adding/removing '.
2955: 'tools for any current members.',
1.5 raeburn 2956: 'full' => 'Fullname',
2957: 'user' => 'Username',
2958: 'doma' => 'Domain',
2959: );
2960: my @defprivs;
2961: my $specificity;
2962: if ($action eq 'create') {
2963: if (defined($env{'form.defpriv'})) {
2964: @defprivs = &Apache::loncommon::get_env_multiple('form.defpriv');
2965: }
2966: $specificity = $env{'form.specificity'};
2967: } else {
1.17 raeburn 2968: if (defined($$stored{'defpriv'})) {
2969: @defprivs = @{$$stored{'defpriv'}};
2970: }
1.5 raeburn 2971: $specificity = $$stored{'specificity'};
2972: }
2973: my @showtools;
2974: my %showboxes = ();
2975: my $numtools = 1 + @{$tools};
1.3 raeburn 2976:
1.6 raeburn 2977: my @excluded = ();
2978: my $numchgs = 0;
2979: if ($formname eq 'change_privs') {
2980: my @currmembers = ();
2981: if (ref($$memchg{'deletion'}) eq 'ARRAY') {
2982: push(@excluded,@{$$memchg{'deletion'}});
2983: }
2984: if (ref($$memchg{'expire'}) eq 'ARRAY') {
2985: push(@excluded,@{$$memchg{'expire'}});
2986: }
2987: if (@excluded > 0) {
2988: foreach my $user (sort(keys(%{$usertools}))) {
2989: if (grep/^$user$/,@excluded) {
2990: next;
2991: }
2992: push(@currmembers,$user);
2993: }
2994: } else {
2995: @currmembers = sort(keys(%{$usertools}));
2996: }
2997: $numchgs = @currmembers;
2998: if (!$numchgs) {
1.45 albertel 2999: $r->print($lt{'nogm'});
1.6 raeburn 3000: return $numchgs;
3001: }
3002: }
3003:
3004: my $totalboxes = &build_boxes($r,$tools,$usertools,$fixedprivs,
3005: $toolprivs,\@showtools,\%showboxes,
3006: 'userpriv_',$specificity,\@excluded);
1.5 raeburn 3007: if (@{$tools} > 0) {
3008: if ($specificity eq 'Yes') {
3009: if ($totalboxes > 0) {
3010: my $numcells = 2;
3011: my $colspan = $numcells + 1;
3012: my %total;
1.6 raeburn 3013: if (keys(%{$usertools}) > 1) {
3014: $r->print('
1.45 albertel 3015: <table border="0" cellspacing="2" cellpadding="2">
1.5 raeburn 3016: <tr>
3017: ');
1.6 raeburn 3018: foreach my $tool (@{$tools}) {
3019: if (@{$showboxes{$tool}} > 0) {
3020: $r->print('<td valign="top">');
1.100 bisitz 3021: $r->print('<fieldset><legend>'.&mt($tool).'</legend>');
3022: $r->print('<table><tr>');
1.6 raeburn 3023: my $privcount = 0;
3024: foreach my $priv (@{$showboxes{$tool}}) {
3025: $privcount ++;
3026: if (($privcount == @{$showboxes{$tool}}) &&
3027: ($privcount > 1)) {
3028: if ($privcount%$numcells) {
3029: $r->print('<td colspan="'.$colspan.'">');
3030: } else {
3031: $r->print('<td>');
3032: }
1.5 raeburn 3033: } else {
3034: $r->print('<td>');
3035: }
1.80 bisitz 3036: $r->print(
1.102 bisitz 3037: '<fieldset><legend>'.&mt($$toolprivs{$tool}{$priv}).'</legend>'
1.80 bisitz 3038: .'<span class="LC_nobreak">'
3039: .' <input type="button" value="'.&mt('check all').'"'
3040: .' onclick="javascript:checkAll(document.'.$formname.'.userpriv_'.$priv.')" />'
3041: .' '
3042: .'<input type="button" value="'.&mt('uncheck all').'"'
3043: .' onclick="javascript:uncheckAll(document.'.$formname.'.userpriv_'.$priv.')" />'
3044: .'</span></fieldset><br />'
3045: );
1.6 raeburn 3046: $r->print('</td>');
3047: if ($privcount < @{$showboxes{$tool}}) {
3048: if (@{$showboxes{$tool}} > 2) {
3049: if ($privcount%$numcells == 0) {
3050: $r->print('</tr><tr>');
3051: }
3052: } else {
3053: $r->print('<tr></tr>');
1.5 raeburn 3054: }
3055: }
3056: }
1.100 bisitz 3057: $r->print('</tr></table></fieldset></td><td> </td>');
1.5 raeburn 3058: }
3059: }
1.45 albertel 3060: $r->print('</tr></table>');
1.5 raeburn 3061: }
1.45 albertel 3062: $r->print(&Apache::loncommon::start_data_table().
3063: &Apache::loncommon::start_data_table_header_row());
1.5 raeburn 3064: $r->print(<<"END");
1.45 albertel 3065: <th>$lt{'full'}</th>
3066: <th>$lt{'user'}</th>
1.5 raeburn 3067: <th>$lt{'doma'}</th>
3068: <th colspan="$numtools">$lt{'addp'}</th>
3069: END
1.45 albertel 3070: $r->print(&Apache::loncommon::end_data_table_header_row());
3071: &member_privs_entries($r,$usertools,$toolprivs,$fixedprivs,
1.6 raeburn 3072: $userdata,$idx,\@showtools,\@defprivs,
3073: \@excluded);
1.45 albertel 3074: $r->print(&Apache::loncommon::end_data_table());
1.5 raeburn 3075: } else {
1.43 albertel 3076: $r->print($lt{'forf'}.'<br />');
1.45 albertel 3077: &display_defprivs($r,$tools,$toolprivs,\@defprivs);
1.5 raeburn 3078: }
3079: } else {
3080: if (keys(%{$usertools}) > 0) {
1.54 raeburn 3081: $r->print($lt{'algr'}.'<br />'.$lt{'ifex'}.'<br /><br />');
1.45 albertel 3082: &display_defprivs($r,$tools,$toolprivs,\@defprivs);
1.5 raeburn 3083: } else {
1.43 albertel 3084: $r->print($lt{'asno'}.'<br />');
1.5 raeburn 3085: }
3086: }
3087: } else {
1.43 albertel 3088: $r->print($lt{'asng'});
1.5 raeburn 3089: }
1.6 raeburn 3090: return $numchgs;
1.1 raeburn 3091: }
3092:
1.5 raeburn 3093: sub process_request {
1.45 albertel 3094: my ($r,$cdom,$cnum,$action,$state,$page,$groupname,$description,
1.5 raeburn 3095: $specificity,$userdata,$startdate,$enddate,$tools,$functions,$toolprivs,
3096: $usertools,$idx,$types,$roles,$sections,$states,$navbuttons,$memchg,
1.45 albertel 3097: $sectioncount,$stored,$gpterm,$ucgpterm,$crstype) = @_;
1.3 raeburn 3098:
3099: $r->print(&Apache::lonhtmlcommon::echo_form_input(
1.6 raeburn 3100: ['origin','action','state','page','sortby']));
1.5 raeburn 3101:
1.29 raeburn 3102: my $earlyout = &validate_groupname($groupname,$action,$cdom,$cnum,$gpterm,
3103: $ucgpterm,$crstype);
1.5 raeburn 3104: if ($earlyout) {
3105: $r->print('
3106: <table width="100%" cellpadding="0" cellspacing="0" border="0">
3107: <tr>
3108: <td> </td>
3109: <td colspan="3">
3110: '.$earlyout.'</td></tr>');
3111: &display_navbuttons($r,$state,$$states{$action}[$page-1],
3112: $$navbuttons{'gtps'});
3113: $r->print('</table>');
3114: return;
3115: }
3116:
3117: my @defprivs = ();
3118: if ($action eq 'create' || $state eq 'chgresult') {
3119: if (defined($env{'form.defpriv'})) {
3120: @defprivs = &Apache::loncommon::get_env_multiple('form.defpriv');
3121: }
3122: if ($state eq 'chgresult') {
3123: my @okprivs = ();
3124: foreach my $tool (@{$tools}) {
3125: foreach my $priv (sort(keys(%{$$toolprivs{$tool}}))) {
3126: push(@okprivs,$priv);
3127: }
3128: }
3129: my @temp = ();
3130: foreach my $defpriv (@defprivs) {
3131: if (grep/^$defpriv$/,@okprivs) {
3132: push(@temp,$defpriv);
3133: }
3134: }
3135: @defprivs = @temp;
3136: }
3137: } else {
1.17 raeburn 3138: if (defined($$stored{'defpriv'})) {
3139: @defprivs = @{$$stored{'defpriv'}};
3140: }
1.5 raeburn 3141: }
3142:
3143: my $outcome;
3144: if ($action eq 'create' || $state eq 'chgresult') {
3145: $outcome = &write_group_data($r,$cdom,$cnum,$action,$state,$groupname,
3146: $description,$startdate,$enddate,
3147: $specificity,$functions,$tools,
3148: $sectioncount,$roles,$types,$sections,
1.29 raeburn 3149: \@defprivs,$stored,$gpterm,$ucgpterm,
3150: $crstype);
1.5 raeburn 3151: }
3152: if (($action eq 'create' && $outcome eq 'ok') || (($action eq 'modify') &&
3153: (($state eq 'memresult') || ($state eq 'addresult')))) {
1.6 raeburn 3154: &process_membership($r,$cdom,$cnum,$action,$state,$groupname,$tools,
3155: $enddate,$startdate,$userdata,$idx,$toolprivs,
1.29 raeburn 3156: $usertools,$specificity,\@defprivs,$memchg,$gpterm,
1.104 raeburn 3157: $ucgpterm,$crstype);
1.5 raeburn 3158: }
3159: return;
3160: }
3161:
3162: sub write_group_data {
3163: my ($r,$cdom,$cnum,$action,$state,$groupname,$description,$startdate,
3164: $enddate,$specificity,$functions,$tools,$sectioncount,$roles,$types,
1.29 raeburn 3165: $sections,$defprivs,$stored,$gpterm,$ucgpterm,$crstype) = @_;
1.5 raeburn 3166: my $now = time;
3167: my $creation = $now;
3168: my $creator = $env{'user.name'}.':'.$env{'user.domain'};
3169: if ($state eq 'chgresult') {
3170: $creation = $$stored{'creation'};
3171: $creator = $$stored{'creator'};
3172: }
1.24 www 3173: my $esc_description = &escape($description);
1.5 raeburn 3174: my @single_attributes = ('description','functions','startdate','enddate',
3175: 'creation','modified','creator','granularity',
1.29 raeburn 3176: 'specificity','autoadd','autodrop','quota');
1.5 raeburn 3177: my @mult_attributes = ('roles','types','sectionpick','defpriv');
1.15 albertel 3178:
1.37 raeburn 3179: my ($crsquota,$freespace,$maxposs) = &get_quota_constraints($action,
3180: $stored);
3181: my $quota = $env{'form.quota'};
3182:
3183: $quota =~ s/^\s*([^\s]*)\s*$/$1/;
3184: if ($quota eq '') {
3185: $quota = 0;
3186: }
3187: if ($quota !~ /^\d*\.?\d*$/) {
3188: $quota = 0;
1.79 bisitz 3189: $r->print('<div class="LC_warning">'
1.96 weissno 3190: .&mt('The value you entered for the quota for the group portfolio in this '.$gpterm
1.79 bisitz 3191: .' contained invalid characters, so it has been set to 0 Mb. You can change this by'
3192: .' modifying the '.$gpterm.' settings.')
3193: .'</div>');
1.37 raeburn 3194: }
3195: if ($quota > $maxposs) {
3196: $quota = $maxposs;
1.79 bisitz 3197: $r->print('<div class="LC_warning">'
1.96 weissno 3198: .&mt('The value you entered for the quota for the group portfolio in this '.$gpterm
1.79 bisitz 3199: .' exceeded the maximum possible value, so it has been set to [_1] Mb '
3200: .'(the maximum possible value).',sprintf("%.2f",$maxposs))
3201: .'</div>');
1.37 raeburn 3202: }
1.5 raeburn 3203: my %groupinfo = (
3204: description => $esc_description,
3205: startdate => $startdate,
3206: enddate => $enddate,
3207: creation => $creation,
3208: modified => $now,
3209: creator => $creator,
3210: granularity => $env{'form.granularity'},
3211: specificity => $specificity,
3212: autoadd => $env{'form.autoadd'},
3213: autodrop => $env{'form.autodrop'},
1.37 raeburn 3214: quota => $quota,
1.5 raeburn 3215: );
1.37 raeburn 3216:
1.5 raeburn 3217: foreach my $func (keys(%{$functions})) {
3218: my $status;
3219: if (grep(/^$func$/,@{$tools})) {
3220: $status = 'on';
3221: } else {
3222: $status = 'off';
3223: }
3224: $groupinfo{'functions'} .= qq|<name id="$func">$status</name>|;
3225: }
3226:
3227: $groupinfo{'roles'} = $roles;
3228: $groupinfo{'types'} = $types;
3229: $groupinfo{'sectionpick'} = $sections;
3230: $groupinfo{'defpriv'} = $defprivs;
3231:
3232: my %groupsettings = ();
3233: foreach my $item (@single_attributes) {
3234: $groupsettings{$groupname} .= qq|<$item>$groupinfo{$item}</$item>|;
3235: }
3236: foreach my $item (@mult_attributes) {
3237: foreach my $entry (@{$groupinfo{$item}}) {
3238: $groupsettings{$groupname} .= qq|<$item>$entry</$item>|;
3239: }
3240: }
3241: my $autosec;
3242: my @autorole = &Apache::loncommon::get_env_multiple('form.autorole');
1.15 albertel 3243:
1.5 raeburn 3244: foreach my $role (@autorole) {
3245: if (defined($env{'form.sec_'.$role})) {
3246: my @autosections=&Apache::loncommon::get_env_multiple('form.sec_'.
3247: $role);
3248: $autosec .= '<role id="'.$role.'">';
3249: foreach my $sec (@autosections) {
3250: $autosec .= '<section>'.$sec.'</section>';
3251: }
3252: $autosec .= '</role>';
3253: }
3254: }
3255: if ($autosec) {
3256: $groupsettings{$groupname} .= qq|<autosec>$autosec</autosec>|;
3257: }
3258: my $result = &Apache::lonnet::modify_coursegroup($cdom,$cnum,
3259: \%groupsettings);
3260:
3261: if ($result eq 'ok') {
3262: if ($action eq 'create') {
1.32 raeburn 3263: my $result = &add_group_folder($cdom,$cnum,$now,$groupname,$action,
3264: $description,$tools,\%groupinfo,
3265: $gpterm,$ucgpterm,$crstype);
1.79 bisitz 3266: if ($result eq 'ok') {
1.109 wenzelju 3267: my $msg = &Apache::lonhtmlcommon::confirm_success(&mt($ucgpterm.' [_1] was created.','<i>'.$groupname.'</i>'));
3268: $msg = &Apache::loncommon::confirmwrapper($msg);
3269: $r->print($msg);
1.79 bisitz 3270: } else {
1.109 wenzelju 3271: my $msg = &Apache::lonhtmlcommon::confirm_success(&mt('A problem occurred when creating folders for the new '.$gpterm.' [_1]:'
3272: ,'<i>'.$groupname.'</i>')
3273: .'<br />'.$result,1);
3274: $msg = &Apache::loncommon::confirmwrapper($msg);
3275: $r->print($msg);
1.32 raeburn 3276: }
1.56 raeburn 3277: } elsif ($action eq 'modify') {
3278: my (@oldtools,@newtools);
3279: if (ref($$stored{'tool'}) eq 'ARRAY') {
3280: @oldtools = @{$$stored{'tool'}};
3281: }
3282: if (ref($tools) eq 'ARRAY') {
3283: @newtools = @{$tools};
3284: }
3285: if (!grep(/^discussion$/,@oldtools) &&
3286: grep(/^discussion$/,@newtools)) {
3287: my $crspath = '/uploaded/'.$cdom.'/'.$cnum.'/';
3288: my $boardsmap = $crspath.'group_boards_'.$groupname.'.sequence';
3289: my $navmap = Apache::lonnavmaps::navmap->new();
1.85 raeburn 3290: my ($bbmapres,$error);
3291: if (defined($navmap)) {
3292: $bbmapres = $navmap->getResourceByUrl($boardsmap);
3293: undef($navmap);
3294: if (!$bbmapres) {
3295: my $grpmap = $crspath.'group_folder_'.$groupname.'.sequence';
3296: my $disctitle = &mt('Discussion Boards');
3297: my $outcome = &map_updater($cdom,$cnum,'group_boards_'.
3298: $groupname.'.sequence','bbseq',
3299: $disctitle,$grpmap);
3300: my ($furl,$ferr) =
3301: &Apache::lonuserstate::readmap($cdom.'/'.$cnum);
3302: # modify parameter
3303: if ($outcome eq 'ok') {
3304: $navmap = Apache::lonnavmaps::navmap->new();
3305: if (defined($navmap)) {
3306: my $parm_result = &parm_setter($navmap,$cdom,$boardsmap,
3307: $groupname);
3308: if ($parm_result) {
3309: $error = &mt('An error occurred while setting parameters '
3310: .'for Discussion Boards folder: '
3311: .'[_1]',$parm_result);
3312: } else {
3313: $r->print('<div class="LC_success">'.
3314: &mt('Discussion Boards Folder created.')
3315: .'</div>');
3316: }
3317: undef($navmap);
3318: } else {
1.104 raeburn 3319: if ($crstype eq 'Community') {
3320: $error = &mt("An error occurred while setting parameters '.
1.85 raeburn 3321: 'for Discussion Boards folder: '.
1.104 raeburn 3322: 'Could not retrieve community information");
3323: } else {
3324: $error = &mt("An error occurred while setting parameters '.
3325: 'for Discussion Boards folder: '.
3326: 'Could not retrieve course information");
3327: }
1.85 raeburn 3328: }
1.56 raeburn 3329: } else {
1.85 raeburn 3330: $r->print($outcome);
1.56 raeburn 3331: }
3332: }
1.85 raeburn 3333: } else {
1.104 raeburn 3334: $error = &mt("An error occurred while retrieving the contents of the group's folder.").'<br />';
3335: if ($crstype eq 'Community') {
3336: $error .= &mt("You need to re-initialize the community.");
3337:
3338: } else {
3339: $error .= &mt("You need to re-initialize the course.");
3340: }
1.85 raeburn 3341: }
3342: if ($error ne '') {
3343: $r->print('<div class="LC_error">'.$error.'</div>');
1.56 raeburn 3344: }
3345: }
1.109 wenzelju 3346: my $message = &Apache::lonhtmlcommon::confirm_success(&mt($ucgpterm.' [_1] was updated.','<i>'.$groupname.'</i>'));
3347: $message = &Apache::loncommon::confirmwrapper($message);
3348: $r->print($message);
1.5 raeburn 3349: }
3350: } else {
3351: my %actiontype = (
3352: 'create' => 'creating',
3353: 'modify' => 'modifying',
3354: );
1.29 raeburn 3355: &Apache::lonnet::logthis("Failed to store $gpterm $groupname ".
3356: 'in '.lc($crstype).': '.$cnum.
3357: ' in domain: '.$cdom);
1.79 bisitz 3358: $r->print('<div class="LC_error">'
3359: .&mt('An error occurred when [_1] the '.$gpterm.'. '
3360: .'Please try again.',$actiontype{$action})
3361: .'</div>');
1.5 raeburn 3362: }
3363: return $result;
3364: }
3365:
3366: sub process_membership {
1.6 raeburn 3367: my ($r,$cdom,$cnum,$action,$state,$groupname,$tools,$enddate,$startdate,
1.29 raeburn 3368: $userdata,$idx,$toolprivs,$usertools,$specificity,$defprivs,$memchg,
1.104 raeburn 3369: $gpterm,$ucgpterm,$crstype)=@_;
1.5 raeburn 3370: my %usersettings = ();
1.6 raeburn 3371: my %added= ();
3372: my %failed = ();
3373: my $num_ok = 0;
3374: my $num_fail = 0;
1.3 raeburn 3375: my %group_privs = ();
1.20 raeburn 3376: my %curr_privs = ();
1.21 raeburn 3377: my %curr_start = ();
3378: my %curr_end = ();
1.3 raeburn 3379: my %tooltype = ();
1.77 raeburn 3380: my $context = 'processgroupmembership';
1.5 raeburn 3381:
1.3 raeburn 3382: foreach my $tool (@{$tools}) {
3383: foreach my $priv (sort(keys(%{$$toolprivs{$tool}}))) {
3384: $tooltype{$priv} = $tool;
1.5 raeburn 3385: if ($specificity eq 'Yes') {
1.3 raeburn 3386: my @users =
3387: &Apache::loncommon::get_env_multiple('form.userpriv_'.$priv);
3388: foreach my $user (@users) {
3389: $group_privs{$user} .= $priv.':';
1.8 raeburn 3390: if ($state eq 'memresult') {
3391: unless (exists($$usertools{$user}{$tool})) {
3392: $$usertools{$user}{$tool} = 1;
3393: }
3394: }
1.3 raeburn 3395: }
3396: } else {
1.5 raeburn 3397: if (@{$defprivs} > 0) {
1.26 raeburn 3398: if (grep/^\Q$priv\E$/,@{$defprivs}) {
1.5 raeburn 3399: foreach my $user (sort(keys(%{$usertools}))) {
3400: if ($$usertools{$user}{$tool}) {
3401: $group_privs{$user} .= $priv.':';
3402: }
1.3 raeburn 3403: }
3404: }
3405: }
3406: }
3407: }
3408: }
3409: foreach my $user (keys(%group_privs)) {
3410: $group_privs{$user} =~ s/:$//;
3411: }
1.5 raeburn 3412:
1.6 raeburn 3413: my $now = time;
3414: my @activate = ();
3415: my @expire = ();
3416: my @deletion = ();
3417: my @reenable = ();
1.20 raeburn 3418: my @unchanged = ();
1.6 raeburn 3419: if ($state eq 'memresult') {
3420: if (ref($$memchg{'activate'}) eq 'ARRAY') {
3421: @activate = @{$$memchg{'activate'}};
3422: }
3423: if (ref($$memchg{'expire'}) eq 'ARRAY') {
3424: @expire = @{$$memchg{'expire'}};
3425: }
3426: if (ref($$memchg{'deletion'}) eq 'ARRAY') {
3427: @deletion = @{$$memchg{'deletion'}};
3428: }
3429: if (ref($$memchg{'reenable'}) eq 'ARRAY') {
3430: @reenable = @{$$memchg{'reenable'}};
3431: }
1.20 raeburn 3432: my %membership = &Apache::lonnet::get_group_membership($cdom,$cnum,
3433: $groupname);
3434: foreach my $key (sort(keys(%membership))) {
3435: if ($key =~ /^\Q$groupname\E:([^:]+:[^:]+)$/) {
1.21 raeburn 3436: ($curr_end{$1},$curr_start{$1},$curr_privs{$1}) =
3437: split(/:/,$membership{$key},3);
1.20 raeburn 3438: }
3439: }
1.6 raeburn 3440: if (@expire + @deletion > 0) {
3441: foreach my $user (@expire) {
1.21 raeburn 3442: my $savestart = $curr_start{$user};
3443: if ($savestart > $now) {
3444: $savestart = $now;
1.6 raeburn 3445: }
1.21 raeburn 3446: $usersettings{$groupname.':'.$user} = $now.':'.$savestart.':'.
3447: $curr_privs{$user};
1.6 raeburn 3448: if (&Apache::lonnet::modify_group_roles($cdom,$cnum,$groupname,
1.21 raeburn 3449: $user,$now,$savestart,
1.77 raeburn 3450: $curr_privs{$user},'',$context) eq 'ok') {
1.6 raeburn 3451: push(@{$added{'expired'}},$user);
3452: $num_ok ++;
3453: } else {
3454: push(@{$failed{'expired'}},$user);
3455: $num_fail ++;
3456: }
3457: }
3458: foreach my $user (@deletion) {
3459: $usersettings{$groupname.':'.$user} = $now.':-1:';
3460: if (&Apache::lonnet::modify_group_roles($cdom,$cnum,$groupname,
1.76 raeburn 3461: $user,$now,'-1','','',$context)
1.6 raeburn 3462: eq 'ok') {
3463: push(@{$added{'deleted'}},$user);
3464: $num_ok ++;
3465: } else {
3466: push(@{$failed{'deleted'}},$user);
3467: $num_fail ++;
3468: }
3469: }
3470: }
1.8 raeburn 3471: }
1.6 raeburn 3472:
1.5 raeburn 3473: foreach my $user (sort(keys(%{$usertools}))) {
1.20 raeburn 3474: if ((grep(/^$user$/,@expire)) || (grep(/^$user$/,@deletion))) {
3475: next;
3476: }
1.6 raeburn 3477: my $type;
3478: my $start = $startdate;
3479: my $end = $enddate;
3480: if ($state eq 'memresult') {
3481: if (@activate > 0) {
3482: if (grep/^$user$/,@activate) {
3483: $start = $now;
1.21 raeburn 3484: $end = $enddate;
1.6 raeburn 3485: $type = 'activated';
3486: }
3487: }
3488: if (@reenable > 0) {
3489: if (grep/^$user$/,@reenable) {
1.21 raeburn 3490: $start = $startdate;
3491: $end = $enddate;
1.6 raeburn 3492: $type = 'reenabled';
3493: }
3494: }
1.38 raeburn 3495: if ($type eq '') {
3496: if ($curr_privs{$user} eq $group_privs{$user}) {
3497: push(@unchanged,$user);
3498: next;
3499: }
3500: if (exists($curr_start{$user})) {
3501: $start = $curr_start{$user};
3502: }
3503: if (exists($curr_end{$user})) {
3504: $end = $curr_end{$user};
3505: }
3506: $type = 'modified';
3507: }
1.6 raeburn 3508: } else {
3509: $type = 'added';
3510: }
3511: $usersettings{$groupname.':'.$user} = $end.':'.$start.':'.
1.5 raeburn 3512: $group_privs{$user};
3513: if (&Apache::lonnet::modify_group_roles($cdom,$cnum,$groupname,
1.6 raeburn 3514: $user,$end,$start,
1.76 raeburn 3515: $group_privs{$user},'',$context) eq 'ok') {
1.6 raeburn 3516: push(@{$added{$type}},$user);
3517: $num_ok ++;
1.3 raeburn 3518: } else {
1.6 raeburn 3519: push(@{$failed{$type}},$user);
3520: $num_fail ++;
1.5 raeburn 3521: }
3522: }
3523: my $roster_result = &Apache::lonnet::modify_coursegroup_membership($cdom,
3524: $cnum,\%usersettings);
1.6 raeburn 3525: if ($num_ok) {
1.109 wenzelju 3526: my $msgall ='';
3527: foreach my $type (sort(keys(%added))) {
3528: my $message = &mt('The following users were successfully [_1]',$type);
1.20 raeburn 3529: if (!($type eq 'deleted' || $type eq 'expired')) {
1.109 wenzelju 3530: $message .= &mt(' with the following privileges');
1.6 raeburn 3531: }
1.109 wenzelju 3532: $message .= ':<br/>';
1.6 raeburn 3533: foreach my $user (@{$added{$type}}) {
1.8 raeburn 3534: my $privlist = '';
3535: if (!($type eq 'deleted' || $type eq 'expired')) {
3536: $privlist = ': ';
1.6 raeburn 3537: my @privs = split(/:/,$group_privs{$user});
3538: my $curr_tool = '';
3539: foreach my $priv (@privs) {
3540: unless ($curr_tool eq $tooltype{$priv}) {
3541: $curr_tool = $tooltype{$priv};
3542: $privlist .= '<b>'.$curr_tool.'</b>: ';
3543: }
3544: $privlist .= $$toolprivs{$curr_tool}{$priv}.', ';
3545: }
3546: $privlist =~ s/, $//;
3547: }
1.109 wenzelju 3548: $message .= $$userdata{$user}[$$idx{fullname}].' - '.$user.$privlist.'<br />';
1.6 raeburn 3549: }
1.109 wenzelju 3550: $message .= '<br/>';
3551: $message = &Apache::lonhtmlcommon::confirm_success($message);
3552: $msgall .= $message;
1.6 raeburn 3553: }
1.109 wenzelju 3554: $msgall = &Apache::loncommon::confirmwrapper($msgall);
3555: $r->print($msgall);
1.6 raeburn 3556: }
3557: if ($num_fail) {
3558: foreach my $type (sort(keys(%failed))) {
1.79 bisitz 3559: $r->print('<div class="LC_error">'
3560: .&mt("The following users could not be $type, because an error occurred:")
3561: .'</div>');
1.6 raeburn 3562: foreach my $user (@{$failed{$type}}) {
3563: $r->print($$userdata{$user}[$$idx{fullname}].' - '.$user.'<br />');
3564: }
1.5 raeburn 3565: }
1.20 raeburn 3566: $r->print('<br />');
3567: }
1.109 wenzelju 3568: # Is that really needed?
3569: #
3570: # if (@unchanged > 0) {
3571: # $r->print(&mt('No change occurred for the following users:').'<br />');
3572: # foreach my $user (sort(@unchanged)) {
3573: # $r->print($$userdata{$user}[$$idx{fullname}].' - '.$user.'<br />');
3574: # }
3575: # $r->print('<br />');
3576: # }
1.5 raeburn 3577: if ($roster_result eq 'ok') {
1.80 bisitz 3578: $r->print('<div class="LC_success">'
3579: .&mt($ucgpterm.' membership list updated.')
3580: .'</div>');
1.104 raeburn 3581: $r->print('<p class="LC_info">');
3582: if ($crstype eq 'Community') {
3583: $r->print(&mt("Any currently logged in community users affected by the changes you made"
1.80 bisitz 3584: .' to group membership or privileges for the [_1] group will need to log out'
3585: .' and log back in for their LON-CAPA sessions to reflect these changes.'
1.104 raeburn 3586: ,'<i>'.$groupname.'</i>'));
3587:
3588: } else {
3589: $r->print(&mt("Any currently logged in course users affected by the changes you made"
3590: .' to group membership or privileges for the [_1] group will need to log out'
3591: .' and log back in for their LON-CAPA sessions to reflect these changes.'
3592: ,'<i>'.$groupname.'</i>'));
3593: }
3594: $r->print('</p>');
1.5 raeburn 3595: } else {
1.80 bisitz 3596: $r->print('<div class="LC_error">'
3597: .&mt("An error occurred while updating the $gpterm membership list:")
3598: .'<br />'.$roster_result
3599: .'</div>');
1.5 raeburn 3600: }
3601: return;
3602: }
3603:
3604: sub mapping_options {
1.44 albertel 3605: my ($r,$action,$formname,$page,$sectioncount,$states,$stored,
1.58 raeburn 3606: $navbuttons,$img1,$img2,$gpterm,$ucgpterm,$crstype,$cdom,$cnum) = @_;
1.5 raeburn 3607: my %lt = &Apache::lonlocal::texthash(
1.29 raeburn 3608: 'auto' => "Settings for automatic $gpterm enrollment",
3609: 'gmma' => "$ucgpterm membership mapping to specific sections/roles",
3610: 'endi' => "Enable/disable automatic $gpterm enrollment for ".
3611: "users in specified roles and sections",
1.53 raeburn 3612: '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 3613: '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.",
3614: 'pirs' => "Pick roles and sections for automatic $gpterm enrollment",
1.5 raeburn 3615: 'on' => 'on',
3616: 'off' => 'off',
1.29 raeburn 3617: 'auad' => "Automatically enable $gpterm membership when roles are added?",
3618: 'auex' => "Automatically expire $gpterm membership when roles are removed?",
3619: 'mapr' => "Mapping of roles and sections affected by automatic $gpterm enrollment/disenrollment follows scheme chosen below.",
1.5 raeburn 3620: );
1.44 albertel 3621: &automapping($r,$action,$stored,\%lt,$img1);
1.58 raeburn 3622: &mapping_settings($r,$sectioncount,\%lt,$stored,$img2,$crstype,$cdom,$cnum,
3623: $action);
1.5 raeburn 3624: return;
3625: }
3626:
3627: sub automapping {
1.44 albertel 3628: my ($r,$action,$stored,$lt,$image) = @_;
1.5 raeburn 3629: my $add = 'off';
3630: my $drop = 'off';
3631: if (exists($$stored{'autoadd'})) {
3632: $add = $$stored{'autoadd'};
3633: }
3634: if (exists($$stored{'autodrop'})) {
3635: $drop = $$stored{'autodrop'};
3636: }
1.78 raeburn 3637: $r->print(&Apache::lonhtmlcommon::topic_bar($image,$$lt{'endi'}).'
1.44 albertel 3638: <b>'.$$lt{'gmma'}.':</b><br />'.$$lt{'adds'}.'<br />'.$$lt{'drops'}.'<br /><br />
1.83 bisitz 3639: <span class="LC_nobreak">'.$$lt{'auad'}.':
1.80 bisitz 3640: <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 3641: if ($action eq 'modify') {
1.82 bisitz 3642: $r->print(' ('.&mt('Currently set to [_1].','<b>'.$$lt{$add}.'</b>').')');
1.5 raeburn 3643: }
3644: $r->print('
1.83 bisitz 3645: </span><br />
3646: <span class="LC_nobreak">'.$$lt{'auex'}.':
1.80 bisitz 3647: <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 3648: if ($action eq 'modify') {
1.82 bisitz 3649: $r->print(' ('.&mt('Currently set to [_1].','<b>'.$$lt{$drop}.'</b>').')');
1.3 raeburn 3650: }
1.83 bisitz 3651: $r->print('</span><br /><br />'.$$lt{'mapr'});
1.5 raeburn 3652: }
1.3 raeburn 3653:
1.5 raeburn 3654: sub mapping_settings {
1.58 raeburn 3655: my ($r,$sectioncount,$lt,$stored,$image,$crstype,$cdom,$cnum,$action) = @_;
1.5 raeburn 3656: my @sections = keys(%{$sectioncount});
3657: if (@sections > 0) {
3658: @sections = sort {$a cmp $b} @sections;
1.17 raeburn 3659: unshift(@sections,'none'); # Put 'no sections' next
3660: unshift(@sections,'all'); # Put 'all' at the front of the list
1.53 raeburn 3661: } else {
3662: @sections = ('all','none');
1.3 raeburn 3663: }
1.78 raeburn 3664: $r->print(&Apache::lonhtmlcommon::topic_bar($image,$$lt{'pirs'}));
1.104 raeburn 3665: my @roles = &standard_roles($crstype);
1.59 raeburn 3666: my %customroles = &Apache::lonhtmlcommon::course_custom_roles($cdom,$cnum);
1.44 albertel 3667: $r->print(&Apache::loncommon::start_data_table().
3668: &Apache::loncommon::start_data_table_header_row());
1.5 raeburn 3669: $r->print('
3670: <th>'.&mt('Active?').'</th>
3671: <th>'.&mt('Role').'</th>');
3672: if (@sections > 0) {
1.44 albertel 3673: $r->print('<th>'.&mt('Sections').'</th>');
1.3 raeburn 3674: }
1.44 albertel 3675: $r->print(&Apache::loncommon::end_data_table_header_row()."\n");
1.5 raeburn 3676: foreach my $role (@roles) {
1.58 raeburn 3677: my $roletitle=&Apache::lonnet::plaintext($role,$crstype);
3678: $r->print(&print_autorole_item($role,$roletitle,\@sections));
1.5 raeburn 3679: }
1.58 raeburn 3680: my @customs;
1.5 raeburn 3681: foreach my $role (sort(keys(%customroles))) {
1.58 raeburn 3682: my ($roletitle) = ($role =~ m|^cr/[^/]+/[^/]+/(.+)$|);
3683: push (@customs,$role);
3684: $r->print(&print_autorole_item($role,$roletitle,\@sections));
3685: }
3686: if ($action eq 'modify') {
3687: foreach my $role (@{$$stored{'autorole'}}) {
3688: if ((!grep(/^\Q$role\E$/,@customs)) &&
3689: (!grep(/^\Q$role\E$/,@roles))) {
3690: my $roletitle;
3691: if ($role =~ /^cr/) {
3692: ($roletitle) = ($role =~ m|_([^_]+)$|);
3693: } else {
3694: $roletitle = &Apache::lonnet::plaintext($role,$crstype);
3695: }
3696: $r->print(&print_autorole_item($role,$roletitle,\@sections));
3697: }
3698: }
1.5 raeburn 3699: }
1.44 albertel 3700: $r->print(&Apache::loncommon::end_data_table());
1.5 raeburn 3701: return;
3702: }
1.3 raeburn 3703:
1.58 raeburn 3704: sub print_autorole_item {
3705: my ($role,$roletitle,$sections) = @_;
3706: my $sections_sel;
3707: if (@{$sections} > 0) {
1.104 raeburn 3708: if (($role eq 'cc') || ($role eq 'co')) {
1.58 raeburn 3709: $sections_sel = '<td align="right">'.
3710: &mt('all sections').'<input type="hidden" '.
1.104 raeburn 3711: 'name="sec_'.$role.'" value="all" /></td>';
1.58 raeburn 3712: } else {
3713: $sections_sel='<td align="right">'.
3714: §ions_selection($sections,'sec_'.$role).
3715: '</td>';
3716: }
3717: }
3718: my $output = &Apache::loncommon::start_data_table_row().
3719: '<td><input type="checkbox" '.
3720: 'name="autorole" value="'.$role.'" />'.
3721: '</td><td>'.$roletitle.'</td>'.$sections_sel.
3722: &Apache::loncommon::end_data_table_row();
3723: return $output;
3724: }
3725:
1.5 raeburn 3726: sub standard_roles {
1.104 raeburn 3727: my ($crstype) = @_;
3728: my @roles = qw(in ta ep ad st);
3729: if ($crstype eq 'Community') {
3730: unshift(@roles,'co');
3731: } else {
3732: unshift(@roles,'cc');
3733: }
1.5 raeburn 3734: return @roles;
3735: }
3736:
3737: sub modify_menu {
1.29 raeburn 3738: my ($r,$groupname,$page,$gpterm) = @_;
1.5 raeburn 3739: my @menu =
1.106 wenzelju 3740: ( { categorytitle =>'Group Actions',
3741: items => [
3742:
3743: { linktext => "Modify default $gpterm settings",
3744: url => '/adm/coursegroups?action=modify&refpage='.$env{'form.refpage'}.'&groupname='.$groupname.'&state=change_settings&branch=settings',
3745: icon => 'grp_settings.png',
3746: alttext => "Modify default $gpterm settings",
3747: permission => '1',
3748: help => 'Course_Modify_Group',
1.5 raeburn 3749: },
1.106 wenzelju 3750: { linktext => 'Modify access, tools and privileges for members',
3751: url => '/adm/coursegroups?action=modify&refpage='.$env{'form.refpage'}.'&groupname='.$groupname.'&state=change_members&branch=members',
3752: icon => 'grp_tools.png',
3753: alttext => 'Modify access, tools and privileges for members',
3754: permission => '1',
1.5 raeburn 3755: help => 'Course_Modify_Group_Membership',
3756: },
1.106 wenzelju 3757: { linktext => "Add member(s) to the $gpterm",
3758: url => '/adm/coursegroups?action=modify&refpage='.$env{'form.refpage'}.'&groupname='.$groupname.'&state=add_members&branch=adds',
3759: icon => 'grp_add.png',
3760: alttext => "Add member(s) to the $gpterm",
3761: permission => '1',
1.5 raeburn 3762: help => 'Course_Group_Add_Members',
1.106 wenzelju 3763: }]}
3764: );
3765: $r->print(&Apache::lonhtmlcommon::generate_menu(@menu));
1.3 raeburn 3766: return;
3767: }
3768:
3769: sub member_privs_entries {
1.45 albertel 3770: my ($r,$usertools,$toolprivs,$fixedprivs,$userdata,$idx,$showtools,
3771: $defprivs,$excluded) = @_;
1.5 raeburn 3772: foreach my $user (sort(keys(%{$usertools}))) {
1.6 raeburn 3773: if (defined($excluded)) {
3774: if (ref($excluded) eq 'ARRAY') {
3775: if (grep/^$user$/,@{$excluded}) {
3776: next;
3777: }
3778: }
3779: }
1.5 raeburn 3780: my ($uname,$udom) = split(/:/,$user);
1.45 albertel 3781: $r->print(&Apache::loncommon::start_data_table_row().'
1.5 raeburn 3782: <td>'.$$userdata{$user}[$$idx{fullname}].'</td>
1.3 raeburn 3783: <td>'.$uname.'</td>
3784: <td>'.$udom.'</td>
1.53 raeburn 3785: <td valign="top">
3786: <table>
3787: <tr>
3788: <td><b>'.
3789: &mt('Collaborative Tool').'</b></td>
3790: </tr>
3791: <tr>
3792: <td><b>'.&mt('Fixed').'</b></td>
3793: </tr>
3794: <tr>
3795: <td><b>'.&mt('Optional').'</b></td>
3796: </tr>
3797: </table>
3798: </td>');
1.5 raeburn 3799: foreach my $tool (@{$showtools}) {
3800: if (exists($$usertools{$user}{$tool})) {
1.45 albertel 3801: $r->print('<td valign="top"><table><tr><th colspan="2">'.$tool.'</th></tr>');
1.3 raeburn 3802: my $privcount = 0;
3803: my $fixed = '';
3804: my $dynamic = '';
3805: foreach my $priv (sort(keys(%{$$toolprivs{$tool}}))) {
3806: if (exists($$fixedprivs{$tool}{$priv})) {
1.5 raeburn 3807: $fixed .= '<input type="hidden" name="userpriv_'.$priv.'" value="'.$user.'" />'.$$toolprivs{$tool}{$priv}.' ';
1.3 raeburn 3808: } else {
3809: $privcount ++;
3810: if ($privcount == 3) {
3811: $dynamic .= '</tr><tr>';
3812: }
1.83 bisitz 3813: $dynamic .='<td><span class="LC_nobreak"><label><input type="checkbox" '.
1.5 raeburn 3814: 'name="userpriv_'.$priv.'" value="'.$user.'"';
3815: if (grep/^\Q$priv\E$/,@{$defprivs}) {
3816: $dynamic .= ' checked="checked" ';
3817: }
3818: $dynamic .= ' />'.$$toolprivs{$tool}{$priv}.
1.83 bisitz 3819: '</label></span></td>';
1.3 raeburn 3820: }
3821: }
1.83 bisitz 3822: $r->print('<tr><td colspan="2"><span class="LC_nobreak">'.$fixed.'</span></td></tr><tr>'.$dynamic.'</tr></table></td>');
1.3 raeburn 3823: } else {
1.45 albertel 3824: $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 3825: }
3826: }
1.45 albertel 3827: $r->print(&Apache::loncommon::end_data_table_row());
1.3 raeburn 3828: }
3829: }
3830:
3831: sub get_dates_from_form {
3832: my $startdate;
3833: my $enddate;
3834: $startdate = &Apache::lonhtmlcommon::get_date_from_form('startdate');
3835: $enddate = &Apache::lonhtmlcommon::get_date_from_form('enddate');
3836: if ( exists ($env{'form.no_end_date'}) ) {
3837: $enddate = 0;
3838: }
3839: return ($startdate,$enddate);
1.5 raeburn 3840: }
3841:
1.3 raeburn 3842: sub date_setting_table {
3843: my ($starttime,$endtime,$formname) = @_;
3844: my $startform = &Apache::lonhtmlcommon::date_setter($formname,
3845: 'startdate',$starttime);
3846: my $endform = &Apache::lonhtmlcommon::date_setter($formname,
3847: 'enddate',$endtime);
1.98 bisitz 3848: my $perpetual = ' <span class="LC_nobreak"><label>'
3849: .'<input type="checkbox" name="no_end_date" />'
3850: .&mt('No end date')
3851: .'</label></span>';
3852: my $table = &Apache::lonhtmlcommon::start_pick_box()
3853: .&Apache::lonhtmlcommon::row_title(&mt('Start Date'))
3854: .$startform
3855: .&Apache::lonhtmlcommon::row_closure()
3856: .&Apache::lonhtmlcommon::row_title(&mt('End Date'))
3857: .$endform
3858: .$perpetual
3859: .&Apache::lonhtmlcommon::row_closure(1)
3860: .&Apache::lonhtmlcommon::end_pick_box();
1.41 albertel 3861: return $table;
1.1 raeburn 3862: }
3863:
1.32 raeburn 3864: sub add_group_folder {
3865: my ($cdom,$cnum,$now,$groupname,$action,$description,$tools,$groupinfo,
3866: $gpterm,$ucgpterm,$crstype) = @_;
3867: if ($cdom eq '' || $cnum eq '') {
1.104 raeburn 3868: my $error = '<span class="LC_error">';
3869: if ($crstype eq 'Community') {
3870: $error .= &mt("Error: invalid community domain or number - group folder creation failed.");
3871: } else {
3872: $error .= &mt("Error: invalid course domain or number - group folder creation failed.");
3873: }
3874: $error .= '</span>';
3875: return $error;
1.32 raeburn 3876: }
1.67 raeburn 3877: my ($outcome,$allgrpsmap,$grpmap,$boardsmap,$grppage,$warning);
1.32 raeburn 3878: my $crspath = '/uploaded/'.$cdom.'/'.$cnum.'/';
1.47 raeburn 3879: $allgrpsmap = $crspath.'group_allfolders.sequence';
1.32 raeburn 3880: if ($action eq 'create') {
1.67 raeburn 3881: if (&get_folder_lock($cdom,$cnum,'group_allfolders',$now) eq 'ok') {
3882: # check if group_allfolders.sequence exists.
1.69 raeburn 3883: my $mapcontents = &Apache::lonnet::getfile($allgrpsmap);
3884: if ($mapcontents eq '-1') { #file does not exist;
1.80 bisitz 3885: my $grpstitle = &mt("$crstype $ucgpterm".'s');
1.67 raeburn 3886: my $topmap_url = '/'.$env{'course.'.$env{'request.course.id'}.'.url'};
3887: $topmap_url =~ s|/+|/|g;
3888: if ($topmap_url =~ m|^/uploaded|) {
3889: $outcome = &map_updater($cdom,$cnum,'group_allfolders.sequence',
3890: 'toplevelgroup',$grpstitle,$topmap_url);
3891: } else {
1.80 bisitz 3892: $outcome = '<span class="LC_warning">'
3893: .&mt('Non-standard course - folder for all groups not added.')
3894: .'</span>';
1.67 raeburn 3895: }
1.32 raeburn 3896: if ($outcome ne 'ok') {
1.67 raeburn 3897: my $delresult = &release_folder_lock($cdom,$cnum,'group_allfolders');
3898: if ($delresult ne 'ok') {
3899: $warning = $delresult;
3900: }
1.84 raeburn 3901: return $outcome.$warning;
1.32 raeburn 3902: }
3903: }
1.67 raeburn 3904: my $delresult = &release_folder_lock($cdom,$cnum,'group_allfolders');
3905: if ($delresult ne 'ok') {
3906: $warning = $delresult ;
3907: }
3908: } else {
1.80 bisitz 3909: $outcome = '<span class="LC_error">'
3910: .&mt('Could not obtain exclusive lock to check status of the folder for all groups. No group folder added.')
1.84 raeburn 3911: .'</span>';
1.67 raeburn 3912: return $outcome;
1.32 raeburn 3913: }
1.75 bisitz 3914: my $grpfolder = &mt($ucgpterm.' Folder - [_1]',$description);
1.49 raeburn 3915: $grppage='/adm/'.$cdom.'/'.$cnum.'/'.$groupname.'/smppg';
1.75 bisitz 3916: my $grptitle = &mt('Group homepage - [_1]',$description);
1.55 raeburn 3917: my ($discussions,$disctitle);
1.47 raeburn 3918: my $outcome = &map_updater($cdom,$cnum,'group_folder_'.$groupname.'.sequence',
1.32 raeburn 3919: 'grpseq',$grpfolder,$allgrpsmap,$grppage,
3920: $grptitle);
3921: if ($outcome ne 'ok') {
1.67 raeburn 3922: return $outcome.$warning;
1.32 raeburn 3923: }
3924: my $pageout = &create_homepage($cdom,$cnum,$groupname,$groupinfo,
3925: $tools,$gpterm,$ucgpterm,$now);
3926: # Link to folder for bulletin boards
1.47 raeburn 3927: $grpmap = $crspath.'group_folder_'.$groupname.'.sequence';
1.32 raeburn 3928: if (grep/^discussion$/,@{$tools}) {
3929: $disctitle = &mt('Discussion Boards');
1.47 raeburn 3930: my $outcome = &map_updater($cdom,$cnum,'group_boards_'.$groupname.
1.32 raeburn 3931: '.sequence','bbseq',$disctitle,$grpmap);
3932: if ($outcome ne 'ok') {
1.67 raeburn 3933: return $outcome.$warning;
1.32 raeburn 3934: }
1.47 raeburn 3935: $boardsmap = $crspath.'group_boards_'.$groupname.'.sequence';
1.32 raeburn 3936: }
3937: } else {
3938: #modify group folder if status of discussions tools is changed
3939: }
3940: my ($furl,$ferr)= &Apache::lonuserstate::readmap($cdom.'/'.$cnum);
1.67 raeburn 3941: my $navmap = Apache::lonnavmaps::navmap->new();
1.85 raeburn 3942: if (!defined($navmap)) {
1.104 raeburn 3943: $warning .= '<span class="LC_error">';
3944: if ($crstype eq 'Community') {
3945: $warning .= &mt("Error retrieving community contents").
3946: ' '.&mt("You need to re-initialize the community.");
3947: } else {
3948: $warning .= &mt("Error retrieving course contents").
3949: ' '.&mt("You need to re-initialize the course.");
3950: }
3951: $warning .= '</span>';
3952: return $warning;
1.85 raeburn 3953: }
1.32 raeburn 3954: # modify parameters
3955: my $parm_result;
3956: if ($action eq 'create') {
3957: if ($grpmap) {
3958: $parm_result .= &parm_setter($navmap,$cdom,$grpmap,$groupname);
3959: }
3960: if ($grppage) {
3961: $parm_result .= &parm_setter($navmap,$cdom,$grppage,$groupname);
3962: }
3963: if ($boardsmap) {
3964: $parm_result .= &parm_setter($navmap,$cdom,$boardsmap,$groupname);
3965: }
3966: }
1.67 raeburn 3967: undef($navmap);
1.32 raeburn 3968: if ($parm_result) {
1.67 raeburn 3969: return $warning.$parm_result;
3970: } else {
3971: return 'ok';
3972: }
3973: }
3974:
3975: sub get_folder_lock {
3976: my ($cdom,$cnum,$folder_name,$now) = @_;
3977: # get lock for folder being edited.
3978: my $lockhash = {
3979: $folder_name."\0".'locked_folder' => $now.':'.$env{'user.name'}.
3980: ':'.$env{'user.domain'},
3981: };
3982: my $tries = 0;
3983: my $gotlock = &Apache::lonnet::newput('coursegroups',$lockhash,$cdom,$cnum);
3984:
3985: while (($gotlock ne 'ok') && $tries <3) {
3986: $tries ++;
1.68 albertel 3987: sleep(1);
1.67 raeburn 3988: $gotlock = &Apache::lonnet::newput('coursegroups',$lockhash,$cdom,$cnum);
3989: }
3990: return $gotlock;
3991: }
3992:
3993: sub release_folder_lock {
3994: my ($cdom,$cnum,$folder_name) = @_;
3995: # remove lock
3996: my @del_lock = ($folder_name."\0".'locked_folder');
3997: my $dellockoutcome=&Apache::lonnet::del('coursegroups',\@del_lock,$cdom,$cnum);
3998: if ($dellockoutcome ne 'ok') {
1.80 bisitz 3999: return ('<div class="LC_error">'
4000: .&mt('Warning: failed to release lock for folder: [_1].','<tt>'.$folder_name.'</tt>')
4001: .'</div>'
4002: );
1.32 raeburn 4003: } else {
4004: return 'ok';
4005: }
4006: }
4007:
4008: sub map_updater {
4009: my ($cdom,$cnum,$newfile,$itemname,$itemtitle,$parentmap,$startsrc,
4010: $starttitle,$endsrc,$endtitle) = @_;
4011: my $outcome;
4012: $env{'form.'.$itemname} = &new_map($startsrc,$starttitle,$endsrc,
4013: $endtitle);
4014: my $newmapurl=&Apache::lonnet::finishuserfileupload($cnum,$cdom,$itemname,
4015: $newfile);
4016: if ($newmapurl !~ m|^/uploaded|) {
1.80 bisitz 4017: $outcome = '<div class="LC_error">'
4018: .&mt('Error uploading new folder.')." ($newfile): $newmapurl"
4019: .'</div>';
1.32 raeburn 4020: return $outcome;
1.67 raeburn 4021: }
1.63 albertel 4022: my ($errtext,$fatal)=&LONCAPA::map::mapread($parentmap);
1.32 raeburn 4023: if ($fatal) {
1.80 bisitz 4024: $outcome = '<div class="LC_error">'
4025: .&mt('Error reading contents of parent folder.')." ($parentmap): $errtext"
4026: .'</div>';
1.32 raeburn 4027: return $outcome;
4028: } else {
1.63 albertel 4029: my $newidx=&LONCAPA::map::getresidx($newmapurl);
4030: $LONCAPA::map::resources[$newidx] = $itemtitle.':'.$newmapurl.
1.32 raeburn 4031: ':false:normal:res';
1.63 albertel 4032: $LONCAPA::map::order[1+$#LONCAPA::map::order]=$newidx;
4033: my ($outtext,$errtext) = &LONCAPA::map::storemap($parentmap,1);
1.67 raeburn 4034: if ($errtext) {
1.80 bisitz 4035: $outcome = '<div class="LC_error">'
4036: .&mt('Error saving updated parent folder.')." ($parentmap): $errtext"
4037: .'</div>';
1.32 raeburn 4038: return $outcome;
4039: }
4040: }
4041: return 'ok';
4042: }
4043:
4044: sub new_map {
4045: my ($startsrc,$starttitle,$endsrc,$endtitle) = @_;
4046: my $newmapstr = '
4047: <map>
4048: <resource id="1" src="'.$startsrc.'" type="start" title="'.$starttitle.'"></resource>
4049: <link from="1" to="2" index="1"></link>
4050: <resource id="2" src="'.$endsrc.'" type="finish" title="'.$endtitle.'"></resource>
4051: </map>
4052: ';
4053: return $newmapstr;
4054: }
4055:
4056: sub parm_setter {
1.104 raeburn 4057: my ($navmap,$cdom,$url,$groupname,$crstype) = @_;
1.85 raeburn 4058: if (!defined($navmap)) {
1.104 raeburn 4059: my $allresults;
4060: if ($crstype eq 'Community') {
4061: $allresults = &mt("Parameters not set for [_1] because the contents of the community could not be retrieved.",$url).' '.
4062: &mt("You need to reinitialize the community.");
4063: } else {
4064: $allresults = &mt("Parameters not set for [_1] because the contents of the course could not be retrieved.",$url).' '.
4065: &mt("You need to reinitialize the course.");
4066:
4067: }
4068: return '<div class="LC_warning">'.$allresults.'</div>';
1.85 raeburn 4069: }
1.32 raeburn 4070: my %hide_settings = (
4071: 'course' => {
4072: 'num' => 13,
4073: 'set' => 'yes',
4074: },
4075: 'group' => {
4076: 'num' => 5,
4077: 'set' => 'no',
4078: 'extra' => $groupname,
4079: },
4080: );
4081: my $res = $navmap->getResourceByUrl($url);
1.104 raeburn 4082: my $allresults;
1.67 raeburn 4083: if ($res) {
4084: my $symb = $res->symb();
4085: foreach my $level (keys(%hide_settings)) {
4086: my $parmresult =
4087: &Apache::lonparmset::storeparm_by_symb($symb,
1.32 raeburn 4088: '0_hiddenresource',
4089: $hide_settings{$level}{'num'},
4090: $hide_settings{$level}{'set'},
4091: 'string_yesno',undef,$cdom,
4092: undef,undef,
4093: $hide_settings{$level}{'extra'});
1.67 raeburn 4094: if ($parmresult) {
4095: $allresults .= $level.': '.$parmresult;
4096: }
1.37 raeburn 4097: }
1.67 raeburn 4098: } else {
1.104 raeburn 4099: $allresults = '<div class="LC_warning">';
4100: if ($crstype eq 'Community') {
4101: $allresults .= &mt("Parameters not set for [_1] because the resource was not recognized as part of the community.",'<tt>'.$url.'</tt>');
4102: } else {
4103: $allresults .= &mt('Parameters not set for [_1] because the resource was not recognized as part of the course.','<tt>'.$url.'</tt>');
4104: }
4105: $allresults .= '</div>';
1.32 raeburn 4106: }
1.37 raeburn 4107: return $allresults;
1.32 raeburn 4108: }
4109:
1.3 raeburn 4110: sub create_homepage {
1.32 raeburn 4111: my ($cdom,$cnum,$name,$groupinfo,$tools,$gpterm,$ucgpterm,$now) = @_;
1.3 raeburn 4112: my $functionality = join(',',@{$tools});
1.24 www 4113: my $content = &unescape($$groupinfo{description});
1.3 raeburn 4114: $content=~s/\s+$//s;
4115: $content=~s/^\s+//s;
4116: $content=~s/\<br\s*\/*\>$//s;
4117: $content=&Apache::lonfeedback::clear_out_html($content,1);
4118:
4119: my %pageinfo = (
1.29 raeburn 4120: 'aaa_title' => "$ucgpterm: $name",
1.3 raeburn 4121: 'abb_links' => $functionality,
4122: 'bbb_content' => $content,
4123: 'ccc_webreferences' => '',
1.32 raeburn 4124: 'uploaded.lastmodified' => $now,
1.3 raeburn 4125: );
4126: my $putresult = &Apache::lonnet::put('grppage_'.$name,\%pageinfo,$cdom,$cnum);
4127: return $putresult;
1.1 raeburn 4128: }
4129:
1.5 raeburn 4130: sub check_uncheck_tools {
4131: my ($r,$available) = @_;
4132: if (ref($available) eq 'ARRAY') {
4133: $r->print('
4134: <script type="text/javascript">
4135: function checkAllTools(formname) {
4136: ');
4137: foreach my $tool (@{$available}) {
4138: $r->print(' checkAll(formname.user_'.$tool.');'."\n");
4139: }
4140: $r->print(' checkAll(formname.togglefunc);'."\n");
4141: $r->print('
4142: }
4143: function uncheckAllTools(formname) {
4144: ');
4145: foreach my $tool (@{$available}) {
4146: $r->print(' uncheckAll(formname.user_'.$tool.');'."\n");
4147: }
4148: $r->print(' uncheckAll(formname.togglefunc);'."\n");
4149: $r->print('
4150: }
4151: function toggleTools(field,caller) {
4152: if (caller.checked) {
4153: checkAll(field);
4154: } else {
4155: uncheckAll(field);
4156: }
4157: return;
4158: }
4159: </script>
4160: ');
4161: }
4162: return;
4163: }
4164:
4165: sub validate_groupname {
1.29 raeburn 4166: my ($groupname,$action,$cdom,$cnum,$gpterm,$ucgpterm,$crstype) = @_;
1.16 albertel 4167: my %sectioncount = &Apache::loncommon::get_sections($cdom,$cnum);
1.17 raeburn 4168: my %curr_groups = &Apache::longroup::coursegroups($cdom,$cnum);
1.65 raeburn 4169: my %deleted_groups = &Apache::longroup::coursegroups($cdom,$cnum,undef,
4170: 'deleted_groups');
1.64 raeburn 4171: if (my $tmp = &Apache::lonnet::error(%deleted_groups)) {
4172: undef(%deleted_groups);
4173: &Apache::lonnet::logthis('Error retrieving groups: '.$tmp.' in '.$cnum.':'.$cdom);
4174: }
1.5 raeburn 4175: my %lt = &Apache::lonlocal::texthash (
1.29 raeburn 4176: igna => "Invalid $gpterm name",
4177: tgne => "The $gpterm name entered ",
4178: grna => "$ucgpterm names and section names used in a ".
4179: "$crstype must be unique.",
4180: isno => "is not a valid name.",
4181: gnmo => "$ucgpterm names may only contain letters, ".
4182: "numbers or underscores.",
4183: cnnb => "can not be used as it is the name of ",
4184: inth => " in this $crstype",
4185: thgr => "- does not correspond to the name of an ".
4186: "existing $gpterm",
1.5 raeburn 4187: );
1.15 albertel 4188:
1.42 albertel 4189: my $exitmsg = '<span class="LC_error">'.$lt{'igna'}.'</span><br /><br />'.
4190: $lt{'tgne'}.' "'.$groupname.'" ';
1.5 raeburn 4191: my $dupmsg = $lt{'grna'};
4192: my $earlyout;
4193: if (($groupname eq '') || ($groupname =~ /\W/)) {
4194: $earlyout = $exitmsg.$lt{'isno'}.'<br />'.$lt{'gnmo'};
4195: return $earlyout;
4196: }
1.16 albertel 4197: if (exists($sectioncount{$groupname})) {
4198: return $exitmsg.$lt{'cnnb'}.&mt('a section').$lt{'inth'}.
4199: '<br />'.$lt{'grna'};
1.5 raeburn 4200: }
1.64 raeburn 4201: if ($action eq 'create') {
4202: if (exists($curr_groups{$groupname})) {
4203: return $exitmsg.$lt{'cnnb'}.&mt('an existing [_1]',$gpterm).
4204: $lt{'inth'}.'.<br />'.$lt{'grna'};
4205: } elsif (exists($deleted_groups{$groupname})) {
4206: return $exitmsg.$lt{'cnnb'}.&mt('a [_1] which previously existed',$gpterm).
4207: $lt{'inth'}.'.<br />'.$lt{'grna'};
4208: }
1.5 raeburn 4209: } elsif ($action eq 'modify') {
4210: unless(exists($curr_groups{$groupname})) {
1.29 raeburn 4211: $earlyout = &mt('[_1] name:',$ucgpterm).' '.$groupname.$lt{'thgr'}.
4212: $lt{'inth'};
1.5 raeburn 4213: return $earlyout;
4214: }
4215: }
4216: return;
4217: }
4218:
4219: sub check_changes {
4220: my ($member_changes,$memchg) = @_;
4221: my %exclusions;
4222: @{$exclusions{'changefunc'}} = ('expire');
4223: @{$exclusions{'changepriv'}} = ('expire','changefunc');
4224:
4225: foreach my $change (@{$member_changes}) {
1.6 raeburn 4226: if ($change eq 'deletion') {
1.5 raeburn 4227: next;
4228: }
1.6 raeburn 4229: my @checks = ('deletion');
1.5 raeburn 4230: if (exists($exclusions{$change})) {
4231: push(@checks,@{$exclusions{$change}});
4232: }
4233: my @temp = ();
4234: foreach my $item (@{$$memchg{$change}}) {
4235: my $match = 0;
4236: foreach my $check (@checks) {
1.6 raeburn 4237: if (defined($$memchg{$check})) {
4238: if (ref(@{$$memchg{$check}}) eq 'ARRAY') {
4239: if (@{$$memchg{$check}} > 0) {
4240: if (grep/^$item$/,@{$$memchg{$check}}) {
4241: $match = 1;
4242: last;
4243: }
4244: }
1.5 raeburn 4245: }
4246: }
4247: }
4248: if ($match) {
4249: next;
4250: }
4251: push(@temp,$item);
4252: }
4253: @{$$memchg{$change}} = @temp;
4254: }
4255: }
1.3 raeburn 4256:
1.1 raeburn 4257: 1;
1.106 wenzelju 4258:
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>