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