--- loncom/interface/domainprefs.pm 2010/07/17 20:02:07 1.137 +++ loncom/interface/domainprefs.pm 2010/08/24 13:37:50 1.139 @@ -1,7 +1,7 @@ # The LearningOnline Network with CAPA # Handler to set domain-wide configuration settings # -# $Id: domainprefs.pm,v 1.137 2010/07/17 20:02:07 raeburn Exp $ +# $Id: domainprefs.pm,v 1.139 2010/08/24 13:37:50 raeburn Exp $ # # Copyright Michigan State University Board of Trustees # @@ -340,8 +340,10 @@ sub handler { 'coursedefaults' => {text => 'Course/Community defaults', help => 'Domain_Configuration_Course_Defaults', - header => [{col1 => 'Setting', - col2 => 'Value',}], + header => [{col1 => 'Defaults which can be overridden in each course by a CC', + col2 => 'Value',}, + {col1 => 'Defaults which can be overridden for each course by a DC', + col2 => 'Value',},], }, 'privacy' => {text => 'User Privacy', @@ -517,6 +519,8 @@ sub print_config_box { $output .= &print_usersessions('top',$dom,$settings,\$rowtotal); } elsif ($action eq 'rolecolors') { $output .= &print_rolecolors($phase,'student',$dom,$confname,$settings,\$rowtotal); + } elsif ($action eq 'coursedefaults') { + $output .= &print_coursedefaults('top',$dom,$settings,\$rowtotal); } $output .= ' @@ -580,6 +584,8 @@ sub print_config_box { $output .= &print_helpsettings('bottom',$dom,$confname,$settings,\$rowtotal); } elsif ($action eq 'usersessions') { $output .= &print_usersessions('bottom',$dom,$settings,\$rowtotal); + } elsif ($action eq 'coursedefaults') { + $output .= &print_coursedefaults('bottom',$dom,$settings,\$rowtotal); } elsif ($action eq 'rolecolors') { $output .= &print_rolecolors($phase,'coordinator',$dom,$confname,$settings,\$rowtotal).' @@ -668,8 +674,6 @@ sub print_config_box { $output .= &print_serverstatuses($dom,$settings,\$rowtotal); } elsif ($action eq 'helpsettings') { $output .= &print_helpsettings('top',$dom,$confname,$settings,\$rowtotal); - } elsif ($action eq 'coursedefaults') { - $output .= &print_coursedefaults($dom,$settings,\$rowtotal); } } $output .= ' @@ -2240,19 +2244,43 @@ sub radiobutton_prefs { } sub print_coursedefaults { - my ($dom,$settings,$rowtotal) = @_; + my ($position,$dom,$settings,$rowtotal) = @_; my ($css_class,$datatable); my $itemcount = 1; - my (%checkedon,%checkedoff,%choices,%defaultchecked,@toggles); - %choices = - &Apache::lonlocal::texthash ( - canuse_pdfforms => 'Course/Community users can create/upload PDF forms', - ); - %defaultchecked = ('canuse_pdfforms' => 'off'); - @toggles = ('canuse_pdfforms',); - ($datatable,$itemcount) = &radiobutton_prefs($settings,\@toggles,\%defaultchecked, + if ($position eq 'top') { + my (%checkedon,%checkedoff,%choices,%defaultchecked,@toggles); + %choices = + &Apache::lonlocal::texthash ( + canuse_pdfforms => 'Course/Community users can create/upload PDF forms', + ); + %defaultchecked = ('canuse_pdfforms' => 'off'); + @toggles = ('canuse_pdfforms',); + ($datatable,$itemcount) = &radiobutton_prefs($settings,\@toggles,\%defaultchecked, \%choices,$itemcount); - $$rowtotal += $itemcount; + $$rowtotal += $itemcount; + } else { + $css_class = $itemcount%2 ? ' class="LC_odd_row"' : ''; + my %choices = + &Apache::lonlocal::texthash ( + anonsurvey_threshold => 'Responder count needed before showing submissions for anonymous surveys', + ); + my $currdefresponder; + if (ref($settings) eq 'HASH') { + $currdefresponder = $settings->{'anonsurvey_threshold'}; + } + if (!$currdefresponder) { + $currdefresponder = 10; + } elsif ($currdefresponder < 1) { + $currdefresponder = 1; + } + $datatable .= + ''.$choices{'anonsurvey_threshold'}. + ''. + ''. + ''. + ''; + } return $datatable; } @@ -2270,10 +2298,12 @@ sub print_usersessions { } else { $prefix = 'remote'; @types = ('version','excludedomain','includedomain'); - } + } my (%current,%checkedon,%checkedoff); my @lcversions = &Apache::lonnet::all_loncaparevs(); - my @alldoms = sort(&Apache::lonnet::all_domains()); + my (%by_ip,%by_location,@intdoms); + &build_location_hashes(\@intdoms,\%by_ip,\%by_location); + my @locations = sort(keys(%by_location)); foreach my $type (@types) { $checkedon{$type} = ''; $checkedoff{$type} = ' checked="checked"'; @@ -2322,12 +2352,21 @@ sub print_usersessions { "\n". '
'; my $rem; - for (my $i=0; $i<@alldoms; $i++) { - next if ($alldoms[$i] eq $dom); - my $checkedtype; - if (ref($current{$type}) eq 'ARRAY') { - if (grep(/^\Q$alldoms[$i]\E$/,@{$current{$type}})) { - $checkedtype = ' checked="checked"'; + for (my $i=0; $i<@locations; $i++) { + my ($showloc,$value,$checkedtype); + if (ref($by_location{$locations[$i]}) eq 'ARRAY') { + my $ip = $by_location{$locations[$i]}->[0]; + if (ref($by_ip{$ip}) eq 'ARRAY') { + $value = join(':',@{$by_ip{$ip}}); + $showloc = join(', ',@{$by_ip{$ip}}); + if (ref($current{$type}) eq 'ARRAY') { + foreach my $loc (@{$by_ip{$ip}}) { + if (grep(/^\Q$loc\E$/,@{$current{$type}})) { + $checkedtype = ' checked="checked"'; + last; + } + } + } } } $rem = $i%($numinrow); @@ -2340,10 +2379,10 @@ sub print_usersessions { $datatable .= ''; } - $rem = @alldoms%($numinrow); + $rem = @locations%($numinrow); my $colsleft = $numinrow - $rem; if ($colsleft > 1 ) { $datatable .= '
'. ''. @@ -2360,6 +2399,54 @@ sub print_usersessions { return $datatable; } +sub build_location_hashes { + my ($intdoms,$by_ip,$by_location) = @_; + return unless((ref($intdoms) eq 'ARRAY') && (ref($by_ip) eq 'HASH') && + (ref($by_location) eq 'HASH')); + my %iphost = &Apache::lonnet::get_iphost(); + my $primary_id = &Apache::lonnet::domain($env{'request.role.domain'},'primary'); + my $primary_ip = &Apache::lonnet::get_host_ip($primary_id); + if (ref($iphost{$primary_ip}) eq 'ARRAY') { + foreach my $id (@{$iphost{$primary_ip}}) { + my $intdom = &Apache::lonnet::internet_dom($id); + unless(grep(/^\Q$intdom\E$/,@{$intdoms})) { + push(@{$intdoms},$intdom); + } + } + } + foreach my $ip (keys(%iphost)) { + if (ref($iphost{$ip}) eq 'ARRAY') { + foreach my $id (@{$iphost{$ip}}) { + my $location = &Apache::lonnet::internet_dom($id); + if ($location) { + next if (grep(/^\Q$location\E$/,@{$intdoms})); + if (ref($by_ip->{$ip}) eq 'ARRAY') { + unless(grep(/^\Q$location\E$/,@{$by_ip->{$ip}})) { + push(@{$by_ip->{$ip}},$location); + } + } else { + $by_ip->{$ip} = [$location]; + } + } + } + } + } + foreach my $ip (sort(keys(%{$by_ip}))) { + if (ref($by_ip->{$ip}) eq 'ARRAY') { + @{$by_ip->{$ip}} = sort(@{$by_ip->{$ip}}); + my $first = $by_ip->{$ip}->[0]; + if (ref($by_location->{$first}) eq 'ARRAY') { + unless (grep(/^\Q$ip\E$/,@{$by_location->{$first}})) { + push(@{$by_location->{$first}},$ip); + } + } else { + $by_location->{$first} = [$ip]; + } + } + } + return; +} + sub contact_titles { my %titles = &Apache::lonlocal::texthash ( 'supportemail' => 'Support E-mail address', @@ -6605,6 +6692,18 @@ sub modify_coursedefaults { } $defaultshash{'coursedefaults'}{$item} = $env{'form.'.$item}; } + my $currdefresponder = $domconfig{'coursedefaults'}{'anonsurvey_threshold'}; + my $newdefresponder = $env{'form.anonsurvey_threshold'}; + $newdefresponder =~ s/\D//g; + if ($newdefresponder eq '' || $newdefresponder < 1) { + $newdefresponder = 1; + } + $defaultshash{'coursedefaults'}{'anonsurvey_threshold'} = $newdefresponder; + if ($currdefresponder ne $newdefresponder) { + unless ($currdefresponder eq '' && $newdefresponder == 10) { + $changes{'anonsurvey_threshold'} = 1; + } + } } my $putresult = &Apache::lonnet::put_dom('configuration',\%defaultshash, $dom); @@ -6624,7 +6723,9 @@ sub modify_coursedefaults { } else { $resulttext .= '
  • '.&mt('Course/Community users can create/upload PDF forms set to "off"').'
  • '; } - } + } elsif ($item eq 'anonsurvey_threshold') { + $resulttext .= '
  • '.&mt('Responder count required for display of anonymous survey submissions set to [_1].',$defaultshash{'coursedefaults'}{'anonsurvey_threshold'}).'
  • '; + } } $resulttext .= ''; } else { @@ -6642,12 +6743,16 @@ sub modify_usersessions { my @types = ('version','excludedomain','includedomain'); my @prefixes = ('remote','hosted'); my @lcversions = &Apache::lonnet::all_loncaparevs(); + my (%by_ip,%by_location,@intdoms); + &build_location_hashes(\@intdoms,\%by_ip,\%by_location); + my @locations = sort(keys(%by_location)); my (%defaultshash,%changes); foreach my $prefix (@prefixes) { $defaultshash{'usersessions'}{$prefix} = {}; } my %domdefaults = &Apache::lonnet::get_domain_defaults($dom); my $resulttext; + my %iphost = &Apache::lonnet::get_iphost(); foreach my $prefix (@prefixes) { foreach my $type (@types) { my $inuse = $env{'form.'.$prefix.'_'.$type.'_inuse'}; @@ -6694,8 +6799,17 @@ sub modify_usersessions { my @vals = &Apache::loncommon::get_env_multiple('form.'.$prefix.'_'.$type); my @okvals; foreach my $val (@vals) { - if (&Apache::lonnet::domain($val) ne '') { - push(@okvals,$val); + if ($val =~ /:/) { + my @items = split(/:/,$val); + foreach my $item (@items) { + if (ref($by_location{$item}) eq 'ARRAY') { + push(@okvals,$item); + } + } + } else { + if (ref($by_location{$val}) eq 'ARRAY') { + push(@okvals,$val); + } } } @okvals = sort(@okvals); @@ -6942,8 +7056,8 @@ sub usersession_titles { remote => 'Hosting of sessions for users in this domain on servers in other domains', version => 'LON-CAPA version requirement', - excludedomain => 'Specific domains excluded', - includedomain => 'Specific domains included', + excludedomain => 'Allow all, but exclude specific domains', + includedomain => 'Deny all, but include specific domains', ); }