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