--- loncom/interface/domainprefs.pm 2008/06/30 15:56:23 1.59 +++ loncom/interface/domainprefs.pm 2008/07/21 16:24:31 1.66 @@ -1,7 +1,7 @@ # The LearningOnline Network with CAPA # Handler to set domain-wide configuration settings # -# $Id: domainprefs.pm,v 1.59 2008/06/30 15:56:23 bisitz Exp $ +# $Id: domainprefs.pm,v 1.66 2008/07/21 16:24:31 raeburn Exp $ # # Copyright Michigan State University Board of Trustees # @@ -41,6 +41,7 @@ use LONCAPA; use LONCAPA::Enrollment; use File::Copy; use Locale::Language; +use DateTime::TimeZone; sub handler { my $r=shift; @@ -79,7 +80,7 @@ sub handler { my %prefs = ( 'rolecolors' => { text => 'Default color schemes', - help => 'Default_Color_Schemes', + help => 'Domconfig_Color_Schemes', header => [{col1 => 'Student Settings', col2 => '',}, {col1 => 'Coordinator Settings', @@ -91,31 +92,31 @@ sub handler { }, 'login' => { text => 'Log-in page options', - help => 'Domain_Log-in_Page', + help => 'Domconfig_Login_Page', header => [{col1 => 'Item', col2 => '',}], }, 'defaults' => { text => 'Default authentication/language/timezone', - help => '', + help => 'Domconfig_LangTZAuth', header => [{col1 => 'Setting', col2 => 'Value'}], }, 'quotas' => { text => 'Default quotas for user portfolios', - help => 'Default_User_Quota', + help => 'Domconfig_Quotas', header => [{col1 => 'User type', col2 => 'Default quota'}], }, 'autoenroll' => { text => 'Auto-enrollment settings', - help => 'Domain_Auto_Enrollment', + help => 'Domconfig_Auto_Enrollment', header => [{col1 => 'Configuration setting', col2 => 'Value(s)'}], }, 'autoupdate' => { text => 'Auto-update settings', - help => 'Domain_Auto_Update', + help => 'Domconfig_Auto_Updates', header => [{col1 => 'Setting', col2 => 'Value',}, {col1 => 'User population', @@ -123,20 +124,20 @@ sub handler { }, 'directorysrch' => { text => 'Institutional directory searches', - help => 'Domain_Directory_Search', + help => 'Domconfig_InstDirectory_Search', header => [{col1 => 'Setting', col2 => 'Value',}], }, 'contacts' => { text => 'Contact Information', - help => 'Domain_Contact_Information', + help => 'Domconfig_Contact_Info', header => [{col1 => 'Setting', col2 => 'Value',}], }, 'usercreation' => { text => 'User creation', - help => 'Domain_User_Creation', + help => 'Domconfig_User_Creation', header => [{col1 => 'Format rule type', col2 => 'Format rules in force'}, {col1 => 'User account creation', @@ -146,22 +147,24 @@ sub handler { }, 'usermodification' => { text => 'User modification', - help => 'Domain_User_Modification', + help => 'Domconfig_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'}], + col2 => 'User information updateable in course context'}, + {col1 => "Status of user", + col2 => 'Information settable when self-creating account (if directory data blank)'}], }, 'scantron' => { text => 'Scantron format file', - help => 'Domain_Scantron_Formats', + help => 'Domconfig_Scantron_Format', header => [ {col1 => 'Item', col2 => '', }], }, 'coursecategories' => { text => 'Cataloging of courses', - help => 'Domain_Course_Catalog', + help => 'Domconfig_Cataloging_Courses', header => [{col1 => 'Category settings', col2 => '',}, {col1 => 'Categories', @@ -316,7 +319,10 @@ sub handler { } $count = 0; foreach my $item (@prefs_order) { - $r->print('

'); + $r->print('

'. + &Apache::loncommon::help_open_topic($prefs{$item}->{'help'}). + '

'); $count ++; if ((!$seconddiv) && ($count >= $midpoint)) { $r->print(''."\n".'
'."\n"); @@ -379,18 +385,18 @@ sub print_config_box { $output .= ' - '; -# -# FIXME - put the help link back in when the help files exist -# -# '); + '."\n". + ''; $rowtotal ++; if (($action eq 'autoupdate') || ($action eq 'rolecolors') || ($action eq 'usercreation') || ($action eq 'usermodification') || ($action eq 'coursecategories')) { - my $colspan = ($action eq 'rolecolors')?' colspan="2"':''; + my $colspan = ''; + if (($action eq 'rolecolors') || ($action eq 'coursecategories')) { + $colspan = ' colspan="2"'; + } $output .= ' + + +
'.&mt($item->{text}). - ' 
'.&mt($item->{text}).' '. -# &Apache::loncommon::help_open_topic($item->{'help'}).'
'. + &mt($item->{text}).' '. + &Apache::loncommon::help_open_topic($item->{'help'}).'
@@ -420,7 +426,6 @@ sub print_config_box { '; - my $colspan = ($action eq 'coursecategories')?' colspan="2"':''; $output .= ' '; @@ -441,7 +446,19 @@ sub print_config_box { &print_usercreation('bottom',$dom,$settings,\$rowtotal); $rowtotal ++; } elsif ($action eq 'usermodification') { - $output .= &print_usermodification('bottom',$dom,$settings,\$rowtotal); + $output .= &print_usermodification('middle',$dom,$settings,\$rowtotal).' +
'.&mt($item->{'header'}->[1]->{'col1'}).''.&mt($item->{'header'}->[1]->{'col2'}).'
+
+ + + + '. + + &print_usermodification('bottom',$dom,$settings,\$rowtotal); + $rowtotal ++; } elsif ($action eq 'coursecategories') { $output .= &print_coursecategories('bottom',$dom,$item,$settings,\$rowtotal); } else { @@ -1682,10 +1699,14 @@ sub user_formats_row { ); my $css_class = $rowcount%2?' class="LC_odd_row"':''; $output = ''. - ''. - '
'.&mt($item->{'header'}->[2]->{'col1'}).''.&mt($item->{'header'}->[2]->{'col2'}).'
'. - &mt("Format rules to check for $text{$type}: "). - ''; + ''. + '
'; + if ($type eq 'email') { + $output .= &mt("Formats disallowed for $text{$type}: "); + } else { + $output .= &mt("Format rules to check for $text{$type}: "); + } + $output .= ''; my $rem; if (ref($ruleorder) eq 'ARRAY') { for (my $i=0; $i<@{$ruleorder}; $i++) { @@ -1773,7 +1794,7 @@ sub print_usermodification { $$rowtotal ++; $rowcount ++; } - } else { + } elsif ($position eq 'middle') { $context = 'course'; $rowcount = 0; foreach my $role ('st','ep','ta','in','cr') { @@ -1782,6 +1803,20 @@ sub print_usermodification { $$rowtotal ++; $rowcount ++; } + } elsif ($position eq 'bottom') { + $context = 'selfcreate'; + my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom); + $usertypes->{'default'} = $othertitle; + if (ref($types) eq 'ARRAY') { + push(@{$types},'default'); + $usertypes->{'default'} = $othertitle; + foreach my $status (@{$types}) { + $datatable .= &modifiable_userdata_row($context,$status,$settings, + $numinrow,$rowcount,$usertypes); + $$rowtotal ++; + $rowcount ++; + } + } } return $datatable; } @@ -1847,7 +1882,8 @@ sub defaults_titles { sub print_scantronformat { my ($r,$dom,$confname,$settings,$rowtotal) = @_; my $itemcount = 1; - my ($datatable,$css_class,$scantronurl,$is_custom,%error,%scantronurls); + my ($datatable,$css_class,$scantronurl,$is_custom,%error,%scantronurls, + %confhash); my $switchserver = &check_switchserver($dom,$confname); my %lt = &Apache::lonlocal::texthash ( default => 'Default scantron format file error', @@ -1874,23 +1910,52 @@ sub print_scantronformat { ); my %md5chk; foreach my $type (keys(%legacyfile)) { - $md5chk{$type} = split(/ /,`md5sum $legacyfile{$type}`); - chop($md5chk{$type}); + ($md5chk{$type}) = split(/ /,`md5sum $legacyfile{$type}`); + chomp($md5chk{$type}); } if ($md5chk{'default'} ne $md5chk{'custom'}) { foreach my $type (keys(%legacyfile)) { - ($scantronurls{$type},$error{$type}) = + ($scantronurls{$type},my $error) = &legacy_scantronformat($r,$dom,$confname, $type,$legacyfile{$type}, $scantronurls{$type}, $scantronfiles{$type}); + if ($error ne '') { + $error{$type} = $error; + } + } + if (keys(%error) == 0) { + $is_custom = 1; + $confhash{'scantron'}{'scantronformat'} = + $scantronurls{'custom'}; + my $putresult = + &Apache::lonnet::put_dom('configuration', + \%confhash,$dom); + if ($putresult ne 'ok') { + $error{'custom'} = + ''. + &mt('An error occurred updating the domain configuration: [_1]',$putresult).''; + } } } else { - ($scantronurls{'default'},$error{'default'}) = + ($scantronurls{'default'},my $error) = &legacy_scantronformat($r,$dom,$confname, 'default',$legacyfile{'default'}, $scantronurls{'default'}, $scantronfiles{'default'}); + if ($error eq '') { + $confhash{'scantron'}{'scantronformat'} = ''; + my $putresult = + &Apache::lonnet::put_dom('configuration', + \%confhash,$dom); + if ($putresult ne 'ok') { + $error{'default'} = + ''. + &mt('An error occurred updating the domain configuration: [_1]',$putresult).''; + } + } else { + $error{'default'} = $error; + } } } } @@ -1911,39 +1976,59 @@ sub print_scantronformat { $scantronurl = $scantronurls{'default'}; } } else { - $scantronurl = $scantronurls{'default'}; + if ($is_custom) { + $scantronurl = $scantronurls{'custom'}; + } else { + $scantronurl = $scantronurls{'default'}; + } } $css_class = $itemcount%2?' class="LC_odd_row"':''; $datatable .= ''; if (!$is_custom) { - $datatable .= ''; + if (keys(%error) == 0) { + $datatable .= '' - .''. + ''; @@ -1990,7 +2075,7 @@ sub print_coursecategories { ); my %level = &Apache::lonlocal::texthash ( dom => 'Set in "Modify Course" (Domain)', - crs => 'Set in "Parameters" (Course)', + crs => 'Set in "Modify Parameters" (Course)', ); $datatable = ''. ''. @@ -2314,12 +2399,20 @@ sub build_category_rows { } sub modifiable_userdata_row { - my ($context,$role,$settings,$numinrow,$rowcount) = @_; + my ($context,$role,$settings,$numinrow,$rowcount,$usertypes) = @_; my $rolename; - if ($role eq 'cr') { - $rolename = &mt('Custom role'); + if ($context eq 'selfcreate') { + if (ref($usertypes) eq 'HASH') { + $rolename = $usertypes->{$role}; + } else { + $rolename = $role; + } } else { - $rolename = &Apache::lonnet::plaintext($role); + if ($role eq 'cr') { + $rolename = &mt('Custom role'); + } else { + $rolename = &Apache::lonnet::plaintext($role); + } } my @fields = ('lastname','firstname','middlename','generation', 'permanentemail','id'); @@ -4042,10 +4135,11 @@ sub modify_usermodification { $curr_usermodification{$key} = $domconfig{'usermodification'}{$key}; } } - my @contexts = ('author','course'); + my @contexts = ('author','course','selfcreate'); my %context_title = ( author => 'In author context', course => 'In course context', + selfcreate => 'When self creating account', ); my @fields = ('lastname','firstname','middlename','generation', 'permanentemail','id'); @@ -4053,6 +4147,12 @@ sub modify_usermodification { author => ['ca','aa'], course => ['st','ep','ta','in','cr'], ); + my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom); + if (ref($types) eq 'ARRAY') { + push(@{$types},'default'); + $usertypes->{'default'} = $othertitle; + } + $roles{'selfcreate'} = $types; my %fieldtitles = &Apache::loncommon::personal_data_fieldtitles(); my %modifyhash; foreach my $context (@contexts) { @@ -4100,13 +4200,26 @@ sub modify_usermodification { if (ref($changes{$context}) eq 'ARRAY') { foreach my $role (@{$changes{$context}}) { my $rolename; - if ($role eq 'cr') { - $rolename = &mt('Custom'); + if ($context eq 'selfcreate') { + $rolename = $role; + if (ref($usertypes) eq 'HASH') { + if ($usertypes->{$role} ne '') { + $rolename = $usertypes->{$role}; + } + } } else { - $rolename = &Apache::lonnet::plaintext($role); + if ($role eq 'cr') { + $rolename = &mt('Custom'); + } else { + $rolename = &Apache::lonnet::plaintext($role); + } } my @modifiable; - $resulttext .= '
  • '.&mt('Target user with [_1] role',$rolename).' - '.&mt('modifiable fields: '); + if ($context eq 'selfcreate') { + $resulttext .= '
  • '.&mt('Self-creation of account by users with status: [_1] ',$rolename).' - '.&mt('modifiable fields (if institutional data blank): '); + } else { + $resulttext .= '
  • '.&mt('Target user with [_1] role',$rolename).' - '.&mt('modifiable fields: '); + } foreach my $field (@fields) { if ($modifyhash{$context}{$role}{$field}) { push(@modifiable,$fieldtitles{$field}); @@ -4161,8 +4274,7 @@ sub modify_defaults { } } elsif ($item eq 'timezone_def') { if ($newvalues{$item} ne '') { - my @timezones = &DateTime::TimeZone->all_names; - if (!grep(/^\Q$newvalues{$item}\E/,@timezones)) { + if (!DateTime::TimeZone->is_valid_name($newvalues{$item})) { push(@errors,$item); } }
  • '.&mt('Default in use:').'
    '; + $datatable .= '
    '.&mt('Default in use:').'
    '. + ''; if ($scantronurl) { $datatable .= ''. &mt('Default scantron format file').''; } else { $datatable = &mt('File unavailable for display'); } - $datatable .= '
    '.&mt('Upload:').'
    '; + $datatable .= '
    '; + if (!$switchserver) { + $datatable .= &mt('Upload:').'
    '; + } + } else { + my $errorstr; + foreach my $key (sort(keys(%error))) { + $errorstr .= $lt{$key}.': '.$error{$key}.'
    '; + } + $datatable .= '
    '.$errorstr; + } } else { if (keys(%error) > 0) { my $errorstr; foreach my $key (sort(keys(%error))) { $errorstr .= $lt{$key}.': '.$error{$key}.'
    '; } - $datatable .= '
    '.$errorstr.''; + $datatable .= ''.$errorstr.' '; } elsif ($scantronurl) { - $datatable .= '' .&mt('Custom scantron format file').'' - .''.&mt('Replace:').'
    '; + $datatable .= '
    '. + ''. + &mt('Custom scantron format file').' '. + &mt('Replace:').'
    '; } } if (keys(%error) == 0) { if ($switchserver) { $datatable .= &mt('Upload to library server: [_1]',$switchserver); } else { - $datatable .=' '; + $datatable .=' '. + ''; } } $datatable .= '
    '.$title{'togglecats'}.'