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