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