bug #2356433 [display] HeaderFlipType "fake" problems
[phpmyadmin/crack.git] / libraries / mysql_charsets.lib.php
blob518b92a4f51db3fa047df48cd0d16c3ad52b1cec
1 <?php
2 /* vim: set expandtab sw=4 ts=4 sts=4: */
3 /**
5 * @version $Id$
6 */
7 if (! defined('PHPMYADMIN')) {
8 exit;
11 /**
15 if (! PMA_cacheExists('mysql_charsets_count', true)) {
16 $res = PMA_DBI_query('SHOW CHARACTER SET;');
18 $mysql_charsets = array();
19 while ($row = PMA_DBI_fetch_assoc($res)) {
20 $mysql_charsets[] = $row['Charset'];
21 // never used
22 //$mysql_charsets_maxlen[$row['Charset']] = $row['Maxlen'];
23 $mysql_charsets_descriptions[$row['Charset']] = $row['Description'];
25 PMA_DBI_free_result($res);
27 $mysql_charsets_count = count($mysql_charsets);
28 sort($mysql_charsets, SORT_STRING);
30 $mysql_collations = array_flip($mysql_charsets);
31 $mysql_default_collations = $mysql_collations_flat = $mysql_charsets_available = $mysql_collations_available = array();
33 $res = PMA_DBI_query('SHOW COLLATION;');
34 while ($row = PMA_DBI_fetch_assoc($res)) {
35 if (!is_array($mysql_collations[$row['Charset']])) {
36 $mysql_collations[$row['Charset']] = array($row['Collation']);
37 } else {
38 $mysql_collations[$row['Charset']][] = $row['Collation'];
40 $mysql_collations_flat[] = $row['Collation'];
41 if ((isset($row['D']) && $row['D'] == 'Y') || (isset($row['Default']) && $row['Default'] == 'Yes')) {
42 $mysql_default_collations[$row['Charset']] = $row['Collation'];
44 //$mysql_collations_available[$row['Collation']] = !isset($row['Compiled']) || $row['Compiled'] == 'Yes';
45 $mysql_collations_available[$row['Collation']] = TRUE;
46 $mysql_charsets_available[$row['Charset']] =
47 !empty($mysql_charsets_available[$row['Charset']])
48 || !empty($mysql_collations_available[$row['Collation']]);
50 PMA_DBI_free_result($res);
51 unset($res, $row);
53 $mysql_collations_count = count($mysql_collations_flat);
54 sort($mysql_collations_flat, SORT_STRING);
55 foreach ($mysql_collations AS $key => $value) {
56 sort($mysql_collations[$key], SORT_STRING);
57 reset($mysql_collations[$key]);
59 unset($key, $value);
61 PMA_cacheSet('mysql_charsets', $GLOBALS['mysql_charsets'], true);
62 PMA_cacheSet('mysql_charsets_descriptions', $GLOBALS['mysql_charsets_descriptions'], true);
63 PMA_cacheSet('mysql_charsets_count', $GLOBALS['mysql_charsets_count'], true);
64 PMA_cacheSet('mysql_charsets_available', $GLOBALS['mysql_charsets_available'], true);
65 PMA_cacheSet('mysql_collations', $GLOBALS['mysql_collations'], true);
66 PMA_cacheSet('mysql_default_collations', $GLOBALS['mysql_default_collations'], true);
67 PMA_cacheSet('mysql_collations_flat', $GLOBALS['mysql_collations_flat'], true);
68 PMA_cacheSet('mysql_collations_count', $GLOBALS['mysql_collations_count'], true);
69 PMA_cacheSet('mysql_collations_available', $GLOBALS['mysql_collations_available'], true);
70 } else {
71 $GLOBALS['mysql_charsets'] = PMA_cacheGet('mysql_charsets', true);
72 $GLOBALS['mysql_charsets_descriptions'] = PMA_cacheGet('mysql_charsets_descriptions', true);
73 $GLOBALS['mysql_charsets_count'] = PMA_cacheGet('mysql_charsets_count', true);
74 $GLOBALS['mysql_charsets_available'] = PMA_cacheGet('mysql_charsets_available', true);
75 $GLOBALS['mysql_collations'] = PMA_cacheGet('mysql_collations', true);
76 $GLOBALS['mysql_default_collations'] = PMA_cacheGet('mysql_default_collations', true);
77 $GLOBALS['mysql_collations_flat'] = PMA_cacheGet('mysql_collations_flat', true);
78 $GLOBALS['mysql_collations_count'] = PMA_cacheGet('mysql_collations_count', true);
79 $GLOBALS['mysql_collations_available'] = PMA_cacheGet('mysql_collations_available', true);
82 define('PMA_CSDROPDOWN_COLLATION', 0);
83 define('PMA_CSDROPDOWN_CHARSET', 1);
85 function PMA_generateCharsetDropdownBox($type = PMA_CSDROPDOWN_COLLATION,
86 $name = null, $id = null, $default = null, $label = TRUE, $indent = 0,
87 $submitOnChange = FALSE, $displayUnavailable = FALSE)
89 global $mysql_charsets, $mysql_charsets_descriptions,
90 $mysql_charsets_available, $mysql_collations, $mysql_collations_available;
92 if (empty($name)) {
93 if ($type == PMA_CSDROPDOWN_COLLATION) {
94 $name = 'collation';
95 } else {
96 $name = 'character_set';
100 $return_str = '<select xml:lang="en" dir="ltr" name="'
101 . htmlspecialchars($name) . '"'
102 . (empty($id) ? '' : ' id="' . htmlspecialchars($id) . '"')
103 . ($submitOnChange ? ' onchange="this.form.submit();"' : '') . '>' . "\n";
104 if ($label) {
105 $return_str .= '<option value="">'
106 . ($type == PMA_CSDROPDOWN_COLLATION ? $GLOBALS['strCollation'] : $GLOBALS['strCharset'])
107 . '</option>' . "\n";
109 $return_str .= '<option value=""></option>' . "\n";
110 foreach ($mysql_charsets as $current_charset) {
111 if (!$mysql_charsets_available[$current_charset]) {
112 continue;
114 $current_cs_descr =
115 empty($mysql_charsets_descriptions[$current_charset])
116 ? $current_charset
117 : $mysql_charsets_descriptions[$current_charset];
119 if ($type == PMA_CSDROPDOWN_COLLATION) {
120 $return_str .= '<optgroup label="' . $current_charset
121 . '" title="' . $current_cs_descr . '">' . "\n";
122 foreach ($mysql_collations[$current_charset] as $current_collation) {
123 if (!$mysql_collations_available[$current_collation]) {
124 continue;
126 $return_str .= '<option value="' . $current_collation
127 . '" title="' . PMA_getCollationDescr($current_collation) . '"'
128 . ($default == $current_collation ? ' selected="selected"' : '') . '>'
129 . $current_collation . '</option>' . "\n";
131 $return_str .= '</optgroup>' . "\n";
132 } else {
133 $return_str .= '<option value="' . $current_charset
134 . '" title="' . $current_cs_descr . '"'
135 . ($default == $current_charset ? ' selected="selected"' : '') . '>'
136 . $current_charset . '</option>' . "\n";
139 $return_str .= '</select>' . "\n";
141 return $return_str;
144 function PMA_generateCharsetQueryPart($collation) {
145 list($charset) = explode('_', $collation);
146 return ' CHARACTER SET ' . $charset . ($charset == $collation ? '' : ' COLLATE ' . $collation);
150 * returns collation of given db
152 * @uses PMA_DBI_fetch_value()
153 * @uses PMA_DBI_select_db()
154 * @uses PMA_sqlAddSlashes()
155 * @uses $GLOBALS['db']
156 * @param string $db name of db
157 * @return string collation of $db
159 function PMA_getDbCollation($db) {
160 if ($db == 'information_schema') {
161 // We don't have to check the collation of the virtual
162 // information_schema database: We know it!
163 return 'utf8_general_ci';
166 return PMA_DBI_fetch_value('SELECT DEFAULT_COLLATION_NAME FROM information_schema.SCHEMATA WHERE SCHEMA_NAME = \'' . PMA_sqlAddSlashes($db) . '\' LIMIT 1;');
170 * returns default server collation from show variables
172 * @uses PMA_DBI_fetch_value()
173 * @return string $server_collation
175 function PMA_getServerCollation() {
176 return PMA_DBI_fetch_value(
177 'SHOW VARIABLES LIKE \'collation_server\'', 0, 1);
181 * returns description for given collation
183 * @uses is_array()
184 * @uses explode()
185 * @uses count()
186 * @uses $GLOBALS['str[Languages|Sorting]']
188 * @param string $collation MySQL collation string
189 * @return string collation description
191 function PMA_getCollationDescr($collation) {
192 static $collation_cache;
194 if (!is_array($collation_cache)) {
195 $collation_cache = array();
196 } elseif (isset($collation_cache[$collation])) {
197 return $collation_cache[$collation];
200 if ($collation == 'binary') {
201 return $GLOBALS['strBinary'];
203 $parts = explode('_', $collation);
204 if (count($parts) == 1) {
205 $parts[1] = 'general';
206 } elseif ($parts[1] == 'ci' || $parts[1] == 'cs') {
207 $parts[2] = $parts[1];
208 $parts[1] = 'general';
210 $descr = '';
211 switch ($parts[1]) {
212 case 'bulgarian':
213 $descr = $GLOBALS['strBulgarian'];
214 break;
215 case 'chinese':
216 if ($parts[0] == 'gb2312' || $parts[0] == 'gbk') {
217 $descr = $GLOBALS['strSimplifiedChinese'];
218 } elseif ($parts[0] == 'big5') {
219 $descr = $GLOBALS['strTraditionalChinese'];
221 break;
222 case 'ci':
223 $descr = $GLOBALS['strCaseInsensitive'];
224 break;
225 case 'cs':
226 $descr = $GLOBALS['strCaseSensitive'];
227 break;
228 case 'croatian':
229 $descr = $GLOBALS['strCroatian'];
230 break;
231 case 'czech':
232 $descr = $GLOBALS['strCzech'];
233 break;
234 case 'danish':
235 $descr = $GLOBALS['strDanish'];
236 break;
237 case 'english':
238 $descr = $GLOBALS['strEnglish'];
239 break;
240 case 'esperanto':
241 $descr = $GLOBALS['strEsperanto'];
242 break;
243 case 'estonian':
244 $descr = $GLOBALS['strEstonian'];
245 break;
246 case 'german1':
247 $descr = $GLOBALS['strGerman'] . ' (' . $GLOBALS['strDictionary'] . ')';
248 break;
249 case 'german2':
250 $descr = $GLOBALS['strGerman'] . ' (' . $GLOBALS['strPhoneBook'] . ')';
251 break;
252 case 'hungarian':
253 $descr = $GLOBALS['strHungarian'];
254 break;
255 case 'icelandic':
256 $descr = $GLOBALS['strIcelandic'];
257 break;
258 case 'japanese':
259 $descr = $GLOBALS['strJapanese'];
260 break;
261 case 'latvian':
262 $descr = $GLOBALS['strLatvian'];
263 break;
264 case 'lithuanian':
265 $descr = $GLOBALS['strLithuanian'];
266 break;
267 case 'korean':
268 $descr = $GLOBALS['strKorean'];
269 break;
270 case 'persian':
271 $descr = $GLOBALS['strPersian'];
272 break;
273 case 'polish':
274 $descr = $GLOBALS['strPolish'];
275 break;
276 case 'roman':
277 $descr = $GLOBALS['strWestEuropean'];
278 break;
279 case 'romanian':
280 $descr = $GLOBALS['strRomanian'];
281 break;
282 case 'slovak':
283 $descr = $GLOBALS['strSlovak'];
284 break;
285 case 'slovenian':
286 $descr = $GLOBALS['strSlovenian'];
287 break;
288 case 'spanish':
289 $descr = $GLOBALS['strSpanish'];
290 break;
291 case 'spanish2':
292 $descr = $GLOBALS['strTraditionalSpanish'];
293 break;
294 case 'swedish':
295 $descr = $GLOBALS['strSwedish'];
296 break;
297 case 'thai':
298 $descr = $GLOBALS['strThai'];
299 break;
300 case 'turkish':
301 $descr = $GLOBALS['strTurkish'];
302 break;
303 case 'ukrainian':
304 $descr = $GLOBALS['strUkrainian'];
305 break;
306 case 'unicode':
307 $descr = $GLOBALS['strUnicode'] . ' (' . $GLOBALS['strMultilingual'] . ')';
308 break;
309 case 'bin':
310 $is_bin = TRUE;
311 case 'general':
312 switch ($parts[0]) {
313 // Unicode charsets
314 case 'ucs2':
315 case 'utf8':
316 $descr = $GLOBALS['strUnicode'] . ' (' . $GLOBALS['strMultilingual'] . ')';
317 break;
318 // West European charsets
319 case 'ascii':
320 case 'cp850':
321 case 'dec8':
322 case 'hp8':
323 case 'latin1':
324 case 'macroman':
325 $descr = $GLOBALS['strWestEuropean'] . ' (' . $GLOBALS['strMultilingual'] . ')';
326 break;
327 // Central European charsets
328 case 'cp1250':
329 case 'cp852':
330 case 'latin2':
331 case 'macce':
332 $descr = $GLOBALS['strCentralEuropean'] . ' (' . $GLOBALS['strMultilingual'] . ')';
333 break;
334 // Russian charsets
335 case 'cp866':
336 case 'koi8r':
337 $descr = $GLOBALS['strRussian'];
338 break;
339 // Simplified Chinese charsets
340 case 'gb2312':
341 case 'gbk':
342 $descr = $GLOBALS['strSimplifiedChinese'];
343 break;
344 // Japanese charsets
345 case 'sjis':
346 case 'ujis':
347 case 'cp932':
348 case 'eucjpms':
349 $descr = $GLOBALS['strJapanese'];
350 break;
351 // Baltic charsets
352 case 'cp1257':
353 case 'latin7':
354 $descr = $GLOBALS['strBaltic'] . ' (' . $GLOBALS['strMultilingual'] . ')';
355 break;
356 // Other
357 case 'armscii8':
358 case 'armscii':
359 $descr = $GLOBALS['strArmenian'];
360 break;
361 case 'big5':
362 $descr = $GLOBALS['strTraditionalChinese'];
363 break;
364 case 'cp1251':
365 $descr = $GLOBALS['strCyrillic'] . ' (' . $GLOBALS['strMultilingual'] . ')';
366 break;
367 case 'cp1256':
368 $descr = $GLOBALS['strArabic'];
369 break;
370 case 'euckr':
371 $descr = $GLOBALS['strKorean'];
372 break;
373 case 'hebrew':
374 $descr = $GLOBALS['strHebrew'];
375 break;
376 case 'geostd8':
377 $descr = $GLOBALS['strGeorgian'];
378 break;
379 case 'greek':
380 $descr = $GLOBALS['strGreek'];
381 break;
382 case 'keybcs2':
383 $descr = $GLOBALS['strCzechSlovak'];
384 break;
385 case 'koi8u':
386 $descr = $GLOBALS['strUkrainian'];
387 break;
388 case 'latin5':
389 $descr = $GLOBALS['strTurkish'];
390 break;
391 case 'swe7':
392 $descr = $GLOBALS['strSwedish'];
393 break;
394 case 'tis620':
395 $descr = $GLOBALS['strThai'];
396 break;
397 default:
398 $descr = $GLOBALS['strUnknown'];
399 break;
401 if (!empty($is_bin)) {
402 $descr .= ', ' . $GLOBALS['strBinary'];
404 break;
405 default: $descr = $GLOBALS['strUnknown'];
407 if (!empty($parts[2])) {
408 if ($parts[2] == 'ci') {
409 $descr .= ', ' . $GLOBALS['strCaseInsensitive'];
410 } elseif ($parts[2] == 'cs') {
411 $descr .= ', ' . $GLOBALS['strCaseSensitive'];
415 $collation_cache[$collation] = $descr;
416 return $descr;