/** * Specific search of user common name, only the common name is returned * * This method is designed for speed and to limit the number of returned values. * * @param String $name Name of the group to look for * @param Integer $sizeLimit Limit the amount of result sent * * @return LDAPResultIterator */ function searchUserAsYouType($name, $sizeLimit, $validEmail = false) { $apIt = new AppendIterator(); if ($name && $this->_connectAndBind()) { $name = $this->query_escaper->escapeFilter($name); if (isset($this->ldapParams['tooltip_search_user'])) { $filter = str_replace("%words%", $name, $this->ldapParams['tooltip_search_user']); } else { $filter = '(' . $this->ldapParams['cn'] . '=' . $name . '*)'; } if ($validEmail) { // Only search people with a non empty mail field $mail = $this->query_escaper->escapeFilter($this->ldapParams['mail']); $filter = '(&' . $filter . '(' . $mail . '=*))'; } // We only care about Common name and Login (lower the amount of data // to fetch speed up the request. if (isset($this->ldapParams['tooltip_search_attrs'])) { $attrs = explode(';', $this->ldapParams['tooltip_search_attrs']); } else { $attrs = array($this->ldapParams['cn'], $this->ldapParams['uid']); } // We want types and values $attrsOnly = 0; // Catch errors to detect if there are more results available than // the list actually returned (helps to refine the search) $this->trapErrors(); // Use SCOPE_ONELEVEL to only search in "sys_ldap_people_dn" branch // of the directory to speed up the search. $peopleDn = explode(';', $this->ldapParams['people_dn']); foreach ($peopleDn as $count) { $ds[] = $this->ds; } if (isset($this->ldapParams['tooltip_search_user'])) { $asr = ldap_search($ds, $peopleDn, $filter, $attrs, $attrsOnly, $sizeLimit, 0, LDAP_DEREF_NEVER); $this->logger->debug('LDAP in-depth search as you type ' . $filter . ' ***PEOPLEDN: ' . $peopleDn . ' ***errors:' . ldap_error($this->ds)); } else { $asr = ldap_list($ds, $peopleDn, $filter, $attrs, $attrsOnly, $sizeLimit, 0, LDAP_DEREF_NEVER); $this->logger->debug('LDAP high-level search as you type ' . $filter . ' ***PEOPLEDN: ' . print_r($peopleDn, true) . ' ***errors:' . ldap_error($this->ds)); } if ($asr !== false) { foreach ($asr as $sr) { $entries = ldap_get_entries($this->ds, $sr); if ($entries !== false) { // AppendIterator doesn't seem to handle invalid iterator well. // So don't append invalid iterators... $it = new LDAPResultIterator($entries, $this->ldapParams); if ($it->valid()) { $apIt->append($it); } } } } } return $apIt; }
/** * Specific search of user common name, only the common name is returned * * This method is designed for speed and to limit the number of returned values. * * @param String $name Name of the group to look for * @param Integer $sizeLimit Limit the amount of result sent * * @return LDAPResultIterator */ function searchUserAsYouType($name, $sizeLimit, $validEmail = false) { $apIt = new AppendIterator(); if ($name && $this->_connectAndBind()) { $filter = '(' . $this->ldapParams['cn'] . '=' . $name . '*)'; if ($validEmail) { // Only search people with a non empty mail field $filter = '(&' . $filter . '(' . $this->ldapParams['mail'] . '=*))'; } // We only care about Common name and Login (lower the amount of data // to fetch speed up the request. $attrs = array($this->ldapParams['cn'], $this->ldapParams['uid']); // We want types and values $attrsOnly = 0; // Catch errors to detect if there are more results available than // the list actually returned (helps to refine the search) $this->trapErrors(); // Use SCOPE_ONELEVEL to only search in "sys_ldap_people_dn" branch // of the directory to speed up the search. $peopleDn = split(';', $this->ldapParams['people_dn']); foreach ($peopleDn as $count) { $ds[] = $this->ds; } $asr = ldap_list($ds, $peopleDn, $filter, $attrs, $attrsOnly, $sizeLimit, 0, LDAP_DEREF_NEVER); if ($asr !== false) { foreach ($asr as $sr) { $entries = ldap_get_entries($this->ds, $sr); if ($entries !== false) { // AppendIterator doesn't seem to handle invalid iterator well. // So don't append invalid iterators... $it = new LDAPResultIterator($entries, $this->ldapParams); if ($it->valid()) { $apIt->append($it); } } } } } return $apIt; }