Commit dd857b36 authored by Carsten  Rose's avatar Carsten Rose
Browse files

FormAction.php: add functionality to process action elements with 'fillStoreLdap'

AbstractBuildForm.php: use of new OnArray::...() functions.
parent 0a81a4cb
......@@ -479,7 +479,9 @@ abstract class AbstractBuildForm {
$config = array();
if (isset($formElement[FE_FILL_STORE_LDAP]) || isset($formElement[FE_TYPEAHEAD_LDAP])) {
$formElement = $this->copyLdapConfigForm2FormElement($formElement);
$keyNames = [F_LDAP_SERVER, F_LDAP_BASE_DN, F_LDAP_ATTRIBUTES, F_LDAP_SEARCH, F_TYPEAHEAD_LDAP_SEARCH, F_TYPEAHEAD_LIMIT,
F_TYPEAHEAD_MINLENGTH, F_TYPEAHEAD_LDAP_VALUE_PRINTF, F_TYPEAHEAD_LDAP_KEY_PRINTF, F_LDAP_TIME_LIMIT];
$formElement = OnArray::copyArrayItemsIfNotAlreadyExist($this->formSpec, $formElement, $keyNames);
} else {
return $formElement; // nothing to do.
}
......@@ -487,10 +489,7 @@ abstract class AbstractBuildForm {
if (isset($formElement[FE_FILL_STORE_LDAP])) {
// Extract necessary elements
foreach ([FE_LDAP_SERVER, FE_LDAP_BASE_DN, FE_LDAP_SEARCH, FE_LDAP_ATTRIBUTES] as $key) {
$config[$key] = $formElement[$key];
}
$config = OnArray::getArrayItems($formElement, [FE_LDAP_SERVER, FE_LDAP_BASE_DN, FE_LDAP_SEARCH, FE_LDAP_ATTRIBUTES]);
$config = $this->evaluate->parseArray($config);
$ldap = new Ldap();
......@@ -501,27 +500,6 @@ abstract class AbstractBuildForm {
return $formElement;
}
/**
* Copy LDAP Config from $this->formSpec to $formElement. Do not copy if a parameter already exist on $formElement.
*
* @param array $formElement
* @return array
*/
private function copyLdapConfigForm2FormElement(array $formElement) {
foreach ([F_LDAP_SERVER, F_LDAP_BASE_DN, F_LDAP_ATTRIBUTES, F_LDAP_SEARCH, F_TYPEAHEAD_LDAP_SEARCH, F_TYPEAHEAD_LIMIT,
F_TYPEAHEAD_MINLENGTH, F_TYPEAHEAD_LDAP_VALUE_PRINTF, F_TYPEAHEAD_LDAP_KEY_PRINTF, F_LDAP_TIME_LIMIT] as $key) {
if (!isset($formElement[$key])) {
if (isset($this->formSpec[$key])) {
$formElement[$key] = $this->formSpec[$key];
}
}
}
return $formElement;
}
/**
* Check if there is an explicit 'autofocus' definition in at least one FE.
* Found: do nothing, it will be rendered at the correct position.
......@@ -898,6 +876,7 @@ abstract class AbstractBuildForm {
throw new UserFormException('Missing definition: ' . $key, ERROR_MISSING_DEFINITON);
}
}
if ($formElement[FE_TYPEAHEAD_LDAP_VALUE_PRINTF] . $formElement[FE_TYPEAHEAD_LDAP_KEY_PRINTF] == '') {
throw new UserFormException('Missing definition: ' . FE_TYPEAHEAD_LDAP_VALUE_PRINTF . ' or ' . FE_TYPEAHEAD_LDAP_KEY_PRINTF, ERROR_MISSING_DEFINITON);
}
......
......@@ -96,6 +96,19 @@ class FormAction {
continue;
}
if (isset($fe[FE_FILL_STORE_LDAP])) {
$keyNames = [F_LDAP_SERVER, F_LDAP_BASE_DN, F_LDAP_ATTRIBUTES, F_LDAP_SEARCH, F_LDAP_TIME_LIMIT];
$fe = OnArray::copyArrayItemsIfNotAlreadyExist($this->formSpec, $fe, $keyNames);
// Extract necessary elements
$config = OnArray::getArrayItems($fe, [FE_LDAP_SERVER, FE_LDAP_BASE_DN, FE_LDAP_SEARCH, FE_LDAP_ATTRIBUTES]);
$config = $this->evaluate->parseArray($config);
$ldap = new Ldap();
$arr = $ldap->process($config, '', MODE_LDAP_SINGLE);
$this->store->setStore($arr, STORE_LDAP, true);
}
if ($fe[FE_TYPE] === FE_TYPE_SENDMAIL) {
$this->sendMail($fe);
//no further processing of current element necessary.
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment