/home/mjc1/public_html/db_admin/libraries/mysql_charsets.lib.php


1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
<?php
/* $Id: mysql_charsets.lib.php,v 2.23 2004/09/21 11:00:43 rabus Exp $ */
// vim: expandtab sw=4 ts=4 sts=4:

if (PMA_MYSQL_INT_VERSION >= 40100){

    
$res PMA_DBI_query('SHOW CHARACTER SET;');

    
$mysql_charsets = array();
    while (
$row PMA_DBI_fetch_assoc($res)) {
        
$mysql_charsets[] = $row['Charset'];
        
$mysql_charsets_maxlen[$row['Charset']] = $row['Maxlen'];
        
$mysql_charsets_descriptions[$row['Charset']] = $row['Description'];
    }
    @
PMA_DBI_free_result($res);
    unset(
$res$row);

    
$res PMA_DBI_query('SHOW COLLATION;');

    
$mysql_charsets_count count($mysql_charsets);
    
sort($mysql_charsetsSORT_STRING);

    
$mysql_collations array_flip($mysql_charsets);
    
$mysql_default_collations $mysql_collations_flat = array();;
    while (
$row PMA_DBI_fetch_assoc($res)) {
        if (!
is_array($mysql_collations[$row['Charset']])) {
            
$mysql_collations[$row['Charset']] = array($row['Collation']);
        } else {
            
$mysql_collations[$row['Charset']][] = $row['Collation'];
        }
        
$mysql_collations_flat[] = $row['Collation'];
        if ((isset(
$row['D']) && $row['D'] == 'Y') || (isset($row['Default']) && $row['Default'] == 'Yes')) {
            
$mysql_default_collations[$row['Charset']] = $row['Collation'];
        }
    }

    
$mysql_collations_count count($mysql_collations_flat);
    
sort($mysql_collations_flatSORT_STRING);
    foreach (
$mysql_collations AS $key => $value) {
        
sort($mysql_collations[$key], SORT_STRING);
        
reset($mysql_collations[$key]);
    }

    @
PMA_DBI_free_result($res);
    unset(
$res$row);

    function 
PMA_getCollationDescr($collation) {
        if (
$collation == 'binary') {
            return 
$GLOBALS['strBinary'];
        }
        
$parts explode('_'$collation);
        if (
count($parts) == 1) {
            
$parts[1] = 'general';
        } elseif (
$parts[1] == 'ci' || $parts[1] == 'cs') {
            
$parts[2] = $parts[1];
            
$parts[1] = 'general';
        }
        
$descr '';
        switch (
$parts[1]) {
            case 
'bulgarian':
                
$descr $GLOBALS['strBulgarian'];
                break;
            case 
'chinese':
                if (
$parts[0] == 'gb2312' || $parts[0] == 'gbk') {
                    
$descr $GLOBALS['strSimplifiedChinese'];
                } elseif (
$parts[0] == 'big5') {
                    
$descr $GLOBALS['strTraditionalChinese'];
                }
                break;
            case 
'ci':
                
$descr $GLOBALS['strCaseInsensitive'];
                break;
            case 
'cs':
                
$descr $GLOBALS['strCaseSensitive'];
                break;
            case 
'croatian':
                
$descr $GLOBALS['strCroatian'];
                break;
            case 
'czech':
                
$descr $GLOBALS['strCzech'];
                break;
            case 
'danish':
                
$descr $GLOBALS['strDanish'];
                break;
            case 
'english':
                
$descr $GLOBALS['strEnglish'];
                break;
            case 
'estonian':
                
$descr $GLOBALS['strEstonian'];
                break;
            case 
'german1':
                
$descr $GLOBALS['strGerman'] . ' (' $GLOBALS['strDictionary'] . ')';
                break;
            case 
'german2':
                
$descr $GLOBALS['strGerman'] . ' (' $GLOBALS['strPhoneBook'] . ')';
                break;
            case 
'hungarian':
                
$descr $GLOBALS['strHungarian'];
                break;
            case 
'icelandic':
                
$descr $GLOBALS['strIcelandic'];
                break;
            case 
'japanese':
                
$descr $GLOBALS['strJapanese'];
                break;
            case 
'latvian':
                
$descr $GLOBALS['strLatvian'];
                break;
            case 
'lithuanian':
                
$descr $GLOBALS['strLithuanian'];
                break;
            case 
'korean':
                
$descr $GLOBALS['strKorean'];
                break;
            case 
'persian':
                
$descr $GLOBALS['strPersian'];
                break;
            case 
'polish':
                
$descr $GLOBALS['strPolish'];
                break;
            case 
'roman':
                
$descr $GLOBALS['strWestEuropean'];
                break;
            case 
'romanian':
                
$descr $GLOBALS['strRomanian'];
                break;
            case 
'slovak':
                
$descr $GLOBALS['strSlovak'];
                break;
            case 
'slovenian':
                
$descr $GLOBALS['strSlovenian'];
                break;
            case 
'spanish':
                
$descr $GLOBALS['strSpanish'];
                break;
            case 
'spanish2':
                
$descr $GLOBALS['strTraditionalSpanish'];
                break;
            case 
'swedish':
                
$descr $GLOBALS['strSwedish'];
                break;
            case 
'thai':
                
$descr $GLOBALS['strThai'];
                break;
            case 
'turkish':
                
$descr $GLOBALS['strTurkish'];
                break;
            case 
'ukrainian':
                
$descr $GLOBALS['strUkrainian'];
                break;
            case 
'unicode':
                
$descr $GLOBALS['strUnicode'] . ' (' $GLOBALS['strMultilingual'] . ')';
                break;
            case 
'bin':
                
$is_bin TRUE;
            case 
'general':
                switch (
$parts[0]) {
                    
// Unicode charsets
                    
case 'ucs2':
                    case 
'utf8':
                        
$descr $GLOBALS['strUnicode'] . ' (' $GLOBALS['strMultilingual'] . ')';
                        break;
                    
// West European charsets
                    
case 'ascii':
                    case 
'cp850':
                    case 
'dec8':
                    case 
'hp8':
                    case 
'latin1':
                    case 
'macroman':
                        
$descr $GLOBALS['strWestEuropean'] . ' (' $GLOBALS['strMultilingual'] . ')';
                        break;
                    
// Central European charsets
                    
case 'cp1250':
                    case 
'cp852':
                    case 
'latin2':
                    case 
'macce':
                        
$descr $GLOBALS['strCentralEuropean'] . ' (' $GLOBALS['strMultilingual'] . ')';
                        break;
                    
// Russian charsets
                    
case 'cp866':
                    case 
'koi8r':
                        
$descr $GLOBALS['strRussian'];
                        break;
                    
// Simplified Chinese charsets
                    
case 'gb2312':
                    case 
'gbk':
                        
$descr $GLOBALS['strSimplifiedChinese'];
                        break;
                    
// Japanese charsets
                    
case 'sjis':
                    case 
'ujis':
                        
$descr $GLOBALS['strJapanese'];
                        break;
                    
// Baltic charsets
                    
case 'cp1257':
                    case 
'latin7':
                        
$descr $GLOBALS['strBaltic'] . ' (' $GLOBALS['strMultilingual'] . ')';
                        break;
                    
// Other
                    
case 'armscii8':
                    case 
'armscii':
                        
$descr $GLOBALS['strArmenian'];
                        break;
                    case 
'big5':
                        
$descr $GLOBALS['strTraditionalChinese'];
                        break;
                    case 
'cp1251':
                        
$descr $GLOBALS['strCyrillic'] . ' (' $GLOBALS['strMultilingual'] . ')';
                        break;
                    case 
'cp1256':
                        
$descr $GLOBALS['strArabic'];
                        break;
                    case 
'euckr':
                        
$descr $GLOBALS['strKorean'];
                        break;
                    case 
'hebrew':
                        
$descr $GLOBALS['strHebrew'];
                        break;
                    case 
'geostd8':
                        
$descr $GLOBALS['strGeorgian'];
                        break;
                    case 
'greek':
                        
$descr $GLOBALS['strGreek'];
                        break;
                    case 
'keybcs2':
                        
$descr $GLOBALS['strCzechSlovak'];
                        break;
                    case 
'koi8u':
                        
$descr $GLOBALS['strUkrainian'];
                        break;
                    case 
'latin5':
                        
$descr $GLOBALS['strTurkish'];
                        break;
                    case 
'swe7':
                        
$descr $GLOBALS['strSwedish'];
                        break;
                    case 
'tis620':
                        
$descr $GLOBALS['strThai'];
                        break;
                    default:
                        
$descr $GLOBALS['strUnknown'];
                        break;
                }
                if (!empty(
$is_bin)) {
                    
$descr .= ', ' $GLOBALS['strBinary'];
                }
                break;
            default: 
$descr $GLOBALS['strUnknown'];
        }
        if (!empty(
$parts[2])) {
            if (
$parts[2] == 'ci') {
                
$descr .= ', ' $GLOBALS['strCaseInsensitive'];
            } elseif (
$parts[2] == 'cs') {
                
$descr .= ', ' $GLOBALS['strCaseSensitive'];
            }
        }
        return 
$descr;
    }

    function 
PMA_getDbCollation($db) {
        global 
$userlink;
        if (
PMA_MYSQL_INT_VERSION >= 40101) {
            
// MySQL 4.1.0 does not support seperate charset settings
            // for databases.
            
$res PMA_DBI_query('SHOW CREATE DATABASE ' PMA_backquote($db) . ';'NULLPMA_DBI_QUERY_STORE);
            
$row PMA_DBI_fetch_row($res);
            
PMA_DBI_free_result($res);
            
$tokenized explode(' '$row[1]);
            unset(
$row$res$sql_query);

            for (
$i 1$i count($tokenized); $i++) {
                if (
$tokenized[$i] == 'DEFAULT' && $tokenized[$i 1] == 'CHARACTER' && $tokenized[$i 2] == 'SET') {
                    
// We've found the character set!
                    
if (isset($tokenized[$i 5]) && $tokenized[$i 4] == 'COLLATE') {
                        return 
$tokenized[$i 5]; // We found the collation!
                    
} else {
                        
// We did not find the collation, so let's return the
                        // default collation for the charset we've found.
                        
return $GLOBALS['mysql_default_collations'][$tokenized [$i 3]];
                    }
                }
            }
        }
        return 
'';
    }

    
define('PMA_CSDROPDOWN_COLLATION'0);
    
define('PMA_CSDROPDOWN_CHARSET',   1);
    
    function 
PMA_generateCharsetDropdownBox($type PMA_CSDROPDOWN_COLLATION$name NULL$id NULL$default NULL$label TRUE$indent 0$submitOnChange FALSE) {
        global 
$mysql_charsets$mysql_charsets_descriptions$mysql_collations;

        if (empty(
$name)) {
            if (
$type == PMA_CSDROPDOWN_COLLATION) {
                
$name 'collation';
            } else {
                
$name 'character_set';
            }
        }

        
$spacer '';
        for (
$i 1$i <= $indent$i++) $spacer .= '    ';

        
$return_str  $spacer '<select name="' htmlspecialchars($name) . '"' . (empty($id) ? '' ' id="' htmlspecialchars($id) . '"') . ($submitOnChange ' onchange="this.form.submit();"' '') . '>' "\n";
        if (
$label) {
            
$return_str .= $spacer '    <option value="">' . ($type == PMA_CSDROPDOWN_COLLATION $GLOBALS['strCollation'] : $GLOBALS['strCharset']) . '</option>' "\n";
        }
        
$return_str .= $spacer '    <option value=""></option>' "\n";
        foreach (
$mysql_charsets as $current_charset) {
            
$current_cs_descr = empty($mysql_charsets_descriptions[$current_charset]) ? $current_charset $mysql_charsets_descriptions[$current_charset];
            if (
$type == PMA_CSDROPDOWN_COLLATION) {
                
$return_str .= $spacer '    <optgroup label="' $current_charset '" title="' $current_cs_descr '">' "\n";
                foreach (
$mysql_collations[$current_charset] as $current_collation) {
                    
$return_str .= $spacer '        <option value="' $current_collation '" title="' PMA_getCollationDescr($current_collation) . '"' . ($default == $current_collation ' selected="selected"' '') . '>' $current_collation '</option>' "\n";
                }
                
$return_str .= $spacer '    </optgroup>' "\n";
            } else {
                
$return_str .= $spacer '    <option value="' $current_charset '" title="' $current_cs_descr '"' . ($default == $current_charset ' selected="selected"' '') . '>' $current_charset '</option>' "\n";
            }
        }
        
$return_str .= $spacer '</select>' "\n";

        return 
$return_str;
    }

    function 
PMA_generateCharsetQueryPart($collation) {
        list(
$charset) = explode('_'$collation);
        return 
' CHARACTER SET ' $charset . ($charset == $collation '' ' COLLATE ' $collation);
    }

}

?>