From 4542651db19e32e3ebb7bc07899905fa3e857235 Mon Sep 17 00:00:00 2001 From: Thilina Buddika Date: Mon, 9 Jul 2012 06:37:02 +0530 Subject: [PATCH] implementation of PMA_getHtmlForDisplayTheInitials --- libraries/server_privileges.lib.php | 52 +++++++++++++++++++++++++++++ server_privileges.php | 30 +---------------- 2 files changed, 53 insertions(+), 29 deletions(-) diff --git a/libraries/server_privileges.lib.php b/libraries/server_privileges.lib.php index 5184af44841f..27d20c5c7b1e 100644 --- a/libraries/server_privileges.lib.php +++ b/libraries/server_privileges.lib.php @@ -2256,4 +2256,56 @@ function PMA_getFieldsetForAddDeleteUser($conditional_class) return $html_output; } +/** + * Get HTML for Displays the initials + * + * @param array $array_initials array for all initials, even non A-Z + * @param string $conditional_class if ajaxable 'Ajax' otherwise '' + * + * @return string HTML snippet + */ +function PMA_getHtmlForDisplayTheInitials($array_initials, $conditional_class) +{ + // initialize to false the letters A-Z + for ($letter_counter = 1; $letter_counter < 27; $letter_counter++) { + if (! isset($array_initials[chr($letter_counter + 64)])) { + $array_initials[chr($letter_counter + 64)] = false; + } + } + + $initials = PMA_DBI_try_query( + 'SELECT DISTINCT UPPER(LEFT(`User`,1)) FROM `user` ORDER BY `User` ASC', + null, + PMA_DBI_QUERY_STORE + ); + while (list($tmp_initial) = PMA_DBI_fetch_row($initials)) { + $array_initials[$tmp_initial] = true; + } + + // Display the initials, which can be any characters, not + // just letters. For letters A-Z, we add the non-used letters + // as greyed out. + + uksort($array_initials, "strnatcasecmp"); + + $html_output = '' + . ''; + foreach ($array_initials as $tmp_initial => $initial_was_found) { + if ($initial_was_found) { + $html_output .= '' . "\n"; + } else { + $html_output .= ''; + } + } + $html_output .= '' . "\n"; + $html_output .= '
' + . '' . $tmp_initial . '' + . '' . $tmp_initial . '' + . '[' . __('Show all') . ']
'; + + return $html_output; +} + ?> diff --git a/server_privileges.php b/server_privileges.php index 247f3c946815..b5599bdd6af5 100644 --- a/server_privileges.php +++ b/server_privileges.php @@ -806,35 +806,7 @@ * Also not necassary if there is less than 20 privileges */ if ($GLOBALS['is_ajax_request'] != true && PMA_DBI_num_rows($res) > 20 ) { - - // initialize to false the letters A-Z - for ($letter_counter = 1; $letter_counter < 27; $letter_counter++) { - if (! isset($array_initials[chr($letter_counter + 64)])) { - $array_initials[chr($letter_counter + 64)] = false; - } - } - - $initials = PMA_DBI_try_query('SELECT DISTINCT UPPER(LEFT(`User`,1)) FROM `user` ORDER BY `User` ASC', null, PMA_DBI_QUERY_STORE); - while (list($tmp_initial) = PMA_DBI_fetch_row($initials)) { - $array_initials[$tmp_initial] = true; - } - - // Display the initials, which can be any characters, not - // just letters. For letters A-Z, we add the non-used letters - // as greyed out. - - uksort($array_initials, "strnatcasecmp"); - - echo ''; - foreach ($array_initials as $tmp_initial => $initial_was_found) { - if ($initial_was_found) { - echo '' . "\n"; - } else { - echo ''; - } - } - echo '' . "\n"; - echo '
' . $tmp_initial . '' . $tmp_initial . '[' . __('Show all') . ']
'; + echo PMA_getHtmlForDisplayTheInitials($array_initials, $conditional_class); } /**