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