diff --git a/application/controllers/ConfigController.php b/application/controllers/ConfigController.php
index b9c48ac78..ffa87f035 100644
--- a/application/controllers/ConfigController.php
+++ b/application/controllers/ConfigController.php
@@ -8,12 +8,12 @@ use Icinga\Web\Widget\AlertMessageBox;
use Icinga\Web\Notification;
use Icinga\Application\Modules\Module;
use Icinga\Web\Url;
+use Icinga\Web\Form;
use Icinga\Web\Widget;
use Icinga\Application\Icinga;
use Icinga\Application\Config as IcingaConfig;
use Icinga\Data\ResourceFactory;
use Icinga\Form\Config\GeneralForm;
-use Icinga\Form\Config\Authentication\ReorderForm;
use Icinga\Form\Config\Authentication\LdapBackendForm;
use Icinga\Form\Config\Authentication\DbBackendForm;
use Icinga\Form\Config\ResourceForm;
@@ -186,40 +186,47 @@ class ConfigController extends BaseConfigController
}
/**
- * Action for creating a new authentication backend
+ * Action for reordering authentication backends
*/
public function authenticationAction()
{
- $config = IcingaConfig::app('authentication', true);
+ $this->view->messageBox = new AlertMessageBox(true);
$this->view->tabs->activate('authentication');
- $order = array_keys($config->toArray());
- $this->view->messageBox = new AlertMessageBox(true);
-
- $backends = array();
- foreach ($order as $backend) {
- $form = new ReorderForm();
- $form->setName('form_reorder_backend_' . $backend);
- $form->setBackendName($backend);
- $form->setCurrentOrder($order);
- $form->setRequest($this->_request);
-
- if ($form->isSubmittedAndValid()) {
- if ($this->writeAuthenticationFile($form->getReorderedConfig($config))) {
- Notification::success('Authentication Order Updated');
- $this->redirectNow('config/authentication');
+ $config = IcingaConfig::app('authentication');
+ $backendOrder = array_keys($config->toArray());
+ $form = new Form();
+ $form->setName('form_reorder_authbackend');
+ $request = $this->getRequest();
+ if ($request->isPost()) {
+ $requestData = $request->getPost();
+ if ($form->isValid($requestData)) { // Validate the CSRF token
+ $reordered = false;
+ foreach ($backendOrder as $backendName) {
+ if (isset($requestData[$backendName])) {
+ array_splice($backendOrder, array_search($backendName, $backendOrder), 1);
+ array_splice($backendOrder, $requestData[$backendName], 0, $backendName);
+ $reordered = true;
+ break;
+ }
}
- return;
- }
+ if ($reordered) {
+ $reorderedConfig = array();
+ foreach ($backendOrder as $backendName) {
+ $reorderedConfig[$backendName] = $config->{$backendName};
+ }
- $backends[] = (object) array(
- 'name' => $backend,
- 'reorderForm' => $form
- );
+ if ($this->writeAuthenticationFile($reorderedConfig)) {
+ Notification::success($this->translate('Authentication order updated!'));
+ $this->redirectNow('config/authentication');
+ }
+ }
+ }
}
- $this->view->backends = $backends;
+ $this->view->form = $form->create(); // Necessary in case its a GET request
+ $this->view->backendNames = $backendOrder;
}
/**
diff --git a/application/forms/Config/Authentication/ReorderForm.php b/application/forms/Config/Authentication/ReorderForm.php
deleted file mode 100644
index a074febea..000000000
--- a/application/forms/Config/Authentication/ReorderForm.php
+++ /dev/null
@@ -1,233 +0,0 @@
-currentOrder = $order;
- }
-
- /**
- * Set the name of the authentication backend for which to create the form
- *
- * @param string $backend The name of the authentication backend
- */
- public function setBackendName($backend)
- {
- $this->backend = $backend;
- }
-
- /**
- * Return the name of the currently set backend as it will appear in the form
- *
- * @return string The name of the backend
- */
- public function getBackendName()
- {
- return $this->filterName($this->backend);
- }
-
- /**
- * Create this form
- *
- * @see Form::create
- */
- public function create()
- {
- if ($this->moveElementUp($this->backend, $this->currentOrder) !== $this->currentOrder) {
- $upForm = new Form();
-
- $upForm->addElement(
- 'hidden',
- 'form_backend_order',
- array(
- 'required' => true,
- 'value' => join(',', $this->moveElementUp($this->backend, $this->currentOrder))
- )
- );
- $upForm->addElement(
- 'button',
- 'btn_' . $this->getBackendName() . '_reorder_up',
- array(
- 'type' => 'submit',
- 'escape' => false,
- 'value' => 'btn_' . $this->getBackendName() . '_reorder_up',
- 'name' => 'btn_' . $this->getBackendName() . '_reorder_up',
- 'label' => $this->getView()->icon('up.png', t('Move up in authentication order'))
- )
- );
-
- $this->addSubForm($upForm, 'btn_reorder_up');
- }
-
- if ($this->moveElementDown($this->backend, $this->currentOrder) !== $this->currentOrder) {
- $downForm = new Form();
-
- $downForm->addElement(
- 'hidden',
- 'form_backend_order',
- array(
- 'required' => true,
- 'value' => join(',', $this->moveElementDown($this->backend, $this->currentOrder))
- )
- );
- $downForm->addElement(
- 'button',
- 'btn_' . $this->getBackendName() . '_reorder_down',
- array(
- 'type' => 'submit',
- 'escape' => false,
- 'value' => 'btn_' . $this->getBackendName() . '_reorder_down',
- 'name' => 'btn_' . $this->getBackendName() . '_reorder_down',
- 'label' => $this->getView()->icon('down.png', t('Move down in authentication order'))
- )
- );
-
- $this->addSubForm($downForm, 'btn_reorder_down');
- }
- }
-
- /**
- * Return the flattened result of $this->getValues
- *
- * @return array The currently set values
- *
- * @see Form::getValues()
- */
- protected function getFlattenedValues()
- {
- $result = array();
- foreach (parent::getValues() as $key => $value) {
- if (is_array($value)) {
- $result += $value;
- } else {
- $result[$key] = $value;
- }
- }
-
- return $result;
- }
-
- /**
- * Determine whether this form is submitted by testing the submit buttons of both subforms
- *
- * @return bool Whether the form has been submitted or not
- */
- public function isSubmitted()
- {
- $checkData = $this->getRequest()->getParams();
- return isset($checkData['btn_' . $this->getBackendName() . '_reorder_up']) ||
- isset($checkData['btn_' . $this->getBackendName() . '_reorder_down']);
- }
-
- /**
- * Return the reordered configuration after a reorder button has been submitted
- *
- * @param Zend_Config $config The configuration to reorder
- *
- * @return array An array containing the reordered configuration
- */
- public function getReorderedConfig(Zend_Config $config)
- {
- $originalConfig = $config->toArray();
- $newOrder = $this->getFlattenedValues();
- $order = explode(',', $newOrder['form_backend_order']);
-
- $reordered = array();
- foreach ($order as $key) {
- if (isset($originalConfig[$key])) {
- $reordered[$key] = $originalConfig[$key];
- }
- }
-
- return $reordered;
- }
-
- /**
- * Static helper for moving an element in an array one slot up, if possible
- *
- * Example:
- *
- *
- * $array = array('first', 'second', 'third');
- * moveElementUp('third', $array); // returns ['first', 'third', 'second']
- *
- *
- * @param string $key The key to bubble up one slot
- * @param array $array The array to work with
- *
- * @return array The modified array
- */
- protected static function moveElementUp($key, array $array)
- {
- for ($i = 0; $i < count($array) - 1; $i++) {
- if ($array[$i + 1] === $key) {
- $swap = $array[$i];
- $array[$i] = $array[$i + 1];
- $array[$i + 1] = $swap;
- return $array;
- }
- }
-
- return $array;
- }
-
- /**
- * Static helper for moving an element in an array one slot down, if possible
- *
- * Example:
- *
- *
- * $array = array('first', 'second', 'third');
- * moveElementDown('first', $array); // returns ['second', 'first', 'third']
- *
- *
- * @param string $key The key to bubble up one slot
- * @param array $array The array to work with
- *
- * @return array The modified array
- */
- protected static function moveElementDown($key, array $array)
- {
- for ($i = 0; $i < count($array) - 1; $i++) {
- if ($array[$i] === $key) {
- $swap = $array[$i + 1];
- $array[$i + 1] = $array[$i];
- $array[$i] = $swap;
- return $array;
- }
- }
-
- return $array;
- }
-}
diff --git a/application/views/scripts/config/authentication.phtml b/application/views/scripts/config/authentication.phtml
index a86e97600..13cdd901e 100644
--- a/application/views/scripts/config/authentication.phtml
+++ b/application/views/scripts/config/authentication.phtml
@@ -1,45 +1,53 @@
-= $this->tabs ?>
+ = $tabs; ?>
-
+ = $messageBox; ?>
+
+
+ = $this->icon('create.png'); ?>= $this->translate('Create A New LDAP Authentication Backend'); ?>
+
+
+
+ = $this->icon('create.png'); ?>= $this->translate('Create A New DB Authentication Backend'); ?>
+
+
+
+
\ No newline at end of file