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