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