Annotation of loncom/interface/loncoursegroups.pm, revision 1.42
1.24 www 1: # The LearningOnline Network with CAPA
2: #
1.42 ! albertel 3: # $Id: loncoursegroups.pm,v 1.41 2006/07/07 17:11:04 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.5 raeburn 1200: &mapping_options($r,$action,$formname,$page,$tabcol,$sectioncount,
1201: $states,$stored,$navbuttons,4,5,$rowColor1,
1.29 raeburn 1202: $rowColor2,$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.5 raeburn 1494: my $newusers = &pick_new_members($r,$action,$formname,$tabcol,$rowColor1,
1495: $rowColor2,\@available,$idx,$stored,
1496: $memimg,$users,$userdata,$granularity,
1.29 raeburn 1497: \%origmembers,$gpterm,$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 {
1635: my ($r,$action,$formname,$tabcol,$rowColor1,$rowColor2,$available,$idx,
1.29 raeburn 1636: $stored,$img,$users,$userdata,$granularity,$origmembers,$gpterm,
1637: $ucgpterm) = @_;
1.5 raeburn 1638: my %lt = &Apache::lonlocal::texthash(
1.29 raeburn 1639: 'gpme' => "$ucgpterm membership",
1.5 raeburn 1640: 'addm' => 'Add members',
1641: 'setf' => 'Set functionality',
1642: 'func' => 'Functionality',
1643: 'nome' => 'No members to add at this time.',
1.29 raeburn 1644: 'nnew' => "There are no users to add as new members, as all users".
1645: " matching the specified type(s), role(s), and/or ".
1646: "section(s) are already affiliated with this $gpterm.",
1.5 raeburn 1647: 'yoma' => 'You may need to use the '."'".'modify existing, past or '.
1648: 'future members'."'".' page if you need to re-enable '.
1649: 'or activate access for previous or future members.',
1650: );
1651: my %members;
1652: my $totalusers = 0;
1653: my $newusers = 0;
1.3 raeburn 1654: foreach my $role (keys(%{$users})) {
1655: foreach my $user (keys(%{$$users{$role}})) {
1.5 raeburn 1656: $totalusers ++;
1657: if (ref($origmembers) eq 'HASH') {
1658: if (exists($$origmembers{$user})) {
1659: next;
1660: }
1661: }
1.3 raeburn 1662: unless (defined($members{$user})) {
1663: @{$members{$user}} = @{$$userdata{$user}};
1.5 raeburn 1664: $newusers ++;
1.3 raeburn 1665: }
1666: }
1667: }
1668: if (keys(%members) > 0) {
1.5 raeburn 1669: if (@{$available} > 0 && $granularity eq 'Yes') {
1670: $r->print(&check_uncheck_tools($r,$available));
1671: }
1672: }
1.40 albertel 1673: &topic_bar($r,$img,$lt{'gpme'});
1.5 raeburn 1674: if (keys(%members) > 0) {
1675: $r->print('
1.3 raeburn 1676: <table>
1.5 raeburn 1677: <tr>');
1678: &check_uncheck_buttons($r,$formname,'member',$lt{'addm'});
1679: if (@{$available} > 0 && $granularity eq 'Yes') {
1680: $r->print('<td><nobr>
1681: <fieldset><legend><b>'.$lt{'setf'}.'</b></legend>
1682: <input type="button" value="check all"
1683: onclick="javascript:checkAllTools(document.'.$formname.')" />
1684:
1685: <input type="button" value="uncheck all"
1.3 raeburn 1686: onclick="javascript:uncheckAllTools(document.'.$formname.')" />
1.5 raeburn 1687: </fieldset></nobr></td>');
1.3 raeburn 1688: }
1689: $r->print('</tr></table>
1690: ');
1.42 ! albertel 1691: $r->print(&Apache::loncommon::start_data_table());
1.5 raeburn 1692: $r->print('
1.3 raeburn 1693: <table border="0" cellpadding="4" cellspacing="1">
1.5 raeburn 1694: <tr bgcolor="'.$tabcol.'" align="center">
1695: <td><b>'.&mt('Add?').'</b></td>
1696: <td><b><a href="javascript:changeSort('."'fullname'".')">'.&mt('Name').'</a></b></td>
1697: <td><b><a href="javascript:changeSort('."'username'".')">'.&mt('Username').'</a></b>
1.3 raeburn 1698: </td>
1.5 raeburn 1699: <td><b><a href="javascript:changeSort('."'domain'".')">'.&mt('Domain').'</a></b></td>
1700: <td><b><a href="javascript:changeSort('."'id'".')">ID</a></b></td>
1.31 albertel 1701: <td><b><a href="javascript:changeSort('."'section'".')">Section</a></b></td>
1.5 raeburn 1702: ');
1703: if (@{$available} > 0) {
1704: $r->print('<td><b>'.$lt{'func'}.'</b></td>');
1.3 raeburn 1705: }
1706: $r->print('</tr>');
1.5 raeburn 1707: if (@{$available} > 0) {
1708: if ($granularity eq 'Yes') {
1709: $r->print('<tr bgcolor="#cccccc">
1.35 raeburn 1710: <td colspan="6"> </td>
1.7 raeburn 1711: <td align="center"><small><nobr><b>'.&mt('All:').'</b> ');
1.5 raeburn 1712: foreach my $tool (@{$available}) {
1.7 raeburn 1713: $r->print('<label><input type="checkbox" name="togglefunc" '.
1714: 'onclick="javascript:toggleTools(document.'.$formname.'.user_'.$tool.',this);"'.
1715: ' value="'.$tool.'">'.'<b>'.$tool.'</b></label> ');
1.5 raeburn 1716: }
1717: $r->print('</nobr></small></td></tr>');
1718: }
1719: }
1.3 raeburn 1720: my %Sortby = ();
1721: foreach my $user (sort(keys(%members))) {
1722: if ($env{'form.sortby'} eq 'fullname') {
1723: push(@{$Sortby{$members{$user}[$$idx{fullname}]}},$user);
1724: } elsif ($env{'form.sortby'} eq 'username') {
1725: push(@{$Sortby{$members{$user}[$$idx{uname}]}},$user);
1726: } elsif ($env{'form.sortby'} eq 'domain') {
1727: push(@{$Sortby{$members{$user}[$$idx{udom}]}},$user);
1728: } elsif ($env{'form.sortby'} eq 'id') {
1729: push(@{$Sortby{$members{$user}[$$idx{id}]}},$user);
1.31 albertel 1730: } elsif ($env{'form.sortby'} eq 'section') {
1731: push(@{$Sortby{$members{$user}[$$idx{section}]}},$user);
1.3 raeburn 1732: } else {
1733: push(@{$Sortby{$members{$user}[$$idx{fullname}]}},$user);
1734: }
1735: }
1736: my $rowNum = 0;
1737: my $rowColor;
1738: foreach my $key (sort(keys(%Sortby))) {
1739: foreach my $user (@{$Sortby{$key}}) {
1740: if ($rowNum %2 == 1) {
1741: $rowColor = $rowColor1;
1742: } else {
1743: $rowColor = $rowColor2;
1744: }
1745: my $id = $members{$user}[$$idx{id}];
1746: my $fullname = $members{$user}[$$idx{fullname}];
1747: my $udom = $members{$user}[$$idx{udom}];
1748: my $uname = $members{$user}[$$idx{uname}];
1.31 albertel 1749: my $section = $members{$user}[$$idx{section}];
1.3 raeburn 1750: $r->print('<tr bgcolor="'.$rowColor.'"><td align="right">
1751: <input type="checkbox" name="member" value="'.$user.'" /></td><td><small>'.
1752: $fullname.'</small></td><td><small>'.$uname.'</small></td><td><small>'.
1.31 albertel 1753: $udom.'</small></td><td><small>'.$id.'</small></td>'.
1754: '<td><small>'.$section.'</small></td>');
1.5 raeburn 1755: if (@{$available} > 0) {
1756: $r->print('<td align="center"><nobr><small>'.
1757: ' ');
1758: foreach my $tool (@{$available}) {
1759: if ($granularity eq 'Yes') {
1.3 raeburn 1760: $r->print('<input type="checkbox" name="user_'.
1761: $tool.'" value="'.$user.'" />'.$tool.' ');
1762: } else {
1763: $r->print('<input type="hidden" name="user_'.
1764: $tool.'" value="'.$user.'" />'.$tool.' ');
1765: }
1766: }
1.5 raeburn 1767: $r->print('</small></nobr></td>');
1.3 raeburn 1768: }
1769: $r->print('</tr>'."\n");
1770: $rowNum ++;
1771: }
1772: }
1773: $r->print(&Apache::lonhtmlcommon::end_pick_box());
1.5 raeburn 1774: } else {
1775: if ($totalusers > 0) {
1776: $r->print($lt{'nnew'}.'<br /><br />'.$lt{'yoma'});
1777: } else {
1778: $r->print($lt{'nome'});
1779: }
1780: }
1781: return $newusers;
1782: }
1783:
1784: sub privilege_specificity {
1785: my ($r,$tabcol,$rowColor1,$rowColor2,$action,$img,$tools,$stored,
1.29 raeburn 1786: $toolprivs,$fixedprivs,$available,$formname,$gpterm,$ucgpterm) = @_;
1.5 raeburn 1787: my %lt = &Apache::lonlocal::texthash (
1788: 'uprv' => 'User privileges',
1789: 'frty' => 'For each type of functionality you have chosen to include, '.
1790: 'there is a set of standard privileges which apply to all '.
1791: 'of those for whom the functionality is enabled.',
1792: 'thar' => 'There are also additional privileges which can be set for '.
1793: 'some, or all, members. Please choose one of the following:',
1794: 'fort' => 'For the types of functionality you have chosen to include '.
1795: 'there are no additional privileges which can be set for some '.
1796: 'or all members.',
1797: 'eaty' => 'Each of the types of functionality includes standard '.
1798: 'privileges which apply to members with access to that '.
1799: 'functionality, and may also include additional privileges '.
1800: 'which can be set for specific members.',
1.29 raeburn 1801: 'cutg' => "Currently the $gpterm is configured ",
1802: 'sdif' => "so different $gpterm members can receive different privileges.",
1803: 'sall' => "so all $gpterm members will receive the same privileges.",
1804: 'algm' => "All $gpterm members will receive the same privileges.",
1805: 'smgp' => "Some $gpterm members will receive different privileges from ".
1806: "others.",
1807: 'thwi' => "These will be the privileges all $gpterm members receive, ".
1808: "if you selected the first option above.",
1809: 'thes' => "These will be the privileges given to members assigned ".
1810: "in the future, including via automatic $gpterm assignment ".
1811: "for specific sections/roles ",
1812: 'asyo' => "As you have chosen not to include any functionality in the ".
1813: "$gpterm, no default user privileges settings need to be set.",
1.5 raeburn 1814: 'plin' => 'Please indicate which <b>optional</b> privileges members '.
1815: 'will receive by default.',
1816: 'oppr' => 'Optional privileges',
1817: 'defp' => 'The default privileges new members will receive are:',
1818: );
1819: my $totaloptionalprivs = 0;
1820: foreach my $tool (@{$tools}) {
1821: foreach my $priv (sort(keys(%{$$toolprivs{$tool}}))) {
1822: if (!exists($$fixedprivs{$tool}{$priv})) {
1823: $totaloptionalprivs ++;
1824: }
1825: }
1826: }
1.40 albertel 1827: &topic_bar($r,$img,$lt{'uprv'});
1.5 raeburn 1828: if ((($action eq 'create') && (@{$available} > 0)) ||
1829: (($action eq 'modify') && ($formname eq 'change_settings'))) {
1830: my %specific = (
1831: 'No' => 'checked="checked"',
1832: 'Yes' => '',
1833: );
1834: if ($action eq 'create') {
1835: $r->print($lt{'frty'}.'<br />');
1836: if ($totaloptionalprivs) {
1837: $r->print($lt{'thar'});
1838: } else {
1839: $r->print($lt{'fort'});
1840: }
1841: } else {
1842: $r->print($lt{'eaty'}.' '.$lt{cutg});
1843: if ($$stored{'specificity'} eq 'Yes') {
1844: $r->print($lt{'sdif'});
1845: $specific{'Yes'} = $specific{'No'};
1846: $specific{'No'} = '';
1847: } else {
1848: $r->print($lt{'sall'});
1849: }
1850: }
1851: if ($totaloptionalprivs) {
1852: $r->print('
1.40 albertel 1853: <br /><br />
1854: <label><nobr><input type="radio" name="specificity" value="No" '.$specific{'No'}.' /> '.$lt{'algm'}.'</nobr></label><br />
1855: <label><nobr><input type="radio" name="specificity" value="Yes" '.$specific{'Yes'}.' /> '.$lt{'smgp'}.'</nobr></label>');
1.5 raeburn 1856: } else {
1857: $r->print('<input type="hidden" name="specificity" value="No" />');
1858: }
1859: if ($totaloptionalprivs) {
1.40 albertel 1860: $r->print($lt{'plin'});
1.5 raeburn 1861: if ($action eq 'create') {
1862: $r->print(' '.$lt{'thwi'});
1863: }
1864: $r->print('<br />'.$lt{'thes'});
1865: if ($action eq 'create') {
1866: $r->print('('.&mt('if enabled on the next page').').');
1867: } else {
1868: $r->print('('.&mt('if enabled below').').');
1869: }
1870: $r->print('<br /><br />
1.40 albertel 1871: <table><tr>');
1.5 raeburn 1872: &check_uncheck_buttons($r,$formname,'defpriv',$lt{'oppr'});
1873: $r->print('
1874: </tr>
1875: </table>
1.3 raeburn 1876: <br />
1877: ');
1.5 raeburn 1878: } else {
1.40 albertel 1879: $r->print($lt{'algm'}.'<br /><br />');
1.3 raeburn 1880: }
1.42 ! albertel 1881: &default_privileges($r,$action,$tools,$toolprivs,$fixedprivs,
! 1882: $available);
1.3 raeburn 1883: } else {
1.5 raeburn 1884: if ($action eq 'create') {
1885: $r->print($lt{'asyo'});
1886: } elsif ($action eq 'modify' && $formname eq 'pick_members') {
1887: my @defprivs;
1888: if (ref($$stored{'defpriv'}) eq 'ARRAY') {
1889: @defprivs = @{$$stored{'defpriv'}};
1890: }
1891: $r->print($lt{'eaty'}.' '.$lt{cutg});
1892: if ($$stored{'specificity'} eq 'Yes') {
1893: $r->print($lt{'sdif'});
1894: } else {
1895: $r->print($lt{'sall'});
1896: }
1897: $r->print(' '.$lt{'defp'}.'<br /><br />');
1898: &display_defprivs($r,$tabcol,$rowColor1,$rowColor2,$tools,
1899: $toolprivs,\@defprivs);
1900: }
1.3 raeburn 1901: }
1902: return;
1903: }
1904:
1.5 raeburn 1905: sub default_privileges {
1.42 ! albertel 1906: my ($r,$action,$tools,$toolprivs,$fixedprivs,$available) = @_;
1.5 raeburn 1907: my %lt = &Apache::lonlocal::texthash(
1908: 'addp' => 'Additional privileges',
1909: 'fixp' => 'Fixed privileges',
1910: 'oppr' => 'Optional privileges',
1911: 'func' => 'Function',
1912: );
1.42 ! albertel 1913: $r->print(&Apache::lonhtmlcommon::start_pick_box('LC_group_priv_box').
! 1914: &Apache::lonhtmlcommon::row_title($lt{'func'},undef,
! 1915: 'LC_groups_functionality'));
! 1916: $r->print(join('</td><td class="LC_groups_functionality">',@{$tools}));
! 1917: $r->print(&Apache::lonhtmlcommon::row_closure(1));
! 1918: my $fixed = '';
! 1919: my $dynamic = '';
1.3 raeburn 1920: foreach my $tool (@{$tools}) {
1.5 raeburn 1921: my $privcount = 0;
1.42 ! albertel 1922: if ($dynamic ne '') {
! 1923: $dynamic .= '</td><td class="LC_groups_optional">';
! 1924: }
! 1925: $dynamic .= '<table class="LC_group_priv"><tr>';
1.5 raeburn 1926: foreach my $priv (sort(keys(%{$$toolprivs{$tool}}))) {
1927: if (exists($$fixedprivs{$tool}{$priv})) {
1.42 ! albertel 1928: if ($fixed ne '') {
! 1929: $fixed .= '</td><td class="LC_groups_fixed">';
! 1930: }
1.5 raeburn 1931: $fixed .= '<input type="hidden" name="defpriv" value="'.$priv.'" />'.$$toolprivs{$tool}{$priv}.' ';
1932: if ($action eq 'modify') {
1.42 ! albertel 1933: if (grep(/^$tool$/,@{$available})) {
1.5 raeburn 1934: $fixed .= '<small>'.&mt('(on)').'<small> ';
1935: } else {
1936: $fixed .= '<small>'.&mt('(off)').'<small> ';
1.3 raeburn 1937: }
1938: }
1.5 raeburn 1939: } else {
1.42 ! albertel 1940: $privcount++;
1.5 raeburn 1941: if ($privcount == 3) {
1942: $dynamic .= '</tr>
1.42 ! albertel 1943: <tr>'."\n";
1.5 raeburn 1944: }
1.7 raeburn 1945: $dynamic .= '<td><label><input type="checkbox" name="defpriv" value="'.$priv.'" />'.$$toolprivs{$tool}{$priv}.'</label></td>'."\n";
1.3 raeburn 1946: }
1947: }
1.42 ! albertel 1948: if ($privcount == 0) {
! 1949: $dynamic .= '<td>None</td>'."\n";
1.5 raeburn 1950: }
1951: if ($privcount < 3) {
1.42 ! albertel 1952: $dynamic .= '</td>
! 1953: <td> </td>'."\n";
1.5 raeburn 1954: } elsif ($privcount%2) {
1955: $dynamic = '<td> </td>'."\n";
1956: }
1.42 ! albertel 1957: $dynamic .= '</tr></table>';
1.3 raeburn 1958: }
1.42 ! albertel 1959: $r->print(&Apache::lonhtmlcommon::row_title($lt{'fixp'},undef,
! 1960: 'LC_groups_fixed').
! 1961: $fixed.
! 1962: &Apache::lonhtmlcommon::row_closure(1));
! 1963: $r->print(&Apache::lonhtmlcommon::row_title($lt{'oppr'},undef,
! 1964: 'LC_groups_optional').
! 1965: $dynamic.
! 1966: &Apache::lonhtmlcommon::end_pick_box());
1.5 raeburn 1967: $r->print('<br />');
1968: return;
1.42 ! albertel 1969:
1.5 raeburn 1970: }
1971:
1972: sub display_defprivs {
1973: my ($r,$tabcol,$rowColor1,$rowColor2,$tools,$toolprivs,$defprivs) = @_;
1974: my %lt = &Apache::lonlocal::texthash(
1975: 'priv' => 'Privileges',
1976: 'func' => 'Function',
1977: );
1978: $r->print(&Apache::lonhtmlcommon::start_pick_box());
1979: $r->print('<tr>');
1980: my $numrows = 0;
1981: my %currprivs;
1982: foreach my $tool (@{$tools}) {
1983: @{$currprivs{$tool}} = ();
1984: foreach my $priv (sort(keys(%{$$toolprivs{$tool}}))) {
1985: if (ref($defprivs) eq 'ARRAY') {
1986: if (grep/^\Q$priv\E$/,@{$defprivs}) {
1987: push(@{$currprivs{$tool}},$priv);
1988: }
1.3 raeburn 1989: }
1990: }
1.5 raeburn 1991: my $rowcount = int(@{$currprivs{$tool}}/3);
1992: if (@{$currprivs{$tool}}%3 > 0) {
1993: $rowcount ++;
1994: }
1995: if ($rowcount > $numrows) {
1996: $numrows = $rowcount;
1997: }
1998: }
1999: my @rowCols = ($rowColor1,$rowColor2);
2000: foreach my $tool (@{$tools}) {
2001: $r->print('<td align="center" valign="top">
2002: <table cellspacing="0" cellpadding="5">
2003: <tr bgcolor="#cccccc">
2004: <td colspan="3" align="center"><b>'.$tool.'</b></td>
2005: </tr>
2006: ');
2007: my $rownum = 1;
2008: my $privcount = 0;
2009: $r->print('<tr bgcolor="'.$rowColor1.'">');
2010: foreach my $priv (@{$currprivs{$tool}}) {
2011: $privcount ++;
2012: if ($privcount%4 == 0) {
2013: $rownum ++;
2014: my $bgcol = $rownum%2;
2015: $r->print('</tr>
2016: <tr bgcolor="'.$rowCols[$bgcol].'">'."\n");
2017: }
2018: $r->print('<td>'.$$toolprivs{$tool}{$priv}.'</td>'."\n");
2019: }
2020: if ($privcount%3 > 0) {
2021: my $emptycells = 3-($privcount%3);
2022: while($emptycells > 0) {
2023: $r->print('<td> </td>'."\n");
2024: $emptycells --;
2025: }
2026: }
2027: while ($rownum < $numrows) {
2028: $rownum ++;
2029: my $bgcol = $rownum%2;
2030: $r->print('<tr bgcolor="'.$rowCols[$bgcol].'"><td colspan="3"> </td></tr>');
1.3 raeburn 2031: }
1.5 raeburn 2032: $r->print('</table>'."\n".'</td>');
2033: }
2034: $r->print('</tr>'."\n");
2035: $r->print(&Apache::lonhtmlcommon::end_pick_box());
2036: $r->print('<br />');
2037: return;
1.3 raeburn 2038: }
1.5 raeburn 2039:
2040:
2041: sub change_members_form {
2042: my ($r,$cdom,$cnum,$tabcol,$action,$formname,$page,$groupname,$description,
2043: $startdate,$enddate,$tools,$fixedprivs,$functions,$users,$userdata,
1.29 raeburn 2044: $granularity,$quota,$specificity,$idx,$states,$navbuttons,$rowColor1,
2045: $rowColor2,$gpterm,$ucgpterm) = @_;
1.5 raeburn 2046: my %lt = &Apache::lonlocal::texthash(
1.29 raeburn 2047: grse => "$ucgpterm settings",
2048: mogm => "Modify $gpterm membership",
1.5 raeburn 2049: );
2050: my @regexps = ('user_','userpriv_');
2051: $r->print(&Apache::lonhtmlcommon::echo_form_input(
1.6 raeburn 2052: ['origin','action','state','page','expire','deletion',
1.7 raeburn 2053: 'reenable','activate','changepriv','sortby',
2054: 'togglefunc'],\@regexps));
1.5 raeburn 2055: my $rowimg = 1;
2056: my @available = ();
2057: my @unavailable = ();
2058: &check_tools($functions,$tools,\@available,\@unavailable);
2059: my $nexttext = $$navbuttons{'gtns'};
2060: my $prevtext = $$navbuttons{'gtpp'};
2061: $r->print('
1.3 raeburn 2062: <br />
2063: <table width="100%" cellpadding="0" cellspacing="0" border="0">
1.5 raeburn 2064: ');
1.40 albertel 2065: &topic_bar($r,1,$lt{'grse'});
1.5 raeburn 2066: $r->print('
2067: <tr>
1.1 raeburn 2068: <td> </td>
1.5 raeburn 2069: <td colspan="3">
2070: ');
1.40 albertel 2071: &print_current_settings($r,$action,$functions,$startdate,$enddate,
2072: $groupname,$description,$granularity,$quota,
2073: \@available,\@unavailable,$gpterm,$ucgpterm);
1.5 raeburn 2074: $r->print('
2075: </td></tr><tr><td colspan="4"> </td></tr>');
1.40 albertel 2076: &topic_bar($r,2,$lt{'mogm'});
1.5 raeburn 2077: $r->print('
1.3 raeburn 2078: <tr>
2079: <td> </td>
2080: <td colspan="3">
2081: ');
1.5 raeburn 2082: ¤t_membership($r,$cdom,$cnum,$formname,$tabcol,$rowColor1,
2083: $rowColor2,$groupname,\@available,\@unavailable,
2084: $fixedprivs,$granularity,$specificity);
2085: $r->print('</td>');
2086: &display_navbuttons($r,$formname,$$states{$action}[$page-1],$prevtext,
2087: $$states{$action}[$page+1],$nexttext);
2088: $r->print('</table>');
2089: return;
2090: }
2091:
2092: sub current_membership {
2093: my ($r,$cdom,$cnum,$formname,$tabcol,$rowColor1,$rowColor2,$groupname,
2094: $available,$unavailable,$fixedprivs,$granularity,$specificity) = @_;
2095: my %membership = &Apache::lonnet::get_group_membership($cdom,$cnum,
2096: $groupname);
2097: my %lt = &Apache::lonlocal::texthash(
1.6 raeburn 2098: 'actn' => 'Action?',
2099: 'name' => 'Name',
2100: 'usnm' => 'Username',
2101: 'doma' => 'Domain',
2102: 'stda' => 'Start Date',
2103: 'enda' => 'End Date',
1.5 raeburn 2104: 'expi' => 'Expire',
2105: 'reen' => 'Re-enable',
2106: 'acti' => 'Activate',
2107: 'dele' => 'Delete',
2108: 'curf' => 'Current Functionality',
2109: 'chpr' => 'Change Privileges'
2110: );
1.36 raeburn 2111: my ($current,$hastools,$addtools,$num_reenable,$num_activate,$num_expire) =
2112: &Apache::longroup::group_memberlist($cdom,$cnum,$groupname,$fixedprivs,
2113: $available);
2114: if (keys(%{$current}) > 0) {
2115: $r->print('
1.5 raeburn 2116: <tr>
2117: <td> </td>
2118: <td colspan="2">
2119: <table>
2120: <tr>');
1.36 raeburn 2121: if ($num_expire) {
2122: &check_uncheck_buttons($r,$formname,'expire',$lt{'expi'});
2123: }
2124: if ($num_reenable) {
2125: &check_uncheck_buttons($r,$formname,'reenable',$lt{'reen'});
2126: }
2127: if ($num_activate) {
2128: &check_uncheck_buttons($r,$formname,'activate',$lt{'acti'});
2129: }
2130: &check_uncheck_buttons($r,$formname,'deletion',$lt{'dele'});
2131: if (@{$available} > 0) {
2132: if ($specificity eq 'Yes') {
2133: &check_uncheck_buttons($r,$formname,'changepriv',$lt{'chpr'});
1.5 raeburn 2134: }
1.36 raeburn 2135: if ($granularity eq 'Yes') {
2136: $r->print(&check_uncheck_tools($r,$available));
2137: $r->print('
1.5 raeburn 2138: <td>
2139: <nobr>
2140: <fieldset><legend><b>'.$lt{'curf'}.'</b></legend>
2141: <input type="button" value="check all"
2142: onclick="javascript:checkAllTools(document.'.$formname.')" />
2143:
2144: <input type="button" value="uncheck all"
2145: onclick="javascript:uncheckAllTools(document.'.$formname.')" />
2146: </fieldset>
2147: </nobr>
2148: </td>
2149: ');
1.3 raeburn 2150: }
1.36 raeburn 2151: }
2152: $r->print(<<"END");
1.5 raeburn 2153: </tr>
2154: </table>
2155: </td>
2156: <td width="100%"> </td>
2157: </tr>
1.3 raeburn 2158: <tr>
2159: <td colspan="4"> </td>
2160: </tr>
2161: <tr>
2162: <td> </td>
2163: <td colspan="3">
1.5 raeburn 2164: END
1.36 raeburn 2165: $r->print(&Apache::lonhtmlcommon::start_pick_box());
2166: $r->print(<<"END");
1.5 raeburn 2167: <table border="0" cellpadding="4" cellspacing="1">
2168: <tr bgcolor="$tabcol" align="center">
1.6 raeburn 2169: <td><b>$lt{'actn'}</b></td>
2170: <td><b><a href="javascript:changeSort('fullname')">$lt{'name'}</a></b></td>
2171: <td><b><a href="javascript:changeSort('username')">$lt{'usnm'}</a></b>
1.5 raeburn 2172: </td>
1.6 raeburn 2173: <td><b><a href="javascript:changeSort('domain')">$lt{'doma'}</a></b></td>
1.5 raeburn 2174: <td><b><a href="javascript:changeSort('id')">ID</a></b></td>
1.6 raeburn 2175: <td><b><a href="javascript:changeSort('start')">$lt{'stda'}</a></b></td>
2176: <td><b><a href="javascript:changeSort('end')">$lt{'enda'}</a></b></td>
1.5 raeburn 2177: END
1.36 raeburn 2178: my $colspan = 0;
2179: if ($hastools) {
2180: $r->print('<td><b>'.$lt{'curf'}.'</b></td>');
2181: $colspan ++;
2182: }
2183: if ($addtools) {
2184: $r->print('<td><b>Additional Functionality</b></td>');
2185: $colspan ++;
2186: }
2187: $r->print('</tr>');
2188: if ($colspan) {
2189: if ($granularity eq 'Yes') {
2190: $r->print('<tr bgcolor="#cccccc">
1.6 raeburn 2191: <td colspan="7"> </td>
2192: <td colspan="'.$colspan.'" align="center"><small><nobr><b>'.&mt('All:').
2193: '</b> ');
1.36 raeburn 2194: foreach my $tool (@{$available}) {
2195: $r->print('<label><input type="checkbox" name="togglefunc"'.
1.7 raeburn 2196: ' onclick="javascript:toggleTools(document.'.$formname.'.user_'.$tool.',this);"'.
2197: ' value="'.$tool.'">'.'<b>'.$tool.'</b></label> ');
1.6 raeburn 2198: }
1.36 raeburn 2199: $r->print('</nobr></small></td></tr>');
1.6 raeburn 2200: }
1.36 raeburn 2201: }
2202: my %Sortby = ();
2203: foreach my $user (sort(keys(%{$current}))) {
2204: if ($env{'form.sortby'} eq 'fullname') {
2205: push(@{$Sortby{$$current{$user}{fullname}}},$user);
2206: } elsif ($env{'form.sortby'} eq 'username') {
2207: push(@{$Sortby{$$current{$user}{uname}}},$user);
2208: } elsif ($env{'form.sortby'} eq 'domain') {
2209: push(@{$Sortby{$$current{$user}{udom}}},$user);
2210: } elsif ($env{'form.sortby'} eq 'id') {
2211: push(@{$Sortby{$$current{$user}{id}}},$user);
2212: } else {
2213: push(@{$Sortby{$$current{$user}{fullname}}},$user);
2214: }
2215: }
2216: my $rowNum = 0;
2217: my $rowColor;
2218: foreach my $key (sort(keys(%Sortby))) {
2219: foreach my $user (@{$Sortby{$key}}) {
2220: if ($rowNum %2 == 1) {
2221: $rowColor = $rowColor1;
1.5 raeburn 2222: } else {
1.36 raeburn 2223: $rowColor = $rowColor2;
1.5 raeburn 2224: }
1.36 raeburn 2225: my $id = $$current{$user}{id};
2226: my $fullname = $$current{$user}{fullname};
2227: my $udom = $$current{$user}{udom};
2228: my $uname = $$current{$user}{uname};
2229: my $start = $$current{$user}{start};
2230: my $end = $$current{$user}{end};
2231: $r->print('<tr bgcolor="'.$rowColor.'">
2232: <td><small>');
2233: if ($$current{$user}{changestate} eq 'reenable') {
2234: $r->print('<nobr><label>'.
1.5 raeburn 2235: '<input type="checkbox" name="reenable" value="'.$user.'" />'.
1.7 raeburn 2236: $lt{'reen'}.'</label></nobr><br />');
1.36 raeburn 2237: } elsif ($$current{$user}{changestate} eq 'expire') {
2238: $r->print('<nobr><label>'.
1.5 raeburn 2239: '<input type="checkbox" name="expire" value="'.$user.'" />'.
1.7 raeburn 2240: $lt{'expi'}.'</label></nobr><br />');
1.36 raeburn 2241: } elsif ($$current{$user}{changestate} eq 'activate') {
2242: $r->print('<nobr><label>'.
1.5 raeburn 2243: '<input type="checkbox" name="activate" value="'.$user.'" />'.
1.7 raeburn 2244: $lt{'acti'}.'</label></nobr><br />');
1.36 raeburn 2245: }
2246: $r->print('<nobr><label>'.
1.6 raeburn 2247: '<input type="checkbox" name="deletion" value="'.$user.'" />'.
1.7 raeburn 2248: $lt{'dele'}.'</label></nobr>');
1.36 raeburn 2249: if ($specificity eq 'Yes') {
2250: $r->print('<br /><nobr><label>'.
1.5 raeburn 2251: '<input type="checkbox" name="changepriv" value="'.$user.'" />'.$lt{'chpr'}.
1.7 raeburn 2252: '</label></nobr>');
1.36 raeburn 2253: }
2254: $r->print('
1.5 raeburn 2255: </td>
2256: <td><small>'.
2257: $fullname.'</small></td><td><small>'.$uname.'</small></td><td><small>'.
2258: $udom.'</small></td><td><small>'.$id.'</small></td><td><small>'.$start.
2259: '</small></td><td><small>'.$end.'</small></td>');
1.36 raeburn 2260: if ($hastools) {
2261: $r->print('<td align="left"><small><nobr>'.
1.6 raeburn 2262: ' ');
1.36 raeburn 2263: foreach my $tool (@{$$current{$user}{currtools}}) {
2264: if ($granularity eq 'Yes') {
2265: $r->print('<label><input type="checkbox" '.
1.7 raeburn 2266: 'checked="checked" '.
2267: 'name="user_'.$tool.'" value="'.
2268: $user.'" />'.$tool.'</label>');
1.36 raeburn 2269: } else {
2270: $r->print('<input type="hidden" '.
1.7 raeburn 2271: 'checked="checked" '.
2272: 'name="user_'.$tool.'" value="'.
2273: $user.'" />'.$tool);
1.36 raeburn 2274: }
2275: $r->print(' ');
1.5 raeburn 2276: }
1.36 raeburn 2277: $r->print('</nobr></small></td>');
2278: }
2279: if ($addtools) {
2280: $r->print('<td align="left"><small>');
2281: if ($granularity eq 'Yes') {
2282: foreach my $tool (@{$$current{$user}{newtools}}) {
2283: $r->print('<nobr><label><input type="checkbox"
1.5 raeburn 2284: name="user_'.$tool.'" value="'.
2285: $user.'" />'.$tool.
1.7 raeburn 2286: '</label></nobr> ');
1.36 raeburn 2287: }
2288: } else {
2289: foreach my $tool (@{$$current{$user}{newtools}}) {
2290: $r->print('<nobr><input type="hidden"
1.5 raeburn 2291: name="user_'. $tool.'" value="'.
2292: $user.'" />'.$tool.
2293: '</nobr> ');
2294: }
2295: }
1.36 raeburn 2296: $r->print('</small></td>');
1.5 raeburn 2297: }
1.36 raeburn 2298: $r->print('</tr>'."\n");
2299: $rowNum ++;
1.5 raeburn 2300: }
1.36 raeburn 2301: }
2302: $r->print(&Apache::lonhtmlcommon::end_pick_box());
2303: $r->print('
1.3 raeburn 2304: </td>
1.5 raeburn 2305: </tr>');
2306: }
2307: return;
2308: }
2309:
2310: sub check_uncheck_buttons {
2311: my ($r,$formname,$field,$title,$colspan) = @_;
2312: $r->print('
2313: <td '.$colspan.'>
2314: <nobr>
2315: <fieldset>
2316: <legend><b>'.$title.'</b></legend>
2317: <input type="button" value="check all"
2318: onclick="javascript:checkAll(document.'.$formname.'.'.$field.')" />
2319:
2320: <input type="button" value="uncheck all"
2321: onclick="javascript:uncheckAll(document.'.$formname.'.'.$field.')" />
2322: </fieldset>
2323: </nobr>
2324: </td>
2325: ');
2326: }
2327:
2328:
2329: sub change_privs_form {
2330: my ($r,$cdom,$cnum,$tabcol,$action,$formname,$page,$startdate,$enddate,
2331: $tools,$functions,$toolprivs,$fixedprivs,$userdata,$usertools,
2332: $memchg,$idx,$states,$stored,$sectioncount,$navbuttons,$rowColor1,
1.29 raeburn 2333: $rowColor2,$gpterm,$ucgpterm) = @_;
1.5 raeburn 2334: my @regexps = ('userpriv_');
2335: my $nexttext;
1.6 raeburn 2336: my %lt = &Apache::lonlocal::texthash(
2337: 'tode' => 'To be deleted',
2338: 'toex' => 'To be expired',
1.29 raeburn 2339: 'nome' => "No members to be deleted or expired from the $gpterm.",
1.6 raeburn 2340: );
1.5 raeburn 2341: $r->print(&Apache::lonhtmlcommon::echo_form_input(
1.6 raeburn 2342: ['origin','action','state','page','sortby'],\@regexps));
2343: if ($env{'form.branch'} eq 'adds') {
2344: $nexttext = $$navbuttons{'adme'};
2345: } else {
2346: $nexttext = $$navbuttons{'mose'};
2347: }
1.5 raeburn 2348: $r->print('<br /><table width="100%" cellpadding="0" cellspacing="0" border="0">');
1.40 albertel 2349: &topic_bar($r,3,&mt('Members to delete or expire'));
1.6 raeburn 2350: my $exp_or_del = 0;
2351: if (ref($$memchg{'deletion'}) eq 'ARRAY') {
2352: if (@{$$memchg{'deletion'}} > 0) {
2353: $r->print('<tr><td> </td><td colspan="3"><b>'.$lt{'tode'}.':</b><br /><ul>');
2354: foreach my $user (@{$$memchg{'deletion'}}) {
2355: $r->print('<li>'.$$userdata{$user}[$$idx{fullname}].
2356: ' ('.$user.')</li>');
2357: }
2358: $r->print('</ul></td><tr><td colspan="4"> </td></tr>');
2359: $exp_or_del += @{$$memchg{'deletion'}};
2360: }
2361: }
2362: if (ref($$memchg{'expire'}) eq 'ARRAY') {
2363: if (@{$$memchg{'expire'}} > 0) {
2364: $r->print('<tr><td> </td><td colspan="3"><b>'.$lt{'toex'}.':</b><br /><ul>');
2365: foreach my $user (@{$$memchg{'expire'}}) {
2366: $r->print('<li>'.$$userdata{$user}[$$idx{fullname}].
2367: ' ('.$user.')</li>');
2368: }
2369: $r->print('</ul></td><tr><td colspan="4"> </td></tr>');
2370: $exp_or_del += @{$$memchg{'expire'}};
2371: }
2372: }
2373: if (!$exp_or_del) {
2374: $r->print('<tr><td> </td><td colspan="3">'.$lt{'nome'}.
2375: '</td></tr><tr><td colspan="4"> </td></tr>');
2376: }
1.5 raeburn 2377:
1.40 albertel 2378: &topic_bar($r,4,&mt('[_1] member privileges',$ucgpterm));
1.6 raeburn 2379:
2380: my $numchgs = &member_privileges_form($r,$tabcol,$action,$formname,$tools,
2381: $toolprivs,$fixedprivs,$userdata,
2382: $usertools,$idx,$memchg,$states,
1.29 raeburn 2383: $stored,$rowColor1,$rowColor2,
2384: $gpterm);
1.5 raeburn 2385: $r->print('</td></tr><tr><td colspan="4"> </td></tr>');
2386: my $prevtext = $$navbuttons{'gtps'};
1.6 raeburn 2387: if ($numchgs || $exp_or_del) {
2388: &display_navbuttons($r,$formname,$$states{$action}[$page-1],$prevtext,
2389: $$states{$action}[$page+1],$nexttext);
2390: } else {
2391: &display_navbuttons($r,$formname,$$states{$action}[$page-1],$prevtext);
2392: }
1.5 raeburn 2393: $r->print('</table>');
2394: return;
2395: }
2396:
2397: sub add_members_form {
2398: my ($r,$tabcol,$action,$formname,$page,$startdate,$enddate,$groupname,
1.29 raeburn 2399: $description,$granularity,$quota,$sectioncount,$tools,$functions,
2400: $stored,$states,$navbuttons,$rowColor1,$rowColor2,$gpterm,$ucgpterm)=@_;
1.40 albertel 2401: $r->print(' <br />');
1.5 raeburn 2402: my @available = ();
2403: my @unavailable = ();
2404: &check_tools($functions,$tools,\@available,\@unavailable);
1.40 albertel 2405: &print_current_settings($r,$action,$functions,$startdate,$enddate,
2406: $groupname,$description,$granularity,$quota,
2407: \@available,\@unavailable,$gpterm,$ucgpterm);
2408: &membership_options($r,$action,$formname,$sectioncount,1,$gpterm,$ucgpterm);
1.5 raeburn 2409: my $nexttext = $$navbuttons{'gtns'};
2410: my $prevtext = $$navbuttons{'gtpp'};
2411: &display_navbuttons($r,$formname,$$states{$action}[$page-1],$prevtext,
2412: $$states{$action}[$page+1],$nexttext);
2413: return;
2414: }
2415:
2416: sub choose_privs_form {
2417: my ($r,$cdom,$cnum,$tabcol,$action,$formname,$page,$startdate,$enddate,
2418: $tools,$functions,$toolprivs,$fixedprivs,$userdata,$usertools,$idx,
1.29 raeburn 2419: $states,$stored,$sectioncount,$navbuttons,$rowColor1,$rowColor2,
2420: $gpterm,$ucgpterm,$crstype) = @_;
1.5 raeburn 2421:
2422: my @regexps = ('userpriv_');
2423: my $nexttext;
2424:
2425: if ($action eq 'create') {
2426: push(@regexps,'sec_');
2427: $r->print(&Apache::lonhtmlcommon::echo_form_input(
1.6 raeburn 2428: ['origin','action','state','page','sortby','autoadd','autodrop'],
1.5 raeburn 2429: \@regexps));
2430: $nexttext = $$navbuttons{'crgr'};
2431: } else {
2432: $r->print(&Apache::lonhtmlcommon::echo_form_input(
1.6 raeburn 2433: ['origin','action','state','page','sortby'],\@regexps));
1.5 raeburn 2434: $nexttext = $$navbuttons{'adme'};
2435: }
2436:
2437: $r->print('<br /><table width="100%" cellpadding="0" cellspacing="0" border="0">');
1.40 albertel 2438: &topic_bar($r,6,&mt('[_1] member privileges',$ucgpterm));
1.5 raeburn 2439:
2440: &member_privileges_form($r,$tabcol,$action,$formname,$tools,$toolprivs,
2441: $fixedprivs,$userdata,$usertools,$idx,undef,
1.29 raeburn 2442: $states,$stored,$rowColor1,$rowColor2,$gpterm);
1.5 raeburn 2443:
2444: $r->print('</td></tr><tr><td colspan="4"> </td></tr>');
2445: if ($action eq 'create') {
2446: if (keys(%{$sectioncount}) > 0) {
2447: my $img1 = 7;
2448: my $img2 = 8;
2449: &mapping_options($r,$action,$formname,$page,$tabcol,$sectioncount,
2450: $states,$stored,$navbuttons,$img1,$img2,
1.29 raeburn 2451: $rowColor1,$rowColor2,$gpterm,$ucgpterm,$crstype);
1.5 raeburn 2452: }
2453: }
2454: my $prevtext = $$navbuttons{'gtps'};
2455: &display_navbuttons($r,$formname,$$states{$action}[$page-1],$prevtext,
2456: $$states{$action}[$page+1],$nexttext);
2457: $r->print('</table>');
2458: return;
2459: }
2460:
2461: sub build_boxes {
2462: my ($r,$tools,$usertools,$fixedprivs,$toolprivs,$showtools,
1.6 raeburn 2463: $showboxes,$prefix,$specificity,$excluded) = @_;
1.5 raeburn 2464: my $totalboxes = 0;
2465: if (@{$tools} > 0) {
2466: if ($specificity eq 'Yes') {
2467: foreach my $tool (@{$tools}) {
2468: @{$$showboxes{$tool}} = ();
2469: foreach my $user (sort(keys(%{$usertools}))) {
1.6 raeburn 2470: if (ref($excluded) eq 'ARRAY') {
2471: if (grep/^$user$/,@{$excluded}) {
2472: next;
2473: }
1.5 raeburn 2474: }
1.6 raeburn 2475: if ($$usertools{$user}{$tool}) {
2476: unless (grep/^$tool$/,@{$showtools}) {
2477: push(@{$showtools},$tool);
2478: }
2479: foreach my $priv (sort(keys(%{$$toolprivs{$tool}}))) {
2480: unless (exists($$fixedprivs{$tool}{$priv})) {
2481: unless(grep(/^$priv$/,@{$$showboxes{$tool}})) {
2482: push(@{$$showboxes{$tool}},$priv);
2483: $totalboxes ++;
2484: }
1.5 raeburn 2485: }
2486: }
2487: }
2488: }
2489: }
2490: if ($totalboxes > 0) {
2491: $r->print('
2492: <script type="text/javascript">
2493: function checkAllTools(formname) {
2494: ');
2495: foreach my $tool (sort(keys(%{$showboxes}))) {
2496: foreach my $priv (@{$$showboxes{$tool}}) {
2497: $r->print(' checkAll(formname.'.$prefix.$priv.');'."\n");
2498: }
2499: }
2500: $r->print('
2501: }
2502: function uncheckAllTools(formname) {
2503: ');
2504: foreach my $tool (sort(keys(%{$showboxes}))) {
2505: foreach my $priv (@{$$showboxes{$tool}}) {
2506: $r->print(' uncheckAll(formname'.$prefix.$priv.');'."\n");
2507: }
2508: }
2509: $r->print('
2510: }
2511: </script>
2512: ');
2513: }
2514: }
2515: }
2516: return $totalboxes;
2517: }
2518:
2519: sub member_privileges_form {
2520: my ($r,$tabcol,$action,$formname,$tools,$toolprivs,$fixedprivs,$userdata,
1.29 raeburn 2521: $usertools,$idx,$memchg,$states,$stored,$rowColor1,$rowColor2,
2522: $gpterm) = @_;
1.5 raeburn 2523: my %lt = &Apache::lonlocal::texthash(
2524: 'addp' => 'Additional privileges',
2525: 'fixp' => 'Fixed privileges',
2526: 'oppr' => 'Optional privileges',
2527: 'func' => 'Function',
2528: 'forf' => 'For the functionality you have chosen to include '.
2529: 'there are no optional privileges to set besides '.
2530: 'the standard privileges.',
1.29 raeburn 2531: 'algr' => "All $gpterm members will receive the same privileges.",
2532: 'asno' => "As no $gpterm members are being added, ".
2533: "there are no specific user privileges to set.",
2534: 'asng' => "As no $gpterm tools will be made available to users, ".
2535: "there are no specific user privileges to set.",
2536: 'nogm' => "No $gpterm member privileges to display or set, ".
2537: "as you have not indicated that you will be activating,".
2538: " re-enabling, changing privileges, or adding/removing ".
2539: "functionality for any current members ",
1.5 raeburn 2540: 'full' => 'Fullname',
2541: 'user' => 'Username',
2542: 'doma' => 'Domain',
2543: );
2544: my @defprivs;
2545: my $specificity;
2546: if ($action eq 'create') {
2547: if (defined($env{'form.defpriv'})) {
2548: @defprivs = &Apache::loncommon::get_env_multiple('form.defpriv');
2549: }
2550: $specificity = $env{'form.specificity'};
2551: } else {
1.17 raeburn 2552: if (defined($$stored{'defpriv'})) {
2553: @defprivs = @{$$stored{'defpriv'}};
2554: }
1.5 raeburn 2555: $specificity = $$stored{'specificity'};
2556: }
2557: my @showtools;
2558: my %showboxes = ();
2559: my $numtools = 1 + @{$tools};
1.3 raeburn 2560:
1.6 raeburn 2561: my @excluded = ();
2562: my $numchgs = 0;
2563: if ($formname eq 'change_privs') {
2564: my @currmembers = ();
2565: if (ref($$memchg{'deletion'}) eq 'ARRAY') {
2566: push(@excluded,@{$$memchg{'deletion'}});
2567: }
2568: if (ref($$memchg{'expire'}) eq 'ARRAY') {
2569: push(@excluded,@{$$memchg{'expire'}});
2570: }
2571: if (@excluded > 0) {
2572: foreach my $user (sort(keys(%{$usertools}))) {
2573: if (grep/^$user$/,@excluded) {
2574: next;
2575: }
2576: push(@currmembers,$user);
2577: }
2578: } else {
2579: @currmembers = sort(keys(%{$usertools}));
2580: }
2581: $numchgs = @currmembers;
2582: if (!$numchgs) {
2583: $r->print('<tr><td> </td><td colspan="3">'.$lt{'nogm'});
2584: return $numchgs;
2585: }
2586: }
2587:
2588: my $totalboxes = &build_boxes($r,$tools,$usertools,$fixedprivs,
2589: $toolprivs,\@showtools,\%showboxes,
2590: 'userpriv_',$specificity,\@excluded);
1.5 raeburn 2591: if (@{$tools} > 0) {
2592: if ($specificity eq 'Yes') {
2593: if ($totalboxes > 0) {
2594: my $numcells = 2;
2595: my $colspan = $numcells + 1;
2596: my %total;
1.6 raeburn 2597: if (keys(%{$usertools}) > 1) {
2598: $r->print('
1.5 raeburn 2599: <tr>
2600: <td> </td>
2601: <td colspan="3">
2602: <table border="0" cellspacing="2" cellpadding="2" border="0">
2603: <tr>
2604: ');
1.6 raeburn 2605: foreach my $tool (@{$tools}) {
2606: if (@{$showboxes{$tool}} > 0) {
2607: $r->print('<td valign="top">');
2608: $r->print('<table class="thinborder"><tr bgcolor="'.
2609: $tabcol.'"><th colspan="'.$colspan.'">'.
2610: $tool.'</th></tr><tr>');
2611: my $privcount = 0;
2612: foreach my $priv (@{$showboxes{$tool}}) {
2613: $privcount ++;
2614: if (($privcount == @{$showboxes{$tool}}) &&
2615: ($privcount > 1)) {
2616: if ($privcount%$numcells) {
2617: $r->print('<td colspan="'.$colspan.'">');
2618: } else {
2619: $r->print('<td>');
2620: }
1.5 raeburn 2621: } else {
2622: $r->print('<td>');
2623: }
1.6 raeburn 2624: $r->print(qq|
1.5 raeburn 2625: <fieldset><legend><b>$$toolprivs{$tool}{$priv}</b></legend>
2626: <nobr>
2627: <input type="button" value="check all"
2628: onclick="javascript:checkAll(document.$formname.userpriv_$priv)" />
2629:
2630: <input type="button" value="uncheck all"
2631: onclick="javascript:uncheckAll(document.$formname.userpriv_$priv)" />
2632: </nobr></fieldset><br />|);
1.6 raeburn 2633: $r->print('</td>');
2634: if ($privcount < @{$showboxes{$tool}}) {
2635: if (@{$showboxes{$tool}} > 2) {
2636: if ($privcount%$numcells == 0) {
2637: $r->print('</tr><tr>');
2638: }
2639: } else {
2640: $r->print('<tr></tr>');
1.5 raeburn 2641: }
2642: }
2643: }
1.6 raeburn 2644: $r->print('</tr></table></td><td> </td>');
1.5 raeburn 2645: }
2646: }
1.6 raeburn 2647: $r->print('</tr></table></td></tr>');
2648: $r->print('<tr><td colspan="4"> </td></tr>');
1.5 raeburn 2649: }
1.6 raeburn 2650: $r->print('<tr><td> </td><td colspan="3">');
1.5 raeburn 2651: $r->print(&Apache::lonhtmlcommon::start_pick_box());
2652: $r->print(<<"END");
2653: <tr bgcolor="$tabcol">
2654: <th><b>$lt{'full'}</th>
2655: <th><b>$lt{'user'}</th>
2656: <th>$lt{'doma'}</th>
2657: <th colspan="$numtools">$lt{'addp'}</th>
2658: </tr>
2659: END
2660: &member_privs_entries($r,$tabcol,$rowColor1,$rowColor2,
2661: $usertools,$toolprivs,$fixedprivs,
1.6 raeburn 2662: $userdata,$idx,\@showtools,\@defprivs,
2663: \@excluded);
1.5 raeburn 2664: $r->print('</td>');
2665: $r->print(&Apache::lonhtmlcommon::end_pick_box());
2666: $r->print('</td></tr>
2667: <tr>
2668: <td colspan="4"> </td>
2669: </tr>
2670: ');
2671: } else {
2672: $r->print('<tr><td> </td><td colspan="3">'.$lt{'forf'}.
2673: '<br />');
2674: &display_defprivs($r,$tabcol,$rowColor1,$rowColor2,$tools,
2675: $toolprivs,\@defprivs);
2676: }
2677: } else {
2678: if (keys(%{$usertools}) > 0) {
2679: $r->print('<tr><td> </td><td colspan="3">'.$lt{'algr'}.
2680: '<br /><br />');
2681: &display_defprivs($r,$tabcol,$rowColor1,$rowColor2,$tools,
2682: $toolprivs,\@defprivs);
2683: } else {
2684: $r->print('<tr><td> </td><td colspan="3">'.$lt{'asno'}.
2685: '<br />');
2686: }
2687: }
2688: } else {
2689: $r->print('<tr><td> </td><td colspan="3">'.$lt{'asng'});
2690: }
1.6 raeburn 2691: return $numchgs;
1.1 raeburn 2692: }
2693:
1.5 raeburn 2694: sub process_request {
2695: my ($r,$cdom,$cnum,$tabcol,$action,$state,$page,$groupname,$description,
2696: $specificity,$userdata,$startdate,$enddate,$tools,$functions,$toolprivs,
2697: $usertools,$idx,$types,$roles,$sections,$states,$navbuttons,$memchg,
1.29 raeburn 2698: $sectioncount,$stored,$rowColor1,$rowColor2,$gpterm,$ucgpterm,
2699: $crstype) = @_;
1.3 raeburn 2700:
2701: $r->print(&Apache::lonhtmlcommon::echo_form_input(
1.6 raeburn 2702: ['origin','action','state','page','sortby']));
1.5 raeburn 2703:
1.29 raeburn 2704: my $earlyout = &validate_groupname($groupname,$action,$cdom,$cnum,$gpterm,
2705: $ucgpterm,$crstype);
1.5 raeburn 2706: if ($earlyout) {
2707: $r->print('
2708: <table width="100%" cellpadding="0" cellspacing="0" border="0">
2709: <tr>
2710: <td> </td>
2711: <td colspan="3">
2712: '.$earlyout.'</td></tr>');
2713: &display_navbuttons($r,$state,$$states{$action}[$page-1],
2714: $$navbuttons{'gtps'});
2715: $r->print('</table>');
2716: return;
2717: }
2718:
2719: my @defprivs = ();
2720: if ($action eq 'create' || $state eq 'chgresult') {
2721: if (defined($env{'form.defpriv'})) {
2722: @defprivs = &Apache::loncommon::get_env_multiple('form.defpriv');
2723: }
2724: if ($state eq 'chgresult') {
2725: my @okprivs = ();
2726: foreach my $tool (@{$tools}) {
2727: foreach my $priv (sort(keys(%{$$toolprivs{$tool}}))) {
2728: push(@okprivs,$priv);
2729: }
2730: }
2731: my @temp = ();
2732: foreach my $defpriv (@defprivs) {
2733: if (grep/^$defpriv$/,@okprivs) {
2734: push(@temp,$defpriv);
2735: }
2736: }
2737: @defprivs = @temp;
2738: }
2739: } else {
1.17 raeburn 2740: if (defined($$stored{'defpriv'})) {
2741: @defprivs = @{$$stored{'defpriv'}};
2742: }
1.5 raeburn 2743: }
2744:
2745: my $outcome;
2746: if ($action eq 'create' || $state eq 'chgresult') {
2747: $outcome = &write_group_data($r,$cdom,$cnum,$action,$state,$groupname,
2748: $description,$startdate,$enddate,
2749: $specificity,$functions,$tools,
2750: $sectioncount,$roles,$types,$sections,
1.29 raeburn 2751: \@defprivs,$stored,$gpterm,$ucgpterm,
2752: $crstype);
1.5 raeburn 2753: }
2754: if (($action eq 'create' && $outcome eq 'ok') || (($action eq 'modify') &&
2755: (($state eq 'memresult') || ($state eq 'addresult')))) {
1.6 raeburn 2756: &process_membership($r,$cdom,$cnum,$action,$state,$groupname,$tools,
2757: $enddate,$startdate,$userdata,$idx,$toolprivs,
1.29 raeburn 2758: $usertools,$specificity,\@defprivs,$memchg,$gpterm,
2759: $ucgpterm);
1.5 raeburn 2760: }
2761: return;
2762: }
2763:
2764: sub write_group_data {
2765: my ($r,$cdom,$cnum,$action,$state,$groupname,$description,$startdate,
2766: $enddate,$specificity,$functions,$tools,$sectioncount,$roles,$types,
1.29 raeburn 2767: $sections,$defprivs,$stored,$gpterm,$ucgpterm,$crstype) = @_;
1.5 raeburn 2768: my $now = time;
2769: my $creation = $now;
2770: my $creator = $env{'user.name'}.':'.$env{'user.domain'};
2771: if ($state eq 'chgresult') {
2772: $creation = $$stored{'creation'};
2773: $creator = $$stored{'creator'};
2774: }
1.24 www 2775: my $esc_description = &escape($description);
1.5 raeburn 2776: my @single_attributes = ('description','functions','startdate','enddate',
2777: 'creation','modified','creator','granularity',
1.29 raeburn 2778: 'specificity','autoadd','autodrop','quota');
1.5 raeburn 2779: my @mult_attributes = ('roles','types','sectionpick','defpriv');
1.15 albertel 2780:
1.37 raeburn 2781: my ($crsquota,$freespace,$maxposs) = &get_quota_constraints($action,
2782: $stored);
2783: my $quota = $env{'form.quota'};
2784:
2785: $quota =~ s/^\s*([^\s]*)\s*$/$1/;
2786: if ($quota eq '') {
2787: $quota = 0;
2788: }
2789: if ($quota !~ /^\d*\.?\d*$/) {
2790: $quota = 0;
2791: $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));
2792: }
2793: if ($quota > $maxposs) {
2794: $quota = $maxposs;
2795: $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));
2796: }
1.5 raeburn 2797: my %groupinfo = (
2798: description => $esc_description,
2799: startdate => $startdate,
2800: enddate => $enddate,
2801: creation => $creation,
2802: modified => $now,
2803: creator => $creator,
2804: granularity => $env{'form.granularity'},
2805: specificity => $specificity,
2806: autoadd => $env{'form.autoadd'},
2807: autodrop => $env{'form.autodrop'},
1.37 raeburn 2808: quota => $quota,
1.5 raeburn 2809: );
1.37 raeburn 2810:
1.5 raeburn 2811: foreach my $func (keys(%{$functions})) {
2812: my $status;
2813: if (grep(/^$func$/,@{$tools})) {
2814: $status = 'on';
2815: } else {
2816: $status = 'off';
2817: }
2818: $groupinfo{'functions'} .= qq|<name id="$func">$status</name>|;
2819: }
2820:
2821: $groupinfo{'roles'} = $roles;
2822: $groupinfo{'types'} = $types;
2823: $groupinfo{'sectionpick'} = $sections;
2824: $groupinfo{'defpriv'} = $defprivs;
2825:
2826: my %groupsettings = ();
2827: foreach my $item (@single_attributes) {
2828: $groupsettings{$groupname} .= qq|<$item>$groupinfo{$item}</$item>|;
2829: }
2830: foreach my $item (@mult_attributes) {
2831: foreach my $entry (@{$groupinfo{$item}}) {
2832: $groupsettings{$groupname} .= qq|<$item>$entry</$item>|;
2833: }
2834: }
2835: my $autosec;
2836: my @autorole = &Apache::loncommon::get_env_multiple('form.autorole');
1.15 albertel 2837:
1.5 raeburn 2838: foreach my $role (@autorole) {
2839: if (defined($env{'form.sec_'.$role})) {
2840: my @autosections=&Apache::loncommon::get_env_multiple('form.sec_'.
2841: $role);
2842: $autosec .= '<role id="'.$role.'">';
2843: foreach my $sec (@autosections) {
2844: $autosec .= '<section>'.$sec.'</section>';
2845: }
2846: $autosec .= '</role>';
2847: }
2848: }
2849: if ($autosec) {
2850: $groupsettings{$groupname} .= qq|<autosec>$autosec</autosec>|;
2851: }
2852: my $result = &Apache::lonnet::modify_coursegroup($cdom,$cnum,
2853: \%groupsettings);
2854:
2855: if ($result eq 'ok') {
2856: if ($action eq 'create') {
1.32 raeburn 2857: my $result = &add_group_folder($cdom,$cnum,$now,$groupname,$action,
2858: $description,$tools,\%groupinfo,
2859: $gpterm,$ucgpterm,$crstype);
2860: if ($result ne 'ok') {
1.37 raeburn 2861: $r->print(&mt('A problem occurred when creating folders for the new [_1]. [_2].<br />',$gpterm,$result));
1.32 raeburn 2862: }
1.29 raeburn 2863: $r->print(&mt('[_1] [_2] was created.<br />',$ucgpterm,$groupname));
1.5 raeburn 2864: } else {
1.29 raeburn 2865: $r->print(&mt('[_1] [_2] was updated.<br />',$ucgpterm,$groupname));
1.5 raeburn 2866: }
2867: } else {
2868: my %actiontype = (
2869: 'create' => 'creating',
2870: 'modify' => 'modifying',
2871: );
1.29 raeburn 2872: &Apache::lonnet::logthis("Failed to store $gpterm $groupname ".
2873: 'in '.lc($crstype).': '.$cnum.
2874: ' in domain: '.$cdom);
1.37 raeburn 2875: $r->print(&mt('An error occurred when [_1] the [_2]. '.
1.29 raeburn 2876: 'Please try again.',$actiontype{$action},$gpterm));
1.5 raeburn 2877: }
2878: return $result;
2879: }
2880:
2881: sub process_membership {
1.6 raeburn 2882: my ($r,$cdom,$cnum,$action,$state,$groupname,$tools,$enddate,$startdate,
1.29 raeburn 2883: $userdata,$idx,$toolprivs,$usertools,$specificity,$defprivs,$memchg,
2884: $gpterm,$ucgpterm)=@_;
1.5 raeburn 2885: my %usersettings = ();
1.6 raeburn 2886: my %added= ();
2887: my %failed = ();
2888: my $num_ok = 0;
2889: my $num_fail = 0;
1.3 raeburn 2890: my %group_privs = ();
1.20 raeburn 2891: my %curr_privs = ();
1.21 raeburn 2892: my %curr_start = ();
2893: my %curr_end = ();
1.3 raeburn 2894: my %tooltype = ();
1.5 raeburn 2895:
1.3 raeburn 2896: foreach my $tool (@{$tools}) {
2897: foreach my $priv (sort(keys(%{$$toolprivs{$tool}}))) {
2898: $tooltype{$priv} = $tool;
1.5 raeburn 2899: if ($specificity eq 'Yes') {
1.3 raeburn 2900: my @users =
2901: &Apache::loncommon::get_env_multiple('form.userpriv_'.$priv);
2902: foreach my $user (@users) {
2903: $group_privs{$user} .= $priv.':';
1.8 raeburn 2904: if ($state eq 'memresult') {
2905: unless (exists($$usertools{$user}{$tool})) {
2906: $$usertools{$user}{$tool} = 1;
2907: }
2908: }
1.3 raeburn 2909: }
2910: } else {
1.5 raeburn 2911: if (@{$defprivs} > 0) {
1.26 raeburn 2912: if (grep/^\Q$priv\E$/,@{$defprivs}) {
1.5 raeburn 2913: foreach my $user (sort(keys(%{$usertools}))) {
2914: if ($$usertools{$user}{$tool}) {
2915: $group_privs{$user} .= $priv.':';
2916: }
1.3 raeburn 2917: }
2918: }
2919: }
2920: }
2921: }
2922: }
2923: foreach my $user (keys(%group_privs)) {
2924: $group_privs{$user} =~ s/:$//;
2925: }
1.5 raeburn 2926:
1.6 raeburn 2927: my $now = time;
2928: my @activate = ();
2929: my @expire = ();
2930: my @deletion = ();
2931: my @reenable = ();
1.20 raeburn 2932: my @unchanged = ();
1.6 raeburn 2933: if ($state eq 'memresult') {
2934: if (ref($$memchg{'activate'}) eq 'ARRAY') {
2935: @activate = @{$$memchg{'activate'}};
2936: }
2937: if (ref($$memchg{'expire'}) eq 'ARRAY') {
2938: @expire = @{$$memchg{'expire'}};
2939: }
2940: if (ref($$memchg{'deletion'}) eq 'ARRAY') {
2941: @deletion = @{$$memchg{'deletion'}};
2942: }
2943: if (ref($$memchg{'reenable'}) eq 'ARRAY') {
2944: @reenable = @{$$memchg{'reenable'}};
2945: }
1.20 raeburn 2946: my %membership = &Apache::lonnet::get_group_membership($cdom,$cnum,
2947: $groupname);
2948: foreach my $key (sort(keys(%membership))) {
2949: if ($key =~ /^\Q$groupname\E:([^:]+:[^:]+)$/) {
1.21 raeburn 2950: ($curr_end{$1},$curr_start{$1},$curr_privs{$1}) =
2951: split(/:/,$membership{$key},3);
1.20 raeburn 2952: }
2953: }
1.6 raeburn 2954: if (@expire + @deletion > 0) {
2955: foreach my $user (@expire) {
1.21 raeburn 2956: my $savestart = $curr_start{$user};
2957: if ($savestart > $now) {
2958: $savestart = $now;
1.6 raeburn 2959: }
1.21 raeburn 2960: $usersettings{$groupname.':'.$user} = $now.':'.$savestart.':'.
2961: $curr_privs{$user};
1.6 raeburn 2962: if (&Apache::lonnet::modify_group_roles($cdom,$cnum,$groupname,
1.21 raeburn 2963: $user,$now,$savestart,
2964: $curr_privs{$user}) eq 'ok') {
1.6 raeburn 2965: push(@{$added{'expired'}},$user);
2966: $num_ok ++;
2967: } else {
2968: push(@{$failed{'expired'}},$user);
2969: $num_fail ++;
2970: }
2971: }
2972: foreach my $user (@deletion) {
2973: $usersettings{$groupname.':'.$user} = $now.':-1:';
2974: if (&Apache::lonnet::modify_group_roles($cdom,$cnum,$groupname,
2975: $user,$now,'-1','')
2976: eq 'ok') {
2977: push(@{$added{'deleted'}},$user);
2978: $num_ok ++;
2979: } else {
2980: push(@{$failed{'deleted'}},$user);
2981: $num_fail ++;
2982: }
2983: }
2984: }
1.8 raeburn 2985: }
1.6 raeburn 2986:
1.5 raeburn 2987: foreach my $user (sort(keys(%{$usertools}))) {
1.20 raeburn 2988: if ((grep(/^$user$/,@expire)) || (grep(/^$user$/,@deletion))) {
2989: next;
2990: }
1.6 raeburn 2991: my $type;
2992: my $start = $startdate;
2993: my $end = $enddate;
2994: if ($state eq 'memresult') {
2995: if (@activate > 0) {
2996: if (grep/^$user$/,@activate) {
2997: $start = $now;
1.21 raeburn 2998: $end = $enddate;
1.6 raeburn 2999: $type = 'activated';
3000: }
3001: }
3002: if (@reenable > 0) {
3003: if (grep/^$user$/,@reenable) {
1.21 raeburn 3004: $start = $startdate;
3005: $end = $enddate;
1.6 raeburn 3006: $type = 'reenabled';
3007: }
3008: }
1.38 raeburn 3009: if ($type eq '') {
3010: if ($curr_privs{$user} eq $group_privs{$user}) {
3011: push(@unchanged,$user);
3012: next;
3013: }
3014: if (exists($curr_start{$user})) {
3015: $start = $curr_start{$user};
3016: }
3017: if (exists($curr_end{$user})) {
3018: $end = $curr_end{$user};
3019: }
3020: $type = 'modified';
3021: }
1.6 raeburn 3022: } else {
3023: $type = 'added';
3024: }
3025: $usersettings{$groupname.':'.$user} = $end.':'.$start.':'.
1.5 raeburn 3026: $group_privs{$user};
3027: if (&Apache::lonnet::modify_group_roles($cdom,$cnum,$groupname,
1.6 raeburn 3028: $user,$end,$start,
1.5 raeburn 3029: $group_privs{$user}) eq 'ok') {
1.6 raeburn 3030: push(@{$added{$type}},$user);
3031: $num_ok ++;
1.3 raeburn 3032: } else {
1.6 raeburn 3033: push(@{$failed{$type}},$user);
3034: $num_fail ++;
1.5 raeburn 3035: }
3036: }
3037: my $roster_result = &Apache::lonnet::modify_coursegroup_membership($cdom,
3038: $cnum,\%usersettings);
1.6 raeburn 3039: if ($num_ok) {
3040: foreach my $type (sort(keys(%added))) {
3041: $r->print(&mt('The following users were successfully [_1]',$type));
1.20 raeburn 3042: if (!($type eq 'deleted' || $type eq 'expired')) {
1.6 raeburn 3043: $r->print(&mt(' with the following privileges'));
3044: }
3045: $r->print(':<br />');
3046: foreach my $user (@{$added{$type}}) {
1.8 raeburn 3047: my $privlist = '';
3048: if (!($type eq 'deleted' || $type eq 'expired')) {
3049: $privlist = ': ';
1.6 raeburn 3050: my @privs = split(/:/,$group_privs{$user});
3051: my $curr_tool = '';
3052: foreach my $priv (@privs) {
3053: unless ($curr_tool eq $tooltype{$priv}) {
3054: $curr_tool = $tooltype{$priv};
3055: $privlist .= '<b>'.$curr_tool.'</b>: ';
3056: }
3057: $privlist .= $$toolprivs{$curr_tool}{$priv}.', ';
3058: }
3059: $privlist =~ s/, $//;
3060: }
1.8 raeburn 3061: $r->print($$userdata{$user}[$$idx{fullname}].' - '.$user.$privlist.'<br />');
1.6 raeburn 3062: }
1.20 raeburn 3063: $r->print('<br />');
1.6 raeburn 3064: }
3065: }
3066: if ($num_fail) {
3067: foreach my $type (sort(keys(%failed))) {
3068: $r->print(&mt('The following users could not be [_1], because an error occurred:<br />',$type));
3069: foreach my $user (@{$failed{$type}}) {
3070: $r->print($$userdata{$user}[$$idx{fullname}].' - '.$user.'<br />');
3071: }
1.5 raeburn 3072: }
1.20 raeburn 3073: $r->print('<br />');
3074: }
3075: if (@unchanged > 0) {
3076: $r->print(&mt('No change occurred for the following users:<br />'));
3077: foreach my $user (sort(@unchanged)) {
3078: $r->print($$userdata{$user}[$$idx{fullname}].' - '.$user.'<br />');
3079: }
3080: $r->print('<br />');
1.5 raeburn 3081: }
3082: if ($roster_result eq 'ok') {
1.29 raeburn 3083: $r->print('<br />'.&mt('[_1] membership list updated.',$ucgpterm));
1.30 albertel 3084: $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 3085: } else {
1.29 raeburn 3086: $r->print('<br />'.&mt('An error occurred while updating the [_1] membership list -',$gpterm).$roster_result.'<br />');
1.5 raeburn 3087: }
3088: return;
3089: }
3090:
3091: sub mapping_options {
3092: my ($r,$action,$formname,$page,$tabcol,$sectioncount,$states,$stored,
1.29 raeburn 3093: $navbuttons,$img1,$img2,$rowColor1,$rowColor2,$gpterm,$ucgpterm,
3094: $crstype) = @_;
1.5 raeburn 3095: my %lt = &Apache::lonlocal::texthash(
1.29 raeburn 3096: 'auto' => "Settings for automatic $gpterm enrollment",
3097: 'gmma' => "$ucgpterm membership mapping to specific sections/roles",
3098: 'endi' => "Enable/disable automatic $gpterm enrollment for ".
3099: "users in specified roles and sections",
3100: '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.",
3101: '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.",
3102: 'pirs' => "Pick roles and sections for automatic $gpterm enrollment",
1.5 raeburn 3103: 'curr' => 'Currently set to',
3104: 'on' => 'on',
3105: 'off' => 'off',
1.29 raeburn 3106: 'auad' => "Automatically enable $gpterm membership when roles are added?",
3107: 'auex' => "Automatically expire $gpterm membership when roles are removed?",
3108: 'mapr' => "Mapping of roles and sections affected by automatic $gpterm enrollment/disenrollment follows scheme chosen below.",
1.5 raeburn 3109: );
3110: &automapping($r,$action,$tabcol,$stored,\%lt,$img1);
3111: $r->print('
3112: <tr>
3113: <td colspan="4"> </td>
3114: </tr>');
3115: &mapping_settings($r,$tabcol,$rowColor1,$rowColor2,$sectioncount,\%lt,
1.29 raeburn 3116: $stored,$img2,$crstype);
1.5 raeburn 3117: return;
3118: }
3119:
3120: sub automapping {
3121: my ($r,$action,$tabcol,$stored,$lt,$image) = @_;
3122: my $add = 'off';
3123: my $drop = 'off';
3124: if (exists($$stored{'autoadd'})) {
3125: $add = $$stored{'autoadd'};
3126: }
3127: if (exists($$stored{'autodrop'})) {
3128: $drop = $$stored{'autodrop'};
3129: }
1.40 albertel 3130: &topic_bar($r,$image,$$lt{'endi'});
1.5 raeburn 3131: $r->print('
3132: <tr>
3133: <td> </td>
3134: <td colspan="3">
3135: <b>'.$$lt{'gmma'}.':</b><br />'.$$lt{'adds'}.'<br />'.$$lt{'drops'}.'<br />
3136: </td>
3137: </tr>
3138: <tr>
3139: <td colspan="4"> </td>
3140: </tr>
3141: <tr>
3142: <td> </td>
3143: <td colspan="3">
3144: <nobr>'.$$lt{'auad'}.':
1.18 albertel 3145: <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 3146: if ($action eq 'modify') {
3147: $r->print(' ('.$$lt{'curr'}.' <b>'.$$lt{$add}.'</b>)');
3148: }
3149: $r->print('
3150: </nobr>
3151: </td>
3152: </tr>
3153: <tr>
3154: <td> </td>
3155: <td colspan="3">
3156: <nobr>'.$$lt{'auex'}.':
1.18 albertel 3157: <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 3158: if ($action eq 'modify') {
3159: $r->print(' ('.$$lt{'curr'}.' <b>'.$$lt{$drop}.'</b>)');
1.3 raeburn 3160: }
1.5 raeburn 3161: $r->print('</nobr>
3162: </td>
3163: </tr>
3164: <tr>
3165: <td colspan="4"> </td>
3166: </tr>
3167: <tr>
3168: <td> </td>
3169: <td colspan="3">'.$$lt{'mapr'}.'
3170: </td>
3171: </tr>
3172: ');
3173: }
1.3 raeburn 3174:
1.5 raeburn 3175: sub mapping_settings {
1.29 raeburn 3176: my ($r,$tabcol,$rowColor1,$rowColor2,$sectioncount,$lt,$stored,$image,
3177: $crstype) = @_;
1.5 raeburn 3178: my @sections = keys(%{$sectioncount});
3179: if (@sections > 0) {
3180: @sections = sort {$a cmp $b} @sections;
1.17 raeburn 3181: unshift(@sections,'none'); # Put 'no sections' next
3182: unshift(@sections,'all'); # Put 'all' at the front of the list
1.3 raeburn 3183: }
1.40 albertel 3184: &topic_bar($r,$image,$$lt{'pirs'});
1.5 raeburn 3185: $r->print('
3186: <tr>
3187: <td> </td>
3188: <td colspan="3">
3189: ');
3190: my @roles = &standard_roles();
3191: my %customroles = &my_custom_roles();
3192: $r->print(&Apache::lonhtmlcommon::start_pick_box());
3193: $r->print('
3194: <tr bgcolor="'.$tabcol.'">
3195: <th>'.&mt('Active?').'</th>
3196: <th>'.&mt('Role').'</th>');
3197: if (@sections > 0) {
3198: $r->print('<th>'.&mt('Sections').'</th></tr>'."\n");
1.3 raeburn 3199: }
1.5 raeburn 3200: my $rowNum = 0;
3201: my $rowColor;
3202: foreach my $role (@roles) {
1.29 raeburn 3203: my $plrole=&Apache::lonnet::plaintext($role,$crstype);
1.5 raeburn 3204: my $sections_sel;
3205: if (@sections > 0) {
1.17 raeburn 3206: if ($role eq 'cc') {
3207: $sections_sel = '<td align="right">'.
3208: &mt('all sections').'<input type="hidden" '.
3209: 'name="sec_cc" value="all" /></td>';
3210: } else {
3211: $sections_sel='<td align="right">'.
3212: §ions_selection(\@sections,'sec_'.$role).
3213: '</td>';
3214: }
1.5 raeburn 3215: }
3216: if ($rowNum %2 == 1) {
3217: $rowColor = $rowColor1;
3218: } else {
3219: $rowColor = $rowColor2;
1.3 raeburn 3220: }
1.5 raeburn 3221: $r->print('<tr bgcolor="'.$rowColor.'"><td><input type="checkbox" '.
3222: 'name="autorole" value="'.$role.'"></td><td>'.$plrole.
3223: '</td>'.$sections_sel.'</tr>');
3224: $rowNum ++;
3225: }
3226: foreach my $role (sort(keys(%customroles))) {
3227: my $sections_sel;
3228: if (@sections > 0) {
3229: $sections_sel = '<td>'.§ions_selection(\@sections,'sec_'.$role).
3230: '</td>';
1.3 raeburn 3231: }
1.5 raeburn 3232: if ($rowNum %2 == 1) {
3233: $rowColor = $rowColor1;
1.3 raeburn 3234: } else {
1.5 raeburn 3235: $rowColor = $rowColor2;
3236: }
3237: $r->print('<tr bgcolor="'.$rowColor.'"><td><input type="checkbox" '.
3238: 'value="'.$role.'"></td><td>'.$role.'</td>'.
3239: $sections_sel.'</tr>');
3240: $rowNum ++;
3241: }
3242: $r->print(&Apache::lonhtmlcommon::end_pick_box());
3243: return;
3244: }
1.3 raeburn 3245:
1.5 raeburn 3246: sub standard_roles {
1.17 raeburn 3247: my @roles = ('cc','in','ta','ep','st');
1.5 raeburn 3248: return @roles;
3249: }
3250:
3251: sub my_custom_roles {
3252: my %returnhash=();
3253: my %rolehash=&Apache::lonnet::dump('roles');
3254: foreach (keys %rolehash) {
3255: if ($_=~/^rolesdef\_(\w+)$/) {
3256: $returnhash{$1}=$1;
3257: }
3258: }
3259: return %returnhash;
3260: }
3261:
3262: sub modify_menu {
1.29 raeburn 3263: my ($r,$groupname,$page,$gpterm) = @_;
1.5 raeburn 3264: my @menu =
3265: (
1.29 raeburn 3266: { text => "Modify default $gpterm settings",
1.5 raeburn 3267: help => 'Course_Modify_Group',
3268: state => 'change_settings',
3269: branch => 'settings',
3270: },
1.6 raeburn 3271: { text => 'Modify access, tools and/or privileges for previous, '.
3272: 'future, or current members',
1.5 raeburn 3273: help => 'Course_Modify_Group_Membership',
3274: state => 'change_members',
3275: branch => 'members',
3276: },
1.29 raeburn 3277: { text => "Add member(s) to the $gpterm",
1.5 raeburn 3278: help => 'Course_Group_Add_Members',
3279: state => 'add_members',
3280: branch => 'adds',
3281: },
3282: );
3283: my $menu_html = '';
3284: foreach my $menu_item (@menu) {
3285: $menu_html .=
3286: '<p><font size="+1"><a href="/adm/coursegroups?action=modify&refpage='.$env{'form.refpage'}.'&groupname='.$groupname.'&state='.$menu_item->{'state'}.'&branch='.$menu_item->{'branch'}.'">';
3287: $menu_html.= &mt($menu_item->{'text'}).'</a></font>';
3288: if (exists($menu_item->{'help'})) {
3289: $menu_html.=
3290: &Apache::loncommon::help_open_topic($menu_item->{'help'});
3291: }
3292: $menu_html.='</p>'.$/;
1.3 raeburn 3293: }
1.5 raeburn 3294: $r->print($menu_html);
1.3 raeburn 3295: return;
3296: }
3297:
3298: sub member_privs_entries {
1.5 raeburn 3299: my ($r,$tabcol,$rowColor1,$rowColor2,$usertools,$toolprivs,
1.6 raeburn 3300: $fixedprivs,$userdata,$idx,$showtools,$defprivs,$excluded) = @_;
1.3 raeburn 3301: my $rowColor;
3302: my $rowNum = 0;
1.5 raeburn 3303: foreach my $user (sort(keys(%{$usertools}))) {
1.6 raeburn 3304: if (defined($excluded)) {
3305: if (ref($excluded) eq 'ARRAY') {
3306: if (grep/^$user$/,@{$excluded}) {
3307: next;
3308: }
3309: }
3310: }
1.5 raeburn 3311: my ($uname,$udom) = split(/:/,$user);
1.3 raeburn 3312: if ($rowNum %2 == 1) {
3313: $rowColor = $rowColor1;
3314: } else {
3315: $rowColor = $rowColor2;
3316: }
3317: $r->print('<tr bgcolor="'.$rowColor.'">
1.5 raeburn 3318: <td>'.$$userdata{$user}[$$idx{fullname}].'</td>
1.3 raeburn 3319: <td>'.$uname.'</td>
3320: <td>'.$udom.'</td>
3321: <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 3322: foreach my $tool (@{$showtools}) {
3323: if (exists($$usertools{$user}{$tool})) {
1.3 raeburn 3324: $r->print('<td valign="top"><table><tr bgcolor="'.$tabcol.'"><td colspan="2" align="center"><b>'.$tool.'</b></td></tr>');
3325: my $privcount = 0;
3326: my $fixed = '';
3327: my $dynamic = '';
3328: foreach my $priv (sort(keys(%{$$toolprivs{$tool}}))) {
3329: if (exists($$fixedprivs{$tool}{$priv})) {
1.5 raeburn 3330: $fixed .= '<input type="hidden" name="userpriv_'.$priv.'" value="'.$user.'" />'.$$toolprivs{$tool}{$priv}.' ';
1.3 raeburn 3331: } else {
3332: $privcount ++;
3333: if ($privcount == 3) {
3334: $dynamic .= '</tr><tr>';
3335: }
1.7 raeburn 3336: $dynamic .='<td><nobr><label><input type="checkbox" '.
1.5 raeburn 3337: 'name="userpriv_'.$priv.'" value="'.$user.'"';
3338: if (grep/^\Q$priv\E$/,@{$defprivs}) {
3339: $dynamic .= ' checked="checked" ';
3340: }
3341: $dynamic .= ' />'.$$toolprivs{$tool}{$priv}.
1.7 raeburn 3342: '</label></nobr></td>';
1.3 raeburn 3343: }
3344: }
3345: $r->print('<tr><td colspan="2"><nobr>'.$fixed.'</nobr></td></tr><tr>'.$dynamic.'</tr></table></td>');
3346: } else {
1.5 raeburn 3347: $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 3348: }
3349: }
3350: $rowNum ++;
3351: }
3352: }
3353:
3354: sub get_dates_from_form {
3355: my $startdate;
3356: my $enddate;
3357: $startdate = &Apache::lonhtmlcommon::get_date_from_form('startdate');
3358: $enddate = &Apache::lonhtmlcommon::get_date_from_form('enddate');
3359: if ( exists ($env{'form.no_end_date'}) ) {
3360: $enddate = 0;
3361: }
3362: return ($startdate,$enddate);
1.5 raeburn 3363: }
3364:
1.3 raeburn 3365: sub date_setting_table {
3366: my ($starttime,$endtime,$formname) = @_;
3367: my $startform = &Apache::lonhtmlcommon::date_setter($formname,
3368: 'startdate',$starttime);
3369: my $endform = &Apache::lonhtmlcommon::date_setter($formname,
3370: 'enddate',$endtime);
1.41 albertel 3371: my $perpetual =
3372: '<nobr><label><input type="checkbox" name="no_end_date" />'.
3373: &mt('None').'</label></nobr>';
1.42 ! albertel 3374: my $table = "<table class=\"LC_descriptive_input\">\n".
! 3375: '<tr><td class="LC_description">'.&mt('Start:').'</td>'.
1.3 raeburn 3376: '<td>'.$startform.'</td>'.
1.41 albertel 3377: '<td> </td>'."</tr>\n".
1.42 ! albertel 3378: '<tr><td class="LC_description">'.&mt('End:').'</td>'.
1.3 raeburn 3379: '<td>'.$endform.'</td>'.
1.41 albertel 3380: '<td>'.$perpetual.'</td>'."</tr>\n".
3381: "</table>\n";
3382: return $table;
1.1 raeburn 3383: }
3384:
1.32 raeburn 3385: sub add_group_folder {
3386: my ($cdom,$cnum,$now,$groupname,$action,$description,$tools,$groupinfo,
3387: $gpterm,$ucgpterm,$crstype) = @_;
3388: if ($cdom eq '' || $cnum eq '') {
3389: return &mt('Error: invalid course domain or number - group folder creation failed');
3390: }
3391: my ($outcome,$allgrpsmap,$grpmap,$boardsmap,$grppage);
3392: my $navmap = Apache::lonnavmaps::navmap->new();
3393: my $crspath = '/uploaded/'.$cdom.'/'.$cnum.'/';
3394: $allgrpsmap = $crspath.'default_0.sequence';
3395: my $topmap = $navmap->getResourceByUrl($allgrpsmap);
3396: undef($navmap);
3397: if ($action eq 'create') {
3398: # check if default_0.sequence exists.
3399: if (!$topmap) {
3400: my $grpstitle = &mt('[_1] [_2]',$crstype,$ucgpterm);
3401: my $topmap_url = '/'.$env{'course.'.$env{'request.course.id'}.'.url'};
3402: $topmap_url =~ s|/+|/|g;
3403: if ($topmap_url =~ m|^/uploaded|) {
3404: $outcome = &map_updater($cdom,$cnum,'default_0.sequence',
3405: 'toplevelgroup',$grpstitle,$topmap_url);
3406: if ($outcome ne 'ok') {
3407: return $outcome;
3408: }
3409: } else {
3410: $outcome = &mt('Non-standard course - group folder not added.');
3411: return $outcome;
3412: }
3413: }
3414: my $grpfolder = &mt('[_1] Folder -',$ucgpterm,).$description;
3415: $grppage='/adm/'.$cdom.'/'.$cnum.'/'.$groupname.'/grppg';
3416: my $grptitle = &mt('Group homepage').' - '.$description;
3417: my ($seqid,$discussions,$disctitle);
3418: my $outcome = &map_updater($cdom,$cnum,'default_'.$now.'.sequence',
3419: 'grpseq',$grpfolder,$allgrpsmap,$grppage,
3420: $grptitle);
3421: if ($outcome ne 'ok') {
3422: return $outcome;
3423: }
3424: my $pageout = &create_homepage($cdom,$cnum,$groupname,$groupinfo,
3425: $tools,$gpterm,$ucgpterm,$now);
3426: # Link to folder for bulletin boards
3427: $grpmap = $crspath.'default_'.$now.'.sequence';
3428: if (grep/^discussion$/,@{$tools}) {
3429: $seqid = $now + 1;
3430: $disctitle = &mt('Discussion Boards');
3431: my $outcome = &map_updater($cdom,$cnum,'default_'.$seqid.
3432: '.sequence','bbseq',$disctitle,$grpmap);
3433: if ($outcome ne 'ok') {
3434: return $outcome;
3435: }
3436: $boardsmap = $crspath.'default_'.$seqid.'.sequence';
3437: }
3438: } else {
3439: #modify group folder if status of discussions tools is changed
3440: }
3441: my ($furl,$ferr)= &Apache::lonuserstate::readmap($cdom.'/'.$cnum);
1.33 raeburn 3442: $navmap = Apache::lonnavmaps::navmap->new();
1.32 raeburn 3443: # modify parameters
3444: my $parm_result;
3445: if ($action eq 'create') {
3446: if ($allgrpsmap) {
3447: $parm_result .= &parm_setter($navmap,$cdom,$allgrpsmap,$groupname);
3448: }
3449: if ($grpmap) {
3450: $parm_result .= &parm_setter($navmap,$cdom,$grpmap,$groupname);
3451: }
3452: if ($grppage) {
3453: $parm_result .= &parm_setter($navmap,$cdom,$grppage,$groupname);
3454: }
3455: if ($boardsmap) {
3456: $parm_result .= &parm_setter($navmap,$cdom,$boardsmap,$groupname);
3457: }
3458: }
3459: if ($parm_result) {
3460: return $parm_result;
3461: } else {
3462: return 'ok';
3463: }
3464: }
3465:
3466: sub map_updater {
3467: my ($cdom,$cnum,$newfile,$itemname,$itemtitle,$parentmap,$startsrc,
3468: $starttitle,$endsrc,$endtitle) = @_;
3469: my $outcome;
3470: $env{'form.'.$itemname} = &new_map($startsrc,$starttitle,$endsrc,
3471: $endtitle);
3472: my $newmapurl=&Apache::lonnet::finishuserfileupload($cnum,$cdom,$itemname,
3473: $newfile);
3474: if ($newmapurl !~ m|^/uploaded|) {
1.37 raeburn 3475: $outcome = &mt('Error uploading new folder.')." ($newfile): $newmapurl".'<br />';
1.32 raeburn 3476: return $outcome;
3477: }
3478: my ($errtext,$fatal)=&Apache::lonratedt::mapread($parentmap);
3479: if ($fatal) {
1.37 raeburn 3480: $outcome = &mt('Error reading contents of parent folder')." ($parentmap): $errtext".'<br />';
1.32 raeburn 3481: return $outcome;
3482: } else {
3483: my $newidx=&Apache::lonratedt::getresidx($newmapurl);
3484: $Apache::lonratedt::resources[$newidx] = $itemtitle.':'.$newmapurl.
3485: ':false:normal:res';
3486: $Apache::lonratedt::order[1+$#Apache::lonratedt::order]=$newidx;
3487: my ($outtext,$errtext) = &Apache::lonratedt::storemap($parentmap,1);
3488: if ($errtext) {
1.37 raeburn 3489: $outcome = &mt('Error storing updated parent folder')." ($parentmap): $errtext".'<br />';
1.32 raeburn 3490: return $outcome;
3491: }
3492: }
3493: return 'ok';
3494: }
3495:
3496: sub new_map {
3497: my ($startsrc,$starttitle,$endsrc,$endtitle) = @_;
3498: my $newmapstr = '
3499: <map>
3500: <resource id="1" src="'.$startsrc.'" type="start" title="'.$starttitle.'"></resource>
3501: <link from="1" to="2" index="1"></link>
3502: <resource id="2" src="'.$endsrc.'" type="finish" title="'.$endtitle.'"></resource>
3503: </map>
3504: ';
3505: return $newmapstr;
3506: }
3507:
3508: sub parm_setter {
3509: my ($navmap,$cdom,$url,$groupname) = @_;
1.37 raeburn 3510: my $allresults;
1.32 raeburn 3511: my %hide_settings = (
3512: 'course' => {
3513: 'num' => 13,
3514: 'set' => 'yes',
3515: },
3516: 'group' => {
3517: 'num' => 5,
3518: 'set' => 'no',
3519: 'extra' => $groupname,
3520: },
3521: );
3522: my $res = $navmap->getResourceByUrl($url);
3523: my $symb = $res->symb();
3524: foreach my $level (keys(%hide_settings)) {
1.37 raeburn 3525: my $parmresult = &Apache::lonparmset::storeparm_by_symb($symb,
1.32 raeburn 3526: '0_hiddenresource',
3527: $hide_settings{$level}{'num'},
3528: $hide_settings{$level}{'set'},
3529: 'string_yesno',undef,$cdom,
3530: undef,undef,
3531: $hide_settings{$level}{'extra'});
1.37 raeburn 3532: if ($parmresult) {
3533: $allresults .= $level.': '.$parmresult;
3534: }
1.32 raeburn 3535: }
1.37 raeburn 3536: return $allresults;
1.32 raeburn 3537: }
3538:
1.3 raeburn 3539: sub create_homepage {
1.32 raeburn 3540: my ($cdom,$cnum,$name,$groupinfo,$tools,$gpterm,$ucgpterm,$now) = @_;
1.3 raeburn 3541: my $functionality = join(',',@{$tools});
1.24 www 3542: my $content = &unescape($$groupinfo{description});
1.3 raeburn 3543: $content=~s/\s+$//s;
3544: $content=~s/^\s+//s;
3545: $content=~s/\<br\s*\/*\>$//s;
3546: $content=&Apache::lonfeedback::clear_out_html($content,1);
3547:
3548: my %pageinfo = (
1.29 raeburn 3549: 'aaa_title' => "$ucgpterm: $name",
1.3 raeburn 3550: 'abb_links' => $functionality,
3551: 'bbb_content' => $content,
3552: 'ccc_webreferences' => '',
1.32 raeburn 3553: 'uploaded.lastmodified' => $now,
1.3 raeburn 3554: );
3555: my $putresult = &Apache::lonnet::put('grppage_'.$name,\%pageinfo,$cdom,$cnum);
3556: return $putresult;
1.1 raeburn 3557: }
3558:
1.5 raeburn 3559: sub check_uncheck_tools {
3560: my ($r,$available) = @_;
3561: if (ref($available) eq 'ARRAY') {
3562: $r->print('
3563: <script type="text/javascript">
3564: function checkAllTools(formname) {
3565: ');
3566: foreach my $tool (@{$available}) {
3567: $r->print(' checkAll(formname.user_'.$tool.');'."\n");
3568: }
3569: $r->print(' checkAll(formname.togglefunc);'."\n");
3570: $r->print('
3571: }
3572: function uncheckAllTools(formname) {
3573: ');
3574: foreach my $tool (@{$available}) {
3575: $r->print(' uncheckAll(formname.user_'.$tool.');'."\n");
3576: }
3577: $r->print(' uncheckAll(formname.togglefunc);'."\n");
3578: $r->print('
3579: }
3580: function toggleTools(field,caller) {
3581: if (caller.checked) {
3582: checkAll(field);
3583: } else {
3584: uncheckAll(field);
3585: }
3586: return;
3587: }
3588: </script>
3589: ');
3590: }
3591: return;
3592: }
3593:
3594: sub validate_groupname {
1.29 raeburn 3595: my ($groupname,$action,$cdom,$cnum,$gpterm,$ucgpterm,$crstype) = @_;
1.16 albertel 3596: my %sectioncount = &Apache::loncommon::get_sections($cdom,$cnum);
1.17 raeburn 3597: my %curr_groups = &Apache::longroup::coursegroups($cdom,$cnum);
1.15 albertel 3598:
1.5 raeburn 3599: my %lt = &Apache::lonlocal::texthash (
1.29 raeburn 3600: igna => "Invalid $gpterm name",
3601: tgne => "The $gpterm name entered ",
3602: grna => "$ucgpterm names and section names used in a ".
3603: "$crstype must be unique.",
3604: isno => "is not a valid name.",
3605: gnmo => "$ucgpterm names may only contain letters, ".
3606: "numbers or underscores.",
3607: cnnb => "can not be used as it is the name of ",
3608: inth => " in this $crstype",
3609: thgr => "- does not correspond to the name of an ".
3610: "existing $gpterm",
1.5 raeburn 3611: );
1.15 albertel 3612:
1.42 ! albertel 3613: my $exitmsg = '<span class="LC_error">'.$lt{'igna'}.'</span><br /><br />'.
! 3614: $lt{'tgne'}.' "'.$groupname.'" ';
1.5 raeburn 3615: my $dupmsg = $lt{'grna'};
3616: my $earlyout;
3617: if (($groupname eq '') || ($groupname =~ /\W/)) {
3618: $earlyout = $exitmsg.$lt{'isno'}.'<br />'.$lt{'gnmo'};
3619: return $earlyout;
3620: }
1.16 albertel 3621: if (exists($sectioncount{$groupname})) {
3622: return $exitmsg.$lt{'cnnb'}.&mt('a section').$lt{'inth'}.
3623: '<br />'.$lt{'grna'};
1.5 raeburn 3624: }
1.15 albertel 3625: if ($action eq 'create'
3626: && exists($curr_groups{$groupname})) {
3627:
1.29 raeburn 3628: return $exitmsg.$lt{'cnnb'}.&mt('an existing [_1]',$gpterm).
1.15 albertel 3629: $lt{'inth'}.'<br />'.$lt{'grna'};
3630:
1.5 raeburn 3631: } elsif ($action eq 'modify') {
3632: unless(exists($curr_groups{$groupname})) {
1.29 raeburn 3633: $earlyout = &mt('[_1] name:',$ucgpterm).' '.$groupname.$lt{'thgr'}.
3634: $lt{'inth'};
1.5 raeburn 3635: return $earlyout;
3636: }
3637: }
3638: return;
3639: }
3640:
3641: sub topic_bar {
1.40 albertel 3642: my ($r,$imgnum,$title) = @_;
1.5 raeburn 3643: $r->print('
1.40 albertel 3644: <div class="LC_topic_bar">
3645: <img src="/res/adm/pages/bl_step'.$imgnum.'.gif" />
3646: <span>'.$title.'<span>
3647: </div>
1.5 raeburn 3648: ');
3649: return;
3650: }
3651:
3652: sub check_changes {
3653: my ($member_changes,$memchg) = @_;
3654: my %exclusions;
3655: @{$exclusions{'changefunc'}} = ('expire');
3656: @{$exclusions{'changepriv'}} = ('expire','changefunc');
3657:
3658: foreach my $change (@{$member_changes}) {
1.6 raeburn 3659: if ($change eq 'deletion') {
1.5 raeburn 3660: next;
3661: }
1.6 raeburn 3662: my @checks = ('deletion');
1.5 raeburn 3663: if (exists($exclusions{$change})) {
3664: push(@checks,@{$exclusions{$change}});
3665: }
3666: my @temp = ();
3667: foreach my $item (@{$$memchg{$change}}) {
3668: my $match = 0;
3669: foreach my $check (@checks) {
1.6 raeburn 3670: if (defined($$memchg{$check})) {
3671: if (ref(@{$$memchg{$check}}) eq 'ARRAY') {
3672: if (@{$$memchg{$check}} > 0) {
3673: if (grep/^$item$/,@{$$memchg{$check}}) {
3674: $match = 1;
3675: last;
3676: }
3677: }
1.5 raeburn 3678: }
3679: }
3680: }
3681: if ($match) {
3682: next;
3683: }
3684: push(@temp,$item);
3685: }
3686: @{$$memchg{$change}} = @temp;
3687: }
3688: }
1.3 raeburn 3689:
1.1 raeburn 3690: 1;
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>