Merge branch 'master' of git://phpmyadmin.git.sourceforge.net/gitroot/phpmyadmin...
[phpmyadmin/crack.git] / libraries / tbl_properties.inc.php
blobf4ade94bc86cf6b3e1de953c33576f1829965dad
1 <?php
2 /* vim: set expandtab sw=4 ts=4 sts=4: */
3 /**
4 * Display form for changing/adding table fields/columns
6 * included by tbl_addfield.php, -_alter.php, -_create.php
7 * @package phpMyAdmin
8 */
9 if (! defined('PHPMYADMIN')) {
10 exit;
13 /**
14 * Check parameters
16 require_once './libraries/common.inc.php';
17 require_once './libraries/common.lib.php';
18 PMA_checkParameters(array('db', 'table', 'action', 'num_fields'));
21 // Get available character sets and storage engines
22 require_once './libraries/mysql_charsets.lib.php';
23 require_once './libraries/StorageEngine.class.php';
25 /**
26 * Class for partition management
28 require_once './libraries/Partition.class.php';
30 // load additional configuration variables
31 require_once './libraries/data_mysql.inc.php';
33 if (is_int($cfg['DefaultPropDisplay'])) {
34 if ($num_fields <= $cfg['DefaultPropDisplay']) {
35 $display_type = 'vertical';
36 } else {
37 $display_type = 'horizontal';
39 } else {
40 $display_type = $cfg['DefaultPropDisplay'];
43 if ('horizontal' == $display_type) {
44 $length_values_input_size = 8;
45 } else {
46 $length_values_input_size = 30;
49 $_form_params = array(
50 'db' => $db,
53 if ($action == 'tbl_create.php') {
54 $_form_params['reload'] = 1;
55 } elseif ($action == 'tbl_addfield.php') {
56 $_form_params['field_where'] = $_REQUEST['field_where'];
57 $_form_params['after_field'] = $_REQUEST['after_field'];
58 $_form_params['table'] = $table;
59 } else {
60 $_form_params['table'] = $table;
63 if (isset($num_fields)) {
64 $_form_params['orig_num_fields'] = $num_fields;
67 if (isset($_REQUEST['field_where'])) {
68 $_form_params['orig_field_where'] = $_REQUEST['field_where'];
71 if (isset($_REQUEST['after_field'])) {
72 $_form_params['orig_after_field'] = $_REQUEST['after_field'];
75 if (isset($selected) && is_array($selected)) {
76 foreach ($selected as $o_fld_nr => $o_fld_val) {
77 $_form_params['selected[' . $o_fld_nr . ']'] = $o_fld_val;
78 if (! isset($true_selected)) {
79 $_form_params['true_selected[' . $o_fld_nr . ']'] = $o_fld_val;
83 if (isset($true_selected) && is_array($true_selected)) {
84 foreach ($true_selected as $o_fld_nr => $o_fld_val) {
85 $_form_params['true_selected[' . $o_fld_nr . ']'] = $o_fld_val;
88 } elseif (isset($_REQUEST['field'])) {
89 $_form_params['orig_field'] = $_REQUEST['field'];
90 if (isset($orig_field)) {
91 $_form_params['true_selected[]'] = $orig_field;
92 } else {
93 $_form_params['true_selected[]'] = $_REQUEST['field'];
97 $is_backup = ($action != 'tbl_create.php' && $action != 'tbl_addfield.php');
99 $header_cells = array();
100 $content_cells = array();
102 $header_cells[] = __('Name');
103 $header_cells[] = __('Type')
104 . ($GLOBALS['cfg']['ReplaceHelpImg']
105 ? PMA_showMySQLDocu('SQL-Syntax', 'data-types')
106 : '<br /><span style="font-weight: normal">' . PMA_showMySQLDocu('SQL-Syntax', 'data-types')
107 . '</span>');
108 $header_cells[] = __('Length/Values') . PMA_showHint(__('If column type is "enum" or "set", please enter the values using this format: \'a\',\'b\',\'c\'...<br />If you ever need to put a backslash ("\") or a single quote ("\'") amongst those values, precede it with a backslash (for example \'\\\\xyz\' or \'a\\\'b\').'));
109 $header_cells[] = __('Default') . PMA_showHint(__('For default values, please enter just a single value, without backslash escaping or quotes, using this format: a'));
110 $header_cells[] = __('Collation');
111 $header_cells[] = __('Attributes');
112 $header_cells[] = __('Null');
114 // We could remove this 'if' and let the key information be shown and
115 // editable. However, for this to work, tbl_alter must be modified to use the
116 // key fields, as tbl_addfield does.
118 if (!$is_backup) {
119 $header_cells[] = __('Index');
122 $header_cells[] = '<abbr title="AUTO_INCREMENT">' . ($display_type == 'horizontal' ? 'A_I' : 'AUTO_INCREMENT') . '</abbr>';
124 require_once './libraries/transformations.lib.php';
125 $cfgRelation = PMA_getRelationsParam();
127 $comments_map = array();
128 $mime_map = array();
129 $available_mime = array();
131 $comments_map = PMA_getComments($db, $table);
132 $header_cells[] = __('Comments');
134 if ($cfgRelation['mimework'] && $cfg['BrowseMIME']) {
135 $mime_map = PMA_getMIME($db, $table);
136 $available_mime = PMA_getAvailableMIMEtypes();
138 $hint = '<br />' .
139 sprintf(__('For a list of available transformation options and their MIME type transformations, click on %stransformation descriptions%s'),
140 '<a href="transformation_overview.php?'
141 . PMA_generate_common_url($db, $table) . '" target="_blank">',
142 '</a>');
145 $header_cells[] = __('MIME type');
146 $header_cells[] = __('Browser transformation');
147 $header_cells[] = __('Transformation options')
148 . PMA_showHint(__('Please enter the values for transformation options using this format: \'a\', 100, b,\'c\'...<br />If you ever need to put a backslash ("\") or a single quote ("\'") amongst those values, precede it with a backslash (for example \'\\\\xyz\' or \'a\\\'b\').') . $hint);
151 // workaround for field_fulltext, because its submitted indizes contain
152 // the index as a value, not a key. Inserted here for easier maintaineance
153 // and less code to change in existing files.
154 if (isset($field_fulltext) && is_array($field_fulltext)) {
155 foreach ($field_fulltext as $fulltext_nr => $fulltext_indexkey) {
156 $submit_fulltext[$fulltext_indexkey] = $fulltext_indexkey;
160 for ($i = 0; $i < $num_fields; $i++) {
161 if (! empty($regenerate)) {
162 // An error happened with previous inputs, so we will restore the data
163 // to embed it once again in this form.
165 $row['Field'] = (isset($_REQUEST['field_name'][$i]) ? $_REQUEST['field_name'][$i] : false);
166 $row['Type'] = (isset($_REQUEST['field_type'][$i]) ? $_REQUEST['field_type'][$i] : false);
167 $row['Collation'] = (isset($_REQUEST['field_collation'][$i]) ? $_REQUEST['field_collation'][$i] : '');
168 $row['Null'] = (isset($_REQUEST['field_null'][$i]) ? $_REQUEST['field_null'][$i] : '');
170 if (isset($_REQUEST['field_key'][$i]) && $_REQUEST['field_key'][$i] == 'primary_' . $i) {
171 $row['Key'] = 'PRI';
172 } elseif (isset($_REQUEST['field_key'][$i]) && $_REQUEST['field_key'][$i] == 'index_' . $i) {
173 $row['Key'] = 'MUL';
174 } elseif (isset($_REQUEST['field_key'][$i]) && $_REQUEST['field_key'][$i] == 'unique_' . $i) {
175 $row['Key'] = 'UNI';
176 } elseif (isset($_REQUEST['field_key'][$i]) && $_REQUEST['field_key'][$i] == 'fulltext_' . $i) {
177 $row['Key'] = 'FULLTEXT';
178 } else {
179 $row['Key'] = '';
182 // put None in the drop-down for Default, when someone adds a field
183 $row['DefaultType'] = (isset($_REQUEST['field_default_type'][$i]) ? $_REQUEST['field_default_type'][$i] : 'NONE');
184 $row['DefaultValue'] = (isset($_REQUEST['field_default_value'][$i]) ? $_REQUEST['field_default_value'][$i] : '');
186 switch ($row['DefaultType']) {
187 case 'NONE' :
188 $row['Default'] = null;
189 break;
190 case 'USER_DEFINED' :
191 $row['Default'] = $row['DefaultValue'];
192 break;
193 case 'NULL' :
194 case 'CURRENT_TIMESTAMP' :
195 $row['Default'] = $row['DefaultType'];
196 break;
199 $row['Extra'] = (isset($_REQUEST['field_extra'][$i]) ? $_REQUEST['field_extra'][$i] : false);
200 $row['Comment'] = (isset($submit_fulltext[$i]) && ($submit_fulltext[$i] == $i) ? 'FULLTEXT' : false);
202 $submit_length = (isset($_REQUEST['field_length'][$i]) ? $_REQUEST['field_length'][$i] : false);
203 $submit_attribute = (isset($_REQUEST['field_attribute'][$i]) ? $_REQUEST['field_attribute'][$i] : false);
205 $submit_default_current_timestamp = (isset($_REQUEST['field_default_current_timestamp'][$i]) ? true : false);
207 if (isset($_REQUEST['field_comments'][$i])) {
208 $comments_map[$row['Field']] = $_REQUEST['field_comments'][$i];
211 if (isset($_REQUEST['field_mimetype'][$i])) {
212 $mime_map[$row['Field']]['mimetype'] = $_REQUEST['field_mimetype'][$i];
215 if (isset($_REQUEST['field_transformation'][$i])) {
216 $mime_map[$row['Field']]['transformation'] = $_REQUEST['field_transformation'][$i];
219 if (isset($_REQUEST['field_transformation_options'][$i])) {
220 $mime_map[$row['Field']]['transformation_options'] = $_REQUEST['field_transformation_options'][$i];
223 } elseif (isset($fields_meta[$i])) {
224 $row = $fields_meta[$i];
225 switch ($row['Default']) {
226 case null:
227 if ($row['Null'] == 'YES') {
228 $row['DefaultType'] = 'NULL';
229 $row['DefaultValue'] = '';
230 // SHOW FULL FIELDS does not report the case when there is a DEFAULT value
231 // which is empty so we need to use the results of SHOW CREATE TABLE
232 } elseif (isset($row) && isset($analyzed_sql[0]['create_table_fields'][$row['Field']]['default_value'])) {
233 $row['DefaultType'] = 'USER_DEFINED';
234 $row['DefaultValue'] = $row['Default'];
235 } else {
236 $row['DefaultType'] = 'NONE';
237 $row['DefaultValue'] = '';
239 break;
240 case 'CURRENT_TIMESTAMP':
241 $row['DefaultType'] = 'CURRENT_TIMESTAMP';
242 $row['DefaultValue'] = '';
243 break;
244 default:
245 $row['DefaultType'] = 'USER_DEFINED';
246 $row['DefaultValue'] = $row['Default'];
247 break;
251 if (isset($row['Type'])) {
252 $extracted_fieldspec = PMA_extractFieldSpec($row['Type']);
253 if ($extracted_fieldspec['type'] == 'bit') {
254 $row['Default'] = PMA_convert_bit_default_value($row['Default']);
257 // Cell index: If certain fields get left out, the counter shouldn't change.
258 $ci = 0;
259 // Everytime a cell shall be left out the STRG-jumping feature, $ci_offset
260 // has to be incremented ($ci_offset++)
261 $ci_offset = -1;
263 // old column name
264 if ($is_backup) {
265 if (! empty($true_selected[$i])) {
266 $_form_params['field_orig[' . $i . ']'] = $true_selected[$i];
267 } elseif (isset($row['Field'])) {
268 $_form_params['field_orig[' . $i . ']'] = $row['Field'];
269 } else {
270 $_form_params['field_orig[' . $i . ']'] = '';
274 // column name
275 $content_cells[$i][$ci] = '<input id="field_' . $i . '_' . ($ci - $ci_offset) . '"'
276 . ' type="text" name="field_name[' . $i . ']"'
277 . ' maxlength="64" class="textfield" title="' . __('Column') . '"'
278 . ' size="' . ($GLOBALS['cfg']['DefaultPropDisplay'] == 'horizontal' ? '10' : '30') . '"'
279 . ' value="' . (isset($row['Field']) ? htmlspecialchars($row['Field']) : '') . '"'
280 . ' />';
281 $ci++;
283 // column type
284 $select_id = 'field_' . $i . '_' . ($ci - $ci_offset);
285 $content_cells[$i][$ci] = '<select class="column_type" name="field_type[' . $i . ']"'
286 .' id="' . $select_id . '">';
288 if (empty($row['Type'])) {
289 // creating a column
290 $row['Type'] = '';
291 $type = '';
292 } else {
293 $type = $row['Type'];
296 if (! empty($row['Type'])) {
297 $type = $extracted_fieldspec['type'];
298 if ('set' == $extracted_fieldspec['type'] || 'enum' == $extracted_fieldspec['type']) {
299 $length = $extracted_fieldspec['spec_in_brackets'];
300 } else {
301 // strip the "BINARY" attribute, except if we find "BINARY(" because
302 // this would be a BINARY or VARBINARY field type
303 $type = preg_replace('@BINARY([^\(])@i', '', $type);
304 $type = preg_replace('@ZEROFILL@i', '', $type);
305 $type = preg_replace('@UNSIGNED@i', '', $type);
306 $length = $extracted_fieldspec['spec_in_brackets'];
307 } // end if else
308 } else {
309 // creating a column
310 $length = '';
313 // some types, for example longtext, are reported as
314 // "longtext character set latin7" when their charset and / or collation
315 // differs from the ones of the corresponding database.
316 $tmp = strpos($type, 'character set');
317 if ($tmp) {
318 $type = substr($type, 0, $tmp - 1);
321 if (isset($submit_length) && $submit_length != false) {
322 $length = $submit_length;
325 // rtrim the type, for cases like "float unsigned"
326 $type = rtrim($type);
327 $type_upper = strtoupper($type);
329 $content_cells[$i][$ci] .= PMA_getSupportedDatatypes(true, $type_upper);
330 $content_cells[$i][$ci] .= ' </select>';
331 $ci++;
333 // old column length
334 if ($is_backup) {
335 $_form_params['field_length_orig[' . $i . ']'] = $length;
338 // column length
339 if (isset($extracted_fieldspec) && ('set' == $extracted_fieldspec['type'] || 'enum' == $extracted_fieldspec['type'])) {
340 $binary = 0;
341 $unsigned = 0;
342 $zerofill = 0;
343 } else {
344 $binary = false;
345 $unsigned = stristr($row['Type'], 'unsigned');
346 $zerofill = stristr($row['Type'], 'zerofill');
348 $length_to_display = $length;
350 $content_cells[$i][$ci] = '<input id="field_' . $i . '_' . ($ci - $ci_offset) . '"'
351 . ' type="text" name="field_length[' . $i . ']" size="' . $length_values_input_size . '"'
352 . ' value="' . htmlspecialchars($length_to_display) . '"'
353 . ' class="textfield" />'
354 . '<p class="enum_notice" id="enum_notice_' . $i . '_' . ($ci - $ci_offset) . '">';
355 $content_cells[$i][$ci] .= __('ENUM or SET data too long?')
356 . '<a onclick="return false;" href="enum_editor.php?' . PMA_generate_common_url() . '&amp;values=' . urlencode($length_to_display) . '&amp;field=' . (isset($row['Field']) ? urlencode($row['Field']) : "") . '" class="open_enum_editor" target="_blank"> '
357 . __('Get more editing space') . '</a></p>';
358 $ci++;
360 // column default
362 * having NULL enabled does not implicit having Default with NULL
364 if (isset($row)
365 && ! isset($row['Default']) && isset($row['Null']) && $row['Null'] == 'YES') {
366 $row['Default'] = 'NULL';
370 // old column default
371 if ($is_backup) {
372 $_form_params['field_default_orig[' . $i . ']'] =
373 (isset($row['Default']) ? $row['Default'] : '');
376 // here we put 'NONE' as the default value of drop-down; otherwise
377 // users would have problems if they forget to enter the default
378 // value (example, for an INT)
379 $default_options = array(
380 'NONE' => _pgettext('for default', 'None'),
381 'USER_DEFINED' => __('As defined:'),
382 'NULL' => 'NULL',
383 'CURRENT_TIMESTAMP' => 'CURRENT_TIMESTAMP',
386 // for a TIMESTAMP, do not show the string "CURRENT_TIMESTAMP" as a default value
387 if ($type_upper == 'TIMESTAMP'
388 && ! empty($default_current_timestamp)
389 && isset($row['Default'])) {
390 $row['Default'] = '';
393 if ($type_upper == 'BIT') {
394 $row['DefaultValue'] = PMA_convert_bit_default_value($row['DefaultValue']);
397 $content_cells[$i][$ci] = '<select name="field_default_type[' . $i . ']">';
398 foreach ($default_options as $key => $value) {
399 $content_cells[$i][$ci] .= '<option value="' . $key . '"';
400 // is only set when we go back to edit a field's structure
401 if (isset($row['DefaultType']) && $row['DefaultType'] == $key) {
402 $content_cells[$i][$ci] .= ' selected="selected"';
404 $content_cells[$i][$ci] .= ' >' . $value . '</option>';
406 $content_cells[$i][$ci] .= '</select>';
407 $content_cells[$i][$ci] .= '<br />';
408 $content_cells[$i][$ci] .= '<input id="field_' . $i . '_' . ($ci - $ci_offset) . '"'
409 . ' type="text" name="field_default_value[' . $i . ']" size="12"'
410 . ' value="' . (isset($row['DefaultValue']) ? htmlspecialchars($row['DefaultValue']) : '') . '"'
411 . ' class="textfield" />';
412 $ci++;
414 // column collation
415 $tmp_collation = empty($row['Collation']) ? null : $row['Collation'];
416 $content_cells[$i][$ci] = PMA_generateCharsetDropdownBox(
417 PMA_CSDROPDOWN_COLLATION, 'field_collation[' . $i . ']',
418 'field_' . $i . '_' . ($ci - $ci_offset), $tmp_collation, false);
419 unset($tmp_collation);
420 $ci++;
422 // column attribute
423 $content_cells[$i][$ci] = '<select style="font-size: 70%;"'
424 . ' name="field_attribute[' . $i . ']"'
425 . ' id="field_' . $i . '_' . ($ci - $ci_offset) . '">';
427 $attribute = '';
428 if ($binary) {
429 $attribute = 'BINARY';
431 if ($unsigned) {
432 $attribute = 'UNSIGNED';
434 if ($zerofill) {
435 $attribute = 'UNSIGNED ZEROFILL';
437 if (isset($row['Extra']) && $row['Extra'] == 'on update CURRENT_TIMESTAMP') {
438 $attribute = 'on update CURRENT_TIMESTAMP';
441 if (isset($submit_attribute) && $submit_attribute != false) {
442 $attribute = $submit_attribute;
445 // here, we have a TIMESTAMP that SHOW FULL FIELDS reports as having the
446 // NULL attribute, but SHOW CREATE TABLE says the contrary. Believe
447 // the latter.
448 if (PMA_MYSQL_INT_VERSION < 50025
449 && isset($row['Field'])
450 && isset($analyzed_sql[0]['create_table_fields'][$row['Field']]['type'])
451 && $analyzed_sql[0]['create_table_fields'][$row['Field']]['type'] == 'TIMESTAMP'
452 && $analyzed_sql[0]['create_table_fields'][$row['Field']]['timestamp_not_null'] == true) {
453 $row['Null'] = '';
456 // MySQL 4.1.2+ TIMESTAMP options
457 // (if on_update_current_timestamp is set, then it's TRUE)
458 if (isset($row['Field'])
459 && isset($analyzed_sql[0]['create_table_fields'][$row['Field']]['on_update_current_timestamp'])) {
460 $attribute = 'on update CURRENT_TIMESTAMP';
462 if ((isset($row['Field'])
463 && isset($analyzed_sql[0]['create_table_fields'][$row['Field']]['default_current_timestamp']))
464 || (isset($submit_default_current_timestamp) && $submit_default_current_timestamp)) {
465 $default_current_timestamp = true;
466 } else {
467 $default_current_timestamp = false;
470 $cnt_attribute_types = count($cfg['AttributeTypes']);
471 for ($j = 0; $j < $cnt_attribute_types; $j++) {
472 $content_cells[$i][$ci] .= ' <option value="'. $cfg['AttributeTypes'][$j] . '"';
473 if (strtoupper($attribute) == strtoupper($cfg['AttributeTypes'][$j])) {
474 $content_cells[$i][$ci] .= ' selected="selected"';
476 $content_cells[$i][$ci] .= '>' . $cfg['AttributeTypes'][$j] . '</option>';
479 $content_cells[$i][$ci] .= '</select>';
480 $ci++;
482 // column NULL
483 $content_cells[$i][$ci] = '<input name="field_null[' . $i . ']"'
484 . ' id="field_' . $i . '_' . ($ci - $ci_offset) . '"';
486 if (! empty($row['Null']) && $row['Null'] != 'NO' && $row['Null'] != 'NOT NULL') {
487 $content_cells[$i][$ci] .= ' checked="checked"';
490 $content_cells[$i][$ci] .= ' type="checkbox" value="NULL" />';
491 $ci++;
493 // column indexes
494 // See my other comment about removing this 'if'.
495 if (!$is_backup) {
496 $content_cells[$i][$ci] = '<select name="field_key[' . $i . ']"'
497 . ' id="field_' . $i . '_' . ($ci - $ci_offset) . '">';
498 $content_cells[$i][$ci] .= '<option value="none_' . $i . '">---</option>';
500 $content_cells[$i][$ci] .= '<option value="primary_' . $i . '" title="' . __('Primary') . '"';
501 if (isset($row['Key']) && $row['Key'] == 'PRI') {
502 $content_cells[$i][$ci] .= ' selected="selected"';
504 $content_cells[$i][$ci] .= '>PRIMARY</option>';
506 $content_cells[$i][$ci] .= '<option value="unique_' . $i . '" title="' . __('Unique') . '"';
507 if (isset($row['Key']) && $row['Key'] == 'UNI') {
508 $content_cells[$i][$ci] .= ' selected="selected"';
510 $content_cells[$i][$ci] .= '>UNIQUE</option>';
512 $content_cells[$i][$ci] .= '<option value="index_' . $i . '" title="' . __('Index') . '"';
513 if (isset($row['Key']) && $row['Key'] == 'MUL') {
514 $content_cells[$i][$ci] .= ' selected="selected"';
516 $content_cells[$i][$ci] .= '>INDEX</option>';
518 $content_cells[$i][$ci] .= '<option value="fulltext_' . $i . '" title="' . __('Fulltext') . '"';
519 if (isset($row['Key']) && $row['Key'] == 'FULLTEXT') {
520 $content_cells[$i][$ci] .= ' selected="selected"';
522 $content_cells[$i][$ci] .= '>FULLTEXT</option>';
524 $content_cells[$i][$ci] .= '</select>';
525 $ci++;
526 } // end if ($action ==...)
528 // column auto_increment
529 $content_cells[$i][$ci] = '<input name="field_extra[' . $i . ']"'
530 . ' id="field_' . $i . '_' . ($ci - $ci_offset) . '"';
532 if (isset($row['Extra']) && strtolower($row['Extra']) == 'auto_increment') {
533 $content_cells[$i][$ci] .= ' checked="checked"';
536 $content_cells[$i][$ci] .= ' type="checkbox" value="AUTO_INCREMENT" />';
537 $ci++;
539 // column comments
540 $content_cells[$i][$ci] = '<input id="field_' . $i . '_' . ($ci - $ci_offset) . '"'
541 . ' type="text" name="field_comments[' . $i . ']" size="12"'
542 . ' value="' . (isset($row['Field']) && is_array($comments_map) && isset($comments_map[$row['Field']]) ? htmlspecialchars($comments_map[$row['Field']]) : '') . '"'
543 . ' class="textfield" />';
544 $ci++;
546 // column MIME-types
547 if ($cfgRelation['mimework'] && $cfg['BrowseMIME'] && $cfgRelation['commwork']) {
548 $content_cells[$i][$ci] = '<select id="field_' . $i . '_' . ($ci - $ci_offset) . '" size="1" name="field_mimetype[' . $i . ']">';
549 $content_cells[$i][$ci] .= ' <option value="">&nbsp;</option>';
551 if (is_array($available_mime['mimetype'])) {
552 foreach ($available_mime['mimetype'] AS $mimekey => $mimetype) {
553 $checked = (isset($row['Field']) && isset($mime_map[$row['Field']]['mimetype']) && ($mime_map[$row['Field']]['mimetype'] == str_replace('/', '_', $mimetype)) ? 'selected ' : '');
554 $content_cells[$i][$ci] .= ' <option value="' . str_replace('/', '_', $mimetype) . '" ' . $checked . '>' . htmlspecialchars($mimetype) . '</option>';
558 $content_cells[$i][$ci] .= '</select>';
559 $ci++;
561 $content_cells[$i][$ci] = '<select id="field_' . $i . '_' . ($ci - $ci_offset) . '" size="1" name="field_transformation[' . $i . ']">';
562 $content_cells[$i][$ci] .= ' <option value="" title="' . __('None') . '"></option>';
563 if (is_array($available_mime['transformation'])) {
564 foreach ($available_mime['transformation'] AS $mimekey => $transform) {
565 $checked = (isset($row['Field']) && isset($mime_map[$row['Field']]['transformation']) && (preg_match('@' . preg_quote($available_mime['transformation_file'][$mimekey]) . '3?@i', $mime_map[$row['Field']]['transformation'])) ? 'selected ' : '');
566 $tooltip = 'strTransformation_' . strtolower(str_replace('.inc.php', '', $available_mime['transformation_file'][$mimekey]));
567 $tooltip = isset($$tooltip) ? $$tooltip : sprintf(str_replace('<br />', ' ', __('No description is available for this transformation.<br />Please ask the author what %s does.')), 'PMA_transformation_' . $tooltip . '()');
568 $content_cells[$i][$ci] .= '<option value="' . $available_mime['transformation_file'][$mimekey] . '" ' . $checked . ' title="' . htmlspecialchars($tooltip) . '">' . htmlspecialchars($transform) . '</option>';
572 $content_cells[$i][$ci] .= '</select>';
573 $ci++;
575 $content_cells[$i][$ci] = '<input id="field_' . $i . '_' . ($ci - $ci_offset) . '"'
576 . ' type="text" name="field_transformation_options[' . $i . ']"'
577 . ' size="16" class="textfield"'
578 . ' value="' . (isset($row['Field']) && isset($mime_map[$row['Field']]['transformation_options']) ? htmlspecialchars($mime_map[$row['Field']]['transformation_options']) : '') . '"'
579 . ' />';
580 //$ci++;
582 } // end for
585 <script src="./js/keyhandler.js" type="text/javascript"></script>
586 <script type="text/javascript">
587 // <![CDATA[
588 var switch_movement = <?php echo $display_type == 'horizontal' ? '0' : '1'; ?>;
589 document.onkeydown = onKeyDownArrowsHandler;
590 // ]]>
591 </script>
593 <form id="<?php echo ($action == 'tbl_create.php' ? 'create_table' : 'append_fields'); ?>_form" method="post" action="<?php echo $action; ?>" <?php echo ($GLOBALS['cfg']['AjaxEnable'] ? ' class="ajax"' : ''); ?>>
594 <?php
595 echo PMA_generate_common_hidden_inputs($_form_params);
596 unset($_form_params);
597 if ($action == 'tbl_create.php') {
599 <table>
600 <tr valign="top">
601 <th><?php echo __('Table name'); ?>:&nbsp;</th>
602 </tr>
603 <tr><td><input type="text" name="table" size="40" maxlength="80"
604 value="<?php echo (isset($_REQUEST['table']) ? htmlspecialchars($_REQUEST['table']) : ''); ?>"
605 class="textfield" />
606 </td>
607 <td>
608 <?php if ($action == 'tbl_create.php' || $action == 'tbl_addfield.php') { ?>
609 <?php echo sprintf(__('Add %s column(s)'), '<input type="text" id="added_fields" name="added_fields" size="2" value="1" onfocus="this.select()" />'); ?>
610 <input type="submit" name="submit_num_fields" value="<?php echo __('Go'); ?>"
611 onclick="return checkFormElementInRange(this.form, 'added_fields', '<?php echo str_replace('\'', '\\\'', __('You have to add at least one column.')); ?>', 1)"
613 <?php } ?>
614 </td>
615 </tr>
616 </table>
617 <?php
621 if (is_array($content_cells) && is_array($header_cells)) {
622 // last row is for javascript insert
623 //$empty_row = array_pop($content_cells);
625 echo '<table id="table_columns">';
626 echo '<caption class="tblHeaders">' . __('Structure') . PMA_showMySQLDocu('SQL-Syntax', 'CREATE_TABLE') . '</caption>';
628 if ($display_type == 'horizontal') {
630 <tr>
631 <?php foreach ($header_cells as $header_val) { ?>
632 <th><?php echo $header_val; ?></th>
633 <?php } ?>
634 </tr>
635 <?php
637 $odd_row = true;
638 foreach ($content_cells as $content_row) {
639 echo '<tr class="' . ($odd_row ? 'odd' : 'even') . ' noclick">';
640 $odd_row = ! $odd_row;
642 if (is_array($content_row)) {
643 foreach ($content_row as $content_row_val) {
645 <td align="center"><?php echo $content_row_val; ?></td>
646 <?php
649 echo '</tr>';
651 } else {
652 $i = 0;
653 $odd_row = true;
654 foreach ($header_cells as $header_val) {
655 echo '<tr class="' . ($odd_row ? 'odd' : 'even') . ' noclick">';
656 $odd_row = ! $odd_row;
658 <th><?php echo $header_val; ?></th>
659 <?php
660 foreach ($content_cells as $content_cell) {
661 if (isset($content_cell[$i]) && $content_cell[$i] != '') {
663 <td><?php echo $content_cell[$i]; ?></td>
664 <?php
667 echo '</tr>';
668 $i++;
672 </table>
673 <br />
674 <?php
678 * needs to be finished
681 if ($display_type == 'horizontal') {
682 $new_field = '';
683 foreach ($empty_row as $content_row_val) {
684 $new_field .= '<td align="center">' . $content_row_val . '</td>';
687 <script type="text/javascript">
688 // <![CDATA[
689 var odd_row = <?php echo $odd_row; ?>;
691 function addField() {
692 var new_fields = document.getElementById('added_fields').value;
693 var new_field_container = document.getElementById('table_columns');
694 var new_field = '<?php echo preg_replace('|\s+|', ' ', preg_replace('|\'|', '\\\'', $new_field)); ?>';
695 var i = 0;
696 for (i = 0; i < new_fields; i++) {
697 if (odd_row) {
698 new_field_container.innerHTML += '<tr class="odd">' + new_field + '</tr>';
699 } else {
700 new_field_container.innerHTML += '<tr class="even">' + new_field + '</tr>';
702 odd_row = ! odd_row;
705 return true;
707 // ]]>
708 </script>
709 <?php
713 if ($action == 'tbl_create.php') {
715 <table>
716 <tr valign="top">
717 <th><?php echo __('Table comments'); ?>:&nbsp;</th>
718 <td width="25">&nbsp;</td>
719 <th><?php echo __('Storage Engine'); ?>:
720 <?php echo PMA_showMySQLDocu('Storage_engines', 'Storage_engines'); ?>
721 </th>
722 <td width="25">&nbsp;</td>
723 <th><?php echo __('Collation') ;?>:&nbsp;</th>
724 </tr>
725 <tr><td><input type="text" name="comment" size="40" maxlength="80"
726 value="<?php echo (isset($_REQUEST['comment']) ? htmlspecialchars($_REQUEST['comment']) : ''); ?>"
727 class="textfield" />
728 </td>
729 <td width="25">&nbsp;</td>
730 <td>
731 <?php
732 echo PMA_StorageEngine::getHtmlSelect('tbl_type', null,
733 (isset($_REQUEST['tbl_type']) ? $_REQUEST['tbl_type'] : null));
735 </td>
736 <td width="25">&nbsp;</td>
737 <td>
738 <?php
739 echo PMA_generateCharsetDropdownBox(PMA_CSDROPDOWN_COLLATION, 'tbl_collation',
740 null, (isset($_REQUEST['tbl_collation']) ? $_REQUEST['tbl_collation'] : null), false, 3);
742 </td>
743 </tr>
744 <?php
745 if (PMA_Partition::havePartitioning()) {
747 <tr valign="top">
748 <th><?php echo __('PARTITION definition'); ?>:&nbsp;<?php echo PMA_showMySQLDocu('Partitioning', 'Partitioning'); ?>
749 </th>
750 </tr>
751 <tr>
752 <td>
753 <textarea name="partition_definition" id="partitiondefinition"
754 cols="<?php echo $GLOBALS['cfg']['TextareaCols'];?>"
755 rows="<?php echo $GLOBALS['cfg']['TextareaRows'];?>"
756 dir="<?php echo $GLOBALS['text_dir'];?>"><?php echo (isset($_REQUEST['partition_definition']) ? htmlspecialchars($_REQUEST['partition_definition']) : ''); ?></textarea>
757 </td>
758 </tr>
759 <?php
762 </table>
763 <br />
764 <?php
765 } // end if ($action == 'tbl_create.php')
768 <fieldset class="tblFooters">
769 <input type="submit" name="do_save_data" value="<?php echo __('Save'); ?>" />
770 </fieldset>
771 <div id="properties_message"></div>
772 </form>
774 <div id="enum_editor">
775 <a class="close_enum_editor"><?php echo __('Close'); ?></a>
776 <h3><?php printf(__('Values for the column "%s"'), isset($row['Field']) ? htmlspecialchars($row['Field']) : ""); ?></h3>
777 <p><?php echo __('Enter each value in a separate field.'); ?></p>
778 <div id="values"></div>
779 <p><a class="add_value"><?php echo __('+ Add a value'); ?></a></p>
780 <input type="submit" value="<?php echo __('Go'); ?>" /> <a class="cancel_enum_editor"><?php echo __('Cancel'); ?></a>
781 </div>
783 <div id="popup_background"></div>