Annotation of loncom/interface/loncoursegroups.pm, revision 1.59
1.24 www 1: # The LearningOnline Network with CAPA
2: #
1.59 ! raeburn 3: # $Id: loncoursegroups.pm,v 1.58 2006/07/28 18:44:27 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}}) {
1.58 raeburn 968:
1.17 raeburn 969: push (@{$stored{'sec_'.$role}},$section);
970: }
971: if (@{$groupinfo{'autosec'}{$role}} > 0) {
972: push(@{$stored{'autorole'}},$role);
973: }
974: }
1.15 albertel 975: }
1.5 raeburn 976: }
977: return %stored;
978: }
979:
1.3 raeburn 980: sub display_control {
1.48 albertel 981: my ($r,$cdom,$cnum,$action,$state,$page,$sectioncount,$groupname,
1.3 raeburn 982: $description,$functions,$tools,$toolprivs,$fixedprivs,$startdate,
1.45 albertel 983: $enddate,$users,$userdata,$idx,$memchg,$usertools,
1.29 raeburn 984: $view_permission,$manage_permission,$stored,$granularity,$quota,
1.48 albertel 985: $specificity,$types,$roles,$sections,$states,$navbuttons,
986: $gpterm,$ucgpterm,$crstype) = @_;
1.3 raeburn 987: if ($action eq 'create') {
988: if ($state eq 'pick_name') {
1.46 albertel 989: &general_settings_form($r,$cdom,$cnum,$action,$state,$page,
1.5 raeburn 990: $functions,$tools,$toolprivs,$fixedprivs,
991: $sectioncount,$stored,$states,$navbuttons,
1.46 albertel 992: $gpterm,$ucgpterm,$crstype);
1.3 raeburn 993: } elsif ($state eq 'pick_members') {
1.46 albertel 994: &choose_members_form($r,$cdom,$cnum,$action,$state,$page,
1.29 raeburn 995: $groupname,$description,$granularity,$quota,
1.5 raeburn 996: $startdate,$enddate,$tools,$fixedprivs,
997: $toolprivs,$functions,$users,$userdata,$idx,
1.46 albertel 998: $stored,$states,$navbuttons,$gpterm,$ucgpterm,
999: $crstype);
1.3 raeburn 1000: } elsif ($state eq 'pick_privs') {
1.45 albertel 1001: &choose_privs_form($r,$cdom,$cnum,$action,$state,$page,
1.5 raeburn 1002: $startdate,$enddate,$tools,$functions,
1003: $toolprivs,$fixedprivs,$userdata,$usertools,
1004: $idx,$states,$stored,$sectioncount,$navbuttons,
1.45 albertel 1005: $gpterm,$ucgpterm,$crstype);
1.3 raeburn 1006: } elsif ($state eq 'result') {
1.45 albertel 1007: &process_request($r,$cdom,$cnum,$action,$state,$page,
1.5 raeburn 1008: $groupname,$description,$specificity,$userdata,
1009: $startdate,$enddate,$tools,$functions,
1010: $toolprivs,$usertools,$idx,$types,$roles,
1011: $sections,$states,$navbuttons,$memchg,
1.45 albertel 1012: $sectioncount,$stored,$gpterm,$ucgpterm,$crstype);
1.5 raeburn 1013: }
1014: } elsif ($action eq 'modify') {
1015: my $groupname = $env{'form.groupname'};
1.53 raeburn 1016: if ($state eq 'pick_task') {
1.29 raeburn 1017: &modify_menu($r,$groupname,$page,$gpterm);
1.5 raeburn 1018: } elsif ($state eq 'change_settings') {
1.46 albertel 1019: &general_settings_form($r,$cdom,$cnum,$action,$state,$page,
1.5 raeburn 1020: $functions,$tools,$toolprivs,$fixedprivs,
1021: $sectioncount,$stored,$states,$navbuttons,
1.46 albertel 1022: $gpterm,$ucgpterm,$crstype);
1.5 raeburn 1023: } elsif ($state eq 'change_members') {
1.48 albertel 1024: &change_members_form($r,$cdom,$cnum,$action,$state,$page,
1.5 raeburn 1025: $groupname,$description,$startdate,$enddate,
1026: $tools,$fixedprivs,$functions,$users,
1.29 raeburn 1027: $userdata,$granularity,$quota,$specificity,
1.48 albertel 1028: $idx,$states,$navbuttons,$gpterm,$ucgpterm);
1.5 raeburn 1029: } elsif ($state eq 'add_members') {
1.59 ! raeburn 1030: &add_members_form($r,$cdom,$cnum,$action,$state,$page,$startdate,
1.5 raeburn 1031: $enddate,$groupname,$description,$granularity,
1.29 raeburn 1032: $quota,$sectioncount,$tools,$functions,$stored,
1.46 albertel 1033: $states,$navbuttons,$gpterm,$ucgpterm);
1.5 raeburn 1034: } elsif ($state eq 'pick_members') {
1.46 albertel 1035: &choose_members_form($r,$cdom,$cnum,$action,$state,$page,
1.29 raeburn 1036: $groupname,$description,$granularity,$quota,
1.5 raeburn 1037: $startdate,$enddate,$tools,$fixedprivs,
1038: $toolprivs,$functions,$users,$userdata,$idx,
1.46 albertel 1039: $stored,$states,$navbuttons,$gpterm,$ucgpterm,
1040: $crstype);
1.5 raeburn 1041: } elsif ($state eq 'pick_privs') {
1.46 albertel 1042: &choose_privs_form($r,$cdom,$cnum,$action,$state,$page,
1.5 raeburn 1043: $startdate,$enddate,$tools,$functions,
1044: $toolprivs,$fixedprivs,$userdata,$usertools,
1045: $idx,$states,$stored,$sectioncount,$navbuttons,
1.46 albertel 1046: $gpterm,$ucgpterm,$crstype);
1.5 raeburn 1047: } elsif ($state eq 'change_privs') {
1.45 albertel 1048: &change_privs_form($r,$cdom,$cnum,$action,$state,$page,
1.5 raeburn 1049: $startdate,$enddate,$tools,$functions,
1050: $toolprivs,$fixedprivs,$userdata,$usertools,
1051: $memchg,$idx,$states,$stored,$sectioncount,
1.45 albertel 1052: $navbuttons,$gpterm,$ucgpterm);
1.5 raeburn 1053: } elsif ($state eq 'chgresult' || $state eq 'memresult' ||
1054: $state eq 'addresult') {
1.45 albertel 1055: &process_request($r,$cdom,$cnum,$action,$state,$page,
1.5 raeburn 1056: $groupname,$description,$specificity,$userdata,
1057: $startdate,$enddate,$tools,$functions,
1058: $toolprivs,$usertools,$idx,$types,$roles,
1059: $sections,$states,$navbuttons,$memchg,
1.45 albertel 1060: $sectioncount,$stored,$gpterm,$ucgpterm,$crstype);
1.1 raeburn 1061: }
1062: }
1063: }
1064:
1065: sub header {
1.39 albertel 1066: my ($bodytitle,$jscript,$action,$state,$page,$loaditems) = @_;
1.9 albertel 1067: my $start_page=
1.11 albertel 1068: &Apache::loncommon::start_page($bodytitle,
1069: '<script type="text/javascript">'.
1070: $jscript.'</script>',
1.39 albertel 1071: {'add_entries' => $loaditems,});
1.3 raeburn 1072: my $output = <<"END";
1.11 albertel 1073: $start_page
1.9 albertel 1074: <form method="POST" name="$state">
1.3 raeburn 1075:
1076: END
1077: if ($action eq 'create' || $action eq 'modify') {
1078: $output .= <<"END";
1079: <input type="hidden" name="action" value="$action" />
1080: <input type="hidden" name="state" value="" />
1081: <input type="hidden" name="origin" value="$state" />
1.5 raeburn 1082: <input type="hidden" name="page" value="$page" />
1.3 raeburn 1083: END
1084: }
1085: return $output;
1.1 raeburn 1086: }
1087:
1.3 raeburn 1088: sub onload_action {
1089: my ($action,$state) = @_;
1.13 albertel 1090: my %loaditems;
1.3 raeburn 1091: if ((defined($env{'form.origin'})) && ($action eq 'create') &&
1092: ($state eq 'pick_name' || $state eq 'pick_members' ||
1093: $state eq 'pick_privs')) {
1094: unless ($env{'form.origin'} eq '') {
1.13 albertel 1095: $loaditems{'onload'} =
1096: 'javascript:setFormElements(document.'.$state.')';
1.1 raeburn 1097: }
1098: }
1.5 raeburn 1099: if (($action eq 'modify') &&
1100: ($state eq 'change_settings' || $state eq 'change_members' ||
1.53 raeburn 1101: $state eq 'change_privs' || $state eq 'add_members')) {
1.13 albertel 1102: $loaditems{'onload'} =
1103: 'javascript:setFormElements(document.'.$state.')';
1.5 raeburn 1104: }
1.13 albertel 1105: return \%loaditems;
1.1 raeburn 1106: }
1107:
1108: sub footer {
1.9 albertel 1109: my $end_page = &Apache::loncommon::end_page();
1.1 raeburn 1110: return(<<ENDFOOT);
1.6 raeburn 1111: <input type="hidden" name="sortby" value="$env{'form.sortby'}" />
1.1 raeburn 1112: </form>
1.9 albertel 1113: $end_page
1.1 raeburn 1114: ENDFOOT
1115: }
1116:
1.3 raeburn 1117: sub build_members_list {
1118: my ($cdom,$cnum,$types,$roles,$sections,$users,$userdata) = @_;
1119: my %access = ();
1120: foreach my $role (@{$roles}) {
1121: %{$$users{$role}} = ();
1122: }
1123: foreach my $type (@{$types}) {
1124: $access{$type} = $type;
1125: }
1126: &Apache::loncommon::get_course_users($cdom,$cnum,\%access,$roles,
1.5 raeburn 1127: $sections,$users,$userdata);
1.3 raeburn 1128: return;
1129: }
1130:
1131: sub group_files {
1.29 raeburn 1132: my ($group,$currdir,$numfiles,$numdirs) = @_;
1133: my $dirptr=16384;
1134: my @dir_list=&Apache::portfolio::get_dir_list($currdir,$group);
1135: foreach my $line (@dir_list) {
1136: my ($filename,$dom,undef,$testdir,undef,undef,undef,undef,$size,undef,$mtime,undef,undef,undef,$obs,undef)=split(/\&/,$line,16);
1137: if (($filename !~ /^\.\.?$/) && ($filename !~ /\.meta$/ ) && ($filename !~ /(.*)\.(\d+)\.([^\.]*)$/) && ($filename ne 'no_such_dir')) {
1138: if ($dirptr&$testdir) {
1139: $currdir .= '/'.$filename;
1140: $$numdirs ++;
1141: &group_files($numfiles,$numdirs)
1142: } else {
1143: $$numfiles ++;
1144: }
1145: }
1146: }
1.3 raeburn 1147: return;
1148: }
1149:
1150: sub group_members {
1.4 raeburn 1151: my ($cdom,$cnum,$group,$group_info) = @_;
1152: my %memberhash = &Apache::lonnet::get_group_membership($cdom,$cnum,$group);
1153: my $now = time;
1154: my ($tmp)=keys(%memberhash);
1155: if ($tmp=~/^error:/) {
1156: $$group_info{'totalmembers'} = 'Unknown - an error occurred';
1157: return $tmp;
1158: }
1159: my $totalmembers = 0;
1160: my $active = 0;
1161: my $previous = 0;
1162: my $future = 0;
1163: foreach my $member (keys %memberhash) {
1164: $totalmembers ++;
1165: my ($end,$start) = split(/:/,$memberhash{$member});
1.6 raeburn 1166: unless ($start == -1) {
1167: if (($end!=0) && ($end<$now)) {
1168: $previous ++;
1169: } elsif (($start!=0) && ($start>$now)) {
1170: $future ++;
1171: } else {
1172: $active ++;
1173: }
1.4 raeburn 1174: }
1175: }
1176: if ($totalmembers == 0) {
1177: $$group_info{$group}{'totalmembers'} = 'None';
1178: } else {
1.47 raeburn 1179: $$group_info{$group}{'totalmembers'} = '<nobr>'.$active.
1180: ' - active</nobr><br /><nobr>'.$previous.
1181: ' - previous</nobr><br /><nobr>'.$future.
1182: ' - future</nobr>';
1.4 raeburn 1183: }
1184: return 'ok';
1.3 raeburn 1185: }
1186:
1187:
1.5 raeburn 1188: sub general_settings_form {
1.46 albertel 1189: my ($r,$cdom,$cnum,$action,$formname,$page,$functions,$tools,
1.5 raeburn 1190: $toolprivs,$fixedprivs,$sectioncount,$stored,$states,$navbuttons,
1.46 albertel 1191: $gpterm,$ucgpterm,$crstype) = @_;
1.5 raeburn 1192: my ($nexttext,$prevtext);
1.42 albertel 1193: &groupsettings_options($r,$functions,$action,$formname,$stored,1,
1.29 raeburn 1194: $gpterm,$ucgpterm,$crstype);
1.41 albertel 1195: &access_date_settings($r,$action,$formname,$stored,2,$gpterm,$ucgpterm);
1.5 raeburn 1196: if ($action eq 'create') {
1.59 ! raeburn 1197: &membership_options($r,$cdom,$cnum,$action,$formname,$sectioncount,3,
! 1198: $gpterm,$ucgpterm);
1.5 raeburn 1199: $nexttext = $$navbuttons{'gtns'};
1200: } else {
1201: my @available = ();
1202: my @unavailable = ();
1203: &check_tools($functions,$tools,\@available,\@unavailable);
1204: @{$tools} = sort(keys(%{$functions}));
1.46 albertel 1205: &privilege_specificity($r,$action,3,$tools,$stored,$toolprivs,
1206: $fixedprivs,\@available,$formname,
1207: $gpterm,$ucgpterm);
1.44 albertel 1208: &mapping_options($r,$action,$formname,$page,$sectioncount,
1209: $states,$stored,$navbuttons,4,5,
1.58 raeburn 1210: $gpterm,$ucgpterm,$crstype,$cdom,$cnum);
1.5 raeburn 1211: $nexttext = $$navbuttons{'mose'};
1212: }
1213: $prevtext = $$navbuttons{'gtpp'};
1214: &display_navbuttons($r,$formname,$$states{$action}[$page-1],$prevtext,
1215: $$states{$action}[$page+1],$nexttext);
1216: return;
1217: }
1218:
1219: sub groupsettings_options {
1.42 albertel 1220: my ($r,$functions,$action,$formname,$stored,$image,$gpterm,
1.29 raeburn 1221: $ucgpterm,$crstype) = @_;
1.1 raeburn 1222: my %lt = &Apache::lonlocal::texthash(
1.53 raeburn 1223: 'gdat' => "Group access start and end dates",
1224: 'gnde' => "Group name, title and available collaborative tools",
1225: 'desc' => 'Group Title',
1226: 'func' => 'Collaborative Tools',
1227: 'gnam' => 'Group Name',
1228: 'lett' => 'Letters, numbers and underscore only',
1229: 'doyo' => 'Different subsets of the chosen collaborative tools '.
1230: 'for different group members?',
1.1 raeburn 1231: );
1.37 raeburn 1232: my ($crsquota,$freespace,$maxposs) = &get_quota_constraints($action,$stored);
1.40 albertel 1233: &topic_bar($r,$image,$lt{'gnde'});
1.5 raeburn 1234: $r->print('
1.42 albertel 1235: <table class="LC_descriptive_input">
1.3 raeburn 1236: <tr>
1.42 albertel 1237: <td class="LC_description">'.$lt{'gnam'}.':</td>
1.5 raeburn 1238: <td colspan="5">
1239: ');
1240: if ($action eq 'create') {
1.53 raeburn 1241: $r->print('<input type="text" name="groupname" size="25" /> ('.
1242: $lt{'lett'}.')');
1.5 raeburn 1243: } else {
1244: $r->print('<input type="hidden" name="groupname" value="'.
1245: $env{'form.groupname'}.'" />'.$env{'form.groupname'});
1246: }
1247: $r->print(<<"END");
1.3 raeburn 1248: </td>
1249: <tr>
1250: <tr>
1.42 albertel 1251: <td class="LC_description">$lt{'desc'}:</td>
1.5 raeburn 1252: <td colspan="5"><input type="text" name="description" size="40"
1253: value="" />
1.3 raeburn 1254: </td>
1255: <tr>
1256: <tr>
1.42 albertel 1257: <td class="LC_description">$lt{'func'}:</td>
1.3 raeburn 1258: END
1259: my $numitems = keys(%{$functions});
1260: my $halfnum = int($numitems/2);
1261: my $remnum = $numitems%2;
1262: if ($remnum) {
1263: $halfnum ++;
1264: }
1.5 raeburn 1265: my @allfunctions = sort(keys (%{$functions}));
1.3 raeburn 1266: for (my $i=0; $i<$halfnum; $i++) {
1.7 raeburn 1267: $r->print('<td><label><input type="checkbox" name="tool" value="'.
1.3 raeburn 1268: $allfunctions[$i].'" /> '.
1.7 raeburn 1269: $$functions{$allfunctions[$i]}.'</label></td>
1.3 raeburn 1270: <td> </td><td> </td>');
1271: }
1272: $r->print('<td><input type="button" value="check all" '.
1273: 'onclick="javascript:checkAll(document.'.$formname.'.tool)" />'.
1274: '</td></tr><tr><td> </td>');
1275: for (my $j=$halfnum; $j<@allfunctions; $j++) {
1.7 raeburn 1276: $r->print('<td><label><input type="checkbox" name="tool" value="'.
1.3 raeburn 1277: $allfunctions[$j].'" /> '.
1.7 raeburn 1278: $$functions{$allfunctions[$j]}.'</label></td>
1.3 raeburn 1279: <td> </td><td> </td>');
1280: }
1281: if ($remnum) {
1282: $r->print('<td> </td>');
1283: }
1.5 raeburn 1284: $r->print('
1.3 raeburn 1285: <td>
1.5 raeburn 1286: <input type="button" value="uncheck all"
1287: onclick="javascript:uncheckAll(document.'.$formname.'.tool)" />
1.3 raeburn 1288: </td>
1289: </tr>
1290: <tr>
1.42 albertel 1291: <td class="LC_description">'.&mt('Granularity:').'</td>
1.29 raeburn 1292: <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 1293: if ($action eq 'modify') {
1294: $r->print(' ('.&mt('Currently set to "[_1]"',
1295: $$stored{'granularity'}).')');
1296: }
1297: $r->print('
1298: </td>
1299: </tr>
1.29 raeburn 1300: <tr>
1.42 albertel 1301: <td class="LC_description">'.&mt('Disk quota: ').'</td><td colspan="10">');
1.29 raeburn 1302: if ($action eq 'create') {
1303: $r->print(&mt('If you enable the file repository for the [_1], allocate a disk quota.',$gpterm));
1304: } else {
1305: $r->print(&mt('Quota allocated to file repository:'));
1306: }
1307: $r->print(' <input type="text" name="quota" size="4" />Mb');
1308: if ($action eq 'create') {
1309: $r->print('<br />'.
1.51 raeburn 1310: &mt('A total of [_1] Mb can be divided amongst all [_2]s in the '.
1.29 raeburn 1311: '[_3], and [_4] Mb are currently unallocated.',$crsquota,
1.53 raeburn 1312: $gpterm,lc($crstype),sprintf("%.2f",$freespace)));
1.29 raeburn 1313: } else {
1314: $r->print(' ('.&mt('The quota is currently [_1] Mb',
1315: $$stored{'quota'}).').');
1316:
1317: $r->print('<br />'.&mt('The quota can be increased to [_1] Mb, '.
1318: 'by adding all unallocated space for [_2]s in the [_3].',
1.53 raeburn 1319: sprintf("%.2f",$maxposs),$gpterm,lc($crstype)));
1.29 raeburn 1320: }
1321: $r->print('
1322: </td>
1323: </tr>
1.3 raeburn 1324: </table>
1.5 raeburn 1325: ');
1326: return;
1327: }
1328:
1.37 raeburn 1329: sub get_quota_constraints {
1330: my ($action,$stored) = @_;
1331: my ($crsquota,$freespace,$maxposs);
1332: $crsquota = $env{'course.'.$env{'request.course.id'}.'.internal.coursequota'};
1333: if ($crsquota eq '') {
1334: $crsquota = 20;
1335: }
1336: $freespace = $crsquota - &Apache::longroup::sum_quotas();
1337: if ($action eq 'create') {
1338: $maxposs = $freespace;
1339: } else {
1340: $maxposs = $$stored{'quota'} + $freespace;
1341: }
1342: return ($crsquota,$freespace,$maxposs);
1343: }
1344:
1.5 raeburn 1345: sub membership_options {
1.59 ! raeburn 1346: my ($r,$cdom,$cnum,$action,$state,$sectioncount,$image,$gpterm,$ucgpterm)=@_;
1.29 raeburn 1347: my $crstype = &Apache::loncommon::course_type();
1.5 raeburn 1348: my %lt = &Apache::lonlocal::texthash(
1.53 raeburn 1349: 'pipa' => 'Build a list of users for selection of group members',
1350: 'gmem' => "Group membership selection list criteria:",
1.5 raeburn 1351: 'picr' => 'Pick the criteria to use to build a list of '.
1.29 raeburn 1352: lc($crstype).' users from which you will select ',
1.53 raeburn 1353: 'meof' => "members of the new group.",
1354: 'admg' => "additional members of the group.",
1.29 raeburn 1355: 'ifno' => "If you do not wish to add members when you first ".
1.53 raeburn 1356: "create the group, there is no need to pick any criteria.",
1357: '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 1358: 'acty' => 'Access types',
1.29 raeburn 1359: 'coro' => $crstype.' roles',
1360: 'cose' => $crstype.' sections',
1.5 raeburn 1361: );
1362: my %status_types = (
1363: active => &mt('Currently has access'),
1364: previous => &mt('Previously had access'),
1365: future => &mt('Will have future access'),
1366: );
1.15 albertel 1367:
1.59 ! raeburn 1368: my @roles = ('st','cc','in','ta','ep','cr');
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.59 ! raeburn 1391: $r->print(&Apache::lonhtmlcommon::role_select_row(\@roles,undef,undef,1,$cdom,$cnum));
1.3 raeburn 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)) ||
1.55 raeburn 1828: (($action eq 'modify') && ($formname eq 'change_settings'))) {
1.5 raeburn 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'});
1.55 raeburn 1885: $r->print('<input type="hidden" name="specificity" value="No" />');
1.5 raeburn 1886: } elsif ($action eq 'modify' && $formname eq 'pick_members') {
1887: my @defprivs;
1888: if (ref($$stored{'defpriv'}) eq 'ARRAY') {
1889: @defprivs = @{$$stored{'defpriv'}};
1890: }
1891: $r->print($lt{'eaty'}.' '.$lt{cutg});
1892: if ($$stored{'specificity'} eq 'Yes') {
1893: $r->print($lt{'sdif'});
1894: } else {
1895: $r->print($lt{'sall'});
1896: }
1897: $r->print(' '.$lt{'defp'}.'<br /><br />');
1.45 albertel 1898: &display_defprivs($r,$tools,$toolprivs,\@defprivs);
1.5 raeburn 1899: }
1.3 raeburn 1900: }
1901: return;
1902: }
1903:
1.5 raeburn 1904: sub default_privileges {
1.42 albertel 1905: my ($r,$action,$tools,$toolprivs,$fixedprivs,$available) = @_;
1.5 raeburn 1906: my %lt = &Apache::lonlocal::texthash(
1907: 'addp' => 'Additional privileges',
1908: 'fixp' => 'Fixed privileges',
1909: 'oppr' => 'Optional privileges',
1.53 raeburn 1910: 'func' => 'Collaborative Tool',
1.5 raeburn 1911: );
1.42 albertel 1912: $r->print(&Apache::lonhtmlcommon::start_pick_box('LC_group_priv_box').
1913: &Apache::lonhtmlcommon::row_title($lt{'func'},undef,
1914: 'LC_groups_functionality'));
1915: $r->print(join('</td><td class="LC_groups_functionality">',@{$tools}));
1916: $r->print(&Apache::lonhtmlcommon::row_closure(1));
1917: my $fixed = '';
1918: my $dynamic = '';
1.3 raeburn 1919: foreach my $tool (@{$tools}) {
1.5 raeburn 1920: my $privcount = 0;
1.42 albertel 1921: if ($dynamic ne '') {
1922: $dynamic .= '</td><td class="LC_groups_optional">';
1923: }
1924: $dynamic .= '<table class="LC_group_priv"><tr>';
1.5 raeburn 1925: foreach my $priv (sort(keys(%{$$toolprivs{$tool}}))) {
1926: if (exists($$fixedprivs{$tool}{$priv})) {
1.42 albertel 1927: if ($fixed ne '') {
1928: $fixed .= '</td><td class="LC_groups_fixed">';
1929: }
1.53 raeburn 1930: $fixed .= '<input type="hidden" name="defpriv" value="'.$priv.'" /><nobr>'.$$toolprivs{$tool}{$priv}.' ';
1.5 raeburn 1931: if ($action eq 'modify') {
1.42 albertel 1932: if (grep(/^$tool$/,@{$available})) {
1.5 raeburn 1933: $fixed .= '<small>'.&mt('(on)').'<small> ';
1934: } else {
1935: $fixed .= '<small>'.&mt('(off)').'<small> ';
1.3 raeburn 1936: }
1937: }
1.53 raeburn 1938: $fixed .= '</nobr>';
1.5 raeburn 1939: } else {
1.42 albertel 1940: $privcount++;
1.5 raeburn 1941: if ($privcount == 3) {
1942: $dynamic .= '</tr>
1.42 albertel 1943: <tr>'."\n";
1.5 raeburn 1944: }
1.53 raeburn 1945: $dynamic .= '<td><nobr><label><input type="checkbox" name="defpriv" value="'.$priv.'" />'.$$toolprivs{$tool}{$priv}.'</label></nobr></td>'."\n";
1.3 raeburn 1946: }
1947: }
1.42 albertel 1948: if ($privcount == 0) {
1949: $dynamic .= '<td>None</td>'."\n";
1.5 raeburn 1950: }
1951: if ($privcount < 3) {
1.53 raeburn 1952: $dynamic .= '<td> </td>'."\n";
1.5 raeburn 1953: } elsif ($privcount%2) {
1954: $dynamic = '<td> </td>'."\n";
1955: }
1.42 albertel 1956: $dynamic .= '</tr></table>';
1.3 raeburn 1957: }
1.42 albertel 1958: $r->print(&Apache::lonhtmlcommon::row_title($lt{'fixp'},undef,
1959: 'LC_groups_fixed').
1960: $fixed.
1961: &Apache::lonhtmlcommon::row_closure(1));
1962: $r->print(&Apache::lonhtmlcommon::row_title($lt{'oppr'},undef,
1963: 'LC_groups_optional').
1964: $dynamic.
1965: &Apache::lonhtmlcommon::end_pick_box());
1.5 raeburn 1966: $r->print('<br />');
1967: return;
1.42 albertel 1968:
1.5 raeburn 1969: }
1970:
1971: sub display_defprivs {
1.45 albertel 1972: my ($r,$tools,$toolprivs,$defprivs) = @_;
1973: my $function = &Apache::loncommon::get_users_function();
1974: my $tabcol = &Apache::loncommon::designparm($function.'.tabbg');
1975: my $rowColor1 = "#dddddd";
1976: my $rowColor2 = "#eeeeee";
1.5 raeburn 1977: my %lt = &Apache::lonlocal::texthash(
1978: 'priv' => 'Privileges',
1.53 raeburn 1979: 'func' => 'Collaborative Tool',
1.5 raeburn 1980: );
1981: $r->print(&Apache::lonhtmlcommon::start_pick_box());
1982: $r->print('<tr>');
1983: my $numrows = 0;
1984: my %currprivs;
1985: foreach my $tool (@{$tools}) {
1986: @{$currprivs{$tool}} = ();
1987: foreach my $priv (sort(keys(%{$$toolprivs{$tool}}))) {
1988: if (ref($defprivs) eq 'ARRAY') {
1.45 albertel 1989: if (grep(/^\Q$priv\E$/,@{$defprivs})) {
1.5 raeburn 1990: push(@{$currprivs{$tool}},$priv);
1991: }
1.3 raeburn 1992: }
1993: }
1.5 raeburn 1994: my $rowcount = int(@{$currprivs{$tool}}/3);
1995: if (@{$currprivs{$tool}}%3 > 0) {
1996: $rowcount ++;
1997: }
1998: if ($rowcount > $numrows) {
1999: $numrows = $rowcount;
2000: }
2001: }
2002: my @rowCols = ($rowColor1,$rowColor2);
2003: foreach my $tool (@{$tools}) {
2004: $r->print('<td align="center" valign="top">
2005: <table cellspacing="0" cellpadding="5">
2006: <tr bgcolor="#cccccc">
2007: <td colspan="3" align="center"><b>'.$tool.'</b></td>
2008: </tr>
2009: ');
2010: my $rownum = 1;
2011: my $privcount = 0;
2012: $r->print('<tr bgcolor="'.$rowColor1.'">');
2013: foreach my $priv (@{$currprivs{$tool}}) {
2014: $privcount ++;
2015: if ($privcount%4 == 0) {
2016: $rownum ++;
2017: my $bgcol = $rownum%2;
2018: $r->print('</tr>
2019: <tr bgcolor="'.$rowCols[$bgcol].'">'."\n");
2020: }
2021: $r->print('<td>'.$$toolprivs{$tool}{$priv}.'</td>'."\n");
2022: }
2023: if ($privcount%3 > 0) {
2024: my $emptycells = 3-($privcount%3);
2025: while($emptycells > 0) {
2026: $r->print('<td> </td>'."\n");
2027: $emptycells --;
2028: }
2029: }
2030: while ($rownum < $numrows) {
2031: $rownum ++;
2032: my $bgcol = $rownum%2;
2033: $r->print('<tr bgcolor="'.$rowCols[$bgcol].'"><td colspan="3"> </td></tr>');
1.3 raeburn 2034: }
1.5 raeburn 2035: $r->print('</table>'."\n".'</td>');
2036: }
2037: $r->print('</tr>'."\n");
2038: $r->print(&Apache::lonhtmlcommon::end_pick_box());
2039: $r->print('<br />');
2040: return;
1.3 raeburn 2041: }
1.5 raeburn 2042:
2043:
2044: sub change_members_form {
1.48 albertel 2045: my ($r,$cdom,$cnum,$action,$formname,$page,$groupname,$description,
1.5 raeburn 2046: $startdate,$enddate,$tools,$fixedprivs,$functions,$users,$userdata,
1.48 albertel 2047: $granularity,$quota,$specificity,$idx,$states,$navbuttons,$gpterm,
2048: $ucgpterm) = @_;
1.5 raeburn 2049: my %lt = &Apache::lonlocal::texthash(
1.29 raeburn 2050: grse => "$ucgpterm settings",
2051: mogm => "Modify $gpterm membership",
1.5 raeburn 2052: );
2053: my @regexps = ('user_','userpriv_');
2054: $r->print(&Apache::lonhtmlcommon::echo_form_input(
1.6 raeburn 2055: ['origin','action','state','page','expire','deletion',
1.7 raeburn 2056: 'reenable','activate','changepriv','sortby',
2057: 'togglefunc'],\@regexps));
1.5 raeburn 2058: my $rowimg = 1;
2059: my @available = ();
2060: my @unavailable = ();
2061: &check_tools($functions,$tools,\@available,\@unavailable);
2062: my $nexttext = $$navbuttons{'gtns'};
2063: my $prevtext = $$navbuttons{'gtpp'};
2064: $r->print('
1.3 raeburn 2065: <br />
1.5 raeburn 2066: ');
1.40 albertel 2067: &topic_bar($r,1,$lt{'grse'});
2068: &print_current_settings($r,$action,$functions,$startdate,$enddate,
2069: $groupname,$description,$granularity,$quota,
2070: \@available,\@unavailable,$gpterm,$ucgpterm);
2071: &topic_bar($r,2,$lt{'mogm'});
1.53 raeburn 2072: my $numcurrent = ¤t_membership($r,$cdom,$cnum,$formname,$groupname,
2073: \@available,\@unavailable,$fixedprivs,
2074: $granularity,$specificity);
2075: if ($numcurrent > 0) {
2076: &display_navbuttons($r,$formname,$$states{$action}[$page-1],$prevtext,
2077: $$states{$action}[$page+1],$nexttext);
2078: } else {
2079: &display_navbuttons($r,$formname,$$states{$action}[$page-1],$prevtext);
2080: }
1.5 raeburn 2081: return;
2082: }
2083:
2084: sub current_membership {
1.48 albertel 2085: my ($r,$cdom,$cnum,$formname,$groupname,$available,$unavailable,
2086: $fixedprivs,$granularity,$specificity) = @_;
1.5 raeburn 2087: my %membership = &Apache::lonnet::get_group_membership($cdom,$cnum,
2088: $groupname);
2089: my %lt = &Apache::lonlocal::texthash(
1.6 raeburn 2090: 'actn' => 'Action?',
2091: 'name' => 'Name',
2092: 'usnm' => 'Username',
2093: 'doma' => 'Domain',
2094: 'stda' => 'Start Date',
2095: 'enda' => 'End Date',
1.5 raeburn 2096: 'expi' => 'Expire',
2097: 'reen' => 'Re-enable',
2098: 'acti' => 'Activate',
2099: 'dele' => 'Delete',
1.53 raeburn 2100: 'curf' => 'Current Tool Set',
1.5 raeburn 2101: 'chpr' => 'Change Privileges'
2102: );
1.52 raeburn 2103: my ($current,$num_items,$hastools,$addtools) =
1.36 raeburn 2104: &Apache::longroup::group_memberlist($cdom,$cnum,$groupname,$fixedprivs,
2105: $available);
1.53 raeburn 2106: my $numcurrent = scalar(keys(%{$current}));
2107: if ($numcurrent > 0) {
1.36 raeburn 2108: $r->print('
1.5 raeburn 2109: <table>
2110: <tr>');
1.52 raeburn 2111: if ($num_items->{'active'}) {
1.36 raeburn 2112: &check_uncheck_buttons($r,$formname,'expire',$lt{'expi'});
2113: }
1.52 raeburn 2114: if ($num_items->{'previous'}) {
1.36 raeburn 2115: &check_uncheck_buttons($r,$formname,'reenable',$lt{'reen'});
2116: }
1.52 raeburn 2117: if ($num_items->{'future'}) {
1.36 raeburn 2118: &check_uncheck_buttons($r,$formname,'activate',$lt{'acti'});
2119: }
2120: &check_uncheck_buttons($r,$formname,'deletion',$lt{'dele'});
2121: if (@{$available} > 0) {
2122: if ($specificity eq 'Yes') {
2123: &check_uncheck_buttons($r,$formname,'changepriv',$lt{'chpr'});
1.5 raeburn 2124: }
1.36 raeburn 2125: if ($granularity eq 'Yes') {
2126: $r->print(&check_uncheck_tools($r,$available));
2127: $r->print('
1.5 raeburn 2128: <td>
2129: <nobr>
2130: <fieldset><legend><b>'.$lt{'curf'}.'</b></legend>
2131: <input type="button" value="check all"
2132: onclick="javascript:checkAllTools(document.'.$formname.')" />
2133:
2134: <input type="button" value="uncheck all"
2135: onclick="javascript:uncheckAllTools(document.'.$formname.')" />
2136: </fieldset>
2137: </nobr>
2138: </td>
2139: ');
1.3 raeburn 2140: }
1.36 raeburn 2141: }
2142: $r->print(<<"END");
1.5 raeburn 2143: </tr>
2144: </table>
1.48 albertel 2145: <br />
1.5 raeburn 2146: END
1.48 albertel 2147: $r->print(&Apache::loncommon::start_data_table().
2148: &Apache::loncommon::start_data_table_header_row());
1.36 raeburn 2149: $r->print(<<"END");
1.48 albertel 2150: <th>$lt{'actn'}</th>
2151: <th><a href="javascript:changeSort('fullname')">$lt{'name'}</a></th>
2152: <th><a href="javascript:changeSort('username')">$lt{'usnm'}</a></th>
2153: <th><a href="javascript:changeSort('domain')">$lt{'doma'}</a></th>
2154: <th><a href="javascript:changeSort('id')">ID</a></th>
2155: <th><a href="javascript:changeSort('start')">$lt{'stda'}</a></th>
2156: <th><a href="javascript:changeSort('end')">$lt{'enda'}</a></th>
1.5 raeburn 2157: END
1.36 raeburn 2158: my $colspan = 0;
2159: if ($hastools) {
1.48 albertel 2160: $r->print('<th>'.$lt{'curf'}.'</th>');
2161: $colspan++;
1.36 raeburn 2162: }
2163: if ($addtools) {
1.53 raeburn 2164: $r->print('<th>'.&mt('Additional Tools').'</th>');
1.48 albertel 2165: $colspan++;
1.36 raeburn 2166: }
1.48 albertel 2167: $r->print(&Apache::loncommon::end_data_table_header_row());
1.36 raeburn 2168: if ($colspan) {
2169: if ($granularity eq 'Yes') {
1.48 albertel 2170: $r->print(&Apache::loncommon::start_data_table_row('LC_data_table_dense LC_data_table_highlight').'
1.6 raeburn 2171: <td colspan="7"> </td>
1.48 albertel 2172: <td colspan="'.$colspan.'" align="center"><nobr><b>'.&mt('All:').
1.6 raeburn 2173: '</b> ');
1.36 raeburn 2174: foreach my $tool (@{$available}) {
2175: $r->print('<label><input type="checkbox" name="togglefunc"'.
1.7 raeburn 2176: ' onclick="javascript:toggleTools(document.'.$formname.'.user_'.$tool.',this);"'.
1.48 albertel 2177: ' value="'.$tool.'" />'.'<b>'.$tool.'</b></label> ');
1.6 raeburn 2178: }
1.48 albertel 2179: $r->print('</nobr></td></tr>');
1.6 raeburn 2180: }
1.36 raeburn 2181: }
2182: my %Sortby = ();
2183: foreach my $user (sort(keys(%{$current}))) {
2184: if ($env{'form.sortby'} eq 'fullname') {
2185: push(@{$Sortby{$$current{$user}{fullname}}},$user);
2186: } elsif ($env{'form.sortby'} eq 'username') {
2187: push(@{$Sortby{$$current{$user}{uname}}},$user);
2188: } elsif ($env{'form.sortby'} eq 'domain') {
2189: push(@{$Sortby{$$current{$user}{udom}}},$user);
2190: } elsif ($env{'form.sortby'} eq 'id') {
2191: push(@{$Sortby{$$current{$user}{id}}},$user);
2192: } else {
2193: push(@{$Sortby{$$current{$user}{fullname}}},$user);
2194: }
2195: }
2196: foreach my $key (sort(keys(%Sortby))) {
2197: foreach my $user (@{$Sortby{$key}}) {
2198: my $id = $$current{$user}{id};
2199: my $fullname = $$current{$user}{fullname};
2200: my $udom = $$current{$user}{udom};
2201: my $uname = $$current{$user}{uname};
2202: my $start = $$current{$user}{start};
2203: my $end = $$current{$user}{end};
1.48 albertel 2204: $r->print(&Apache::loncommon::start_data_table_row('LC_data_table_dense').'
2205: <td>');
1.36 raeburn 2206: if ($$current{$user}{changestate} eq 'reenable') {
2207: $r->print('<nobr><label>'.
1.5 raeburn 2208: '<input type="checkbox" name="reenable" value="'.$user.'" />'.
1.7 raeburn 2209: $lt{'reen'}.'</label></nobr><br />');
1.36 raeburn 2210: } elsif ($$current{$user}{changestate} eq 'expire') {
2211: $r->print('<nobr><label>'.
1.5 raeburn 2212: '<input type="checkbox" name="expire" value="'.$user.'" />'.
1.7 raeburn 2213: $lt{'expi'}.'</label></nobr><br />');
1.36 raeburn 2214: } elsif ($$current{$user}{changestate} eq 'activate') {
2215: $r->print('<nobr><label>'.
1.5 raeburn 2216: '<input type="checkbox" name="activate" value="'.$user.'" />'.
1.7 raeburn 2217: $lt{'acti'}.'</label></nobr><br />');
1.36 raeburn 2218: }
2219: $r->print('<nobr><label>'.
1.6 raeburn 2220: '<input type="checkbox" name="deletion" value="'.$user.'" />'.
1.7 raeburn 2221: $lt{'dele'}.'</label></nobr>');
1.36 raeburn 2222: if ($specificity eq 'Yes') {
2223: $r->print('<br /><nobr><label>'.
1.5 raeburn 2224: '<input type="checkbox" name="changepriv" value="'.$user.'" />'.$lt{'chpr'}.
1.7 raeburn 2225: '</label></nobr>');
1.36 raeburn 2226: }
2227: $r->print('
1.48 albertel 2228: </td>'.
2229: '<td>'.$fullname.'</td>'.
2230: '<td>'.$uname.'</td>'.
2231: '<td>'. $udom.'</td>'.
2232: '<td>'.$id.'</td>'.
2233: '<td>'.$start.'</td>'.
2234: '<td>'.$end.'</td>');
1.36 raeburn 2235: if ($hastools) {
1.48 albertel 2236: $r->print('<td align="left"><nobr>'.
1.6 raeburn 2237: ' ');
1.36 raeburn 2238: foreach my $tool (@{$$current{$user}{currtools}}) {
2239: if ($granularity eq 'Yes') {
2240: $r->print('<label><input type="checkbox" '.
1.7 raeburn 2241: 'checked="checked" '.
2242: 'name="user_'.$tool.'" value="'.
2243: $user.'" />'.$tool.'</label>');
1.36 raeburn 2244: } else {
2245: $r->print('<input type="hidden" '.
1.7 raeburn 2246: 'checked="checked" '.
2247: 'name="user_'.$tool.'" value="'.
2248: $user.'" />'.$tool);
1.36 raeburn 2249: }
2250: $r->print(' ');
1.5 raeburn 2251: }
1.48 albertel 2252: $r->print('</nobr></td>');
1.36 raeburn 2253: }
2254: if ($addtools) {
1.48 albertel 2255: $r->print('<td align="left">');
1.36 raeburn 2256: if ($granularity eq 'Yes') {
2257: foreach my $tool (@{$$current{$user}{newtools}}) {
2258: $r->print('<nobr><label><input type="checkbox"
1.5 raeburn 2259: name="user_'.$tool.'" value="'.
2260: $user.'" />'.$tool.
1.7 raeburn 2261: '</label></nobr> ');
1.36 raeburn 2262: }
2263: } else {
2264: foreach my $tool (@{$$current{$user}{newtools}}) {
2265: $r->print('<nobr><input type="hidden"
1.5 raeburn 2266: name="user_'. $tool.'" value="'.
2267: $user.'" />'.$tool.
2268: '</nobr> ');
2269: }
2270: }
1.48 albertel 2271: $r->print('</td>');
1.5 raeburn 2272: }
1.48 albertel 2273: $r->print(&Apache::loncommon::end_data_table_row()."\n");
1.5 raeburn 2274: }
1.36 raeburn 2275: }
1.48 albertel 2276: $r->print(&Apache::loncommon::end_data_table());
1.53 raeburn 2277: } else {
2278: $r->print(&mt('There are no active, future or previous group members to modify.'));
1.5 raeburn 2279: }
1.53 raeburn 2280: return $numcurrent;
1.5 raeburn 2281: }
2282:
2283: sub check_uncheck_buttons {
2284: my ($r,$formname,$field,$title,$colspan) = @_;
2285: $r->print('
2286: <td '.$colspan.'>
2287: <fieldset>
2288: <legend><b>'.$title.'</b></legend>
1.48 albertel 2289: <nobr>
1.5 raeburn 2290: <input type="button" value="check all"
2291: onclick="javascript:checkAll(document.'.$formname.'.'.$field.')" />
2292:
2293: <input type="button" value="uncheck all"
2294: onclick="javascript:uncheckAll(document.'.$formname.'.'.$field.')" />
1.48 albertel 2295: </nobr>
1.5 raeburn 2296: </fieldset>
2297: </td>
2298: ');
2299: }
2300:
2301:
2302: sub change_privs_form {
1.45 albertel 2303: my ($r,$cdom,$cnum,$action,$formname,$page,$startdate,$enddate,
2304: $tools,$functions,$toolprivs,$fixedprivs,$userdata,$usertools,
2305: $memchg,$idx,$states,$stored,$sectioncount,$navbuttons,$gpterm,
2306: $ucgpterm) = @_;
1.5 raeburn 2307: my @regexps = ('userpriv_');
2308: my $nexttext;
1.6 raeburn 2309: my %lt = &Apache::lonlocal::texthash(
2310: 'tode' => 'To be deleted',
2311: 'toex' => 'To be expired',
1.29 raeburn 2312: 'nome' => "No members to be deleted or expired from the $gpterm.",
1.6 raeburn 2313: );
1.5 raeburn 2314: $r->print(&Apache::lonhtmlcommon::echo_form_input(
1.6 raeburn 2315: ['origin','action','state','page','sortby'],\@regexps));
2316: if ($env{'form.branch'} eq 'adds') {
2317: $nexttext = $$navbuttons{'adme'};
2318: } else {
2319: $nexttext = $$navbuttons{'mose'};
2320: }
1.40 albertel 2321: &topic_bar($r,3,&mt('Members to delete or expire'));
1.6 raeburn 2322: my $exp_or_del = 0;
2323: if (ref($$memchg{'deletion'}) eq 'ARRAY') {
2324: if (@{$$memchg{'deletion'}} > 0) {
1.50 albertel 2325: $r->print('<b>'.$lt{'tode'}.':</b><br /><ul>');
1.6 raeburn 2326: foreach my $user (@{$$memchg{'deletion'}}) {
2327: $r->print('<li>'.$$userdata{$user}[$$idx{fullname}].
2328: ' ('.$user.')</li>');
2329: }
1.45 albertel 2330: $r->print('</ul>');
1.6 raeburn 2331: $exp_or_del += @{$$memchg{'deletion'}};
2332: }
2333: }
2334: if (ref($$memchg{'expire'}) eq 'ARRAY') {
2335: if (@{$$memchg{'expire'}} > 0) {
1.50 albertel 2336: $r->print('<b>'.$lt{'toex'}.':</b><br /><ul>');
1.6 raeburn 2337: foreach my $user (@{$$memchg{'expire'}}) {
2338: $r->print('<li>'.$$userdata{$user}[$$idx{fullname}].
2339: ' ('.$user.')</li>');
2340: }
1.45 albertel 2341: $r->print('</ul>');
1.6 raeburn 2342: $exp_or_del += @{$$memchg{'expire'}};
2343: }
2344: }
2345: if (!$exp_or_del) {
1.45 albertel 2346: $r->print($lt{'nome'}.'<br />');
1.6 raeburn 2347: }
1.5 raeburn 2348:
1.53 raeburn 2349: &topic_bar($r,4,&mt('Setting optional privileges for specific group members'));
1.6 raeburn 2350:
1.45 albertel 2351: my $numchgs = &member_privileges_form($r,$action,$formname,$tools,
1.6 raeburn 2352: $toolprivs,$fixedprivs,$userdata,
2353: $usertools,$idx,$memchg,$states,
1.45 albertel 2354: $stored,$gpterm);
1.5 raeburn 2355: my $prevtext = $$navbuttons{'gtps'};
1.6 raeburn 2356: if ($numchgs || $exp_or_del) {
2357: &display_navbuttons($r,$formname,$$states{$action}[$page-1],$prevtext,
2358: $$states{$action}[$page+1],$nexttext);
2359: } else {
2360: &display_navbuttons($r,$formname,$$states{$action}[$page-1],$prevtext);
2361: }
1.5 raeburn 2362: return;
2363: }
2364:
2365: sub add_members_form {
1.59 ! raeburn 2366: my ($r,$cdom,$cnum,$action,$formname,$page,$startdate,$enddate,$groupname,
1.29 raeburn 2367: $description,$granularity,$quota,$sectioncount,$tools,$functions,
1.46 albertel 2368: $stored,$states,$navbuttons,$gpterm,$ucgpterm)=@_;
1.40 albertel 2369: $r->print(' <br />');
1.5 raeburn 2370: my @available = ();
2371: my @unavailable = ();
2372: &check_tools($functions,$tools,\@available,\@unavailable);
1.40 albertel 2373: &print_current_settings($r,$action,$functions,$startdate,$enddate,
2374: $groupname,$description,$granularity,$quota,
2375: \@available,\@unavailable,$gpterm,$ucgpterm);
1.59 ! raeburn 2376: &membership_options($r,$cdom,$cnum,$action,$formname,$sectioncount,1,$gpterm,
! 2377: $ucgpterm);
1.5 raeburn 2378: my $nexttext = $$navbuttons{'gtns'};
2379: my $prevtext = $$navbuttons{'gtpp'};
2380: &display_navbuttons($r,$formname,$$states{$action}[$page-1],$prevtext,
2381: $$states{$action}[$page+1],$nexttext);
2382: return;
2383: }
2384:
2385: sub choose_privs_form {
1.45 albertel 2386: my ($r,$cdom,$cnum,$action,$formname,$page,$startdate,$enddate,
2387: $tools,$functions,$toolprivs,$fixedprivs,$userdata,$usertools,$idx,
2388: $states,$stored,$sectioncount,$navbuttons,$gpterm,$ucgpterm,
2389: $crstype) = @_;
1.5 raeburn 2390:
2391: my @regexps = ('userpriv_');
2392: my $nexttext;
2393:
2394: if ($action eq 'create') {
2395: push(@regexps,'sec_');
2396: $r->print(&Apache::lonhtmlcommon::echo_form_input(
1.6 raeburn 2397: ['origin','action','state','page','sortby','autoadd','autodrop'],
1.5 raeburn 2398: \@regexps));
2399: $nexttext = $$navbuttons{'crgr'};
2400: } else {
2401: $r->print(&Apache::lonhtmlcommon::echo_form_input(
1.6 raeburn 2402: ['origin','action','state','page','sortby'],\@regexps));
1.5 raeburn 2403: $nexttext = $$navbuttons{'adme'};
2404: }
2405:
1.53 raeburn 2406: &topic_bar($r,6,&mt('Setting optional privileges for specific group members'));
1.5 raeburn 2407:
1.45 albertel 2408: &member_privileges_form($r,$action,$formname,$tools,$toolprivs,
1.5 raeburn 2409: $fixedprivs,$userdata,$usertools,$idx,undef,
1.45 albertel 2410: $states,$stored,$gpterm);
1.5 raeburn 2411:
2412: if ($action eq 'create') {
1.53 raeburn 2413: my $img1 = 7;
2414: my $img2 = 8;
2415: &mapping_options($r,$action,$formname,$page,$sectioncount,
2416: $states,$stored,$navbuttons,$img1,$img2,
1.58 raeburn 2417: $gpterm,$ucgpterm,$crstype,$cdom,$cnum);
1.5 raeburn 2418: }
2419: my $prevtext = $$navbuttons{'gtps'};
2420: &display_navbuttons($r,$formname,$$states{$action}[$page-1],$prevtext,
2421: $$states{$action}[$page+1],$nexttext);
2422: return;
2423: }
2424:
2425: sub build_boxes {
2426: my ($r,$tools,$usertools,$fixedprivs,$toolprivs,$showtools,
1.6 raeburn 2427: $showboxes,$prefix,$specificity,$excluded) = @_;
1.5 raeburn 2428: my $totalboxes = 0;
2429: if (@{$tools} > 0) {
2430: if ($specificity eq 'Yes') {
2431: foreach my $tool (@{$tools}) {
2432: @{$$showboxes{$tool}} = ();
2433: foreach my $user (sort(keys(%{$usertools}))) {
1.6 raeburn 2434: if (ref($excluded) eq 'ARRAY') {
2435: if (grep/^$user$/,@{$excluded}) {
2436: next;
2437: }
1.5 raeburn 2438: }
1.6 raeburn 2439: if ($$usertools{$user}{$tool}) {
2440: unless (grep/^$tool$/,@{$showtools}) {
2441: push(@{$showtools},$tool);
2442: }
2443: foreach my $priv (sort(keys(%{$$toolprivs{$tool}}))) {
2444: unless (exists($$fixedprivs{$tool}{$priv})) {
2445: unless(grep(/^$priv$/,@{$$showboxes{$tool}})) {
2446: push(@{$$showboxes{$tool}},$priv);
2447: $totalboxes ++;
2448: }
1.5 raeburn 2449: }
2450: }
2451: }
2452: }
2453: }
2454: if ($totalboxes > 0) {
2455: $r->print('
2456: <script type="text/javascript">
2457: function checkAllTools(formname) {
2458: ');
2459: foreach my $tool (sort(keys(%{$showboxes}))) {
2460: foreach my $priv (@{$$showboxes{$tool}}) {
2461: $r->print(' checkAll(formname.'.$prefix.$priv.');'."\n");
2462: }
2463: }
2464: $r->print('
2465: }
2466: function uncheckAllTools(formname) {
2467: ');
2468: foreach my $tool (sort(keys(%{$showboxes}))) {
2469: foreach my $priv (@{$$showboxes{$tool}}) {
2470: $r->print(' uncheckAll(formname'.$prefix.$priv.');'."\n");
2471: }
2472: }
2473: $r->print('
2474: }
2475: </script>
2476: ');
2477: }
2478: }
2479: }
2480: return $totalboxes;
2481: }
2482:
2483: sub member_privileges_form {
1.45 albertel 2484: my ($r,$action,$formname,$tools,$toolprivs,$fixedprivs,$userdata,
2485: $usertools,$idx,$memchg,$states,$stored,$gpterm) = @_;
1.5 raeburn 2486: my %lt = &Apache::lonlocal::texthash(
2487: 'addp' => 'Additional privileges',
1.53 raeburn 2488: 'fixp' => 'Core privileges',
1.5 raeburn 2489: 'oppr' => 'Optional privileges',
1.53 raeburn 2490: 'func' => 'Tool',
2491: 'forf' => 'For the collaborative tools included for group '.
2492: 'members being added or modified, '.
2493: 'there are no optional privileges to set '.
2494: 'for specific members.',
1.54 raeburn 2495: 'algr' => 'All new group members will receive the same privileges.', 'ifex' => 'If previously expired members are being re-enabled, or '.
2496: 'if access for future members is being activated now, '.
2497: 'previously set privileges will be preserved.',
1.53 raeburn 2498: 'asno' => 'As no group members are being added, '.
2499: 'there are no specific user privileges to set.',
2500: 'asng' => 'As no group tools will be made available to users, '.
2501: 'there are no specific user privileges to set.',
2502: 'nogm' => 'No group member privileges to display or set, '.
2503: 'as you have not indicated that you will be activating,'.
2504: ' re-enabling, changing privileges, or adding/removing '.
2505: 'tools for any current members.',
1.5 raeburn 2506: 'full' => 'Fullname',
2507: 'user' => 'Username',
2508: 'doma' => 'Domain',
2509: );
2510: my @defprivs;
2511: my $specificity;
2512: if ($action eq 'create') {
2513: if (defined($env{'form.defpriv'})) {
2514: @defprivs = &Apache::loncommon::get_env_multiple('form.defpriv');
2515: }
2516: $specificity = $env{'form.specificity'};
2517: } else {
1.17 raeburn 2518: if (defined($$stored{'defpriv'})) {
2519: @defprivs = @{$$stored{'defpriv'}};
2520: }
1.5 raeburn 2521: $specificity = $$stored{'specificity'};
2522: }
2523: my @showtools;
2524: my %showboxes = ();
2525: my $numtools = 1 + @{$tools};
1.3 raeburn 2526:
1.6 raeburn 2527: my @excluded = ();
2528: my $numchgs = 0;
2529: if ($formname eq 'change_privs') {
2530: my @currmembers = ();
2531: if (ref($$memchg{'deletion'}) eq 'ARRAY') {
2532: push(@excluded,@{$$memchg{'deletion'}});
2533: }
2534: if (ref($$memchg{'expire'}) eq 'ARRAY') {
2535: push(@excluded,@{$$memchg{'expire'}});
2536: }
2537: if (@excluded > 0) {
2538: foreach my $user (sort(keys(%{$usertools}))) {
2539: if (grep/^$user$/,@excluded) {
2540: next;
2541: }
2542: push(@currmembers,$user);
2543: }
2544: } else {
2545: @currmembers = sort(keys(%{$usertools}));
2546: }
2547: $numchgs = @currmembers;
2548: if (!$numchgs) {
1.45 albertel 2549: $r->print($lt{'nogm'});
1.6 raeburn 2550: return $numchgs;
2551: }
2552: }
2553:
2554: my $totalboxes = &build_boxes($r,$tools,$usertools,$fixedprivs,
2555: $toolprivs,\@showtools,\%showboxes,
2556: 'userpriv_',$specificity,\@excluded);
1.5 raeburn 2557: if (@{$tools} > 0) {
2558: if ($specificity eq 'Yes') {
2559: if ($totalboxes > 0) {
2560: my $numcells = 2;
2561: my $colspan = $numcells + 1;
2562: my %total;
1.6 raeburn 2563: if (keys(%{$usertools}) > 1) {
2564: $r->print('
1.45 albertel 2565: <table border="0" cellspacing="2" cellpadding="2">
1.5 raeburn 2566: <tr>
2567: ');
1.6 raeburn 2568: foreach my $tool (@{$tools}) {
2569: if (@{$showboxes{$tool}} > 0) {
2570: $r->print('<td valign="top">');
1.45 albertel 2571: $r->print('<table class="thinborder"><tr>'.
2572: '<th colspan="'.$colspan.'">'.
1.6 raeburn 2573: $tool.'</th></tr><tr>');
2574: my $privcount = 0;
2575: foreach my $priv (@{$showboxes{$tool}}) {
2576: $privcount ++;
2577: if (($privcount == @{$showboxes{$tool}}) &&
2578: ($privcount > 1)) {
2579: if ($privcount%$numcells) {
2580: $r->print('<td colspan="'.$colspan.'">');
2581: } else {
2582: $r->print('<td>');
2583: }
1.5 raeburn 2584: } else {
2585: $r->print('<td>');
2586: }
1.6 raeburn 2587: $r->print(qq|
1.5 raeburn 2588: <fieldset><legend><b>$$toolprivs{$tool}{$priv}</b></legend>
2589: <nobr>
2590: <input type="button" value="check all"
2591: onclick="javascript:checkAll(document.$formname.userpriv_$priv)" />
2592:
2593: <input type="button" value="uncheck all"
2594: onclick="javascript:uncheckAll(document.$formname.userpriv_$priv)" />
2595: </nobr></fieldset><br />|);
1.6 raeburn 2596: $r->print('</td>');
2597: if ($privcount < @{$showboxes{$tool}}) {
2598: if (@{$showboxes{$tool}} > 2) {
2599: if ($privcount%$numcells == 0) {
2600: $r->print('</tr><tr>');
2601: }
2602: } else {
2603: $r->print('<tr></tr>');
1.5 raeburn 2604: }
2605: }
2606: }
1.6 raeburn 2607: $r->print('</tr></table></td><td> </td>');
1.5 raeburn 2608: }
2609: }
1.45 albertel 2610: $r->print('</tr></table>');
1.5 raeburn 2611: }
1.45 albertel 2612: $r->print(&Apache::loncommon::start_data_table().
2613: &Apache::loncommon::start_data_table_header_row());
1.5 raeburn 2614: $r->print(<<"END");
1.45 albertel 2615: <th>$lt{'full'}</th>
2616: <th>$lt{'user'}</th>
1.5 raeburn 2617: <th>$lt{'doma'}</th>
2618: <th colspan="$numtools">$lt{'addp'}</th>
2619: END
1.45 albertel 2620: $r->print(&Apache::loncommon::end_data_table_header_row());
2621: &member_privs_entries($r,$usertools,$toolprivs,$fixedprivs,
1.6 raeburn 2622: $userdata,$idx,\@showtools,\@defprivs,
2623: \@excluded);
1.45 albertel 2624: $r->print(&Apache::loncommon::end_data_table());
1.5 raeburn 2625: } else {
1.43 albertel 2626: $r->print($lt{'forf'}.'<br />');
1.45 albertel 2627: &display_defprivs($r,$tools,$toolprivs,\@defprivs);
1.5 raeburn 2628: }
2629: } else {
2630: if (keys(%{$usertools}) > 0) {
1.54 raeburn 2631: $r->print($lt{'algr'}.'<br />'.$lt{'ifex'}.'<br /><br />');
1.45 albertel 2632: &display_defprivs($r,$tools,$toolprivs,\@defprivs);
1.5 raeburn 2633: } else {
1.43 albertel 2634: $r->print($lt{'asno'}.'<br />');
1.5 raeburn 2635: }
2636: }
2637: } else {
1.43 albertel 2638: $r->print($lt{'asng'});
1.5 raeburn 2639: }
1.6 raeburn 2640: return $numchgs;
1.1 raeburn 2641: }
2642:
1.5 raeburn 2643: sub process_request {
1.45 albertel 2644: my ($r,$cdom,$cnum,$action,$state,$page,$groupname,$description,
1.5 raeburn 2645: $specificity,$userdata,$startdate,$enddate,$tools,$functions,$toolprivs,
2646: $usertools,$idx,$types,$roles,$sections,$states,$navbuttons,$memchg,
1.45 albertel 2647: $sectioncount,$stored,$gpterm,$ucgpterm,$crstype) = @_;
1.3 raeburn 2648:
2649: $r->print(&Apache::lonhtmlcommon::echo_form_input(
1.6 raeburn 2650: ['origin','action','state','page','sortby']));
1.5 raeburn 2651:
1.29 raeburn 2652: my $earlyout = &validate_groupname($groupname,$action,$cdom,$cnum,$gpterm,
2653: $ucgpterm,$crstype);
1.5 raeburn 2654: if ($earlyout) {
2655: $r->print('
2656: <table width="100%" cellpadding="0" cellspacing="0" border="0">
2657: <tr>
2658: <td> </td>
2659: <td colspan="3">
2660: '.$earlyout.'</td></tr>');
2661: &display_navbuttons($r,$state,$$states{$action}[$page-1],
2662: $$navbuttons{'gtps'});
2663: $r->print('</table>');
2664: return;
2665: }
2666:
2667: my @defprivs = ();
2668: if ($action eq 'create' || $state eq 'chgresult') {
2669: if (defined($env{'form.defpriv'})) {
2670: @defprivs = &Apache::loncommon::get_env_multiple('form.defpriv');
2671: }
2672: if ($state eq 'chgresult') {
2673: my @okprivs = ();
2674: foreach my $tool (@{$tools}) {
2675: foreach my $priv (sort(keys(%{$$toolprivs{$tool}}))) {
2676: push(@okprivs,$priv);
2677: }
2678: }
2679: my @temp = ();
2680: foreach my $defpriv (@defprivs) {
2681: if (grep/^$defpriv$/,@okprivs) {
2682: push(@temp,$defpriv);
2683: }
2684: }
2685: @defprivs = @temp;
2686: }
2687: } else {
1.17 raeburn 2688: if (defined($$stored{'defpriv'})) {
2689: @defprivs = @{$$stored{'defpriv'}};
2690: }
1.5 raeburn 2691: }
2692:
2693: my $outcome;
2694: if ($action eq 'create' || $state eq 'chgresult') {
2695: $outcome = &write_group_data($r,$cdom,$cnum,$action,$state,$groupname,
2696: $description,$startdate,$enddate,
2697: $specificity,$functions,$tools,
2698: $sectioncount,$roles,$types,$sections,
1.29 raeburn 2699: \@defprivs,$stored,$gpterm,$ucgpterm,
2700: $crstype);
1.5 raeburn 2701: }
2702: if (($action eq 'create' && $outcome eq 'ok') || (($action eq 'modify') &&
2703: (($state eq 'memresult') || ($state eq 'addresult')))) {
1.6 raeburn 2704: &process_membership($r,$cdom,$cnum,$action,$state,$groupname,$tools,
2705: $enddate,$startdate,$userdata,$idx,$toolprivs,
1.29 raeburn 2706: $usertools,$specificity,\@defprivs,$memchg,$gpterm,
2707: $ucgpterm);
1.5 raeburn 2708: }
2709: return;
2710: }
2711:
2712: sub write_group_data {
2713: my ($r,$cdom,$cnum,$action,$state,$groupname,$description,$startdate,
2714: $enddate,$specificity,$functions,$tools,$sectioncount,$roles,$types,
1.29 raeburn 2715: $sections,$defprivs,$stored,$gpterm,$ucgpterm,$crstype) = @_;
1.5 raeburn 2716: my $now = time;
2717: my $creation = $now;
2718: my $creator = $env{'user.name'}.':'.$env{'user.domain'};
2719: if ($state eq 'chgresult') {
2720: $creation = $$stored{'creation'};
2721: $creator = $$stored{'creator'};
2722: }
1.24 www 2723: my $esc_description = &escape($description);
1.5 raeburn 2724: my @single_attributes = ('description','functions','startdate','enddate',
2725: 'creation','modified','creator','granularity',
1.29 raeburn 2726: 'specificity','autoadd','autodrop','quota');
1.5 raeburn 2727: my @mult_attributes = ('roles','types','sectionpick','defpriv');
1.15 albertel 2728:
1.37 raeburn 2729: my ($crsquota,$freespace,$maxposs) = &get_quota_constraints($action,
2730: $stored);
2731: my $quota = $env{'form.quota'};
2732:
2733: $quota =~ s/^\s*([^\s]*)\s*$/$1/;
2734: if ($quota eq '') {
2735: $quota = 0;
2736: }
2737: if ($quota !~ /^\d*\.?\d*$/) {
2738: $quota = 0;
2739: $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));
2740: }
2741: if ($quota > $maxposs) {
2742: $quota = $maxposs;
1.53 raeburn 2743: $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 2744: }
1.5 raeburn 2745: my %groupinfo = (
2746: description => $esc_description,
2747: startdate => $startdate,
2748: enddate => $enddate,
2749: creation => $creation,
2750: modified => $now,
2751: creator => $creator,
2752: granularity => $env{'form.granularity'},
2753: specificity => $specificity,
2754: autoadd => $env{'form.autoadd'},
2755: autodrop => $env{'form.autodrop'},
1.37 raeburn 2756: quota => $quota,
1.5 raeburn 2757: );
1.37 raeburn 2758:
1.5 raeburn 2759: foreach my $func (keys(%{$functions})) {
2760: my $status;
2761: if (grep(/^$func$/,@{$tools})) {
2762: $status = 'on';
2763: } else {
2764: $status = 'off';
2765: }
2766: $groupinfo{'functions'} .= qq|<name id="$func">$status</name>|;
2767: }
2768:
2769: $groupinfo{'roles'} = $roles;
2770: $groupinfo{'types'} = $types;
2771: $groupinfo{'sectionpick'} = $sections;
2772: $groupinfo{'defpriv'} = $defprivs;
2773:
2774: my %groupsettings = ();
2775: foreach my $item (@single_attributes) {
2776: $groupsettings{$groupname} .= qq|<$item>$groupinfo{$item}</$item>|;
2777: }
2778: foreach my $item (@mult_attributes) {
2779: foreach my $entry (@{$groupinfo{$item}}) {
2780: $groupsettings{$groupname} .= qq|<$item>$entry</$item>|;
2781: }
2782: }
2783: my $autosec;
2784: my @autorole = &Apache::loncommon::get_env_multiple('form.autorole');
1.15 albertel 2785:
1.5 raeburn 2786: foreach my $role (@autorole) {
2787: if (defined($env{'form.sec_'.$role})) {
2788: my @autosections=&Apache::loncommon::get_env_multiple('form.sec_'.
2789: $role);
2790: $autosec .= '<role id="'.$role.'">';
2791: foreach my $sec (@autosections) {
2792: $autosec .= '<section>'.$sec.'</section>';
2793: }
2794: $autosec .= '</role>';
2795: }
2796: }
2797: if ($autosec) {
2798: $groupsettings{$groupname} .= qq|<autosec>$autosec</autosec>|;
2799: }
2800: my $result = &Apache::lonnet::modify_coursegroup($cdom,$cnum,
2801: \%groupsettings);
2802:
2803: if ($result eq 'ok') {
2804: if ($action eq 'create') {
1.32 raeburn 2805: my $result = &add_group_folder($cdom,$cnum,$now,$groupname,$action,
2806: $description,$tools,\%groupinfo,
2807: $gpterm,$ucgpterm,$crstype);
2808: if ($result ne 'ok') {
1.37 raeburn 2809: $r->print(&mt('A problem occurred when creating folders for the new [_1]. [_2].<br />',$gpterm,$result));
1.32 raeburn 2810: }
1.29 raeburn 2811: $r->print(&mt('[_1] [_2] was created.<br />',$ucgpterm,$groupname));
1.56 raeburn 2812: } elsif ($action eq 'modify') {
2813: my (@oldtools,@newtools);
2814: if (ref($$stored{'tool'}) eq 'ARRAY') {
2815: @oldtools = @{$$stored{'tool'}};
2816: }
2817: if (ref($tools) eq 'ARRAY') {
2818: @newtools = @{$tools};
2819: }
2820: if (!grep(/^discussion$/,@oldtools) &&
2821: grep(/^discussion$/,@newtools)) {
2822: my $crspath = '/uploaded/'.$cdom.'/'.$cnum.'/';
2823: my $boardsmap = $crspath.'group_boards_'.$groupname.'.sequence';
2824: my $navmap = Apache::lonnavmaps::navmap->new();
2825: my $bbmapres = $navmap->getResourceByUrl($boardsmap);
2826: undef($navmap);
2827: if (!$bbmapres) {
2828: my $grpmap = $crspath.'group_folder_'.$groupname.'.sequence';
2829: my $disctitle = &mt('Discussion Boards');
2830: my $outcome = &map_updater($cdom,$cnum,'group_boards_'.
2831: $groupname.'.sequence','bbseq',
2832: $disctitle,$grpmap);
2833: my ($furl,$ferr) =
2834: &Apache::lonuserstate::readmap($cdom.'/'.$cnum);
2835: $navmap = Apache::lonnavmaps::navmap->new();
2836: # modify parameter
2837: if ($outcome eq 'ok') {
2838: my $parm_result = &parm_setter($navmap,$cdom,$boardsmap,
2839: $groupname);
2840: if ($parm_result) {
2841: $r->print(&mt('Error while setting parameters '.
2842: 'for Discussion Boards folder: '.
2843: '[_1]<br />.',$parm_result));
2844: } else {
2845: $r->print(&mt('Discussion Boards Folder created.<br />'));
2846: }
2847: } else {
2848: $r->print($outcome);
2849: }
2850: undef($navmap);
2851: }
2852: }
1.29 raeburn 2853: $r->print(&mt('[_1] [_2] was updated.<br />',$ucgpterm,$groupname));
1.5 raeburn 2854: }
2855: } else {
2856: my %actiontype = (
2857: 'create' => 'creating',
2858: 'modify' => 'modifying',
2859: );
1.29 raeburn 2860: &Apache::lonnet::logthis("Failed to store $gpterm $groupname ".
2861: 'in '.lc($crstype).': '.$cnum.
2862: ' in domain: '.$cdom);
1.37 raeburn 2863: $r->print(&mt('An error occurred when [_1] the [_2]. '.
1.29 raeburn 2864: 'Please try again.',$actiontype{$action},$gpterm));
1.5 raeburn 2865: }
2866: return $result;
2867: }
2868:
2869: sub process_membership {
1.6 raeburn 2870: my ($r,$cdom,$cnum,$action,$state,$groupname,$tools,$enddate,$startdate,
1.29 raeburn 2871: $userdata,$idx,$toolprivs,$usertools,$specificity,$defprivs,$memchg,
2872: $gpterm,$ucgpterm)=@_;
1.5 raeburn 2873: my %usersettings = ();
1.6 raeburn 2874: my %added= ();
2875: my %failed = ();
2876: my $num_ok = 0;
2877: my $num_fail = 0;
1.3 raeburn 2878: my %group_privs = ();
1.20 raeburn 2879: my %curr_privs = ();
1.21 raeburn 2880: my %curr_start = ();
2881: my %curr_end = ();
1.3 raeburn 2882: my %tooltype = ();
1.5 raeburn 2883:
1.3 raeburn 2884: foreach my $tool (@{$tools}) {
2885: foreach my $priv (sort(keys(%{$$toolprivs{$tool}}))) {
2886: $tooltype{$priv} = $tool;
1.5 raeburn 2887: if ($specificity eq 'Yes') {
1.3 raeburn 2888: my @users =
2889: &Apache::loncommon::get_env_multiple('form.userpriv_'.$priv);
2890: foreach my $user (@users) {
2891: $group_privs{$user} .= $priv.':';
1.8 raeburn 2892: if ($state eq 'memresult') {
2893: unless (exists($$usertools{$user}{$tool})) {
2894: $$usertools{$user}{$tool} = 1;
2895: }
2896: }
1.3 raeburn 2897: }
2898: } else {
1.5 raeburn 2899: if (@{$defprivs} > 0) {
1.26 raeburn 2900: if (grep/^\Q$priv\E$/,@{$defprivs}) {
1.5 raeburn 2901: foreach my $user (sort(keys(%{$usertools}))) {
2902: if ($$usertools{$user}{$tool}) {
2903: $group_privs{$user} .= $priv.':';
2904: }
1.3 raeburn 2905: }
2906: }
2907: }
2908: }
2909: }
2910: }
2911: foreach my $user (keys(%group_privs)) {
2912: $group_privs{$user} =~ s/:$//;
2913: }
1.5 raeburn 2914:
1.6 raeburn 2915: my $now = time;
2916: my @activate = ();
2917: my @expire = ();
2918: my @deletion = ();
2919: my @reenable = ();
1.20 raeburn 2920: my @unchanged = ();
1.6 raeburn 2921: if ($state eq 'memresult') {
2922: if (ref($$memchg{'activate'}) eq 'ARRAY') {
2923: @activate = @{$$memchg{'activate'}};
2924: }
2925: if (ref($$memchg{'expire'}) eq 'ARRAY') {
2926: @expire = @{$$memchg{'expire'}};
2927: }
2928: if (ref($$memchg{'deletion'}) eq 'ARRAY') {
2929: @deletion = @{$$memchg{'deletion'}};
2930: }
2931: if (ref($$memchg{'reenable'}) eq 'ARRAY') {
2932: @reenable = @{$$memchg{'reenable'}};
2933: }
1.20 raeburn 2934: my %membership = &Apache::lonnet::get_group_membership($cdom,$cnum,
2935: $groupname);
2936: foreach my $key (sort(keys(%membership))) {
2937: if ($key =~ /^\Q$groupname\E:([^:]+:[^:]+)$/) {
1.21 raeburn 2938: ($curr_end{$1},$curr_start{$1},$curr_privs{$1}) =
2939: split(/:/,$membership{$key},3);
1.20 raeburn 2940: }
2941: }
1.6 raeburn 2942: if (@expire + @deletion > 0) {
2943: foreach my $user (@expire) {
1.21 raeburn 2944: my $savestart = $curr_start{$user};
2945: if ($savestart > $now) {
2946: $savestart = $now;
1.6 raeburn 2947: }
1.21 raeburn 2948: $usersettings{$groupname.':'.$user} = $now.':'.$savestart.':'.
2949: $curr_privs{$user};
1.6 raeburn 2950: if (&Apache::lonnet::modify_group_roles($cdom,$cnum,$groupname,
1.21 raeburn 2951: $user,$now,$savestart,
2952: $curr_privs{$user}) eq 'ok') {
1.6 raeburn 2953: push(@{$added{'expired'}},$user);
2954: $num_ok ++;
2955: } else {
2956: push(@{$failed{'expired'}},$user);
2957: $num_fail ++;
2958: }
2959: }
2960: foreach my $user (@deletion) {
2961: $usersettings{$groupname.':'.$user} = $now.':-1:';
2962: if (&Apache::lonnet::modify_group_roles($cdom,$cnum,$groupname,
2963: $user,$now,'-1','')
2964: eq 'ok') {
2965: push(@{$added{'deleted'}},$user);
2966: $num_ok ++;
2967: } else {
2968: push(@{$failed{'deleted'}},$user);
2969: $num_fail ++;
2970: }
2971: }
2972: }
1.8 raeburn 2973: }
1.6 raeburn 2974:
1.5 raeburn 2975: foreach my $user (sort(keys(%{$usertools}))) {
1.20 raeburn 2976: if ((grep(/^$user$/,@expire)) || (grep(/^$user$/,@deletion))) {
2977: next;
2978: }
1.6 raeburn 2979: my $type;
2980: my $start = $startdate;
2981: my $end = $enddate;
2982: if ($state eq 'memresult') {
2983: if (@activate > 0) {
2984: if (grep/^$user$/,@activate) {
2985: $start = $now;
1.21 raeburn 2986: $end = $enddate;
1.6 raeburn 2987: $type = 'activated';
2988: }
2989: }
2990: if (@reenable > 0) {
2991: if (grep/^$user$/,@reenable) {
1.21 raeburn 2992: $start = $startdate;
2993: $end = $enddate;
1.6 raeburn 2994: $type = 'reenabled';
2995: }
2996: }
1.38 raeburn 2997: if ($type eq '') {
2998: if ($curr_privs{$user} eq $group_privs{$user}) {
2999: push(@unchanged,$user);
3000: next;
3001: }
3002: if (exists($curr_start{$user})) {
3003: $start = $curr_start{$user};
3004: }
3005: if (exists($curr_end{$user})) {
3006: $end = $curr_end{$user};
3007: }
3008: $type = 'modified';
3009: }
1.6 raeburn 3010: } else {
3011: $type = 'added';
3012: }
3013: $usersettings{$groupname.':'.$user} = $end.':'.$start.':'.
1.5 raeburn 3014: $group_privs{$user};
3015: if (&Apache::lonnet::modify_group_roles($cdom,$cnum,$groupname,
1.6 raeburn 3016: $user,$end,$start,
1.5 raeburn 3017: $group_privs{$user}) eq 'ok') {
1.6 raeburn 3018: push(@{$added{$type}},$user);
3019: $num_ok ++;
1.3 raeburn 3020: } else {
1.6 raeburn 3021: push(@{$failed{$type}},$user);
3022: $num_fail ++;
1.5 raeburn 3023: }
3024: }
3025: my $roster_result = &Apache::lonnet::modify_coursegroup_membership($cdom,
3026: $cnum,\%usersettings);
1.6 raeburn 3027: if ($num_ok) {
3028: foreach my $type (sort(keys(%added))) {
3029: $r->print(&mt('The following users were successfully [_1]',$type));
1.20 raeburn 3030: if (!($type eq 'deleted' || $type eq 'expired')) {
1.6 raeburn 3031: $r->print(&mt(' with the following privileges'));
3032: }
3033: $r->print(':<br />');
3034: foreach my $user (@{$added{$type}}) {
1.8 raeburn 3035: my $privlist = '';
3036: if (!($type eq 'deleted' || $type eq 'expired')) {
3037: $privlist = ': ';
1.6 raeburn 3038: my @privs = split(/:/,$group_privs{$user});
3039: my $curr_tool = '';
3040: foreach my $priv (@privs) {
3041: unless ($curr_tool eq $tooltype{$priv}) {
3042: $curr_tool = $tooltype{$priv};
3043: $privlist .= '<b>'.$curr_tool.'</b>: ';
3044: }
3045: $privlist .= $$toolprivs{$curr_tool}{$priv}.', ';
3046: }
3047: $privlist =~ s/, $//;
3048: }
1.8 raeburn 3049: $r->print($$userdata{$user}[$$idx{fullname}].' - '.$user.$privlist.'<br />');
1.6 raeburn 3050: }
1.20 raeburn 3051: $r->print('<br />');
1.6 raeburn 3052: }
3053: }
3054: if ($num_fail) {
3055: foreach my $type (sort(keys(%failed))) {
3056: $r->print(&mt('The following users could not be [_1], because an error occurred:<br />',$type));
3057: foreach my $user (@{$failed{$type}}) {
3058: $r->print($$userdata{$user}[$$idx{fullname}].' - '.$user.'<br />');
3059: }
1.5 raeburn 3060: }
1.20 raeburn 3061: $r->print('<br />');
3062: }
3063: if (@unchanged > 0) {
3064: $r->print(&mt('No change occurred for the following users:<br />'));
3065: foreach my $user (sort(@unchanged)) {
3066: $r->print($$userdata{$user}[$$idx{fullname}].' - '.$user.'<br />');
3067: }
3068: $r->print('<br />');
1.5 raeburn 3069: }
3070: if ($roster_result eq 'ok') {
1.29 raeburn 3071: $r->print('<br />'.&mt('[_1] membership list updated.',$ucgpterm));
1.53 raeburn 3072: $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 3073: } else {
1.29 raeburn 3074: $r->print('<br />'.&mt('An error occurred while updating the [_1] membership list -',$gpterm).$roster_result.'<br />');
1.5 raeburn 3075: }
3076: return;
3077: }
3078:
3079: sub mapping_options {
1.44 albertel 3080: my ($r,$action,$formname,$page,$sectioncount,$states,$stored,
1.58 raeburn 3081: $navbuttons,$img1,$img2,$gpterm,$ucgpterm,$crstype,$cdom,$cnum) = @_;
1.5 raeburn 3082: my %lt = &Apache::lonlocal::texthash(
1.29 raeburn 3083: 'auto' => "Settings for automatic $gpterm enrollment",
3084: 'gmma' => "$ucgpterm membership mapping to specific sections/roles",
3085: 'endi' => "Enable/disable automatic $gpterm enrollment for ".
3086: "users in specified roles and sections",
1.53 raeburn 3087: '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 3088: '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.",
3089: 'pirs' => "Pick roles and sections for automatic $gpterm enrollment",
1.5 raeburn 3090: 'curr' => 'Currently set to',
3091: 'on' => 'on',
3092: 'off' => 'off',
1.29 raeburn 3093: 'auad' => "Automatically enable $gpterm membership when roles are added?",
3094: 'auex' => "Automatically expire $gpterm membership when roles are removed?",
3095: 'mapr' => "Mapping of roles and sections affected by automatic $gpterm enrollment/disenrollment follows scheme chosen below.",
1.5 raeburn 3096: );
1.44 albertel 3097: &automapping($r,$action,$stored,\%lt,$img1);
1.58 raeburn 3098: &mapping_settings($r,$sectioncount,\%lt,$stored,$img2,$crstype,$cdom,$cnum,
3099: $action);
1.5 raeburn 3100: return;
3101: }
3102:
3103: sub automapping {
1.44 albertel 3104: my ($r,$action,$stored,$lt,$image) = @_;
1.5 raeburn 3105: my $add = 'off';
3106: my $drop = 'off';
3107: if (exists($$stored{'autoadd'})) {
3108: $add = $$stored{'autoadd'};
3109: }
3110: if (exists($$stored{'autodrop'})) {
3111: $drop = $$stored{'autodrop'};
3112: }
1.40 albertel 3113: &topic_bar($r,$image,$$lt{'endi'});
1.5 raeburn 3114: $r->print('
1.44 albertel 3115: <b>'.$$lt{'gmma'}.':</b><br />'.$$lt{'adds'}.'<br />'.$$lt{'drops'}.'<br /><br />
1.5 raeburn 3116: <nobr>'.$$lt{'auad'}.':
1.18 albertel 3117: <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 3118: if ($action eq 'modify') {
3119: $r->print(' ('.$$lt{'curr'}.' <b>'.$$lt{$add}.'</b>)');
3120: }
3121: $r->print('
1.44 albertel 3122: </nobr><br />
1.5 raeburn 3123: <nobr>'.$$lt{'auex'}.':
1.18 albertel 3124: <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 3125: if ($action eq 'modify') {
3126: $r->print(' ('.$$lt{'curr'}.' <b>'.$$lt{$drop}.'</b>)');
1.3 raeburn 3127: }
1.44 albertel 3128: $r->print('</nobr><br /><br />'.$$lt{'mapr'});
1.5 raeburn 3129: }
1.3 raeburn 3130:
1.5 raeburn 3131: sub mapping_settings {
1.58 raeburn 3132: my ($r,$sectioncount,$lt,$stored,$image,$crstype,$cdom,$cnum,$action) = @_;
1.5 raeburn 3133: my @sections = keys(%{$sectioncount});
3134: if (@sections > 0) {
3135: @sections = sort {$a cmp $b} @sections;
1.17 raeburn 3136: unshift(@sections,'none'); # Put 'no sections' next
3137: unshift(@sections,'all'); # Put 'all' at the front of the list
1.53 raeburn 3138: } else {
3139: @sections = ('all','none');
1.3 raeburn 3140: }
1.40 albertel 3141: &topic_bar($r,$image,$$lt{'pirs'});
1.5 raeburn 3142: my @roles = &standard_roles();
1.59 ! raeburn 3143: my %customroles = &Apache::lonhtmlcommon::course_custom_roles($cdom,$cnum);
1.44 albertel 3144: $r->print(&Apache::loncommon::start_data_table().
3145: &Apache::loncommon::start_data_table_header_row());
1.5 raeburn 3146: $r->print('
3147: <th>'.&mt('Active?').'</th>
3148: <th>'.&mt('Role').'</th>');
3149: if (@sections > 0) {
1.44 albertel 3150: $r->print('<th>'.&mt('Sections').'</th>');
1.3 raeburn 3151: }
1.44 albertel 3152: $r->print(&Apache::loncommon::end_data_table_header_row()."\n");
1.5 raeburn 3153: foreach my $role (@roles) {
1.58 raeburn 3154: my $roletitle=&Apache::lonnet::plaintext($role,$crstype);
3155: $r->print(&print_autorole_item($role,$roletitle,\@sections));
1.5 raeburn 3156: }
1.58 raeburn 3157: my @customs;
1.5 raeburn 3158: foreach my $role (sort(keys(%customroles))) {
1.58 raeburn 3159: my ($roletitle) = ($role =~ m|^cr/[^/]+/[^/]+/(.+)$|);
3160: push (@customs,$role);
3161: $r->print(&print_autorole_item($role,$roletitle,\@sections));
3162: }
3163: if ($action eq 'modify') {
3164: foreach my $role (@{$$stored{'autorole'}}) {
3165: if ((!grep(/^\Q$role\E$/,@customs)) &&
3166: (!grep(/^\Q$role\E$/,@roles))) {
3167: my $roletitle;
3168: if ($role =~ /^cr/) {
3169: ($roletitle) = ($role =~ m|_([^_]+)$|);
3170: } else {
3171: $roletitle = &Apache::lonnet::plaintext($role,$crstype);
3172: }
3173: $r->print(&print_autorole_item($role,$roletitle,\@sections));
3174: }
3175: }
1.5 raeburn 3176: }
1.44 albertel 3177: $r->print(&Apache::loncommon::end_data_table());
1.5 raeburn 3178: return;
3179: }
1.3 raeburn 3180:
1.58 raeburn 3181: sub print_autorole_item {
3182: my ($role,$roletitle,$sections) = @_;
3183: my $sections_sel;
3184: if (@{$sections} > 0) {
3185: if ($role eq 'cc') {
3186: $sections_sel = '<td align="right">'.
3187: &mt('all sections').'<input type="hidden" '.
3188: 'name="sec_cc" value="all" /></td>';
3189: } else {
3190: $sections_sel='<td align="right">'.
3191: §ions_selection($sections,'sec_'.$role).
3192: '</td>';
3193: }
3194: }
3195: my $output = &Apache::loncommon::start_data_table_row().
3196: '<td><input type="checkbox" '.
3197: 'name="autorole" value="'.$role.'" />'.
3198: '</td><td>'.$roletitle.'</td>'.$sections_sel.
3199: &Apache::loncommon::end_data_table_row();
3200: return $output;
3201: }
3202:
1.5 raeburn 3203: sub standard_roles {
1.17 raeburn 3204: my @roles = ('cc','in','ta','ep','st');
1.5 raeburn 3205: return @roles;
3206: }
3207:
3208: sub modify_menu {
1.29 raeburn 3209: my ($r,$groupname,$page,$gpterm) = @_;
1.5 raeburn 3210: my @menu =
3211: (
1.29 raeburn 3212: { text => "Modify default $gpterm settings",
1.5 raeburn 3213: help => 'Course_Modify_Group',
3214: state => 'change_settings',
3215: branch => 'settings',
3216: },
1.6 raeburn 3217: { text => 'Modify access, tools and/or privileges for previous, '.
3218: 'future, or current members',
1.5 raeburn 3219: help => 'Course_Modify_Group_Membership',
3220: state => 'change_members',
3221: branch => 'members',
3222: },
1.29 raeburn 3223: { text => "Add member(s) to the $gpterm",
1.5 raeburn 3224: help => 'Course_Group_Add_Members',
3225: state => 'add_members',
3226: branch => 'adds',
3227: },
3228: );
3229: my $menu_html = '';
3230: foreach my $menu_item (@menu) {
3231: $menu_html .=
3232: '<p><font size="+1"><a href="/adm/coursegroups?action=modify&refpage='.$env{'form.refpage'}.'&groupname='.$groupname.'&state='.$menu_item->{'state'}.'&branch='.$menu_item->{'branch'}.'">';
3233: $menu_html.= &mt($menu_item->{'text'}).'</a></font>';
3234: if (exists($menu_item->{'help'})) {
3235: $menu_html.=
3236: &Apache::loncommon::help_open_topic($menu_item->{'help'});
3237: }
3238: $menu_html.='</p>'.$/;
1.3 raeburn 3239: }
1.5 raeburn 3240: $r->print($menu_html);
1.3 raeburn 3241: return;
3242: }
3243:
3244: sub member_privs_entries {
1.45 albertel 3245: my ($r,$usertools,$toolprivs,$fixedprivs,$userdata,$idx,$showtools,
3246: $defprivs,$excluded) = @_;
1.5 raeburn 3247: foreach my $user (sort(keys(%{$usertools}))) {
1.6 raeburn 3248: if (defined($excluded)) {
3249: if (ref($excluded) eq 'ARRAY') {
3250: if (grep/^$user$/,@{$excluded}) {
3251: next;
3252: }
3253: }
3254: }
1.5 raeburn 3255: my ($uname,$udom) = split(/:/,$user);
1.45 albertel 3256: $r->print(&Apache::loncommon::start_data_table_row().'
1.5 raeburn 3257: <td>'.$$userdata{$user}[$$idx{fullname}].'</td>
1.3 raeburn 3258: <td>'.$uname.'</td>
3259: <td>'.$udom.'</td>
1.53 raeburn 3260: <td valign="top">
3261: <table>
3262: <tr>
3263: <td><b>'.
3264: &mt('Collaborative Tool').'</b></td>
3265: </tr>
3266: <tr>
3267: <td><b>'.&mt('Fixed').'</b></td>
3268: </tr>
3269: <tr>
3270: <td><b>'.&mt('Optional').'</b></td>
3271: </tr>
3272: </table>
3273: </td>');
1.5 raeburn 3274: foreach my $tool (@{$showtools}) {
3275: if (exists($$usertools{$user}{$tool})) {
1.45 albertel 3276: $r->print('<td valign="top"><table><tr><th colspan="2">'.$tool.'</th></tr>');
1.3 raeburn 3277: my $privcount = 0;
3278: my $fixed = '';
3279: my $dynamic = '';
3280: foreach my $priv (sort(keys(%{$$toolprivs{$tool}}))) {
3281: if (exists($$fixedprivs{$tool}{$priv})) {
1.5 raeburn 3282: $fixed .= '<input type="hidden" name="userpriv_'.$priv.'" value="'.$user.'" />'.$$toolprivs{$tool}{$priv}.' ';
1.3 raeburn 3283: } else {
3284: $privcount ++;
3285: if ($privcount == 3) {
3286: $dynamic .= '</tr><tr>';
3287: }
1.7 raeburn 3288: $dynamic .='<td><nobr><label><input type="checkbox" '.
1.5 raeburn 3289: 'name="userpriv_'.$priv.'" value="'.$user.'"';
3290: if (grep/^\Q$priv\E$/,@{$defprivs}) {
3291: $dynamic .= ' checked="checked" ';
3292: }
3293: $dynamic .= ' />'.$$toolprivs{$tool}{$priv}.
1.7 raeburn 3294: '</label></nobr></td>';
1.3 raeburn 3295: }
3296: }
3297: $r->print('<tr><td colspan="2"><nobr>'.$fixed.'</nobr></td></tr><tr>'.$dynamic.'</tr></table></td>');
3298: } else {
1.45 albertel 3299: $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 3300: }
3301: }
1.45 albertel 3302: $r->print(&Apache::loncommon::end_data_table_row());
1.3 raeburn 3303: }
3304: }
3305:
3306: sub get_dates_from_form {
3307: my $startdate;
3308: my $enddate;
3309: $startdate = &Apache::lonhtmlcommon::get_date_from_form('startdate');
3310: $enddate = &Apache::lonhtmlcommon::get_date_from_form('enddate');
3311: if ( exists ($env{'form.no_end_date'}) ) {
3312: $enddate = 0;
3313: }
3314: return ($startdate,$enddate);
1.5 raeburn 3315: }
3316:
1.3 raeburn 3317: sub date_setting_table {
3318: my ($starttime,$endtime,$formname) = @_;
3319: my $startform = &Apache::lonhtmlcommon::date_setter($formname,
3320: 'startdate',$starttime);
3321: my $endform = &Apache::lonhtmlcommon::date_setter($formname,
3322: 'enddate',$endtime);
1.41 albertel 3323: my $perpetual =
3324: '<nobr><label><input type="checkbox" name="no_end_date" />'.
3325: &mt('None').'</label></nobr>';
1.42 albertel 3326: my $table = "<table class=\"LC_descriptive_input\">\n".
3327: '<tr><td class="LC_description">'.&mt('Start:').'</td>'.
1.3 raeburn 3328: '<td>'.$startform.'</td>'.
1.41 albertel 3329: '<td> </td>'."</tr>\n".
1.42 albertel 3330: '<tr><td class="LC_description">'.&mt('End:').'</td>'.
1.3 raeburn 3331: '<td>'.$endform.'</td>'.
1.41 albertel 3332: '<td>'.$perpetual.'</td>'."</tr>\n".
3333: "</table>\n";
3334: return $table;
1.1 raeburn 3335: }
3336:
1.32 raeburn 3337: sub add_group_folder {
3338: my ($cdom,$cnum,$now,$groupname,$action,$description,$tools,$groupinfo,
3339: $gpterm,$ucgpterm,$crstype) = @_;
3340: if ($cdom eq '' || $cnum eq '') {
3341: return &mt('Error: invalid course domain or number - group folder creation failed');
3342: }
3343: my ($outcome,$allgrpsmap,$grpmap,$boardsmap,$grppage);
3344: my $navmap = Apache::lonnavmaps::navmap->new();
3345: my $crspath = '/uploaded/'.$cdom.'/'.$cnum.'/';
1.47 raeburn 3346: $allgrpsmap = $crspath.'group_allfolders.sequence';
1.32 raeburn 3347: my $topmap = $navmap->getResourceByUrl($allgrpsmap);
3348: undef($navmap);
3349: if ($action eq 'create') {
1.47 raeburn 3350: # check if group_allfolders.sequence exists.
1.32 raeburn 3351: if (!$topmap) {
1.52 raeburn 3352: my $grpstitle = &mt('[_1] [_2]s',$crstype,$ucgpterm);
1.32 raeburn 3353: my $topmap_url = '/'.$env{'course.'.$env{'request.course.id'}.'.url'};
3354: $topmap_url =~ s|/+|/|g;
3355: if ($topmap_url =~ m|^/uploaded|) {
1.47 raeburn 3356: $outcome = &map_updater($cdom,$cnum,'group_allfolders.sequence',
1.32 raeburn 3357: 'toplevelgroup',$grpstitle,$topmap_url);
3358: if ($outcome ne 'ok') {
3359: return $outcome;
3360: }
3361: } else {
1.47 raeburn 3362: $outcome = &mt('Non-standard course - folder for all groups not added.');
1.32 raeburn 3363: return $outcome;
3364: }
3365: }
3366: my $grpfolder = &mt('[_1] Folder -',$ucgpterm,).$description;
1.49 raeburn 3367: $grppage='/adm/'.$cdom.'/'.$cnum.'/'.$groupname.'/smppg';
1.32 raeburn 3368: my $grptitle = &mt('Group homepage').' - '.$description;
1.55 raeburn 3369: my ($discussions,$disctitle);
1.47 raeburn 3370: my $outcome = &map_updater($cdom,$cnum,'group_folder_'.$groupname.'.sequence',
1.32 raeburn 3371: 'grpseq',$grpfolder,$allgrpsmap,$grppage,
3372: $grptitle);
3373: if ($outcome ne 'ok') {
3374: return $outcome;
3375: }
3376: my $pageout = &create_homepage($cdom,$cnum,$groupname,$groupinfo,
3377: $tools,$gpterm,$ucgpterm,$now);
3378: # Link to folder for bulletin boards
1.47 raeburn 3379: $grpmap = $crspath.'group_folder_'.$groupname.'.sequence';
1.32 raeburn 3380: if (grep/^discussion$/,@{$tools}) {
3381: $disctitle = &mt('Discussion Boards');
1.47 raeburn 3382: my $outcome = &map_updater($cdom,$cnum,'group_boards_'.$groupname.
1.32 raeburn 3383: '.sequence','bbseq',$disctitle,$grpmap);
3384: if ($outcome ne 'ok') {
3385: return $outcome;
3386: }
1.47 raeburn 3387: $boardsmap = $crspath.'group_boards_'.$groupname.'.sequence';
1.32 raeburn 3388: }
3389: } else {
3390: #modify group folder if status of discussions tools is changed
3391: }
3392: my ($furl,$ferr)= &Apache::lonuserstate::readmap($cdom.'/'.$cnum);
1.33 raeburn 3393: $navmap = Apache::lonnavmaps::navmap->new();
1.32 raeburn 3394: # modify parameters
3395: my $parm_result;
3396: if ($action eq 'create') {
3397: if ($grpmap) {
3398: $parm_result .= &parm_setter($navmap,$cdom,$grpmap,$groupname);
3399: }
3400: if ($grppage) {
3401: $parm_result .= &parm_setter($navmap,$cdom,$grppage,$groupname);
3402: }
3403: if ($boardsmap) {
3404: $parm_result .= &parm_setter($navmap,$cdom,$boardsmap,$groupname);
3405: }
3406: }
3407: if ($parm_result) {
3408: return $parm_result;
3409: } else {
3410: return 'ok';
3411: }
3412: }
3413:
3414: sub map_updater {
3415: my ($cdom,$cnum,$newfile,$itemname,$itemtitle,$parentmap,$startsrc,
3416: $starttitle,$endsrc,$endtitle) = @_;
3417: my $outcome;
3418: $env{'form.'.$itemname} = &new_map($startsrc,$starttitle,$endsrc,
3419: $endtitle);
3420: my $newmapurl=&Apache::lonnet::finishuserfileupload($cnum,$cdom,$itemname,
3421: $newfile);
3422: if ($newmapurl !~ m|^/uploaded|) {
1.37 raeburn 3423: $outcome = &mt('Error uploading new folder.')." ($newfile): $newmapurl".'<br />';
1.32 raeburn 3424: return $outcome;
3425: }
3426: my ($errtext,$fatal)=&Apache::lonratedt::mapread($parentmap);
3427: if ($fatal) {
1.37 raeburn 3428: $outcome = &mt('Error reading contents of parent folder')." ($parentmap): $errtext".'<br />';
1.32 raeburn 3429: return $outcome;
3430: } else {
3431: my $newidx=&Apache::lonratedt::getresidx($newmapurl);
3432: $Apache::lonratedt::resources[$newidx] = $itemtitle.':'.$newmapurl.
3433: ':false:normal:res';
3434: $Apache::lonratedt::order[1+$#Apache::lonratedt::order]=$newidx;
3435: my ($outtext,$errtext) = &Apache::lonratedt::storemap($parentmap,1);
3436: if ($errtext) {
1.37 raeburn 3437: $outcome = &mt('Error storing updated parent folder')." ($parentmap): $errtext".'<br />';
1.32 raeburn 3438: return $outcome;
3439: }
3440: }
3441: return 'ok';
3442: }
3443:
3444: sub new_map {
3445: my ($startsrc,$starttitle,$endsrc,$endtitle) = @_;
3446: my $newmapstr = '
3447: <map>
3448: <resource id="1" src="'.$startsrc.'" type="start" title="'.$starttitle.'"></resource>
3449: <link from="1" to="2" index="1"></link>
3450: <resource id="2" src="'.$endsrc.'" type="finish" title="'.$endtitle.'"></resource>
3451: </map>
3452: ';
3453: return $newmapstr;
3454: }
3455:
3456: sub parm_setter {
3457: my ($navmap,$cdom,$url,$groupname) = @_;
1.37 raeburn 3458: my $allresults;
1.32 raeburn 3459: my %hide_settings = (
3460: 'course' => {
3461: 'num' => 13,
3462: 'set' => 'yes',
3463: },
3464: 'group' => {
3465: 'num' => 5,
3466: 'set' => 'no',
3467: 'extra' => $groupname,
3468: },
3469: );
3470: my $res = $navmap->getResourceByUrl($url);
3471: my $symb = $res->symb();
3472: foreach my $level (keys(%hide_settings)) {
1.37 raeburn 3473: my $parmresult = &Apache::lonparmset::storeparm_by_symb($symb,
1.32 raeburn 3474: '0_hiddenresource',
3475: $hide_settings{$level}{'num'},
3476: $hide_settings{$level}{'set'},
3477: 'string_yesno',undef,$cdom,
3478: undef,undef,
3479: $hide_settings{$level}{'extra'});
1.37 raeburn 3480: if ($parmresult) {
3481: $allresults .= $level.': '.$parmresult;
3482: }
1.32 raeburn 3483: }
1.37 raeburn 3484: return $allresults;
1.32 raeburn 3485: }
3486:
1.3 raeburn 3487: sub create_homepage {
1.32 raeburn 3488: my ($cdom,$cnum,$name,$groupinfo,$tools,$gpterm,$ucgpterm,$now) = @_;
1.3 raeburn 3489: my $functionality = join(',',@{$tools});
1.24 www 3490: my $content = &unescape($$groupinfo{description});
1.3 raeburn 3491: $content=~s/\s+$//s;
3492: $content=~s/^\s+//s;
3493: $content=~s/\<br\s*\/*\>$//s;
3494: $content=&Apache::lonfeedback::clear_out_html($content,1);
3495:
3496: my %pageinfo = (
1.29 raeburn 3497: 'aaa_title' => "$ucgpterm: $name",
1.3 raeburn 3498: 'abb_links' => $functionality,
3499: 'bbb_content' => $content,
3500: 'ccc_webreferences' => '',
1.32 raeburn 3501: 'uploaded.lastmodified' => $now,
1.3 raeburn 3502: );
3503: my $putresult = &Apache::lonnet::put('grppage_'.$name,\%pageinfo,$cdom,$cnum);
3504: return $putresult;
1.1 raeburn 3505: }
3506:
1.5 raeburn 3507: sub check_uncheck_tools {
3508: my ($r,$available) = @_;
3509: if (ref($available) eq 'ARRAY') {
3510: $r->print('
3511: <script type="text/javascript">
3512: function checkAllTools(formname) {
3513: ');
3514: foreach my $tool (@{$available}) {
3515: $r->print(' checkAll(formname.user_'.$tool.');'."\n");
3516: }
3517: $r->print(' checkAll(formname.togglefunc);'."\n");
3518: $r->print('
3519: }
3520: function uncheckAllTools(formname) {
3521: ');
3522: foreach my $tool (@{$available}) {
3523: $r->print(' uncheckAll(formname.user_'.$tool.');'."\n");
3524: }
3525: $r->print(' uncheckAll(formname.togglefunc);'."\n");
3526: $r->print('
3527: }
3528: function toggleTools(field,caller) {
3529: if (caller.checked) {
3530: checkAll(field);
3531: } else {
3532: uncheckAll(field);
3533: }
3534: return;
3535: }
3536: </script>
3537: ');
3538: }
3539: return;
3540: }
3541:
3542: sub validate_groupname {
1.29 raeburn 3543: my ($groupname,$action,$cdom,$cnum,$gpterm,$ucgpterm,$crstype) = @_;
1.16 albertel 3544: my %sectioncount = &Apache::loncommon::get_sections($cdom,$cnum);
1.17 raeburn 3545: my %curr_groups = &Apache::longroup::coursegroups($cdom,$cnum);
1.15 albertel 3546:
1.5 raeburn 3547: my %lt = &Apache::lonlocal::texthash (
1.29 raeburn 3548: igna => "Invalid $gpterm name",
3549: tgne => "The $gpterm name entered ",
3550: grna => "$ucgpterm names and section names used in a ".
3551: "$crstype must be unique.",
3552: isno => "is not a valid name.",
3553: gnmo => "$ucgpterm names may only contain letters, ".
3554: "numbers or underscores.",
3555: cnnb => "can not be used as it is the name of ",
3556: inth => " in this $crstype",
3557: thgr => "- does not correspond to the name of an ".
3558: "existing $gpterm",
1.5 raeburn 3559: );
1.15 albertel 3560:
1.42 albertel 3561: my $exitmsg = '<span class="LC_error">'.$lt{'igna'}.'</span><br /><br />'.
3562: $lt{'tgne'}.' "'.$groupname.'" ';
1.5 raeburn 3563: my $dupmsg = $lt{'grna'};
3564: my $earlyout;
3565: if (($groupname eq '') || ($groupname =~ /\W/)) {
3566: $earlyout = $exitmsg.$lt{'isno'}.'<br />'.$lt{'gnmo'};
3567: return $earlyout;
3568: }
1.16 albertel 3569: if (exists($sectioncount{$groupname})) {
3570: return $exitmsg.$lt{'cnnb'}.&mt('a section').$lt{'inth'}.
3571: '<br />'.$lt{'grna'};
1.5 raeburn 3572: }
1.15 albertel 3573: if ($action eq 'create'
3574: && exists($curr_groups{$groupname})) {
3575:
1.29 raeburn 3576: return $exitmsg.$lt{'cnnb'}.&mt('an existing [_1]',$gpterm).
1.15 albertel 3577: $lt{'inth'}.'<br />'.$lt{'grna'};
3578:
1.5 raeburn 3579: } elsif ($action eq 'modify') {
3580: unless(exists($curr_groups{$groupname})) {
1.29 raeburn 3581: $earlyout = &mt('[_1] name:',$ucgpterm).' '.$groupname.$lt{'thgr'}.
3582: $lt{'inth'};
1.5 raeburn 3583: return $earlyout;
3584: }
3585: }
3586: return;
3587: }
3588:
3589: sub topic_bar {
1.40 albertel 3590: my ($r,$imgnum,$title) = @_;
1.5 raeburn 3591: $r->print('
1.40 albertel 3592: <div class="LC_topic_bar">
1.45 albertel 3593: <img alt="'.&mt('Step [_1]',$imgnum).
3594: '"src="/res/adm/pages/bl_step'.$imgnum.'.gif" />
3595: <span>'.$title.'</span>
1.40 albertel 3596: </div>
1.5 raeburn 3597: ');
3598: return;
3599: }
3600:
3601: sub check_changes {
3602: my ($member_changes,$memchg) = @_;
3603: my %exclusions;
3604: @{$exclusions{'changefunc'}} = ('expire');
3605: @{$exclusions{'changepriv'}} = ('expire','changefunc');
3606:
3607: foreach my $change (@{$member_changes}) {
1.6 raeburn 3608: if ($change eq 'deletion') {
1.5 raeburn 3609: next;
3610: }
1.6 raeburn 3611: my @checks = ('deletion');
1.5 raeburn 3612: if (exists($exclusions{$change})) {
3613: push(@checks,@{$exclusions{$change}});
3614: }
3615: my @temp = ();
3616: foreach my $item (@{$$memchg{$change}}) {
3617: my $match = 0;
3618: foreach my $check (@checks) {
1.6 raeburn 3619: if (defined($$memchg{$check})) {
3620: if (ref(@{$$memchg{$check}}) eq 'ARRAY') {
3621: if (@{$$memchg{$check}} > 0) {
3622: if (grep/^$item$/,@{$$memchg{$check}}) {
3623: $match = 1;
3624: last;
3625: }
3626: }
1.5 raeburn 3627: }
3628: }
3629: }
3630: if ($match) {
3631: next;
3632: }
3633: push(@temp,$item);
3634: }
3635: @{$$memchg{$change}} = @temp;
3636: }
3637: }
1.3 raeburn 3638:
1.1 raeburn 3639: 1;
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>