| [ Index ] |
|
Code source de phpMyAdmin 2.10.3 |
1 <?php 2 /* $Id: mysql_charsets.lib.php 9264 2006-08-09 18:11:13Z lem9 $ */ 3 // vim: expandtab sw=4 ts=4 sts=4: 4 5 if (PMA_MYSQL_INT_VERSION >= 40100){ 6 7 $res = PMA_DBI_query('SHOW CHARACTER SET;'); 8 9 $mysql_charsets = array(); 10 while ($row = PMA_DBI_fetch_assoc($res)) { 11 $mysql_charsets[] = $row['Charset']; 12 // never used 13 //$mysql_charsets_maxlen[$row['Charset']] = $row['Maxlen']; 14 $mysql_charsets_descriptions[$row['Charset']] = $row['Description']; 15 } 16 @PMA_DBI_free_result( $res ); 17 18 $mysql_charsets_count = count($mysql_charsets); 19 sort($mysql_charsets, SORT_STRING); 20 21 $mysql_collations = array_flip($mysql_charsets); 22 $mysql_default_collations = $mysql_collations_flat = $mysql_charsets_available = $mysql_collations_available = array(); 23 24 $res = PMA_DBI_query('SHOW COLLATION;'); 25 while ($row = PMA_DBI_fetch_assoc($res)) { 26 if (!is_array($mysql_collations[$row['Charset']])) { 27 $mysql_collations[$row['Charset']] = array($row['Collation']); 28 } else { 29 $mysql_collations[$row['Charset']][] = $row['Collation']; 30 } 31 $mysql_collations_flat[] = $row['Collation']; 32 if ((isset($row['D']) && $row['D'] == 'Y') || (isset($row['Default']) && $row['Default'] == 'Yes')) { 33 $mysql_default_collations[$row['Charset']] = $row['Collation']; 34 } 35 //$mysql_collations_available[$row['Collation']] = !isset($row['Compiled']) || $row['Compiled'] == 'Yes'; 36 $mysql_collations_available[$row['Collation']] = TRUE; 37 $mysql_charsets_available[$row['Charset']] = !empty($mysql_charsets_available[$row['Charset']]) || !empty($mysql_collations_available[$row['Collation']]); 38 } 39 @PMA_DBI_free_result( $res ); 40 unset( $res, $row ); 41 42 $mysql_collations_count = count($mysql_collations_flat); 43 sort($mysql_collations_flat, SORT_STRING); 44 foreach ($mysql_collations AS $key => $value) { 45 sort($mysql_collations[$key], SORT_STRING); 46 reset($mysql_collations[$key]); 47 } 48 unset( $key, $value ); 49 50 define('PMA_CSDROPDOWN_COLLATION', 0); 51 define('PMA_CSDROPDOWN_CHARSET', 1); 52 53 function PMA_generateCharsetDropdownBox($type = PMA_CSDROPDOWN_COLLATION, $name = null, $id = null, $default = null, $label = TRUE, $indent = 0, $submitOnChange = FALSE, $displayUnavailable = FALSE) { 54 global $mysql_charsets, $mysql_charsets_descriptions, $mysql_charsets_available, $mysql_collations, $mysql_collations_available; 55 56 if (empty($name)) { 57 if ($type == PMA_CSDROPDOWN_COLLATION) { 58 $name = 'collation'; 59 } else { 60 $name = 'character_set'; 61 } 62 } 63 64 $spacer = ''; 65 for ($i = 1; $i <= $indent; $i++) $spacer .= ' '; 66 67 $return_str = $spacer . '<select xml:lang="en" dir="ltr" name="' . htmlspecialchars($name) . '"' . (empty($id) ? '' : ' id="' . htmlspecialchars($id) . '"') . ($submitOnChange ? ' onchange="this.form.submit();"' : '') . '>' . "\n"; 68 if ($label) { 69 $return_str .= $spacer . ' <option value="">' . ($type == PMA_CSDROPDOWN_COLLATION ? $GLOBALS['strCollation'] : $GLOBALS['strCharset']) . '</option>' . "\n"; 70 } 71 $return_str .= $spacer . ' <option value=""></option>' . "\n"; 72 foreach ($mysql_charsets as $current_charset) { 73 if (!$mysql_charsets_available[$current_charset]) { 74 continue; 75 } 76 $current_cs_descr = empty($mysql_charsets_descriptions[$current_charset]) ? $current_charset : $mysql_charsets_descriptions[$current_charset]; 77 if ($type == PMA_CSDROPDOWN_COLLATION) { 78 $return_str .= $spacer . ' <optgroup label="' . $current_charset . '" title="' . $current_cs_descr . '">' . "\n"; 79 foreach ($mysql_collations[$current_charset] as $current_collation) { 80 if (!$mysql_collations_available[$current_collation]) { 81 continue; 82 } 83 $return_str .= $spacer . ' <option value="' . $current_collation . '" title="' . PMA_getCollationDescr($current_collation) . '"' . ($default == $current_collation ? ' selected="selected"' : '') . '>' . $current_collation . '</option>' . "\n"; 84 } 85 $return_str .= $spacer . ' </optgroup>' . "\n"; 86 } else { 87 $return_str .= $spacer . ' <option value="' . $current_charset . '" title="' . $current_cs_descr . '"' . ($default == $current_charset ? ' selected="selected"' : '') . '>' . $current_charset . '</option>' . "\n"; 88 } 89 } 90 $return_str .= $spacer . '</select>' . "\n"; 91 92 return $return_str; 93 } 94 95 function PMA_generateCharsetQueryPart($collation) { 96 list($charset) = explode('_', $collation); 97 return ' CHARACTER SET ' . $charset . ($charset == $collation ? '' : ' COLLATE ' . $collation); 98 } 99 100 /** 101 * returns collation of given db 102 * 103 * @uses PMA_MYSQL_INT_VERSION 104 * @uses PMA_DBI_fetch_value() 105 * @uses PMA_DBI_select_db() 106 * @uses PMA_sqlAddSlashes() 107 * @uses $GLOBALS['db'] 108 * @param string $db name of db 109 * @return string collation of $db 110 */ 111 function PMA_getDbCollation( $db ) { 112 if ( PMA_MYSQL_INT_VERSION >= 50000 && $db == 'information_schema' ) { 113 // We don't have to check the collation of the virtual 114 // information_schema database: We know it! 115 return 'utf8_general_ci'; 116 } 117 if ( PMA_MYSQL_INT_VERSION >= 50006 ) { 118 // Since MySQL 5.0.6, we don't have to parse SHOW CREATE DATABASE anymore. 119 return PMA_DBI_fetch_value('SELECT DEFAULT_COLLATION_NAME FROM information_schema.SCHEMATA WHERE SCHEMA_NAME = \'' . PMA_sqlAddSlashes($db) . '\' LIMIT 1;'); 120 } elseif ( PMA_MYSQL_INT_VERSION >= 40101 ) { 121 // MySQL 4.1.0 does not support seperate charset settings 122 // for databases. 123 PMA_DBI_select_db( $db ); 124 // the query does not work if this string is in double quotes 125 // and MySQL is running in ANSI mode 126 $return = PMA_DBI_fetch_value( 'SHOW VARIABLES LIKE \'collation_database\'', 0, 1 ); 127 if ( isset( $GLOBALS['db'] ) && $db !== $GLOBALS['db'] ) { 128 PMA_DBI_select_db( $GLOBALS['db'] ); 129 } 130 return $return; 131 } 132 return ''; 133 } 134 135 } else { 136 function PMA_getDbCollation( $db ) { return PMA_getServerCollation(); } 137 } 138 139 /** 140 * returns default server collation from show variables 141 * 142 * @uses PMA_DBI_fetch_value() 143 * @return string $server_collation 144 */ 145 function PMA_getServerCollation() { 146 return PMA_DBI_fetch_value( 147 'SHOW VARIABLES LIKE \'collation_server\'', 0, 1 ); 148 } 149 150 /** 151 * returns description for given collation 152 * 153 * @uses is_array() 154 * @uses explode() 155 * @uses count() 156 * @uses $GLOBALS['str[Languages|Sorting]'] 157 * 158 * @param string $collation MySQL collation string 159 * @return string collation description 160 */ 161 function PMA_getCollationDescr( $collation ) { 162 static $collation_cache; 163 164 if (!is_array($collation_cache)) { 165 $collation_cache = array(); 166 } elseif (isset($collation_cache[$collation])) { 167 return $collation_cache[$collation]; 168 } 169 170 if ($collation == 'binary') { 171 return $GLOBALS['strBinary']; 172 } 173 $parts = explode('_', $collation); 174 if (count($parts) == 1) { 175 $parts[1] = 'general'; 176 } elseif ($parts[1] == 'ci' || $parts[1] == 'cs') { 177 $parts[2] = $parts[1]; 178 $parts[1] = 'general'; 179 } 180 $descr = ''; 181 switch ($parts[1]) { 182 case 'bulgarian': 183 $descr = $GLOBALS['strBulgarian']; 184 break; 185 case 'chinese': 186 if ($parts[0] == 'gb2312' || $parts[0] == 'gbk') { 187 $descr = $GLOBALS['strSimplifiedChinese']; 188 } elseif ($parts[0] == 'big5') { 189 $descr = $GLOBALS['strTraditionalChinese']; 190 } 191 break; 192 case 'ci': 193 $descr = $GLOBALS['strCaseInsensitive']; 194 break; 195 case 'cs': 196 $descr = $GLOBALS['strCaseSensitive']; 197 break; 198 case 'croatian': 199 $descr = $GLOBALS['strCroatian']; 200 break; 201 case 'czech': 202 $descr = $GLOBALS['strCzech']; 203 break; 204 case 'danish': 205 $descr = $GLOBALS['strDanish']; 206 break; 207 case 'english': 208 $descr = $GLOBALS['strEnglish']; 209 break; 210 case 'esperanto': 211 $descr = $GLOBALS['strEsperanto']; 212 break; 213 case 'estonian': 214 $descr = $GLOBALS['strEstonian']; 215 break; 216 case 'german1': 217 $descr = $GLOBALS['strGerman'] . ' (' . $GLOBALS['strDictionary'] . ')'; 218 break; 219 case 'german2': 220 $descr = $GLOBALS['strGerman'] . ' (' . $GLOBALS['strPhoneBook'] . ')'; 221 break; 222 case 'hungarian': 223 $descr = $GLOBALS['strHungarian']; 224 break; 225 case 'icelandic': 226 $descr = $GLOBALS['strIcelandic']; 227 break; 228 case 'japanese': 229 $descr = $GLOBALS['strJapanese']; 230 break; 231 case 'latvian': 232 $descr = $GLOBALS['strLatvian']; 233 break; 234 case 'lithuanian': 235 $descr = $GLOBALS['strLithuanian']; 236 break; 237 case 'korean': 238 $descr = $GLOBALS['strKorean']; 239 break; 240 case 'persian': 241 $descr = $GLOBALS['strPersian']; 242 break; 243 case 'polish': 244 $descr = $GLOBALS['strPolish']; 245 break; 246 case 'roman': 247 $descr = $GLOBALS['strWestEuropean']; 248 break; 249 case 'romanian': 250 $descr = $GLOBALS['strRomanian']; 251 break; 252 case 'slovak': 253 $descr = $GLOBALS['strSlovak']; 254 break; 255 case 'slovenian': 256 $descr = $GLOBALS['strSlovenian']; 257 break; 258 case 'spanish': 259 $descr = $GLOBALS['strSpanish']; 260 break; 261 case 'spanish2': 262 $descr = $GLOBALS['strTraditionalSpanish']; 263 break; 264 case 'swedish': 265 $descr = $GLOBALS['strSwedish']; 266 break; 267 case 'thai': 268 $descr = $GLOBALS['strThai']; 269 break; 270 case 'turkish': 271 $descr = $GLOBALS['strTurkish']; 272 break; 273 case 'ukrainian': 274 $descr = $GLOBALS['strUkrainian']; 275 break; 276 case 'unicode': 277 $descr = $GLOBALS['strUnicode'] . ' (' . $GLOBALS['strMultilingual'] . ')'; 278 break; 279 case 'bin': 280 $is_bin = TRUE; 281 case 'general': 282 switch ($parts[0]) { 283 // Unicode charsets 284 case 'ucs2': 285 case 'utf8': 286 $descr = $GLOBALS['strUnicode'] . ' (' . $GLOBALS['strMultilingual'] . ')'; 287 break; 288 // West European charsets 289 case 'ascii': 290 case 'cp850': 291 case 'dec8': 292 case 'hp8': 293 case 'latin1': 294 case 'macroman': 295 $descr = $GLOBALS['strWestEuropean'] . ' (' . $GLOBALS['strMultilingual'] . ')'; 296 break; 297 // Central European charsets 298 case 'cp1250': 299 case 'cp852': 300 case 'latin2': 301 case 'macce': 302 $descr = $GLOBALS['strCentralEuropean'] . ' (' . $GLOBALS['strMultilingual'] . ')'; 303 break; 304 // Russian charsets 305 case 'cp866': 306 case 'koi8r': 307 $descr = $GLOBALS['strRussian']; 308 break; 309 // Simplified Chinese charsets 310 case 'gb2312': 311 case 'gbk': 312 $descr = $GLOBALS['strSimplifiedChinese']; 313 break; 314 // Japanese charsets 315 case 'sjis': 316 case 'ujis': 317 case 'cp932': 318 case 'eucjpms': 319 $descr = $GLOBALS['strJapanese']; 320 break; 321 // Baltic charsets 322 case 'cp1257': 323 case 'latin7': 324 $descr = $GLOBALS['strBaltic'] . ' (' . $GLOBALS['strMultilingual'] . ')'; 325 break; 326 // Other 327 case 'armscii8': 328 case 'armscii': 329 $descr = $GLOBALS['strArmenian']; 330 break; 331 case 'big5': 332 $descr = $GLOBALS['strTraditionalChinese']; 333 break; 334 case 'cp1251': 335 $descr = $GLOBALS['strCyrillic'] . ' (' . $GLOBALS['strMultilingual'] . ')'; 336 break; 337 case 'cp1256': 338 $descr = $GLOBALS['strArabic']; 339 break; 340 case 'euckr': 341 $descr = $GLOBALS['strKorean']; 342 break; 343 case 'hebrew': 344 $descr = $GLOBALS['strHebrew']; 345 break; 346 case 'geostd8': 347 $descr = $GLOBALS['strGeorgian']; 348 break; 349 case 'greek': 350 $descr = $GLOBALS['strGreek']; 351 break; 352 case 'keybcs2': 353 $descr = $GLOBALS['strCzechSlovak']; 354 break; 355 case 'koi8u': 356 $descr = $GLOBALS['strUkrainian']; 357 break; 358 case 'latin5': 359 $descr = $GLOBALS['strTurkish']; 360 break; 361 case 'swe7': 362 $descr = $GLOBALS['strSwedish']; 363 break; 364 case 'tis620': 365 $descr = $GLOBALS['strThai']; 366 break; 367 default: 368 $descr = $GLOBALS['strUnknown']; 369 break; 370 } 371 if (!empty($is_bin)) { 372 $descr .= ', ' . $GLOBALS['strBinary']; 373 } 374 break; 375 default: $descr = $GLOBALS['strUnknown']; 376 } 377 if (!empty($parts[2])) { 378 if ($parts[2] == 'ci') { 379 $descr .= ', ' . $GLOBALS['strCaseInsensitive']; 380 } elseif ($parts[2] == 'cs') { 381 $descr .= ', ' . $GLOBALS['strCaseSensitive']; 382 } 383 } 384 385 $collation_cache[$collation] = $descr; 386 return $descr; 387 } 388 ?>
titre
Description
Corps
titre
Description
Corps
titre
Description
Corps
titre
Corps
| Généré le : Mon Nov 26 15:18:20 2007 | par Balluche grâce à PHPXref 0.7 |
|