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

raeburn lon-capa-cvs-allow@mail.lon-capa.org
Sun, 26 Aug 2007 15:31:05 -0000


This is a MIME encoded message

--raeburn1188142265
Content-Type: text/plain

raeburn		Sun Aug 26 11:31:05 2007 EDT

  Modified files:              
    /loncom/interface	loncreateuser.pm domainprefs.pm 
  Log:
  searchtype of "begins with" can be set for institutional searches in domain configuration.
  searchtype information now stored as a reference to an array instead of scalar in domain settings hash. 
  
  
--raeburn1188142265
Content-Type: text/plain
Content-Disposition: attachment; filename="raeburn-20070826113105.txt"

Index: loncom/interface/loncreateuser.pm
diff -u loncom/interface/loncreateuser.pm:1.177 loncom/interface/loncreateuser.pm:1.178
--- loncom/interface/loncreateuser.pm:1.177	Sat Aug 25 15:52:29 2007
+++ loncom/interface/loncreateuser.pm	Sun Aug 26 11:31:03 2007
@@ -1,7 +1,7 @@
 # The LearningOnline Network with CAPA
 # Create a user
 #
-# $Id: loncreateuser.pm,v 1.177 2007/08/25 19:52:29 raeburn Exp $
+# $Id: loncreateuser.pm,v 1.178 2007/08/26 15:31:03 raeburn Exp $
 #
 # Copyright Michigan State University Board of Trustees
 #
@@ -2419,7 +2419,8 @@
                        lastfirst => 'last name, first name',
                        lastname  => 'last name',
                        contains  => 'contains',
-                       exact     => 'as exact match to'
+                       exact     => 'as exact match to',
+                       begins    => 'begins with',
                    );
     if ($can_search) {
         if (ref($dom_inst_srch{'directorysrch'}{'searchby'}) eq 'ARRAY') {
@@ -2431,11 +2432,20 @@
         }
     }
     if ($can_search) {
-        if (($dom_inst_srch{'directorysrch'}{'searchtypes'} eq 'specify') ||
-            ($dom_inst_srch{'directorysrch'}{'searchtypes'} eq $srch->{'srchtype'})) {
-            return 'ok';
-        } else {    
-            return &mt('Directory search in domain [_1] is not available for the requested search type: "[_2]"',$srch->{'srchdomain'},$longtext{$srch->{'srchtype'}});
+        if (ref($dom_inst_srch{'directorysrch'}{'searchtypes'}) eq 'ARRAY') {
+            if (grep(/^\Q$srch->{'srchtype'}\E/,@{$dom_inst_srch{'directorysrch'}{'searchtypes'}})) {
+                return 'ok';
+            } else {
+                return &mt('Directory search in domain [_1] is not available for the requested search type: "[_2]"',$srch->{'srchdomain'},$longtext{$srch->{'srchtype'}});
+            }
+        } else {
+            if ((($dom_inst_srch{'directorysrch'}{'searchtypes'} eq 'specify') &&
+                 ($srch->{'srchtype'} eq 'exact' || $srch->{'srchtype'} eq 'contains')) ||
+                ($dom_inst_srch{'directorysrch'}{'searchtypes'} eq $srch->{'srchtype'})) {
+                return 'ok';
+            } else {
+                return &mt('Directory search in domain [_1] is not available for the requested search type: "[_2]"',$srch->{'srchdomain'},$longtext{$srch->{'srchtype'}});
+            }
         }
     }
 }
Index: loncom/interface/domainprefs.pm
diff -u loncom/interface/domainprefs.pm:1.24 loncom/interface/domainprefs.pm:1.25
--- loncom/interface/domainprefs.pm:1.24	Sat Jul 28 17:23:53 2007
+++ loncom/interface/domainprefs.pm	Sun Aug 26 11:31:03 2007
@@ -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 @@
     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 @@
             $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 @@
                   '<label><input type="radio" name="dirsrch_available"'.
                   $srchoff.' value="0" />'.&mt('No').'</label></span></td>'.
                   '</tr><tr>'.
-                  '<td colspan="2">'.&mt('Search latitude').'</td>'.
-                  '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
-                  '<input type="radio" name="searchtypes"'.
-                  $exacton.' value="exact" />'.&mt('Exact match only').'</label>&nbsp;'.
-                  '<label><input type="radio" name="searchtypes"'.
-                  $containson.' value="contains" />'.&mt('Contains is a match').'</label>'.
-                  '&nbsp;<label><input type="radio" name="searchtypes"'.
-                  $specifyon.' value="specify" />'.&mt('Specifiable type').
-                  '</label></span></td></tr>'.
-                  '<tr class="LC_odd_row">'.
-                  '<td colspan="2">'.&mt('Other domains can search').'</td>'.
+                  '<td colspan="2">'.&mt('Other domains can search?').'</td>'.
                   '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
                   '<input type="radio" name="dirsrch_localonly"'.
                   $localoff.' value="0" />'.&mt('Yes').'</label>&nbsp;'.
                   '<label><input type="radio" name="dirsrch_localonly"'.
                   $localon.' value="1" />'.&mt('No').'</label></span></td>'.
-                  '</tr><tr>'.
+                  '</tr>';
+    $datatable .= &users_cansearch_row($settings,$types,$usertypes,$dom,
+                                       $numinrow,$othertitle);
+    $datatable .= '<tr>'.
+                  '<td>'.&mt('Supported search methods').
+                  '</td><td class="LC_left_item" colspan="2"><table><tr>';
+    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 .= '<td class="LC_left_item">'.
+                          '<span class="LC_nobreak"><label>'.
+                          '<input type="checkbox" name="searchby" '.
+                          'value="'.$title.'"'.$check.'/>'.
+                          $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">'.
+                  '<span class="LC_nobreak"><label>'.
+                  '<input type="checkbox" name="searchtypes" '.
+                  $exacton.' value="exact" />'.&mt('Exact match').
+                  '</label>&nbsp;'.
+                  '<label><input type="checkbox" name="searchtypes" '.
+                  $beginson.' value="begins" />'.&mt('Begins with').
+                  '</label>&nbsp;'.
+                  '<label><input type="checkbox" name="searchtypes" '.
+                  $containson.' value="contains" />'.&mt('Contains').
+                  '</label></span></td></tr>';
+    return $datatable;
+}
+
+sub users_cansearch_row {
+    my ($settings,$types,$usertypes,$dom,$numinrow,$othertitle) = @_;
+    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++) {
@@ -954,9 +993,9 @@
             my $rem = $i%($numinrow);
             if ($rem == 0) {
                 if ($i > 0) {
-                    $datatable .= '</tr>';
+                    $output .= '</tr>';
                 }
-                $datatable .= '<tr>';
+                $output .= '<tr>';
             }
             my $check = ' ';
             if (ref($settings->{'cansearch'}) eq 'ARRAY') {
@@ -964,20 +1003,20 @@
                     $check = ' checked="checked" ';
                 }
             }
-            $datatable .= '<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>';
         }
     }
 
     my $rem = @{$types}%($numinrow);
     my $colsleft = $numinrow - $rem;
     if ($colsleft > 1) {
-        $datatable .= '<td colspan="'.$colsleft.'" class="LC_left_item">';
+        $output .= '<td colspan="'.$colsleft.'" class="LC_left_item">';
     } else {
-        $datatable .= '<td class="LC_left_item">';
+        $output .= '<td class="LC_left_item">';
     }
     my $defcheck = ' ';
     if (ref($settings->{'cansearch'}) eq 'ARRAY') {
@@ -985,32 +1024,12 @@
               $defcheck = ' checked="checked" ';
          }
     }
-    $datatable .= '<span class="LC_nobreak"><label>'.
-                  '<input type="checkbox" name="cansearch" '.
-                  'value="default"'.$defcheck.'/>'.
-                  $othertitle.'</label></span></td>'.
-                  '</tr></table></td></tr>';
-
-    $datatable .= '<tr class="LC_odd_row">'.
-                  '<td>'.&mt('Supported search methods').
-                  '</td><td class="LC_left_item" colspan="2"><table><tr>';
-    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 .= '<td class="LC_left_item">'.
-                          '<span class="LC_nobreak"><label>'.
-                          '<input type="checkbox" name="searchby" '.
-                          'value="'.$title.'"'.$check.'/>'.
-                          $searchtitles->{$title}.'</label></span></td>';
-        }
-    }
-    $datatable .= '</tr></table></td></tr>';
-    return $datatable;
+    $output .= '<span class="LC_nobreak"><label>'.
+               '<input type="checkbox" name="cansearch" '.
+               'value="default"'.$defcheck.'/>'.
+               $othertitle.'</label></span></td>'.
+               '</tr></table></td></tr>';
+    return $output;
 }
 
 sub sorted_inst_types {
@@ -1042,6 +1061,16 @@
     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 @@
     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 @@
     } 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 @@
                 $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:').'<ul>';
             if ($changes{'available'}) {
@@ -2056,13 +2103,18 @@
                 $chgtext =~ s/\; $//;
                 $resulttext .= '<li>'.&mt("$title{'searchby'} set to: [_1]",$chgtext).'</li>';
             }
-            if ($changes{'searchtypes'}) {
-                my %srchtypes_desc = ( 
-                                       exact => 'Exact match only',
-                                       contains => 'Contains is a match',
-                                       specify => 'Match type specifiable',
-                                     );
-                $resulttext .= '<li>'.&mt("$title{'searchtypes'} set to: \"$srchtypes_desc{$env{'form.searchtypes'}}\"").'</li>';
+            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 .= '<li>'.&mt("$title{'searchtypes'} set to: \"[_1]\"",$chgtext).'</li>';
             }
             $resulttext .= '</ul>';
         } else {
@@ -2076,4 +2128,3 @@
 }
 
 1;
-

--raeburn1188142265--