--- loncom/interface/domainprefs.pm 2007/07/25 20:12:26 1.23 +++ 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.23 2007/07/25 20:12:26 raeburn Exp $ +# $Id: domainprefs.pm,v 1.25 2007/08/26 15:31:03 raeburn Exp $ # # Copyright Michigan State University Board of Trustees # @@ -271,7 +271,7 @@ sub print_config_box { '); - if ($action eq 'login') { + if (($action eq 'login') || ($action eq 'directorysrch')) { $r->print(' '); } else { @@ -895,21 +895,37 @@ 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') { if ($settings->{'available'} eq '1') { $srchon = $srchoff; $srchoff = ' '; } - if ($settings->{'searchtypes'} eq 'exact') { - $exacton = $containson; - $containson = ' '; - } - if ($settings->{'searchtypes'} eq 'specify') { - $specifyon = $containson; - $containson = ' '; + if ($settings->{'localonly'} eq '1') { + $localon = $localoff; + $localoff = ' '; + } + 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(); @@ -917,33 +933,69 @@ sub print_directorysrch { my $numinrow = 4; my $datatable=''. - ''. + ''. ''. ''. - ''. + ''. ''. - ''. - ''; + return $output; } sub sorted_inst_types { @@ -1029,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; @@ -1929,11 +1971,13 @@ 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'); @@ -1966,12 +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, @@ -1986,13 +2057,13 @@ sub modify_directorysrch { $changes{'available'} = 1; } } - if (exists($currdirsrch{'searchtypes'})) { - if ($currdirsrch{'searchtypes'} ne $env{'form.searchtypes'}) { - $changes{'searchtypes'} = 1; + if (exists($currdirsrch{'localonly'})) { + if ($currdirsrch{'localonly'} ne $env{'form.dirsrch_localonly'}) { + $changes{'localonly'} = 1; } } else { - if ($env{'form.searchtypes'}) { - $changes{'searchtypes'} = 1; + if ($env{'form.dirsrch_localonly'} eq '1') { + $changes{'localonly'} = 1; } } if (keys(%changes) > 0) { @@ -2000,6 +2071,10 @@ sub modify_directorysrch { if ($changes{'available'}) { $resulttext .= '
  • '.&mt("$title{'available'} set to: $offon[$env{'form.dirsrch_available'}]").'
  • '; } + if ($changes{'localonly'}) { + $resulttext .= '
  • '.&mt("$title{'localonly'} set to: $otherdoms[$env{'form.dirsrch_localonly'}]").'
  • '; + } + if (ref($changes{'cansearch'}) eq 'ARRAY') { my ($othertitle,$usertypes,$types) = &sorted_inst_types($dom); my $chgtext; @@ -2013,7 +2088,7 @@ sub modify_directorysrch { } else { $chgtext =~ s/\; $//; } - $resulttext .= '
  • '.&mt("$title{'cansearch'} set to: [_1]",$chgtext).'
  • '; + $resulttext .= '
  • '.&mt("$title{'cansearch'} ([_1]) set to: [_2]",$dom,$chgtext).'
  • '; } if (ref($changes{'searchby'}) eq 'ARRAY') { my ($searchtitles,$titleorder) = &sorted_searchtitles(); @@ -2028,13 +2103,18 @@ sub modify_directorysrch { $chgtext =~ s/\; $//; $resulttext .= '
  • '.&mt("$title{'searchby'} set to: [_1]",$chgtext).'
  • '; } - if ($changes{'searchtypes'}) { - my %srchtypes_desc = ( - exact => 'Exact match only', - contains => 'Contains is a match', - specify => 'Match type specifiable', - ); - $resulttext .= '
  • '.&mt("$title{'searchtypes'} set to: \"$srchtypes_desc{$env{'form.searchtypes'}}\"").'
  • '; + if (ref($changes{'searchtypes'}) eq 'ARRAY') { + my ($srchtypes_desc,$srchtypeorder) = &sorted_searchtypes(); + my $chgtext; + foreach my $type (@{$srchtypeorder}) { + if (grep(/^\Q$type\E$/,@searchtypes)) { + if (defined($srchtypes_desc->{$type})) { + $chgtext .= $srchtypes_desc->{$type}.'; '; + } + } + } + $chgtext =~ s/\; $//; + $resulttext .= '
  • '.&mt("$title{'searchtypes'} set to: \"[_1]\"",$chgtext).'
  • '; } $resulttext .= ''; } else { @@ -2048,4 +2128,3 @@ sub modify_directorysrch { } 1; -
    '.$item->{'header'}->[0]->{'col1'}.'
    '.&mt('Directory search available?').''.&mt('Directory search available?').' '. '
    '.&mt('Search latitude').''.&mt('Other domains can search?').' '. - ''. - ' 
    '.&mt('Users permitted to search'). - ''; + ''.&mt('Yes').' '. + ''. + ''; + $datatable .= &users_cansearch_row($settings,$types,$usertypes,$dom, + $numinrow,$othertitle); + $datatable .= ''. + ''. + ''. + ''; + return $datatable; +} + +sub users_cansearch_row { + my ($settings,$types,$usertypes,$dom,$numinrow,$othertitle) = @_; + my $output = ''. + ''; - - $datatable .= ''. - ''; - return $datatable; + $output .= ''. + '
    '.&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').''. + ' '. + ' '. + '
    '.&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 .= ''; + $output .= ''; } - $datatable .= ''; + $output .= ''; } my $check = ' '; if (ref($settings->{'cansearch'}) eq 'ARRAY') { @@ -951,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') { @@ -972,32 +1024,12 @@ sub print_directorysrch { $defcheck = ' checked="checked" '; } } - $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 .= '
    '. - '