summaryrefslogtreecommitdiff
path: root/program
diff options
context:
space:
mode:
authoralecpl <alec@alec.pl>2012-04-07 07:47:38 +0000
committeralecpl <alec@alec.pl>2012-04-07 07:47:38 +0000
commit19fccd8b220e9ed86301b4efc82551bc7769aa2d (patch)
tree117d8670116b2f6288c58b014ff26107c64d3bf9 /program
parent187e9f432ffe266a576e57ae2028acaf85686eac (diff)
- Improved validation and forced RDN in required_fields (#1488254)
Diffstat (limited to 'program')
-rw-r--r--program/include/rcube_ldap.php47
1 files changed, 32 insertions, 15 deletions
diff --git a/program/include/rcube_ldap.php b/program/include/rcube_ldap.php
index 29554e8f3..61c66f340 100644
--- a/program/include/rcube_ldap.php
+++ b/program/include/rcube_ldap.php
@@ -127,15 +127,23 @@ class rcube_ldap extends rcube_addressbook
}
}
}
- else if ($this->coltypes['address'])
+ else if ($this->coltypes['address']) {
$this->coltypes['address'] = array('type' => 'textarea', 'childs' => null, 'limit' => 1, 'size' => 40);
+ }
// make sure 'required_fields' is an array
- if (!is_array($this->prop['required_fields']))
+ if (!is_array($this->prop['required_fields'])) {
$this->prop['required_fields'] = (array) $this->prop['required_fields'];
+ }
- foreach ($this->prop['required_fields'] as $key => $val)
+ // make sure LDAP_rdn field is required
+ if (!empty($this->prop['LDAP_rdn']) && !in_array($this->prop['LDAP_rdn'], $this->prop['required_fields'])) {
+ $this->prop['required_fields'][] = $this->prop['LDAP_rdn'];
+ }
+
+ foreach ($this->prop['required_fields'] as $key => $val) {
$this->prop['required_fields'][$key] = $this->_attr_name(strtolower($val));
+ }
// Build sub_fields filter
if (!empty($this->prop['sub_fields']) && is_array($this->prop['sub_fields'])) {
@@ -962,6 +970,11 @@ class rcube_ldap extends rcube_addressbook
*/
public function validate(&$save_data, $autofix = false)
{
+ // validate e-mail addresses
+ if (!parent::validate($save_data, $autofix)) {
+ return false;
+ }
+
// check for name input
if (empty($save_data['name'])) {
$this->set_error(self::ERROR_VALIDATE, 'nonamewarning');
@@ -972,7 +985,7 @@ class rcube_ldap extends rcube_addressbook
$missing = null;
$ldap_data = $this->_map_data($save_data);
foreach ($this->prop['required_fields'] as $fld) {
- if (!isset($ldap_data[$fld])) {
+ if (!isset($ldap_data[$fld]) || $ldap_data[$fld] === '') {
$missing[$fld] = 1;
}
}
@@ -981,25 +994,29 @@ class rcube_ldap extends rcube_addressbook
// try to complete record automatically
if ($autofix) {
$reverse_map = array_flip($this->fieldmap);
- $name_parts = preg_split('/[\s,.]+/', $save_data['name']);
- if ($missing['sn']) {
- $sn_field = $reverse_map['sn'];
- $save_data[$sn_field] = array_pop ($name_parts);
+ $name_parts = preg_split('/[\s,.]+/', $save_data['name']);
+ $sn_field = $this->fieldmap['surname'];
+ $fn_field = $this->fieldmap['firstname'];
+
+ if ($sn_field && $missing[$sn_field]) {
+ $save_data['surname'] = array_pop($name_parts);
+ unset($missing[$sn_field]);
}
- if ($missing[($fn_field = $this->fieldmap['firstname'])]) {
+
+ if ($fn_field && $missing[$fn_field]) {
$save_data['firstname'] = array_shift($name_parts);
+ unset($missing[$fn_field]);
}
-
- return $this->validate($save_data, false);
}
// TODO: generate message saying which fields are missing
- $this->set_error(self::ERROR_VALIDATE, 'formincomplete');
- return false;
+ if (!empty($missing)) {
+ $this->set_error(self::ERROR_VALIDATE, 'formincomplete');
+ return false;
+ }
}
- // validate e-mail addresses
- return parent::validate($save_data, $autofix);
+ return true;
}