--- loncom/interface/domainprefs.pm 2007/07/25 20:12:26 1.23 +++ 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.23 2007/07/25 20:12:26 raeburn Exp $ +# $Id: domainprefs.pm,v 1.26 2007/09/01 21:20:14 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 { @@ -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 .= ''. - ''. + ''. ''; @@ -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,92 +897,73 @@ 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(); my ($othertitle,$usertypes,$types) = &sorted_inst_types($dom); my $numinrow = 4; + my $cansrchrow = 0; my $datatable=''. - ''. + ''. ''. ''. - ''. + ''. ''. - ''. - ''; - - $datatable .= ''. - '
'.$item->{'header'}->[0]->{'col1'}.''.&mt($othertitle).''.$othertitle.''. ' Mb
'.&mt('Directory search available?').''.&mt('Directory search available?').' '. '
'.&mt('Search latitude').''.&mt('Other domains can search?').' '. - ''. - ' 
'.&mt('Users permitted to search'). - ''; - 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 .= ''; + ''.&mt('Yes').' '. + ''. + ''; + 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 .= '
'.&mt('Supported search methods'). - ''; + $datatable .= ''; + if ($cansrchrow) { + $datatable .= ''; + } else { + $datatable .= ''; + } + $datatable .= ''. + ''; return $datatable; } +sub users_cansearch_row { + my ($settings,$types,$usertypes,$dom,$numinrow,$othertitle) = @_; + my $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}; @@ -1029,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; @@ -1681,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_(.+)$/) { @@ -1716,8 +1777,14 @@ sub modify_quotas { if ($putresult eq 'ok') { if (keys(%changes) > 0) { $resulttext = &mt('Changes made:').'
    '; - foreach my $item (sort(keys(%changes))) { - $resulttext .= '
  • '.&mt('[_1] set to [_2] Mb',$usertypes->{$item},$formhash{$item}).'
  • '; + foreach my $type (@{$types},'default') { + if (defined($changes{$type})) { + my $typetitle = $usertypes->{$type}; + if ($type eq 'default') { + $typetitle = $othertitle; + } + $resulttext .= '
  • '.&mt('[_1] set to [_2] Mb',$typetitle,$formhash{$type}).'
  • '; + } } $resulttext .= '
'; } else { @@ -1811,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', @@ -1822,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_(.+)_([^_]+)$/) { @@ -1844,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; } } @@ -1859,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, @@ -1892,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 { @@ -1928,28 +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') { @@ -1966,12 +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, @@ -1986,13 +2088,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,20 +2102,27 @@ 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; - foreach my $type (@cansearch) { - if (defined($usertypes->{$type})) { - $chgtext .= $usertypes->{$type}.'; '; + if (ref($usertypes) eq 'HASH') { + if (keys(%{$usertypes}) > 0) { + foreach my $type (@{$types}) { + if (grep(/^\Q$type\E$/,@cansearch)) { + $chgtext .= $usertypes->{$type}.'; '; + } + } + if (grep(/^default$/,@cansearch)) { + $chgtext .= $othertitle; + } else { + $chgtext =~ s/\; $//; + } + $resulttext .= '
  • '.&mt("Users from domain '[_1]' permitted to search the institutional directory set to: [_2]",$dom,$chgtext).'
  • '; } } - if (grep(/^default$/,@cansearch)) { - $chgtext .= $othertitle; - } else { - $chgtext =~ s/\; $//; - } - $resulttext .= '
  • '.&mt("$title{'cansearch'} set to: [_1]",$chgtext).'
  • '; } if (ref($changes{'searchby'}) eq 'ARRAY') { my ($searchtitles,$titleorder) = &sorted_searchtitles(); @@ -2028,13 +2137,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 +2162,3 @@ sub modify_directorysrch { } 1; -
    '.&mt('Supported search methods'). + ''; foreach my $title (@{$titleorder}) { if (defined($searchtitles->{$title})) { my $check = ' '; @@ -997,13 +980,82 @@ sub print_directorysrch { } } $datatable .= '
    '.&mt('Search latitude').''. + ' '. + ' '. + '
    '.&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 .= '