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