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