Add OK and Cancel button for grid editing
[phpmyadmin/arisferyanto.git] / libraries / mysql_charsets.lib.php
blob83d7d77a1cea0febdfbc0343f438fce43c351c10
1 <?php
2 /* vim: set expandtab sw=4 ts=4 sts=4: */
3 /**
5 * @package PhpMyAdmin
6 */
7 if (! defined('PHPMYADMIN')) {
8 exit;
11 /**
14 if (! PMA_cacheExists('mysql_charsets', true)) {
15 $sql = PMA_DRIZZLE
16 ? 'SELECT * FROM data_dictionary.CHARACTER_SETS'
17 : 'SELECT * FROM information_schema.CHARACTER_SETS';
18 $res = PMA_DBI_query($sql);
20 $mysql_charsets = array();
21 while ($row = PMA_DBI_fetch_assoc($res)) {
22 $mysql_charsets[] = $row['CHARACTER_SET_NAME'];
23 // never used
24 //$mysql_charsets_maxlen[$row['Charset']] = $row['Maxlen'];
25 $mysql_charsets_descriptions[$row['CHARACTER_SET_NAME']] = $row['DESCRIPTION'];
27 PMA_DBI_free_result($res);
29 sort($mysql_charsets, SORT_STRING);
31 $mysql_collations = array_flip($mysql_charsets);
32 $mysql_default_collations = $mysql_collations_flat = $mysql_charsets_available = $mysql_collations_available = array();
34 $sql = PMA_DRIZZLE
35 ? 'SELECT * FROM data_dictionary.COLLATIONS'
36 : 'SELECT * FROM information_schema.COLLATIONS';
37 $res = PMA_DBI_query($sql);
38 while ($row = PMA_DBI_fetch_assoc($res)) {
39 if (! is_array($mysql_collations[$row['CHARACTER_SET_NAME']])) {
40 $mysql_collations[$row['CHARACTER_SET_NAME']] = array($row['COLLATION_NAME']);
41 } else {
42 $mysql_collations[$row['CHARACTER_SET_NAME']][] = $row['COLLATION_NAME'];
44 $mysql_collations_flat[] = $row['COLLATION_NAME'];
45 if ($row['IS_DEFAULT'] == 'Yes' || $row['IS_DEFAULT'] == '1') {
46 $mysql_default_collations[$row['CHARACTER_SET_NAME']] = $row['COLLATION_NAME'];
48 //$mysql_collations_available[$row['Collation']] = ! isset($row['Compiled']) || $row['Compiled'] == 'Yes';
49 $mysql_collations_available[$row['COLLATION_NAME']] = true;
50 $mysql_charsets_available[$row['CHARACTER_SET_NAME']] =
51 !empty($mysql_charsets_available[$row['CHARACTER_SET_NAME']])
52 || !empty($mysql_collations_available[$row['COLLATION_NAME']]);
54 PMA_DBI_free_result($res);
55 unset($res, $row);
57 if (PMA_DRIZZLE && isset($mysql_collations['utf8_general_ci']) && isset($mysql_collations['utf8'])) {
58 $mysql_collations['utf8'] = $mysql_collations['utf8_general_ci'];
59 $mysql_default_collations['utf8'] = $mysql_default_collations['utf8_general_ci'];
60 $mysql_charsets_available['utf8'] = $mysql_charsets_available['utf8_general_ci'];
61 unset($mysql_collations['utf8_general_ci'], $mysql_default_collations['utf8_general_ci'],
62 $mysql_charsets_available['utf8_general_ci']);
65 sort($mysql_collations_flat, SORT_STRING);
66 foreach ($mysql_collations AS $key => $value) {
67 sort($mysql_collations[$key], SORT_STRING);
68 reset($mysql_collations[$key]);
70 unset($key, $value);
72 PMA_cacheSet('mysql_charsets', $GLOBALS['mysql_charsets'], true);
73 PMA_cacheSet('mysql_charsets_descriptions', $GLOBALS['mysql_charsets_descriptions'], 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_available', $GLOBALS['mysql_collations_available'], true);
79 } else {
80 $GLOBALS['mysql_charsets'] = PMA_cacheGet('mysql_charsets', true);
81 $GLOBALS['mysql_charsets_descriptions'] = PMA_cacheGet('mysql_charsets_descriptions', true);
82 $GLOBALS['mysql_charsets_available'] = PMA_cacheGet('mysql_charsets_available', true);
83 $GLOBALS['mysql_collations'] = PMA_cacheGet('mysql_collations', true);
84 $GLOBALS['mysql_default_collations'] = PMA_cacheGet('mysql_default_collations', true);
85 $GLOBALS['mysql_collations_flat'] = PMA_cacheGet('mysql_collations_flat', true);
86 $GLOBALS['mysql_collations_available'] = PMA_cacheGet('mysql_collations_available', true);
89 define('PMA_CSDROPDOWN_COLLATION', 0);
90 define('PMA_CSDROPDOWN_CHARSET', 1);
92 function PMA_generateCharsetDropdownBox($type = PMA_CSDROPDOWN_COLLATION,
93 $name = null, $id = null, $default = null, $label = true, $indent = 0,
94 $submitOnChange = false, $displayUnavailable = false)
96 global $mysql_charsets, $mysql_charsets_descriptions,
97 $mysql_charsets_available, $mysql_collations, $mysql_collations_available;
99 if (empty($name)) {
100 if ($type == PMA_CSDROPDOWN_COLLATION) {
101 $name = 'collation';
102 } else {
103 $name = 'character_set';
107 $return_str = '<select xml:lang="en" dir="ltr" name="'
108 . htmlspecialchars($name) . '"'
109 . (empty($id) ? '' : ' id="' . htmlspecialchars($id) . '"')
110 . ($submitOnChange ? ' class="autosubmit"' : '') . '>' . "\n";
111 if ($label) {
112 $return_str .= '<option value="">'
113 . ($type == PMA_CSDROPDOWN_COLLATION ? __('Collation') : __('Charset'))
114 . '</option>' . "\n";
116 $return_str .= '<option value=""></option>' . "\n";
117 foreach ($mysql_charsets as $current_charset) {
118 if (!$mysql_charsets_available[$current_charset]) {
119 continue;
121 $current_cs_descr =
122 empty($mysql_charsets_descriptions[$current_charset])
123 ? $current_charset
124 : $mysql_charsets_descriptions[$current_charset];
126 if ($type == PMA_CSDROPDOWN_COLLATION) {
127 $return_str .= '<optgroup label="' . $current_charset
128 . '" title="' . $current_cs_descr . '">' . "\n";
129 foreach ($mysql_collations[$current_charset] as $current_collation) {
130 if (!$mysql_collations_available[$current_collation]) {
131 continue;
133 $return_str .= '<option value="' . $current_collation
134 . '" title="' . PMA_getCollationDescr($current_collation) . '"'
135 . ($default == $current_collation ? ' selected="selected"' : '') . '>'
136 . $current_collation . '</option>' . "\n";
138 $return_str .= '</optgroup>' . "\n";
139 } else {
140 $return_str .= '<option value="' . $current_charset
141 . '" title="' . $current_cs_descr . '"'
142 . ($default == $current_charset ? ' selected="selected"' : '') . '>'
143 . $current_charset . '</option>' . "\n";
146 $return_str .= '</select>' . "\n";
148 return $return_str;
151 function PMA_generateCharsetQueryPart($collation)
153 if (!PMA_DRIZZLE) {
154 list($charset) = explode('_', $collation);
155 return ' CHARACTER SET ' . $charset . ($charset == $collation ? '' : ' COLLATE ' . $collation);
156 } else {
157 return ' COLLATE ' . $collation;
162 * returns collation of given db
164 * @param string $db name of db
165 * @return string collation of $db
167 function PMA_getDbCollation($db)
169 if (PMA_is_system_schema($db)) {
170 // We don't have to check the collation of the virtual
171 // information_schema database: We know it!
172 return 'utf8_general_ci';
175 if (! $GLOBALS['cfg']['Server']['DisableIS']) {
176 // this is slow with thousands of databases
177 $sql = PMA_DRIZZLE
178 ? 'SELECT DEFAULT_COLLATION_NAME FROM data_dictionary.SCHEMAS WHERE SCHEMA_NAME = \'' . PMA_sqlAddSlashes($db) . '\' LIMIT 1'
179 : 'SELECT DEFAULT_COLLATION_NAME FROM information_schema.SCHEMATA WHERE SCHEMA_NAME = \'' . PMA_sqlAddSlashes($db) . '\' LIMIT 1';
180 return PMA_DBI_fetch_value($sql);
181 } else {
182 PMA_DBI_select_db($db);
183 $return = PMA_DBI_fetch_value('SHOW VARIABLES LIKE \'collation_database\'', 0, 1);
184 if ($db !== $GLOBALS['db']) {
185 PMA_DBI_select_db($GLOBALS['db']);
187 return $return;
192 * returns default server collation from show variables
194 * @return string $server_collation
196 function PMA_getServerCollation()
198 return PMA_DBI_fetch_value(
199 'SHOW VARIABLES LIKE \'collation_server\'', 0, 1);
203 * returns description for given collation
206 * @param string $collation MySQL collation string
207 * @return string collation description
209 function PMA_getCollationDescr($collation)
211 if ($collation == 'binary') {
212 return __('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';
221 $descr = '';
222 switch ($parts[1]) {
223 case 'bulgarian':
224 $descr = __('Bulgarian');
225 break;
226 case 'chinese':
227 if ($parts[0] == 'gb2312' || $parts[0] == 'gbk') {
228 $descr = __('Simplified Chinese');
229 } elseif ($parts[0] == 'big5') {
230 $descr = __('Traditional Chinese');
232 break;
233 case 'ci':
234 $descr = __('case-insensitive');
235 break;
236 case 'cs':
237 $descr = __('case-sensitive');
238 break;
239 case 'croatian':
240 $descr = __('Croatian');
241 break;
242 case 'czech':
243 $descr = __('Czech');
244 break;
245 case 'danish':
246 $descr = __('Danish');
247 break;
248 case 'english':
249 $descr = __('English');
250 break;
251 case 'esperanto':
252 $descr = __('Esperanto');
253 break;
254 case 'estonian':
255 $descr = __('Estonian');
256 break;
257 case 'german1':
258 $descr = __('German') . ' (' . __('dictionary') . ')';
259 break;
260 case 'german2':
261 $descr = __('German') . ' (' . __('phone book') . ')';
262 break;
263 case 'hungarian':
264 $descr = __('Hungarian');
265 break;
266 case 'icelandic':
267 $descr = __('Icelandic');
268 break;
269 case 'japanese':
270 $descr = __('Japanese');
271 break;
272 case 'latvian':
273 $descr = __('Latvian');
274 break;
275 case 'lithuanian':
276 $descr = __('Lithuanian');
277 break;
278 case 'korean':
279 $descr = __('Korean');
280 break;
281 case 'persian':
282 $descr = __('Persian');
283 break;
284 case 'polish':
285 $descr = __('Polish');
286 break;
287 case 'roman':
288 $descr = __('West European');
289 break;
290 case 'romanian':
291 $descr = __('Romanian');
292 break;
293 case 'slovak':
294 $descr = __('Slovak');
295 break;
296 case 'slovenian':
297 $descr = __('Slovenian');
298 break;
299 case 'spanish':
300 $descr = __('Spanish');
301 break;
302 case 'spanish2':
303 $descr = __('Traditional Spanish');
304 break;
305 case 'swedish':
306 $descr = __('Swedish');
307 break;
308 case 'thai':
309 $descr = __('Thai');
310 break;
311 case 'turkish':
312 $descr = __('Turkish');
313 break;
314 case 'ukrainian':
315 $descr = __('Ukrainian');
316 break;
317 case 'unicode':
318 $descr = __('Unicode') . ' (' . __('multilingual') . ')';
319 break;
320 case 'bin':
321 $is_bin = true;
322 case 'general':
323 switch ($parts[0]) {
324 // Unicode charsets
325 case 'ucs2':
326 case 'utf8':
327 $descr = __('Unicode') . ' (' . __('multilingual') . ')';
328 break;
329 // West European charsets
330 case 'ascii':
331 case 'cp850':
332 case 'dec8':
333 case 'hp8':
334 case 'latin1':
335 case 'macroman':
336 $descr = __('West European') . ' (' . __('multilingual') . ')';
337 break;
338 // Central European charsets
339 case 'cp1250':
340 case 'cp852':
341 case 'latin2':
342 case 'macce':
343 $descr = __('Central European') . ' (' . __('multilingual') . ')';
344 break;
345 // Russian charsets
346 case 'cp866':
347 case 'koi8r':
348 $descr = __('Russian');
349 break;
350 // Simplified Chinese charsets
351 case 'gb2312':
352 case 'gbk':
353 $descr = __('Simplified Chinese');
354 break;
355 // Japanese charsets
356 case 'sjis':
357 case 'ujis':
358 case 'cp932':
359 case 'eucjpms':
360 $descr = __('Japanese');
361 break;
362 // Baltic charsets
363 case 'cp1257':
364 case 'latin7':
365 $descr = __('Baltic') . ' (' . __('multilingual') . ')';
366 break;
367 // Other
368 case 'armscii8':
369 case 'armscii':
370 $descr = __('Armenian');
371 break;
372 case 'big5':
373 $descr = __('Traditional Chinese');
374 break;
375 case 'cp1251':
376 $descr = __('Cyrillic') . ' (' . __('multilingual') . ')';
377 break;
378 case 'cp1256':
379 $descr = __('Arabic');
380 break;
381 case 'euckr':
382 $descr = __('Korean');
383 break;
384 case 'hebrew':
385 $descr = __('Hebrew');
386 break;
387 case 'geostd8':
388 $descr = __('Georgian');
389 break;
390 case 'greek':
391 $descr = __('Greek');
392 break;
393 case 'keybcs2':
394 $descr = __('Czech-Slovak');
395 break;
396 case 'koi8u':
397 $descr = __('Ukrainian');
398 break;
399 case 'latin5':
400 $descr = __('Turkish');
401 break;
402 case 'swe7':
403 $descr = __('Swedish');
404 break;
405 case 'tis620':
406 $descr = __('Thai');
407 break;
408 default:
409 $descr = __('unknown');
410 break;
412 if (!empty($is_bin)) {
413 $descr .= ', ' . __('Binary');
415 break;
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');
426 return $descr;