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