--- loncom/interface/domainprefs.pm 2008/12/03 13:09:56 1.71 +++ loncom/interface/domainprefs.pm 2008/12/08 22:42:43 1.72 @@ -1,7 +1,7 @@ # The LearningOnline Network with CAPA # Handler to set domain-wide configuration settings # -# $Id: domainprefs.pm,v 1.71 2008/12/03 13:09:56 muellerd Exp $ +# $Id: domainprefs.pm,v 1.72 2008/12/08 22:42:43 raeburn Exp $ # # Copyright Michigan State University Board of Trustees # @@ -105,10 +105,11 @@ sub handler { col2 => 'Value'}], }, 'quotas' => - { text => 'Default quotas for user portfolios', + { 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', @@ -519,10 +520,12 @@ sub print_config_box { $output .= ' '.&mt($item->{'header'}->[0]->{'col1'}).''; } - if ($action eq 'serverstatuses') { - $output .= ''. - &mt($item->{'header'}->[0]->{'col2'}). - '
('.&mt('user1:domain1,user2:domain2 etc.').')'; + if (defined($item->{'header'}->[0]->{'col3'})) { + $output .= ''. + &mt($item->{'header'}->[0]->{'col2'}); + if ($action eq 'serverstatuses') { + $output .= '
('.&mt('user1:domain1,user2:domain2 etc.').')'; + } } else { $output .= ''. &mt($item->{'header'}->[0]->{'col2'}); @@ -1238,23 +1241,46 @@ 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->{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 .= ''. ''.$usertypes->{$type}.''. - ''. + ''; + foreach my $item (@usertools) { + my $checked = 'checked="checked" '; + if (ref($settings->{$item}) eq 'HASH') { + if ($settings->{$item}->{$type} == 0) { + $checked = ''; + } + } + $datatable .= '  '; + } + $datatable .= ''. ' Mb'; } } } 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'}; } } @@ -1262,9 +1288,40 @@ sub print_quotas { $css_class = $typecount%2?' class="LC_odd_row"':''; $datatable .= ''. ''.$othertitle.''. - ''. + ''; + foreach my $item (@usertools) { + my $checked = 'checked="checked" '; + if (ref($settings->{$item}) eq 'HASH') { + if ($settings->{$item}->{'default'} == 0) { + $checked = ''; + } + } + $datatable .= '  '; + } + $datatable .= ''. ' Mb'; + $typecount ++; + $css_class = $typecount%2?' class="LC_odd_row"':''; + $datatable .= ''. + '
'.&mt('LON-CAPA Advanced Users').''. + '
'; + foreach my $item (@usertools) { + my $checked = 'checked="checked" '; + if (ref($settings->{$item}) eq 'HASH') { + if ($settings->{$item}->{'_LC_adv'} == 0) { + $checked = ''; + } + } + $datatable .= '  '; + } + $datatable .= '('.&mt('overrides affiliation').')'; $$rowtotal += $typecount; return $datatable; } @@ -1585,6 +1642,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; @@ -3430,57 +3496,137 @@ 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:').'
    '; - 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 .= '
  • '.&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 .= '
  • '; + } + foreach my $item (@usertools) { + if (ref($changes{$item}) eq 'HASH') { + $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 .= '
    • '.&mt('[_1] set to [_2] Mb',$typetitle,$formhash{$type}).'
    • '; + $resulttext .= '
  • '; } } $resulttext .= '
'; } 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 = ''. @@ -4443,15 +4589,11 @@ sub modify_defaults { } 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'}, - datelocale_def => $newvalues{'datelocale_def'}, - } - ); + defaults => \%newvalues, + ); my $title = &defaults_titles(); my $putresult = &Apache::lonnet::put_dom('configuration',\%defaults_hash, $dom); @@ -4480,8 +4622,7 @@ sub modify_defaults { $resulttext .= ''; $mailmsgtext .= "\n"; my $cachetime = 24*60*60; - &Apache::lonnet::do_cache_new('domdefaults',$dom, - $defaults_hash{'defaults'},$cachetime); + &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);