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