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