diff options
author | xmujay <xmujay@gmail.com> | 2013-06-10 15:53:54 +0400 |
---|---|---|
committer | xmujay <xmujay@gmail.com> | 2013-06-10 15:53:54 +0400 |
commit | 5e3f7a080a40f0b3c25e730ed67667d6a8c0097c (patch) | |
tree | bb0744ec87066c9ddd6c0fcafc61af0100056938 | |
parent | f23d7fc736340ab43a524da61fa06c919c5e0bbd (diff) |
refactor server_collations.php
1. split long function
2. add server_common.lib.php
-rw-r--r-- | libraries/server_collations.lib.php | 114 | ||||
-rw-r--r-- | libraries/server_common.lib.php | 3 | ||||
-rw-r--r-- | server_collations.php | 76 |
3 files changed, 131 insertions, 62 deletions
diff --git a/libraries/server_collations.lib.php b/libraries/server_collations.lib.php new file mode 100644 index 0000000000..9ccb41f385 --- /dev/null +++ b/libraries/server_collations.lib.php @@ -0,0 +1,114 @@ +<?php +/* vim: set expandtab sw=4 ts=4 sts=4: */ + +/** + * functions for displaying server Character Sets and Collations + * + * @usedby server_collations.php + * + * @package PhpMyAdmin + */ +if (! defined('PHPMYADMIN')) { + exit; +} + +/** + * Returns the html for server Character Sets and Collations. + * + * @param Array $mysql_charsets Mysql Charsets list + * + * @param Array $mysql_collations Mysql Collations list + * + * @param Array $mysql_charsets_descriptions Charsets descriptions + * + * @param Array $mysql_default_collations Default Collations list + * + * @param Array $mysql_collations_available Available Collations list + * + * @return string + */ +function PMA_getCharsetInfo($mysql_charsets, $mysql_collations, + $mysql_charsets_descriptions, $mysql_default_collations, + $mysql_collations_available) +{ + /** + * Outputs the result + */ + $html = '<div id="div_mysql_charset_collations">' . "\n" + . '<table class="data noclick">' . "\n" + . '<tr><th>' . __('Collation') . '</th>' . "\n" + . ' <th>' . __('Description') . '</th>' . "\n" + . '</tr>' . "\n"; + + $i = 0; + $table_row_count = count($mysql_charsets) + count($mysql_collations); + + foreach ($mysql_charsets as $current_charset) { + if ($i >= $table_row_count / 2) { + $i = 0; + $html .= '</table>' . "\n" + . '<table class="data noclick">' . "\n" + . '<tr><th>' . __('Collation') . '</th>' . "\n" + . ' <th>' . __('Description') . '</th>' . "\n" + . '</tr>' . "\n"; + } + $i++; + $html .= '<tr><th colspan="2" class="right">' . "\n" + . ' ' . htmlspecialchars($current_charset) . "\n" + . (empty($mysql_charsets_descriptions[$current_charset]) + ? '' + : ' (<i>' . htmlspecialchars( + $mysql_charsets_descriptions[$current_charset] + ) . '</i>)' . "\n") + . ' </th>' . "\n" + . '</tr>' . "\n"; + + $html .= PMA_getCollationsInfo($current_charset, $mysql_collations, $i, + $mysql_default_collations, $mysql_collations_available); + } + unset($table_row_count); + $html .= '</table>' . "\n" + . '</div>' . "\n"; + + return $html; +} + + +/** + * Returns the html for server Collations. + * + * @param String $current_charset Current Charset + * + * @param Array $mysql_collations Collations list + * + * @param Array $mysql_default_collations Default Collations list + * + * @param Array $mysql_collations_available Available Collations list + * + * @param int $i Display Index + * + * @return string + */ +function PMA_getCollationsInfo($current_charset, $mysql_collations, &$i, + $mysql_default_collations, $mysql_collations_available) +{ + $odd_row = true; + $html = ''; + foreach ($mysql_collations[$current_charset] as $current_collation) { + $i++; + $html .= '<tr class="' + . ($odd_row ? 'odd' : 'even') + . ($mysql_default_collations[$current_charset] == $current_collation + ? ' marked' + : '') + . ($mysql_collations_available[$current_collation] ? '' : ' disabled') + . '">' . "\n" + . ' <td>' . htmlspecialchars($current_collation) . '</td>' . "\n" + . ' <td>' . PMA_getCollationDescr($current_collation) . '</td>' . "\n" + . '</tr>' . "\n"; + $odd_row = !$odd_row; + } + return $html; +} + +?> diff --git a/libraries/server_common.lib.php b/libraries/server_common.lib.php index 1b99c3c623..b686c65ef3 100644 --- a/libraries/server_common.lib.php +++ b/libraries/server_common.lib.php @@ -26,6 +26,9 @@ function PMA_getSubPageHeader($type) $res['binlog']['icon'] = 's_tbl.png'; $res['binlog']['text'] = __('Binary log'); + $res['collations']['icon'] = 's_asci.png'; + $res['collations']['text'] = __('Character Sets and Collations'); + $html = '<h2>' . "\n" . PMA_Util::getImage($res[$type]['icon']) . ' ' . $res[$type]['text'] . "\n" diff --git a/server_collations.php b/server_collations.php index 0e1164789a..0bd3b4fd14 100644 --- a/server_collations.php +++ b/server_collations.php @@ -13,75 +13,27 @@ require_once 'libraries/common.inc.php'; /** * Does the common work */ -require 'libraries/server_common.inc.php'; +require_once 'libraries/server_common.inc.php'; -$response = PMA_Response::getInstance(); - -/** - * Displays the sub-page heading - */ -$html = '<h2>' . "\n" - . ' ' . PMA_Util::getImage('s_asci.png') - . '' . __('Character Sets and Collations') . "\n" - . '</h2>' . "\n"; +require_once 'libraries/server_collations.lib.php'; /** * Includes the required charset library */ require_once 'libraries/mysql_charsets.lib.php'; +$response = PMA_Response::getInstance(); -/** - * Outputs the result - */ -$html .= '<div id="div_mysql_charset_collations">' . "\n" - . '<table class="data noclick">' . "\n" - . '<tr><th>' . __('Collation') . '</th>' . "\n" - . ' <th>' . __('Description') . '</th>' . "\n" - . '</tr>' . "\n"; - -$i = 0; -$table_row_count = count($mysql_charsets) + count($mysql_collations); - -foreach ($mysql_charsets as $current_charset) { - if ($i >= $table_row_count / 2) { - $i = 0; - $html .= '</table>' . "\n" - . '<table class="data noclick">' . "\n" - . '<tr><th>' . __('Collation') . '</th>' . "\n" - . ' <th>' . __('Description') . '</th>' . "\n" - . '</tr>' . "\n"; - } - $i++; - $html .= '<tr><th colspan="2" class="right">' . "\n" - . ' ' . htmlspecialchars($current_charset) . "\n" - . (empty($mysql_charsets_descriptions[$current_charset]) - ? '' - : ' (<i>' . htmlspecialchars( - $mysql_charsets_descriptions[$current_charset] - ) . '</i>)' . "\n") - . ' </th>' . "\n" - . '</tr>' . "\n"; - $odd_row = true; - foreach ($mysql_collations[$current_charset] as $current_collation) { - $i++; - $html .= '<tr class="' - . ($odd_row ? 'odd' : 'even') - . ($mysql_default_collations[$current_charset] == $current_collation - ? ' marked' - : '') - . ($mysql_collations_available[$current_collation] ? '' : ' disabled') - . '">' . "\n" - . ' <td>' . htmlspecialchars($current_collation) . '</td>' . "\n" - . ' <td>' . PMA_getCollationDescr($current_collation) . '</td>' . "\n" - . '</tr>' . "\n"; - $odd_row = !$odd_row; - } -} -unset($table_row_count); -$html .= '</table>' . "\n" - . '</div>' . "\n"; - -$response->addHTML($html); +$response->addHTML(PMA_getSubPageHeader('collations')); +$response->addHTML(PMA_getCharsetInfo( + $mysql_charsets, + $mysql_collations, + $mysql_charsets_descriptions, + $mysql_default_collations, + $mysql_collations_available + ) + ); + +exit; ?> |