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