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