protected function _getResults(array $fields, $res)
{
$results = array();
if (@ldap_count_entries($this->_ds, $res) == 0) {
return $results;
}
$entry = @ldap_first_entry($this->_ds, $res);
do {
if ($entry === false) {
throw new Turba_Exception(sprintf(_("Read failed: (%s) %s"), ldap_errno($this->_ds), ldap_error($this->_ds)));
}
$result = array();
foreach ($fields as $field) {
$field_l = Horde_String::lower($field);
if ($field == 'dn') {
$result[$field] = Horde_String::convertCharset(@ldap_get_dn($this->_ds,$entry), $this->_params['charset'], 'UTF-8');
} elseif ( $this->_isBinaryValue($field) ) {
$values = @ldap_get_values_len($this->_ds, $entry, $field);
if ( !empty($values) ) {
$result[$field] = $values[0];
}
} else {
$values = @ldap_get_values($this->_ds, $entry, $field);
$result[$field] = '';
if (!empty($values)) {
for ($j = 0; $j < $values['count']; $j++) {
if (!empty($result[$field])) {
$result[$field] .= $this->_params['multiple_entry_separator'];
}
$result[$field] .= Horde_String::convertCharset($values[$j], $this->_params['charset'], 'UTF-8');
}
/* If schema checking is enabled check the
* backend syntax. */
if (!empty($this->_params['checksyntax'])) {
$postal = $this->_isPostalAddress($field_l);
} else {
/* Otherwise rely on the attribute mapping
* in attributes.php. */
$attr = array_search($field_l, $this->map);
$postal = (!empty($attr) && !empty($GLOBALS['attributes'][$attr]) &&
$GLOBALS['attributes'][$attr]['type'] == 'address');
}
if ($postal) {
$result[$field] = str_replace('$', "\r\n", $result[$field]);
}
}
}
}
$results[] = $result;
} while ( $entry = @ldap_next_entry($this->_ds, $entry) );
return $results;
}
/**
* Checks if an attribute has binary value.
*
* @param string $attribute An attribute name.
*
* @return boolean True if the specified attribute is binary.
*/
protected function _isBinaryValue($attribute)
{
/* certificate: 1.3.6.1.4.1.1466.115.121.1.8
* jpeg: 1.3.6.1.4.1.1466.115.121.1.28 */
if (!empty($this->_params['checksyntax'])) {
$attr = strstr($attribute,';',true);
$attribute = $attr ? $attr : $attribute;
$syn = $this->_getSyntax($attribute);
return (($syn == '1.3.6.1.4.1.1466.115.121.1.8') ||
($syn == '1.3.6.1.4.1.1466.115.121.1.28'));
} else {
return isset($this->_params['binary'])
? array_search($attribute,$this->_params['binary']) !== false
: false;
}
}