--- loncom/interface/domainprefs.pm 2007/07/28 21:23:53 1.24 +++ loncom/interface/domainprefs.pm 2007/08/26 15:31:03 1.25 @@ -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.25 2007/08/26 15:31:03 raeburn Exp $ # # Copyright Michigan State University Board of Trustees # @@ -895,9 +895,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,13 +907,25 @@ 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(); @@ -930,23 +940,52 @@ sub print_directorysrch { ''. ''. - ''.&mt('Search latitude').''. - ' '. - ''. - ' '. - ''. - ''.&mt('Other domains can search').''. + ''.&mt('Other domains can search?').''. ' '. ''. - ''. + ''; + $datatable .= &users_cansearch_row($settings,$types,$usertypes,$dom, + $numinrow,$othertitle); + $datatable .= ''. + ''.&mt('Supported search methods'). + ''; + foreach my $title (@{$titleorder}) { + if (defined($searchtitles->{$title})) { + my $check = ' '; + if (ref($settings->{'searchby'}) eq 'ARRAY') { + if (grep(/^\Q$title\E$/,@{$settings->{'searchby'}})) { + $check = ' checked="checked" '; + } + } + $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.')'. ''; for (my $i=0; $i<@{$types}; $i++) { @@ -954,9 +993,9 @@ sub print_directorysrch { my $rem = $i%($numinrow); if ($rem == 0) { if ($i > 0) { - $datatable .= ''; + $output .= ''; } - $datatable .= ''; + $output .= ''; } my $check = ' '; if (ref($settings->{'cansearch'}) eq 'ARRAY') { @@ -964,20 +1003,20 @@ sub print_directorysrch { $check = ' checked="checked" '; } } - $datatable .= ''; + $output .= ''; } } my $rem = @{$types}%($numinrow); my $colsleft = $numinrow - $rem; if ($colsleft > 1) { - $datatable .= ''. - '
'. - ''. + ''; + $output .= ''; } else { - $datatable .= ''; + $output .= ''; } my $defcheck = ' '; if (ref($settings->{'cansearch'}) eq 'ARRAY') { @@ -985,32 +1024,12 @@ sub print_directorysrch { $defcheck = ' checked="checked" '; } } - $datatable .= '
'; - - $datatable .= ''. - ''.&mt('Supported search methods'). - ''; - foreach my $title (@{$titleorder}) { - if (defined($searchtitles->{$title})) { - my $check = ' '; - if (ref($settings->{'searchby'}) eq 'ARRAY') { - if (grep(/^\Q$title\E$/,@{$settings->{'searchby'}})) { - $check = ' checked="checked" '; - } - } - $datatable .= ''; - } - } - $datatable .= '
'. - '
'; - return $datatable; + $output .= ''. + ''; + return $output; } sub sorted_inst_types { @@ -1042,6 +1061,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; @@ -1948,6 +1977,7 @@ sub modify_directorysrch { 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'); @@ -1980,13 +2010,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 +2066,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 +2128,3 @@ sub modify_directorysrch { } 1; -