--- loncom/interface/domainprefs.pm 2007/11/10 03:51:46 1.32 +++ 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.32 2007/11/10 03:51:46 raeburn Exp $ +# $Id: domainprefs.pm,v 1.34 2007/12/12 19:44:53 raeburn Exp $ # # Copyright Michigan State University Board of Trustees # @@ -68,10 +68,10 @@ sub handler { my %domconfig = &Apache::lonnet::get_dom('configuration',['login','rolecolors', 'quotas','autoenroll','autoupdate','directorysrch', - 'usercreation','contacts'],$dom); + 'usercreation','usermodification','contacts'],$dom); my @prefs_order = ('rolecolors','login','quotas','autoenroll', 'autoupdate','directorysrch','contacts', - 'usercreation'); + 'usercreation','usermodification'); my %prefs = ( 'rolecolors' => { text => 'Default color schemes', @@ -127,11 +127,21 @@ 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'}], }, + 'usermodification' => + { text => 'User modification', + help => 'Domain_User_Modification', + header => [{col1 => 'Target user has role', + col2 => 'User information updateable in author context'}, + {col1 => 'Target user has role', + col2 => 'User information updateable in course context'}], + }, ); my @roles = ('student','coordinator','author','admin'); my @actions = &Apache::loncommon::get_env_multiple('form.actions'); @@ -306,6 +316,8 @@ sub process_changes { $output = &modify_directorysrch($dom,%domconfig); } elsif ($action eq 'usercreation') { $output = &modify_usercreation($dom,%domconfig); + } elsif ($action eq 'usermodification') { + $output = &modify_usermodification($dom,%domconfig); } elsif ($action eq 'contacts') { $output = &modify_contacts($dom,%domconfig); } @@ -327,7 +339,7 @@ sub print_config_box { # '); $rowtotal ++; if (($action eq 'autoupdate') || ($action eq 'rolecolors') || - ($action eq 'usercreation')) { + ($action eq 'usercreation') || ($action eq 'usermodification')) { my $colspan = ($action eq 'rolecolors')?' colspan="2"':''; $output .= ' @@ -341,7 +353,9 @@ sub print_config_box { if ($action eq 'autoupdate') { $output .= &print_autoupdate('top',$dom,$settings,\$rowtotal); } elsif ($action eq 'usercreation') { - $output .= &print_usercreation('top',$dom,$settings,\$rowtotal); + $output .= &print_usercreation('top',$dom,$settings,\$rowtotal); + } elsif ($action eq 'usermodification') { + $output .= &print_usermodification('top',$dom,$settings,\$rowtotal); } else { $output .= &print_rolecolors($phase,'student',$dom,$confname,$settings,\$rowtotal); } @@ -360,7 +374,20 @@ 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 { $output .= &print_rolecolors($phase,'coordinator',$dom,$confname,$settings,\$rowtotal).'
'.$item->{'header'}->[2]->{'col1'}.''.$item->{'header'}->[2]->{'col2'}.'
@@ -1056,14 +1083,7 @@ sub print_autoupdate { my ($othertitle,$usertypes,$types) = &sorted_inst_types($dom); my @fields = ('lastname','firstname','middlename','gen', 'permanentemail','id'); - my %fieldtitles = &Apache::lonlocal::texthash ( - id => 'Student/Employee ID', - permanentemail => 'E-mail address', - lastname => 'Last Name', - firstname => 'First Name', - middlename => 'Middle Name', - gen => 'Generation', - ); + my %fieldtitles = &Apache::loncommon::personal_data_fieldtitles(); my $numrows = 0; if (ref($types) eq 'ARRAY') { if (@{$types} > 0) { @@ -1290,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 = ''. - ''.$lt{'nondc'}. - ''; - foreach my $item ('author','course') { - $datatable .= ''; - } - $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, @@ -1334,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 .= ''. + ''.$lt{$item}. + ''; + foreach my $option ('any','official','unofficial','none') { + my $check = ' '; + if ($checked{$item} eq $option) { + $check = ' checked="checked" '; + } + $datatable .= '  '; + } + $datatable .= ''; + } } else { my @contexts = ('author','course','domain'); my @authtypes = ('int','krb4','krb5','loc'); @@ -1430,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', @@ -1449,6 +1502,96 @@ sub context_names { return %context_title; } +sub print_usermodification { + my ($position,$dom,$settings,$rowtotal) = @_; + my $numinrow = 4; + my ($context,$datatable,$rowcount); + if ($position eq 'top') { + $rowcount = 0; + $context = 'author'; + foreach my $role ('ca','aa') { + $datatable .= &modifiable_userdata_row($context,$role,$settings, + $numinrow,$rowcount); + $$rowtotal ++; + $rowcount ++; + } + } else { + $context = 'course'; + $rowcount = 0; + foreach my $role ('st','ep','ta','in','cr') { + $datatable .= &modifiable_userdata_row($context,$role,$settings, + $numinrow,$rowcount); + $$rowtotal ++; + $rowcount ++; + } + } + return $datatable; +} + +sub modifiable_userdata_row { + my ($context,$role,$settings,$numinrow,$rowcount) = @_; + my $rolename; + if ($role eq 'cr') { + $rolename = &mt('Custom role'); + } else { + $rolename = &Apache::lonnet::plaintext($role); + } + my @fields = ('lastname','firstname','middlename','generation', + 'permanentemail','id'); + my %fieldtitles = &Apache::loncommon::personal_data_fieldtitles(); + my $output; + my $css_class = $rowcount%2?' class="LC_odd_row"':''; + $output = ''. + ''.$rolename.''. + ''; + my $rem; + my %checks; + if (ref($settings) eq 'HASH') { + if (ref($settings->{$context}) eq 'HASH') { + if (ref($settings->{$context}->{$role}) eq 'HASH') { + foreach my $field (@fields) { + if ($settings->{$context}->{$role}->{$field}) { + $checks{$field} = ' checked="checked" '; + } + } + } + } + } + for (my $i=0; $i<@fields; $i++) { + my $rem = $i%($numinrow); + if ($rem == 0) { + if ($i > 0) { + $output .= ''; + } + $output .= ''; + } + my $check = ' '; + if (exists($checks{$fields[$i]})) { + $check = $checks{$fields[$i]} + } else { + if ($role eq 'st') { + if (ref($settings) ne 'HASH') { + $check = ' checked="checked" '; + } + } + } + $output .= ''; + $rem = @fields%($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) = @_; @@ -2723,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 = ''. @@ -2734,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}; @@ -2746,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)) { @@ -2823,7 +2979,7 @@ sub modify_usercreation { my %usercreation_hash = ( usercreation => { - cancreate => \@cancreate, + cancreate => \%cancreate, username_rule => \@username_rule, id_rule => \@id_rule, authtypes => \%authhash, @@ -2836,15 +2992,19 @@ sub modify_usercreation { if (keys(%changes) > 0) { $resulttext = &mt('Changes made:').'