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