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