/** * Build a piece of a search query. * * @param array $criteria The array of criteria. * * @return string An LDAP query fragment. */ protected function _buildSearchQuery(array $criteria) { $clause = ''; foreach ($criteria as $key => $vals) { if (!empty($vals['OR']) || $key === 'OR') { $clause .= '(|' . $this->_buildSearchQuery($vals) . ')'; } elseif (!empty($vals['AND'])) { $clause .= '(&' . $this->_buildSearchQuery($vals) . ')'; } else { if (isset($vals['field'])) { $rhs = Horde_String::convertCharset($vals['test'], 'UTF-8', $this->_params['charset']); $clause .= Horde_Ldap::buildClause($vals['field'], $vals['op'], $rhs, array('begin' => !empty($vals['begin']))); } else { foreach ($vals as $test) { if (!empty($test['OR'])) { $clause .= '(|' . $this->_buildSearchQuery($test) . ')'; } elseif (!empty($test['AND'])) { $clause .= '(&' . $this->_buildSearchQuery($test) . ')'; } else { $rhs = Horde_String::convertCharset($test['test'], 'UTF-8', $this->_params['charset']); $clause .= Horde_Ldap::buildClause($test['field'], $test['op'], $rhs, array('begin' => !empty($vals['begin']))); } } } } } return $clause; }