]> git.sur5r.net Git - contagged/commitdiff
Configurable search fields
authorAndy Wettstein <ajw@illinois.edu>
Wed, 3 Dec 2008 11:48:18 +0000 (12:48 +0100)
committerAndy Wettstein <ajw@illinois.edu>
Wed, 3 Dec 2008 11:48:18 +0000 (12:48 +0100)
Makes it possible to configure what LDAP fields are considered when doing
search.

darcs-hash:20081203114818-18fff-3297461c8eac6bf3852dad6efadfcbe549f7c2d8.gz

inc/config.php
index.php

index 782f9a4ed003537ce5aab3fd54fb09a72f22b397..c03cbc7e5232570b44f4ce26dbccf48df77b90f6 100644 (file)
@@ -34,6 +34,9 @@
   // Where to store private contacts (relative to $conf['usertree'])
   $conf['privatebook'] = 'ou=contacts';
 
   // Where to store private contacts (relative to $conf['usertree'])
   $conf['privatebook'] = 'ou=contacts';
 
+  // What fields to look at when searching?
+  $conf['searchfields'] = array('uid','mail','name','givenname','o');
+
   // Should the public address book be viewable by logged in users only? (0|1)
   $conf['userlogreq']  = 0;
 
   // Should the public address book be viewable by logged in users only? (0|1)
   $conf['userlogreq']  = 0;
 
index 7fcf106a9d1dc464785e6d972cfd26ae3e8d0f0c..17240acffdd52721e427600539cb6f852143d700 100644 (file)
--- a/index.php
+++ b/index.php
@@ -94,6 +94,7 @@
    */
   function _makeldapfilter(){
     global $FIELDS;
    */
   function _makeldapfilter(){
     global $FIELDS;
+    global $conf;
 
     //handle given filter
 
 
     //handle given filter
 
       $words=preg_split('/\s+/',$search);
       $filter='';
       foreach($words as $word){
       $words=preg_split('/\s+/',$search);
       $filter='';
       foreach($words as $word){
-        $filter .= '(|(|('.$FIELDS['name'].'=*'.$word.'*)('.
-                   $FIELDS['givenname'].'=*'.$word.'*))('.
-                   $FIELDS['organization'].'=*'.$word.'*))';
+       $wordfilter='';
+        foreach($conf['searchfields'] as $field) {
+          $wordfilter .= '('.$field.'=*'.$word.'*)';
+       }
+        for($i=0; $i <count($conf['searchfields']); $i++){
+          $wordfilter = '(|'.$wordfilter.')';
+       }
+        $filter .= '(&'.$wordfilter.')';
       }
       $ldapfilter = "(&(objectClass=inetOrgPerson)$filter)";
     }elseif(!empty($org)){
       }
       $ldapfilter = "(&(objectClass=inetOrgPerson)$filter)";
     }elseif(!empty($org)){