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