--- loncom/interface/domainprefs.pm 2007/09/01 21:20:14 1.26 +++ loncom/interface/domainprefs.pm 2007/09/12 12:01:04 1.27 @@ -1,7 +1,7 @@ # The LearningOnline Network with CAPA # Handler to set domain-wide configuration settings # -# $Id: domainprefs.pm,v 1.26 2007/09/01 21:20:14 raeburn Exp $ +# $Id: domainprefs.pm,v 1.27 2007/09/12 12:01:04 raeburn Exp $ # # Copyright Michigan State University Board of Trustees # @@ -67,7 +67,8 @@ sub handler { } my %domconfig = &Apache::lonnet::get_dom('configuration',['login','rolecolors', - 'quotas','autoenroll','autoupdate','directorysrch'],$dom); + 'quotas','autoenroll','autoupdate','directorysrch', + 'usercreation'],$dom); my @prefs = ( { text => 'Default color schemes', help => 'Default_Color_Schemes', @@ -113,6 +114,12 @@ sub handler { header => [{col1 => 'Setting', col2 => 'Value',}], }, + { text => 'User creation', + help => 'Domain_User_Creation', + action => 'usercreation', + header => [{col1 => 'Setting', + col2 => 'Value',}], + }, ); my @roles = ('student','coordinator','author','admin'); &Apache::lonhtmlcommon::add_breadcrumb @@ -197,6 +204,8 @@ sub process_changes { $output = &modify_autoupdate($dom,%domconfig); } elsif ($action eq 'directorysrch') { $output = &modify_directorysrch($dom,%domconfig); + } elsif ($action eq 'usercreation') { + $output = &modify_user_creation($dom,%domconfig); } return $output; } @@ -289,7 +298,9 @@ sub print_config_box { $r->print(&print_autoenroll($dom,$settings)); } elsif ($action eq 'directorysrch') { $r->print(&print_directorysrch($dom,$settings)); - } + } elsif ($action eq 'usercreation') { + $r->print(&print_usercreation($dom,$settings)); + } } $r->print(' @@ -1000,6 +1011,82 @@ sub print_directorysrch { return $datatable; } +sub print_usercreation { + my ($dom,$settings) = @_; + my $numinrow = 4; + my ($rules,$ruleorder) = &Apache::lonnet::inst_userrules($dom); + my %checked; + if (ref($settings) eq 'HASH') { + if (ref($settings->{'cancreate'}) eq 'ARRAY') { + foreach my $item (@{$settings->{'cancreate'}}) { + $checked{$item} = ' checked="checked" '; + } + } + } + my $datatable = ''.&mt('User creation other than by DC: ').''. + ''. + '
'. + '
'. + '
'; + if (ref($rules) eq 'HASH') { + if (keys(%{$rules}) > 0) { + $datatable .= &username_formats_row($settings,$rules,$ruleorder, + $numinrow); + } + } + return $datatable; +} + +sub username_formats_row { + my ($settings,$rules,$ruleorder,$numinrow) = @_; + my $output = ''. + ''.&mt('Format rules to check for new usernames'). + ''; + my $rem; + if (ref($ruleorder) eq 'ARRAY') { + for (my $i=0; $i<@{$ruleorder}; $i++) { + if (ref($rules->{$ruleorder->[$i]}) eq 'HASH') { + my $rem = $i%($numinrow); + if ($rem == 0) { + if ($i > 0) { + $output .= ''; + } + $output .= ''; + } + my $check = ' '; + if (ref($settings->{'username_rule'}) eq 'ARRAY') { + if (grep(/^\Q$ruleorder->[$i]\E$/,@{$settings->{'username_rule'}})) { + $check = ' checked="checked" '; + } + } + $output .= ''; + } + } + $rem = @{$ruleorder}%($numinrow); + } + my $colsleft = $numinrow - $rem; + if ($colsleft > 1 ) { + $output .= ''; + } elsif ($colsleft == 1) { + $output .= ''; + } + $output .= '
'. + ''. + '  
'; + return $output; +} + sub users_cansearch_row { my ($settings,$types,$usertypes,$dom,$numinrow,$othertitle) = @_; my $output = ''. @@ -2156,6 +2243,100 @@ sub modify_directorysrch { } } else { $resulttext = ''. + &mt('An error occurred: [_1]',$putresult).''; + } + return $resulttext; +} + +sub modify_user_creation { + my ($dom,%domconfig) = @_; + my ($resulttext,%curr_usercreation,%changes); + if (ref($domconfig{'usercreation'}) eq 'HASH') { + foreach my $key (keys(%{$domconfig{'usercreation'}})) { + $curr_usercreation{$key} = $domconfig{'usercreation'}{$key}; + } + } + my %title = &Apache::lonlocal::texthash ( + author => 'adding co-authors/assistant authors', + course => 'adding users to a course', + ); + my @username_rule = &Apache::loncommon::get_env_multiple('form.username_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); + } + } + foreach my $type (@cancreate) { + if (!grep(/^\Q$type\E$/,@{$curr_usercreation{'cancreate'}})) { + push(@{$changes{'cancreate'}},$type); + } + } + } else { + push(@{$changes{'cancreate'}},@cancreate); + } + if (ref($curr_usercreation{'username_rule'}) eq 'ARRAY') { + foreach my $type (@{$curr_usercreation{'username_rule'}}) { + if (!grep(/^\Q$type\E$/,@username_rule)) { + push(@{$changes{'username_rule'}},$type); + } + } + foreach my $type (@username_rule) { + if (!grep(/^\Q$type\E$/,@{$curr_usercreation{'username_rule'}})) { + push(@{$changes{'username_rule'}},$type); + } + } + } else { + push(@{$changes{'username_rule'}},@username_rule); + } + + my %usercreation_hash = ( + usercreation => { + cancreate => \@cancreate, + username_rule => \@username_rule, + } + ); + + my $putresult = &Apache::lonnet::put_dom('configuration',\%usercreation_hash, + $dom); + if ($putresult eq 'ok') { + if (keys(%changes) > 0) { + $resulttext = &mt('Changes made:').''; + } else { + $resulttext = &mt('No changes made to log-in page settings'); + } + } else { + $resulttext = ''. &mt('An error occurred: [_1]',$putresult).''; } return $resulttext;