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