--- loncom/interface/domainprefs.pm 2008/06/30 03:47:12 1.58 +++ loncom/interface/domainprefs.pm 2008/12/18 17:06:00 1.76.2.3 @@ -1,7 +1,7 @@ # The LearningOnline Network with CAPA # Handler to set domain-wide configuration settings # -# $Id: domainprefs.pm,v 1.58 2008/06/30 03:47:12 raeburn Exp $ +# $Id: domainprefs.pm,v 1.76.2.3 2008/12/18 17:06:00 raeburn 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::loncgi(); use File::Copy; use Locale::Language; +use DateTime::TimeZone; +use DateTime::Locale; sub handler { my $r=shift; @@ -71,15 +74,15 @@ sub handler { &Apache::lonnet::get_dom('configuration',['login','rolecolors', 'quotas','autoenroll','autoupdate','directorysrch', 'usercreation','usermodification','contacts','defaults', - 'scantron','coursecategories'],$dom); + 'scantron','coursecategories','serverstatuses'],$dom); my @prefs_order = ('rolecolors','login','defaults','quotas','autoenroll', 'autoupdate','directorysrch','contacts', 'usercreation','usermodification','scantron', - 'coursecategories'); + '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 +94,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', + { text => 'User blogs, home pages and portfolios', + help => 'Domain_Configuration_Quotas', header => [{col1 => 'User type', - col2 => 'Default quota'}], + 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 +127,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,30 +148,40 @@ 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' => + 'coursecategories' => { text => 'Cataloging of courses', - help => 'Domain_Course_Catalog', - header => [{col1 => 'Category settings', + 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'); @@ -257,7 +271,7 @@ sub handler { $r->print('<input type="hidden" name="phase" value="" />'. '<input type="hidden" name="numcols" value="'. $env{'form.numcols'}.'" />'."\n". - '<span clas="LC_error">'.&mt('No settings chosen'). + '<span class="LC_error">'.&mt('No settings chosen'). '</span>'); } $r->print('</form>'); @@ -316,7 +330,10 @@ sub handler { } $count = 0; foreach my $item (@prefs_order) { - $r->print('<h4><label><input type="checkbox" name="actions" value="'.$item.'" /> '.&mt($prefs{$item}->{'text'}).'</label></h4>'); + $r->print('<h4>'. + &Apache::loncommon::help_open_topic($prefs{$item}->{'help'}). + '<label><input type="checkbox" name="actions" value="'.$item. + '" /> '.&mt($prefs{$item}->{'text'}).'</label></h4>'); $count ++; if ((!$seconddiv) && ($count >= $midpoint)) { $r->print('</div>'."\n".'<div class="LC_left_float">'."\n"); @@ -365,6 +382,8 @@ 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); } return $output; } @@ -379,27 +398,27 @@ sub print_config_box { $output .= '<table class="LC_nested_outer"> <tr> - <th align="left"><span class="LC_nobreak">'.&mt($item->{text}). - ' </span></th></tr>'; -# -# FIXME - put the help link back in when the help files exist -# <th>'.&mt($item->{text}).' '. -# &Apache::loncommon::help_open_topic($item->{'help'}).'</th> -# </tr>'); + <th align="left" valign="middle"><span class="LC_nobreak">'. + &mt($item->{text}).' '. + &Apache::loncommon::help_open_topic($item->{'help'}).'</span></th>'."\n". + '</tr>'; $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 .= ' <tr> <td> <table class="LC_nested"> <tr class="LC_info_row"> - <td class="LC_left_item"'.$colspan.'>'.$item->{'header'}->[0]->{'col1'}.'</td> - <td class="LC_right_item">'.$item->{'header'}->[0]->{'col2'}.'</td> + <td class="LC_left_item"'.$colspan.'>'.&mt($item->{'header'}->[0]->{'col1'}).'</td> + <td class="LC_right_item">'.&mt($item->{'header'}->[0]->{'col2'}).'</td> </tr>'; - $rowtotal ++; + $rowtotal ++; if ($action eq 'autoupdate') { $output .= &print_autoupdate('top',$dom,$settings,\$rowtotal); } elsif ($action eq 'usercreation') { @@ -419,10 +438,9 @@ sub print_config_box { <td> <table class="LC_nested"> <tr class="LC_info_row"> - <td class="LC_left_item"'.$colspan.'>'.$item->{'header'}->[1]->{'col1'}.'</td>'; - my $colspan = ($action eq 'coursecategories')?' colspan="2"':''; + <td class="LC_left_item"'.$colspan.'>'.&mt($item->{'header'}->[1]->{'col1'}).'</td>'; $output .= ' - <td class="LC_right_item"'.$colspan.'>'.$item->{'header'}->[1]->{'col2'}.'</td> + <td class="LC_right_item"'.$colspan.'>'.&mt($item->{'header'}->[1]->{'col2'}).'</td> </tr>'; $rowtotal ++; if ($action eq 'autoupdate') { @@ -436,12 +454,24 @@ sub print_config_box { <td> <table class="LC_nested"> <tr class="LC_info_row"> - <td class="LC_left_item"'.$colspan.'>'.$item->{'header'}->[2]->{'col1'}.'</td> - <td class="LC_right_item">'.$item->{'header'}->[2]->{'col2'}.'</td> </tr>'. + <td class="LC_left_item"'.$colspan.'>'.&mt($item->{'header'}->[2]->{'col1'}).'</td> + <td class="LC_right_item">'.&mt($item->{'header'}->[2]->{'col2'}).'</td> </tr>'. &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).' + </table> + </td> + </tr> + <tr> + <td> + <table class="LC_nested"> + <tr class="LC_info_row"> + <td class="LC_left_item"'.$colspan.'>'.&mt($item->{'header'}->[2]->{'col1'}).'</td> + <td class="LC_right_item">'.&mt($item->{'header'}->[2]->{'col2'}).'</td> </tr>'. + + &print_usermodification('bottom',$dom,$settings,\$rowtotal); + $rowtotal ++; } elsif ($action eq 'coursecategories') { $output .= &print_coursecategories('bottom',$dom,$item,$settings,\$rowtotal); } else { @@ -453,8 +483,10 @@ sub print_config_box { <td> <table class="LC_nested"> <tr class="LC_info_row"> - <td class="LC_left_item"'.$colspan.'>'.$item->{'header'}->[2]->{'col1'}.'</td> - <td class="LC_right_item">'.$item->{'header'}->[2]->{'col2'}.'</td> + <td class="LC_left_item"'.$colspan.' valign="top">'. + &mt($item->{'header'}->[2]->{'col1'}).'</td> + <td class="LC_right_item" valign="top">'. + &mt($item->{'header'}->[2]->{'col2'}).'</td> </tr>'. &print_rolecolors($phase,'author',$dom,$confname,$settings,\$rowtotal).' </table> @@ -464,8 +496,8 @@ sub print_config_box { <td> <table class="LC_nested"> <tr class="LC_info_row"> - <td class="LC_left_item"'.$colspan.'>'.$item->{'header'}->[3]->{'col1'}.'</td> - <td class="LC_right_item">'.$item->{'header'}->[3]->{'col2'}.'</td> + <td class="LC_left_item"'.$colspan.'>'.&mt($item->{'header'}->[3]->{'col1'}).'</td> + <td class="LC_right_item">'.&mt($item->{'header'}->[3]->{'col2'}).'</td> </tr>'. &print_rolecolors($phase,'admin',$dom,$confname,$settings,\$rowtotal); $rowtotal += 2; @@ -478,14 +510,36 @@ sub print_config_box { <tr class="LC_info_row">'; if (($action eq 'login') || ($action eq 'directorysrch')) { $output .= ' - <td class="LC_left_item" colspan="2">'.$item->{'header'}->[0]->{'col1'}.'</td>'; + <td class="LC_left_item" colspan="2">'.&mt($item->{'header'}->[0]->{'col1'}).'</td>'; + } elsif ($action eq 'serverstatuses') { + $output .= ' + <td class="LC_left_item" valign="top">'.&mt($item->{'header'}->[0]->{'col1'}). + '<br />('.&mt('Automatic access for Dom. Coords.').')</td>'; + } else { $output .= ' - <td class="LC_left_item">'.$item->{'header'}->[0]->{'col1'}.'</td>'; + <td class="LC_left_item" valign="top">'.&mt($item->{'header'}->[0]->{'col1'}).'</td>'; } - $output .= ' - <td class="LC_right_item">'.$item->{'header'}->[0]->{'col2'}.'</td> - </tr>'; + if (defined($item->{'header'}->[0]->{'col3'})) { + $output .= '<td class="LC_left_item" valign="top">'. + &mt($item->{'header'}->[0]->{'col2'}); + if ($action eq 'serverstatuses') { + $output .= '<br />(<tt>'.&mt('user1:domain1,user2:domain2 etc.').'</tt>)'; + } + } else { + $output .= '<td class="LC_right_item" valign="top">'. + &mt($item->{'header'}->[0]->{'col2'}); + } + $output .= '</td>'; + if ($item->{'header'}->[0]->{'col3'}) { + $output .= '<td class="LC_right_item" valign="top">'. + &mt($item->{'header'}->[0]->{'col3'}); + if ($action eq 'serverstatuses') { + $output .= '<br />(<tt>'.&mt('IP1,IP2 etc.').'</tt>)'; + } + $output .= '</td>'; + } + $output .= '</tr>'; $rowtotal ++; if ($action eq 'login') { $output .= &print_login($dom,$confname,$phase,$settings,\$rowtotal); @@ -501,6 +555,8 @@ sub print_config_box { $output .= &print_defaults($dom,\$rowtotal); } elsif ($action eq 'scantron') { $output .= &print_scantronformat($r,$dom,$confname,$settings,\$rowtotal); + } elsif ($action eq 'serverstatuses') { + $output .= &print_serverstatuses($dom,$settings,\$rowtotal); } } $output .= ' @@ -644,6 +700,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}; @@ -665,10 +722,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 '') { @@ -862,20 +922,27 @@ sub display_color_options { $itemcount ++; $css_class = $itemcount%2?' class="LC_odd_row"':''; $datatable .= '<tr'.$css_class.'>'. - '<td>'.$choices->{$img}.'</td>'; + '<td>'.$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 .= '</td>'; 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)/([^/]+)$-) { @@ -964,7 +1031,7 @@ sub display_color_options { my $bgs_def; foreach my $item (@{$bgs}) { if (!$is_custom->{$item}) { - $bgs_def .= '<td>'.$choices->{$item}.' <span id="css_default_'.$role.'_'.$item.'" style="background-color: '.$defaults->{'bgs'}{$item}.';"> </span><br />'.$defaults->{'bgs'}{$item}.'</td>'; + $bgs_def .= '<td><span class="LC_nobreak">'.$choices->{$item}.'</span> <span id="css_default_'.$role.'_'.$item.'" style="background-color: '.$defaults->{'bgs'}{$item}.';"> </span><br />'.$defaults->{'bgs'}{$item}.'</td>'; } } if ($bgs_def) { @@ -1015,6 +1082,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 '<br /><label> <input type="checkbox" name="'. + 'login_showlogo_'.$img.'" value="1" '.$checkedon.'/>'. + &mt('show').'</label>'."\n"; +} + sub login_header_options { my ($img,$role,$defaults,$is_custom,$choices,$loginheader) = @_; my $image_checked = ' checked="checked" '; @@ -1066,7 +1159,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:').'<br />'; } else { $output .= &mt('Default in use:').'<br />'; @@ -1148,23 +1241,50 @@ sub print_quotas { my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom); my $typecount = 0; my $css_class; + my @usertools = ('aboutme','blog','portfolio'); + my %titles = &tool_titles(); if (ref($types) eq 'ARRAY') { foreach my $type (@{$types}) { + my $currdefquota; + 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 .= '<tr'.$css_class.'>'. + $datatable .= '<tr'.$css_class.'>'. '<td>'.$usertypes->{$type}.'</td>'. - '<td class="LC_right_item"><span class="LC_nobreak">'. + '<td class="LC_left_item">'; + foreach my $item (@usertools) { + my $checked = 'checked="checked" '; + if (ref($settings) eq 'HASH') { + if (ref($settings->{$item}) eq 'HASH') { + if ($settings->{$item}->{$type} == 0) { + $checked = ''; + } + } + } + $datatable .= '<span class="LC_nobreak"><label>'. + '<input type="checkbox" name="tools_'.$item. + '" value="'.$type.'" '.$checked.'/>'.$titles{$item}. + '</label></span> '; + } + $datatable .= '</td><td class="LC_right_item"><span class="LC_nobreak">'. '<input type="text" name="quota_'.$type. - '" value="'.$settings->{$type}. + '" value="'.$currdefquota. '" size="5" /> Mb</span></td></tr>'; } } } my $defaultquota = '20'; if (ref($settings) eq 'HASH') { - if (defined($settings->{'default'})) { + if (ref($settings->{'defaultquota'}) eq 'HASH') { + $defaultquota = $settings->{'defaultquota'}->{'default'}; + } elsif (defined($settings->{'default'})) { $defaultquota = $settings->{'default'}; } } @@ -1172,9 +1292,44 @@ sub print_quotas { $css_class = $typecount%2?' class="LC_odd_row"':''; $datatable .= '<tr'.$css_class.'>'. '<td>'.$othertitle.'</td>'. - '<td class="LC_right_item"><span class="LC_nobreak">'. + '<td class="LC_left_item">'; + foreach my $item (@usertools) { + my $checked = 'checked="checked" '; + if (ref($settings) eq 'HASH') { + if (ref($settings->{$item}) eq 'HASH') { + if ($settings->{$item}->{'default'} == 0) { + $checked = ''; + } + } + } + $datatable .= '<span class="LC_nobreak"><label>'. + '<input type="checkbox" name="tools_'.$item. + '" value="default" '.$checked.'/>'.$titles{$item}. + '</label></span> '; + } + $datatable .= '</td><td class="LC_right_item"><span class="LC_nobreak">'. '<input type="text" name="defaultquota" value="'. $defaultquota.'" size="5" /> Mb</span></td></tr>'; + $typecount ++; + $css_class = $typecount%2?' class="LC_odd_row"':''; + $datatable .= '<tr'.$css_class.'>'. + '<td><br/>'.&mt('LON-CAPA Advanced Users').'</td>'. + '<td class="LC_left_item" colspan="2"><br />'; + foreach my $item (@usertools) { + my $checked = 'checked="checked" '; + if (ref($settings) eq 'HASH') { + if (ref($settings->{$item}) eq 'HASH') { + if ($settings->{$item}->{'_LC_adv'} == 0) { + $checked = ''; + } + } + } + $datatable .= '<span class="LC_nobreak"><label>'. + '<input type="checkbox" name="tools_'.$item. + '" value="_LC_adv" '.$checked.'/>'.$titles{$item}. + '</label></span> '; + } + $datatable .= '('.&mt('overrides affiliation').')</td></tr>'; $$rowtotal += $typecount; return $datatable; } @@ -1448,24 +1603,17 @@ sub print_contacts { 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 .= '<tr'.$css_class.'>'. '<td><span class="LC_nobreak">'.$titles->{$item}. '</span></td><td class="LC_right_item">'. '<input type="text" name="'.$item.'" value="'. $to{$item}.'" /></td></tr>'; - $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 .= '<tr'.$css_class.'>'. '<td><span class="LC_nobreak">'. $titles->{$type}.': </span></td>'. @@ -1482,7 +1630,6 @@ sub print_contacts { '<input type="text" name="'.$type.'_others" '. 'value="'.$otheremails{$type}.'" />'. '</td></tr>'."\n"; - $rownum ++; } $$rowtotal += $rownum; return $datatable; @@ -1491,7 +1638,7 @@ 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' @@ -1503,6 +1650,15 @@ sub contact_titles { return (\%titles,\%short_titles); } +sub tool_titles { + my %titles = &Apache::lonlocal::texthash ( + aboutme => 'Personal Home Page', + blog => 'Blog', + portfolio => 'Portfolio', + ); + return %titles; +} + sub print_usercreation { my ($position,$dom,$settings,$rowtotal) = @_; my $numinrow = 4; @@ -1682,10 +1838,14 @@ sub user_formats_row { ); my $css_class = $rowcount%2?' class="LC_odd_row"':''; $output = '<tr '.$css_class.'>'. - '<td><span class="LC_nobreak">'. - &mt("Format rules to check for $text{$type}: "). - '</span></td>'. - '<td class="LC_left_item" colspan="2"><table>'; + '<td><span class="LC_nobreak">'; + if ($type eq 'email') { + $output .= &mt("Formats disallowed for $text{$type}: "); + } else { + $output .= &mt("Format rules to check for $text{$type}: "); + } + $output .= '</span></td>'. + '<td class="LC_left_item" colspan="2"><table>'; my $rem; if (ref($ruleorder) eq 'ARRAY') { for (my $i=0; $i<@{$ruleorder}; $i++) { @@ -1773,7 +1933,7 @@ sub print_usermodification { $$rowtotal ++; $rowcount ++; } - } else { + } elsif ($position eq 'middle') { $context = 'course'; $rowcount = 0; foreach my $role ('st','ep','ta','in','cr') { @@ -1782,13 +1942,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; @@ -1823,6 +1998,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 .= '<input type="text" name="'.$item.'" value="'. $domdefaults{$item}.'" />'; @@ -1840,6 +2018,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); } @@ -1847,7 +2026,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 +2054,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'} = + '<span class="LC_error">'. + &mt('An error occurred updating the domain configuration: [_1]',$putresult).'</span>'; + } } } 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'} = + '<span class="LC_error">'. + &mt('An error occurred updating the domain configuration: [_1]',$putresult).'</span>'; + } + } else { + $error{'default'} = $error; + } } } } @@ -1911,39 +2120,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 .= '<tr'.$css_class.'>'; if (!$is_custom) { - $datatable .= '<td>'.&mt('Default in use:').'<br />'; + $datatable .= '<td>'.&mt('Default in use:').'<br />'. + '<span class="LC_nobreak">'; if ($scantronurl) { $datatable .= '<a href="'.$scantronurl.'" target="_blank">'. &mt('Default scantron format file').'</a>'; } else { $datatable = &mt('File unavailable for display'); } - $datatable .= '</td><td valign="bottom">'.&mt('Upload:').'<br />'; + $datatable .= '</span></td>'; + if (keys(%error) == 0) { + $datatable .= '<td valign="bottom">'; + if (!$switchserver) { + $datatable .= &mt('Upload:').'<br />'; + } + } else { + my $errorstr; + foreach my $key (sort(keys(%error))) { + $errorstr .= $lt{$key}.': '.$error{$key}.'<br />'; + } + $datatable .= '<td>'.$errorstr; + } } else { if (keys(%error) > 0) { my $errorstr; foreach my $key (sort(keys(%error))) { $errorstr .= $lt{$key}.': '.$error{$key}.'<br />'; } - $datatable .= '<td>'.$errorstr.'</td><td>'; + $datatable .= '<td>'.$errorstr.'</td><td> '; } elsif ($scantronurl) { - $datatable .= '<td><a href="'.$scantronurl.'" target="_blank">' .&mt('Custom scantron format file').'</a>' - .'<span class="LC_nobreak"><label>' - .'<input type="checkbox" name="scantronformat_del"' - .'" value="1" />'.&mt('Delete?').'</label></td>' - .'<td>'.&mt('Replace:').'</span><br />'; + $datatable .= '<td><span class="LC_nobreak">'. + '<a href="'.$scantronurl.'" target="_blank">'. + &mt('Custom scantron format file').'</a><label>'. + '<input type="checkbox" name="scantronformat_del"'. + '" value="1" />'.&mt('Delete?').'</label></span></td>'. + '<td><span class="LC_nobreak"> '. + &mt('Replace:').'</span><br />'; } } if (keys(%error) == 0) { if ($switchserver) { $datatable .= &mt('Upload to library server: [_1]',$switchserver); } else { - $datatable .=' <input type="file" name="scantronformat" />'; + $datatable .='<span class="LC_nobreak"> '. + '<input type="file" name="scantronformat" /></span>'; } } $datatable .= '</td></tr>'; @@ -1990,7 +2219,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 = '<tr class="LC_odd_row">'. '<td>'.$title{'togglecats'}.'</td>'. @@ -2081,7 +2310,7 @@ sub print_coursecategories { } $datatable .= '<option value="'.$k.'"'.$selstr.'>'.$vpos.'</option>'; } - $datatable .= '</select></span></td><td colspan="2">'.&mt('New:').' ' + $datatable .= '</select></span></td><td colspan="2">'.&mt('Add category:').' ' .'<input type="text" size="20" name="addcategory_name" value="" /></td>' .'</tr>'."\n"; $itemcount ++; @@ -2119,6 +2348,58 @@ sub print_coursecategories { 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::loncgi::serverstatus_titles(); + my $rownum = 0; + my $css_class; + foreach my $type (@pages) { + $rownum ++; + $css_class = $rownum%2?' class="LC_odd_row"':''; + $datatable .= '<tr'.$css_class.'>'. + '<td><span class="LC_nobreak">'. + $titles->{$type}.'</span></td>'. + '<td class="LC_left_item">'. + '<input type="text" name="'.$type.'_namedusers" '. + 'value="'.$namedaccess{$type}.'" size="30" /></td>'. + '<td class="LC_right_item">'. + '<span class="LC_nobreak">'. + '<input type="text" name="'.$type.'_machines" '. + 'value="'.$machineaccess{$type}.'" size="10" />'. + '</td></tr>'."\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,$cathash); @@ -2282,7 +2563,7 @@ sub build_category_rows { pop(@{$path}); } } else { - $text .= &mt('New:').' </span><input type="textbox" size="20" name="addcategory_name_'; + $text .= &mt('Add subcategory:').' </span><input type="textbox" size="20" name="addcategory_name_'; if ($j == $numchildren) { $text .= $name; } else { @@ -2314,12 +2595,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'); @@ -2669,6 +2958,13 @@ sub modify_colors { $domconfig->{$role} = {}; } foreach my $img (@images) { + if (($role eq 'login') && (($img eq 'img') || ($img eq 'logo'))) { + if (defined($env{'form.login_showlogo_'.$img})) { + $confhash->{$role}{'showlogo'}{$img} = 1; + } else { + $confhash->{$role}{'showlogo'}{$img} = 0; + } + } if ( ! $env{'form.'.$role.'_'.$img.'.filename'} && !defined($domconfig->{$role}{$img}) && !$env{'form.'.$role.'_del_'.$img} @@ -2743,7 +3039,19 @@ sub modify_colors { $changes{$role}{'images'}{$img} = 1; } } - } + if (($role eq 'login') && (($img eq 'logo') || ($img eq 'img'))) { + if (ref($domconfig->{'login'}{'showlogo'}) eq 'HASH') { + if ($confhash->{$role}{'showlogo'}{$img} ne + $domconfig->{$role}{'showlogo'}{$img}) { + $changes{$role}{'showlogo'}{$img} = 1; + } + } else { + if ($confhash->{$role}{'showlogo'}{$img} == 0) { + $changes{$role}{'showlogo'}{$img} = 1; + } + } + } + } if ($domconfig->{$role}{'font'} ne '') { if ($confhash->{$role}{'font'} ne $domconfig->{$role}{'font'}) { $changes{$role}{'font'} = 1; @@ -2835,6 +3143,11 @@ sub default_change_checker { $confhash->{$role}{$img} = ''; $changes->{$role}{'images'}{$img} = 1; } + if ($role eq 'login') { + if ($confhash->{$role}{'showlogo'}{$img} == 0) { + $changes->{$role}{'showlogo'}{$img} = 1; + } + } } if ($confhash->{$role}{'font'}) { $changes->{$role}{'font'} = 1; @@ -2866,7 +3179,13 @@ sub display_colorchgs { $resulttext .= '<li>'.&mt($choices{$key}).':<ul>'; } foreach my $item (sort(keys(%{$changes->{$role}{$key}}))) { - if ($confhash->{$role}{$item} eq '') { + if (($role eq 'login') && ($key eq 'showlogo')) { + if ($confhash->{$role}{$key}{$item}) { + $resulttext .= '<li>'.&mt("$choices{$item} set to be displayed").'</li>'; + } else { + $resulttext .= '<li>'.&mt("$choices{$item} set to not be displayed").'</li>'; + } + } elsif ($confhash->{$role}{$item} eq '') { $resulttext .= '<li>'.&mt("$choices{$item} set to default").'</li>'; } else { my $newitem = $confhash->{$role}{$item}; @@ -3185,57 +3504,150 @@ END sub modify_quotas { my ($dom,%domconfig) = @_; + my %domdefaults = &Apache::lonnet::get_domain_defaults($dom); my ($resulttext,%changes); my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom); - my %formhash; + my @usertools = ('aboutme','blog','portfolio'); + my %titles = &tool_titles(); + my (%confhash,%toolshash); foreach my $key (keys(%env)) { if ($key =~ /^form\.quota_(.+)$/) { - $formhash{$1} = $env{$key}; + $confhash{'defaultquota'}{$1} = $env{$key}; + } elsif ($key =~ /^form\.tools_(.+)$/) { + @{$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; + $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{'quotas'}) eq 'HASH') { + if (ref($domconfig{'quotas'}{$item}) eq 'HASH') { + if ($domconfig{'quotas'}{$item}{$type} ne $confhash{$item}{$type}) { + $changes{$item}{$type} = 1; + } + } else { + if (!$confhash{$item}{$type}) { + $changes{$item}{$type} = 1; + } } } else { - $formhash{$key} = $domconfig{'quotas'}{$key}; + if (!$confhash{$item}{$type}) { + $changes{$item}{$type} = 1; + } + } + } + } + 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 { + 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}; + } } } } - foreach my $key (keys(%formhash)) { - if ($formhash{$key} ne '') { + if (ref($confhash{'defaultquota'}) eq 'HASH') { + foreach my $key (keys(%{$confhash{'defaultquota'}})) { if (ref($domconfig{'quotas'}) eq 'HASH') { - if (!exists($domconfig{'quotas'}{$key})) { - $changes{$key} = 1; + 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{$key} = 1; + $changes{'defaultquota'}{$key} = 1; } } } + + foreach my $key (keys(%confhash)) { + $domdefaults{$key} = $confhash{$key}; + } + my %quotahash = ( - quotas => {%formhash}, + quotas => { %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:').'<ul>'; - foreach my $type (@{$types},'default') { - if (defined($changes{$type})) { - my $typetitle = $usertypes->{$type}; - if ($type eq 'default') { - $typetitle = $othertitle; + if (ref($changes{'defaultquota'}) eq 'HASH') { + $resulttext .= '<li>'.&mt('Portfolio default quotas').'<ul>'; + foreach my $type (@{$types},'default') { + if (defined($changes{'defaultquota'}{$type})) { + my $typetitle = $usertypes->{$type}; + if ($type eq 'default') { + $typetitle = $othertitle; + } + $resulttext .= '<li>'.&mt('[_1] set to [_2] Mb',$typetitle,$confhash{'defaultquota'}{$type}).'</li>'; + } + } + $resulttext .= '</ul></li>'; + } + 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'); + if ($env{'environment.tools.'.$item} ne '') { + if ($env{'environment.availabletools.'.$item} ne $newacc) { + $newenv{'environment.availabletools.'.$item} = $newacc; + } + } + $resulttext .= '<li>'.$titles{$item}.'<ul>'; + 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 .= '<li>'.&mt('Set to be available to [_1]',$typetitle).'</li>'; + } else { + $resulttext .= '<li>'.&mt('Set to be unavailable to [_1]',$typetitle).'</li>'; + } + } } - $resulttext .= '<li>'.&mt('[_1] set to [_2] Mb',$typetitle,$formhash{$type}).'</li>'; + $resulttext .= '</ul></li>'; } } $resulttext .= '</ul>'; + if (keys(%newenv)) { + &Apache::lonnet::appenv(\%newenv); + } } else { - $resulttext = &mt('No changes made to default quotas'); + $resulttext = &mt('No changes made to availability of home pages, blogs, portfolios or default quotas'); } } else { $resulttext = '<span class="LC_error">'. @@ -4042,10 +4454,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 +4466,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 +4519,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 .= '<li><span class="LC_cusr_emph">'.&mt('Target user with [_1] role',$rolename).'</span> - '.&mt('modifiable fields: '); + if ($context eq 'selfcreate') { + $resulttext .= '<li><span class="LC_cusr_emph">'.&mt('Self-creation of account by users with status: [_1] ',$rolename).'</span> - '.&mt('modifiable fields (if institutional data blank): '); + } else { + $resulttext .= '<li><span class="LC_cusr_emph">'.&mt('Target user with [_1] role',$rolename).'</span> - '.&mt('modifiable fields: '); + } foreach my $field (@fields) { if ($modifyhash{$context}{$role}{$field}) { push(@modifiable,$fieldtitles{$field}); @@ -4138,7 +4570,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}; @@ -4161,25 +4593,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); @@ -4208,9 +4643,8 @@ sub modify_defaults { $resulttext .= '</ul>'; $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); } @@ -4491,6 +4925,132 @@ sub modify_coursecategories { } 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); + } + } + } + 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; + } + } + if (!$badip) { + push(@okmachines,$ip); + } + } + @okmachines = sort(@okmachines); + $newserverstatus{$type}{'machines'} = join(',',@okmachines); + } + } + my %serverstatushash = ( + serverstatuses => \%newserverstatus, + ); + my $putresult = &Apache::lonnet::put_dom('configuration',\%serverstatushash, + $dom); + my %changes; + foreach my $type (@pages) { + if (ref($currserverstatus{$type}) eq 'HASH') { + my @currnamed = split(/,/,$currserverstatus{$type}{'namedusers'}); + my @newusers = split(/,/,$newserverstatus{$type}{'namedusers'}); + foreach my $item (@currnamed) { + if (!grep(/^\Q$item\E$/,@newusers)) { + $changes{$type}{'namedusers'} = 1; + last; + } + } + foreach my $item (@newusers) { + if (!grep(/^\Q$item\E$/,@currnamed)) { + $changes{$type}{'namedusers'} = 1; + last; + } + } + my @currmachines = split(/,/,$currserverstatus{$type}{'machines'}); + my @newmachines = split(/,/,$newserverstatus{$type}{'machines'}); + foreach my $item (@currmachines) { + if (!grep(/^\Q$item\E$/,@newmachines)) { + $changes{$type}{'machines'} = 1; + last; + } + } + foreach my $item (@newmachines) { + if (!grep(/^\Q$item\E$/,@currmachines)) { + $changes{$type}{'machines'} = 1; + last; + } + } + + } + } + if (keys(%changes) > 0) { + my $titles= &LONCAPA::loncgi::serverstatus_titles(); + my $putresult = &Apache::lonnet::put_dom('configuration', + \%serverstatushash,$dom); + if ($putresult eq 'ok') { + $resulttext .= &mt('Changes made:').'<ul>'; + foreach my $type (@pages) { + if (defined($changes{$type})) { + $resulttext .= '<li>'.$titles->{$type}.'<ul>'; + if (defined($changes{$type}{'namedusers'})) { + if ($newserverstatus{$type}{'namedusers'} eq '') { + $resulttext .= '<li>'.&mt("Access terminated for all specific (named) users").'</li>'."\n"; + } else { + $resulttext .= '<li>'.&mt("Access available for the following specified users: ").$newserverstatus{$type}{'namedusers'}.'</li>'."\n"; + } + } elsif (defined($changes{$type}{'machines'})) { + if ($newserverstatus{$type}{'machines'} eq '') { + $resulttext .= '<li>'.&mt("Access terminated for all specific IP addresses").'</li>'."\n"; + } else { + $resulttext .= '<li>'.&mt("Access available for the following specified IP addresses: ").$newserverstatus{$type}{'machines'}.'</li>'."\n"; + } + + } + $resulttext .= '</ul></li>'; + } + } + $resulttext .= '</ul>'; + } else { + $resulttext = '<span class="LC_error">'. + &mt('An error occurred saving access settings for server status pages: [_1].',$putresult).'</span>'; + + } + } else { + $resulttext = &mt('No changes made to access to server status pages'); + } + return $resulttext; +} sub recurse_check { my ($chkcats,$categories,$depth,$name) = @_;