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