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