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