--- loncom/interface/domainprefs.pm 2007/12/11 00:44:23 1.33 +++ loncom/interface/domainprefs.pm 2008/01/04 10:17:13 1.39 @@ -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.39 2008/01/04 10:17:13 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'}], }, @@ -279,11 +281,24 @@ sub handler { ' />  '. '

'); + ' />

'); + my ($numitems,$midpoint,$seconddiv,$count); + $numitems = @prefs_order; + $midpoint = int($numitems/2); + if ($numitems%2) { + $midpoint ++; + } + $count = 0; foreach my $item (@prefs_order) { - $r->print('

'); + $r->print('

'); + $count ++; + if ((!$seconddiv) && ($count >= $midpoint)) { + $r->print('
'."\n".'
'."\n"); + $seconddiv = 1; + } } - $r->print('

'.&mt('Display options').'

'."\n". + $r->print('

'. + &mt('Display options').'

'."\n". '

'.&mt('Display using: ')."\n". '  '. @@ -372,7 +387,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 { @@ -1009,6 +1035,10 @@ sub print_autoenroll { } } my $domform = &Apache::loncommon::select_dom_form($defdom,'sender_domain',1); + my $notif_sender; + if (ref($settings) eq 'HASH') { + $notif_sender = $settings->{'sender_uname'}; + } my $datatable=''. ''. ''; $$rowtotal += 2; return $datatable; @@ -1165,9 +1194,11 @@ sub print_directorysrch { foreach my $title (@{$titleorder}) { if (defined($searchtitles->{$title})) { my $check = ' '; - if (ref($settings->{'searchby'}) eq 'ARRAY') { - if (grep(/^\Q$title\E$/,@{$settings->{'searchby'}})) { - $check = ' checked="checked" '; + if (ref($settings) eq 'HASH') { + if (ref($settings->{'searchby'}) eq 'ARRAY') { + if (grep(/^\Q$title\E$/,@{$settings->{'searchby'}})) { + $check = ' 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 +1349,64 @@ sub print_usercreation { $rowcount ++; } } + if ($rowcount == 0) { + $datatable .= ''; + $$rowtotal ++; + $rowcount ++; + } + } elsif ($position eq 'middle') { + my @creators = ('author','course'); + my ($rules,$ruleorder) = + &Apache::lonnet::inst_userrules($dom,'username'); + 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'); @@ -1357,8 +1423,13 @@ sub print_usercreation { } } } + } else { + foreach my $item (@contexts) { + foreach my $auth (@authtypes) { + $checked{$item}{$auth} = ' checked="checked" '; + } + } } - my @authtypes = ('int','krb4','krb5','loc'); my %title = &context_names(); my %authname = &authtype_names(); my $rownum = 0; @@ -1412,9 +1483,11 @@ sub user_formats_row { $output .= ''; } my $check = ' '; - if (ref($settings->{$type.'_rule'}) eq 'ARRAY') { - if (grep(/^\Q$ruleorder->[$i]\E$/,@{$settings->{$type.'_rule'}})) { - $check = ' checked="checked" '; + if (ref($settings) eq 'HASH') { + if (ref($settings->{$type.'_rule'}) eq 'ARRAY') { + if (grep(/^\Q$ruleorder->[$i]\E$/,@{$settings->{$type.'_rule'}})) { + $check = ' checked="checked" '; + } } } $output .= ''; } my $check = ' '; - if (ref($settings->{'fields'}) eq 'HASH') { - if (ref($settings->{'fields'}{$type}) eq 'ARRAY') { - if (grep(/^\Q$fields->[$i]\E$/,@{$settings->{'fields'}{$type}})) { - $check = ' checked="checked" '; + if (ref($settings) eq 'HASH') { + if (ref($settings->{'fields'}) eq 'HASH') { + if (ref($settings->{'fields'}{$type}) eq 'ARRAY') { + if (grep(/^\Q$fields->[$i]\E$/,@{$settings->{'fields'}{$type}})) { + $check = ' checked="checked" '; + } } } } @@ -2058,7 +2145,7 @@ sub check_configuser { sub check_authorstatus { my ($dom,$confname,%currroles) = @_; my $author_ok; - if (!$currroles{':'.$dom.':au'}) { + if (!$currroles{$confname.':'.$dom.':au'}) { my $start = time; my $end = 0; $author_ok = @@ -2820,7 +2907,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 +2918,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 +2930,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 +3020,7 @@ sub modify_usercreation { my %usercreation_hash = ( usercreation => { - cancreate => \@cancreate, + cancreate => \%cancreate, username_rule => \@username_rule, id_rule => \@id_rule, authtypes => \%authhash, @@ -2933,15 +3033,19 @@ sub modify_usercreation { if (keys(%changes) > 0) { $resulttext = &mt('Changes made:').'
    '; if (ref($changes{'cancreate'}) eq 'ARRAY') { - my $chgtext = '
      '; - foreach my $type (@cancreate) { - $chgtext .= '
    • '.$title{$type}.'
    • '; - } - $chgtext .= '
    '; - if (@cancreate > 0) { - $resulttext .= '
  • '.&mt('Creation of new users is permitted by a Domain Coordinator, and also by other users when: ').$chgtext.'
  • '; - } else { - $resulttext .= '
  • '.&mt("Creation of new users is now only allowed when the user's role is Domain Coordinator.").'
  • '; + my %lt = &usercreation_types(); + foreach my $type (@{$changes{'cancreate'}}) { + my $chgtext; + if ($cancreate{$type} eq 'none') { + $chgtext = $lt{$type}.' '.&mt('creation of new users is not permitted, except by a Domain Coordinator.'); + } elsif ($cancreate{$type} eq 'any') { + $chgtext = $lt{$type}.' '.&mt('creation of new users is permitted for both institutional and non-institutional usernames.'); + } elsif ($cancreate{$type} eq 'official') { + $chgtext = $lt{$type}.' '.&mt('creation of new users is only permitted for institutional usernames.',$lt{$type}); + } elsif ($cancreate{$type} eq 'unofficial') { + $chgtext = $lt{$type}.' '.&mt('creation of new users is only permitted for non-institutional usernames.',$lt{$type}); + } + $resulttext .= '
  • '.$chgtext.'
  • '; } } if (ref($changes{'username_rule'}) eq 'ARRAY') {
'.$item->{'header'}->[2]->{'col1'}.''.$item->{'header'}->[2]->{'col2'}.'
'.&mt('Auto-enrollment active?').''. &mt('username').': '. '  '.&mt('domain'). + $notif_sender.'" size="10" />  '.&mt('domain'). ': '.$domform.'
'. @@ -1297,33 +1328,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 .= '
'.&mt('No format rules have been defined for usernames or IDs in this domain.').'
'.$lt{$item}. + ''; + my @options = ('any'); + if (ref($rules) eq 'HASH') { + if (keys(%{$rules}) > 0) { + push(@options,('official','unofficial')); + } + } + push(@options,'none'); + foreach my $option (@options) { + my $check = ' '; + if ($checked{$item} eq $option) { + $check = ' checked="checked" '; + } + $datatable .= '  '; + } + $datatable .= '
'. @@ -1437,6 +1510,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', @@ -1657,10 +1742,12 @@ sub usertype_update_row { $datatable .= '