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