+ * Should get error from server using the ldap_errno() and ldap_err2str() functions
+ * @param string $sError error message used when ldap error functions
+ * and connection resource are unavailable
+ * @return string error message
+ * @since 1.5.1
+ */
+ function ldap_error($sError) {
+ // it is possible that function_exists() tests are not needed
+ if(function_exists('ldap_err2str') &&
+ function_exists('ldap_errno') &&
+ is_resource($this->linkid)) {
+ return ldap_err2str(ldap_errno($this->linkid));
+ // return ldap_error($this->linkid);
+ } else {
+ return $sError;
+ }
+ }
+
+ /* ========================== Public ======================== */
+
+ /**
+ * Search the LDAP server
+ * @param string $expr search expression
+ * @return array search results
+ */
+ function search($expr) {
+ /* To be replaced by advanded search expression parsing */
+ if(is_array($expr)) return false;
+
+ // don't allow wide search when listing is disabled.
+ if ($expr=='*' && ! $this->listing) {
+ return array();
+ } elseif ($expr=='*') {
+ // allow use of wildcard when listing is enabled.
+ $expression = '(cn=*)';
+ } else {
+ /* Convert search from user's charset to the one used in ldap */
+ $expr = $this->charset_encode($expr);
+
+ /* sanitize search string */
+ $expr = $this->ldapspecialchars($expr);
+
+ /* Search for same string in cn, main and sn */
+ $expression = '(|(cn=*'.$expr.'*)(mail=*'.$expr.'*)(sn=*'.$expr.'*))';
+
+ /* Undo sanitizing of * symbol */
+ $expression = str_replace('\2a','*',$expression);
+ }
+
+ /* Add search filtering */
+ if ($this->filter!='')
+ $expression = '(&' . $this->filter . $expression . ')';
+
+ /* Use internal search function and return search results */
+ return $this->ldap_search($expression);
+ }
+
+
+ /**
+ * List all entries present in LDAP server