--- loncom/interface/domainprefs.pm 2007/12/11 00:44:23 1.33 +++ loncom/interface/domainprefs.pm 2007/12/12 19:44:53 1.34 @@ -1,7 +1,7 @@ # The LearningOnline Network with CAPA # Handler to set domain-wide configuration settings # -# $Id: domainprefs.pm,v 1.33 2007/12/11 00:44:23 raeburn Exp $ +# $Id: domainprefs.pm,v 1.34 2007/12/12 19:44:53 raeburn Exp $ # # Copyright Michigan State University Board of Trustees # @@ -127,8 +127,10 @@ sub handler { 'usercreation' => { text => 'User creation', help => 'Domain_User_Creation', - header => [{col1 => 'Setting', - col2 => 'Value',}, + header => [{col1 => 'Format Rule Type', + col2 => 'Format Rules in force'}, + {col1 => 'User account creation', + col2 => 'Usernames which may be created',}, {col1 => 'Context', col2 => 'Assignable Authentication Types'}], }, @@ -372,7 +374,18 @@ sub print_config_box { if ($action eq 'autoupdate') { $output .= &print_autoupdate('bottom',$dom,$settings,\$rowtotal); } elsif ($action eq 'usercreation') { - $output .= &print_usercreation('bottom',$dom,$settings,\$rowtotal); + $output .= &print_usercreation('middle',$dom,$settings,\$rowtotal).' + + + + + + + + + '. + &print_usercreation('bottom',$dom,$settings,\$rowtotal); + $rowtotal ++; } elsif ($action eq 'usermodification') { $output .= &print_usermodification('bottom',$dom,$settings,\$rowtotal); } else { @@ -1297,33 +1310,10 @@ sub print_usercreation { my ($position,$dom,$settings,$rowtotal) = @_; my $numinrow = 4; my $datatable; - my %lt = &Apache::lonlocal::texthash ( - nondc => 'User creation other than by Domain Coordinator: ', - author => 'When adding a co-author/assistant author', - course => 'When adding users to a course', - ); if ($position eq 'top') { - my %checked; - if (ref($settings) eq 'HASH') { - if (ref($settings->{'cancreate'}) eq 'ARRAY') { - foreach my $item (@{$settings->{'cancreate'}}) { - $checked{$item} = ' checked="checked" '; - } - } - } - $datatable = ''. - ''; $$rowtotal ++; - my ($rules,$ruleorder) = &Apache::lonnet::inst_userrules($dom,'username'); my $rowcount = 0; + my ($rules,$ruleorder) = &Apache::lonnet::inst_userrules($dom,'username'); if (ref($rules) eq 'HASH') { if (keys(%{$rules}) > 0) { $datatable .= &user_formats_row('username',$settings,$rules, @@ -1341,6 +1331,50 @@ sub print_usercreation { $rowcount ++; } } + } elsif ($position eq 'middle') { + my @creators = ('author','course'); + my %lt = &usercreation_types(); + my %checked; + if (ref($settings) eq 'HASH') { + if (ref($settings->{'cancreate'}) eq 'HASH') { + foreach my $item (@creators) { + $checked{$item} = $settings->{'cancreate'}{$item}; + } + } elsif (ref($settings->{'cancreate'}) eq 'ARRAY') { + foreach my $item (@creators) { + if (grep(/^\Q$item\E$/,@{$settings->{'cancreate'}})) { + $checked{$item} = 'none'; + } + } + } + } + my $rownum = 0; + foreach my $item (@creators) { + $rownum ++; + if ($checked{$item} eq '') { + $checked{$item} = 'any'; + } + my $css_class; + if ($rownum%2) { + $css_class = ''; + } else { + $css_class = ' class="LC_odd_row" '; + } + $datatable .= ''. + ''; + } } else { my @contexts = ('author','course','domain'); my @authtypes = ('int','krb4','krb5','loc'); @@ -1437,6 +1471,18 @@ sub user_formats_row { return $output; } +sub usercreation_types { + my %lt = &Apache::lonlocal::texthash ( + author => 'When adding a co-author', + course => 'When adding a user to a course', + any => 'Any', + official => 'Institutional only ', + unofficial => 'Non-institutional only', + none => 'None', + ); + return %lt; +} + sub authtype_names { my %lt = &Apache::lonlocal::texthash( int => 'Internal', @@ -2820,7 +2866,7 @@ sub modify_contacts { } $resulttext .= ''; } else { - $resulttext = &mt('No changes made to contact information.'); + $resulttext = &mt('No changes made to contact information'); } } else { $resulttext = ''. @@ -2831,7 +2877,7 @@ sub modify_contacts { sub modify_usercreation { my ($dom,%domconfig) = @_; - my ($resulttext,%curr_usercreation,%changes,%authallowed); + my ($resulttext,%curr_usercreation,%changes,%authallowed,%cancreate); if (ref($domconfig{'usercreation'}) eq 'HASH') { foreach my $key (keys(%{$domconfig{'usercreation'}})) { $curr_usercreation{$key} = $domconfig{'usercreation'}{$key}; @@ -2843,21 +2889,34 @@ sub modify_usercreation { ); my @username_rule = &Apache::loncommon::get_env_multiple('form.username_rule'); my @id_rule = &Apache::loncommon::get_env_multiple('form.id_rule'); - my @cancreate = &Apache::loncommon::get_env_multiple('form.can_createuser'); - if (ref($curr_usercreation{'cancreate'}) eq 'ARRAY') { - foreach my $type (@{$curr_usercreation{'cancreate'}}) { - if (!grep(/^\Q$type\E$/,@cancreate)) { - push(@{$changes{'cancreate'}},$type); - } + my @contexts = ('author','course'); + foreach my $item(@contexts) { + $cancreate{$item} = $env{'form.can_createuser_'.$item}; + } + if (ref($curr_usercreation{'cancreate'}) eq 'HASH') { + foreach my $item (@contexts) { + if ($curr_usercreation{'cancreate'}{$item} ne $cancreate{$item}) { + push(@{$changes{'cancreate'}},$item); + } } - foreach my $type (@cancreate) { - if (!grep(/^\Q$type\E$/,@{$curr_usercreation{'cancreate'}})) { - push(@{$changes{'cancreate'}},$type); + } elsif (ref($curr_usercreation{'cancreate'}) eq 'ARRAY') { + foreach my $item (@contexts) { + if (grep(/^\Q$item\E$/,@{$curr_usercreation{'cancreate'}})) { + if ($cancreate{$item} ne 'any') { + push(@{$changes{'cancreate'}},$item); + } + } else { + if ($cancreate{$item} ne 'none') { + push(@{$changes{'cancreate'}},$item); + } } } } else { - push(@{$changes{'cancreate'}},@cancreate); + foreach my $item ('author','course') { + push(@{$changes{'cancreate'}},$item); + } } + if (ref($curr_usercreation{'username_rule'}) eq 'ARRAY') { foreach my $type (@{$curr_usercreation{'username_rule'}}) { if (!grep(/^\Q$type\E$/,@username_rule)) { @@ -2920,7 +2979,7 @@ sub modify_usercreation { my %usercreation_hash = ( usercreation => { - cancreate => \@cancreate, + cancreate => \%cancreate, username_rule => \@username_rule, id_rule => \@id_rule, authtypes => \%authhash, @@ -2933,15 +2992,19 @@ sub modify_usercreation { if (keys(%changes) > 0) { $resulttext = &mt('Changes made:').'
'.$item->{'header'}->[2]->{'col1'}.''.$item->{'header'}->[2]->{'col2'}.'
'.$lt{'nondc'}. - ''; - foreach my $item ('author','course') { - $datatable .= ''; - } - $datatable .= '
'.$lt{$item}. + ''; + foreach my $option ('any','official','unofficial','none') { + my $check = ' '; + if ($checked{$item} eq $option) { + $check = ' checked="checked" '; + } + $datatable .= '  '; + } + $datatable .= '