From 52d58d47e0b81e6f966f4eec6442c16688d65454 Mon Sep 17 00:00:00 2001 From: Yannick Warnier Date: Mon, 18 Feb 2008 18:12:29 +0100 Subject: [PATCH] [svn r14307] Added user theme selection in user's profile (includes creating api_get_themes() in main_api and corresponding select list in FormValidator). Implements part of FS#2204 --- main/admin/settings.php | 4 +- main/auth/profile.php | 13 +++++- main/inc/header.inc.php | 10 ++++ .../formvalidator/Element/select_theme.php | 46 +++++++++++++++++++ .../lib/formvalidator/FormValidator.class.php | 1 + main/inc/lib/main_api.lib.php | 35 ++++++++++++++ main/inc/local.inc.php | 1 + 7 files changed, 106 insertions(+), 4 deletions(-) create mode 100644 main/inc/lib/formvalidator/Element/select_theme.php diff --git a/main/admin/settings.php b/main/admin/settings.php index c13f9bc32c..8c6f294b76 100644 --- a/main/admin/settings.php +++ b/main/admin/settings.php @@ -1,10 +1,10 @@ addRule('email', get_lang('EmailWrong'), 'email'); // OPENID URL -if(api_get_setting('openid_authentication')=='true') +if(is_profile_editable() && api_get_setting('openid_authentication')=='true') { $form->addElement('text', 'openid', get_lang('OpenIDURL'), array('size' => 40)); if (api_get_setting('profile', 'openid') !== 'true') @@ -247,6 +247,15 @@ if (is_profile_editable() && api_get_setting('profile', 'password') == 'true') if (CHECK_PASS_EASY_TO_FIND) $form->addRule('password1', get_lang('PassTooEasy').': '.api_generate_password(), 'callback', 'api_check_password'); } +if (is_profile_editable() && api_get_setting('user_selected_theme') == 'true') +{ + $form->addElement('select_theme', 'theme', get_lang('Theme')); + if (api_get_setting('profile', 'theme') !== 'true') + $form->freeze('theme'); + $form->applyFilter('theme', 'trim'); + //if (api_get_setting('registration', 'openid') == 'true') + // $form->addRule('openid', get_lang('ThisFieldIsRequired'), 'required'); +} // SUBMIT if (is_profile_editable()) diff --git a/main/inc/header.inc.php b/main/inc/header.inc.php index a63ef2f673..4cc6f43242 100644 --- a/main/inc/header.inc.php +++ b/main/inc/header.inc.php @@ -74,6 +74,16 @@ echo get_setting('siteName'); /*_options = array(); + $this->_values = array(); + foreach ($themes as $theme) + { + $this->addOption($theme,$theme); + } + } +} +?> \ No newline at end of file diff --git a/main/inc/lib/formvalidator/FormValidator.class.php b/main/inc/lib/formvalidator/FormValidator.class.php index 9daedbf13f..e8d9ad3c6b 100644 --- a/main/inc/lib/formvalidator/FormValidator.class.php +++ b/main/inc/lib/formvalidator/FormValidator.class.php @@ -57,6 +57,7 @@ class FormValidator extends HTML_QuickForm $this->registerElementType('datepicker', $dir.'Element/datepicker.php', 'HTML_QuickForm_datepicker'); $this->registerElementType('receivers', $dir.'Element/receivers.php', 'HTML_QuickForm_receivers'); $this->registerElementType('select_language', $dir.'Element/select_language.php', 'HTML_QuickForm_Select_Language'); + $this->registerElementType('select_theme', $dir.'Element/select_theme.php', 'HTML_QuickForm_Select_Theme'); $this->registerRule('date', null, 'HTML_QuickForm_Rule_Date', $dir.'Rule/Date.php'); $this->registerRule('date_compare', null, 'HTML_QuickForm_Rule_DateCompare', $dir.'Rule/DateCompare.php'); $this->registerRule('html',null,'HTML_QuickForm_Rule_HTML',$dir.'Rule/HTML.php'); diff --git a/main/inc/lib/main_api.lib.php b/main/inc/lib/main_api.lib.php index 754c9f2f30..c10a5a1e9f 100644 --- a/main/inc/lib/main_api.lib.php +++ b/main/inc/lib/main_api.lib.php @@ -444,6 +444,7 @@ function api_get_user_info($user_id = '') $user_info['status'] = $result_array['status']; $user_info['auth_source'] = $result_array['auth_source']; $user_info['username'] = $result_array['username']; + $user_info['theme'] = $result_array['theme']; return $user_info; } return false; @@ -1818,6 +1819,40 @@ function api_get_languages() return $language_list; } +/** + * Returns a list of CSS themes currently available in the CSS folder + * @return array List of themes directories from the css folder + */ +function api_get_themes() +{ + $cssdir = api_get_path(SYS_PATH).'main/css/'; + $list = array(); + if (is_dir($cssdir)) + { + $themes = scandir($cssdir); + if($themes !== false) + { + sort($themes); + foreach($themes as $theme) + { + if(substr($theme,0,1)=='.') + { + //ignore + continue; + } + else + { + if(is_dir($cssdir.$theme)) + { + $list[] = $theme; + } + } + } + } + } + return $list; +} + /* ============================================================================== WYSIWYG HTML AREA diff --git a/main/inc/local.inc.php b/main/inc/local.inc.php index 7f4739b68a..1989f7e6cf 100644 --- a/main/inc/local.inc.php +++ b/main/inc/local.inc.php @@ -527,6 +527,7 @@ $admin_table = Database::get_main_table(TABLE_MAIN_ADMIN); $_user ['user_id'] = $uData ['user_id']; $_user ['language'] = $uData ['language']; $_user ['auth_source'] = $uData ['auth_source']; + $_user ['theme'] = $uData ['theme']; $is_platformAdmin = (bool) (! is_null( $uData['is_admin'])); $is_allowedCreateCourse = (bool) ($uData ['status'] == 1);