--- loncom/interface/domainprefs.pm 2008/06/24 15:01:23 1.56 +++ loncom/interface/domainprefs.pm 2009/03/08 20:26:32 1.90 @@ -1,7 +1,7 @@ # The LearningOnline Network with CAPA # Handler to set domain-wide configuration settings # -# $Id: domainprefs.pm,v 1.56 2008/06/24 15:01:23 bisitz Exp $ +# $Id: domainprefs.pm,v 1.90 2009/03/08 20:26:32 weissno Exp $ # # Copyright Michigan State University Board of Trustees # @@ -37,10 +37,13 @@ use Apache::loncommon(); use Apache::lonhtmlcommon(); use Apache::lonlocal; use Apache::lonmsg(); -use LONCAPA; +use LONCAPA qw(:DEFAULT :match); use LONCAPA::Enrollment; +use LONCAPA::lonauthcgi(); use File::Copy; use Locale::Language; +use DateTime::TimeZone; +use DateTime::Locale; sub handler { my $r=shift; @@ -62,7 +65,7 @@ sub handler { } &Apache::lonhtmlcommon::clear_breadcrumbs(); &Apache::loncommon::get_unprocessed_cgi($ENV{'QUERY_STRING'}, - ['phase']); + ['phase','actions']); my $phase = 'pickactions'; if ( exists($env{'form.phase'}) ) { $phase = $env{'form.phase'}; @@ -71,15 +74,16 @@ sub handler { &Apache::lonnet::get_dom('configuration',['login','rolecolors', 'quotas','autoenroll','autoupdate','directorysrch', 'usercreation','usermodification','contacts','defaults', - 'scantron','coursecategories'],$dom); + 'scantron','coursecategories','serverstatuses', + 'requestcourses'],$dom); my @prefs_order = ('rolecolors','login','defaults','quotas','autoenroll', 'autoupdate','directorysrch','contacts', 'usercreation','usermodification','scantron', - 'coursecategories'); + 'requestcourses','coursecategories','serverstatuses'); my %prefs = ( 'rolecolors' => { text => 'Default color schemes', - help => 'Default_Color_Schemes', + help => 'Domain_Configuration_Color_Schemes', header => [{col1 => 'Student Settings', col2 => '',}, {col1 => 'Coordinator Settings', @@ -91,31 +95,32 @@ sub handler { }, 'login' => { text => 'Log-in page options', - help => 'Domain_Log-in_Page', + help => 'Domain_Configuration_Login_Page', header => [{col1 => 'Item', col2 => '',}], }, 'defaults' => { text => 'Default authentication/language/timezone', - help => '', + help => 'Domain_Configuration_LangTZAuth', header => [{col1 => 'Setting', col2 => 'Value'}], }, 'quotas' => - { text => 'Default quotas for user portfolios', - help => 'Default_User_Quota', - header => [{col1 => 'User type', - col2 => 'Default quota'}], + { text => 'User blogs, personal information pages and portfolios', + help => 'Domain_Configuration_Quotas', + header => [{col1 => 'User affiliation', + col2 => 'Available tools', + col3 => 'Portfolio quota',}], }, 'autoenroll' => { text => 'Auto-enrollment settings', - help => 'Domain_Auto_Enrollment', + help => 'Domain_Configuration_Auto_Enrollment', header => [{col1 => 'Configuration setting', col2 => 'Value(s)'}], }, 'autoupdate' => { text => 'Auto-update settings', - help => 'Domain_Auto_Update', + help => 'Domain_Configuration_Auto_Updates', header => [{col1 => 'Setting', col2 => 'Value',}, {col1 => 'User population', @@ -123,20 +128,20 @@ sub handler { }, 'directorysrch' => { text => 'Institutional directory searches', - help => 'Domain_Directory_Search', + help => 'Domain_Configuration_InstDirectory_Search', header => [{col1 => 'Setting', col2 => 'Value',}], }, 'contacts' => { text => 'Contact Information', - help => 'Domain_Contact_Information', + help => 'Domain_Configuration_Contact_Info', header => [{col1 => 'Setting', col2 => 'Value',}], }, 'usercreation' => { text => 'User creation', - help => 'Domain_User_Creation', + help => 'Domain_Configuration_User_Creation', header => [{col1 => 'Format rule type', col2 => 'Format rules in force'}, {col1 => 'User account creation', @@ -144,28 +149,46 @@ sub handler { {col1 => 'Context', col2 => 'Assignable authentication types'}], }, - 'usermodification' => + 'usermodification' => { text => 'User modification', - help => 'Domain_User_Modification', + help => 'Domain_Configuration_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' => + 'scantron' => { text => 'Scantron format file', - help => 'Domain_Scantron_Formats', + help => 'Domain_Configuration_Scantron_Format', header => [ {col1 => 'Item', col2 => '', }], }, - 'coursecategories' => + 'requestcourses' => + {text => 'Request creation of courses', + help => 'Domain_Configuration_Request_Courses', + header => [{col1 => 'User affiliation', + col2 => 'Requestable course types',}], + }, + 'coursecategories' => { text => 'Cataloging of courses', - help => 'Domain_Course_Catalog', - header => [ {col1 => 'Categories', - col2 => '', - }], - } + help => 'Domain_Configuration_Cataloging_Courses', + header => [{col1 => 'Category settings', + col2 => '',}, + {col1 => 'Categories', + col2 => '', + }], + }, + 'serverstatuses' => + {text => 'Access to server status pages', + help => 'Domain_Configuration_Server_Status', + header => [{col1 => 'Status Page', + col2 => 'Other named users', + col3 => 'Specific IPs', + }], + }, ); my @roles = ('student','coordinator','author','admin'); my @actions = &Apache::loncommon::get_env_multiple('form.actions'); @@ -255,7 +278,7 @@ sub handler { $r->print(''. ''."\n". - ''.&mt('No settings chosen'). + ''.&mt('No settings chosen'). ''); } $r->print(''); @@ -314,7 +337,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"); @@ -344,7 +370,7 @@ sub process_changes { $output = &modify_rolecolors($r,$dom,$confname,$roles, %domconfig); } elsif ($action eq 'quotas') { - $output = &modify_quotas($dom,%domconfig); + $output = &modify_quotas($dom,$action,%domconfig); } elsif ($action eq 'autoenroll') { $output = &modify_autoenroll($dom,%domconfig); } elsif ($action eq 'autoupdate') { @@ -363,6 +389,10 @@ sub process_changes { $output = &modify_scantron($r,$dom,$confname,%domconfig); } elsif ($action eq 'coursecategories') { $output = &modify_coursecategories($dom,%domconfig); + } elsif ($action eq 'serverstatuses') { + $output = &modify_serverstatuses($dom,%domconfig); + } elsif ($action eq 'requestcourses') { + $output = &modify_quotas($dom,$action,%domconfig); } return $output; } @@ -377,32 +407,35 @@ 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')) { - my $colspan = ($action eq 'rolecolors')?' colspan="2"':''; + ($action eq 'usercreation') || ($action eq 'usermodification') || + ($action eq 'coursecategories')) { + 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'}).'
- - + + '; - $rowtotal ++; + $rowtotal ++; if ($action eq 'autoupdate') { $output .= &print_autoupdate('top',$dom,$settings,\$rowtotal); } elsif ($action eq 'usercreation') { $output .= &print_usercreation('top',$dom,$settings,\$rowtotal); } elsif ($action eq 'usermodification') { $output .= &print_usermodification('top',$dom,$settings,\$rowtotal); + } elsif ($action eq 'coursecategories') { + $output .= &print_coursecategories('top',$dom,$item,$settings,\$rowtotal); } else { $output .= &print_rolecolors($phase,'student',$dom,$confname,$settings,\$rowtotal); } @@ -414,8 +447,9 @@ sub print_config_box {
'.$item->{'header'}->[0]->{'col1'}.''.$item->{'header'}->[0]->{'col2'}.''.&mt($item->{'header'}->[0]->{'col1'}).''.&mt($item->{'header'}->[0]->{'col2'}).'
- - + '; + $output .= ' + '; $rowtotal ++; if ($action eq 'autoupdate') { @@ -429,12 +463,26 @@ sub print_config_box { + + +
'.$item->{'header'}->[1]->{'col1'}.''.$item->{'header'}->[1]->{'col2'}.''.&mt($item->{'header'}->[1]->{'col1'}).''.&mt($item->{'header'}->[1]->{'col2'}).'
- - '. + + '. &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).' +
'.$item->{'header'}->[2]->{'col1'}.''.$item->{'header'}->[2]->{'col2'}.'
'.&mt($item->{'header'}->[2]->{'col1'}).''.&mt($item->{'header'}->[2]->{'col2'}).'
+
+ + + + '. + + &print_usermodification('bottom',$dom,$settings,\$rowtotal); + $rowtotal ++; + } elsif ($action eq 'coursecategories') { + $output .= &print_coursecategories('bottom',$dom,$item,$settings,\$rowtotal); } else { $output .= &print_rolecolors($phase,'coordinator',$dom,$confname,$settings,\$rowtotal).'
'.&mt($item->{'header'}->[2]->{'col1'}).''.&mt($item->{'header'}->[2]->{'col2'}).'
@@ -444,8 +492,10 @@ sub print_config_box {
- - + + '. &print_rolecolors($phase,'author',$dom,$confname,$settings,\$rowtotal).'
'.$item->{'header'}->[2]->{'col1'}.''.$item->{'header'}->[2]->{'col2'}.''. + &mt($item->{'header'}->[2]->{'col1'}).''. + &mt($item->{'header'}->[2]->{'col2'}).'
@@ -455,8 +505,8 @@ sub print_config_box {
- - + + '. &print_rolecolors($phase,'admin',$dom,$confname,$settings,\$rowtotal); $rowtotal += 2; @@ -469,20 +519,41 @@ sub print_config_box { '; if (($action eq 'login') || ($action eq 'directorysrch')) { $output .= ' - '; + '; + } elsif ($action eq 'serverstatuses') { + $output .= ' + '; + } else { $output .= ' - '; + '; } - my $colspan = ($action eq 'coursecategories')?' colspan="2"':''; - $output .= ' - - '; + if (defined($item->{'header'}->[0]->{'col3'})) { + $output .= ''; + if ($item->{'header'}->[0]->{'col3'}) { + $output .= ''; + } + $output .= ''; $rowtotal ++; if ($action eq 'login') { $output .= &print_login($dom,$confname,$phase,$settings,\$rowtotal); } elsif ($action eq 'quotas') { - $output .= &print_quotas($dom,$settings,\$rowtotal); + $output .= &print_quotas($dom,$settings,\$rowtotal,$action); } elsif ($action eq 'autoenroll') { $output .= &print_autoenroll($dom,$settings,\$rowtotal); } elsif ($action eq 'directorysrch') { @@ -493,8 +564,10 @@ sub print_config_box { $output .= &print_defaults($dom,\$rowtotal); } elsif ($action eq 'scantron') { $output .= &print_scantronformat($r,$dom,$confname,$settings,\$rowtotal); - } elsif ($action eq 'coursecategories'){ - $output .= &print_coursecategories($dom,$item,$settings,\$rowtotal); + } elsif ($action eq 'serverstatuses') { + $output .= &print_serverstatuses($dom,$settings,\$rowtotal); + } elsif ($action eq 'requestcourses') { + $output .= &print_quotas($dom,$settings,\$rowtotal,$action); } } $output .= ' @@ -638,6 +711,7 @@ sub print_login { ); foreach my $item (@images) { $defaults{$item} = $defaultdesign{'login.'.$item}; + $defaults{'showlogo'}{$item} = 1; } foreach my $item (@bgs) { $defaults{'bgs'}{$item} = $defaultdesign{'login.'.$item}; @@ -659,10 +733,13 @@ sub print_login { } } foreach my $item (@images) { - if ($settings->{$item} ne '') { + if (defined($settings->{$item})) { $designs{$item} = $settings->{$item}; $is_custom{$item} = 1; } + if (defined($settings->{'showlogo'}{$item})) { + $designs{'showlogo'}{$item} = $settings->{'showlogo'}{$item}; + } } foreach my $item (@logintext) { if ($settings->{$item} ne '') { @@ -751,9 +828,9 @@ sub login_choices { bgs => "Background colors", links => "Link colors", font => "Font color", - pgbg => "Page", - mainbg => "Main panel", - sidebg => "Side panel", + pgbg => "Header", + mainbg => "Page", + sidebg => "Login box", link => "Link", alink => "Active link", vlink => "Visited link", @@ -856,20 +933,27 @@ sub display_color_options { $itemcount ++; $css_class = $itemcount%2?' class="LC_odd_row"':''; $datatable .= ''. - ''; + ''; if ($designs->{$img} ne '') { $imgfile = $designs->{$img}; $img_import = ($imgfile =~ m{^/adm/}); } else { $imgfile = $defaults->{$img}; } - if ($img eq 'login') { - $login_hdr_pick = &login_header_options($img,$role,$defaults,$is_custom,$choices, - $loginheader); - $logincolors = - &login_text_colors($img,$role,$logintext,$phase,$choices,$designs); - } if ($imgfile) { my ($showfile,$fullsize); if ($imgfile =~ m-^(/res/\Q$dom\E/\Q$confname\E/\Q$img\E)/([^/]+)$-) { @@ -958,7 +1042,7 @@ sub display_color_options { my $bgs_def; foreach my $item (@{$bgs}) { if (!$is_custom->{$item}) { - $bgs_def .= ''; + $bgs_def .= ''; } } if ($bgs_def) { @@ -1009,6 +1093,32 @@ sub display_color_options { return $datatable; } +sub logo_display_options { + my ($img,$defaults,$designs) = @_; + my $checkedon; + if (ref($defaults) eq 'HASH') { + if (ref($defaults->{'showlogo'}) eq 'HASH') { + if ($defaults->{'showlogo'}{$img}) { + $checkedon = 'checked="checked" '; + } + } + } + if (ref($designs) eq 'HASH') { + if (ref($designs->{'showlogo'}) eq 'HASH') { + if (defined($designs->{'showlogo'}{$img})) { + if ($designs->{'showlogo'}{$img} == 0) { + $checkedon = ''; + } elsif ($designs->{'showlogo'}{$img} == 1) { + $checkedon = 'checked="checked" '; + } + } + } + } + return '
'."\n"; +} + sub login_header_options { my ($img,$role,$defaults,$is_custom,$choices,$loginheader) = @_; my $image_checked = ' checked="checked" '; @@ -1060,7 +1170,7 @@ sub image_changes { my ($is_custom,$alt_text,$img_import,$showfile,$fullsize,$role,$img,$imgfile,$logincolors) = @_; my $output; if (!$is_custom) { - if ($img eq 'login') { + if ($img ne 'domlogo') { $output .= &mt('Default image:').'
'; } else { $output .= &mt('Default in use:').'
'; @@ -1137,38 +1247,139 @@ ENDCOL } sub print_quotas { - my ($dom,$settings,$rowtotal) = @_; - my $datatable; + my ($dom,$settings,$rowtotal,$action) = @_; + my $context; + if ($action eq 'quotas') { + $context = 'tools'; + } else { + $context = $action; + } + my ($datatable,$defaultquota,@usertools); my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom); my $typecount = 0; my $css_class; + if ($context eq 'requestcourses') { + @usertools = ('official','unofficial'); + } else { + @usertools = ('aboutme','blog','portfolio'); + } + my %titles = &tool_titles(); if (ref($types) eq 'ARRAY') { foreach my $type (@{$types}) { + my $currdefquota; + unless ($context eq 'requestcourses') { + if (ref($settings) eq 'HASH') { + if (ref($settings->{defaultquota}) eq 'HASH') { + $currdefquota = $settings->{defaultquota}->{$type}; + } else { + $currdefquota = $settings->{$type}; + } + } + } if (defined($usertypes->{$type})) { $typecount ++; $css_class = $typecount%2?' class="LC_odd_row"':''; - $datatable .= ''. + $datatable .= ''. ''. + ''; + unless ($context eq 'requestcourses') { + $datatable .= ''; + '" value="'.$currdefquota. + '" size="5" /> Mb'; + } + $datatable .= ''; } } } - my $defaultquota = '20'; - if (ref($settings) eq 'HASH') { - if (defined($settings->{'default'})) { - $defaultquota = $settings->{'default'}; + unless ($context eq 'requestcourses') { + $defaultquota = '20'; + if (ref($settings) eq 'HASH') { + if (ref($settings->{'defaultquota'}) eq 'HASH') { + $defaultquota = $settings->{'defaultquota'}->{'default'}; + } elsif (defined($settings->{'default'})) { + $defaultquota = $settings->{'default'}; + } } } $typecount ++; $css_class = $typecount%2?' class="LC_odd_row"':''; $datatable .= ''. ''. - ''; + ''; + unless ($context eq 'requestcourses') { + $datatable .= ''; + } + $datatable .= ''; + $typecount ++; + $css_class = $typecount%2?' class="LC_odd_row"':''; + $datatable .= ''. + ''. + ''; $$rowtotal += $typecount; return $datatable; } @@ -1409,7 +1620,7 @@ sub print_contacts { my $datatable; my @contacts = ('adminemail','supportemail'); my (%checked,%to,%otheremails); - my @mailings = ('errormail','packagesmail','helpdeskmail'); + my @mailings = ('errormail','packagesmail','lonstatusmail','helpdeskmail'); foreach my $type (@mailings) { $otheremails{$type} = ''; } @@ -1429,6 +1640,8 @@ sub print_contacts { } $otheremails{$type} = $settings->{$type}{'others'}; } + } elsif ($type eq 'lonstatusmail') { + $checked{'lonstatusmail'}{'adminemail'} = ' checked="checked" '; } } } else { @@ -1436,30 +1649,24 @@ sub print_contacts { $to{'adminemail'} = $Apache::lonnet::perlvar{'lonAdmEMail'}; $checked{'errormail'}{'adminemail'} = ' checked="checked" '; $checked{'packagesmail'}{'adminemail'} = ' checked="checked" '; - $checked{'helpdeskmail'}{'supportemail'} = ' checked="checked" '; + $checked{'helpdeskmail'}{'supportemail'} = ' checked="checked" '; + $checked{'lonstatusmail'}{'adminemail'} = ' checked="checked" '; } my ($titles,$short_titles) = &contact_titles(); my $rownum = 0; my $css_class; foreach my $item (@contacts) { - if ($rownum%2) { - $css_class = ''; - } else { - $css_class = ' class="LC_odd_row" '; - } + $rownum ++; + $css_class = $rownum%2?' class="LC_odd_row"':''; $datatable .= ''. ''; - $rownum ++; } foreach my $type (@mailings) { - if ($rownum%2) { - $css_class = ''; - } else { - $css_class = ' class="LC_odd_row" '; - } + $rownum ++; + $css_class = $rownum%2?' class="LC_odd_row"':''; $datatable .= ''. ''. @@ -1476,7 +1683,6 @@ sub print_contacts { ''. ''."\n"; - $rownum ++; } $$rowtotal += $rownum; return $datatable; @@ -1485,10 +1691,11 @@ sub print_contacts { sub contact_titles { my %titles = &Apache::lonlocal::texthash ( 'supportemail' => 'Support E-mail address', - 'adminemail' => 'Default Server Admin E-mail address', + 'adminemail' => 'Default Server Admin E-mail address', 'errormail' => 'Error reports to be e-mailed to', 'packagesmail' => 'Package update alerts to be e-mailed to', - 'helpdeskmail' => 'Helpdesk requests to be e-mailed to' + 'helpdeskmail' => 'Helpdesk requests to be e-mailed to', + 'lonstatusmail' => 'E-mail from nightly status check (warnings/errors)', ); my %short_titles = &Apache::lonlocal::texthash ( adminemail => 'Admin E-mail address', @@ -1497,6 +1704,17 @@ sub contact_titles { return (\%titles,\%short_titles); } +sub tool_titles { + my %titles = &Apache::lonlocal::texthash ( + aboutme => 'Personal Information Page', + blog => 'Blog', + portfolio => 'Portfolio', + official => 'Official courses (with institutional codes)', + unofficial => 'Unofficial courses', + ); + return %titles; +} + sub print_usercreation { my ($position,$dom,$settings,$rowtotal) = @_; my $numinrow = 4; @@ -1676,10 +1894,14 @@ sub user_formats_row { ); my $css_class = $rowcount%2?' class="LC_odd_row"':''; $output = ''. - ''. - '
'.$item->{'header'}->[3]->{'col1'}.''.$item->{'header'}->[3]->{'col2'}.''.&mt($item->{'header'}->[3]->{'col1'}).''.&mt($item->{'header'}->[3]->{'col2'}).'
'.$item->{'header'}->[0]->{'col1'}.''.&mt($item->{'header'}->[0]->{'col1'}).''.&mt($item->{'header'}->[0]->{'col1'}). + '
('.&mt('Automatic access for Dom. Coords.').')
'.$item->{'header'}->[0]->{'col1'}.''.&mt($item->{'header'}->[0]->{'col1'}).''.$item->{'header'}->[0]->{'col2'}.'
'. + &mt($item->{'header'}->[0]->{'col2'}); + if ($action eq 'serverstatuses') { + $output .= '
('.&mt('user1:domain1,user2:domain2 etc.').')'; + } + } else { + $output .= '
'. + &mt($item->{'header'}->[0]->{'col2'}); + } + $output .= ''. + &mt($item->{'header'}->[0]->{'col3'}); + if ($action eq 'serverstatuses') { + $output .= '
('.&mt('IP1,IP2 etc.').')'; + } + $output .= '
'.$choices->{$img}.''.$choices->{$img}; my ($imgfile,$img_import,$login_hdr_pick,$logincolors); + if ($role eq 'login') { + if ($img eq 'login') { + $login_hdr_pick = + &login_header_options($img,$role,$defaults,$is_custom,$choices, + $loginheader); + $logincolors = + &login_text_colors($img,$role,$logintext,$phase,$choices, + $designs); + } elsif ($img ne 'domlogo') { + $datatable.= &logo_display_options($img,$defaults,$designs); + } + } + $datatable .= ''.$choices->{$item}.'    
'.$defaults->{'bgs'}{$item}.'
'.$choices->{$item}.'    
'.$defaults->{'bgs'}{$item}.'
'.$usertypes->{$type}.''; + foreach my $item (@usertools) { + my $checked; + unless ($context eq 'requestcourses') { + $checked = 'checked="checked" '; + } + if (ref($settings) eq 'HASH') { + if (ref($settings->{$item}) eq 'HASH') { + if ($settings->{$item}->{$type} == 0) { + $checked = ''; + } elsif ($settings->{$item}->{$type} == 1) { + $checked = 'checked="checked" '; + } + } + } + $datatable .= '  '; + } + $datatable .= ''. ' Mb
'.$othertitle.''. - ' Mb
'; + foreach my $item (@usertools) { + my $checked; + unless ($context eq 'requestcourses') { + $checked = 'checked="checked" '; + } + if (ref($settings) eq 'HASH') { + if (ref($settings->{$item}) eq 'HASH') { + if ($settings->{$item}->{'default'} == 0) { + $checked = ''; + } elsif ($settings->{$item}->{'default'} == 1) { + $checked = 'checked="checked" '; + } + } + } + $datatable .= '  '; + } + $datatable .= ''. + ' Mb

'.&mt('LON-CAPA Advanced Users').'

'; + foreach my $item (@usertools) { + my $checked; + unless ($context eq 'requestcourses') { + $checked = 'checked="checked" '; + } + if (ref($settings) eq 'HASH') { + if (ref($settings->{$item}) eq 'HASH') { + if ($settings->{$item}->{'_LC_adv'} == 0) { + $checked = ''; + } elsif ($settings->{$item}->{'_LC_adv'} == 1) { + $checked = 'checked="checked" '; + } + } + } + $datatable .= '  '; + } + $datatable .= '('.&mt('overrides affiliation'). + ')
'.$titles->{$item}. ''. '
'. $titles->{$type}.':
'. - &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++) { @@ -1727,7 +1949,7 @@ sub usercreation_types { any => 'Any', official => 'Institutional only ', unofficial => 'Non-institutional only', - email => 'Email address', + email => 'E-mail address', login => 'Institutional Login', sso => 'SSO', none => 'None', @@ -1767,7 +1989,7 @@ sub print_usermodification { $$rowtotal ++; $rowcount ++; } - } else { + } elsif ($position eq 'middle') { $context = 'course'; $rowcount = 0; foreach my $role ('st','ep','ta','in','cr') { @@ -1776,13 +1998,28 @@ 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; } sub print_defaults { my ($dom,$rowtotal) = @_; - my @items = ('auth_def','auth_arg_def','lang_def','timezone_def'); + my @items = ('auth_def','auth_arg_def','lang_def','timezone_def', + 'datelocale_def'); my %domdefaults = &Apache::lonnet::get_domain_defaults($dom); my $titles = &defaults_titles(); my $rownum = 0; @@ -1817,6 +2054,9 @@ sub print_defaults { } elsif ($item eq 'timezone_def') { my $includeempty = 1; $datatable .= &Apache::loncommon::select_timezone($item,$domdefaults{$item},undef,$includeempty); + } elsif ($item eq 'datelocale_def') { + my $includeempty = 1; + $datatable .= &Apache::loncommon::select_datelocale($item,$domdefaults{$item},undef,$includeempty); } else { $datatable .= ''; @@ -1834,6 +2074,7 @@ sub defaults_titles { 'auth_arg_def' => 'Default authentication argument', 'lang_def' => 'Default language', 'timezone_def' => 'Default timezone', + 'datelocale_def' => 'Default locale for dates', ); return (\%titles); } @@ -1841,7 +2082,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', @@ -1868,23 +2110,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; + } } } } @@ -1905,39 +2176,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 .= '' - .''. + ''; @@ -1961,118 +2252,219 @@ sub legacy_scantronformat { } sub print_coursecategories { - my ($dom,$hdritem,$settings,$rowtotal) = @_; - my ($datatable,$css_class); - my $itemcount = 1; - if (ref($settings) eq 'HASH') { - my (@cats,@trails,%allitems,%idx,@jsarray); - &Apache::loncommon::extract_categories($settings,\@cats,\@trails, - \%allitems,\%idx,\@jsarray); - my $maxdepth = scalar(@cats); - my $colattrib = ''; - if ($maxdepth > 2) { - $colattrib = ' colspan="2" '; - } - my @path; - if (@cats > 0) { - if (ref($cats[0]) eq 'ARRAY') { - my $numtop = @{$cats[0]}; - my $maxnum = $numtop; - if ((!grep(/^instcode$/,@{$cats[0]})) || ($settings->{'instcode::0'} eq '')) { - $maxnum ++; - } - my $lastidx; - for (my $i=0; $i<$numtop; $i++) { - my $parent = $cats[0][$i]; + my ($position,$dom,$hdritem,$settings,$rowtotal) = @_; + my $datatable; + if ($position eq 'top') { + my $toggle_cats_crs = ' '; + my $toggle_cats_dom = ' checked="checked" '; + my $can_cat_crs = ' '; + my $can_cat_dom = ' checked="checked" '; + if (ref($settings) eq 'HASH') { + if ($settings->{'togglecats'} eq 'crs') { + $toggle_cats_crs = $toggle_cats_dom; + $toggle_cats_dom = ' '; + } + if ($settings->{'categorize'} eq 'crs') { + $can_cat_crs = $can_cat_dom; + $can_cat_dom = ' '; + } + } + my %title = &Apache::lonlocal::texthash ( + togglecats => 'Show/Hide a course in the catalog', + categorize => 'Assign a category to a course', + ); + my %level = &Apache::lonlocal::texthash ( + dom => 'Set in "Modify Course" (Domain)', + crs => 'Set in "Modify Parameters" (Course)', + ); + $datatable = ''. + ''. + ''. + ''. + ''. + ''. + ''; + $$rowtotal += 2; + } else { + my $css_class; + my $itemcount = 1; + my $cathash; + if (ref($settings) eq 'HASH') { + $cathash = $settings->{'cats'}; + } + if (ref($cathash) eq 'HASH') { + my (@cats,@trails,%allitems,%idx,@jsarray); + &Apache::loncommon::extract_categories($cathash,\@cats,\@trails, + \%allitems,\%idx,\@jsarray); + my $maxdepth = scalar(@cats); + my $colattrib = ''; + if ($maxdepth > 2) { + $colattrib = ' colspan="2" '; + } + my @path; + if (@cats > 0) { + if (ref($cats[0]) eq 'ARRAY') { + my $numtop = @{$cats[0]}; + my $maxnum = $numtop; + if ((!grep(/^instcode$/,@{$cats[0]})) || ($cathash->{'instcode::0'} eq '')) { + $maxnum ++; + } + my $lastidx; + for (my $i=0; $i<$numtop; $i++) { + my $parent = $cats[0][$i]; + $css_class = $itemcount%2?' class="LC_odd_row"':''; + my $item = &escape($parent).'::0'; + my $chgstr = ' onchange="javascript:reorderCats(this.form,'."'','$item','$idx{$item}'".');"'; + $lastidx = $idx{$item}; + $datatable .= '' + .' ' + .''; + } else { + $datatable .= $parent + .' '; + } + my $depth = 1; + push(@path,$parent); + $datatable .= &build_category_rows($itemcount,\@cats,$depth,$parent,\@path,\%idx); + pop(@path); + $datatable .= ''; + $itemcount ++; + } $css_class = $itemcount%2?' class="LC_odd_row"':''; - my $item = &escape($parent).'::0'; - my $chgstr = ' onchange="javascript:reorderCats(this.form,'."'','$item','$idx{$item}'".');"'; - $lastidx = $idx{$item}; - $datatable .= '' - .' ' - .''; - } else { - $datatable .= $parent - .' '; - } - my $depth = 1; - push(@path,$parent); - $datatable .= &build_category_rows($itemcount,\@cats,$depth,$parent,\@path,\%idx); - pop(@path); - $datatable .= ''; + $datatable .= '' + .''."\n"; $itemcount ++; - } - $css_class = $itemcount%2?' class="LC_odd_row"':''; - my $chgstr = ' onchange="javascript:reorderCats(this.form,'."'','addcategory_pos','$lastidx'".');"'; - $datatable .= '' - .''."\n"; - $itemcount ++; - if ((!grep(/^instcode$/,@{$cats[0]})) || ($settings->{'instcode::0'} eq '')) { - $css_class = $itemcount%2?' class="LC_odd_row"':''; - my $chgstr = ' onchange="javascript:reorderCats(this.form,'."'','instcode_pos','$lastidx'".');"'; - $datatable .= '' + .''; } - $datatable .= '' - .''; } + } else { + $datatable .= &initialize_categories($itemcount); } } else { - $datatable .= &initialize_categories($itemcount); + $datatable .= '' + .&initialize_categories($itemcount); } - } else { - $datatable .= '' - .&initialize_categories($itemcount); + $$rowtotal += $itemcount; } - $$rowtotal += $itemcount; return $datatable; } +sub print_serverstatuses { + my ($dom,$settings,$rowtotal) = @_; + my $datatable; + my @pages = &serverstatus_pages(); + my (%namedaccess,%machineaccess); + foreach my $type (@pages) { + $namedaccess{$type} = ''; + $machineaccess{$type}= ''; + } + if (ref($settings) eq 'HASH') { + foreach my $type (@pages) { + if (exists($settings->{$type})) { + if (ref($settings->{$type}) eq 'HASH') { + foreach my $key (keys(%{$settings->{$type}})) { + if ($key eq 'namedusers') { + $namedaccess{$type} = $settings->{$type}->{$key}; + } elsif ($key eq 'machines') { + $machineaccess{$type} = $settings->{$type}->{$key}; + } + } + } + } + } + } + my $titles= &LONCAPA::lonauthcgi::serverstatus_titles(); + my $rownum = 0; + my $css_class; + foreach my $type (@pages) { + $rownum ++; + $css_class = $rownum%2?' class="LC_odd_row"':''; + $datatable .= ''. + ''. + ''. + ''."\n"; + } + $$rowtotal += $rownum; + return $datatable; +} + +sub serverstatus_pages { + return ('userstatus','lonstatus','loncron','server-status','codeversions', + 'clusterstatus','metadata_keywords','metadata_harvest', + 'takeoffline','takeonline','showenv'); +} + sub coursecategories_javascript { my ($settings) = @_; - my ($output,$jstext); + my ($output,$jstext,$cathash); if (ref($settings) eq 'HASH') { + $cathash = $settings->{'cats'}; + } + if (ref($cathash) eq 'HASH') { my (@cats,@jsarray,%idx); - &Apache::loncommon::gather_categories($settings,\@cats,\%idx,\@jsarray); + &Apache::loncommon::gather_categories($cathash,\@cats,\%idx,\@jsarray); if (@jsarray > 0) { $jstext = ' var categories = Array('.scalar(@jsarray).');'."\n"; for (my $i=0; $i<@jsarray; $i++) { @@ -2227,7 +2619,7 @@ sub build_category_rows { pop(@{$path}); } } else { - $text .= &mt('New:').' '; + } else { + $resulttext .= '
  • '.&mt("$choices{$item} set to not be displayed").'
  • '; + } + } elsif ($confhash->{$role}{$item} eq '') { $resulttext .= '
  • '.&mt("$choices{$item} set to default").'
  • '; } else { my $newitem = $confhash->{$role}{$item}; @@ -3129,58 +3559,190 @@ END } sub modify_quotas { - my ($dom,%domconfig) = @_; + my ($dom,$action,%domconfig) = @_; + my ($context,@usertools); + if ($action eq 'quotas') { + $context = 'tools'; + } else { + $context = $action; + } + if ($context eq 'requestcourses') { + @usertools = ('official','unofficial'); + } else { + @usertools = ('aboutme','blog','portfolio'); + } + my %domdefaults = &Apache::lonnet::get_domain_defaults($dom); my ($resulttext,%changes); my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom); - my %formhash; + my %titles = &tool_titles(); + my (%confhash,%toolshash); foreach my $key (keys(%env)) { - if ($key =~ /^form\.quota_(.+)$/) { - $formhash{$1} = $env{$key}; + unless ($context eq 'requestcourses') { + if ($key =~ /^form\.quota_(.+)$/) { + $confhash{'defaultquota'}{$1} = $env{$key}; + } + } + if ($key =~ /^form\.\Q$context\E_(.+)$/) { + @{$toolshash{$1}} = &Apache::loncommon::get_env_multiple($key); } } - $formhash{'default'} = $env{'form.defaultquota'}; - if (ref($domconfig{'quotas'}) eq 'HASH') { - foreach my $key (keys(%{$domconfig{'quotas'}})) { - if (exists($formhash{$key})) { - if ($formhash{$key} ne $domconfig{'quotas'}{$key}) { - $changes{$key} = 1; + unless ($context eq 'requestcourses') { + $confhash{'defaultquota'}{'default'} = $env{'form.defaultquota'}; + } + foreach my $item (@usertools) { + foreach my $type (@{$types},'default','_LC_adv') { + if (grep(/^\Q$type\E$/,@{$toolshash{$item}})) { + $confhash{$item}{$type} = 1; + } else { + $confhash{$item}{$type} = 0; + } + if (ref($domconfig{$action}) eq 'HASH') { + if (ref($domconfig{$action}{$item}) eq 'HASH') { + if ($domconfig{$action}{$item}{$type} ne $confhash{$item}{$type}) { + $changes{$item}{$type} = 1; + } + } else { + if ($context eq 'requestcourses') { + if ($confhash{$item}{$type}) { + $changes{$item}{$type} = 1; + } + } else { + if (!$confhash{$item}{$type}) { + $changes{$item}{$type} = 1; + } + } } } else { - $formhash{$key} = $domconfig{'quotas'}{$key}; + if ($context eq 'requestcourses') { + if ($confhash{$item}{$type}) { + $changes{$item}{$type} = 1; + } + } else { + if (!$confhash{$item}{$type}) { + $changes{$item}{$type} = 1; + } + } } } } - foreach my $key (keys(%formhash)) { - if ($formhash{$key} ne '') { - if (ref($domconfig{'quotas'}) eq 'HASH') { - if (!exists($domconfig{'quotas'}{$key})) { - $changes{$key} = 1; + unless ($context eq 'requestcourses') { + if (ref($domconfig{'quotas'}) eq 'HASH') { + if (ref($domconfig{'quotas'}{'defaultquota'}) eq 'HASH') { + foreach my $key (keys(%{$domconfig{'quotas'}{'defaultquota'}})) { + if (exists($confhash{'defaultquota'}{$key})) { + if ($confhash{'defaultquota'}{$key} ne $domconfig{'quotas'}{'defaultquota'}{$key}) { + $changes{'defaultquota'}{$key} = 1; + } + } else { + $confhash{'defaultquota'}{$key} = $domconfig{'quotas'}{'defaultquota'}{$key}; + } } } else { - $changes{$key} = 1; + foreach my $key (keys(%{$domconfig{'quotas'}})) { + if (exists($confhash{'defaultquota'}{$key})) { + if ($confhash{'defaultquota'}{$key} ne $domconfig{'quotas'}{$key}) { + $changes{'defaultquota'}{$key} = 1; + } + } else { + $confhash{'defaultquota'}{$key} = $domconfig{'quotas'}{$key}; + } + } + } + } + if (ref($confhash{'defaultquota'}) eq 'HASH') { + foreach my $key (keys(%{$confhash{'defaultquota'}})) { + if (ref($domconfig{'quotas'}) eq 'HASH') { + if (ref($domconfig{'quotas'}{'defaultquota'}) eq 'HASH') { + if (!exists($domconfig{'quotas'}{'defaultquota'}{$key})) { + $changes{'defaultquota'}{$key} = 1; + } + } else { + if (!exists($domconfig{'quotas'}{$key})) { + $changes{'defaultquota'}{$key} = 1; + } + } + } else { + $changes{'defaultquota'}{$key} = 1; + } } } } + + foreach my $key (keys(%confhash)) { + $domdefaults{$key} = $confhash{$key}; + } + my %quotahash = ( - quotas => {%formhash}, + $action => { %confhash } ); my $putresult = &Apache::lonnet::put_dom('configuration',\%quotahash, $dom); if ($putresult eq 'ok') { if (keys(%changes) > 0) { + my $cachetime = 24*60*60; + &Apache::lonnet::do_cache_new('domdefaults',$dom,\%domdefaults,$cachetime); + $resulttext = &mt('Changes made:').'
      '; - foreach my $type (@{$types},'default') { - if (defined($changes{$type})) { - my $typetitle = $usertypes->{$type}; - if ($type eq 'default') { - $typetitle = $othertitle; + unless ($context eq 'requestcourses') { + if (ref($changes{'defaultquota'}) eq 'HASH') { + $resulttext .= '
    • '.&mt('Portfolio default quotas').'
        '; + foreach my $type (@{$types},'default') { + if (defined($changes{'defaultquota'}{$type})) { + my $typetitle = $usertypes->{$type}; + if ($type eq 'default') { + $typetitle = $othertitle; + } + $resulttext .= '
      • '.&mt('[_1] set to [_2] Mb',$typetitle,$confhash{'defaultquota'}{$type}).'
      • '; + } } - $resulttext .= '
      • '.&mt('[_1] set to [_2] Mb',$typetitle,$formhash{$type}).'
      • '; + $resulttext .= '
    • '; + } + } + my %newenv; + foreach my $item (@usertools) { + if (ref($changes{$item}) eq 'HASH') { + my $newacc = + &Apache::lonnet::usertools_access($env{'user.name'}, + $env{'user.domain'}, + $item,'reload',$context); + if ($context eq 'requestcourses') { + if ($env{'environment.canrequest.'.$item} ne $newacc) { + $newenv{'environment.canrequest.'.$item} = $newacc; + } + } else { + if ($env{'environment.availabletools.'.$item} ne $newacc) { + $newenv{'environment.availabletools.'.$item} = $newacc; + } + } + $resulttext .= '
    • '.$titles{$item}.'
        '; + foreach my $type (@{$types},'default','_LC_adv') { + if ($changes{$item}{$type}) { + my $typetitle = $usertypes->{$type}; + if ($type eq 'default') { + $typetitle = $othertitle; + } elsif ($type eq '_LC_adv') { + $typetitle = 'LON-CAPA Advanced Users'; + } + if ($confhash{$item}{$type}) { + $resulttext .= '
      • '.&mt('Set to be available to [_1]',$typetitle).'
      • '; + } else { + $resulttext .= '
      • '.&mt('Set to be unavailable to [_1]',$typetitle).'
      • '; + } + } + } + $resulttext .= '
    • '; } } $resulttext .= '
    '; + if (keys(%newenv)) { + &Apache::lonnet::appenv(\%newenv); + } } else { - $resulttext = &mt('No changes made to default quotas'); + if ($context eq 'requestcourses') { + $resulttext = &mt('No changes made to rights to request creation of courses.'); + } else { + $resulttext = &mt('No changes made to availability of personal information pages, blogs, portfolios or default quotas'); + } } } else { $resulttext = ''. @@ -3563,7 +4125,7 @@ sub modify_contacts { } my (%others,%to); my @contacts = ('supportemail','adminemail'); - my @mailings = ('errormail','packagesmail','helpdeskmail'); + my @mailings = ('errormail','packagesmail','helpdeskmail','lonstatusmail'); foreach my $type (@mailings) { @{$newsetting{$type}} = &Apache::loncommon::get_env_multiple('form.'.$type); @@ -3608,6 +4170,7 @@ sub modify_contacts { $default{'errormail'} = 'adminemail'; $default{'packagesmail'} = 'adminemail'; $default{'helpdeskmail'} = 'supportemail'; + $default{'lonstatusmail'} = 'adminemail'; foreach my $item (@contacts) { if ($to{$item} ne $default{$item}) { $changes{$item} = 1; @@ -3987,10 +4550,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'); @@ -3998,6 +4562,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) { @@ -4045,13 +4615,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}); @@ -4083,7 +4666,7 @@ sub modify_defaults { my ($dom,$r) = @_; my ($resulttext,$mailmsgtxt,%newvalues,%changes,@errors); my %domdefaults = &Apache::lonnet::get_domain_defaults($dom); - my @items = ('auth_def','auth_arg_def','lang_def','timezone_def'); + my @items = ('auth_def','auth_arg_def','lang_def','timezone_def','datelocale_def'); my @authtypes = ('internal','krb4','krb5','localauth'); foreach my $item (@items) { $newvalues{$item} = $env{'form.'.$item}; @@ -4106,25 +4689,28 @@ 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); } } + } elsif ($item eq 'datelocale_def') { + if ($newvalues{$item} ne '') { + my @datelocale_ids = DateTime::Locale->ids(); + if (!grep(/^\Q$newvalues{$item}\E$/,@datelocale_ids)) { + push(@errors,$item); + } + } } if (grep(/^\Q$item\E$/,@errors)) { $newvalues{$item} = $domdefaults{$item}; } elsif ($domdefaults{$item} ne $newvalues{$item}) { $changes{$item} = 1; } + $domdefaults{$item} = $newvalues{$item}; } my %defaults_hash = ( - defaults => { auth_def => $newvalues{'auth_def'}, - auth_arg_def => $newvalues{'auth_arg_def'}, - lang_def => $newvalues{'lang_def'}, - timezone_def => $newvalues{'timezone_def'}, - } - ); + defaults => \%newvalues, + ); my $title = &defaults_titles(); my $putresult = &Apache::lonnet::put_dom('configuration',\%defaults_hash, $dom); @@ -4153,9 +4739,8 @@ sub modify_defaults { $resulttext .= ''; $mailmsgtext .= "\n"; my $cachetime = 24*60*60; - &Apache::lonnet::do_cache_new('domdefaults',$dom, - $defaults_hash{'defaults'},$cachetime); - if ($changes{'auth_def'} || $changes{'auth_arg_def'} || $changes{'lang_def'}) { + &Apache::lonnet::do_cache_new('domdefaults',$dom,\%domdefaults,$cachetime); + if ($changes{'auth_def'} || $changes{'auth_arg_def'} || $changes{'lang_def'} || $changes{'datelocale_def'}) { my $sysmail = $r->dir_config('lonSysEMail'); &Apache::lonmsg::sendemail($sysmail,"LON-CAPA Domain Settings Change - $dom",$mailmsgtext); } @@ -4257,69 +4842,87 @@ sub modify_scantron { sub modify_coursecategories { my ($dom,%domconfig) = @_; - my ($resulttext,%deletions,%reorderings,%needreordering,%adds,$errors); + my ($resulttext,%deletions,%reorderings,%needreordering,%adds,%changes,$errors, + $cathash); my @deletecategory = &Apache::loncommon::get_env_multiple('form.deletecategory'); if (ref($domconfig{'coursecategories'}) eq 'HASH') { - if (($domconfig{'coursecategories'}{'instcode::0'} ne '') && ($env{'form.instcode'} == 0)) { + $cathash = $domconfig{'coursecategories'}{'cats'}; + if ($domconfig{'coursecategories'}{'togglecats'} ne $env{'form.togglecats'}) { + $changes{'togglecats'} = 1; + $domconfig{'coursecategories'}{'togglecats'} = $env{'form.togglecats'}; + } + if ($domconfig{'coursecategories'}{'categorize'} ne $env{'form.categorize'}) { + $changes{'categorize'} = 1; + $domconfig{'coursecategories'}{'categorize'} = $env{'form.categorize'}; + } + } else { + $changes{'togglecats'} = 1; + $changes{'categorize'} = 1; + $domconfig{'coursecategories'} = { + togglecats => $env{'form.togglecats'}, + categorize => $env{'form.categorize'}, + }; + } + if (ref($cathash) eq 'HASH') { + if (($domconfig{'coursecategories'}{'cats'}{'instcode::0'} ne '') && ($env{'form.instcode'} == 0)) { push (@deletecategory,'instcode::0'); } } - my (@predelcats,@predeltrails,%predelallitems); - if (ref($domconfig{'coursecategories'}) eq 'HASH') { + my (@predelcats,@predeltrails,%predelallitems,%sort_by_deltrail); + if (ref($cathash) eq 'HASH') { if (@deletecategory > 0) { #FIXME Need to remove category from all courses using a deleted category - &Apache::loncommon::extract_categories($domconfig{'coursecategories'},\@predelcats,\@predeltrails,\%predelallitems); + &Apache::loncommon::extract_categories($cathash,\@predelcats,\@predeltrails,\%predelallitems); foreach my $item (@deletecategory) { - if ($domconfig{'coursecategories'}{$item} ne '') { - delete($domconfig{'coursecategories'}{$item}); + if ($domconfig{'coursecategories'}{'cats'}{$item} ne '') { + delete($domconfig{'coursecategories'}{'cats'}{$item}); $deletions{$item} = 1; - &recurse_cat_deletes($item,$domconfig{'coursecategories'}, - \%deletions); + &recurse_cat_deletes($item,$cathash,\%deletions); } } } - foreach my $item (keys(%{$domconfig{'coursecategories'}})) { + foreach my $item (keys(%{$cathash})) { my ($cat,$container,$depth) = map { &unescape($_); } split(/:/,$item); - if ($domconfig{'coursecategories'}{$item} ne $env{'form.'.$item}) { + if ($cathash->{$item} ne $env{'form.'.$item}) { $reorderings{$item} = 1; - $domconfig{'coursecategories'}{$item} = $env{'form.'.$item}; + $domconfig{'coursecategories'}{'cats'}{$item} = $env{'form.'.$item}; } if ($env{'form.addcategory_name_'.$item} ne '') { my $newcat = $env{'form.addcategory_name_'.$item}; my $newdepth = $depth+1; my $newitem = &escape($newcat).':'.&escape($cat).':'.$newdepth; - $domconfig{'coursecategories'}{$newitem} = $env{'form.addcategory_pos_'.$item}; + $domconfig{'coursecategories'}{'cats'}{$newitem} = $env{'form.addcategory_pos_'.$item}; $adds{$newitem} = 1; } if ($env{'form.subcat_'.$item} ne '') { my $newcat = $env{'form.subcat_'.$item}; my $newdepth = $depth+1; my $newitem = &escape($newcat).':'.&escape($cat).':'.$newdepth; - $domconfig{'coursecategories'}{$newitem} = 0; + $domconfig{'coursecategories'}{'cats'}{$newitem} = 0; $adds{$newitem} = 1; } } } if ($env{'form.instcode'} eq '1') { - if (ref($domconfig{'coursecategories'}) eq 'HASH') { + if (ref($cathash) eq 'HASH') { my $newitem = 'instcode::0'; - if ($domconfig{'coursecategories'}{$newitem} eq '') { - $domconfig{'coursecategories'}{$newitem} = $env{'form.instcode_pos'}; + if ($cathash->{$newitem} eq '') { + $domconfig{'coursecategories'}{'cats'}{$newitem} = $env{'form.instcode_pos'}; $adds{$newitem} = 1; } } else { my $newitem = 'instcode::0'; - $domconfig{'coursecategories'}{$newitem} = $env{'form.instcode_pos'}; + $domconfig{'coursecategories'}{'cats'}{$newitem} = $env{'form.instcode_pos'}; $adds{$newitem} = 1; } } if ($env{'form.addcategory_name'} ne '') { my $newitem = &escape($env{'form.addcategory_name'}).'::0'; - $domconfig{'coursecategories'}{$newitem} = $env{'form.addcategory_pos'}; + $domconfig{'coursecategories'}{'cats'}{$newitem} = $env{'form.addcategory_pos'}; $adds{$newitem} = 1; } + my $putresult; if ((keys(%deletions) > 0) || (keys(%reorderings) > 0) || (keys(%adds) > 0)) { - my %sort_by_deltrail; if (keys(%deletions) > 0) { foreach my $key (keys(%deletions)) { if ($predelallitems{$key} ne '') { @@ -4328,7 +4931,7 @@ sub modify_coursecategories { } } my (@chkcats,@chktrails,%chkallitems); - &Apache::loncommon::extract_categories($domconfig{'coursecategories'},\@chkcats,\@chktrails,\%chkallitems); + &Apache::loncommon::extract_categories($domconfig{'coursecategories'}{'cats'},\@chkcats,\@chktrails,\%chkallitems); if (ref($chkcats[0]) eq 'ARRAY') { my $depth = 0; my $chg = 0; @@ -4340,59 +4943,208 @@ sub modify_coursecategories { } else { $item = &escape($name).'::0'; if ($chg) { - $domconfig{'coursecategories'}{$item} -= $chg; + $domconfig{'coursecategories'}{'cats'}{$item} -= $chg; } $depth ++; - &recurse_check(\@chkcats,$domconfig{'coursecategories'},$depth,$name); + &recurse_check(\@chkcats,$domconfig{'coursecategories'}{'cats'},$depth,$name); $depth --; } } } - my $putresult = &Apache::lonnet::put_dom('configuration',\%domconfig,$dom); - my (@cats,@trails,%allitems); - &Apache::loncommon::extract_categories($domconfig{'coursecategories'},\@cats,\@trails,\%allitems); + } + if ((keys(%changes) > 0) || (keys(%deletions) > 0) || (keys(%reorderings) > 0) || (keys(%adds) > 0)) { + $putresult = &Apache::lonnet::put_dom('configuration',\%domconfig,$dom); if ($putresult eq 'ok') { + my %title = ( + togglecats => 'Show/Hide a course in the catalog', + categorize => 'Category assigned to course', + ); + my %level = ( + dom => 'set from "Modify Course" (Domain)', + crs => 'set from "Parameters" (Course)', + ); $resulttext = &mt('Changes made:').'
      '; - if (keys(%deletions) > 0) { - $resulttext .= '
    • '.&mt('Deleted categories:').'
        '; - foreach my $predeltrail (sort {$a <=> $b } (keys(%sort_by_deltrail))) { - $resulttext .= '
      • '.$predeltrails[$predeltrail].'
      • '; + if ($changes{'togglecats'}) { + $resulttext .= '
      • '.&mt("$title{'togglecats'} $level{$env{'form.togglecats'}}").'
      • '; + } + if ($changes{'categorize'}) { + $resulttext .= '
      • '.&mt("$title{'categorize'} $level{$env{'form.categorize'}}").'
      • '; + } + if ((keys(%deletions) > 0) || (keys(%reorderings) > 0) || (keys(%adds) > 0)) { + my $cathash; + if (ref($domconfig{'coursecategories'}) eq 'HASH') { + $cathash = $domconfig{'coursecategories'}{'cats'}; + } else { + $cathash = {}; + } + my (@cats,@trails,%allitems); + &Apache::loncommon::extract_categories($cathash,\@cats,\@trails,\%allitems); + if (keys(%deletions) > 0) { + $resulttext .= '
      • '.&mt('Deleted categories:').'
          '; + foreach my $predeltrail (sort {$a <=> $b } (keys(%sort_by_deltrail))) { + $resulttext .= '
        • '.$predeltrails[$predeltrail].'
        • '; + } + $resulttext .= '
      • '; + } + if (keys(%reorderings) > 0) { + my %sort_by_trail; + $resulttext .= '
      • '.&mt('Reordered categories:').'
          '; + foreach my $key (keys(%reorderings)) { + if ($allitems{$key} ne '') { + $sort_by_trail{$allitems{$key}} = $trails[$allitems{$key}]; + } + } + foreach my $trail (sort {$a <=> $b } (keys(%sort_by_trail))) { + $resulttext .= '
        • '.$trails[$trail].'
        • '; + } + $resulttext .= '
      • '; + } + if (keys(%adds) > 0) { + my %sort_by_trail; + $resulttext .= '
      • '.&mt('Added categories:').'
          '; + foreach my $key (keys(%adds)) { + if ($allitems{$key} ne '') { + $sort_by_trail{$allitems{$key}} = $trails[$allitems{$key}]; + } + } + foreach my $trail (sort {$a <=> $b } (keys(%sort_by_trail))) { + $resulttext .= '
        • '.$trails[$trail].'
        • '; + } + $resulttext .= '
      • '; + } + } + $resulttext .= '
      '; + } else { + $resulttext = ''. + &mt('An error occurred: [_1]',$putresult).''; + } + } else { + $resulttext = &mt('No changes made to course categories'); + } + return $resulttext; +} + +sub modify_serverstatuses { + my ($dom,%domconfig) = @_; + my ($resulttext,%changes,%currserverstatus,%newserverstatus); + if (ref($domconfig{'serverstatuses'}) eq 'HASH') { + %currserverstatus = %{$domconfig{'serverstatuses'}}; + } + my @pages = &serverstatus_pages(); + foreach my $type (@pages) { + $newserverstatus{$type}{'namedusers'} = ''; + $newserverstatus{$type}{'machines'} = ''; + if (defined($env{'form.'.$type.'_namedusers'})) { + my @users = split(/,/,$env{'form.'.$type.'_namedusers'}); + my @okusers; + foreach my $user (@users) { + my ($uname,$udom) = split(/:/,$user); + if (($udom =~ /^$match_domain$/) && + (&Apache::lonnet::domain($udom)) && + ($uname =~ /^$match_username$/)) { + if (!grep(/^\Q$user\E/,@okusers)) { + push(@okusers,$user); + } } - $resulttext .= '
  • '; } - if (keys(%reorderings) > 0) { - my %sort_by_trail; - $resulttext .= '
  • '.&mt('Reordered categories:').'
      '; - foreach my $key (keys(%reorderings)) { - if ($allitems{$key} ne '') { - $sort_by_trail{$allitems{$key}} = $trails[$allitems{$key}]; + if (@okusers > 0) { + @okusers = sort(@okusers); + $newserverstatus{$type}{'namedusers'} = join(',',@okusers); + } + } + if (defined($env{'form.'.$type.'_machines'})) { + my @machines = split(/,/,$env{'form.'.$type.'_machines'}); + my @okmachines; + foreach my $ip (@machines) { + my @parts = split(/\./,$ip); + next if (@parts < 4); + my $badip = 0; + for (my $i=0; $i<4; $i++) { + if (!(($parts[$i] >= 0) && ($parts[$i] <= 255))) { + $badip = 1; + last; } } - foreach my $trail (sort {$a <=> $b } (keys(%sort_by_trail))) { - $resulttext .= '
    • '.$trails[$trail].'
    • '; + if (!$badip) { + push(@okmachines,$ip); } - $resulttext .= '
  • '; } - if (keys(%adds) > 0) { - my %sort_by_trail; - $resulttext .= '
  • '.&mt('Added categories:').'
      '; - foreach my $key (keys(%adds)) { - if ($allitems{$key} ne '') { - $sort_by_trail{$allitems{$key}} = $trails[$allitems{$key}]; + @okmachines = sort(@okmachines); + $newserverstatus{$type}{'machines'} = join(',',@okmachines); + } + } + my %serverstatushash = ( + serverstatuses => \%newserverstatus, + ); + my %changes; + foreach my $type (@pages) { + foreach my $setting ('namedusers','machines') { + my (@current,@new); + if (ref($currserverstatus{$type}) eq 'HASH') { + if ($currserverstatus{$type}{$setting} ne '') { + @current = split(/,/,$currserverstatus{$type}{$setting}); + } + } + if ($newserverstatus{$type}{$setting} ne '') { + @new = split(/,/,$newserverstatus{$type}{$setting}); + } + if (@current > 0) { + if (@new > 0) { + foreach my $item (@current) { + if (!grep(/^\Q$item\E$/,@new)) { + $changes{$type}{$setting} = 1; + last; + } + } + foreach my $item (@new) { + if (!grep(/^\Q$item\E$/,@current)) { + $changes{$type}{$setting} = 1; + last; + } } + } else { + $changes{$type}{$setting} = 1; } - foreach my $trail (sort {$a <=> $b } (keys(%sort_by_trail))) { - $resulttext .= '
    • '.$trails[$trail].'
    • '; + } elsif (@new > 0) { + $changes{$type}{$setting} = 1; + } + } + } + if (keys(%changes) > 0) { + my $titles= &LONCAPA::lonauthcgi::serverstatus_titles(); + my $putresult = &Apache::lonnet::put_dom('configuration', + \%serverstatushash,$dom); + if ($putresult eq 'ok') { + $resulttext .= &mt('Changes made:').'
        '; + foreach my $type (@pages) { + if (ref($changes{$type}) eq 'HASH') { + $resulttext .= '
      • '.$titles->{$type}.'
          '; + if ($changes{$type}{'namedusers'}) { + if ($newserverstatus{$type}{'namedusers'} eq '') { + $resulttext .= '
        • '.&mt("Access terminated for all specific (named) users").'
        • '."\n"; + } else { + $resulttext .= '
        • '.&mt("Access available for the following specified users: ").$newserverstatus{$type}{'namedusers'}.'
        • '."\n"; + } + } + if ($changes{$type}{'machines'}) { + if ($newserverstatus{$type}{'machines'} eq '') { + $resulttext .= '
        • '.&mt("Access terminated for all specific IP addresses").'
        • '."\n"; + } else { + $resulttext .= '
        • '.&mt("Access available for the following specified IP addresses: ").$newserverstatus{$type}{'machines'}.'
        • '."\n"; + } + + } + $resulttext .= '
      • '; } - $resulttext .= '
      '; } $resulttext .= '
    '; } else { $resulttext = ''. - &mt('An error occurred: [_1]',$putresult).''; + &mt('An error occurred saving access settings for server status pages: [_1].',$putresult).''; + } } else { - $resulttext = &mt('No changes made to course categories'); + $resulttext = &mt('No changes made to access to server status pages'); } return $resulttext; }
  • '.&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'}.' '. + '
    '.$title{'categorize'}.''. + ' '. + '
    ' + .''; + if ($parent eq 'instcode') { + $datatable .= ''.&mt('Official courses') + .'
    (' + .&mt('with institutional codes').')
    ' - .'
    '; - if ($parent eq 'instcode') { - $datatable .= ''.&mt('Official courses') - .'
    (' - .&mt('with institutional codes').')
    '.&mt('Add category:').' ' + .'
    '.&mt('New:').' ' - .'
    '. - '
    '. + '' + .&mt('Official courses').''.'
    (' + .&mt('with institutional codes').')
     ' + .'
    ' - .&mt('Official courses').''.'
    (' - .&mt('with institutional codes').')
     ' - .'
    '.$hdritem->{'header'}->[0]->{'col2'}.''.$hdritem->{'header'}->[0]->{'col2'}.''. + $titles->{$type}.''. + ''. + ''. + ''. + '