Patch for LDAP Preferences storage
Kevin Hildebrand
kevin@hq.ensoport.com
Fri, 12 Apr 2002 14:31:25 -0400 (EDT)
I wanted to have all of the Horde preferences as one multi-valued
attribute instead of having to have numerous entries required in my LDAP
schema. In this scheme, the preference/value pairs are seperated by a
colon, and each pair gets an entry in LDAP. Add an entry to horde.conf to
specify the multi-valued LDAP attribute name which holds the preferences.
(If pref_field is not set, the code reverts to the old behavior)
$conf['prefs']['params']['pref_field'] = 'hordeprefs';
Cheers!
Kevin Hildebrand
ensoport Internetworks
=====================================================================
*** /tmp/T0YnaaJ4 Fri Apr 12 14:18:55 2002
--- /tmp/T1ZnaaJ4 Fri Apr 12 14:18:55 2002
***************
*** 207,221 ****
$this->_connect();
}
! /* Map preference names to LDAP schema names. */
! $ldapprefs = array();
! foreach($prefs as $pref) {
! $ldapprefs[] = $this->map($pref);
}
!
! $search = ldap_search($this->connection, $this->params['basedn'],
! $this->params['uid'] . '=' . $this->user,
! $ldapprefs);
if ($search) {
$result = ldap_get_entries($this->connection, $search);
} else {
--- 207,229 ----
$this->_connect();
}
! if (isset($this->params['pref_field'])) {
! $search = ldap_search($this->connection, $this->params['basedn'],
! $this->params['uid'] . '=' . $this->user,
! array($this->params['pref_field']));
! } else {
!
! /* Map preference names to LDAP schema names. */
! $ldapprefs = array();
! foreach($prefs as $pref) {
! $ldapprefs[] = $this->map($pref);
! }
!
! $search = ldap_search($this->connection, $this->params['basedn'],
! $this->params['uid'] . '=' . $this->user,
! $ldapprefs);
}
!
if ($search) {
$result = ldap_get_entries($this->connection, $search);
} else {
***************
*** 232,242 ****
* check when populating the $this->prefs hash from the LDAP
* server.
*/
! foreach ($prefs as $pref) {
! if (isset($result[0][$this->map($pref)][0])) {
! $this->prefs[$pref]['val'] = utf8_decode($result[0][$this->map($pref)][0]);
! $this->prefs[$pref]['default'] = false;
}
}
} else {
Horde::logMessage(_("No preferences were retrieved."), __FILE__, __LINE__);
--- 240,265 ----
* check when populating the $this->prefs hash from the LDAP
* server.
*/
! if (isset($this->params['pref_field'])) {
! if (isset($result[0][$this->params['pref_field']])) {
! foreach ($result[0][$this->params['pref_field']] as $prefstr) {
! $prefstr = utf8_decode($prefstr);
! if (substr_count($prefstr, ':') == 0)
! continue;
! list ($pref, $val) = split (':', $prefstr, 2);
! if (isset($this->prefs[$pref])) {
! $this->prefs[$pref]['val'] = $val;
! $this->prefs[$pref]['default'] = false;
! }
! }
}
+ } else {
+ foreach ($prefs as $pref) {
+ if (isset($result[0][$this->map($pref)][0])) {
+ $this->prefs[$pref]['val'] = utf8_decode($result[0][$this->map($pref)][0]);
+ $this->prefs[$pref]['default'] = false;
+ }
+ }
}
} else {
Horde::logMessage(_("No preferences were retrieved."), __FILE__, __LINE__);
***************
*** 297,306 ****
* stored in the LDAP server.
*/
$new_values = array();
! foreach($dirty_prefs as $pref) {
! if(Prefs::getValue($pref) != "") {
! $new_values[$this->map($pref)] = utf8_encode(Prefs::getValue($pref));
}
}
/* Send the hash to the LDAP server. */
--- 320,337 ----
* stored in the LDAP server.
*/
$new_values = array();
! if (isset($this->params['pref_field'])) {
! /* Hum. Can't add a value to a multi-valued entry without
! replacing the whole entry. Oh well. Send everything. */
! foreach($prefs as $pref) {
! $new_values[$this->params['pref_field']][] = utf8_encode("$pref:" . Prefs::getValue($pref));
}
+ } else {
+ foreach($dirty_prefs as $pref) {
+ if(Prefs::getValue($pref) != "") {
+ $new_values[$this->map($pref)] = utf8_encode(Prefs::getValue($pref));
+ }
+ }
}
/* Send the hash to the LDAP server. */
***************
*** 310,316 ****
unset($new_values);
! /* Attemp to cache the preferences in the session. */
$this->cacheUpdate();
return true;
--- 341,347 ----
unset($new_values);
! /* Attempt to cache the preferences in the session. */
$this->cacheUpdate();
return true;