diff --git a/lam/lib/html.inc b/lam/lib/html.inc
index 34d5d65f..095aea8a 100644
--- a/lam/lib/html.inc
+++ b/lam/lib/html.inc
@@ -3960,7 +3960,7 @@ class htmlResponsiveRow extends htmlElement {
if ($this->id !== null) {
$idParam = ' id="' . $this->id . '"';
}
- echo '
';
+ echo '
getDataAttributesAsString() . $idParam . '>';
foreach ($this->cells as $cell) {
$return = array_merge($return, $cell->generateHTML($module, $input, $values, $restricted, $tabindex, $scope));
}
diff --git a/lam/style/500_layout.css b/lam/style/500_layout.css
index 870e9b75..d2fbd317 100644
--- a/lam/style/500_layout.css
+++ b/lam/style/500_layout.css
@@ -380,6 +380,12 @@ table.collapse {
background-position: 0px 0px !important;
}
+.okButton {
+ background-image: url(../graphics/pass.png) !important;
+ background-size: 16px 16px;
+ background-position: 0px 0px !important;
+}
+
.smallPadding span {
padding: 0.1em 0.4em !important;
}
diff --git a/lam/templates/lib/500_lam.js b/lam/templates/lib/500_lam.js
index b705faba..c29bd35f 100644
--- a/lam/templates/lib/500_lam.js
+++ b/lam/templates/lib/500_lam.js
@@ -1034,18 +1034,20 @@ window.lam.html.showDnSelection = function(fieldId, title, okText, cancelText, t
jsonInput: ''
};
data[tokenName] = tokenValue;
+ data['fieldId'] = fieldId;
data['dn'] = dnValue;
jQuery.ajax({
url: '../misc/ajax.php?function=dnselection',
method: 'POST',
data: data
})
- .done(function(jsonData){
+ .done(function(jsonData) {
+ jQuery('#dlg_' + fieldId).html(jsonData.dialogData);
})
.fail(function() {
+ jQuery(this).dialog("close");
});
var buttonList = {};
- buttonList[okText] = function() { alert('OK'); };
buttonList[cancelText] = function() { jQuery(this).dialog("close"); };
jQuery('#dlg_' + fieldId).dialog({
modal: true,
@@ -1056,6 +1058,21 @@ window.lam.html.showDnSelection = function(fieldId, title, okText, cancelText, t
});
};
+/**
+ * Selects the DN from dialog.
+ *
+ * @param el ok button in dialog
+ * @param fieldId field id of input field
+ * @returns false
+ */
+window.lam.html.selectDn = function(el, fieldId) {
+ var field = jQuery('#' + fieldId);
+ var dn = jQuery(el).parents('.row').data('dn');
+ field.val(dn);
+ jQuery('#dlg_' + fieldId).dialog("close");
+ return false;
+}
+
jQuery(document).ready(function() {
window.lam.gui.equalHeight();
window.lam.form.autoTrim();
diff --git a/lam/templates/misc/ajax.php b/lam/templates/misc/ajax.php
index e8e53a8e..04562a7a 100644
--- a/lam/templates/misc/ajax.php
+++ b/lam/templates/misc/ajax.php
@@ -2,6 +2,12 @@
namespace LAM\AJAX;
use \LAM\TOOLS\IMPORT_EXPORT\Importer;
use \LAM\TOOLS\IMPORT_EXPORT\Exporter;
+use \LAM\TYPES\TypeManager;
+use \htmlResponsiveRow;
+use \htmlDiv;
+use \htmlGroup;
+use \htmlOutputText;
+use \htmlButton;
/*
This code is part of LDAP Account Manager (http://www.ldap-account-manager.org/)
@@ -128,6 +134,12 @@ class Ajax {
ob_end_clean();
echo $jsonOut;
}
+ elseif ($function === 'dnselection') {
+ ob_start();
+ $jsonOut = $this->dnSelection();
+ ob_end_clean();
+ echo $jsonOut;
+ }
}
/**
@@ -159,6 +171,72 @@ class Ajax {
$result = checkPasswordStrength($password, null, null);
echo json_encode(array("result" => $result));
}
+
+ /**
+ * Handles DN selection fields.
+ *
+ * @return string JSON output
+ */
+ private function dnSelection() {
+ $dn = trim($_POST['dn']);
+ if (empty($dn) || !get_preg($dn, 'dn')) {
+ $dnList = $this->getDefaultDns();
+ }
+ $dnList = $this->getDefaultDns(); // TODO remove
+ $html = $this->buildDnSelectionHtml($dnList);
+ return json_encode(array('dialogData' => $html));
+ }
+
+ /**
+ * Returns a list of default DNs from account types + tree suffix.
+ *
+ * @return string[] default DNs
+ */
+ private function getDefaultDns() {
+ $typeManager = new TypeManager();
+ $baseDnList = array();
+ foreach ($typeManager->getConfiguredTypes() as $type) {
+ $suffix = $type->getSuffix();
+ if (!empty($suffix)) {
+ $baseDnList[] = $suffix;
+ }
+ }
+ $treeSuffix = $_SESSION['config']->get_Suffix('tree');
+ if (!empty($treeSuffix)) {
+ $baseDnList[] = $suffix;
+ }
+ $baseDnList = array_unique($baseDnList);
+ sort($baseDnList);
+ return $baseDnList;
+ }
+
+ /**
+ * Returns the HTML to build the DN selection list.
+ *
+ * @param string[] $dnList DN list
+ */
+ private function buildDnSelectionHtml($dnList) {
+ $fieldId = trim($_POST['fieldId']);
+ $mainRow = new htmlResponsiveRow();
+ foreach ($dnList as $dn) {
+ $row = new htmlResponsiveRow();
+ $row->addDataAttribute('dn', $dn);
+ $row->add(new htmlOutputText($dn), 12, 9);
+ $buttonId = base64_encode($dn);
+ $buttonId = str_replace('=', '', $buttonId);
+ $button = new htmlButton($buttonId, _('Ok'));
+ $button->setIconClass('okButton');
+ $button->setOnClick('window.lam.html.selectDn(this, \'' . htmlspecialchars($fieldId) . '\')');
+ $row->add($button, 12, 3);
+ $mainRow->add($row, 12);
+ }
+ $tabindex = 1000;
+ ob_start();
+ parseHtml(null, $mainRow, array(), false, $tabindex, 'user');
+ $out = ob_get_contents();
+ ob_end_clean();
+ return $out;
+ }
}
diff --git a/lam/templates/tools/importexport.php b/lam/templates/tools/importexport.php
index 6c001cb2..335f2927 100644
--- a/lam/templates/tools/importexport.php
+++ b/lam/templates/tools/importexport.php
@@ -15,8 +15,6 @@ use \htmlLink;
use \htmlResponsiveInputCheckbox;
use \htmlResponsiveSelect;
use \htmlResponsiveInputField;
-use \htmlGroup;
-use \htmlInputField;
use \htmlHiddenInput;
use LAM\TYPES\TypeManager;