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