Annotation of loncom/interface/loncoursegroups.pm, revision 1.58
1.24 www 1: # The LearningOnline Network with CAPA
2: #
1.58 ! raeburn 3: # $Id: loncoursegroups.pm,v 1.57 2006/07/21 02:51:31 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.46 albertel 1030: &add_members_form($r,$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.40 albertel 1197: &membership_options($r,$action,$formname,$sectioncount,3,$gpterm,
1198: $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.40 albertel 1346: my ($r,$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.34 albertel 1368: #FIXME need to plumb around for the various cr roles defined by the user
1369: my @roles = ('st','cc','in','ta','ep');
1.5 raeburn 1370:
1371: my @sections = keys(%{$sectioncount});
1372:
1.40 albertel 1373: &topic_bar($r,$image,$lt{'pipa'});
1.5 raeburn 1374: $r->print('
1.40 albertel 1375: <b>'.$lt{'gmem'}.'</b><br />'.$lt{'picr'});
1.5 raeburn 1376: if ($action eq 'create') {
1.21 raeburn 1377: $r->print($lt{'meof'}.'<br />'.$lt{'ifno'}.'<br />'.$lt{'asub'});
1.5 raeburn 1378: } else {
1.6 raeburn 1379: $r->print($lt{'admg'});
1.5 raeburn 1380: }
1381: $r->print('
1382: <br />
1383: <br />
1.40 albertel 1384: <table class="LC_status_selector">
1.3 raeburn 1385: <tr>
1.40 albertel 1386: <th>'.$lt{'acty'}.'</th>
1.53 raeburn 1387: <th>'.$lt{'coro'}.'</th>
1388: <th>'.$lt{'cose'}.'</th>
1389: </tr><tr><td>');
1.3 raeburn 1390: $r->print(&Apache::lonhtmlcommon::status_select_row(\%status_types));
1.40 albertel 1391: $r->print('</td><td>');
1.3 raeburn 1392: $r->print(&Apache::lonhtmlcommon::role_select_row(\@roles));
1393: if (@sections > 0) {
1.5 raeburn 1394: @sections = sort {$a cmp $b} @sections;
1.31 albertel 1395: unshift(@sections,'none'); # Put 'no sections' next
1.17 raeburn 1396: unshift(@sections,'all'); # Put 'all' at the front of the list
1.53 raeburn 1397: } else {
1398: @sections = ('all','none');
1.3 raeburn 1399: }
1.53 raeburn 1400: $r->print('</td><td>'.
1401: §ions_selection(\@sections,'sectionpick').'</td>
1.3 raeburn 1402: </tr>
1.40 albertel 1403: </table>');
1.5 raeburn 1404: return;
1405: }
1406:
1407: sub sections_selection {
1408: my ($sections,$elementname) = @_;
1409: my $section_sel;
1410: my $numvisible = 4;
1411: if (@{$sections} < 4) {
1412: $numvisible = @{$sections};
1413: }
1414: foreach my $sec (@{$sections}) {
1.17 raeburn 1415: if ($sec eq 'all') {
1.53 raeburn 1416: $section_sel .= ' <option value="'.$sec.'">'.&mt('all sections').'</option>'."\n";
1.17 raeburn 1417: } elsif ($sec eq 'none') {
1.31 albertel 1418: $section_sel .= ' <option value="'.$sec.'">'.&mt('no section').'</option>'."\n";
1.5 raeburn 1419: } else {
1.31 albertel 1420: $section_sel .= ' <option value="'.$sec.'">'.$sec."</option>\n";
1.5 raeburn 1421: }
1422: }
1423: my $output = '
1424: <select name="'.$elementname.'" multiple="true" size="'.$numvisible.'">
1425: '.$section_sel.'
1426: </select>';
1427: return $output;
1428: }
1429:
1430: sub access_date_settings {
1.41 albertel 1431: my ($r,$action,$formname,$stored,$image,$gpterm,$ucgpterm) = @_;
1.5 raeburn 1432: my %lt = &Apache::lonlocal::texthash(
1.29 raeburn 1433: 'sten' => "Default start and end dates for $gpterm access",
1.5 raeburn 1434: );
1435: my $starttime = time;
1436: my $endtime = time+(6*30*24*60*60); # 6 months from now, approx
1437: if ($action eq 'modify') {
1438: $starttime = $$stored{'startdate'};
1439: unless ($$stored{'enddate'} == 0) {
1440: $endtime = $$stored{'enddate'};
1441: }
1442: }
1.41 albertel 1443: my ($table) = &date_setting_table($starttime,$endtime,$formname);
1.40 albertel 1444: &topic_bar($r,$image,$lt{'sten'});
1.5 raeburn 1445: $r->print('
1.41 albertel 1446: '.$table.'
1447: ');
1.3 raeburn 1448: return;
1449: }
1450:
1.5 raeburn 1451: sub choose_members_form {
1.46 albertel 1452: my ($r,$cdom,$cnum,$action,$formname,$page,$groupname,$description,
1.29 raeburn 1453: $granularity,$quota,$startdate,$enddate,$tools,$fixedprivs,$toolprivs,
1.5 raeburn 1454: $functions,$users,$userdata,$idx,$stored,$states,$navbuttons,
1.46 albertel 1455: $gpterm,$ucgpterm,$crstype) = @_;
1.5 raeburn 1456: my @regexps = ('user_','userpriv_','sec_');
1457: my %origmembers;
1.3 raeburn 1458: $r->print(&Apache::lonhtmlcommon::echo_form_input(
1.5 raeburn 1459: ['origin','action','state','page','member','specificity','branch',
1.7 raeburn 1460: 'defpriv','autorole','autoadd','autodrop','sortby','togglefunc'],
1.5 raeburn 1461: \@regexps));
1.29 raeburn 1462: my $earlyout = &validate_groupname($groupname,$action,$cdom,$cnum,$gpterm,
1463: $ucgpterm,$crstype);
1.5 raeburn 1464: if ($earlyout) {
1.47 raeburn 1465: $r->print($earlyout);
1.5 raeburn 1466: &display_navbuttons($r,$formname,$$states{$action}[$page-1],
1467: $$navbuttons{'gtps'});
1.3 raeburn 1468: return;
1.5 raeburn 1469: }
1470: my ($specimg,$memimg);
1471: my @available = ();
1472: my @unavailable = ();
1473: &check_tools($functions,$tools,\@available,\@unavailable);
1474: if ($action eq 'create') {
1.40 albertel 1475: &print_current_settings($r,$action,$functions,$startdate,$enddate,
1476: $groupname,$description,$granularity,$quota,
1477: \@available,\@unavailable,$gpterm,$ucgpterm);
1.5 raeburn 1478: $specimg = 4;
1479: $memimg = 5;
1480: } else {
1481: $specimg = 2;
1482: $memimg = 3;
1483: my %membership = &Apache::lonnet::get_group_membership($cdom,$cnum,
1484: $groupname);
1485: foreach my $key (sort(keys(%membership))) {
1486: if ($key =~ /^\Q$groupname\E:([^:]+):([^:]+)$/) {
1.6 raeburn 1487: my ($end,$start,@userprivs) = split(/:/,$membership{$key});
1488: unless ($start == -1) {
1489: my $uname = $1;
1490: my $udom = $2;
1491: my $user = $uname.':'.$udom;
1492: $origmembers{$user} = 1;
1493: }
1.5 raeburn 1494: }
1495: }
1496: }
1.46 albertel 1497: &privilege_specificity($r,$action,$specimg,$tools,$stored,$toolprivs,
1.29 raeburn 1498: $fixedprivs,\@available,$formname,$gpterm,$ucgpterm);
1.44 albertel 1499: my $newusers = &pick_new_members($r,$action,$formname,\@available,$idx,
1500: $stored,$memimg,$users,$userdata,
1501: $granularity,\%origmembers,$gpterm,
1502: $ucgpterm);
1.5 raeburn 1503: if ($newusers || $action eq 'create') {
1504: &display_navbuttons($r,$formname,$$states{$action}[$page-1],
1505: $$navbuttons{'gtps'},$$states{$action}[$page+1],
1506: $$navbuttons{'gtns'});
1507: } else {
1508: &display_navbuttons($r,$formname,$$states{$action}[$page-1],
1509: $$navbuttons{'gtps'});
1.3 raeburn 1510: }
1.5 raeburn 1511: return;
1512: }
1513:
1514: sub display_navbuttons {
1515: my ($r,$formname,$prev,$prevtext,$next,$nexttext) = @_;
1.42 albertel 1516: $r->print('<div class="LC_navbuttons">');
1.5 raeburn 1517: if ($prev) {
1518: $r->print('
1519: <input type="button" name="previous" value = "'.$prevtext.'"
1520: onclick="javascript:backPage(document.'.$formname.','."'".$prev."'".')"/>
1521: ');
1522: }
1523: if ($next) {
1524: $r->print('
1525: <input type="button" name="next" value="'.$nexttext.'"
1526: onclick="javascript:nextPage(document.'.$formname.','."'".$next."'".')" />');
1527: }
1.42 albertel 1528: $r->print('</div>');
1.5 raeburn 1529: }
1530:
1531: sub check_tools {
1532: my ($functions,$tools,$available,$unavailable) = @_;
1533: foreach my $item (sort(keys(%{$functions}))) {
1534: if (grep/^$item$/,@{$tools}) {
1535: push(@{$available},$item);
1536: } else {
1537: push(@{$unavailable},$item);
1538: }
1539: }
1540: return;
1541: }
1542:
1543: sub print_current_settings {
1.40 albertel 1544: my ($r,$action,$functions,$startdate,$enddate,$groupname,$description,
1545: $granularity,$quota,$available,$unavailable,$gpterm,$ucgpterm) = @_;
1.5 raeburn 1546:
1547: my %lt = &Apache::lonlocal::texthash(
1.53 raeburn 1548: grna => 'Group Name',
1549: desc => 'Group Title',
1550: grfn => "Collaborative Tools",
1.5 raeburn 1551: gran => 'Granularity',
1.29 raeburn 1552: quot => 'File quota',
1.5 raeburn 1553: dfac => 'Default access dates',
1.53 raeburn 1554: ygrs => "Your group selections - ",
1555: tfwa => "The following settings will apply to the group:",
1556: difn => 'Different collaborative tools<br />for different members:',
1.5 raeburn 1557: stda => 'Start date',
1558: enda => 'End date:',
1559: );
1.3 raeburn 1560: my $showstart = &Apache::lonlocal::locallocaltime($startdate);
1.5 raeburn 1561: my $showend;
1562: if ($enddate == 0) {
1563: $showend = &mt('No end date set');
1564: } else {
1565: $showend = &Apache::lonlocal::locallocaltime($enddate);
1566: }
1567: if ($action eq 'create') {
1568: $r->print('
1.42 albertel 1569: <div><span style="font-size: larger">'.$lt{'ygrs'}.'</span>
1.5 raeburn 1570: <br />'.$lt{'tfwa'}.'
1.40 albertel 1571: </div>');
1.5 raeburn 1572: }
1.40 albertel 1573: $r->print(&Apache::loncommon::start_data_table('LC_course_group_status').
1574: &Apache::loncommon::start_data_table_header_row());
1575: $r->print('
1576: <th>'.$lt{'grna'}.'</th>
1577: <th>'.$lt{'desc'}.'</th>
1578: <th>'.$lt{'grfn'}.'</th>
1579: <th>'.$lt{'gran'}.'</th>
1580: <th>'.$lt{'quot'}.'</th>
1581: <th>'.$lt{'dfac'}.'</th>
1582: ');
1583: $r->print(&Apache::loncommon::end_data_table_header_row().
1584: &Apache::loncommon::start_data_table_row('LC_data_table_dense'));
1.3 raeburn 1585: $r->print('
1.40 albertel 1586: <td valign="top">'.$groupname.'</td>
1587: <td valign="top">'.$description.'</td>
1.3 raeburn 1588: <td>
1589: ');
1.5 raeburn 1590: if (@{$available} > 0) {
1.53 raeburn 1591: $r->print(&mt('<b>Available for assignment to members:</b>').
1592: '<table class="LC_group_priv"><tr>');
1.5 raeburn 1593: my $rowcell = int(@{$available}/2) + @{$available}%2;
1594: for (my $i=0; $i<@{$available}; $i++) {
1595: if (@{$available} > 3) {
1.3 raeburn 1596: if ($i==$rowcell) {
1597: $r->print('</tr><tr>');
1598: }
1599: }
1.40 albertel 1600: $r->print('<td>'.$$functions{$$available[$i]}.
1601: '</td><td> </td>');
1.3 raeburn 1602: }
1.5 raeburn 1603: if ((@{$available} > 3) && (@{$available}%2)) {
1.3 raeburn 1604: $r->print('<td> </td><td> </td>');
1605: }
1606: $r->print('</tr></table><br />');
1607: }
1.5 raeburn 1608: if (@{$unavailable} > 0) {
1.53 raeburn 1609: $r->print(&mt('<b>Unavailable for assignment:</b>').
1610: '<table class="LC_group_priv"><tr>');
1.5 raeburn 1611: my $rowcell = int(@{$unavailable}/2) + @{$unavailable}%2;
1612: for (my $j=0; $j<@{$unavailable}; $j++) {
1613: if (@{$unavailable} > 3) {
1.3 raeburn 1614: if ($j==$rowcell) {
1615: $r->print('</tr><tr>');
1616: }
1617: }
1.40 albertel 1618: $r->print('<td>'.$$functions{$$unavailable[$j]}.
1619: '</td><td> </td>');
1.3 raeburn 1620: }
1.5 raeburn 1621: if ((@{$unavailable} > 3) && (@{$unavailable}%2)) {
1.3 raeburn 1622: $r->print('<td> </td><td> </td>');
1623: }
1624: $r->print('</tr></table>');
1625: }
1626: $r->print(<<"END");
1627: </td>
1.40 albertel 1628: <td valign="top"><b>$lt{'difn'}</b> $granularity</td>
1629: <td valign="top">$quota Mb</td>
1630: <td valign="top"><b>$lt{'stda'}</b> $showstart<br />
1631: <b>$lt{'enda'}</b> $showend
1.3 raeburn 1632: </td>
1633: END
1.40 albertel 1634: $r->print(&Apache::loncommon::end_data_table_row().
1635: &Apache::loncommon::end_data_table());
1.5 raeburn 1636: return;
1637: }
1638:
1639: sub pick_new_members {
1.44 albertel 1640: my ($r,$action,$formname,$available,$idx,$stored,$img,$users,$userdata,
1641: $granularity,$origmembers,$gpterm,$ucgpterm) = @_;
1.5 raeburn 1642: my %lt = &Apache::lonlocal::texthash(
1.53 raeburn 1643: 'gpme' => "Group membership",
1.5 raeburn 1644: 'addm' => 'Add members',
1.53 raeburn 1645: 'setf' => 'Assign collaborative tools',
1646: 'func' => 'Tools',
1647: 'nome' => 'No members to add at this time, as there are no users '.
1648: 'matching the specified type(s), role(s) and section(s).',
1.29 raeburn 1649: 'nnew' => "There are no users to add as new members, as all users".
1.53 raeburn 1650: " matching the specified type(s), role(s), and ".
1651: "section(s) are already affiliated with this group.",
1.5 raeburn 1652: 'yoma' => 'You may need to use the '."'".'modify existing, past or '.
1653: 'future members'."'".' page if you need to re-enable '.
1654: 'or activate access for previous or future members.',
1655: );
1656: my %members;
1657: my $totalusers = 0;
1658: my $newusers = 0;
1.3 raeburn 1659: foreach my $role (keys(%{$users})) {
1660: foreach my $user (keys(%{$$users{$role}})) {
1.5 raeburn 1661: $totalusers ++;
1662: if (ref($origmembers) eq 'HASH') {
1663: if (exists($$origmembers{$user})) {
1664: next;
1665: }
1666: }
1.3 raeburn 1667: unless (defined($members{$user})) {
1668: @{$members{$user}} = @{$$userdata{$user}};
1.5 raeburn 1669: $newusers ++;
1.3 raeburn 1670: }
1671: }
1672: }
1673: if (keys(%members) > 0) {
1.5 raeburn 1674: if (@{$available} > 0 && $granularity eq 'Yes') {
1675: $r->print(&check_uncheck_tools($r,$available));
1676: }
1677: }
1.40 albertel 1678: &topic_bar($r,$img,$lt{'gpme'});
1.5 raeburn 1679: if (keys(%members) > 0) {
1680: $r->print('
1.3 raeburn 1681: <table>
1.5 raeburn 1682: <tr>');
1683: &check_uncheck_buttons($r,$formname,'member',$lt{'addm'});
1684: if (@{$available} > 0 && $granularity eq 'Yes') {
1.48 albertel 1685: $r->print('<td>
1.5 raeburn 1686: <fieldset><legend><b>'.$lt{'setf'}.'</b></legend>
1.48 albertel 1687: <nobr>
1.5 raeburn 1688: <input type="button" value="check all"
1689: onclick="javascript:checkAllTools(document.'.$formname.')" />
1690:
1691: <input type="button" value="uncheck all"
1.3 raeburn 1692: onclick="javascript:uncheckAllTools(document.'.$formname.')" />
1.48 albertel 1693: </nobr>
1694: </fieldset></td>');
1.3 raeburn 1695: }
1696: $r->print('</tr></table>
1697: ');
1.43 albertel 1698: $r->print(&Apache::loncommon::start_data_table().
1699: &Apache::loncommon::start_data_table_header_row());
1.5 raeburn 1700: $r->print('
1.43 albertel 1701: <th>'.&mt('Add?').'</b></td>
1702: <th><a href="javascript:changeSort('."'fullname'".')">'.&mt('Name').'</a></td>
1703: <th><a href="javascript:changeSort('."'username'".')">'.&mt('Username').'</a></td>
1704: <th><a href="javascript:changeSort('."'domain'".')">'.&mt('Domain').'</a></td>
1705: <th><a href="javascript:changeSort('."'id'".')">'.&mt('ID').'</a></td>
1706: <th><a href="javascript:changeSort('."'section'".')">'.&mt('Section').'</a></td>
1.5 raeburn 1707: ');
1708: if (@{$available} > 0) {
1.43 albertel 1709: $r->print('<th>'.$lt{'func'}.'</th>');
1.3 raeburn 1710: }
1.43 albertel 1711: $r->print(&Apache::loncommon::end_data_table_header_row());
1.5 raeburn 1712: if (@{$available} > 0) {
1713: if ($granularity eq 'Yes') {
1.43 albertel 1714: $r->print(&Apache::loncommon::start_data_table_row('LC_data_table_dense LC_data_table_highlight').'
1.35 raeburn 1715: <td colspan="6"> </td>
1.43 albertel 1716: <td align="center"><nobr><b>'.&mt('All:').'</b> ');
1.5 raeburn 1717: foreach my $tool (@{$available}) {
1.7 raeburn 1718: $r->print('<label><input type="checkbox" name="togglefunc" '.
1719: 'onclick="javascript:toggleTools(document.'.$formname.'.user_'.$tool.',this);"'.
1720: ' value="'.$tool.'">'.'<b>'.$tool.'</b></label> ');
1.5 raeburn 1721: }
1.43 albertel 1722: $r->print('</nobr></td></tr>');
1.5 raeburn 1723: }
1724: }
1.3 raeburn 1725: my %Sortby = ();
1726: foreach my $user (sort(keys(%members))) {
1727: if ($env{'form.sortby'} eq 'fullname') {
1728: push(@{$Sortby{$members{$user}[$$idx{fullname}]}},$user);
1729: } elsif ($env{'form.sortby'} eq 'username') {
1730: push(@{$Sortby{$members{$user}[$$idx{uname}]}},$user);
1731: } elsif ($env{'form.sortby'} eq 'domain') {
1732: push(@{$Sortby{$members{$user}[$$idx{udom}]}},$user);
1733: } elsif ($env{'form.sortby'} eq 'id') {
1734: push(@{$Sortby{$members{$user}[$$idx{id}]}},$user);
1.31 albertel 1735: } elsif ($env{'form.sortby'} eq 'section') {
1736: push(@{$Sortby{$members{$user}[$$idx{section}]}},$user);
1.3 raeburn 1737: } else {
1738: push(@{$Sortby{$members{$user}[$$idx{fullname}]}},$user);
1739: }
1740: }
1741: foreach my $key (sort(keys(%Sortby))) {
1742: foreach my $user (@{$Sortby{$key}}) {
1743: my $id = $members{$user}[$$idx{id}];
1744: my $fullname = $members{$user}[$$idx{fullname}];
1745: my $udom = $members{$user}[$$idx{udom}];
1746: my $uname = $members{$user}[$$idx{uname}];
1.31 albertel 1747: my $section = $members{$user}[$$idx{section}];
1.43 albertel 1748: $r->print(&Apache::loncommon::start_data_table_row('LC_data_table_dense').
1749: '<td align="right"><input type="checkbox" name="member" value="'.$user.'" /></td>'.
1750: '<td>'.$fullname.'</td>'.
1751: '<td>'.$uname.'</td>'.
1752: '<td>'.$udom.'</td>'.
1753: '<td>'.$id.'</td>'.
1754: '<td>'.$section.'</td>');
1.5 raeburn 1755: if (@{$available} > 0) {
1.43 albertel 1756: $r->print('<td align="center"><nobr>'.
1.5 raeburn 1757: ' ');
1758: foreach my $tool (@{$available}) {
1759: if ($granularity eq 'Yes') {
1.3 raeburn 1760: $r->print('<input type="checkbox" name="user_'.
1761: $tool.'" value="'.$user.'" />'.$tool.' ');
1762: } else {
1763: $r->print('<input type="hidden" name="user_'.
1764: $tool.'" value="'.$user.'" />'.$tool.' ');
1765: }
1766: }
1.43 albertel 1767: $r->print('</nobr></td>');
1.3 raeburn 1768: }
1.43 albertel 1769: $r->print(&Apache::loncommon::end_data_table_row()."\n");
1.3 raeburn 1770: }
1771: }
1.43 albertel 1772: $r->print(&Apache::loncommon::end_data_table());
1.5 raeburn 1773: } else {
1774: if ($totalusers > 0) {
1775: $r->print($lt{'nnew'}.'<br /><br />'.$lt{'yoma'});
1776: } else {
1777: $r->print($lt{'nome'});
1778: }
1779: }
1780: return $newusers;
1781: }
1782:
1783: sub privilege_specificity {
1.46 albertel 1784: my ($r,$action,$img,$tools,$stored,$toolprivs,$fixedprivs,$available,
1785: $formname,$gpterm,$ucgpterm) = @_;
1.5 raeburn 1786: my %lt = &Apache::lonlocal::texthash (
1.53 raeburn 1787: 'uprv' => 'User privileges for collaborative tools',
1788: 'frty' => 'For each collaborative tool you have chosen to include, '.
1789: 'there is a set of core privileges which all group members '.
1790: 'assigned use of the tool will receive.',
1791: 'thar' => 'For some tools there are also additional optional '.
1792: 'privileges which can be set.',
1793: 'plch' => 'Choose one of the following:',
1794: 'fort' => 'For the collaborative tools you have chosen to include '.
1795: 'only core privileges are available, '.
1796: 'so there are no optional privileges to assign.',
1797: 'eaty' => 'Each collaborative tool includes core '.
1798: 'privileges assigned to all members with access to the '.
1799: 'tool. Some tools may also feature additional privileges '.
1.5 raeburn 1800: 'which can be set for specific members.',
1.53 raeburn 1801: 'cutg' => 'Currently the group is configured ',
1802: 'sdif' => 'so different members can receive different optional privileges for a particular tool.',
1803: 'sall' => 'so all members will receive the same optional privileges for a particular tool.',
1804: 'algm' => 'All group members will receive the same privileges for any tool assigned to them, including the default set of optional privileges.',
1805: 'smgp' => 'Different group members may receive different privileges from '.
1806: 'others for the tools they have been assigned.',
1807: 'thwi' => 'These will be the privileges all group members receive for a particular assigned tool, '.
1808: 'if you selected the first option above.',
1.29 raeburn 1809: 'thes' => "These will be the privileges given to members assigned ".
1.53 raeburn 1810: "in the future via automatic group assignment ".
1811: "for users who receive specific sections/roles in the course ",
1812: 'asyo' => "As you have chosen not to include any collaborative tools ".
1813: "in the group, no default optional privileges need to be set.",
1814: 'plin' => 'Indicate which <b>optional</b> privileges members '.
1815: 'will receive by default for a specific tool.',
1.5 raeburn 1816: 'oppr' => 'Optional privileges',
1817: 'defp' => 'The default privileges new members will receive are:',
1818: );
1819: my $totaloptionalprivs = 0;
1820: foreach my $tool (@{$tools}) {
1821: foreach my $priv (sort(keys(%{$$toolprivs{$tool}}))) {
1822: if (!exists($$fixedprivs{$tool}{$priv})) {
1823: $totaloptionalprivs ++;
1824: }
1825: }
1826: }
1.40 albertel 1827: &topic_bar($r,$img,$lt{'uprv'});
1.5 raeburn 1828: if ((($action eq 'create') && (@{$available} > 0)) ||
1.55 raeburn 1829: (($action eq 'modify') && ($formname eq 'change_settings'))) {
1.5 raeburn 1830: my %specific = (
1831: 'No' => 'checked="checked"',
1832: 'Yes' => '',
1833: );
1834: if ($action eq 'create') {
1835: $r->print($lt{'frty'}.'<br />');
1836: if ($totaloptionalprivs) {
1.53 raeburn 1837: $r->print($lt{'thar'}.'<br /><br />'.$lt{'plch'});
1.5 raeburn 1838: } else {
1839: $r->print($lt{'fort'});
1840: }
1841: } else {
1842: $r->print($lt{'eaty'}.' '.$lt{cutg});
1843: if ($$stored{'specificity'} eq 'Yes') {
1844: $r->print($lt{'sdif'});
1845: $specific{'Yes'} = $specific{'No'};
1846: $specific{'No'} = '';
1847: } else {
1848: $r->print($lt{'sall'});
1849: }
1850: }
1851: if ($totaloptionalprivs) {
1852: $r->print('
1.53 raeburn 1853: <br />
1.40 albertel 1854: <label><nobr><input type="radio" name="specificity" value="No" '.$specific{'No'}.' /> '.$lt{'algm'}.'</nobr></label><br />
1.53 raeburn 1855: <label><nobr><input type="radio" name="specificity" value="Yes" '.$specific{'Yes'}.' /> '.$lt{'smgp'}.'</nobr></label><br /><br />');
1.5 raeburn 1856: } else {
1857: $r->print('<input type="hidden" name="specificity" value="No" />');
1858: }
1859: if ($totaloptionalprivs) {
1.40 albertel 1860: $r->print($lt{'plin'});
1.5 raeburn 1861: if ($action eq 'create') {
1.53 raeburn 1862: $r->print('<br />'.$lt{'thwi'});
1.5 raeburn 1863: }
1864: $r->print('<br />'.$lt{'thes'});
1865: if ($action eq 'create') {
1866: $r->print('('.&mt('if enabled on the next page').').');
1867: } else {
1868: $r->print('('.&mt('if enabled below').').');
1869: }
1870: $r->print('<br /><br />
1.40 albertel 1871: <table><tr>');
1.5 raeburn 1872: &check_uncheck_buttons($r,$formname,'defpriv',$lt{'oppr'});
1873: $r->print('
1874: </tr>
1875: </table>
1.3 raeburn 1876: <br />
1877: ');
1.5 raeburn 1878: } else {
1.40 albertel 1879: $r->print($lt{'algm'}.'<br /><br />');
1.3 raeburn 1880: }
1.42 albertel 1881: &default_privileges($r,$action,$tools,$toolprivs,$fixedprivs,
1882: $available);
1.3 raeburn 1883: } else {
1.5 raeburn 1884: if ($action eq 'create') {
1885: $r->print($lt{'asyo'});
1.55 raeburn 1886: $r->print('<input type="hidden" name="specificity" value="No" />');
1.5 raeburn 1887: } elsif ($action eq 'modify' && $formname eq 'pick_members') {
1888: my @defprivs;
1889: if (ref($$stored{'defpriv'}) eq 'ARRAY') {
1890: @defprivs = @{$$stored{'defpriv'}};
1891: }
1892: $r->print($lt{'eaty'}.' '.$lt{cutg});
1893: if ($$stored{'specificity'} eq 'Yes') {
1894: $r->print($lt{'sdif'});
1895: } else {
1896: $r->print($lt{'sall'});
1897: }
1898: $r->print(' '.$lt{'defp'}.'<br /><br />');
1.45 albertel 1899: &display_defprivs($r,$tools,$toolprivs,\@defprivs);
1.5 raeburn 1900: }
1.3 raeburn 1901: }
1902: return;
1903: }
1904:
1.5 raeburn 1905: sub default_privileges {
1.42 albertel 1906: my ($r,$action,$tools,$toolprivs,$fixedprivs,$available) = @_;
1.5 raeburn 1907: my %lt = &Apache::lonlocal::texthash(
1908: 'addp' => 'Additional privileges',
1909: 'fixp' => 'Fixed privileges',
1910: 'oppr' => 'Optional privileges',
1.53 raeburn 1911: 'func' => 'Collaborative Tool',
1.5 raeburn 1912: );
1.42 albertel 1913: $r->print(&Apache::lonhtmlcommon::start_pick_box('LC_group_priv_box').
1914: &Apache::lonhtmlcommon::row_title($lt{'func'},undef,
1915: 'LC_groups_functionality'));
1916: $r->print(join('</td><td class="LC_groups_functionality">',@{$tools}));
1917: $r->print(&Apache::lonhtmlcommon::row_closure(1));
1918: my $fixed = '';
1919: my $dynamic = '';
1.3 raeburn 1920: foreach my $tool (@{$tools}) {
1.5 raeburn 1921: my $privcount = 0;
1.42 albertel 1922: if ($dynamic ne '') {
1923: $dynamic .= '</td><td class="LC_groups_optional">';
1924: }
1925: $dynamic .= '<table class="LC_group_priv"><tr>';
1.5 raeburn 1926: foreach my $priv (sort(keys(%{$$toolprivs{$tool}}))) {
1927: if (exists($$fixedprivs{$tool}{$priv})) {
1.42 albertel 1928: if ($fixed ne '') {
1929: $fixed .= '</td><td class="LC_groups_fixed">';
1930: }
1.53 raeburn 1931: $fixed .= '<input type="hidden" name="defpriv" value="'.$priv.'" /><nobr>'.$$toolprivs{$tool}{$priv}.' ';
1.5 raeburn 1932: if ($action eq 'modify') {
1.42 albertel 1933: if (grep(/^$tool$/,@{$available})) {
1.5 raeburn 1934: $fixed .= '<small>'.&mt('(on)').'<small> ';
1935: } else {
1936: $fixed .= '<small>'.&mt('(off)').'<small> ';
1.3 raeburn 1937: }
1938: }
1.53 raeburn 1939: $fixed .= '</nobr>';
1.5 raeburn 1940: } else {
1.42 albertel 1941: $privcount++;
1.5 raeburn 1942: if ($privcount == 3) {
1943: $dynamic .= '</tr>
1.42 albertel 1944: <tr>'."\n";
1.5 raeburn 1945: }
1.53 raeburn 1946: $dynamic .= '<td><nobr><label><input type="checkbox" name="defpriv" value="'.$priv.'" />'.$$toolprivs{$tool}{$priv}.'</label></nobr></td>'."\n";
1.3 raeburn 1947: }
1948: }
1.42 albertel 1949: if ($privcount == 0) {
1950: $dynamic .= '<td>None</td>'."\n";
1.5 raeburn 1951: }
1952: if ($privcount < 3) {
1.53 raeburn 1953: $dynamic .= '<td> </td>'."\n";
1.5 raeburn 1954: } elsif ($privcount%2) {
1955: $dynamic = '<td> </td>'."\n";
1956: }
1.42 albertel 1957: $dynamic .= '</tr></table>';
1.3 raeburn 1958: }
1.42 albertel 1959: $r->print(&Apache::lonhtmlcommon::row_title($lt{'fixp'},undef,
1960: 'LC_groups_fixed').
1961: $fixed.
1962: &Apache::lonhtmlcommon::row_closure(1));
1963: $r->print(&Apache::lonhtmlcommon::row_title($lt{'oppr'},undef,
1964: 'LC_groups_optional').
1965: $dynamic.
1966: &Apache::lonhtmlcommon::end_pick_box());
1.5 raeburn 1967: $r->print('<br />');
1968: return;
1.42 albertel 1969:
1.5 raeburn 1970: }
1971:
1972: sub display_defprivs {
1.45 albertel 1973: my ($r,$tools,$toolprivs,$defprivs) = @_;
1974: my $function = &Apache::loncommon::get_users_function();
1975: my $tabcol = &Apache::loncommon::designparm($function.'.tabbg');
1976: my $rowColor1 = "#dddddd";
1977: my $rowColor2 = "#eeeeee";
1.5 raeburn 1978: my %lt = &Apache::lonlocal::texthash(
1979: 'priv' => 'Privileges',
1.53 raeburn 1980: 'func' => 'Collaborative Tool',
1.5 raeburn 1981: );
1982: $r->print(&Apache::lonhtmlcommon::start_pick_box());
1983: $r->print('<tr>');
1984: my $numrows = 0;
1985: my %currprivs;
1986: foreach my $tool (@{$tools}) {
1987: @{$currprivs{$tool}} = ();
1988: foreach my $priv (sort(keys(%{$$toolprivs{$tool}}))) {
1989: if (ref($defprivs) eq 'ARRAY') {
1.45 albertel 1990: if (grep(/^\Q$priv\E$/,@{$defprivs})) {
1.5 raeburn 1991: push(@{$currprivs{$tool}},$priv);
1992: }
1.3 raeburn 1993: }
1994: }
1.5 raeburn 1995: my $rowcount = int(@{$currprivs{$tool}}/3);
1996: if (@{$currprivs{$tool}}%3 > 0) {
1997: $rowcount ++;
1998: }
1999: if ($rowcount > $numrows) {
2000: $numrows = $rowcount;
2001: }
2002: }
2003: my @rowCols = ($rowColor1,$rowColor2);
2004: foreach my $tool (@{$tools}) {
2005: $r->print('<td align="center" valign="top">
2006: <table cellspacing="0" cellpadding="5">
2007: <tr bgcolor="#cccccc">
2008: <td colspan="3" align="center"><b>'.$tool.'</b></td>
2009: </tr>
2010: ');
2011: my $rownum = 1;
2012: my $privcount = 0;
2013: $r->print('<tr bgcolor="'.$rowColor1.'">');
2014: foreach my $priv (@{$currprivs{$tool}}) {
2015: $privcount ++;
2016: if ($privcount%4 == 0) {
2017: $rownum ++;
2018: my $bgcol = $rownum%2;
2019: $r->print('</tr>
2020: <tr bgcolor="'.$rowCols[$bgcol].'">'."\n");
2021: }
2022: $r->print('<td>'.$$toolprivs{$tool}{$priv}.'</td>'."\n");
2023: }
2024: if ($privcount%3 > 0) {
2025: my $emptycells = 3-($privcount%3);
2026: while($emptycells > 0) {
2027: $r->print('<td> </td>'."\n");
2028: $emptycells --;
2029: }
2030: }
2031: while ($rownum < $numrows) {
2032: $rownum ++;
2033: my $bgcol = $rownum%2;
2034: $r->print('<tr bgcolor="'.$rowCols[$bgcol].'"><td colspan="3"> </td></tr>');
1.3 raeburn 2035: }
1.5 raeburn 2036: $r->print('</table>'."\n".'</td>');
2037: }
2038: $r->print('</tr>'."\n");
2039: $r->print(&Apache::lonhtmlcommon::end_pick_box());
2040: $r->print('<br />');
2041: return;
1.3 raeburn 2042: }
1.5 raeburn 2043:
2044:
2045: sub change_members_form {
1.48 albertel 2046: my ($r,$cdom,$cnum,$action,$formname,$page,$groupname,$description,
1.5 raeburn 2047: $startdate,$enddate,$tools,$fixedprivs,$functions,$users,$userdata,
1.48 albertel 2048: $granularity,$quota,$specificity,$idx,$states,$navbuttons,$gpterm,
2049: $ucgpterm) = @_;
1.5 raeburn 2050: my %lt = &Apache::lonlocal::texthash(
1.29 raeburn 2051: grse => "$ucgpterm settings",
2052: mogm => "Modify $gpterm membership",
1.5 raeburn 2053: );
2054: my @regexps = ('user_','userpriv_');
2055: $r->print(&Apache::lonhtmlcommon::echo_form_input(
1.6 raeburn 2056: ['origin','action','state','page','expire','deletion',
1.7 raeburn 2057: 'reenable','activate','changepriv','sortby',
2058: 'togglefunc'],\@regexps));
1.5 raeburn 2059: my $rowimg = 1;
2060: my @available = ();
2061: my @unavailable = ();
2062: &check_tools($functions,$tools,\@available,\@unavailable);
2063: my $nexttext = $$navbuttons{'gtns'};
2064: my $prevtext = $$navbuttons{'gtpp'};
2065: $r->print('
1.3 raeburn 2066: <br />
1.5 raeburn 2067: ');
1.40 albertel 2068: &topic_bar($r,1,$lt{'grse'});
2069: &print_current_settings($r,$action,$functions,$startdate,$enddate,
2070: $groupname,$description,$granularity,$quota,
2071: \@available,\@unavailable,$gpterm,$ucgpterm);
2072: &topic_bar($r,2,$lt{'mogm'});
1.53 raeburn 2073: my $numcurrent = ¤t_membership($r,$cdom,$cnum,$formname,$groupname,
2074: \@available,\@unavailable,$fixedprivs,
2075: $granularity,$specificity);
2076: if ($numcurrent > 0) {
2077: &display_navbuttons($r,$formname,$$states{$action}[$page-1],$prevtext,
2078: $$states{$action}[$page+1],$nexttext);
2079: } else {
2080: &display_navbuttons($r,$formname,$$states{$action}[$page-1],$prevtext);
2081: }
1.5 raeburn 2082: return;
2083: }
2084:
2085: sub current_membership {
1.48 albertel 2086: my ($r,$cdom,$cnum,$formname,$groupname,$available,$unavailable,
2087: $fixedprivs,$granularity,$specificity) = @_;
1.5 raeburn 2088: my %membership = &Apache::lonnet::get_group_membership($cdom,$cnum,
2089: $groupname);
2090: my %lt = &Apache::lonlocal::texthash(
1.6 raeburn 2091: 'actn' => 'Action?',
2092: 'name' => 'Name',
2093: 'usnm' => 'Username',
2094: 'doma' => 'Domain',
2095: 'stda' => 'Start Date',
2096: 'enda' => 'End Date',
1.5 raeburn 2097: 'expi' => 'Expire',
2098: 'reen' => 'Re-enable',
2099: 'acti' => 'Activate',
2100: 'dele' => 'Delete',
1.53 raeburn 2101: 'curf' => 'Current Tool Set',
1.5 raeburn 2102: 'chpr' => 'Change Privileges'
2103: );
1.52 raeburn 2104: my ($current,$num_items,$hastools,$addtools) =
1.36 raeburn 2105: &Apache::longroup::group_memberlist($cdom,$cnum,$groupname,$fixedprivs,
2106: $available);
1.53 raeburn 2107: my $numcurrent = scalar(keys(%{$current}));
2108: if ($numcurrent > 0) {
1.36 raeburn 2109: $r->print('
1.5 raeburn 2110: <table>
2111: <tr>');
1.52 raeburn 2112: if ($num_items->{'active'}) {
1.36 raeburn 2113: &check_uncheck_buttons($r,$formname,'expire',$lt{'expi'});
2114: }
1.52 raeburn 2115: if ($num_items->{'previous'}) {
1.36 raeburn 2116: &check_uncheck_buttons($r,$formname,'reenable',$lt{'reen'});
2117: }
1.52 raeburn 2118: if ($num_items->{'future'}) {
1.36 raeburn 2119: &check_uncheck_buttons($r,$formname,'activate',$lt{'acti'});
2120: }
2121: &check_uncheck_buttons($r,$formname,'deletion',$lt{'dele'});
2122: if (@{$available} > 0) {
2123: if ($specificity eq 'Yes') {
2124: &check_uncheck_buttons($r,$formname,'changepriv',$lt{'chpr'});
1.5 raeburn 2125: }
1.36 raeburn 2126: if ($granularity eq 'Yes') {
2127: $r->print(&check_uncheck_tools($r,$available));
2128: $r->print('
1.5 raeburn 2129: <td>
2130: <nobr>
2131: <fieldset><legend><b>'.$lt{'curf'}.'</b></legend>
2132: <input type="button" value="check all"
2133: onclick="javascript:checkAllTools(document.'.$formname.')" />
2134:
2135: <input type="button" value="uncheck all"
2136: onclick="javascript:uncheckAllTools(document.'.$formname.')" />
2137: </fieldset>
2138: </nobr>
2139: </td>
2140: ');
1.3 raeburn 2141: }
1.36 raeburn 2142: }
2143: $r->print(<<"END");
1.5 raeburn 2144: </tr>
2145: </table>
1.48 albertel 2146: <br />
1.5 raeburn 2147: END
1.48 albertel 2148: $r->print(&Apache::loncommon::start_data_table().
2149: &Apache::loncommon::start_data_table_header_row());
1.36 raeburn 2150: $r->print(<<"END");
1.48 albertel 2151: <th>$lt{'actn'}</th>
2152: <th><a href="javascript:changeSort('fullname')">$lt{'name'}</a></th>
2153: <th><a href="javascript:changeSort('username')">$lt{'usnm'}</a></th>
2154: <th><a href="javascript:changeSort('domain')">$lt{'doma'}</a></th>
2155: <th><a href="javascript:changeSort('id')">ID</a></th>
2156: <th><a href="javascript:changeSort('start')">$lt{'stda'}</a></th>
2157: <th><a href="javascript:changeSort('end')">$lt{'enda'}</a></th>
1.5 raeburn 2158: END
1.36 raeburn 2159: my $colspan = 0;
2160: if ($hastools) {
1.48 albertel 2161: $r->print('<th>'.$lt{'curf'}.'</th>');
2162: $colspan++;
1.36 raeburn 2163: }
2164: if ($addtools) {
1.53 raeburn 2165: $r->print('<th>'.&mt('Additional Tools').'</th>');
1.48 albertel 2166: $colspan++;
1.36 raeburn 2167: }
1.48 albertel 2168: $r->print(&Apache::loncommon::end_data_table_header_row());
1.36 raeburn 2169: if ($colspan) {
2170: if ($granularity eq 'Yes') {
1.48 albertel 2171: $r->print(&Apache::loncommon::start_data_table_row('LC_data_table_dense LC_data_table_highlight').'
1.6 raeburn 2172: <td colspan="7"> </td>
1.48 albertel 2173: <td colspan="'.$colspan.'" align="center"><nobr><b>'.&mt('All:').
1.6 raeburn 2174: '</b> ');
1.36 raeburn 2175: foreach my $tool (@{$available}) {
2176: $r->print('<label><input type="checkbox" name="togglefunc"'.
1.7 raeburn 2177: ' onclick="javascript:toggleTools(document.'.$formname.'.user_'.$tool.',this);"'.
1.48 albertel 2178: ' value="'.$tool.'" />'.'<b>'.$tool.'</b></label> ');
1.6 raeburn 2179: }
1.48 albertel 2180: $r->print('</nobr></td></tr>');
1.6 raeburn 2181: }
1.36 raeburn 2182: }
2183: my %Sortby = ();
2184: foreach my $user (sort(keys(%{$current}))) {
2185: if ($env{'form.sortby'} eq 'fullname') {
2186: push(@{$Sortby{$$current{$user}{fullname}}},$user);
2187: } elsif ($env{'form.sortby'} eq 'username') {
2188: push(@{$Sortby{$$current{$user}{uname}}},$user);
2189: } elsif ($env{'form.sortby'} eq 'domain') {
2190: push(@{$Sortby{$$current{$user}{udom}}},$user);
2191: } elsif ($env{'form.sortby'} eq 'id') {
2192: push(@{$Sortby{$$current{$user}{id}}},$user);
2193: } else {
2194: push(@{$Sortby{$$current{$user}{fullname}}},$user);
2195: }
2196: }
2197: foreach my $key (sort(keys(%Sortby))) {
2198: foreach my $user (@{$Sortby{$key}}) {
2199: my $id = $$current{$user}{id};
2200: my $fullname = $$current{$user}{fullname};
2201: my $udom = $$current{$user}{udom};
2202: my $uname = $$current{$user}{uname};
2203: my $start = $$current{$user}{start};
2204: my $end = $$current{$user}{end};
1.48 albertel 2205: $r->print(&Apache::loncommon::start_data_table_row('LC_data_table_dense').'
2206: <td>');
1.36 raeburn 2207: if ($$current{$user}{changestate} eq 'reenable') {
2208: $r->print('<nobr><label>'.
1.5 raeburn 2209: '<input type="checkbox" name="reenable" value="'.$user.'" />'.
1.7 raeburn 2210: $lt{'reen'}.'</label></nobr><br />');
1.36 raeburn 2211: } elsif ($$current{$user}{changestate} eq 'expire') {
2212: $r->print('<nobr><label>'.
1.5 raeburn 2213: '<input type="checkbox" name="expire" value="'.$user.'" />'.
1.7 raeburn 2214: $lt{'expi'}.'</label></nobr><br />');
1.36 raeburn 2215: } elsif ($$current{$user}{changestate} eq 'activate') {
2216: $r->print('<nobr><label>'.
1.5 raeburn 2217: '<input type="checkbox" name="activate" value="'.$user.'" />'.
1.7 raeburn 2218: $lt{'acti'}.'</label></nobr><br />');
1.36 raeburn 2219: }
2220: $r->print('<nobr><label>'.
1.6 raeburn 2221: '<input type="checkbox" name="deletion" value="'.$user.'" />'.
1.7 raeburn 2222: $lt{'dele'}.'</label></nobr>');
1.36 raeburn 2223: if ($specificity eq 'Yes') {
2224: $r->print('<br /><nobr><label>'.
1.5 raeburn 2225: '<input type="checkbox" name="changepriv" value="'.$user.'" />'.$lt{'chpr'}.
1.7 raeburn 2226: '</label></nobr>');
1.36 raeburn 2227: }
2228: $r->print('
1.48 albertel 2229: </td>'.
2230: '<td>'.$fullname.'</td>'.
2231: '<td>'.$uname.'</td>'.
2232: '<td>'. $udom.'</td>'.
2233: '<td>'.$id.'</td>'.
2234: '<td>'.$start.'</td>'.
2235: '<td>'.$end.'</td>');
1.36 raeburn 2236: if ($hastools) {
1.48 albertel 2237: $r->print('<td align="left"><nobr>'.
1.6 raeburn 2238: ' ');
1.36 raeburn 2239: foreach my $tool (@{$$current{$user}{currtools}}) {
2240: if ($granularity eq 'Yes') {
2241: $r->print('<label><input type="checkbox" '.
1.7 raeburn 2242: 'checked="checked" '.
2243: 'name="user_'.$tool.'" value="'.
2244: $user.'" />'.$tool.'</label>');
1.36 raeburn 2245: } else {
2246: $r->print('<input type="hidden" '.
1.7 raeburn 2247: 'checked="checked" '.
2248: 'name="user_'.$tool.'" value="'.
2249: $user.'" />'.$tool);
1.36 raeburn 2250: }
2251: $r->print(' ');
1.5 raeburn 2252: }
1.48 albertel 2253: $r->print('</nobr></td>');
1.36 raeburn 2254: }
2255: if ($addtools) {
1.48 albertel 2256: $r->print('<td align="left">');
1.36 raeburn 2257: if ($granularity eq 'Yes') {
2258: foreach my $tool (@{$$current{$user}{newtools}}) {
2259: $r->print('<nobr><label><input type="checkbox"
1.5 raeburn 2260: name="user_'.$tool.'" value="'.
2261: $user.'" />'.$tool.
1.7 raeburn 2262: '</label></nobr> ');
1.36 raeburn 2263: }
2264: } else {
2265: foreach my $tool (@{$$current{$user}{newtools}}) {
2266: $r->print('<nobr><input type="hidden"
1.5 raeburn 2267: name="user_'. $tool.'" value="'.
2268: $user.'" />'.$tool.
2269: '</nobr> ');
2270: }
2271: }
1.48 albertel 2272: $r->print('</td>');
1.5 raeburn 2273: }
1.48 albertel 2274: $r->print(&Apache::loncommon::end_data_table_row()."\n");
1.5 raeburn 2275: }
1.36 raeburn 2276: }
1.48 albertel 2277: $r->print(&Apache::loncommon::end_data_table());
1.53 raeburn 2278: } else {
2279: $r->print(&mt('There are no active, future or previous group members to modify.'));
1.5 raeburn 2280: }
1.53 raeburn 2281: return $numcurrent;
1.5 raeburn 2282: }
2283:
2284: sub check_uncheck_buttons {
2285: my ($r,$formname,$field,$title,$colspan) = @_;
2286: $r->print('
2287: <td '.$colspan.'>
2288: <fieldset>
2289: <legend><b>'.$title.'</b></legend>
1.48 albertel 2290: <nobr>
1.5 raeburn 2291: <input type="button" value="check all"
2292: onclick="javascript:checkAll(document.'.$formname.'.'.$field.')" />
2293:
2294: <input type="button" value="uncheck all"
2295: onclick="javascript:uncheckAll(document.'.$formname.'.'.$field.')" />
1.48 albertel 2296: </nobr>
1.5 raeburn 2297: </fieldset>
2298: </td>
2299: ');
2300: }
2301:
2302:
2303: sub change_privs_form {
1.45 albertel 2304: my ($r,$cdom,$cnum,$action,$formname,$page,$startdate,$enddate,
2305: $tools,$functions,$toolprivs,$fixedprivs,$userdata,$usertools,
2306: $memchg,$idx,$states,$stored,$sectioncount,$navbuttons,$gpterm,
2307: $ucgpterm) = @_;
1.5 raeburn 2308: my @regexps = ('userpriv_');
2309: my $nexttext;
1.6 raeburn 2310: my %lt = &Apache::lonlocal::texthash(
2311: 'tode' => 'To be deleted',
2312: 'toex' => 'To be expired',
1.29 raeburn 2313: 'nome' => "No members to be deleted or expired from the $gpterm.",
1.6 raeburn 2314: );
1.5 raeburn 2315: $r->print(&Apache::lonhtmlcommon::echo_form_input(
1.6 raeburn 2316: ['origin','action','state','page','sortby'],\@regexps));
2317: if ($env{'form.branch'} eq 'adds') {
2318: $nexttext = $$navbuttons{'adme'};
2319: } else {
2320: $nexttext = $$navbuttons{'mose'};
2321: }
1.40 albertel 2322: &topic_bar($r,3,&mt('Members to delete or expire'));
1.6 raeburn 2323: my $exp_or_del = 0;
2324: if (ref($$memchg{'deletion'}) eq 'ARRAY') {
2325: if (@{$$memchg{'deletion'}} > 0) {
1.50 albertel 2326: $r->print('<b>'.$lt{'tode'}.':</b><br /><ul>');
1.6 raeburn 2327: foreach my $user (@{$$memchg{'deletion'}}) {
2328: $r->print('<li>'.$$userdata{$user}[$$idx{fullname}].
2329: ' ('.$user.')</li>');
2330: }
1.45 albertel 2331: $r->print('</ul>');
1.6 raeburn 2332: $exp_or_del += @{$$memchg{'deletion'}};
2333: }
2334: }
2335: if (ref($$memchg{'expire'}) eq 'ARRAY') {
2336: if (@{$$memchg{'expire'}} > 0) {
1.50 albertel 2337: $r->print('<b>'.$lt{'toex'}.':</b><br /><ul>');
1.6 raeburn 2338: foreach my $user (@{$$memchg{'expire'}}) {
2339: $r->print('<li>'.$$userdata{$user}[$$idx{fullname}].
2340: ' ('.$user.')</li>');
2341: }
1.45 albertel 2342: $r->print('</ul>');
1.6 raeburn 2343: $exp_or_del += @{$$memchg{'expire'}};
2344: }
2345: }
2346: if (!$exp_or_del) {
1.45 albertel 2347: $r->print($lt{'nome'}.'<br />');
1.6 raeburn 2348: }
1.5 raeburn 2349:
1.53 raeburn 2350: &topic_bar($r,4,&mt('Setting optional privileges for specific group members'));
1.6 raeburn 2351:
1.45 albertel 2352: my $numchgs = &member_privileges_form($r,$action,$formname,$tools,
1.6 raeburn 2353: $toolprivs,$fixedprivs,$userdata,
2354: $usertools,$idx,$memchg,$states,
1.45 albertel 2355: $stored,$gpterm);
1.5 raeburn 2356: my $prevtext = $$navbuttons{'gtps'};
1.6 raeburn 2357: if ($numchgs || $exp_or_del) {
2358: &display_navbuttons($r,$formname,$$states{$action}[$page-1],$prevtext,
2359: $$states{$action}[$page+1],$nexttext);
2360: } else {
2361: &display_navbuttons($r,$formname,$$states{$action}[$page-1],$prevtext);
2362: }
1.5 raeburn 2363: return;
2364: }
2365:
2366: sub add_members_form {
1.46 albertel 2367: my ($r,$action,$formname,$page,$startdate,$enddate,$groupname,
1.29 raeburn 2368: $description,$granularity,$quota,$sectioncount,$tools,$functions,
1.46 albertel 2369: $stored,$states,$navbuttons,$gpterm,$ucgpterm)=@_;
1.40 albertel 2370: $r->print(' <br />');
1.5 raeburn 2371: my @available = ();
2372: my @unavailable = ();
2373: &check_tools($functions,$tools,\@available,\@unavailable);
1.40 albertel 2374: &print_current_settings($r,$action,$functions,$startdate,$enddate,
2375: $groupname,$description,$granularity,$quota,
2376: \@available,\@unavailable,$gpterm,$ucgpterm);
2377: &membership_options($r,$action,$formname,$sectioncount,1,$gpterm,$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.58 ! raeburn 3143: my %customroles = &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: $role =~ s/\//_/g;
! 3161: push (@customs,$role);
! 3162: $r->print(&print_autorole_item($role,$roletitle,\@sections));
! 3163: }
! 3164: if ($action eq 'modify') {
! 3165: foreach my $role (@{$$stored{'autorole'}}) {
! 3166: if ((!grep(/^\Q$role\E$/,@customs)) &&
! 3167: (!grep(/^\Q$role\E$/,@roles))) {
! 3168: my $roletitle;
! 3169: if ($role =~ /^cr/) {
! 3170: ($roletitle) = ($role =~ m|_([^_]+)$|);
! 3171: } else {
! 3172: $roletitle = &Apache::lonnet::plaintext($role,$crstype);
! 3173: }
! 3174: $r->print(&print_autorole_item($role,$roletitle,\@sections));
! 3175: }
! 3176: }
1.5 raeburn 3177: }
1.44 albertel 3178: $r->print(&Apache::loncommon::end_data_table());
1.5 raeburn 3179: return;
3180: }
1.3 raeburn 3181:
1.58 ! raeburn 3182: sub print_autorole_item {
! 3183: my ($role,$roletitle,$sections) = @_;
! 3184: my $sections_sel;
! 3185: if (@{$sections} > 0) {
! 3186: if ($role eq 'cc') {
! 3187: $sections_sel = '<td align="right">'.
! 3188: &mt('all sections').'<input type="hidden" '.
! 3189: 'name="sec_cc" value="all" /></td>';
! 3190: } else {
! 3191: $sections_sel='<td align="right">'.
! 3192: §ions_selection($sections,'sec_'.$role).
! 3193: '</td>';
! 3194: }
! 3195: }
! 3196: my $output = &Apache::loncommon::start_data_table_row().
! 3197: '<td><input type="checkbox" '.
! 3198: 'name="autorole" value="'.$role.'" />'.
! 3199: '</td><td>'.$roletitle.'</td>'.$sections_sel.
! 3200: &Apache::loncommon::end_data_table_row();
! 3201: return $output;
! 3202: }
! 3203:
1.5 raeburn 3204: sub standard_roles {
1.17 raeburn 3205: my @roles = ('cc','in','ta','ep','st');
1.5 raeburn 3206: return @roles;
3207: }
3208:
1.58 ! raeburn 3209: sub course_custom_roles {
! 3210: my ($cdom,$cnum) = @_;
1.5 raeburn 3211: my %returnhash=();
1.58 ! raeburn 3212: my %coursepersonnel=&Apache::lonnet::dump('nohist_userroles',$cdom,$cnum);
! 3213: foreach my $person (sort(keys(%coursepersonnel))) {
! 3214: my ($role) = ($person =~ /^([^:]+):/);
! 3215: my ($end,$start) = split(/:/,$coursepersonnel{$person});
! 3216: if ($end == -1 && $start == -1) {
! 3217: next;
! 3218: }
! 3219: if ($role =~ m|^cr/[^/]+/[^/]+/[^/]|) {
! 3220: $returnhash{$role} ++;
1.5 raeburn 3221: }
3222: }
3223: return %returnhash;
3224: }
3225:
3226: sub modify_menu {
1.29 raeburn 3227: my ($r,$groupname,$page,$gpterm) = @_;
1.5 raeburn 3228: my @menu =
3229: (
1.29 raeburn 3230: { text => "Modify default $gpterm settings",
1.5 raeburn 3231: help => 'Course_Modify_Group',
3232: state => 'change_settings',
3233: branch => 'settings',
3234: },
1.6 raeburn 3235: { text => 'Modify access, tools and/or privileges for previous, '.
3236: 'future, or current members',
1.5 raeburn 3237: help => 'Course_Modify_Group_Membership',
3238: state => 'change_members',
3239: branch => 'members',
3240: },
1.29 raeburn 3241: { text => "Add member(s) to the $gpterm",
1.5 raeburn 3242: help => 'Course_Group_Add_Members',
3243: state => 'add_members',
3244: branch => 'adds',
3245: },
3246: );
3247: my $menu_html = '';
3248: foreach my $menu_item (@menu) {
3249: $menu_html .=
3250: '<p><font size="+1"><a href="/adm/coursegroups?action=modify&refpage='.$env{'form.refpage'}.'&groupname='.$groupname.'&state='.$menu_item->{'state'}.'&branch='.$menu_item->{'branch'}.'">';
3251: $menu_html.= &mt($menu_item->{'text'}).'</a></font>';
3252: if (exists($menu_item->{'help'})) {
3253: $menu_html.=
3254: &Apache::loncommon::help_open_topic($menu_item->{'help'});
3255: }
3256: $menu_html.='</p>'.$/;
1.3 raeburn 3257: }
1.5 raeburn 3258: $r->print($menu_html);
1.3 raeburn 3259: return;
3260: }
3261:
3262: sub member_privs_entries {
1.45 albertel 3263: my ($r,$usertools,$toolprivs,$fixedprivs,$userdata,$idx,$showtools,
3264: $defprivs,$excluded) = @_;
1.5 raeburn 3265: foreach my $user (sort(keys(%{$usertools}))) {
1.6 raeburn 3266: if (defined($excluded)) {
3267: if (ref($excluded) eq 'ARRAY') {
3268: if (grep/^$user$/,@{$excluded}) {
3269: next;
3270: }
3271: }
3272: }
1.5 raeburn 3273: my ($uname,$udom) = split(/:/,$user);
1.45 albertel 3274: $r->print(&Apache::loncommon::start_data_table_row().'
1.5 raeburn 3275: <td>'.$$userdata{$user}[$$idx{fullname}].'</td>
1.3 raeburn 3276: <td>'.$uname.'</td>
3277: <td>'.$udom.'</td>
1.53 raeburn 3278: <td valign="top">
3279: <table>
3280: <tr>
3281: <td><b>'.
3282: &mt('Collaborative Tool').'</b></td>
3283: </tr>
3284: <tr>
3285: <td><b>'.&mt('Fixed').'</b></td>
3286: </tr>
3287: <tr>
3288: <td><b>'.&mt('Optional').'</b></td>
3289: </tr>
3290: </table>
3291: </td>');
1.5 raeburn 3292: foreach my $tool (@{$showtools}) {
3293: if (exists($$usertools{$user}{$tool})) {
1.45 albertel 3294: $r->print('<td valign="top"><table><tr><th colspan="2">'.$tool.'</th></tr>');
1.3 raeburn 3295: my $privcount = 0;
3296: my $fixed = '';
3297: my $dynamic = '';
3298: foreach my $priv (sort(keys(%{$$toolprivs{$tool}}))) {
3299: if (exists($$fixedprivs{$tool}{$priv})) {
1.5 raeburn 3300: $fixed .= '<input type="hidden" name="userpriv_'.$priv.'" value="'.$user.'" />'.$$toolprivs{$tool}{$priv}.' ';
1.3 raeburn 3301: } else {
3302: $privcount ++;
3303: if ($privcount == 3) {
3304: $dynamic .= '</tr><tr>';
3305: }
1.7 raeburn 3306: $dynamic .='<td><nobr><label><input type="checkbox" '.
1.5 raeburn 3307: 'name="userpriv_'.$priv.'" value="'.$user.'"';
3308: if (grep/^\Q$priv\E$/,@{$defprivs}) {
3309: $dynamic .= ' checked="checked" ';
3310: }
3311: $dynamic .= ' />'.$$toolprivs{$tool}{$priv}.
1.7 raeburn 3312: '</label></nobr></td>';
1.3 raeburn 3313: }
3314: }
3315: $r->print('<tr><td colspan="2"><nobr>'.$fixed.'</nobr></td></tr><tr>'.$dynamic.'</tr></table></td>');
3316: } else {
1.45 albertel 3317: $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 3318: }
3319: }
1.45 albertel 3320: $r->print(&Apache::loncommon::end_data_table_row());
1.3 raeburn 3321: }
3322: }
3323:
3324: sub get_dates_from_form {
3325: my $startdate;
3326: my $enddate;
3327: $startdate = &Apache::lonhtmlcommon::get_date_from_form('startdate');
3328: $enddate = &Apache::lonhtmlcommon::get_date_from_form('enddate');
3329: if ( exists ($env{'form.no_end_date'}) ) {
3330: $enddate = 0;
3331: }
3332: return ($startdate,$enddate);
1.5 raeburn 3333: }
3334:
1.3 raeburn 3335: sub date_setting_table {
3336: my ($starttime,$endtime,$formname) = @_;
3337: my $startform = &Apache::lonhtmlcommon::date_setter($formname,
3338: 'startdate',$starttime);
3339: my $endform = &Apache::lonhtmlcommon::date_setter($formname,
3340: 'enddate',$endtime);
1.41 albertel 3341: my $perpetual =
3342: '<nobr><label><input type="checkbox" name="no_end_date" />'.
3343: &mt('None').'</label></nobr>';
1.42 albertel 3344: my $table = "<table class=\"LC_descriptive_input\">\n".
3345: '<tr><td class="LC_description">'.&mt('Start:').'</td>'.
1.3 raeburn 3346: '<td>'.$startform.'</td>'.
1.41 albertel 3347: '<td> </td>'."</tr>\n".
1.42 albertel 3348: '<tr><td class="LC_description">'.&mt('End:').'</td>'.
1.3 raeburn 3349: '<td>'.$endform.'</td>'.
1.41 albertel 3350: '<td>'.$perpetual.'</td>'."</tr>\n".
3351: "</table>\n";
3352: return $table;
1.1 raeburn 3353: }
3354:
1.32 raeburn 3355: sub add_group_folder {
3356: my ($cdom,$cnum,$now,$groupname,$action,$description,$tools,$groupinfo,
3357: $gpterm,$ucgpterm,$crstype) = @_;
3358: if ($cdom eq '' || $cnum eq '') {
3359: return &mt('Error: invalid course domain or number - group folder creation failed');
3360: }
3361: my ($outcome,$allgrpsmap,$grpmap,$boardsmap,$grppage);
3362: my $navmap = Apache::lonnavmaps::navmap->new();
3363: my $crspath = '/uploaded/'.$cdom.'/'.$cnum.'/';
1.47 raeburn 3364: $allgrpsmap = $crspath.'group_allfolders.sequence';
1.32 raeburn 3365: my $topmap = $navmap->getResourceByUrl($allgrpsmap);
3366: undef($navmap);
3367: if ($action eq 'create') {
1.47 raeburn 3368: # check if group_allfolders.sequence exists.
1.32 raeburn 3369: if (!$topmap) {
1.52 raeburn 3370: my $grpstitle = &mt('[_1] [_2]s',$crstype,$ucgpterm);
1.32 raeburn 3371: my $topmap_url = '/'.$env{'course.'.$env{'request.course.id'}.'.url'};
3372: $topmap_url =~ s|/+|/|g;
3373: if ($topmap_url =~ m|^/uploaded|) {
1.47 raeburn 3374: $outcome = &map_updater($cdom,$cnum,'group_allfolders.sequence',
1.32 raeburn 3375: 'toplevelgroup',$grpstitle,$topmap_url);
3376: if ($outcome ne 'ok') {
3377: return $outcome;
3378: }
3379: } else {
1.47 raeburn 3380: $outcome = &mt('Non-standard course - folder for all groups not added.');
1.32 raeburn 3381: return $outcome;
3382: }
3383: }
3384: my $grpfolder = &mt('[_1] Folder -',$ucgpterm,).$description;
1.49 raeburn 3385: $grppage='/adm/'.$cdom.'/'.$cnum.'/'.$groupname.'/smppg';
1.32 raeburn 3386: my $grptitle = &mt('Group homepage').' - '.$description;
1.55 raeburn 3387: my ($discussions,$disctitle);
1.47 raeburn 3388: my $outcome = &map_updater($cdom,$cnum,'group_folder_'.$groupname.'.sequence',
1.32 raeburn 3389: 'grpseq',$grpfolder,$allgrpsmap,$grppage,
3390: $grptitle);
3391: if ($outcome ne 'ok') {
3392: return $outcome;
3393: }
3394: my $pageout = &create_homepage($cdom,$cnum,$groupname,$groupinfo,
3395: $tools,$gpterm,$ucgpterm,$now);
3396: # Link to folder for bulletin boards
1.47 raeburn 3397: $grpmap = $crspath.'group_folder_'.$groupname.'.sequence';
1.32 raeburn 3398: if (grep/^discussion$/,@{$tools}) {
3399: $disctitle = &mt('Discussion Boards');
1.47 raeburn 3400: my $outcome = &map_updater($cdom,$cnum,'group_boards_'.$groupname.
1.32 raeburn 3401: '.sequence','bbseq',$disctitle,$grpmap);
3402: if ($outcome ne 'ok') {
3403: return $outcome;
3404: }
1.47 raeburn 3405: $boardsmap = $crspath.'group_boards_'.$groupname.'.sequence';
1.32 raeburn 3406: }
3407: } else {
3408: #modify group folder if status of discussions tools is changed
3409: }
3410: my ($furl,$ferr)= &Apache::lonuserstate::readmap($cdom.'/'.$cnum);
1.33 raeburn 3411: $navmap = Apache::lonnavmaps::navmap->new();
1.32 raeburn 3412: # modify parameters
3413: my $parm_result;
3414: if ($action eq 'create') {
3415: if ($grpmap) {
3416: $parm_result .= &parm_setter($navmap,$cdom,$grpmap,$groupname);
3417: }
3418: if ($grppage) {
3419: $parm_result .= &parm_setter($navmap,$cdom,$grppage,$groupname);
3420: }
3421: if ($boardsmap) {
3422: $parm_result .= &parm_setter($navmap,$cdom,$boardsmap,$groupname);
3423: }
3424: }
3425: if ($parm_result) {
3426: return $parm_result;
3427: } else {
3428: return 'ok';
3429: }
3430: }
3431:
3432: sub map_updater {
3433: my ($cdom,$cnum,$newfile,$itemname,$itemtitle,$parentmap,$startsrc,
3434: $starttitle,$endsrc,$endtitle) = @_;
3435: my $outcome;
3436: $env{'form.'.$itemname} = &new_map($startsrc,$starttitle,$endsrc,
3437: $endtitle);
3438: my $newmapurl=&Apache::lonnet::finishuserfileupload($cnum,$cdom,$itemname,
3439: $newfile);
3440: if ($newmapurl !~ m|^/uploaded|) {
1.37 raeburn 3441: $outcome = &mt('Error uploading new folder.')." ($newfile): $newmapurl".'<br />';
1.32 raeburn 3442: return $outcome;
3443: }
3444: my ($errtext,$fatal)=&Apache::lonratedt::mapread($parentmap);
3445: if ($fatal) {
1.37 raeburn 3446: $outcome = &mt('Error reading contents of parent folder')." ($parentmap): $errtext".'<br />';
1.32 raeburn 3447: return $outcome;
3448: } else {
3449: my $newidx=&Apache::lonratedt::getresidx($newmapurl);
3450: $Apache::lonratedt::resources[$newidx] = $itemtitle.':'.$newmapurl.
3451: ':false:normal:res';
3452: $Apache::lonratedt::order[1+$#Apache::lonratedt::order]=$newidx;
3453: my ($outtext,$errtext) = &Apache::lonratedt::storemap($parentmap,1);
3454: if ($errtext) {
1.37 raeburn 3455: $outcome = &mt('Error storing updated parent folder')." ($parentmap): $errtext".'<br />';
1.32 raeburn 3456: return $outcome;
3457: }
3458: }
3459: return 'ok';
3460: }
3461:
3462: sub new_map {
3463: my ($startsrc,$starttitle,$endsrc,$endtitle) = @_;
3464: my $newmapstr = '
3465: <map>
3466: <resource id="1" src="'.$startsrc.'" type="start" title="'.$starttitle.'"></resource>
3467: <link from="1" to="2" index="1"></link>
3468: <resource id="2" src="'.$endsrc.'" type="finish" title="'.$endtitle.'"></resource>
3469: </map>
3470: ';
3471: return $newmapstr;
3472: }
3473:
3474: sub parm_setter {
3475: my ($navmap,$cdom,$url,$groupname) = @_;
1.37 raeburn 3476: my $allresults;
1.32 raeburn 3477: my %hide_settings = (
3478: 'course' => {
3479: 'num' => 13,
3480: 'set' => 'yes',
3481: },
3482: 'group' => {
3483: 'num' => 5,
3484: 'set' => 'no',
3485: 'extra' => $groupname,
3486: },
3487: );
3488: my $res = $navmap->getResourceByUrl($url);
3489: my $symb = $res->symb();
3490: foreach my $level (keys(%hide_settings)) {
1.37 raeburn 3491: my $parmresult = &Apache::lonparmset::storeparm_by_symb($symb,
1.32 raeburn 3492: '0_hiddenresource',
3493: $hide_settings{$level}{'num'},
3494: $hide_settings{$level}{'set'},
3495: 'string_yesno',undef,$cdom,
3496: undef,undef,
3497: $hide_settings{$level}{'extra'});
1.37 raeburn 3498: if ($parmresult) {
3499: $allresults .= $level.': '.$parmresult;
3500: }
1.32 raeburn 3501: }
1.37 raeburn 3502: return $allresults;
1.32 raeburn 3503: }
3504:
1.3 raeburn 3505: sub create_homepage {
1.32 raeburn 3506: my ($cdom,$cnum,$name,$groupinfo,$tools,$gpterm,$ucgpterm,$now) = @_;
1.3 raeburn 3507: my $functionality = join(',',@{$tools});
1.24 www 3508: my $content = &unescape($$groupinfo{description});
1.3 raeburn 3509: $content=~s/\s+$//s;
3510: $content=~s/^\s+//s;
3511: $content=~s/\<br\s*\/*\>$//s;
3512: $content=&Apache::lonfeedback::clear_out_html($content,1);
3513:
3514: my %pageinfo = (
1.29 raeburn 3515: 'aaa_title' => "$ucgpterm: $name",
1.3 raeburn 3516: 'abb_links' => $functionality,
3517: 'bbb_content' => $content,
3518: 'ccc_webreferences' => '',
1.32 raeburn 3519: 'uploaded.lastmodified' => $now,
1.3 raeburn 3520: );
3521: my $putresult = &Apache::lonnet::put('grppage_'.$name,\%pageinfo,$cdom,$cnum);
3522: return $putresult;
1.1 raeburn 3523: }
3524:
1.5 raeburn 3525: sub check_uncheck_tools {
3526: my ($r,$available) = @_;
3527: if (ref($available) eq 'ARRAY') {
3528: $r->print('
3529: <script type="text/javascript">
3530: function checkAllTools(formname) {
3531: ');
3532: foreach my $tool (@{$available}) {
3533: $r->print(' checkAll(formname.user_'.$tool.');'."\n");
3534: }
3535: $r->print(' checkAll(formname.togglefunc);'."\n");
3536: $r->print('
3537: }
3538: function uncheckAllTools(formname) {
3539: ');
3540: foreach my $tool (@{$available}) {
3541: $r->print(' uncheckAll(formname.user_'.$tool.');'."\n");
3542: }
3543: $r->print(' uncheckAll(formname.togglefunc);'."\n");
3544: $r->print('
3545: }
3546: function toggleTools(field,caller) {
3547: if (caller.checked) {
3548: checkAll(field);
3549: } else {
3550: uncheckAll(field);
3551: }
3552: return;
3553: }
3554: </script>
3555: ');
3556: }
3557: return;
3558: }
3559:
3560: sub validate_groupname {
1.29 raeburn 3561: my ($groupname,$action,$cdom,$cnum,$gpterm,$ucgpterm,$crstype) = @_;
1.16 albertel 3562: my %sectioncount = &Apache::loncommon::get_sections($cdom,$cnum);
1.17 raeburn 3563: my %curr_groups = &Apache::longroup::coursegroups($cdom,$cnum);
1.15 albertel 3564:
1.5 raeburn 3565: my %lt = &Apache::lonlocal::texthash (
1.29 raeburn 3566: igna => "Invalid $gpterm name",
3567: tgne => "The $gpterm name entered ",
3568: grna => "$ucgpterm names and section names used in a ".
3569: "$crstype must be unique.",
3570: isno => "is not a valid name.",
3571: gnmo => "$ucgpterm names may only contain letters, ".
3572: "numbers or underscores.",
3573: cnnb => "can not be used as it is the name of ",
3574: inth => " in this $crstype",
3575: thgr => "- does not correspond to the name of an ".
3576: "existing $gpterm",
1.5 raeburn 3577: );
1.15 albertel 3578:
1.42 albertel 3579: my $exitmsg = '<span class="LC_error">'.$lt{'igna'}.'</span><br /><br />'.
3580: $lt{'tgne'}.' "'.$groupname.'" ';
1.5 raeburn 3581: my $dupmsg = $lt{'grna'};
3582: my $earlyout;
3583: if (($groupname eq '') || ($groupname =~ /\W/)) {
3584: $earlyout = $exitmsg.$lt{'isno'}.'<br />'.$lt{'gnmo'};
3585: return $earlyout;
3586: }
1.16 albertel 3587: if (exists($sectioncount{$groupname})) {
3588: return $exitmsg.$lt{'cnnb'}.&mt('a section').$lt{'inth'}.
3589: '<br />'.$lt{'grna'};
1.5 raeburn 3590: }
1.15 albertel 3591: if ($action eq 'create'
3592: && exists($curr_groups{$groupname})) {
3593:
1.29 raeburn 3594: return $exitmsg.$lt{'cnnb'}.&mt('an existing [_1]',$gpterm).
1.15 albertel 3595: $lt{'inth'}.'<br />'.$lt{'grna'};
3596:
1.5 raeburn 3597: } elsif ($action eq 'modify') {
3598: unless(exists($curr_groups{$groupname})) {
1.29 raeburn 3599: $earlyout = &mt('[_1] name:',$ucgpterm).' '.$groupname.$lt{'thgr'}.
3600: $lt{'inth'};
1.5 raeburn 3601: return $earlyout;
3602: }
3603: }
3604: return;
3605: }
3606:
3607: sub topic_bar {
1.40 albertel 3608: my ($r,$imgnum,$title) = @_;
1.5 raeburn 3609: $r->print('
1.40 albertel 3610: <div class="LC_topic_bar">
1.45 albertel 3611: <img alt="'.&mt('Step [_1]',$imgnum).
3612: '"src="/res/adm/pages/bl_step'.$imgnum.'.gif" />
3613: <span>'.$title.'</span>
1.40 albertel 3614: </div>
1.5 raeburn 3615: ');
3616: return;
3617: }
3618:
3619: sub check_changes {
3620: my ($member_changes,$memchg) = @_;
3621: my %exclusions;
3622: @{$exclusions{'changefunc'}} = ('expire');
3623: @{$exclusions{'changepriv'}} = ('expire','changefunc');
3624:
3625: foreach my $change (@{$member_changes}) {
1.6 raeburn 3626: if ($change eq 'deletion') {
1.5 raeburn 3627: next;
3628: }
1.6 raeburn 3629: my @checks = ('deletion');
1.5 raeburn 3630: if (exists($exclusions{$change})) {
3631: push(@checks,@{$exclusions{$change}});
3632: }
3633: my @temp = ();
3634: foreach my $item (@{$$memchg{$change}}) {
3635: my $match = 0;
3636: foreach my $check (@checks) {
1.6 raeburn 3637: if (defined($$memchg{$check})) {
3638: if (ref(@{$$memchg{$check}}) eq 'ARRAY') {
3639: if (@{$$memchg{$check}} > 0) {
3640: if (grep/^$item$/,@{$$memchg{$check}}) {
3641: $match = 1;
3642: last;
3643: }
3644: }
1.5 raeburn 3645: }
3646: }
3647: }
3648: if ($match) {
3649: next;
3650: }
3651: push(@temp,$item);
3652: }
3653: @{$$memchg{$change}} = @temp;
3654: }
3655: }
1.3 raeburn 3656:
1.1 raeburn 3657: 1;
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>