--- loncom/interface/domainprefs.pm 2007/07/28 21:23:53 1.24 +++ loncom/interface/domainprefs.pm 2007/09/01 21:20:14 1.26 @@ -1,7 +1,7 @@ # The LearningOnline Network with CAPA # Handler to set domain-wide configuration settings # -# $Id: domainprefs.pm,v 1.24 2007/07/28 21:23:53 raeburn Exp $ +# $Id: domainprefs.pm,v 1.26 2007/09/01 21:20:14 raeburn Exp $ # # Copyright Michigan State University Board of Trustees # @@ -745,7 +745,7 @@ sub print_quotas { my ($othertitle,$usertypes,$types) = &sorted_inst_types($dom); my $typecount = 0; my $css_class; - if (@{$types} > 0) { + if (ref($types) eq 'ARRAY') { foreach my $type (@{$types}) { if (defined($usertypes->{$type})) { $typecount ++; @@ -768,7 +768,7 @@ sub print_quotas { $typecount ++; $css_class = $typecount%2?' class="LC_odd_row"':''; $datatable .= ''. - ''.&mt($othertitle).''. + ''.$othertitle.''. ''. ' Mb'; @@ -878,10 +878,12 @@ sub print_autoupdate { gen => 'Generation', ); my $numrows = 0; - if (@{$types} > 0) { - $datatable = - &usertype_update_row($settings,$usertypes,\%fieldtitles, - \@fields,$types,\$numrows); + if (ref($types) eq 'ARRAY') { + if (@{$types} > 0) { + $datatable = + &usertype_update_row($settings,$usertypes,\%fieldtitles, + \@fields,$types,\$numrows); + } } $datatable .= &usertype_update_row($settings,{'default' => $othertitle}, @@ -895,9 +897,7 @@ sub print_directorysrch { my ($dom,$settings) = @_; my $srchon = ' '; my $srchoff = ' checked="checked" '; - my $exacton = ''; - my $containson = ' checked="checked" '; - my $specifyon = ''; + my ($exacton,$containson,$beginson); my $localon = ' '; my $localoff = ' checked="checked" '; if (ref($settings) eq 'HASH') { @@ -909,19 +909,32 @@ sub print_directorysrch { $localon = $localoff; $localoff = ' '; } - if ($settings->{'searchtypes'} eq 'exact') { - $exacton = $containson; - $containson = ' '; - } - if ($settings->{'searchtypes'} eq 'specify') { - $specifyon = $containson; - $containson = ' '; + if (ref($settings->{'searchtypes'}) eq 'ARRAY') { + foreach my $type (@{$settings->{'searchtypes'}}) { + if ($type eq 'exact') { + $exacton = ' checked="checked" '; + } elsif ($type eq 'contains') { + $containson = ' checked="checked" '; + } elsif ($type eq 'begins') { + $beginson = ' checked="checked" '; + } + } + } else { + if ($settings->{'searchtypes'} eq 'exact') { + $exacton = ' checked="checked" '; + } elsif ($settings->{'searchtypes'} eq 'contains') { + $containson = ' checked="checked" '; + } elsif ($settings->{'searchtypes'} eq 'specify') { + $exacton = ' checked="checked" '; + $containson = ' checked="checked" '; + } } } my ($searchtitles,$titleorder) = &sorted_searchtitles(); my ($othertitle,$usertypes,$types) = &sorted_inst_types($dom); my $numinrow = 4; + my $cansrchrow = 0; my $datatable=''. ''.&mt('Directory search available?').''. ''. ''. - ''.&mt('Search latitude').''. - ' '. - ''. - ' '. - ''. - ''.&mt('Other domains can search').''. + ''.&mt('Other domains can search?').''. ' '. ''. - ''. - ''.&mt('Users allowed to search').' ('.$dom.')'. - ''; - for (my $i=0; $i<@{$types}; $i++) { - if (defined($usertypes->{$types->[$i]})) { - my $rem = $i%($numinrow); - if ($rem == 0) { - if ($i > 0) { - $datatable .= ''; - } - $datatable .= ''; - } - my $check = ' '; - if (ref($settings->{'cansearch'}) eq 'ARRAY') { - if (grep(/^\Q$types->[$i]\E$/,@{$settings->{'cansearch'}})) { - $check = ' checked="checked" '; - } - } - $datatable .= ''; + ''; + if (ref($usertypes) eq 'HASH') { + if (keys(%{$usertypes}) > 0) { + $datatable .= &users_cansearch_row($settings,$types,$usertypes,$dom, + $numinrow,$othertitle); + $cansrchrow = 1; } } - - my $rem = @{$types}%($numinrow); - my $colsleft = $numinrow - $rem; - if ($colsleft > 1) { - $datatable .= ''; } else { - $datatable .= ''; } - my $defcheck = ' '; - if (ref($settings->{'cansearch'}) eq 'ARRAY') { - if (grep(/^default$/,@{$settings->{'cansearch'}})) { - $defcheck = ' checked="checked" '; - } - } - $datatable .= ''. - '
'. - '
'; + if ($cansrchrow) { + $datatable .= '
'; + $datatable .= '
'; - - $datatable .= ''. - ''.&mt('Supported search methods'). + $datatable .= ''.&mt('Supported search methods'). ''; foreach my $title (@{$titleorder}) { if (defined($searchtitles->{$title})) { @@ -1010,13 +980,82 @@ sub print_directorysrch { } } $datatable .= '
'; + if ($cansrchrow) { + $datatable .= ''; + } else { + $datatable .= ''; + } + $datatable .= ''.&mt('Search latitude').''. + ''. + ' '. + ' '. + ''; return $datatable; } +sub users_cansearch_row { + my ($settings,$types,$usertypes,$dom,$numinrow,$othertitle) = @_; + my $output = ''. + ''.&mt('Users allowed to search').' ('.$dom.')'. + ''; + my $rem; + if (ref($types) eq 'ARRAY') { + for (my $i=0; $i<@{$types}; $i++) { + if (defined($usertypes->{$types->[$i]})) { + my $rem = $i%($numinrow); + if ($rem == 0) { + if ($i > 0) { + $output .= ''; + } + $output .= ''; + } + my $check = ' '; + if (ref($settings->{'cansearch'}) eq 'ARRAY') { + if (grep(/^\Q$types->[$i]\E$/,@{$settings->{'cansearch'}})) { + $check = ' checked="checked" '; + } + } + $output .= ''; + } + } + + $rem = @{$types}%($numinrow); + } + my $colsleft = $numinrow - $rem; + if ($colsleft > 1) { + $output .= ''. + '
'. + ''; + } else { + $output .= ''; + } + my $defcheck = ' '; + if (ref($settings->{'cansearch'}) eq 'ARRAY') { + if (grep(/^default$/,@{$settings->{'cansearch'}})) { + $defcheck = ' checked="checked" '; + } + } + $output .= '
'; + return $output; +} + sub sorted_inst_types { my ($dom) = @_; my ($usertypes,$order) = &Apache::lonnet::retrieve_inst_usertypes($dom); - my $othertitle = "All users"; + my $othertitle = &mt('All users'); my @types; if (ref($order) eq 'ARRAY') { @types = @{$order}; @@ -1042,6 +1081,16 @@ sub sorted_searchtitles { return (\%searchtitles,\@titleorder); } +sub sorted_searchtypes { + my %srchtypes_desc = ( + exact => 'is exact match', + contains => 'contains ..', + begins => 'begins with ..', + ); + my @srchtypeorder = ('exact','begins','contains'); + return (\%srchtypes_desc,\@srchtypeorder); +} + sub usertype_update_row { my ($settings,$usertypes,$fieldtitles,$fields,$types,$rownums) = @_; my $datatable; @@ -1694,8 +1743,7 @@ sub check_switchserver { sub modify_quotas { my ($dom,%domconfig) = @_; my ($resulttext,%changes); - my ($usertypes,$order) = - &Apache::lonnet::retrieve_inst_usertypes($dom); + my ($othertitle,$usertypes,$types) = &sorted_inst_types($dom); my %formhash; foreach my $key (keys(%env)) { if ($key =~ /^form\.quota_(.+)$/) { @@ -1729,8 +1777,14 @@ sub modify_quotas { if ($putresult eq 'ok') { if (keys(%changes) > 0) { $resulttext = &mt('Changes made:').''; } else { @@ -1824,7 +1878,7 @@ sub modify_autoupdate { run => 'Auto-update:', classlists => 'Updates to user information in classlists?' ); - my ($usertypes,$order) = &Apache::lonnet::retrieve_inst_usertypes($dom); + my ($othertitle,$usertypes,$types) = &sorted_inst_types($dom); my %fieldtitles = &Apache::lonlocal::texthash ( id => 'Student/Employee ID', permanentemail => 'E-mail address', @@ -1835,7 +1889,7 @@ sub modify_autoupdate { ); my $othertitle = &mt('All users'); if (keys(%{$usertypes}) > 0) { - $othertitle = "Other users"; + $othertitle = &mt('Other users'); } foreach my $key (keys(%env)) { if ($key =~ /^form\.updateable_(.+)_([^_]+)$/) { @@ -1857,14 +1911,14 @@ sub modify_autoupdate { } } elsif ($key eq 'fields') { if (ref($currautoupdate{$key}) eq 'HASH') { - foreach my $item (keys(%{$currautoupdate{$key}})) { + foreach my $item (@{$types},'default') { if (ref($currautoupdate{$key}{$item}) eq 'ARRAY') { my $change = 0; foreach my $type (@{$currautoupdate{$key}{$item}}) { if (!exists($fields{$item})) { $change = 1; } elsif (ref($fields{$item}) eq 'ARRAY') { - if (!grep/^\Q$type\E$/,@{$fields{$item}}) { + if (!grep(/^\Q$type\E$/,@{$fields{$item}})) { $change = 1; } } @@ -1872,18 +1926,20 @@ sub modify_autoupdate { if ($change) { push(@{$changes{$key}},$item); } - } + } } } } } - foreach my $key (keys(%fields)) { - if (ref($currautoupdate{'fields'}) eq 'HASH') { - if (!exists($currautoupdate{'fields'}{$key})) { - push(@{$changes{'fields'}},$key); + foreach my $item (@{$types},'default') { + if (defined($fields{$item})) { + if (ref($currautoupdate{'fields'}) eq 'HASH') { + if (!exists($currautoupdate{'fields'}{$item})) { + push(@{$changes{'fields'}},$item); + } + } else { + push(@{$changes{'fields'}},$item); } - } else { - push(@{$changes{'fields'}},$key); } } my $putresult = &Apache::lonnet::put_dom('configuration',\%updatehash, @@ -1905,9 +1961,9 @@ sub modify_autoupdate { $newvaluestr = &mt('none'); } if ($item eq 'default') { - $resulttext .= '
  • '.&mt("Updates for $othertitle set to: [_1]",$newvaluestr).'
  • '; + $resulttext .= '
  • '.&mt("Updates for '[_1]' set to: '[_2]'",$othertitle,$newvaluestr).'
  • '; } else { - $resulttext .= '
  • '.&mt("Updates for [_1] set to: [_2]",$usertypes->{$item},$newvaluestr).'
  • '; + $resulttext .= '
  • '.&mt("Updates for '[_1]' set to: '[_2]'",$usertypes->{$item},$newvaluestr).'
  • '; } } } else { @@ -1941,29 +1997,34 @@ sub modify_directorysrch { } } my %title = ( available => 'Directory search available', - cansearch => 'Users permitted to search', localonly => 'Other domains can search', searchby => 'Search types', searchtypes => 'Search latitude'); my @offon = ('off','on'); my @otherdoms = ('Yes','No'); + my @searchtypes = &Apache::loncommon::get_env_multiple('form.searchtypes'); my @cansearch = &Apache::loncommon::get_env_multiple('form.cansearch'); my @searchby = &Apache::loncommon::get_env_multiple('form.searchby'); - if (ref($currdirsrch{'cansearch'}) eq 'ARRAY') { - foreach my $type (@{$currdirsrch{'cansearch'}}) { - if (!grep(/^\Q$type\E$/,@cansearch)) { - push(@{$changes{'cansearch'}},$type); + my ($othertitle,$usertypes,$types) = &sorted_inst_types($dom); + if (keys(%{$usertypes}) == 0) { + @cansearch = ('default'); + } else { + if (ref($currdirsrch{'cansearch'}) eq 'ARRAY') { + foreach my $type (@{$currdirsrch{'cansearch'}}) { + if (!grep(/^\Q$type\E$/,@cansearch)) { + push(@{$changes{'cansearch'}},$type); + } } - } - foreach my $type (@cansearch) { - if (!grep(/^\Q$type\E$/,@{$currdirsrch{'cansearch'}})) { - push(@{$changes{'cansearch'}},$type); + foreach my $type (@cansearch) { + if (!grep(/^\Q$type\E$/,@{$currdirsrch{'cansearch'}})) { + push(@{$changes{'cansearch'}},$type); + } } + } else { + push(@{$changes{'cansearch'}},@cansearch); } - } else { - push(@{$changes{'cansearch'}},@cansearch); } if (ref($currdirsrch{'searchby'}) eq 'ARRAY') { @@ -1980,13 +2041,39 @@ sub modify_directorysrch { } else { push(@{$changes{'searchby'}},@searchby); } - + + if (ref($currdirsrch{'searchtypes'}) eq 'ARRAY') { + foreach my $type (@{$currdirsrch{'searchtypes'}}) { + if (!grep(/^\Q$type\E$/,@searchtypes)) { + push(@{$changes{'searchtypes'}},$type); + } + } + foreach my $type (@searchtypes) { + if (!grep(/^\Q$type\E$/,@{$currdirsrch{'searchtypes'}})) { + push(@{$changes{'searchtypes'}},$type); + } + } + } else { + if (exists($currdirsrch{'searchtypes'})) { + foreach my $type (@searchtypes) { + if ($type ne $currdirsrch{'searchtypes'}) { + push(@{$changes{'searchtypes'}},$type); + } + } + if (!grep(/^\Q$currdirsrch{'searchtypes'}\E/,@searchtypes)) { + push(@{$changes{'searchtypes'}},$currdirsrch{'searchtypes'}); + } + } else { + push(@{$changes{'searchtypes'}},@searchtypes); + } + } + my %dirsrch_hash = ( directorysrch => { available => $env{'form.dirsrch_available'}, cansearch => \@cansearch, localonly => $env{'form.dirsrch_localonly'}, searchby => \@searchby, - searchtypes => $env{'form.searchtypes'}, + searchtypes => \@searchtypes, } ); my $putresult = &Apache::lonnet::put_dom('configuration',\%dirsrch_hash, @@ -2010,15 +2097,6 @@ sub modify_directorysrch { $changes{'localonly'} = 1; } } - if (exists($currdirsrch{'searchtypes'})) { - if ($currdirsrch{'searchtypes'} ne $env{'form.searchtypes'}) { - $changes{'searchtypes'} = 1; - } - } else { - if ($env{'form.searchtypes'}) { - $changes{'searchtypes'} = 1; - } - } if (keys(%changes) > 0) { $resulttext = &mt('Changes made:').''; } else { @@ -2076,4 +2162,3 @@ sub modify_directorysrch { } 1; -