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