Annotation of loncom/interface/loncoursegroups.pm, revision 1.26
1.24 www 1: # The LearningOnline Network with CAPA
2: #
1.26 ! raeburn 3: # $Id: loncoursegroups.pm,v 1.25 2006/06/23 00:22:58 raeburn Exp $
1.1 raeburn 4: #
5: # Copyright Michigan State University Board of Trustees
6: #
7: # This file is part of the LearningOnline Network with CAPA (LON-CAPA).
8: #
9: # LON-CAPA is free software; you can redistribute it and/or modify
10: # it under the terms of the GNU General Public License as published by
11: # the Free Software Foundation; either version 2 of the License, or
12: # (at your option) any later version.
13: #
14: # LON-CAPA is distributed in the hope that it will be useful,
15: # but WITHOUT ANY WARRANTY; without even the implied warranty of
16: # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17: # GNU General Public License for more details.
18: #
19: # You should have received a copy of the GNU General Public License
20: # along with LON-CAPA; if not, write to the Free Software
21: # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
22: #
23: # /home/httpd/html/adm/gpl.txt
24: #
25: # http://www.lon-capa.org/
26: #
27:
28: package Apache::loncoursegroups;
29:
30: use strict;
31: use Apache::lonnet;
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 $now = time;
1092: my $totalmembers = 0;
1093: my $active = 0;
1094: my $previous = 0;
1095: my $future = 0;
1096: foreach my $member (keys %memberhash) {
1097: $totalmembers ++;
1098: my ($end,$start) = split(/:/,$memberhash{$member});
1.6 raeburn 1099: unless ($start == -1) {
1100: if (($end!=0) && ($end<$now)) {
1101: $previous ++;
1102: } elsif (($start!=0) && ($start>$now)) {
1103: $future ++;
1104: } else {
1105: $active ++;
1106: }
1.4 raeburn 1107: }
1108: }
1109: if ($totalmembers == 0) {
1110: $$group_info{$group}{'totalmembers'} = 'None';
1111: } else {
1112: $$group_info{$group}{'totalmembers'} = $active.' - active<br />'.$previous.' -previous<br />'.$future.' -future';
1113: }
1114: return 'ok';
1.3 raeburn 1115: }
1116:
1117:
1.5 raeburn 1118: sub general_settings_form {
1119: my ($r,$cdom,$cnum,$action,$tabcol,$formname,$page,$functions,$tools,
1120: $toolprivs,$fixedprivs,$sectioncount,$stored,$states,$navbuttons,
1121: $rowColor1,$rowColor2) = @_;
1122: my ($nexttext,$prevtext);
1123: $r->print(' <br />
1124: <table width="100%" cellpadding="0" cellspacing="0" border="0">
1125: ');
1126: &groupsettings_options($r,$tabcol,$functions,$action,$formname,$stored,1);
1127: $r->print('
1128: <tr>
1129: <td colspan="4"> </td>
1130: </tr>');
1131: &access_date_settings($r,$tabcol,$action,$formname,$stored,2);
1132: $r->print('
1133: <tr>
1134: <td colspan="4"> </td>
1135: </tr>');
1136: if ($action eq 'create') {
1137: &membership_options($r,$action,$formname,$tabcol,$sectioncount,3);
1138: $nexttext = $$navbuttons{'gtns'};
1139: } else {
1140: my @available = ();
1141: my @unavailable = ();
1142: &check_tools($functions,$tools,\@available,\@unavailable);
1143: @{$tools} = sort(keys(%{$functions}));
1144: &privilege_specificity($r,$tabcol,$rowColor1,$rowColor2,$action,
1145: 3,$tools,$stored,$toolprivs,$fixedprivs,
1146: \@available,$formname);
1147: $r->print('
1148: <tr>
1149: <td colspan="4"> </td>
1150: </tr>');
1151: &mapping_options($r,$action,$formname,$page,$tabcol,$sectioncount,
1152: $states,$stored,$navbuttons,4,5,$rowColor1,
1153: $rowColor2);
1154: $nexttext = $$navbuttons{'mose'};
1155: }
1156: $prevtext = $$navbuttons{'gtpp'};
1157: &display_navbuttons($r,$formname,$$states{$action}[$page-1],$prevtext,
1158: $$states{$action}[$page+1],$nexttext);
1159: $r->print('
1160: </table>');
1161: return;
1162: }
1163:
1164: sub groupsettings_options {
1165: my ($r,$tabcol,$functions,$action,$formname,$stored,$image) = @_;
1.1 raeburn 1166: my %lt = &Apache::lonlocal::texthash(
1167: 'gdat' => 'Group open and close dates',
1168: 'sten' => 'Set a start date/time and end date/time for the group',
1169: 'gfun' => 'Group functionality',
1.5 raeburn 1170: 'gnde' => 'Group name, description and available functionality',
1171: 'desc' => 'Description',
1172: 'func' => 'Functionality',
1173: 'gnam' => 'Group Name',
1174: 'doyo' => 'Do you want to assign different functionality '.
1175: 'to different group members?',
1.1 raeburn 1176: );
1.5 raeburn 1177: &topic_bar($r,$tabcol,$image,$lt{'gnde'});
1178: $r->print('
1.3 raeburn 1179: <tr>
1180: <td> </td>
1181: <td colspan="3">
1182: <table border="0" cellpadding="2" cellspacing="2">
1183: <tr>
1.5 raeburn 1184: <td><b>'.$lt{'gnam'}.':</b></td>
1185: <td colspan="5">
1186: ');
1187: if ($action eq 'create') {
1188: $r->print('<input type="text" name="groupname" size="25" />');
1189: } else {
1190: $r->print('<input type="hidden" name="groupname" value="'.
1191: $env{'form.groupname'}.'" />'.$env{'form.groupname'});
1192: }
1193: $r->print(<<"END");
1.3 raeburn 1194: </td>
1195: <tr>
1196: <tr>
1.5 raeburn 1197: <td><b>$lt{'desc'}:</b></td>
1198: <td colspan="5"><input type="text" name="description" size="40"
1199: value="" />
1.3 raeburn 1200: </td>
1201: <tr>
1202: <tr>
1.5 raeburn 1203: <td><b>$lt{'func'}:</b></td>
1.3 raeburn 1204: END
1205: my $numitems = keys(%{$functions});
1206: my $halfnum = int($numitems/2);
1207: my $remnum = $numitems%2;
1208: if ($remnum) {
1209: $halfnum ++;
1210: }
1.5 raeburn 1211: my @allfunctions = sort(keys (%{$functions}));
1.3 raeburn 1212: for (my $i=0; $i<$halfnum; $i++) {
1.7 raeburn 1213: $r->print('<td><label><input type="checkbox" name="tool" value="'.
1.3 raeburn 1214: $allfunctions[$i].'" /> '.
1.7 raeburn 1215: $$functions{$allfunctions[$i]}.'</label></td>
1.3 raeburn 1216: <td> </td><td> </td>');
1217: }
1218: $r->print('<td><input type="button" value="check all" '.
1219: 'onclick="javascript:checkAll(document.'.$formname.'.tool)" />'.
1220: '</td></tr><tr><td> </td>');
1221: for (my $j=$halfnum; $j<@allfunctions; $j++) {
1.7 raeburn 1222: $r->print('<td><label><input type="checkbox" name="tool" value="'.
1.3 raeburn 1223: $allfunctions[$j].'" /> '.
1.7 raeburn 1224: $$functions{$allfunctions[$j]}.'</label></td>
1.3 raeburn 1225: <td> </td><td> </td>');
1226: }
1227: if ($remnum) {
1228: $r->print('<td> </td>');
1229: }
1.5 raeburn 1230: $r->print('
1.3 raeburn 1231: <td>
1.5 raeburn 1232: <input type="button" value="uncheck all"
1233: onclick="javascript:uncheckAll(document.'.$formname.'.tool)" />
1.3 raeburn 1234: </td>
1235: </tr>
1236: <tr>
1237: <td><b>Granularity:</b></td>
1.7 raeburn 1238: <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 1239: if ($action eq 'modify') {
1240: $r->print(' ('.&mt('Currently set to "[_1]"',
1241: $$stored{'granularity'}).')');
1242: }
1243: $r->print('
1244: </td>
1245: </tr>
1.3 raeburn 1246: </table>
1247: </td>
1248: </tr>
1.5 raeburn 1249: ');
1250: return;
1251: }
1252:
1253: sub membership_options {
1254: my ($r,$action,$state,$tabcol,$sectioncount,$image) = @_;
1255: my %lt = &Apache::lonlocal::texthash(
1256: 'pipa' => 'Pick parameters to generate membership list',
1257: 'gmem' => 'Group membership options',
1258: 'picr' => 'Pick the criteria to use to build a list of '.
1259: 'course users from which you will select ',
1260: 'meof' => 'members of the new group.',
1.6 raeburn 1261: 'admg' => 'additional members of the group.',
1.5 raeburn 1262: 'ifno' => 'If you do not wish to add members when you first '.
1.21 raeburn 1263: 'create the group, do not make any selections.',
1264: '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 1265: 'acty' => 'Access types',
1266: 'coro' => 'Course roles',
1267: 'cose' => 'Course sections',
1268: );
1269: my %status_types = (
1270: active => &mt('Currently has access'),
1271: previous => &mt('Previously had access'),
1272: future => &mt('Will have future access'),
1273: );
1.15 albertel 1274:
1.5 raeburn 1275: my @roles = ('st','cc','in','ta','ep','cr');
1276:
1277: my @sections = keys(%{$sectioncount});
1278:
1279: &topic_bar($r,$tabcol,$image,$lt{'pipa'});
1280: $r->print('
1.3 raeburn 1281: <tr>
1282: <td> </td>
1283: <td colspan="3">
1.5 raeburn 1284: <b>'.$lt{'gmem'}.'</b><br/>'.$lt{'picr'});
1285: if ($action eq 'create') {
1.21 raeburn 1286: $r->print($lt{'meof'}.'<br />'.$lt{'ifno'}.'<br />'.$lt{'asub'});
1.5 raeburn 1287: } else {
1.6 raeburn 1288: $r->print($lt{'admg'});
1.5 raeburn 1289: }
1290: $r->print('
1291: <br />
1292: <br />
1.3 raeburn 1293: <table border="0">
1294: <tr>
1.5 raeburn 1295: <td><b>'.$lt{'acty'}.'</b></td>
1.3 raeburn 1296: <td> </td>
1.5 raeburn 1297: <td><b>'.$lt{'coro'}.'</b></td>');
1.3 raeburn 1298: if (@sections >0) {
1.5 raeburn 1299: $r->print('
1.3 raeburn 1300: <td> </td>
1301: <td><b>'.$lt{'cose'}.'</b></td>
1302: <td> </td>');
1303: }
1304: $r->print('</tr><tr>');
1305: $r->print(&Apache::lonhtmlcommon::status_select_row(\%status_types));
1306: $r->print('<td> </td>');
1307: $r->print(&Apache::lonhtmlcommon::role_select_row(\@roles));
1308: if (@sections > 0) {
1.5 raeburn 1309: @sections = sort {$a cmp $b} @sections;
1.17 raeburn 1310: unshift(@sections,'all'); # Put 'all' at the front of the list
1311: unshift(@sections,'none'); # Put 'no sections' next
1.5 raeburn 1312: $r->print('<td> </td>
1313: <td colspan="3" align="center" valign="top">'.
1314: §ions_selection(\@sections,'sectionpick').'</td>');
1.3 raeburn 1315: }
1316: $r->print('
1317: </tr>
1318: </table>
1319: </td>
1.5 raeburn 1320: </tr>');
1321: return;
1322: }
1323:
1324: sub sections_selection {
1325: my ($sections,$elementname) = @_;
1326: my $section_sel;
1327: my $numvisible = 4;
1328: if (@{$sections} < 4) {
1329: $numvisible = @{$sections};
1330: }
1331: foreach my $sec (@{$sections}) {
1.17 raeburn 1332: if ($sec eq 'all') {
1.5 raeburn 1333: $section_sel .= ' <option value="'.$sec.'" />all sections'."\n";
1.17 raeburn 1334: } elsif ($sec eq 'none') {
1.5 raeburn 1335: $section_sel .= ' <option value="'.$sec.'" />no section'."\n";
1336: } else {
1337: $section_sel .= ' <option value="'.$sec.'" />'.$sec."\n";
1338: }
1339: }
1340: my $output = '
1341: <select name="'.$elementname.'" multiple="true" size="'.$numvisible.'">
1342: '.$section_sel.'
1343: </select>';
1344: return $output;
1345: }
1346:
1347: sub access_date_settings {
1348: my ($r,$tabcol,$action,$formname,$stored,$image) = @_;
1349: my %lt = &Apache::lonlocal::texthash(
1350: 'sten' => 'Default start and end dates for group access',
1351: );
1352: my $starttime = time;
1353: my $endtime = time+(6*30*24*60*60); # 6 months from now, approx
1354: if ($action eq 'modify') {
1355: $starttime = $$stored{'startdate'};
1356: unless ($$stored{'enddate'} == 0) {
1357: $endtime = $$stored{'enddate'};
1358: }
1359: }
1360: my ($start_table,$end_table) = &date_setting_table
1361: ($starttime,$endtime,$formname);
1362: &topic_bar($r,$tabcol,$image,$lt{'sten'});
1363: $r->print('
1364: <tr>
1365: <td> </td>
1366: <td colspan="3">'.$start_table.'</td>
1367: <tr>
1.3 raeburn 1368: <tr>
1369: <td colspan="4"> </td>
1370: </tr>
1371: <tr>
1372: <td> </td>
1.5 raeburn 1373: <td colspan="3">'.$end_table.'</td>
1374: <tr>');
1.3 raeburn 1375: return;
1376: }
1377:
1.5 raeburn 1378: sub choose_members_form {
1379: my ($r,$cdom,$cnum,$tabcol,$action,$formname,$page,$groupname,$description,
1380: $granularity,$startdate,$enddate,$tools,$fixedprivs,$toolprivs,
1381: $functions,$users,$userdata,$idx,$stored,$states,$navbuttons,
1382: $rowColor1,$rowColor2) = @_;
1383: my @regexps = ('user_','userpriv_','sec_');
1384: my %origmembers;
1.3 raeburn 1385: $r->print(&Apache::lonhtmlcommon::echo_form_input(
1.5 raeburn 1386: ['origin','action','state','page','member','specificity','branch',
1.7 raeburn 1387: 'defpriv','autorole','autoadd','autodrop','sortby','togglefunc'],
1.5 raeburn 1388: \@regexps));
1389: my $earlyout = &validate_groupname($groupname,$action,$cdom,$cnum);
1390: $r->print('
1391: <table width="100%" cellpadding="0" cellspacing="0" border="0">
1.1 raeburn 1392: <tr>
1393: <td> </td>
1.5 raeburn 1394: <td colspan="3">
1395: ');
1396: if ($earlyout) {
1397: $r->print($earlyout.'</td></tr>');
1398: &display_navbuttons($r,$formname,$$states{$action}[$page-1],
1399: $$navbuttons{'gtps'});
1400: $r->print('</table>');
1.3 raeburn 1401: return;
1.5 raeburn 1402: }
1403: my ($specimg,$memimg);
1404: my @available = ();
1405: my @unavailable = ();
1406: &check_tools($functions,$tools,\@available,\@unavailable);
1407: if ($action eq 'create') {
1408: &print_current_settings($r,$action,$tabcol,$rowColor1,$rowColor2,
1409: $functions,$startdate,$enddate,$groupname,
1410: $description,$granularity,\@available,
1411: \@unavailable);
1412: $specimg = 4;
1413: $memimg = 5;
1414: } else {
1415: $specimg = 2;
1416: $memimg = 3;
1417: my %membership = &Apache::lonnet::get_group_membership($cdom,$cnum,
1418: $groupname);
1419: foreach my $key (sort(keys(%membership))) {
1420: if ($key =~ /^\Q$groupname\E:([^:]+):([^:]+)$/) {
1.6 raeburn 1421: my ($end,$start,@userprivs) = split(/:/,$membership{$key});
1422: unless ($start == -1) {
1423: my $uname = $1;
1424: my $udom = $2;
1425: my $user = $uname.':'.$udom;
1426: $origmembers{$user} = 1;
1427: }
1.5 raeburn 1428: }
1429: }
1430: }
1431: &privilege_specificity($r,$tabcol,$rowColor1,$rowColor2,$action,
1432: $specimg,$tools,$stored,$toolprivs,
1433: $fixedprivs,\@available,$formname);
1434: my $newusers = &pick_new_members($r,$action,$formname,$tabcol,$rowColor1,
1435: $rowColor2,\@available,$idx,$stored,
1436: $memimg,$users,$userdata,$granularity,
1437: \%origmembers);
1438: if ($newusers || $action eq 'create') {
1439: &display_navbuttons($r,$formname,$$states{$action}[$page-1],
1440: $$navbuttons{'gtps'},$$states{$action}[$page+1],
1441: $$navbuttons{'gtns'});
1442: } else {
1443: &display_navbuttons($r,$formname,$$states{$action}[$page-1],
1444: $$navbuttons{'gtps'});
1.3 raeburn 1445: }
1.5 raeburn 1446: $r->print('</table>');
1447: return;
1448: }
1449:
1450: sub display_navbuttons {
1451: my ($r,$formname,$prev,$prevtext,$next,$nexttext) = @_;
1452: $r->print('
1453: <tr>
1454: <td colspan="4"> </td>
1455: </tr>
1456: <tr>
1457: <td> </td>
1458: <td colspan="3">');
1459: if ($prev) {
1460: $r->print('
1461: <input type="button" name="previous" value = "'.$prevtext.'"
1462: onclick="javascript:backPage(document.'.$formname.','."'".$prev."'".')"/>
1463: ');
1464: }
1465: if ($next) {
1466: $r->print('
1467: <input type="button" name="next" value="'.$nexttext.'"
1468: onclick="javascript:nextPage(document.'.$formname.','."'".$next."'".')" />');
1469: }
1470: $r->print('
1471: </td>
1472: </tr>
1473: ');
1474: }
1475:
1476: sub check_tools {
1477: my ($functions,$tools,$available,$unavailable) = @_;
1478: foreach my $item (sort(keys(%{$functions}))) {
1479: if (grep/^$item$/,@{$tools}) {
1480: push(@{$available},$item);
1481: } else {
1482: push(@{$unavailable},$item);
1483: }
1484: }
1485: return;
1486: }
1487:
1488: sub print_current_settings {
1489: my ($r,$action,$tabcol,$rowColor1,$rowColor2,$functions,$startdate,$enddate,
1490: $groupname,$description,$granularity,$available,$unavailable) =@_;
1491:
1492: my %lt = &Apache::lonlocal::texthash(
1493: grna => 'Group Name',
1494: desc => 'Description',
1495: grfn => 'Group Functions',
1496: gran => 'Granularity',
1497: dfac => 'Default access dates',
1498: ygrs => 'Your group selections',
1499: tfwa => 'The following settings will apply to the group:',
1500: difn => 'Different functionality<br />for different users:',
1501: stda => 'Start date',
1502: enda => 'End date:',
1503: );
1.3 raeburn 1504: my $showstart = &Apache::lonlocal::locallocaltime($startdate);
1.5 raeburn 1505: my $showend;
1506: if ($enddate == 0) {
1507: $showend = &mt('No end date set');
1508: } else {
1509: $showend = &Apache::lonlocal::locallocaltime($enddate);
1510: }
1511: $r->print('<table border="0" cellpadding="0" cellspacing="20">');
1512: if ($action eq 'create') {
1513: $r->print('
1.3 raeburn 1514: <tr>
1.5 raeburn 1515: <td><font face="arial,helvetica,sans-serif"><b>'.$lt{'ygrs'}.'</b></font>
1516: <br />'.$lt{'tfwa'}.'
1.3 raeburn 1517: </td>
1.5 raeburn 1518: </tr>');
1519: }
1520: $r->print('<tr><td>');
1.3 raeburn 1521: $r->print(&Apache::lonhtmlcommon::start_pick_box());
1522: $r->print('
1.5 raeburn 1523: <tr>
1524: <td>
1.3 raeburn 1525: <table cellspacing="1" cellpadding="4">
1526: <tr bgcolor="'.$tabcol.'" align="center">
1.5 raeburn 1527: <td><b>'.$lt{'grna'}.'</b></td>
1528: <td><b>'.$lt{'desc'}.'</b></td>
1529: <td><b>'.$lt{'grfn'}.'</b></td>
1530: <td><b>'.$lt{'gran'}.'</b></td>
1531: <td><b>'.$lt{'dfac'}.'</b></td>
1.3 raeburn 1532: </tr>
1533: <tr bgcolor="'.$rowColor2.'">
1534: <td valign="top"><small>'.$groupname.'</small></td>
1535: <td valign="top"><small>'.$description.'</small></td>
1536: <td>
1537: ');
1.5 raeburn 1538: if (@{$available} > 0) {
1.3 raeburn 1539: $r->print('<small><b>Available:</b></small>
1540: <table cellpadding="" cellspacing="1"><tr>');
1.5 raeburn 1541: my $rowcell = int(@{$available}/2) + @{$available}%2;
1542: for (my $i=0; $i<@{$available}; $i++) {
1543: if (@{$available} > 3) {
1.3 raeburn 1544: if ($i==$rowcell) {
1545: $r->print('</tr><tr>');
1546: }
1547: }
1.5 raeburn 1548: $r->print('<td><small>'.$$functions{$$available[$i]}.
1.3 raeburn 1549: '</small></td><td> </td>');
1550: }
1.5 raeburn 1551: if ((@{$available} > 3) && (@{$available}%2)) {
1.3 raeburn 1552: $r->print('<td> </td><td> </td>');
1553: }
1554: $r->print('</tr></table><br />');
1555: }
1.5 raeburn 1556: if (@{$unavailable} > 0) {
1.3 raeburn 1557: $r->print('<small><b>Unavailable:</b></small>
1558: <table cellpadding="0" cellspacing="1" border="0"><tr>');
1.5 raeburn 1559: my $rowcell = int(@{$unavailable}/2) + @{$unavailable}%2;
1560: for (my $j=0; $j<@{$unavailable}; $j++) {
1561: if (@{$unavailable} > 3) {
1.3 raeburn 1562: if ($j==$rowcell) {
1563: $r->print('</tr><tr>');
1564: }
1565: }
1.5 raeburn 1566: $r->print('<td><small>'.$$functions{$$unavailable[$j]}.
1.3 raeburn 1567: '</small></td><td> </td>');
1568: }
1.5 raeburn 1569: if ((@{$unavailable} > 3) && (@{$unavailable}%2)) {
1.3 raeburn 1570: $r->print('<td> </td><td> </td>');
1571: }
1572: $r->print('</tr></table>');
1573: }
1574: $r->print(<<"END");
1575: </td>
1.5 raeburn 1576: <td valign="top"><small><b>$lt{'difn'}
1577: </b> $granularity</small>
1578: <td valign="top"><small><b>$lt{'stda'}</b> $showstart<br />
1579: <b>$lt{'enda'}</b> $showend</small>
1.3 raeburn 1580: </td>
1581: </tr>
1582: </table>
1.5 raeburn 1583: </td>
1584: </tr>
1.3 raeburn 1585: END
1586: $r->print(&Apache::lonhtmlcommon::end_pick_box());
1.5 raeburn 1587: $r->print('</td></tr></table><br />');
1588: return;
1589: }
1590:
1591: sub pick_new_members {
1592: my ($r,$action,$formname,$tabcol,$rowColor1,$rowColor2,$available,$idx,
1593: $stored,$img,$users,$userdata,$granularity,$origmembers) = @_;
1594: my %lt = &Apache::lonlocal::texthash(
1595: 'gpme' => 'Group membership',
1596: 'addm' => 'Add members',
1597: 'setf' => 'Set functionality',
1598: 'func' => 'Functionality',
1599: 'nome' => 'No members to add at this time.',
1600: 'nnew' => 'There are no users to add as new members, as all users'.
1601: ' matching the specified type(s), role(s), and/or '.
1602: 'section(s) are already affiliated with this group.',
1603: 'yoma' => 'You may need to use the '."'".'modify existing, past or '.
1604: 'future members'."'".' page if you need to re-enable '.
1605: 'or activate access for previous or future members.',
1606: );
1607: my %members;
1608: my $totalusers = 0;
1609: my $newusers = 0;
1.3 raeburn 1610: foreach my $role (keys(%{$users})) {
1611: foreach my $user (keys(%{$$users{$role}})) {
1.5 raeburn 1612: $totalusers ++;
1613: if (ref($origmembers) eq 'HASH') {
1614: if (exists($$origmembers{$user})) {
1615: next;
1616: }
1617: }
1.3 raeburn 1618: unless (defined($members{$user})) {
1619: @{$members{$user}} = @{$$userdata{$user}};
1.5 raeburn 1620: $newusers ++;
1.3 raeburn 1621: }
1622: }
1623: }
1624: if (keys(%members) > 0) {
1.5 raeburn 1625: if (@{$available} > 0 && $granularity eq 'Yes') {
1626: $r->print(&check_uncheck_tools($r,$available));
1627: }
1628: }
1629: &topic_bar($r,$tabcol,$img,$lt{'gpme'});
1630: if (keys(%members) > 0) {
1631: $r->print('
1.1 raeburn 1632: <tr>
1.3 raeburn 1633: <td> </td>
1.5 raeburn 1634: <td colspan="3">
1.3 raeburn 1635: <table>
1.5 raeburn 1636: <tr>');
1637: &check_uncheck_buttons($r,$formname,'member',$lt{'addm'});
1638: if (@{$available} > 0 && $granularity eq 'Yes') {
1639: $r->print('<td><nobr>
1640: <fieldset><legend><b>'.$lt{'setf'}.'</b></legend>
1641: <input type="button" value="check all"
1642: onclick="javascript:checkAllTools(document.'.$formname.')" />
1643:
1644: <input type="button" value="uncheck all"
1.3 raeburn 1645: onclick="javascript:uncheckAllTools(document.'.$formname.')" />
1.5 raeburn 1646: </fieldset></nobr></td>');
1.3 raeburn 1647: }
1648: $r->print('</tr></table>
1649: </td>
1650: </tr>
1651: <tr>
1652: <td colspan="4"> </td>
1653: </tr>
1654: <tr>
1655: <td> </td>
1656: <td colspan="3">
1657: ');
1658: $r->print(&Apache::lonhtmlcommon::start_pick_box());
1.5 raeburn 1659: $r->print('
1.3 raeburn 1660: <table border="0" cellpadding="4" cellspacing="1">
1.5 raeburn 1661: <tr bgcolor="'.$tabcol.'" align="center">
1662: <td><b>'.&mt('Add?').'</b></td>
1663: <td><b><a href="javascript:changeSort('."'fullname'".')">'.&mt('Name').'</a></b></td>
1664: <td><b><a href="javascript:changeSort('."'username'".')">'.&mt('Username').'</a></b>
1.3 raeburn 1665: </td>
1.5 raeburn 1666: <td><b><a href="javascript:changeSort('."'domain'".')">'.&mt('Domain').'</a></b></td>
1667: <td><b><a href="javascript:changeSort('."'id'".')">ID</a></b></td>
1668: ');
1669: if (@{$available} > 0) {
1670: $r->print('<td><b>'.$lt{'func'}.'</b></td>');
1.3 raeburn 1671: }
1672: $r->print('</tr>');
1.5 raeburn 1673: if (@{$available} > 0) {
1674: if ($granularity eq 'Yes') {
1675: $r->print('<tr bgcolor="#cccccc">
1676: <td colspan="5"> </td>
1.7 raeburn 1677: <td align="center"><small><nobr><b>'.&mt('All:').'</b> ');
1.5 raeburn 1678: foreach my $tool (@{$available}) {
1.7 raeburn 1679: $r->print('<label><input type="checkbox" name="togglefunc" '.
1680: 'onclick="javascript:toggleTools(document.'.$formname.'.user_'.$tool.',this);"'.
1681: ' value="'.$tool.'">'.'<b>'.$tool.'</b></label> ');
1.5 raeburn 1682: }
1683: $r->print('</nobr></small></td></tr>');
1684: }
1685: }
1.3 raeburn 1686: my %Sortby = ();
1687: foreach my $user (sort(keys(%members))) {
1688: if ($env{'form.sortby'} eq 'fullname') {
1689: push(@{$Sortby{$members{$user}[$$idx{fullname}]}},$user);
1690: } elsif ($env{'form.sortby'} eq 'username') {
1691: push(@{$Sortby{$members{$user}[$$idx{uname}]}},$user);
1692: } elsif ($env{'form.sortby'} eq 'domain') {
1693: push(@{$Sortby{$members{$user}[$$idx{udom}]}},$user);
1694: } elsif ($env{'form.sortby'} eq 'id') {
1695: push(@{$Sortby{$members{$user}[$$idx{id}]}},$user);
1696: } else {
1697: push(@{$Sortby{$members{$user}[$$idx{fullname}]}},$user);
1698: }
1699: }
1700: my $rowNum = 0;
1701: my $rowColor;
1702: foreach my $key (sort(keys(%Sortby))) {
1703: foreach my $user (@{$Sortby{$key}}) {
1704: if ($rowNum %2 == 1) {
1705: $rowColor = $rowColor1;
1706: } else {
1707: $rowColor = $rowColor2;
1708: }
1709: my $id = $members{$user}[$$idx{id}];
1710: my $fullname = $members{$user}[$$idx{fullname}];
1711: my $udom = $members{$user}[$$idx{udom}];
1712: my $uname = $members{$user}[$$idx{uname}];
1713: $r->print('<tr bgcolor="'.$rowColor.'"><td align="right">
1714: <input type="checkbox" name="member" value="'.$user.'" /></td><td><small>'.
1715: $fullname.'</small></td><td><small>'.$uname.'</small></td><td><small>'.
1716: $udom.'</small></td><td><small>'.$id.'</small></td>');
1.5 raeburn 1717: if (@{$available} > 0) {
1718: $r->print('<td align="center"><nobr><small>'.
1719: ' ');
1720: foreach my $tool (@{$available}) {
1721: if ($granularity eq 'Yes') {
1.3 raeburn 1722: $r->print('<input type="checkbox" name="user_'.
1723: $tool.'" value="'.$user.'" />'.$tool.' ');
1724: } else {
1725: $r->print('<input type="hidden" name="user_'.
1726: $tool.'" value="'.$user.'" />'.$tool.' ');
1727: }
1728: }
1.5 raeburn 1729: $r->print('</small></nobr></td>');
1.3 raeburn 1730: }
1731: $r->print('</tr>'."\n");
1732: $rowNum ++;
1733: }
1734: }
1735: $r->print(&Apache::lonhtmlcommon::end_pick_box());
1736: $r->print('
1.5 raeburn 1737: </td>
1738: </tr>');
1739: } else {
1740: $r->print('
1741: <tr>
1742: <td> </td>
1743: <td colspan="3">
1744: ');
1745: if ($totalusers > 0) {
1746: $r->print($lt{'nnew'}.'<br /><br />'.$lt{'yoma'});
1747: } else {
1748: $r->print($lt{'nome'});
1749: }
1750: $r->print('
1751: </td>
1752: </tr>');
1753: }
1754: return $newusers;
1755: }
1756:
1757: sub privilege_specificity {
1758: my ($r,$tabcol,$rowColor1,$rowColor2,$action,$img,$tools,$stored,
1759: $toolprivs,$fixedprivs,$available,$formname) = @_;
1760: my %lt = &Apache::lonlocal::texthash (
1761: 'uprv' => 'User privileges',
1762: 'frty' => 'For each type of functionality you have chosen to include, '.
1763: 'there is a set of standard privileges which apply to all '.
1764: 'of those for whom the functionality is enabled.',
1765: 'thar' => 'There are also additional privileges which can be set for '.
1766: 'some, or all, members. Please choose one of the following:',
1767: 'fort' => 'For the types of functionality you have chosen to include '.
1768: 'there are no additional privileges which can be set for some '.
1769: 'or all members.',
1770: 'eaty' => 'Each of the types of functionality includes standard '.
1771: 'privileges which apply to members with access to that '.
1772: 'functionality, and may also include additional privileges '.
1773: 'which can be set for specific members.',
1774: 'cutg' => 'Currently the group is configured ',
1775: 'sdif' => 'so different group members can receive different privileges.',
1776: 'sall' => 'so all group members will receive the same privileges.',
1777: 'algm' => 'All group members will receive the same privileges.',
1778: 'smgp' => 'Some group members will receive different privileges from '.
1779: 'others.',
1780: 'thwi' => 'These will be the privileges all group members receive, '.
1781: 'if you selected the first option above.',
1782: 'thes' => 'These will be the privileges given to members assigned '.
1783: 'in the future, including via automatic group assignment '.
1784: 'for specific sections/roles ',
1785: 'asyo' => 'As you have chosen not to include any functionality in the '.
1786: 'group, no default user privileges settings need to be set.',
1787: 'plin' => 'Please indicate which <b>optional</b> privileges members '.
1788: 'will receive by default.',
1789: 'oppr' => 'Optional privileges',
1790: 'defp' => 'The default privileges new members will receive are:',
1791: );
1792: my $totaloptionalprivs = 0;
1793: foreach my $tool (@{$tools}) {
1794: foreach my $priv (sort(keys(%{$$toolprivs{$tool}}))) {
1795: if (!exists($$fixedprivs{$tool}{$priv})) {
1796: $totaloptionalprivs ++;
1797: }
1798: }
1799: }
1800: &topic_bar($r,$tabcol,$img,$lt{'uprv'});
1801: $r->print('
1802: <tr>
1803: <td> </td>
1804: <td colspan="3">
1805: ');
1806: if ((($action eq 'create') && (@{$available} > 0)) ||
1807: (($action eq 'modify') && ($formname eq 'change_settings'))) {
1808: my %specific = (
1809: 'No' => 'checked="checked"',
1810: 'Yes' => '',
1811: );
1812: if ($action eq 'create') {
1813: $r->print($lt{'frty'}.'<br />');
1814: if ($totaloptionalprivs) {
1815: $r->print($lt{'thar'});
1816: } else {
1817: $r->print($lt{'fort'});
1818: }
1819: } else {
1820: $r->print($lt{'eaty'}.' '.$lt{cutg});
1821: if ($$stored{'specificity'} eq 'Yes') {
1822: $r->print($lt{'sdif'});
1823: $specific{'Yes'} = $specific{'No'};
1824: $specific{'No'} = '';
1825: } else {
1826: $r->print($lt{'sall'});
1827: }
1828: }
1829: if ($totaloptionalprivs) {
1830: $r->print('
1.7 raeburn 1831: <br /><br /><label><nobr><input type="radio" name="specificity" value="No" '.$specific{'No'}.' /> '.$lt{'algm'}.'</nobr></label><br/>
1832: <label><nobr><input type="radio" name="specificity" value="Yes" '.$specific{'Yes'}.' /> '.$lt{'smgp'}.'</nobr></label>
1.3 raeburn 1833: </td>
1834: </tr>
1835: <tr>
1836: <td colspan="4"> </td>
1837: </tr>');
1.5 raeburn 1838: } else {
1839: $r->print('<input type="hidden" name="specificity" value="No" />');
1840: }
1841: if ($totaloptionalprivs) {
1.3 raeburn 1842: $r->print('
1.5 raeburn 1843: <tr>
1.3 raeburn 1844: <td> </td>
1.5 raeburn 1845: <td colspan="3">'.$lt{'plin'});
1846: if ($action eq 'create') {
1847: $r->print(' '.$lt{'thwi'});
1848: }
1849: $r->print('<br />'.$lt{'thes'});
1850: if ($action eq 'create') {
1851: $r->print('('.&mt('if enabled on the next page').').');
1852: } else {
1853: $r->print('('.&mt('if enabled below').').');
1854: }
1855: $r->print('<br /><br />
1.3 raeburn 1856: </td>
1.5 raeburn 1857: </tr>
1858: <tr>
1859: <td> </td>
1860: <td colspan="2"><table><tr>');
1861: &check_uncheck_buttons($r,$formname,'defpriv',$lt{'oppr'});
1862: $r->print('
1863: </tr>
1864: </table>
1.3 raeburn 1865: </td>
1866: <td width="100%"> </td>
1.5 raeburn 1867: </tr><tr>
1.3 raeburn 1868: <td> </td>
1869: <td colspan="3">
1870: <br />
1871: ');
1.5 raeburn 1872: } else {
1873: $r->print('<tr><td> </td><td colspan="3">'.$lt{'algm'}.'<br /><br />');
1.3 raeburn 1874: }
1.5 raeburn 1875: &default_privileges($r,$action,$tabcol,$rowColor1,$rowColor2,
1876: $tools,$toolprivs,$fixedprivs,$available);
1.3 raeburn 1877: } else {
1.5 raeburn 1878: if ($action eq 'create') {
1879: $r->print($lt{'asyo'});
1880: } elsif ($action eq 'modify' && $formname eq 'pick_members') {
1881: my @defprivs;
1882: if (ref($$stored{'defpriv'}) eq 'ARRAY') {
1883: @defprivs = @{$$stored{'defpriv'}};
1884: }
1885: $r->print($lt{'eaty'}.' '.$lt{cutg});
1886: if ($$stored{'specificity'} eq 'Yes') {
1887: $r->print($lt{'sdif'});
1888: } else {
1889: $r->print($lt{'sall'});
1890: }
1891: $r->print(' '.$lt{'defp'}.'<br /><br />');
1892: &display_defprivs($r,$tabcol,$rowColor1,$rowColor2,$tools,
1893: $toolprivs,\@defprivs);
1894: }
1.3 raeburn 1895: }
1896: $r->print('
1897: </td>
1898: </tr>
1.5 raeburn 1899: ');
1.3 raeburn 1900: return;
1901: }
1902:
1.5 raeburn 1903: sub default_privileges {
1904: my ($r,$action,$tabcol,$rowColor1,$rowColor2,$tools,$toolprivs,
1905: $fixedprivs,$available) = @_;
1906: my %lt = &Apache::lonlocal::texthash(
1907: 'addp' => 'Additional privileges',
1908: 'fixp' => 'Fixed privileges',
1909: 'oppr' => 'Optional privileges',
1910: 'func' => 'Function',
1911: );
1912: $r->print(&Apache::lonhtmlcommon::start_pick_box());
1913: $r->print('<tr>
1914: <td bgcolor="'.$tabcol.'" valign="top">
1915: <table cellspacing="0" cellpadding="1">
1916: <tr>
1917: <td valign="top"><b>'.$lt{'func'}.'</b></td>
1918: </tr>
1919: <tr>
1920: <td valign="top"><b>'.$lt{'fixp'}.'</b></td>
1921: </tr>
1922: <tr>
1923: <td valign="top"><b>'.$lt{'oppr'}.'</b></td>
1924: </tr>
1925: </table>
1926: </td>
1927: ');
1.3 raeburn 1928: foreach my $tool (@{$tools}) {
1.5 raeburn 1929: $r->print('<td align="center" valign="top">
1930: <table cellspacing="0" cellpadding="1">
1931: <tr bgcolor="#cccccc">
1932: <td colspan="2" align="center"><b>'.$tool.'</b></td>
1933: </tr>
1934: ');
1935: my $privcount = 0;
1936: my $fixed = '';
1937: my $dynamic = '';
1938: foreach my $priv (sort(keys(%{$$toolprivs{$tool}}))) {
1939: if (exists($$fixedprivs{$tool}{$priv})) {
1940: $fixed .= '<input type="hidden" name="defpriv" value="'.$priv.'" />'.$$toolprivs{$tool}{$priv}.' ';
1941: if ($action eq 'modify') {
1942: if (grep/^$tool$/,@{$available}) {
1943: $fixed .= '<small>'.&mt('(on)').'<small> ';
1944: } else {
1945: $fixed .= '<small>'.&mt('(off)').'<small> ';
1.3 raeburn 1946: }
1947: }
1.5 raeburn 1948: } else {
1949: $privcount ++;
1950: if ($privcount == 3) {
1951: $dynamic .= '</tr>
1952: <tr bgcolor="'.$rowColor1.'">'."\n";
1953: }
1.7 raeburn 1954: $dynamic .= '<td><label><input type="checkbox" name="defpriv" value="'.$priv.'" />'.$$toolprivs{$tool}{$priv}.'</label></td>'."\n";
1.3 raeburn 1955: }
1956: }
1.5 raeburn 1957: if ($dynamic eq '') {
1958: $dynamic = '<td>None</td>'."\n";
1959: }
1960: if ($privcount < 3) {
1961: $dynamic .= '</tr>
1962: <tr bgcolor="'.$rowColor1.'">
1963: <td colspan="2"> </td>'."\n";
1964: } elsif ($privcount%2) {
1965: $dynamic = '<td> </td>'."\n";
1966: }
1967: $r->print('<tr bgcolor="'.$rowColor2.'">
1968: <td colspan="2" align="center"><nobr>'.$fixed.'</nobr></td>
1969: </tr>
1970: <tr bgcolor="'.$rowColor1.'">'."\n".$dynamic.'</tr>'."\n".'</table>'."\n".'</td>
1971: ');
1.3 raeburn 1972: }
1.5 raeburn 1973: $r->print('</tr>'."\n");
1974: $r->print(&Apache::lonhtmlcommon::end_pick_box());
1975: $r->print('<br />');
1976: return;
1977: }
1978:
1979: sub display_defprivs {
1980: my ($r,$tabcol,$rowColor1,$rowColor2,$tools,$toolprivs,$defprivs) = @_;
1981: my %lt = &Apache::lonlocal::texthash(
1982: 'priv' => 'Privileges',
1983: 'func' => 'Function',
1984: );
1985: $r->print(&Apache::lonhtmlcommon::start_pick_box());
1986: $r->print('<tr>');
1987: my $numrows = 0;
1988: my %currprivs;
1989: foreach my $tool (@{$tools}) {
1990: @{$currprivs{$tool}} = ();
1991: foreach my $priv (sort(keys(%{$$toolprivs{$tool}}))) {
1992: if (ref($defprivs) eq 'ARRAY') {
1993: if (grep/^\Q$priv\E$/,@{$defprivs}) {
1994: push(@{$currprivs{$tool}},$priv);
1995: }
1.3 raeburn 1996: }
1997: }
1.5 raeburn 1998: my $rowcount = int(@{$currprivs{$tool}}/3);
1999: if (@{$currprivs{$tool}}%3 > 0) {
2000: $rowcount ++;
2001: }
2002: if ($rowcount > $numrows) {
2003: $numrows = $rowcount;
2004: }
2005: }
2006: my @rowCols = ($rowColor1,$rowColor2);
2007: foreach my $tool (@{$tools}) {
2008: $r->print('<td align="center" valign="top">
2009: <table cellspacing="0" cellpadding="5">
2010: <tr bgcolor="#cccccc">
2011: <td colspan="3" align="center"><b>'.$tool.'</b></td>
2012: </tr>
2013: ');
2014: my $rownum = 1;
2015: my $privcount = 0;
2016: $r->print('<tr bgcolor="'.$rowColor1.'">');
2017: foreach my $priv (@{$currprivs{$tool}}) {
2018: $privcount ++;
2019: if ($privcount%4 == 0) {
2020: $rownum ++;
2021: my $bgcol = $rownum%2;
2022: $r->print('</tr>
2023: <tr bgcolor="'.$rowCols[$bgcol].'">'."\n");
2024: }
2025: $r->print('<td>'.$$toolprivs{$tool}{$priv}.'</td>'."\n");
2026: }
2027: if ($privcount%3 > 0) {
2028: my $emptycells = 3-($privcount%3);
2029: while($emptycells > 0) {
2030: $r->print('<td> </td>'."\n");
2031: $emptycells --;
2032: }
2033: }
2034: while ($rownum < $numrows) {
2035: $rownum ++;
2036: my $bgcol = $rownum%2;
2037: $r->print('<tr bgcolor="'.$rowCols[$bgcol].'"><td colspan="3"> </td></tr>');
1.3 raeburn 2038: }
1.5 raeburn 2039: $r->print('</table>'."\n".'</td>');
2040: }
2041: $r->print('</tr>'."\n");
2042: $r->print(&Apache::lonhtmlcommon::end_pick_box());
2043: $r->print('<br />');
2044: return;
1.3 raeburn 2045: }
1.5 raeburn 2046:
2047:
2048: sub change_members_form {
2049: my ($r,$cdom,$cnum,$tabcol,$action,$formname,$page,$groupname,$description,
2050: $startdate,$enddate,$tools,$fixedprivs,$functions,$users,$userdata,
2051: $granularity,$specificity,$idx,$states,$navbuttons,$rowColor1,
2052: $rowColor2) = @_;
2053: my %lt = &Apache::lonlocal::texthash(
2054: grse => 'Group settings',
2055: mogm => 'Modify group membership',
2056: );
2057: my @regexps = ('user_','userpriv_');
2058: $r->print(&Apache::lonhtmlcommon::echo_form_input(
1.6 raeburn 2059: ['origin','action','state','page','expire','deletion',
1.7 raeburn 2060: 'reenable','activate','changepriv','sortby',
2061: 'togglefunc'],\@regexps));
1.5 raeburn 2062: my $rowimg = 1;
2063: my @available = ();
2064: my @unavailable = ();
2065: &check_tools($functions,$tools,\@available,\@unavailable);
2066: my $nexttext = $$navbuttons{'gtns'};
2067: my $prevtext = $$navbuttons{'gtpp'};
2068: $r->print('
1.3 raeburn 2069: <br />
2070: <table width="100%" cellpadding="0" cellspacing="0" border="0">
1.5 raeburn 2071: ');
2072: &topic_bar($r,$tabcol,1,$lt{'grse'});
2073: $r->print('
2074: <tr>
1.1 raeburn 2075: <td> </td>
1.5 raeburn 2076: <td colspan="3">
2077: ');
2078: &print_current_settings($r,$action,$tabcol,$rowColor1,$rowColor2,
2079: $functions,$startdate,$enddate,$groupname,
2080: $description,$granularity,\@available,\@unavailable);
2081: $r->print('
2082: </td></tr><tr><td colspan="4"> </td></tr>');
2083: &topic_bar($r,$tabcol,2,$lt{'mogm'});
2084: $r->print('
1.3 raeburn 2085: <tr>
2086: <td> </td>
2087: <td colspan="3">
2088: ');
1.5 raeburn 2089: ¤t_membership($r,$cdom,$cnum,$formname,$tabcol,$rowColor1,
2090: $rowColor2,$groupname,\@available,\@unavailable,
2091: $fixedprivs,$granularity,$specificity);
2092: $r->print('</td>');
2093: &display_navbuttons($r,$formname,$$states{$action}[$page-1],$prevtext,
2094: $$states{$action}[$page+1],$nexttext);
2095: $r->print('</table>');
2096: return;
2097: }
2098:
2099: sub current_membership {
2100: my ($r,$cdom,$cnum,$formname,$tabcol,$rowColor1,$rowColor2,$groupname,
2101: $available,$unavailable,$fixedprivs,$granularity,$specificity) = @_;
2102: my %membership = &Apache::lonnet::get_group_membership($cdom,$cnum,
2103: $groupname);
2104: my %lt = &Apache::lonlocal::texthash(
1.6 raeburn 2105: 'actn' => 'Action?',
2106: 'name' => 'Name',
2107: 'usnm' => 'Username',
2108: 'doma' => 'Domain',
2109: 'stda' => 'Start Date',
2110: 'enda' => 'End Date',
1.5 raeburn 2111: 'expi' => 'Expire',
2112: 'reen' => 'Re-enable',
2113: 'acti' => 'Activate',
2114: 'dele' => 'Delete',
2115: 'curf' => 'Current Functionality',
2116: 'chpr' => 'Change Privileges'
2117: );
2118: if (keys(%membership) > 0) {
2119: my %current = ();
2120: my %allnames = ();
2121: my $hastools = 0;
2122: my $addtools = 0;
2123: my $num_reenable = 0;
2124: my $num_activate = 0;
2125: my $num_expire - 0;
2126: foreach my $key (sort(keys(%membership))) {
2127: if ($key =~ /^\Q$groupname\E:([^:]+):([^:]+)$/) {
2128: my $uname = $1;
2129: my $udom = $2;
2130: my $user = $uname.':'.$udom;
2131: my($end,$start,@userprivs) = split(/:/,$membership{$key});
2132: unless ($start == -1) {
2133: $allnames{$udom}{$uname} = 1;
1.22 albertel 2134: $current{$user} = {
2135: uname => $uname,
2136: udom => $udom,
2137: start => &Apache::lonlocal::locallocaltime($start),
1.23 albertel 2138: currtools => [],
2139: newtools => [],
1.22 albertel 2140: };
2141:
1.5 raeburn 2142: if ($end == 0) {
2143: $current{$user}{end} = 'No end date';
2144: } else {
2145: $current{$user}{end} =
2146: &Apache::lonlocal::locallocaltime($end);
2147: }
2148: my $now = time;
2149: if (($end > 0) && ($end < $now)) {
2150: $current{$user}{changestate} = 'reenable';
2151: $num_reenable++;
2152: } elsif (($start > $now)) {
2153: $current{$user}{changestate} = 'activate';
2154: $num_activate ++;
2155: } else {
2156: $current{$user}{changestate} = 'expire';
2157: $num_expire ++;
2158: }
2159: if (@userprivs > 0) {
2160: foreach my $tool (sort(keys(%{$fixedprivs}))) {
2161: foreach my $priv (keys(%{$$fixedprivs{$tool}})) {
2162: if (grep/^$priv$/,@userprivs) {
2163: push(@{$current{$user}{currtools}},$tool);
2164: last;
2165: }
2166: }
2167: }
2168: $hastools = 1;
2169: }
2170: if (@{$available} > 0) {
2171: if (@{$current{$user}{currtools}} > 0) {
2172: if ("@{$available}" ne "@{$current{$user}{currtools}}") {
2173: foreach my $tool (@{$available}) {
2174: unless (grep/^$tool$/,@{$current{$user}{currtools}}) {
2175: push(@{$current{$user}{newtools}},$tool);
2176: }
2177: }
2178: }
2179: } else {
2180: @{$current{$user}{newtools}} = @{$available};
2181: }
2182: if (@{$current{$user}{newtools}} > 0) {
2183: $addtools = 1;
2184: }
1.3 raeburn 2185: }
2186: }
2187: }
1.5 raeburn 2188: }
2189: if (keys(%current) > 0) {
2190: my %idhash;
2191: foreach my $udom (keys(%allnames)) {
2192: %{$idhash{$udom}} = &Apache::lonnet::idrget($udom,
2193: keys(%{$allnames{$udom}}));
2194: foreach my $uname (keys(%{$idhash{$udom}})) {
2195: $current{$uname.':'.$udom}{'id'} = $idhash{$udom}{$uname};
2196: }
2197: foreach my $uname (keys(%{$allnames{$udom}})) {
2198: $current{$uname.':'.$udom}{'fullname'} =
2199: &Apache::loncommon::plainname($uname,$udom,
2200: 'lastname');
2201: }
1.3 raeburn 2202: }
1.5 raeburn 2203: $r->print('
2204: <tr>
2205: <td> </td>
2206: <td colspan="2">
2207: <table>
2208: <tr>');
2209: if ($num_expire) {
2210: &check_uncheck_buttons($r,$formname,'expire',$lt{'expi'});
2211: }
2212: if ($num_reenable) {
2213: &check_uncheck_buttons($r,$formname,'reenable',$lt{'reen'});
2214: }
2215: if ($num_activate) {
2216: &check_uncheck_buttons($r,$formname,'activate',$lt{'acti'});
2217: }
1.6 raeburn 2218: &check_uncheck_buttons($r,$formname,'deletion',$lt{'dele'});
1.5 raeburn 2219: if (@{$available} > 0) {
2220: if ($specificity eq 'Yes') {
2221: &check_uncheck_buttons($r,$formname,'changepriv',$lt{'chpr'});
2222: }
2223: if ($granularity eq 'Yes') {
2224: $r->print(&check_uncheck_tools($r,$available));
2225: $r->print('
2226: <td>
2227: <nobr>
2228: <fieldset><legend><b>'.$lt{'curf'}.'</b></legend>
2229: <input type="button" value="check all"
2230: onclick="javascript:checkAllTools(document.'.$formname.')" />
2231:
2232: <input type="button" value="uncheck all"
2233: onclick="javascript:uncheckAllTools(document.'.$formname.')" />
2234: </fieldset>
2235: </nobr>
2236: </td>
2237: ');
2238: }
1.3 raeburn 2239: }
1.5 raeburn 2240: $r->print(<<"END");
2241: </tr>
2242: </table>
2243: </td>
2244: <td width="100%"> </td>
2245: </tr>
1.3 raeburn 2246: <tr>
2247: <td colspan="4"> </td>
2248: </tr>
2249: <tr>
2250: <td> </td>
2251: <td colspan="3">
1.5 raeburn 2252: END
2253: $r->print(&Apache::lonhtmlcommon::start_pick_box());
2254: $r->print(<<"END");
2255: <table border="0" cellpadding="4" cellspacing="1">
2256: <tr bgcolor="$tabcol" align="center">
1.6 raeburn 2257: <td><b>$lt{'actn'}</b></td>
2258: <td><b><a href="javascript:changeSort('fullname')">$lt{'name'}</a></b></td>
2259: <td><b><a href="javascript:changeSort('username')">$lt{'usnm'}</a></b>
1.5 raeburn 2260: </td>
1.6 raeburn 2261: <td><b><a href="javascript:changeSort('domain')">$lt{'doma'}</a></b></td>
1.5 raeburn 2262: <td><b><a href="javascript:changeSort('id')">ID</a></b></td>
1.6 raeburn 2263: <td><b><a href="javascript:changeSort('start')">$lt{'stda'}</a></b></td>
2264: <td><b><a href="javascript:changeSort('end')">$lt{'enda'}</a></b></td>
1.5 raeburn 2265: END
1.6 raeburn 2266: my $colspan = 0;
1.5 raeburn 2267: if ($hastools) {
2268: $r->print('<td><b>'.$lt{'curf'}.'</b></td>');
1.6 raeburn 2269: $colspan ++;
1.5 raeburn 2270: }
2271: if ($addtools) {
2272: $r->print('<td><b>Additional Functionality</b></td>');
1.6 raeburn 2273: $colspan ++;
1.5 raeburn 2274: }
2275: $r->print('</tr>');
1.6 raeburn 2276: if ($colspan) {
2277: if ($granularity eq 'Yes') {
2278: $r->print('<tr bgcolor="#cccccc">
2279: <td colspan="7"> </td>
2280: <td colspan="'.$colspan.'" align="center"><small><nobr><b>'.&mt('All:').
2281: '</b> ');
2282: foreach my $tool (@{$available}) {
1.7 raeburn 2283: $r->print('<label><input type="checkbox" name="togglefunc"'.
2284: ' onclick="javascript:toggleTools(document.'.$formname.'.user_'.$tool.',this);"'.
2285: ' value="'.$tool.'">'.'<b>'.$tool.'</b></label> ');
1.6 raeburn 2286: }
2287: $r->print('</nobr></small></td></tr>');
2288: }
2289: }
1.5 raeburn 2290: my %Sortby = ();
2291: foreach my $user (sort(keys(%current))) {
2292: if ($env{'form.sortby'} eq 'fullname') {
2293: push(@{$Sortby{$current{$user}{fullname}}},$user);
2294: } elsif ($env{'form.sortby'} eq 'username') {
2295: push(@{$Sortby{$current{$user}{uname}}},$user);
2296: } elsif ($env{'form.sortby'} eq 'domain') {
2297: push(@{$Sortby{$current{$user}{udom}}},$user);
2298: } elsif ($env{'form.sortby'} eq 'id') {
2299: push(@{$Sortby{$current{$user}{id}}},$user);
2300: } else {
2301: push(@{$Sortby{$current{$user}{fullname}}},$user);
2302: }
2303: }
2304: my $rowNum = 0;
2305: my $rowColor;
2306: foreach my $key (sort(keys(%Sortby))) {
2307: foreach my $user (@{$Sortby{$key}}) {
2308: if ($rowNum %2 == 1) {
2309: $rowColor = $rowColor1;
2310: } else {
2311: $rowColor = $rowColor2;
2312: }
2313: my $id = $current{$user}{id};
2314: my $fullname = $current{$user}{fullname};
2315: my $udom = $current{$user}{udom};
2316: my $uname = $current{$user}{uname};
2317: my $start = $current{$user}{start};
2318: my $end = $current{$user}{end};
2319: $r->print('<tr bgcolor="'.$rowColor.'">
2320: <td><small>');
2321: if ($current{$user}{changestate} eq 'reenable') {
1.7 raeburn 2322: $r->print('<nobr><label>'.
1.5 raeburn 2323: '<input type="checkbox" name="reenable" value="'.$user.'" />'.
1.7 raeburn 2324: $lt{'reen'}.'</label></nobr><br />');
1.5 raeburn 2325: } elsif ($current{$user}{changestate} eq 'expire') {
1.7 raeburn 2326: $r->print('<nobr><label>'.
1.5 raeburn 2327: '<input type="checkbox" name="expire" value="'.$user.'" />'.
1.7 raeburn 2328: $lt{'expi'}.'</label></nobr><br />');
1.5 raeburn 2329: } elsif ($current{$user}{changestate} eq 'activate') {
1.7 raeburn 2330: $r->print('<nobr><label>'.
1.5 raeburn 2331: '<input type="checkbox" name="activate" value="'.$user.'" />'.
1.7 raeburn 2332: $lt{'acti'}.'</label></nobr><br />');
1.5 raeburn 2333: }
1.7 raeburn 2334: $r->print('<nobr><label>'.
1.6 raeburn 2335: '<input type="checkbox" name="deletion" value="'.$user.'" />'.
1.7 raeburn 2336: $lt{'dele'}.'</label></nobr>');
1.5 raeburn 2337: if ($specificity eq 'Yes') {
1.7 raeburn 2338: $r->print('<br /><nobr><label>'.
1.5 raeburn 2339: '<input type="checkbox" name="changepriv" value="'.$user.'" />'.$lt{'chpr'}.
1.7 raeburn 2340: '</label></nobr>');
1.5 raeburn 2341: }
2342: $r->print('
2343: </td>
2344: <td><small>'.
2345: $fullname.'</small></td><td><small>'.$uname.'</small></td><td><small>'.
2346: $udom.'</small></td><td><small>'.$id.'</small></td><td><small>'.$start.
2347: '</small></td><td><small>'.$end.'</small></td>');
2348: if ($hastools) {
1.6 raeburn 2349: $r->print('<td align="left"><small><nobr>'.
2350: ' ');
1.5 raeburn 2351: foreach my $tool (@{$current{$user}{currtools}}) {
2352: if ($granularity eq 'Yes') {
1.7 raeburn 2353: $r->print('<label><input type="checkbox" '.
2354: 'checked="checked" '.
2355: 'name="user_'.$tool.'" value="'.
2356: $user.'" />'.$tool.'</label>');
1.5 raeburn 2357: } else {
1.7 raeburn 2358: $r->print('<input type="hidden" '.
2359: 'checked="checked" '.
2360: 'name="user_'.$tool.'" value="'.
2361: $user.'" />'.$tool);
1.5 raeburn 2362: }
1.7 raeburn 2363: $r->print(' ');
1.5 raeburn 2364: }
2365: $r->print('</nobr></small></td>');
2366: }
2367: if ($addtools) {
2368: $r->print('<td align="left"><small>');
2369: if ($granularity eq 'Yes') {
2370: foreach my $tool (@{$current{$user}{newtools}}) {
1.15 albertel 2371: $r->print('<nobr><label><input type="checkbox"
1.5 raeburn 2372: name="user_'.$tool.'" value="'.
2373: $user.'" />'.$tool.
1.7 raeburn 2374: '</label></nobr> ');
1.5 raeburn 2375: }
2376: } else {
2377: foreach my $tool (@{$current{$user}{newtools}}) {
2378: $r->print('<nobr><input type="hidden"
2379: name="user_'. $tool.'" value="'.
2380: $user.'" />'.$tool.
2381: '</nobr> ');
2382: }
2383: }
2384: $r->print('</small></td>');
2385: }
2386: $r->print('</tr>'."\n");
2387: $rowNum ++;
2388: }
2389: }
2390: $r->print(&Apache::lonhtmlcommon::end_pick_box());
2391: $r->print('
1.3 raeburn 2392: </td>
1.5 raeburn 2393: </tr>');
2394: }
2395: }
2396: return;
2397: }
2398:
2399: sub check_uncheck_buttons {
2400: my ($r,$formname,$field,$title,$colspan) = @_;
2401: $r->print('
2402: <td '.$colspan.'>
2403: <nobr>
2404: <fieldset>
2405: <legend><b>'.$title.'</b></legend>
2406: <input type="button" value="check all"
2407: onclick="javascript:checkAll(document.'.$formname.'.'.$field.')" />
2408:
2409: <input type="button" value="uncheck all"
2410: onclick="javascript:uncheckAll(document.'.$formname.'.'.$field.')" />
2411: </fieldset>
2412: </nobr>
2413: </td>
2414: ');
2415: }
2416:
2417:
2418: sub change_privs_form {
2419: my ($r,$cdom,$cnum,$tabcol,$action,$formname,$page,$startdate,$enddate,
2420: $tools,$functions,$toolprivs,$fixedprivs,$userdata,$usertools,
2421: $memchg,$idx,$states,$stored,$sectioncount,$navbuttons,$rowColor1,
2422: $rowColor2) = @_;
2423: my @regexps = ('userpriv_');
2424: my $nexttext;
1.6 raeburn 2425: my %lt = &Apache::lonlocal::texthash(
2426: 'tode' => 'To be deleted',
2427: 'toex' => 'To be expired',
2428: 'nome' => 'No members to be deleted or expired from the group.',
2429: );
1.5 raeburn 2430: $r->print(&Apache::lonhtmlcommon::echo_form_input(
1.6 raeburn 2431: ['origin','action','state','page','sortby'],\@regexps));
2432: if ($env{'form.branch'} eq 'adds') {
2433: $nexttext = $$navbuttons{'adme'};
2434: } else {
2435: $nexttext = $$navbuttons{'mose'};
2436: }
1.5 raeburn 2437: $r->print('<br /><table width="100%" cellpadding="0" cellspacing="0" border="0">');
1.6 raeburn 2438: &topic_bar($r,$tabcol,3,&mt('Members to delete or expire'));
2439: my $exp_or_del = 0;
2440: if (ref($$memchg{'deletion'}) eq 'ARRAY') {
2441: if (@{$$memchg{'deletion'}} > 0) {
2442: $r->print('<tr><td> </td><td colspan="3"><b>'.$lt{'tode'}.':</b><br /><ul>');
2443: foreach my $user (@{$$memchg{'deletion'}}) {
2444: $r->print('<li>'.$$userdata{$user}[$$idx{fullname}].
2445: ' ('.$user.')</li>');
2446: }
2447: $r->print('</ul></td><tr><td colspan="4"> </td></tr>');
2448: $exp_or_del += @{$$memchg{'deletion'}};
2449: }
2450: }
2451: if (ref($$memchg{'expire'}) eq 'ARRAY') {
2452: if (@{$$memchg{'expire'}} > 0) {
2453: $r->print('<tr><td> </td><td colspan="3"><b>'.$lt{'toex'}.':</b><br /><ul>');
2454: foreach my $user (@{$$memchg{'expire'}}) {
2455: $r->print('<li>'.$$userdata{$user}[$$idx{fullname}].
2456: ' ('.$user.')</li>');
2457: }
2458: $r->print('</ul></td><tr><td colspan="4"> </td></tr>');
2459: $exp_or_del += @{$$memchg{'expire'}};
2460: }
2461: }
2462: if (!$exp_or_del) {
2463: $r->print('<tr><td> </td><td colspan="3">'.$lt{'nome'}.
2464: '</td></tr><tr><td colspan="4"> </td></tr>');
2465: }
1.5 raeburn 2466:
1.6 raeburn 2467: &topic_bar($r,$tabcol,4,&mt('Group member privileges'));
2468:
2469: my $numchgs = &member_privileges_form($r,$tabcol,$action,$formname,$tools,
2470: $toolprivs,$fixedprivs,$userdata,
2471: $usertools,$idx,$memchg,$states,
2472: $stored,$rowColor1,$rowColor2);
1.5 raeburn 2473: $r->print('</td></tr><tr><td colspan="4"> </td></tr>');
2474: my $prevtext = $$navbuttons{'gtps'};
1.6 raeburn 2475: if ($numchgs || $exp_or_del) {
2476: &display_navbuttons($r,$formname,$$states{$action}[$page-1],$prevtext,
2477: $$states{$action}[$page+1],$nexttext);
2478: } else {
2479: &display_navbuttons($r,$formname,$$states{$action}[$page-1],$prevtext);
2480: }
1.5 raeburn 2481: $r->print('</table>');
2482: return;
2483: }
2484:
2485: sub add_members_form {
2486: my ($r,$tabcol,$action,$formname,$page,$startdate,$enddate,$groupname,
2487: $description,$granularity,$sectioncount,$tools,$functions,$stored,
2488: $states,$navbuttons,$rowColor1,$rowColor2) = @_;
2489: $r->print(' <br />
2490: <table width="100%" cellpadding="0" cellspacing="0" border="0">
2491: <tr>
2492: <td> </td>
2493: <td colspan="3">
2494: ');
2495: my @available = ();
2496: my @unavailable = ();
2497: &check_tools($functions,$tools,\@available,\@unavailable);
2498: &print_current_settings($r,$action,$tabcol,$rowColor1,$rowColor2,
2499: $functions,$startdate,$enddate,$groupname,
2500: $description,$granularity,\@available,\@unavailable);
2501: $r->print('
2502: </td>
2503: </tr>
2504: <tr>
2505: <td colspan="4"> </td>
2506: </tr>');
2507:
2508: &membership_options($r,$action,$formname,$tabcol,$sectioncount,1);
2509: my $nexttext = $$navbuttons{'gtns'};
2510: my $prevtext = $$navbuttons{'gtpp'};
2511: &display_navbuttons($r,$formname,$$states{$action}[$page-1],$prevtext,
2512: $$states{$action}[$page+1],$nexttext);
1.3 raeburn 2513: $r->print('
1.5 raeburn 2514: </table>');
2515: return;
2516: }
2517:
2518: sub choose_privs_form {
2519: my ($r,$cdom,$cnum,$tabcol,$action,$formname,$page,$startdate,$enddate,
2520: $tools,$functions,$toolprivs,$fixedprivs,$userdata,$usertools,$idx,
2521: $states,$stored,$sectioncount,$navbuttons,$rowColor1,$rowColor2) = @_;
2522:
2523: my @regexps = ('userpriv_');
2524: my $nexttext;
2525:
2526: if ($action eq 'create') {
2527: push(@regexps,'sec_');
2528: $r->print(&Apache::lonhtmlcommon::echo_form_input(
1.6 raeburn 2529: ['origin','action','state','page','sortby','autoadd','autodrop'],
1.5 raeburn 2530: \@regexps));
2531: $nexttext = $$navbuttons{'crgr'};
2532: } else {
2533: $r->print(&Apache::lonhtmlcommon::echo_form_input(
1.6 raeburn 2534: ['origin','action','state','page','sortby'],\@regexps));
1.5 raeburn 2535: $nexttext = $$navbuttons{'adme'};
2536: }
2537:
2538: $r->print('<br /><table width="100%" cellpadding="0" cellspacing="0" border="0">');
2539: &topic_bar($r,$tabcol,6,&mt('Group member privileges'));
2540:
2541: &member_privileges_form($r,$tabcol,$action,$formname,$tools,$toolprivs,
2542: $fixedprivs,$userdata,$usertools,$idx,undef,
2543: $states,$stored,$rowColor1,$rowColor2);
2544:
2545: $r->print('</td></tr><tr><td colspan="4"> </td></tr>');
2546: if ($action eq 'create') {
2547: if (keys(%{$sectioncount}) > 0) {
2548: my $img1 = 7;
2549: my $img2 = 8;
2550: &mapping_options($r,$action,$formname,$page,$tabcol,$sectioncount,
2551: $states,$stored,$navbuttons,$img1,$img2,
2552: $rowColor1,$rowColor2);
2553: }
2554: }
2555: my $prevtext = $$navbuttons{'gtps'};
2556: &display_navbuttons($r,$formname,$$states{$action}[$page-1],$prevtext,
2557: $$states{$action}[$page+1],$nexttext);
2558: $r->print('</table>');
2559: return;
2560: }
2561:
2562: sub build_boxes {
2563: my ($r,$tools,$usertools,$fixedprivs,$toolprivs,$showtools,
1.6 raeburn 2564: $showboxes,$prefix,$specificity,$excluded) = @_;
1.5 raeburn 2565: my $totalboxes = 0;
2566: if (@{$tools} > 0) {
2567: if ($specificity eq 'Yes') {
2568: foreach my $tool (@{$tools}) {
2569: @{$$showboxes{$tool}} = ();
2570: foreach my $user (sort(keys(%{$usertools}))) {
1.6 raeburn 2571: if (ref($excluded) eq 'ARRAY') {
2572: if (grep/^$user$/,@{$excluded}) {
2573: next;
2574: }
1.5 raeburn 2575: }
1.6 raeburn 2576: if ($$usertools{$user}{$tool}) {
2577: unless (grep/^$tool$/,@{$showtools}) {
2578: push(@{$showtools},$tool);
2579: }
2580: foreach my $priv (sort(keys(%{$$toolprivs{$tool}}))) {
2581: unless (exists($$fixedprivs{$tool}{$priv})) {
2582: unless(grep(/^$priv$/,@{$$showboxes{$tool}})) {
2583: push(@{$$showboxes{$tool}},$priv);
2584: $totalboxes ++;
2585: }
1.5 raeburn 2586: }
2587: }
2588: }
2589: }
2590: }
2591: if ($totalboxes > 0) {
2592: $r->print('
2593: <script type="text/javascript">
2594: function checkAllTools(formname) {
2595: ');
2596: foreach my $tool (sort(keys(%{$showboxes}))) {
2597: foreach my $priv (@{$$showboxes{$tool}}) {
2598: $r->print(' checkAll(formname.'.$prefix.$priv.');'."\n");
2599: }
2600: }
2601: $r->print('
2602: }
2603: function uncheckAllTools(formname) {
2604: ');
2605: foreach my $tool (sort(keys(%{$showboxes}))) {
2606: foreach my $priv (@{$$showboxes{$tool}}) {
2607: $r->print(' uncheckAll(formname'.$prefix.$priv.');'."\n");
2608: }
2609: }
2610: $r->print('
2611: }
2612: </script>
2613: ');
2614: }
2615: }
2616: }
2617: return $totalboxes;
2618: }
2619:
2620: sub member_privileges_form {
2621: my ($r,$tabcol,$action,$formname,$tools,$toolprivs,$fixedprivs,$userdata,
2622: $usertools,$idx,$memchg,$states,$stored,$rowColor1,$rowColor2) = @_;
2623: my %lt = &Apache::lonlocal::texthash(
2624: 'addp' => 'Additional privileges',
2625: 'fixp' => 'Fixed privileges',
2626: 'oppr' => 'Optional privileges',
2627: 'func' => 'Function',
2628: 'forf' => 'For the functionality you have chosen to include '.
2629: 'there are no optional privileges to set besides '.
2630: 'the standard privileges.',
2631: 'algr' => 'All group members will receive the same privileges.',
2632: 'asno' => 'As no group members are being added, '.
2633: 'there are no specific user privileges to set.',
2634: 'asng' => 'As no group tools will be made available to users, '.
2635: 'there are no specific user privileges to set.',
1.6 raeburn 2636: 'nogm' => 'No group member privileges to display or set, '.
2637: 'as you have not indicated that you will be activating,'.
2638: ' re-enabling, changing privileges, or adding/removing '.
2639: 'functionality for any current members ',
1.5 raeburn 2640: 'full' => 'Fullname',
2641: 'user' => 'Username',
2642: 'doma' => 'Domain',
2643: );
2644: my @defprivs;
2645: my $specificity;
2646: if ($action eq 'create') {
2647: if (defined($env{'form.defpriv'})) {
2648: @defprivs = &Apache::loncommon::get_env_multiple('form.defpriv');
2649: }
2650: $specificity = $env{'form.specificity'};
2651: } else {
1.17 raeburn 2652: if (defined($$stored{'defpriv'})) {
2653: @defprivs = @{$$stored{'defpriv'}};
2654: }
1.5 raeburn 2655: $specificity = $$stored{'specificity'};
2656: }
2657: my @showtools;
2658: my %showboxes = ();
2659: my $numtools = 1 + @{$tools};
1.3 raeburn 2660:
1.6 raeburn 2661: my @excluded = ();
2662: my $numchgs = 0;
2663: if ($formname eq 'change_privs') {
2664: my @currmembers = ();
2665: if (ref($$memchg{'deletion'}) eq 'ARRAY') {
2666: push(@excluded,@{$$memchg{'deletion'}});
2667: }
2668: if (ref($$memchg{'expire'}) eq 'ARRAY') {
2669: push(@excluded,@{$$memchg{'expire'}});
2670: }
2671: if (@excluded > 0) {
2672: foreach my $user (sort(keys(%{$usertools}))) {
2673: if (grep/^$user$/,@excluded) {
2674: next;
2675: }
2676: push(@currmembers,$user);
2677: }
2678: } else {
2679: @currmembers = sort(keys(%{$usertools}));
2680: }
2681: $numchgs = @currmembers;
2682: if (!$numchgs) {
2683: $r->print('<tr><td> </td><td colspan="3">'.$lt{'nogm'});
2684: return $numchgs;
2685: }
2686: }
2687:
2688: my $totalboxes = &build_boxes($r,$tools,$usertools,$fixedprivs,
2689: $toolprivs,\@showtools,\%showboxes,
2690: 'userpriv_',$specificity,\@excluded);
1.5 raeburn 2691: if (@{$tools} > 0) {
2692: if ($specificity eq 'Yes') {
2693: if ($totalboxes > 0) {
2694: my $numcells = 2;
2695: my $colspan = $numcells + 1;
2696: my %total;
1.6 raeburn 2697: if (keys(%{$usertools}) > 1) {
2698: $r->print('
1.5 raeburn 2699: <tr>
2700: <td> </td>
2701: <td colspan="3">
2702: <table border="0" cellspacing="2" cellpadding="2" border="0">
2703: <tr>
2704: ');
1.6 raeburn 2705: foreach my $tool (@{$tools}) {
2706: if (@{$showboxes{$tool}} > 0) {
2707: $r->print('<td valign="top">');
2708: $r->print('<table class="thinborder"><tr bgcolor="'.
2709: $tabcol.'"><th colspan="'.$colspan.'">'.
2710: $tool.'</th></tr><tr>');
2711: my $privcount = 0;
2712: foreach my $priv (@{$showboxes{$tool}}) {
2713: $privcount ++;
2714: if (($privcount == @{$showboxes{$tool}}) &&
2715: ($privcount > 1)) {
2716: if ($privcount%$numcells) {
2717: $r->print('<td colspan="'.$colspan.'">');
2718: } else {
2719: $r->print('<td>');
2720: }
1.5 raeburn 2721: } else {
2722: $r->print('<td>');
2723: }
1.6 raeburn 2724: $r->print(qq|
1.5 raeburn 2725: <fieldset><legend><b>$$toolprivs{$tool}{$priv}</b></legend>
2726: <nobr>
2727: <input type="button" value="check all"
2728: onclick="javascript:checkAll(document.$formname.userpriv_$priv)" />
2729:
2730: <input type="button" value="uncheck all"
2731: onclick="javascript:uncheckAll(document.$formname.userpriv_$priv)" />
2732: </nobr></fieldset><br />|);
1.6 raeburn 2733: $r->print('</td>');
2734: if ($privcount < @{$showboxes{$tool}}) {
2735: if (@{$showboxes{$tool}} > 2) {
2736: if ($privcount%$numcells == 0) {
2737: $r->print('</tr><tr>');
2738: }
2739: } else {
2740: $r->print('<tr></tr>');
1.5 raeburn 2741: }
2742: }
2743: }
1.6 raeburn 2744: $r->print('</tr></table></td><td> </td>');
1.5 raeburn 2745: }
2746: }
1.6 raeburn 2747: $r->print('</tr></table></td></tr>');
2748: $r->print('<tr><td colspan="4"> </td></tr>');
1.5 raeburn 2749: }
1.6 raeburn 2750: $r->print('<tr><td> </td><td colspan="3">');
1.5 raeburn 2751: $r->print(&Apache::lonhtmlcommon::start_pick_box());
2752: $r->print(<<"END");
2753: <tr bgcolor="$tabcol">
2754: <th><b>$lt{'full'}</th>
2755: <th><b>$lt{'user'}</th>
2756: <th>$lt{'doma'}</th>
2757: <th colspan="$numtools">$lt{'addp'}</th>
2758: </tr>
2759: END
2760: &member_privs_entries($r,$tabcol,$rowColor1,$rowColor2,
2761: $usertools,$toolprivs,$fixedprivs,
1.6 raeburn 2762: $userdata,$idx,\@showtools,\@defprivs,
2763: \@excluded);
1.5 raeburn 2764: $r->print('</td>');
2765: $r->print(&Apache::lonhtmlcommon::end_pick_box());
2766: $r->print('</td></tr>
2767: <tr>
2768: <td colspan="4"> </td>
2769: </tr>
2770: ');
2771: } else {
2772: $r->print('<tr><td> </td><td colspan="3">'.$lt{'forf'}.
2773: '<br />');
2774: &display_defprivs($r,$tabcol,$rowColor1,$rowColor2,$tools,
2775: $toolprivs,\@defprivs);
2776: }
2777: } else {
2778: if (keys(%{$usertools}) > 0) {
2779: $r->print('<tr><td> </td><td colspan="3">'.$lt{'algr'}.
2780: '<br /><br />');
2781: &display_defprivs($r,$tabcol,$rowColor1,$rowColor2,$tools,
2782: $toolprivs,\@defprivs);
2783: } else {
2784: $r->print('<tr><td> </td><td colspan="3">'.$lt{'asno'}.
2785: '<br />');
2786: }
2787: }
2788: } else {
2789: $r->print('<tr><td> </td><td colspan="3">'.$lt{'asng'});
2790: }
1.6 raeburn 2791: return $numchgs;
1.1 raeburn 2792: }
2793:
1.5 raeburn 2794: sub process_request {
2795: my ($r,$cdom,$cnum,$tabcol,$action,$state,$page,$groupname,$description,
2796: $specificity,$userdata,$startdate,$enddate,$tools,$functions,$toolprivs,
2797: $usertools,$idx,$types,$roles,$sections,$states,$navbuttons,$memchg,
2798: $sectioncount,$stored,$rowColor1,$rowColor2) = @_;
1.3 raeburn 2799:
2800: $r->print(&Apache::lonhtmlcommon::echo_form_input(
1.6 raeburn 2801: ['origin','action','state','page','sortby']));
1.5 raeburn 2802:
2803: my $earlyout = &validate_groupname($groupname,$action,$cdom,$cnum);
2804: if ($earlyout) {
2805: $r->print('
2806: <table width="100%" cellpadding="0" cellspacing="0" border="0">
2807: <tr>
2808: <td> </td>
2809: <td colspan="3">
2810: '.$earlyout.'</td></tr>');
2811: &display_navbuttons($r,$state,$$states{$action}[$page-1],
2812: $$navbuttons{'gtps'});
2813: $r->print('</table>');
2814: return;
2815: }
2816:
2817: my @defprivs = ();
2818: if ($action eq 'create' || $state eq 'chgresult') {
2819: if (defined($env{'form.defpriv'})) {
2820: @defprivs = &Apache::loncommon::get_env_multiple('form.defpriv');
2821: }
2822: if ($state eq 'chgresult') {
2823: my @okprivs = ();
2824: foreach my $tool (@{$tools}) {
2825: foreach my $priv (sort(keys(%{$$toolprivs{$tool}}))) {
2826: push(@okprivs,$priv);
2827: }
2828: }
2829: my @temp = ();
2830: foreach my $defpriv (@defprivs) {
2831: if (grep/^$defpriv$/,@okprivs) {
2832: push(@temp,$defpriv);
2833: }
2834: }
2835: @defprivs = @temp;
2836: }
2837: } else {
1.17 raeburn 2838: if (defined($$stored{'defpriv'})) {
2839: @defprivs = @{$$stored{'defpriv'}};
2840: }
1.5 raeburn 2841: }
2842:
2843: my $outcome;
2844: if ($action eq 'create' || $state eq 'chgresult') {
2845: $outcome = &write_group_data($r,$cdom,$cnum,$action,$state,$groupname,
2846: $description,$startdate,$enddate,
2847: $specificity,$functions,$tools,
2848: $sectioncount,$roles,$types,$sections,
2849: \@defprivs,$stored);
2850: }
2851: if (($action eq 'create' && $outcome eq 'ok') || (($action eq 'modify') &&
2852: (($state eq 'memresult') || ($state eq 'addresult')))) {
1.6 raeburn 2853: &process_membership($r,$cdom,$cnum,$action,$state,$groupname,$tools,
2854: $enddate,$startdate,$userdata,$idx,$toolprivs,
2855: $usertools,$specificity,\@defprivs,$memchg);
1.5 raeburn 2856: }
2857: return;
2858: }
2859:
2860: sub write_group_data {
2861: my ($r,$cdom,$cnum,$action,$state,$groupname,$description,$startdate,
2862: $enddate,$specificity,$functions,$tools,$sectioncount,$roles,$types,
2863: $sections,$defprivs,$stored) = @_;
2864: my $now = time;
2865: my $creation = $now;
2866: my $creator = $env{'user.name'}.':'.$env{'user.domain'};
2867: if ($state eq 'chgresult') {
2868: $creation = $$stored{'creation'};
2869: $creator = $$stored{'creator'};
2870: }
1.24 www 2871: my $esc_description = &escape($description);
1.5 raeburn 2872: my @single_attributes = ('description','functions','startdate','enddate',
2873: 'creation','modified','creator','granularity',
2874: 'specificity','autoadd','autodrop');
2875: my @mult_attributes = ('roles','types','sectionpick','defpriv');
1.15 albertel 2876:
1.5 raeburn 2877: my %groupinfo = (
2878: description => $esc_description,
2879: startdate => $startdate,
2880: enddate => $enddate,
2881: creation => $creation,
2882: modified => $now,
2883: creator => $creator,
2884: granularity => $env{'form.granularity'},
2885: specificity => $specificity,
2886: autoadd => $env{'form.autoadd'},
2887: autodrop => $env{'form.autodrop'},
2888: );
2889: foreach my $func (keys(%{$functions})) {
2890: my $status;
2891: if (grep(/^$func$/,@{$tools})) {
2892: $status = 'on';
2893: } else {
2894: $status = 'off';
2895: }
2896: $groupinfo{'functions'} .= qq|<name id="$func">$status</name>|;
2897: }
2898:
2899: $groupinfo{'roles'} = $roles;
2900: $groupinfo{'types'} = $types;
2901: $groupinfo{'sectionpick'} = $sections;
2902: $groupinfo{'defpriv'} = $defprivs;
2903:
2904: my %groupsettings = ();
2905: foreach my $item (@single_attributes) {
2906: $groupsettings{$groupname} .= qq|<$item>$groupinfo{$item}</$item>|;
2907: }
2908: foreach my $item (@mult_attributes) {
2909: foreach my $entry (@{$groupinfo{$item}}) {
2910: $groupsettings{$groupname} .= qq|<$item>$entry</$item>|;
2911: }
2912: }
2913: my $autosec;
2914: my @autorole = &Apache::loncommon::get_env_multiple('form.autorole');
1.15 albertel 2915:
1.5 raeburn 2916: foreach my $role (@autorole) {
2917: if (defined($env{'form.sec_'.$role})) {
2918: my @autosections=&Apache::loncommon::get_env_multiple('form.sec_'.
2919: $role);
2920: $autosec .= '<role id="'.$role.'">';
2921: foreach my $sec (@autosections) {
2922: $autosec .= '<section>'.$sec.'</section>';
2923: }
2924: $autosec .= '</role>';
2925: }
2926: }
2927: if ($autosec) {
2928: $groupsettings{$groupname} .= qq|<autosec>$autosec</autosec>|;
2929: }
2930: my $result = &Apache::lonnet::modify_coursegroup($cdom,$cnum,
2931: \%groupsettings);
2932:
2933: if ($result eq 'ok') {
2934: if ($action eq 'create') {
2935: my $put_result = &create_homepage($cdom,$cnum,$groupname,
2936: \%groupinfo,$tools);
2937: $r->print('Group '.$groupname.' was created.<br />');
2938: } else {
2939: $r->print('Group '.$groupname.' was updated.<br />');
2940: }
2941: } else {
2942: my %actiontype = (
2943: 'create' => 'creating',
2944: 'modify' => 'modifying',
2945: );
2946: &Apache::lonnet::logthis('Failed to store group '.$groupname.
2947: 'in course: '.$cnum.' in domain: '.$cdom);
2948: $r->print(&mt('An error occurred when [_1] the new group. '.
2949: 'Please try again.',$actiontype{$action}));
2950: }
2951: return $result;
2952: }
2953:
2954: sub process_membership {
1.6 raeburn 2955: my ($r,$cdom,$cnum,$action,$state,$groupname,$tools,$enddate,$startdate,
2956: $userdata,$idx,$toolprivs,$usertools,$specificity,$defprivs,$memchg)=@_;
1.5 raeburn 2957: my %usersettings = ();
1.6 raeburn 2958: my %added= ();
2959: my %failed = ();
2960: my $num_ok = 0;
2961: my $num_fail = 0;
1.3 raeburn 2962: my %group_privs = ();
1.20 raeburn 2963: my %curr_privs = ();
1.21 raeburn 2964: my %curr_start = ();
2965: my %curr_end = ();
1.3 raeburn 2966: my %tooltype = ();
1.5 raeburn 2967:
1.3 raeburn 2968: foreach my $tool (@{$tools}) {
2969: foreach my $priv (sort(keys(%{$$toolprivs{$tool}}))) {
2970: $tooltype{$priv} = $tool;
1.5 raeburn 2971: if ($specificity eq 'Yes') {
1.3 raeburn 2972: my @users =
2973: &Apache::loncommon::get_env_multiple('form.userpriv_'.$priv);
2974: foreach my $user (@users) {
2975: $group_privs{$user} .= $priv.':';
1.8 raeburn 2976: if ($state eq 'memresult') {
2977: unless (exists($$usertools{$user}{$tool})) {
2978: $$usertools{$user}{$tool} = 1;
2979: }
2980: }
1.3 raeburn 2981: }
2982: } else {
1.5 raeburn 2983: if (@{$defprivs} > 0) {
1.26 ! raeburn 2984: if (grep/^\Q$priv\E$/,@{$defprivs}) {
1.5 raeburn 2985: foreach my $user (sort(keys(%{$usertools}))) {
2986: if ($$usertools{$user}{$tool}) {
2987: $group_privs{$user} .= $priv.':';
2988: }
1.3 raeburn 2989: }
2990: }
2991: }
2992: }
2993: }
2994: }
2995: foreach my $user (keys(%group_privs)) {
2996: $group_privs{$user} =~ s/:$//;
2997: }
1.5 raeburn 2998:
1.6 raeburn 2999: my $now = time;
3000: my @activate = ();
3001: my @expire = ();
3002: my @deletion = ();
3003: my @reenable = ();
1.20 raeburn 3004: my @unchanged = ();
1.6 raeburn 3005: if ($state eq 'memresult') {
3006: if (ref($$memchg{'activate'}) eq 'ARRAY') {
3007: @activate = @{$$memchg{'activate'}};
3008: }
3009: if (ref($$memchg{'expire'}) eq 'ARRAY') {
3010: @expire = @{$$memchg{'expire'}};
3011: }
3012: if (ref($$memchg{'deletion'}) eq 'ARRAY') {
3013: @deletion = @{$$memchg{'deletion'}};
3014: }
3015: if (ref($$memchg{'reenable'}) eq 'ARRAY') {
3016: @reenable = @{$$memchg{'reenable'}};
3017: }
1.20 raeburn 3018: my %membership = &Apache::lonnet::get_group_membership($cdom,$cnum,
3019: $groupname);
3020: foreach my $key (sort(keys(%membership))) {
3021: if ($key =~ /^\Q$groupname\E:([^:]+:[^:]+)$/) {
1.21 raeburn 3022: ($curr_end{$1},$curr_start{$1},$curr_privs{$1}) =
3023: split(/:/,$membership{$key},3);
1.20 raeburn 3024: }
3025: }
1.6 raeburn 3026: if (@expire + @deletion > 0) {
3027: foreach my $user (@expire) {
1.21 raeburn 3028: my $savestart = $curr_start{$user};
3029: if ($savestart > $now) {
3030: $savestart = $now;
1.6 raeburn 3031: }
1.21 raeburn 3032: $usersettings{$groupname.':'.$user} = $now.':'.$savestart.':'.
3033: $curr_privs{$user};
1.6 raeburn 3034: if (&Apache::lonnet::modify_group_roles($cdom,$cnum,$groupname,
1.21 raeburn 3035: $user,$now,$savestart,
3036: $curr_privs{$user}) eq 'ok') {
1.6 raeburn 3037: push(@{$added{'expired'}},$user);
3038: $num_ok ++;
3039: } else {
3040: push(@{$failed{'expired'}},$user);
3041: $num_fail ++;
3042: }
3043: }
3044: foreach my $user (@deletion) {
3045: $usersettings{$groupname.':'.$user} = $now.':-1:';
3046: if (&Apache::lonnet::modify_group_roles($cdom,$cnum,$groupname,
3047: $user,$now,'-1','')
3048: eq 'ok') {
3049: push(@{$added{'deleted'}},$user);
3050: $num_ok ++;
3051: } else {
3052: push(@{$failed{'deleted'}},$user);
3053: $num_fail ++;
3054: }
3055: }
3056: }
1.8 raeburn 3057: }
1.6 raeburn 3058:
1.5 raeburn 3059: foreach my $user (sort(keys(%{$usertools}))) {
1.20 raeburn 3060: if ((grep(/^$user$/,@expire)) || (grep(/^$user$/,@deletion))) {
3061: next;
3062: }
1.6 raeburn 3063: my $type;
3064: my $start = $startdate;
3065: my $end = $enddate;
3066: if ($state eq 'memresult') {
1.20 raeburn 3067: if ($curr_privs{$user} eq $group_privs{$user}) {
3068: push(@unchanged,$user);
3069: next;
3070: }
1.21 raeburn 3071: if (exists($curr_start{$user})) {
3072: $start = $curr_start{$user};
3073: }
3074: if (exists($curr_end{$user})) {
3075: $end = $curr_end{$user};
3076: }
1.6 raeburn 3077: $type = 'modified';
3078: if (@activate > 0) {
3079: if (grep/^$user$/,@activate) {
3080: $start = $now;
1.21 raeburn 3081: $end = $enddate;
1.6 raeburn 3082: $type = 'activated';
3083: }
3084: }
3085: if (@reenable > 0) {
3086: if (grep/^$user$/,@reenable) {
1.21 raeburn 3087: $start = $startdate;
3088: $end = $enddate;
1.6 raeburn 3089: $type = 'reenabled';
3090: }
3091: }
3092: } else {
3093: $type = 'added';
3094: }
3095: $usersettings{$groupname.':'.$user} = $end.':'.$start.':'.
1.5 raeburn 3096: $group_privs{$user};
3097: if (&Apache::lonnet::modify_group_roles($cdom,$cnum,$groupname,
1.6 raeburn 3098: $user,$end,$start,
1.5 raeburn 3099: $group_privs{$user}) eq 'ok') {
1.6 raeburn 3100: push(@{$added{$type}},$user);
3101: $num_ok ++;
1.3 raeburn 3102: } else {
1.6 raeburn 3103: push(@{$failed{$type}},$user);
3104: $num_fail ++;
1.5 raeburn 3105: }
3106: }
3107: my $roster_result = &Apache::lonnet::modify_coursegroup_membership($cdom,
3108: $cnum,\%usersettings);
1.6 raeburn 3109: if ($num_ok) {
3110: foreach my $type (sort(keys(%added))) {
3111: $r->print(&mt('The following users were successfully [_1]',$type));
1.20 raeburn 3112: if (!($type eq 'deleted' || $type eq 'expired')) {
1.6 raeburn 3113: $r->print(&mt(' with the following privileges'));
3114: }
3115: $r->print(':<br />');
3116: foreach my $user (@{$added{$type}}) {
1.8 raeburn 3117: my $privlist = '';
3118: if (!($type eq 'deleted' || $type eq 'expired')) {
3119: $privlist = ': ';
1.6 raeburn 3120: my @privs = split(/:/,$group_privs{$user});
3121: my $curr_tool = '';
3122: foreach my $priv (@privs) {
3123: unless ($curr_tool eq $tooltype{$priv}) {
3124: $curr_tool = $tooltype{$priv};
3125: $privlist .= '<b>'.$curr_tool.'</b>: ';
3126: }
3127: $privlist .= $$toolprivs{$curr_tool}{$priv}.', ';
3128: }
3129: $privlist =~ s/, $//;
3130: }
1.8 raeburn 3131: $r->print($$userdata{$user}[$$idx{fullname}].' - '.$user.$privlist.'<br />');
1.6 raeburn 3132: }
1.20 raeburn 3133: $r->print('<br />');
1.6 raeburn 3134: }
3135: }
3136: if ($num_fail) {
3137: foreach my $type (sort(keys(%failed))) {
3138: $r->print(&mt('The following users could not be [_1], because an error occurred:<br />',$type));
3139: foreach my $user (@{$failed{$type}}) {
3140: $r->print($$userdata{$user}[$$idx{fullname}].' - '.$user.'<br />');
3141: }
1.5 raeburn 3142: }
1.20 raeburn 3143: $r->print('<br />');
3144: }
3145: if (@unchanged > 0) {
3146: $r->print(&mt('No change occurred for the following users:<br />'));
3147: foreach my $user (sort(@unchanged)) {
3148: $r->print($$userdata{$user}[$$idx{fullname}].' - '.$user.'<br />');
3149: }
3150: $r->print('<br />');
1.5 raeburn 3151: }
3152: if ($roster_result eq 'ok') {
1.17 raeburn 3153: $r->print('<br />'.&mt('Group membership list updated.'));
1.5 raeburn 3154: } else {
1.17 raeburn 3155: $r->print('<br />'.&mt('An error occurred while updating the group membership list -').$roster_result.'<br />');
1.5 raeburn 3156: }
3157: return;
3158: }
3159:
3160: sub mapping_options {
3161: my ($r,$action,$formname,$page,$tabcol,$sectioncount,$states,$stored,
3162: $navbuttons,$img1,$img2,$rowColor1,$rowColor2) = @_;
3163: my %lt = &Apache::lonlocal::texthash(
3164: 'auto' => 'Settings for automatic group enrollment',
3165: 'gmma' => 'Group membership mapping to specific sections/roles',
3166: 'endi' => 'Enable/disable automatic group enrollment for '.
3167: 'users in specified roles and sections',
3168: '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.',
3169: '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.",
3170: 'pirs' => 'Pick roles and sections for automatic group enrollment',
3171: 'curr' => 'Currently set to',
3172: 'on' => 'on',
3173: 'off' => 'off',
3174: 'auad' => 'Automatically enable group membership when roles are added?',
3175: 'auex' => 'Automatically expire group membership when roles are removed?',
3176: 'mapr' => 'Mapping of roles and sections affected by automatic group enrollment/disenrollment follows scheme chosen below.',
3177: );
3178: &automapping($r,$action,$tabcol,$stored,\%lt,$img1);
3179: $r->print('
3180: <tr>
3181: <td colspan="4"> </td>
3182: </tr>');
3183: &mapping_settings($r,$tabcol,$rowColor1,$rowColor2,$sectioncount,\%lt,
3184: $stored,$img2);
3185: return;
3186: }
3187:
3188: sub automapping {
3189: my ($r,$action,$tabcol,$stored,$lt,$image) = @_;
3190: my $add = 'off';
3191: my $drop = 'off';
3192: if (exists($$stored{'autoadd'})) {
3193: $add = $$stored{'autoadd'};
3194: }
3195: if (exists($$stored{'autodrop'})) {
3196: $drop = $$stored{'autodrop'};
3197: }
3198: &topic_bar($r,$tabcol,$image,$$lt{'endi'});
3199: $r->print('
3200: <tr>
3201: <td> </td>
3202: <td colspan="3">
3203: <b>'.$$lt{'gmma'}.':</b><br />'.$$lt{'adds'}.'<br />'.$$lt{'drops'}.'<br />
3204: </td>
3205: </tr>
3206: <tr>
3207: <td colspan="4"> </td>
3208: </tr>
3209: <tr>
3210: <td> </td>
3211: <td colspan="3">
3212: <nobr>'.$$lt{'auad'}.':
1.18 albertel 3213: <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 3214: if ($action eq 'modify') {
3215: $r->print(' ('.$$lt{'curr'}.' <b>'.$$lt{$add}.'</b>)');
3216: }
3217: $r->print('
3218: </nobr>
3219: </td>
3220: </tr>
3221: <tr>
3222: <td> </td>
3223: <td colspan="3">
3224: <nobr>'.$$lt{'auex'}.':
1.18 albertel 3225: <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 3226: if ($action eq 'modify') {
3227: $r->print(' ('.$$lt{'curr'}.' <b>'.$$lt{$drop}.'</b>)');
1.3 raeburn 3228: }
1.5 raeburn 3229: $r->print('</nobr>
3230: </td>
3231: </tr>
3232: <tr>
3233: <td colspan="4"> </td>
3234: </tr>
3235: <tr>
3236: <td> </td>
3237: <td colspan="3">'.$$lt{'mapr'}.'
3238: </td>
3239: </tr>
3240: ');
3241: }
1.3 raeburn 3242:
1.5 raeburn 3243: sub mapping_settings {
3244: my ($r,$tabcol,$rowColor1,$rowColor2,$sectioncount,$lt,$stored,$image) = @_;
3245: my @sections = keys(%{$sectioncount});
3246: if (@sections > 0) {
3247: @sections = sort {$a cmp $b} @sections;
1.17 raeburn 3248: unshift(@sections,'none'); # Put 'no sections' next
3249: unshift(@sections,'all'); # Put 'all' at the front of the list
1.3 raeburn 3250: }
1.5 raeburn 3251: &topic_bar($r,$tabcol,$image,$$lt{'pirs'});
3252: $r->print('
3253: <tr>
3254: <td> </td>
3255: <td colspan="3">
3256: ');
3257: my @roles = &standard_roles();
3258: my %customroles = &my_custom_roles();
3259: $r->print(&Apache::lonhtmlcommon::start_pick_box());
3260: $r->print('
3261: <tr bgcolor="'.$tabcol.'">
3262: <th>'.&mt('Active?').'</th>
3263: <th>'.&mt('Role').'</th>');
3264: if (@sections > 0) {
3265: $r->print('<th>'.&mt('Sections').'</th></tr>'."\n");
1.3 raeburn 3266: }
1.5 raeburn 3267: my $rowNum = 0;
3268: my $rowColor;
3269: foreach my $role (@roles) {
3270: my $plrole=&Apache::lonnet::plaintext($role);
3271: my $sections_sel;
3272: if (@sections > 0) {
1.17 raeburn 3273: if ($role eq 'cc') {
3274: $sections_sel = '<td align="right">'.
3275: &mt('all sections').'<input type="hidden" '.
3276: 'name="sec_cc" value="all" /></td>';
3277: } else {
3278: $sections_sel='<td align="right">'.
3279: §ions_selection(\@sections,'sec_'.$role).
3280: '</td>';
3281: }
1.5 raeburn 3282: }
3283: if ($rowNum %2 == 1) {
3284: $rowColor = $rowColor1;
3285: } else {
3286: $rowColor = $rowColor2;
1.3 raeburn 3287: }
1.5 raeburn 3288: $r->print('<tr bgcolor="'.$rowColor.'"><td><input type="checkbox" '.
3289: 'name="autorole" value="'.$role.'"></td><td>'.$plrole.
3290: '</td>'.$sections_sel.'</tr>');
3291: $rowNum ++;
3292: }
3293: foreach my $role (sort(keys(%customroles))) {
3294: my $sections_sel;
3295: if (@sections > 0) {
3296: $sections_sel = '<td>'.§ions_selection(\@sections,'sec_'.$role).
3297: '</td>';
1.3 raeburn 3298: }
1.5 raeburn 3299: if ($rowNum %2 == 1) {
3300: $rowColor = $rowColor1;
1.3 raeburn 3301: } else {
1.5 raeburn 3302: $rowColor = $rowColor2;
3303: }
3304: $r->print('<tr bgcolor="'.$rowColor.'"><td><input type="checkbox" '.
3305: 'value="'.$role.'"></td><td>'.$role.'</td>'.
3306: $sections_sel.'</tr>');
3307: $rowNum ++;
3308: }
3309: $r->print(&Apache::lonhtmlcommon::end_pick_box());
3310: return;
3311: }
1.3 raeburn 3312:
1.5 raeburn 3313: sub standard_roles {
1.17 raeburn 3314: my @roles = ('cc','in','ta','ep','st');
1.5 raeburn 3315: return @roles;
3316: }
3317:
3318: sub my_custom_roles {
3319: my %returnhash=();
3320: my %rolehash=&Apache::lonnet::dump('roles');
3321: foreach (keys %rolehash) {
3322: if ($_=~/^rolesdef\_(\w+)$/) {
3323: $returnhash{$1}=$1;
3324: }
3325: }
3326: return %returnhash;
3327: }
3328:
3329: sub modify_menu {
3330: my ($r,$groupname,$page) = @_;
3331: my @menu =
3332: (
3333: { text => 'Modify default group settings',
3334: help => 'Course_Modify_Group',
3335: state => 'change_settings',
3336: branch => 'settings',
3337: },
1.6 raeburn 3338: { text => 'Modify access, tools and/or privileges for previous, '.
3339: 'future, or current members',
1.5 raeburn 3340: help => 'Course_Modify_Group_Membership',
3341: state => 'change_members',
3342: branch => 'members',
3343: },
3344: { text => 'Add member(s) to the group',
3345: help => 'Course_Group_Add_Members',
3346: state => 'add_members',
3347: branch => 'adds',
3348: },
3349: );
3350: my $menu_html = '';
3351: foreach my $menu_item (@menu) {
3352: $menu_html .=
3353: '<p><font size="+1"><a href="/adm/coursegroups?action=modify&refpage='.$env{'form.refpage'}.'&groupname='.$groupname.'&state='.$menu_item->{'state'}.'&branch='.$menu_item->{'branch'}.'">';
3354: $menu_html.= &mt($menu_item->{'text'}).'</a></font>';
3355: if (exists($menu_item->{'help'})) {
3356: $menu_html.=
3357: &Apache::loncommon::help_open_topic($menu_item->{'help'});
3358: }
3359: $menu_html.='</p>'.$/;
1.3 raeburn 3360: }
1.5 raeburn 3361: $r->print($menu_html);
1.3 raeburn 3362: return;
3363: }
3364:
3365: sub member_privs_entries {
1.5 raeburn 3366: my ($r,$tabcol,$rowColor1,$rowColor2,$usertools,$toolprivs,
1.6 raeburn 3367: $fixedprivs,$userdata,$idx,$showtools,$defprivs,$excluded) = @_;
1.3 raeburn 3368: my $rowColor;
3369: my $rowNum = 0;
1.5 raeburn 3370: foreach my $user (sort(keys(%{$usertools}))) {
1.6 raeburn 3371: if (defined($excluded)) {
3372: if (ref($excluded) eq 'ARRAY') {
3373: if (grep/^$user$/,@{$excluded}) {
3374: next;
3375: }
3376: }
3377: }
1.5 raeburn 3378: my ($uname,$udom) = split(/:/,$user);
1.3 raeburn 3379: if ($rowNum %2 == 1) {
3380: $rowColor = $rowColor1;
3381: } else {
3382: $rowColor = $rowColor2;
3383: }
3384: $r->print('<tr bgcolor="'.$rowColor.'">
1.5 raeburn 3385: <td>'.$$userdata{$user}[$$idx{fullname}].'</td>
1.3 raeburn 3386: <td>'.$uname.'</td>
3387: <td>'.$udom.'</td>
3388: <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 3389: foreach my $tool (@{$showtools}) {
3390: if (exists($$usertools{$user}{$tool})) {
1.3 raeburn 3391: $r->print('<td valign="top"><table><tr bgcolor="'.$tabcol.'"><td colspan="2" align="center"><b>'.$tool.'</b></td></tr>');
3392: my $privcount = 0;
3393: my $fixed = '';
3394: my $dynamic = '';
3395: foreach my $priv (sort(keys(%{$$toolprivs{$tool}}))) {
3396: if (exists($$fixedprivs{$tool}{$priv})) {
1.5 raeburn 3397: $fixed .= '<input type="hidden" name="userpriv_'.$priv.'" value="'.$user.'" />'.$$toolprivs{$tool}{$priv}.' ';
1.3 raeburn 3398: } else {
3399: $privcount ++;
3400: if ($privcount == 3) {
3401: $dynamic .= '</tr><tr>';
3402: }
1.7 raeburn 3403: $dynamic .='<td><nobr><label><input type="checkbox" '.
1.5 raeburn 3404: 'name="userpriv_'.$priv.'" value="'.$user.'"';
3405: if (grep/^\Q$priv\E$/,@{$defprivs}) {
3406: $dynamic .= ' checked="checked" ';
3407: }
3408: $dynamic .= ' />'.$$toolprivs{$tool}{$priv}.
1.7 raeburn 3409: '</label></nobr></td>';
1.3 raeburn 3410: }
3411: }
3412: $r->print('<tr><td colspan="2"><nobr>'.$fixed.'</nobr></td></tr><tr>'.$dynamic.'</tr></table></td>');
3413: } else {
1.5 raeburn 3414: $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 3415: }
3416: }
3417: $rowNum ++;
3418: }
3419: }
3420:
3421: sub get_dates_from_form {
3422: my $startdate;
3423: my $enddate;
3424: $startdate = &Apache::lonhtmlcommon::get_date_from_form('startdate');
3425: $enddate = &Apache::lonhtmlcommon::get_date_from_form('enddate');
3426: if ( exists ($env{'form.no_end_date'}) ) {
3427: $enddate = 0;
3428: }
3429: return ($startdate,$enddate);
1.5 raeburn 3430: }
3431:
1.3 raeburn 3432: sub date_setting_table {
3433: my ($starttime,$endtime,$formname) = @_;
3434: my $startform = &Apache::lonhtmlcommon::date_setter($formname,
3435: 'startdate',$starttime);
3436: my $endform = &Apache::lonhtmlcommon::date_setter($formname,
3437: 'enddate',$endtime);
1.7 raeburn 3438: my $perpetual = '<nobr><label><input type="checkbox" name="no_end_date" />
3439: no ending date</label></nobr>';
1.3 raeburn 3440: my $start_table = '';
3441: $start_table .= "<table>\n";
3442: $start_table .= '<tr><td align="right">Default starting date for
3443: member access</td>'.
3444: '<td>'.$startform.'</td>'.
3445: '<td> </td>'."</tr>\n";
3446: $start_table .= "</table>";
3447: my $end_table = '';
3448: $end_table .= "<table>\n";
3449: $end_table .= '<tr><td align="right">Default ending date for
3450: member access</td>'.
3451: '<td>'.$endform.'</td>'.
3452: '<td>'.$perpetual.'</td>'."</tr>\n";
3453: $end_table .= "</table>\n";
3454: return ($start_table, $end_table);
1.1 raeburn 3455: }
3456:
1.3 raeburn 3457: sub create_homepage {
3458: my ($cdom,$cnum,$name,$groupinfo,$tools) = @_;
3459: my $functionality = join(',',@{$tools});
1.24 www 3460: my $content = &unescape($$groupinfo{description});
1.3 raeburn 3461: $content=~s/\s+$//s;
3462: $content=~s/^\s+//s;
3463: $content=~s/\<br\s*\/*\>$//s;
3464: $content=&Apache::lonfeedback::clear_out_html($content,1);
3465:
3466: my %pageinfo = (
3467: 'aaa_title' => 'Group: '.$name,
3468: 'abb_links' => $functionality,
3469: 'bbb_content' => $content,
3470: 'ccc_webreferences' => '',
3471: 'uploaded.lastmodified' => time,
3472: );
3473: my $putresult = &Apache::lonnet::put('grppage_'.$name,\%pageinfo,$cdom,$cnum);
3474: return $putresult;
1.1 raeburn 3475: }
3476:
1.5 raeburn 3477: sub check_uncheck_tools {
3478: my ($r,$available) = @_;
3479: if (ref($available) eq 'ARRAY') {
3480: $r->print('
3481: <script type="text/javascript">
3482: function checkAllTools(formname) {
3483: ');
3484: foreach my $tool (@{$available}) {
3485: $r->print(' checkAll(formname.user_'.$tool.');'."\n");
3486: }
3487: $r->print(' checkAll(formname.togglefunc);'."\n");
3488: $r->print('
3489: }
3490: function uncheckAllTools(formname) {
3491: ');
3492: foreach my $tool (@{$available}) {
3493: $r->print(' uncheckAll(formname.user_'.$tool.');'."\n");
3494: }
3495: $r->print(' uncheckAll(formname.togglefunc);'."\n");
3496: $r->print('
3497: }
3498: function toggleTools(field,caller) {
3499: if (caller.checked) {
3500: checkAll(field);
3501: } else {
3502: uncheckAll(field);
3503: }
3504: return;
3505: }
3506: </script>
3507: ');
3508: }
3509: return;
3510: }
3511:
3512: sub validate_groupname {
3513: my ($groupname,$action,$cdom,$cnum) = @_;
1.16 albertel 3514: my %sectioncount = &Apache::loncommon::get_sections($cdom,$cnum);
1.17 raeburn 3515: my %curr_groups = &Apache::longroup::coursegroups($cdom,$cnum);
1.15 albertel 3516:
1.5 raeburn 3517: my %lt = &Apache::lonlocal::texthash (
3518: igna => 'Invalid group name',
3519: tgne => 'The group name entered ',
3520: grna => 'Group names and section names used in a course '.
3521: 'must be unique.',
3522: isno => 'is not a valid name.',
3523: gnmo => 'Group names may only contain letters, numbers '.
3524: 'or underscores.',
3525: cnnb => 'can not be used as it is the name of ',
3526: inth => ' in this course.',
3527: thgr => '- does not correspond to the name of an existing'.
3528: ' group ',
3529: );
1.15 albertel 3530:
1.5 raeburn 3531: my $exitmsg = '<b>'.$lt{'igna'}.'</b><br /><br />'.$lt{'tgne'}.' "'.
3532: $groupname.'" ';
3533: my $dupmsg = $lt{'grna'};
3534: my $earlyout;
3535: if (($groupname eq '') || ($groupname =~ /\W/)) {
3536: $earlyout = $exitmsg.$lt{'isno'}.'<br />'.$lt{'gnmo'};
3537: return $earlyout;
3538: }
1.16 albertel 3539: if (exists($sectioncount{$groupname})) {
3540: return $exitmsg.$lt{'cnnb'}.&mt('a section').$lt{'inth'}.
3541: '<br />'.$lt{'grna'};
1.5 raeburn 3542: }
1.15 albertel 3543: if ($action eq 'create'
3544: && exists($curr_groups{$groupname})) {
3545:
3546: return $exitmsg.$lt{'cnnb'}.&mt('an existing group').
3547: $lt{'inth'}.'<br />'.$lt{'grna'};
3548:
1.5 raeburn 3549: } elsif ($action eq 'modify') {
3550: unless(exists($curr_groups{$groupname})) {
3551: $earlyout = &mt('Group name:').' '.$groupname.$lt{'thgr'}.$lt{'inth'};
3552: return $earlyout;
3553: }
3554: }
3555: return;
3556: }
3557:
3558: sub topic_bar {
3559: my ($r,$tabcol,$imgnum,$title) = @_;
3560: $r->print('
3561: <tr bgcolor="'.$tabcol.'">
3562: <td> </td>
3563: <td valign="middle" align="left">
3564: <nobr>
3565: <img src="/res/adm/pages/bl_step'.$imgnum.'.gif" valign="middle">
3566: </nobr>
3567: </td>
3568: <th align="left"><nobr>'.$title.'<nobr>
3569: </th>
3570: <td width="100%"> </td>
3571: </tr>
3572: <tr>
3573: <td colspan="4"> </td>
3574: </tr>
3575: ');
3576: return;
3577: }
3578:
3579: sub check_changes {
3580: my ($member_changes,$memchg) = @_;
3581: my %exclusions;
3582: @{$exclusions{'changefunc'}} = ('expire');
3583: @{$exclusions{'changepriv'}} = ('expire','changefunc');
3584:
3585: foreach my $change (@{$member_changes}) {
1.6 raeburn 3586: if ($change eq 'deletion') {
1.5 raeburn 3587: next;
3588: }
1.6 raeburn 3589: my @checks = ('deletion');
1.5 raeburn 3590: if (exists($exclusions{$change})) {
3591: push(@checks,@{$exclusions{$change}});
3592: }
3593: my @temp = ();
3594: foreach my $item (@{$$memchg{$change}}) {
3595: my $match = 0;
3596: foreach my $check (@checks) {
1.6 raeburn 3597: if (defined($$memchg{$check})) {
3598: if (ref(@{$$memchg{$check}}) eq 'ARRAY') {
3599: if (@{$$memchg{$check}} > 0) {
3600: if (grep/^$item$/,@{$$memchg{$check}}) {
3601: $match = 1;
3602: last;
3603: }
3604: }
1.5 raeburn 3605: }
3606: }
3607: }
3608: if ($match) {
3609: next;
3610: }
3611: push(@temp,$item);
3612: }
3613: @{$$memchg{$change}} = @temp;
3614: }
3615: }
1.3 raeburn 3616:
1.1 raeburn 3617: 1;
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>