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