summaryrefslogtreecommitdiff
path: root/program/include/rcube_ldap.php
diff options
context:
space:
mode:
authorThomas Bruederli <thomas@roundcube.net>2012-11-09 11:50:33 +0100
committerThomas Bruederli <thomas@roundcube.net>2012-11-09 11:50:33 +0100
commit3f250a0fe63725f3daca904d93fd63d5eb437c56 (patch)
tree977d0ab21ecd01ccc15f56f1d5baaeca5e519e82 /program/include/rcube_ldap.php
parent91c0990385b310bfbae0bbb77489584cb2bdfa6d (diff)
Add config options to automatically generate LDAP attributes for new entries
Diffstat (limited to 'program/include/rcube_ldap.php')
-rw-r--r--program/include/rcube_ldap.php29
1 files changed, 28 insertions, 1 deletions
diff --git a/program/include/rcube_ldap.php b/program/include/rcube_ldap.php
index 61a073fa3..90ce73ae2 100644
--- a/program/include/rcube_ldap.php
+++ b/program/include/rcube_ldap.php
@@ -160,7 +160,7 @@ class rcube_ldap extends rcube_addressbook
}
// make sure LDAP_rdn field is required
- if (!empty($this->prop['LDAP_rdn']) && !in_array($this->prop['LDAP_rdn'], $this->prop['required_fields'])) {
+ if (!empty($this->prop['LDAP_rdn']) && !in_array($this->prop['LDAP_rdn'], $this->prop['required_fields']) && !in_array($this->prop['LDAP_rdn'], array_keys($this->prop['autovalues']))) {
$this->prop['required_fields'][] = $this->prop['LDAP_rdn'];
}
@@ -1086,6 +1086,9 @@ class rcube_ldap extends rcube_addressbook
$newentry = $this->_map_data($save_cols);
$newentry['objectClass'] = $this->prop['LDAP_Object_Classes'];
+ // add automatically generated attributes
+ $this->add_autovalues($newentry);
+
// Verify that the required fields are set.
$missing = null;
foreach ($this->prop['required_fields'] as $fld) {
@@ -1389,6 +1392,30 @@ class rcube_ldap extends rcube_addressbook
}
}
+ /**
+ * Generate missing attributes as configured
+ *
+ * @param array LDAP record attributes
+ */
+ protected function add_autovalues(&$attrs)
+ {
+ $attrvals = array();
+ foreach ($attrs as $k => $v) {
+ $attrvals['{'.$k.'}'] = is_array($v) ? $v[0] : $v;
+ }
+
+ foreach ((array)$this->prop['autovalues'] as $lf => $templ) {
+ if (empty($attrs[$lf])) {
+ // replace {attr} placeholders with concrete attribute values
+ $templ = preg_replace('/\{\w+\}/', '', strtr($templ, $attrvals));
+
+ if (strpos($templ, '(') !== false)
+ $attrs[$lf] = eval("return ($templ);");
+ else
+ $attrs[$lf] = $templ;
+ }
+ }
+ }
/**
* Execute the LDAP search based on the stored credentials