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