2 /* vim: set expandtab sw=4 ts=4 sts=4: */
7 if (! defined('PHPMYADMIN')) {
14 if (PMA_MYSQL_MAJOR_VERSION
> 2009) {
15 /* There are no charsets in Drizzle */
16 $GLOBALS['mysql_charsets'] = array();
17 $GLOBALS['mysql_charsets_descriptions'] = array('utf8' => 'UTF-8 Unicode');
18 $GLOBALS['mysql_charsets_count'] = 0;
19 $GLOBALS['mysql_charsets_available'] = array();
20 $GLOBALS['mysql_collations'] = array();
21 $GLOBALS['mysql_default_collations'] = array();
22 $GLOBALS['mysql_collations_flat'] = array();
23 $GLOBALS['mysql_collations_count'] = 0;
24 $GLOBALS['mysql_collations_available'] = array();
25 } elseif (! PMA_cacheExists('mysql_charsets_count', true)) {
26 $res = PMA_DBI_query('SHOW CHARACTER SET;');
28 $mysql_charsets = array();
29 while ($row = PMA_DBI_fetch_assoc($res)) {
30 $mysql_charsets[] = $row['Charset'];
32 //$mysql_charsets_maxlen[$row['Charset']] = $row['Maxlen'];
33 $mysql_charsets_descriptions[$row['Charset']] = $row['Description'];
35 PMA_DBI_free_result($res);
37 $mysql_charsets_count = count($mysql_charsets);
38 sort($mysql_charsets, SORT_STRING
);
40 $mysql_collations = array_flip($mysql_charsets);
41 $mysql_default_collations = $mysql_collations_flat = $mysql_charsets_available = $mysql_collations_available = array();
43 $res = PMA_DBI_query('SHOW COLLATION;');
44 while ($row = PMA_DBI_fetch_assoc($res)) {
45 if (!is_array($mysql_collations[$row['Charset']])) {
46 $mysql_collations[$row['Charset']] = array($row['Collation']);
48 $mysql_collations[$row['Charset']][] = $row['Collation'];
50 $mysql_collations_flat[] = $row['Collation'];
51 if ((isset($row['D']) && $row['D'] == 'Y') ||
(isset($row['Default']) && $row['Default'] == 'Yes')) {
52 $mysql_default_collations[$row['Charset']] = $row['Collation'];
54 //$mysql_collations_available[$row['Collation']] = !isset($row['Compiled']) || $row['Compiled'] == 'Yes';
55 $mysql_collations_available[$row['Collation']] = TRUE;
56 $mysql_charsets_available[$row['Charset']] =
57 !empty($mysql_charsets_available[$row['Charset']])
58 ||
!empty($mysql_collations_available[$row['Collation']]);
60 PMA_DBI_free_result($res);
63 $mysql_collations_count = count($mysql_collations_flat);
64 sort($mysql_collations_flat, SORT_STRING
);
65 foreach ($mysql_collations AS $key => $value) {
66 sort($mysql_collations[$key], SORT_STRING
);
67 reset($mysql_collations[$key]);
71 PMA_cacheSet('mysql_charsets', $GLOBALS['mysql_charsets'], true);
72 PMA_cacheSet('mysql_charsets_descriptions', $GLOBALS['mysql_charsets_descriptions'], true);
73 PMA_cacheSet('mysql_charsets_count', $GLOBALS['mysql_charsets_count'], true);
74 PMA_cacheSet('mysql_charsets_available', $GLOBALS['mysql_charsets_available'], true);
75 PMA_cacheSet('mysql_collations', $GLOBALS['mysql_collations'], true);
76 PMA_cacheSet('mysql_default_collations', $GLOBALS['mysql_default_collations'], true);
77 PMA_cacheSet('mysql_collations_flat', $GLOBALS['mysql_collations_flat'], true);
78 PMA_cacheSet('mysql_collations_count', $GLOBALS['mysql_collations_count'], true);
79 PMA_cacheSet('mysql_collations_available', $GLOBALS['mysql_collations_available'], true);
81 $GLOBALS['mysql_charsets'] = PMA_cacheGet('mysql_charsets', true);
82 $GLOBALS['mysql_charsets_descriptions'] = PMA_cacheGet('mysql_charsets_descriptions', true);
83 $GLOBALS['mysql_charsets_count'] = PMA_cacheGet('mysql_charsets_count', true);
84 $GLOBALS['mysql_charsets_available'] = PMA_cacheGet('mysql_charsets_available', true);
85 $GLOBALS['mysql_collations'] = PMA_cacheGet('mysql_collations', true);
86 $GLOBALS['mysql_default_collations'] = PMA_cacheGet('mysql_default_collations', true);
87 $GLOBALS['mysql_collations_flat'] = PMA_cacheGet('mysql_collations_flat', true);
88 $GLOBALS['mysql_collations_count'] = PMA_cacheGet('mysql_collations_count', true);
89 $GLOBALS['mysql_collations_available'] = PMA_cacheGet('mysql_collations_available', true);
92 define('PMA_CSDROPDOWN_COLLATION', 0);
93 define('PMA_CSDROPDOWN_CHARSET', 1);
95 function PMA_generateCharsetDropdownBox($type = PMA_CSDROPDOWN_COLLATION
,
96 $name = null, $id = null, $default = null, $label = TRUE, $indent = 0,
97 $submitOnChange = FALSE, $displayUnavailable = FALSE)
99 global $mysql_charsets, $mysql_charsets_descriptions,
100 $mysql_charsets_available, $mysql_collations, $mysql_collations_available;
103 if ($type == PMA_CSDROPDOWN_COLLATION
) {
106 $name = 'character_set';
110 $return_str = '<select xml:lang="en" dir="ltr" name="'
111 . htmlspecialchars($name) . '"'
112 . (empty($id) ?
'' : ' id="' . htmlspecialchars($id) . '"')
113 . ($submitOnChange ?
' onchange="this.form.submit();"' : '') . '>' . "\n";
115 $return_str .= '<option value="">'
116 . ($type == PMA_CSDROPDOWN_COLLATION ?
__('Collation') : __('Charset'))
117 . '</option>' . "\n";
119 $return_str .= '<option value=""></option>' . "\n";
120 foreach ($mysql_charsets as $current_charset) {
121 if (!$mysql_charsets_available[$current_charset]) {
125 empty($mysql_charsets_descriptions[$current_charset])
127 : $mysql_charsets_descriptions[$current_charset];
129 if ($type == PMA_CSDROPDOWN_COLLATION
) {
130 $return_str .= '<optgroup label="' . $current_charset
131 . '" title="' . $current_cs_descr . '">' . "\n";
132 foreach ($mysql_collations[$current_charset] as $current_collation) {
133 if (!$mysql_collations_available[$current_collation]) {
136 $return_str .= '<option value="' . $current_collation
137 . '" title="' . PMA_getCollationDescr($current_collation) . '"'
138 . ($default == $current_collation ?
' selected="selected"' : '') . '>'
139 . $current_collation . '</option>' . "\n";
141 $return_str .= '</optgroup>' . "\n";
143 $return_str .= '<option value="' . $current_charset
144 . '" title="' . $current_cs_descr . '"'
145 . ($default == $current_charset ?
' selected="selected"' : '') . '>'
146 . $current_charset . '</option>' . "\n";
149 $return_str .= '</select>' . "\n";
154 function PMA_generateCharsetQueryPart($collation) {
155 list($charset) = explode('_', $collation);
156 return ' CHARACTER SET ' . $charset . ($charset == $collation ?
'' : ' COLLATE ' . $collation);
160 * returns collation of given db
162 * @uses PMA_DBI_fetch_value()
163 * @uses PMA_DBI_select_db()
164 * @uses PMA_sqlAddSlashes()
165 * @uses $GLOBALS['db']
166 * @param string $db name of db
167 * @return string collation of $db
169 function PMA_getDbCollation($db) {
170 if ($db == 'information_schema') {
171 // We don't have to check the collation of the virtual
172 // information_schema database: We know it!
173 return 'utf8_general_ci';
176 if (! $GLOBALS['cfg']['Server']['DisableIS']) {
177 // this is slow with thousands of databases
178 return PMA_DBI_fetch_value('SELECT DEFAULT_COLLATION_NAME FROM information_schema.SCHEMATA WHERE SCHEMA_NAME = \'' . PMA_sqlAddSlashes($db) . '\' LIMIT 1;');
180 PMA_DBI_select_db($db);
181 $return = PMA_DBI_fetch_value('SHOW VARIABLES LIKE \'collation_database\'', 0, 1);
182 if ($db !== $GLOBALS['db']) {
183 PMA_DBI_select_db($GLOBALS['db']);
190 * returns default server collation from show variables
192 * @uses PMA_DBI_fetch_value()
193 * @return string $server_collation
195 function PMA_getServerCollation() {
196 return PMA_DBI_fetch_value(
197 'SHOW VARIABLES LIKE \'collation_server\'', 0, 1);
201 * returns description for given collation
207 * @param string $collation MySQL collation string
208 * @return string collation description
210 function PMA_getCollationDescr($collation) {
211 if ($collation == 'binary') {
214 $parts = explode('_', $collation);
215 if (count($parts) == 1) {
216 $parts[1] = 'general';
217 } elseif ($parts[1] == 'ci' ||
$parts[1] == 'cs') {
218 $parts[2] = $parts[1];
219 $parts[1] = 'general';
224 $descr = __('Bulgarian');
227 if ($parts[0] == 'gb2312' ||
$parts[0] == 'gbk') {
228 $descr = __('Simplified Chinese');
229 } elseif ($parts[0] == 'big5') {
230 $descr = __('Traditional Chinese');
234 $descr = __('case-insensitive');
237 $descr = __('case-sensitive');
240 $descr = __('Croatian');
243 $descr = __('Czech');
246 $descr = __('Danish');
249 $descr = __('English');
252 $descr = __('Esperanto');
255 $descr = __('Estonian');
258 $descr = __('German') . ' (' . __('dictionary') . ')';
261 $descr = __('German') . ' (' . __('phone book') . ')';
264 $descr = __('Hungarian');
267 $descr = __('Icelandic');
270 $descr = __('Japanese');
273 $descr = __('Latvian');
276 $descr = __('Lithuanian');
279 $descr = __('Korean');
282 $descr = __('Persian');
285 $descr = __('Polish');
288 $descr = __('West European');
291 $descr = __('Romanian');
294 $descr = __('Slovak');
297 $descr = __('Slovenian');
300 $descr = __('Spanish');
303 $descr = __('Traditional Spanish');
306 $descr = __('Swedish');
312 $descr = __('Turkish');
315 $descr = __('Ukrainian');
318 $descr = __('Unicode') . ' (' . __('multilingual') . ')';
327 $descr = __('Unicode') . ' (' . __('multilingual') . ')';
329 // West European charsets
336 $descr = __('West European') . ' (' . __('multilingual') . ')';
338 // Central European charsets
343 $descr = __('Central European') . ' (' . __('multilingual') . ')';
348 $descr = __('Russian');
350 // Simplified Chinese charsets
353 $descr = __('Simplified Chinese');
360 $descr = __('Japanese');
365 $descr = __('Baltic') . ' (' . __('multilingual') . ')';
370 $descr = __('Armenian');
373 $descr = __('Traditional Chinese');
376 $descr = __('Cyrillic') . ' (' . __('multilingual') . ')';
379 $descr = __('Arabic');
382 $descr = __('Korean');
385 $descr = __('Hebrew');
388 $descr = __('Georgian');
391 $descr = __('Greek');
394 $descr = __('Czech-Slovak');
397 $descr = __('Ukrainian');
400 $descr = __('Turkish');
403 $descr = __('Swedish');
409 $descr = __('unknown');
412 if (!empty($is_bin)) {
413 $descr .= ', ' . __('Binary');
416 default: $descr = __('unknown');
418 if (!empty($parts[2])) {
419 if ($parts[2] == 'ci') {
420 $descr .= ', ' . __('case-insensitive');
421 } elseif ($parts[2] == 'cs') {
422 $descr .= ', ' . __('case-sensitive');