[LON-CAPA-cvs] cvs: loncom /interface domainprefs.pm

raeburn lon-capa-cvs-allow@mail.lon-capa.org
Sat, 01 Sep 2007 21:20:14 -0000


This is a MIME encoded message

--raeburn1188681614
Content-Type: text/plain

raeburn		Sat Sep  1 17:20:14 2007 EDT

  Modified files:              
    /loncom/interface	domainprefs.pm 
  Log:
  - Option to set which user types can search institutional directory, only displayed where localenroll::inst_usertypes() has been customized to define user types at the institution.
  - Reduce calls to &lonnet::retrieve_inst_usertypes() to just one - from within &sorted_inst_types(). Call this sub when needed. 
  - Changes to domain settings dependent on institutional user types (default portfolio disk space, autoupdate, directory search) now reported in pre-set order nstead of hash order.
  - Consistent localization for 'All users' and 'Other users'.
  - Wording clarified in changes message for directory search.
  
  
--raeburn1188681614
Content-Type: text/plain
Content-Disposition: attachment; filename="raeburn-20070901172014.txt"

Index: loncom/interface/domainprefs.pm
diff -u loncom/interface/domainprefs.pm:1.25 loncom/interface/domainprefs.pm:1.26
--- loncom/interface/domainprefs.pm:1.25	Sun Aug 26 11:31:03 2007
+++ loncom/interface/domainprefs.pm	Sat Sep  1 17:20:14 2007
@@ -1,7 +1,7 @@
 # The LearningOnline Network with CAPA
 # Handler to set domain-wide configuration settings
 #
-# $Id: domainprefs.pm,v 1.25 2007/08/26 15:31:03 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 @@
     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 @@
     $typecount ++;
     $css_class = $typecount%2?' class="LC_odd_row"':'';
     $datatable .= '<tr'.$css_class.'>'.
-                  '<td>'.&mt($othertitle).'</td>'.
+                  '<td>'.$othertitle.'</td>'.
                   '<td class="LC_right_item"><span class="LC_nobreak">'.
                   '<input type="text" name="defaultquota" value="'.
                   $defaultquota.'" size="5" /> Mb</span></td></tr>';
@@ -878,10 +878,12 @@
                             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},
@@ -932,6 +934,7 @@
     my ($othertitle,$usertypes,$types) = &sorted_inst_types($dom);
 
     my $numinrow = 4;
+    my $cansrchrow = 0;
     my $datatable='<tr class="LC_odd_row">'.
                   '<td colspan="2">'.&mt('Directory search available?').'</td>'.
                   '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
@@ -947,10 +950,19 @@
                   '<label><input type="radio" name="dirsrch_localonly"'.
                   $localon.' value="1" />'.&mt('No').'</label></span></td>'.
                   '</tr>';
-    $datatable .= &users_cansearch_row($settings,$types,$usertypes,$dom,
-                                       $numinrow,$othertitle);
-    $datatable .= '<tr>'.
-                  '<td>'.&mt('Supported search methods').
+    if (ref($usertypes) eq 'HASH') {
+        if (keys(%{$usertypes}) > 0) {
+            $datatable .= &users_cansearch_row($settings,$types,$usertypes,$dom,
+                                               $numinrow,$othertitle);
+            $cansrchrow = 1;
+        }
+    }
+    if ($cansrchrow) {
+        $datatable .= '<tr>';
+    } else {
+        $datatable .= '<tr class="LC_odd_row">';
+    }
+    $datatable .= '<td>'.&mt('Supported search methods').
                   '</td><td class="LC_left_item" colspan="2"><table><tr>';
     foreach my $title (@{$titleorder}) {
         if (defined($searchtitles->{$title})) {
@@ -967,9 +979,14 @@
                           $searchtitles->{$title}.'</label></span></td>';
         }
     }
-    $datatable .= '</tr></table></td></tr><tr class="LC_odd_row">'. 
-                  '<td>'.&mt('Search latitude').'</td>'.
-                  '<td class="LC_left_item"  colspan="2">'.
+    $datatable .= '</tr></table></td></tr>';
+    if ($cansrchrow) {
+        $datatable .= '<tr class="LC_odd_row">';
+    } else {
+        $datatable .= '<tr>';
+    }
+    $datatable .= '<td>'.&mt('Search latitude').'</td>'.   
+                  '<td class="LC_left_item" colspan="2">'.
                   '<span class="LC_nobreak"><label>'.
                   '<input type="checkbox" name="searchtypes" '.
                   $exacton.' value="exact" />'.&mt('Exact match').
@@ -988,30 +1005,33 @@
     my $output =  '<tr class="LC_odd_row">'.
                   '<td>'.&mt('Users allowed to search').' ('.$dom.')'.
                   '</td><td class="LC_left_item" colspan="2"><table>';
-    for (my $i=0; $i<@{$types}; $i++) {
-        if (defined($usertypes->{$types->[$i]})) {
-            my $rem = $i%($numinrow);
-            if ($rem == 0) {
-                if ($i > 0) {
-                    $output .= '</tr>';
+    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 .= '</tr>';
+                    }
+                    $output .= '<tr>';
                 }
-                $output .= '<tr>';
-            }
-            my $check = ' ';
-            if (ref($settings->{'cansearch'}) eq 'ARRAY') {
-                if (grep(/^\Q$types->[$i]\E$/,@{$settings->{'cansearch'}})) {
-                    $check = ' checked="checked" ';
+                my $check = ' ';
+                if (ref($settings->{'cansearch'}) eq 'ARRAY') {
+                    if (grep(/^\Q$types->[$i]\E$/,@{$settings->{'cansearch'}})) {
+                        $check = ' checked="checked" ';
+                    }
                 }
+                $output .= '<td class="LC_left_item">'.
+                           '<span class="LC_nobreak"><label>'.
+                           '<input type="checkbox" name="cansearch" '.
+                           'value="'.$types->[$i].'"'.$check.'/>'.
+                           $usertypes->{$types->[$i]}.'</label></span></td>';
             }
-            $output .= '<td class="LC_left_item">'.
-                       '<span class="LC_nobreak"><label>'.
-                       '<input type="checkbox" name="cansearch" '.
-                       'value="'.$types->[$i].'"'.$check.'/>'.
-                       $usertypes->{$types->[$i]}.'</label></span></td>';
         }
+       
+        $rem = @{$types}%($numinrow);
     }
-
-    my $rem = @{$types}%($numinrow);
     my $colsleft = $numinrow - $rem;
     if ($colsleft > 1) {
         $output .= '<td colspan="'.$colsleft.'" class="LC_left_item">';
@@ -1020,9 +1040,9 @@
     }
     my $defcheck = ' ';
     if (ref($settings->{'cansearch'}) eq 'ARRAY') {
-         if (grep(/^default$/,@{$settings->{'cansearch'}})) {
-              $defcheck = ' checked="checked" ';
-         }
+        if (grep(/^default$/,@{$settings->{'cansearch'}})) {
+            $defcheck = ' checked="checked" ';
+        }
     }
     $output .= '<span class="LC_nobreak"><label>'.
                '<input type="checkbox" name="cansearch" '.
@@ -1035,7 +1055,7 @@
 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};
@@ -1723,8 +1743,7 @@
 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_(.+)$/) {
@@ -1758,8 +1777,14 @@
     if ($putresult eq 'ok') {
         if (keys(%changes) > 0) {
             $resulttext = &mt('Changes made:').'<ul>';
-            foreach my $item (sort(keys(%changes))) {
-                $resulttext .= '<li>'.&mt('[_1] set to [_2] Mb',$usertypes->{$item},$formhash{$item}).'</li>';
+            foreach my $type (@{$types},'default') {
+                if (defined($changes{$type})) { 
+                    my $typetitle = $usertypes->{$type};
+                    if ($type eq 'default') {
+                        $typetitle = $othertitle;
+                    }
+                    $resulttext .= '<li>'.&mt('[_1] set to [_2] Mb',$typetitle,$formhash{$type}).'</li>';
+                }
             }
             $resulttext .= '</ul>';
         } else {
@@ -1853,7 +1878,7 @@
                    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',
@@ -1864,7 +1889,7 @@
                       );
     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_(.+)_([^_]+)$/) {
@@ -1886,14 +1911,14 @@
             }
         } 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;
                                 }
                             }
@@ -1901,18 +1926,20 @@
                         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,
@@ -1934,9 +1961,9 @@
                             $newvaluestr = &mt('none');
                         }
                         if ($item eq 'default') {
-                            $resulttext .= '<li>'.&mt("Updates for $othertitle set to: [_1]",$newvaluestr).'</li>';
+                            $resulttext .= '<li>'.&mt("Updates for '[_1]' set to: '[_2]'",$othertitle,$newvaluestr).'</li>';
                         } else {
-                            $resulttext .= '<li>'.&mt("Updates for [_1] set to: [_2]",$usertypes->{$item},$newvaluestr).'</li>';
+                            $resulttext .= '<li>'.&mt("Updates for '[_1]' set to: '[_2]'",$usertypes->{$item},$newvaluestr).'</li>';
                         }
                     }
                 } else {
@@ -1970,7 +1997,6 @@
         }
     }
     my %title = ( available => 'Directory search available',
-                  cansearch => 'Users permitted to search',
                   localonly => 'Other domains can search',
                   searchby => 'Search types',
                   searchtypes => 'Search latitude');
@@ -1981,19 +2007,24 @@
     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') {
@@ -2076,19 +2107,22 @@
             }
 
             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 .= '<li>'.&mt("Users from domain '<span class=\"LC_cusr_emph\">[_1]</span>' permitted to search the institutional directory set to: [_2]",$dom,$chgtext).'</li>';
                     }
                 }
-                if (grep(/^default$/,@cansearch)) {
-                    $chgtext .= $othertitle;
-                } else {
-                    $chgtext =~ s/\; $//;
-                }
-                $resulttext .= '<li>'.&mt("$title{'cansearch'} ([_1]) set to: [_2]",$dom,$chgtext).'</li>';
             }
             if (ref($changes{'searchby'}) eq 'ARRAY') {
                 my ($searchtitles,$titleorder) = &sorted_searchtitles();

--raeburn1188681614--