diff --git a/phpBB/includes/functions.php b/phpBB/includes/functions.php
index b23cad6f77..37edc27e1d 100644
--- a/phpBB/includes/functions.php
+++ b/phpBB/includes/functions.php
@@ -263,13 +263,13 @@ function phpbb_version_compare($version1, $version2, $operator = null)
// functions used for building option fields
/**
-* Pick a language, any language ...
-*
-* @param string $default Language ISO code to be selected by default in the dropdown list
-* @param array $langdata Language data in format of array(array('lang_iso' => string, lang_local_name => string), ...)
-*
-* @return string HTML options for language selection dropdown list.
-*/
+ * Pick a language, any language ...
+ *
+ * @param string $default Language ISO code to be selected by default in the dropdown list
+ * @param array $langdata Language data in format of array(array('lang_iso' => string, lang_local_name => string), ...)
+ *
+ * @return string HTML options for language selection dropdown list.
+ */
function language_select($default = '', array $langdata = [])
{
global $db;
@@ -295,26 +295,36 @@ function language_select($default = '', array $langdata = [])
}
/**
-* Pick a template/theme combo,
-*/
-function style_select($default = '', $all = false)
+ * Pick a template/theme combo
+ *
+ * @param string $default Style ID to be selected by default in the dropdown list
+ * @param bool $all Flag indicating if all styles data including inactive ones should be fetched
+ * @param array $styledata Style data in format of array(array('style_id' => int, style_name => string), ...)
+ *
+ * @return string HTML options for style selection dropdown list.
+ */
+function style_select($default = '', $all = false, array $styledata = [])
{
global $db;
- $sql_where = (!$all) ? 'WHERE style_active = 1 ' : '';
- $sql = 'SELECT style_id, style_name
- FROM ' . STYLES_TABLE . "
- $sql_where
- ORDER BY style_name";
- $result = $db->sql_query($sql);
+ if (empty($styledata))
+ {
+ $sql_where = (!$all) ? 'WHERE style_active = 1 ' : '';
+ $sql = 'SELECT style_id, style_name
+ FROM ' . STYLES_TABLE . "
+ $sql_where
+ ORDER BY style_name";
+ $result = $db->sql_query($sql);
+ $styledata = (array) $db->sql_fetchrowset($result);
+ $db->sql_freeresult($result);
+ }
$style_options = '';
- while ($row = $db->sql_fetchrow($result))
+ foreach ($styledata as $row)
{
$selected = ($row['style_id'] == $default) ? ' selected="selected"' : '';
$style_options .= '';
}
- $db->sql_freeresult($result);
return $style_options;
}
diff --git a/phpBB/includes/ucp/ucp_prefs.php b/phpBB/includes/ucp/ucp_prefs.php
index 7785aeb07b..0d6a178c67 100644
--- a/phpBB/includes/ucp/ucp_prefs.php
+++ b/phpBB/includes/ucp/ucp_prefs.php
@@ -159,33 +159,23 @@ class ucp_prefs
phpbb_timezone_select($template, $user, $data['tz'], true);
// check if there are any user-selectable languages
- $sql = 'SELECT COUNT(lang_id) as languages_count
- FROM ' . LANG_TABLE;
+ $sql = 'SELECT lang_iso, lang_local_name
+ FROM ' . LANG_TABLE . '
+ ORDER BY lang_english_name';
$result = $db->sql_query($sql);
- if ($db->sql_fetchfield('languages_count') > 1)
- {
- $s_more_languages = true;
- }
- else
- {
- $s_more_languages = false;
- }
+ $lang_row = (array) $db->sql_fetchrowset($result);
$db->sql_freeresult($result);
+ $s_more_languages = count($lang_row) > 1;
// check if there are any user-selectable styles
- $sql = 'SELECT COUNT(style_id) as styles_count
- FROM ' . STYLES_TABLE . '
- WHERE style_active = 1';
+ $sql = 'SELECT style_id, style_name
+ FROM ' . STYLES_TABLE . '
+ WHERE style_active = 1
+ ORDER BY style_name';
$result = $db->sql_query($sql);
- if ($db->sql_fetchfield('styles_count') > 1)
- {
- $s_more_styles = true;
- }
- else
- {
- $s_more_styles = false;
- }
+ $styles_row = (array) $db->sql_fetchrowset($result);
$db->sql_freeresult($result);
+ $s_more_styles = count($styles_row) > 1;
$template->assign_vars(array(
'ERROR' => (count($error)) ? implode('
', $error) : '',
@@ -205,11 +195,11 @@ class ucp_prefs
'DEFAULT_DATEFORMAT' => $config['default_dateformat'],
'A_DEFAULT_DATEFORMAT' => addslashes($config['default_dateformat']),
- 'S_MORE_LANGUAGES' => $s_more_languages,
+ 'S_MORE_LANGUAGES' => $s_more_languages,
'S_MORE_STYLES' => $s_more_styles,
- 'S_LANG_OPTIONS' => language_select($data['lang']),
- 'S_STYLE_OPTIONS' => ($config['override_user_style']) ? '' : style_select($data['user_style']),
+ 'S_LANG_OPTIONS' => language_select($data['lang'], $lang_row),
+ 'S_STYLE_OPTIONS' => ($config['override_user_style']) ? '' : style_select($data['user_style'], false, $styles_row),
'S_CAN_HIDE_ONLINE' => ($auth->acl_get('u_hideonline')) ? true : false,
'S_SELECT_NOTIFY' => ($config['jab_enable'] && $user->data['user_jabber'] && @extension_loaded('xml')) ? true : false)
);