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