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