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