diff --git a/application/forms/PreferenceForm.php b/application/forms/PreferenceForm.php index d8ab9f2b1..f0d50b466 100644 --- a/application/forms/PreferenceForm.php +++ b/application/forms/PreferenceForm.php @@ -6,12 +6,14 @@ namespace Icinga\Forms; use Exception; use DateTimeZone; use Icinga\Application\Config; +use Icinga\Application\Icinga; use Icinga\Application\Logger; use Icinga\Authentication\Auth; use Icinga\User\Preferences; use Icinga\User\Preferences\PreferencesStore; use Icinga\Util\TimezoneDetect; use Icinga\Util\Translator; +use Icinga\Web\Cookie; use Icinga\Web\Form; use Icinga\Web\Notification; use Icinga\Web\Session; @@ -103,6 +105,14 @@ class PreferenceForm extends Form Session::getSession()->user->setPreferences($this->preferences); + if (($theme = $this->getElement('theme')) !== null + && ($theme = $theme->getValue()) !== $this->getRequest()->getCookie('theme') + ) { + $this->getResponse() + ->setCookie(new Cookie('theme', $theme)) + ->setReloadCss(true); + } + try { if ($this->store && $this->getElement('btn_submit_preferences')->isChecked()) { $this->save(); @@ -142,6 +152,20 @@ class PreferenceForm extends Form */ public function createElements(array $formData) { + if (! (bool) Config::app()->get('themes', 'disabled', false)) { + $themes = Icinga::app()->getThemes(); + if (count($themes) > 1) { + $this->addElement( + 'select', + 'theme', + array( + 'label' => $this->translate('Theme', 'Form element label'), + 'multiOptions' => $themes + ) + ); + } + } + $languages = array(); $languages['autodetect'] = sprintf($this->translate('Browser (%s)', 'preferences.form'), $this->getLocale()); foreach (Translator::getAvailableLocaleCodes() as $language) {