Merge remote-tracking branch 'origin/master' into drizzle
[phpmyadmin.git] / libraries / tbl_properties.inc.php
blobb359eb79f19029f83e966ea9e9a344288bc81eeb
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 if (PMA_DRIZZLE) {
32 require_once './libraries/data_drizzle.inc.php';
33 } else {
34 require_once './libraries/data_mysql.inc.php';
37 if (is_int($cfg['DefaultPropDisplay'])) {
38 if ($num_fields <= $cfg['DefaultPropDisplay']) {
39 $display_type = 'vertical';
40 } else {
41 $display_type = 'horizontal';
43 } else {
44 $display_type = $cfg['DefaultPropDisplay'];
47 if ('horizontal' == $display_type) {
48 $length_values_input_size = 8;
49 } else {
50 $length_values_input_size = 30;
53 $_form_params = array(
54 'db' => $db,
57 if ($action == 'tbl_create.php') {
58 $_form_params['reload'] = 1;
59 } elseif ($action == 'tbl_addfield.php') {
60 $_form_params['field_where'] = $_REQUEST['field_where'];
61 $_form_params['after_field'] = $_REQUEST['after_field'];
62 $_form_params['table'] = $table;
63 } else {
64 $_form_params['table'] = $table;
67 if (isset($num_fields)) {
68 $_form_params['orig_num_fields'] = $num_fields;
71 if (isset($_REQUEST['field_where'])) {
72 $_form_params['orig_field_where'] = $_REQUEST['field_where'];
75 if (isset($_REQUEST['after_field'])) {
76 $_form_params['orig_after_field'] = $_REQUEST['after_field'];
79 if (isset($selected) && is_array($selected)) {
80 foreach ($selected as $o_fld_nr => $o_fld_val) {
81 $_form_params['selected[' . $o_fld_nr . ']'] = $o_fld_val;
82 if (! isset($true_selected)) {
83 $_form_params['true_selected[' . $o_fld_nr . ']'] = $o_fld_val;
87 if (isset($true_selected) && is_array($true_selected)) {
88 foreach ($true_selected as $o_fld_nr => $o_fld_val) {
89 $_form_params['true_selected[' . $o_fld_nr . ']'] = $o_fld_val;
92 } elseif (isset($_REQUEST['field'])) {
93 $_form_params['orig_field'] = $_REQUEST['field'];
94 if (isset($orig_field)) {
95 $_form_params['true_selected[]'] = $orig_field;
96 } else {
97 $_form_params['true_selected[]'] = $_REQUEST['field'];
101 $is_backup = ($action != 'tbl_create.php' && $action != 'tbl_addfield.php');
103 $header_cells = array();
104 $content_cells = array();
106 $header_cells[] = __('Name');
107 $header_cells[] = __('Type')
108 . ($GLOBALS['cfg']['ReplaceHelpImg']
109 ? PMA_showMySQLDocu('SQL-Syntax', 'data-types')
110 : '<br /><span style="font-weight: normal">' . PMA_showMySQLDocu('SQL-Syntax', 'data-types')
111 . '</span>');
112 $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\').'));
113 $header_cells[] = __('Default') . PMA_showHint(__('For default values, please enter just a single value, without backslash escaping or quotes, using this format: a'));
114 $header_cells[] = __('Collation');
115 $header_cells[] = __('Attributes');
116 $header_cells[] = __('Null');
118 // We could remove this 'if' and let the key information be shown and
119 // editable. However, for this to work, tbl_alter must be modified to use the
120 // key fields, as tbl_addfield does.
122 if (!$is_backup) {
123 $header_cells[] = __('Index');
126 $header_cells[] = '<abbr title="AUTO_INCREMENT">' . ($display_type == 'horizontal' ? 'A_I' : 'AUTO_INCREMENT') . '</abbr>';
128 require_once './libraries/transformations.lib.php';
129 $cfgRelation = PMA_getRelationsParam();
131 $comments_map = array();
132 $mime_map = array();
133 $available_mime = array();
135 $comments_map = PMA_getComments($db, $table);
136 $header_cells[] = __('Comments');
138 if ($cfgRelation['mimework'] && $cfg['BrowseMIME']) {
139 $mime_map = PMA_getMIME($db, $table);
140 $available_mime = PMA_getAvailableMIMEtypes();
142 $hint = '<br />' .
143 sprintf(__('For a list of available transformation options and their MIME type transformations, click on %stransformation descriptions%s'),
144 '<a href="transformation_overview.php?'
145 . PMA_generate_common_url($db, $table) . '" target="_blank">',
146 '</a>');
149 $header_cells[] = __('MIME type');
150 $header_cells[] = __('Browser transformation');
151 $header_cells[] = __('Transformation options')
152 . 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);
155 // workaround for field_fulltext, because its submitted indizes contain
156 // the index as a value, not a key. Inserted here for easier maintaineance
157 // and less code to change in existing files.
158 if (isset($field_fulltext) && is_array($field_fulltext)) {
159 foreach ($field_fulltext as $fulltext_nr => $fulltext_indexkey) {
160 $submit_fulltext[$fulltext_indexkey] = $fulltext_indexkey;
164 for ($i = 0; $i < $num_fields; $i++) {
165 if (! empty($regenerate)) {
166 // An error happened with previous inputs, so we will restore the data
167 // to embed it once again in this form.
169 $row['Field'] = (isset($_REQUEST['field_name'][$i]) ? $_REQUEST['field_name'][$i] : false);
170 $row['Type'] = (isset($_REQUEST['field_type'][$i]) ? $_REQUEST['field_type'][$i] : false);
171 $row['Collation'] = (isset($_REQUEST['field_collation'][$i]) ? $_REQUEST['field_collation'][$i] : '');
172 $row['Null'] = (isset($_REQUEST['field_null'][$i]) ? $_REQUEST['field_null'][$i] : '');
174 if (isset($_REQUEST['field_key'][$i]) && $_REQUEST['field_key'][$i] == 'primary_' . $i) {
175 $row['Key'] = 'PRI';
176 } elseif (isset($_REQUEST['field_key'][$i]) && $_REQUEST['field_key'][$i] == 'index_' . $i) {
177 $row['Key'] = 'MUL';
178 } elseif (isset($_REQUEST['field_key'][$i]) && $_REQUEST['field_key'][$i] == 'unique_' . $i) {
179 $row['Key'] = 'UNI';
180 } elseif (isset($_REQUEST['field_key'][$i]) && $_REQUEST['field_key'][$i] == 'fulltext_' . $i) {
181 $row['Key'] = 'FULLTEXT';
182 } else {
183 $row['Key'] = '';
186 // put None in the drop-down for Default, when someone adds a field
187 $row['DefaultType'] = (isset($_REQUEST['field_default_type'][$i]) ? $_REQUEST['field_default_type'][$i] : 'NONE');
188 $row['DefaultValue'] = (isset($_REQUEST['field_default_value'][$i]) ? $_REQUEST['field_default_value'][$i] : '');
190 switch ($row['DefaultType']) {
191 case 'NONE' :
192 $row['Default'] = null;
193 break;
194 case 'USER_DEFINED' :
195 $row['Default'] = $row['DefaultValue'];
196 break;
197 case 'NULL' :
198 case 'CURRENT_TIMESTAMP' :
199 $row['Default'] = $row['DefaultType'];
200 break;
203 $row['Extra'] = (isset($_REQUEST['field_extra'][$i]) ? $_REQUEST['field_extra'][$i] : false);
204 $row['Comment'] = (isset($submit_fulltext[$i]) && ($submit_fulltext[$i] == $i) ? 'FULLTEXT' : false);
206 $submit_length = (isset($_REQUEST['field_length'][$i]) ? $_REQUEST['field_length'][$i] : false);
207 $submit_attribute = (isset($_REQUEST['field_attribute'][$i]) ? $_REQUEST['field_attribute'][$i] : false);
209 $submit_default_current_timestamp = (isset($_REQUEST['field_default_current_timestamp'][$i]) ? true : false);
211 if (isset($_REQUEST['field_comments'][$i])) {
212 $comments_map[$row['Field']] = $_REQUEST['field_comments'][$i];
215 if (isset($_REQUEST['field_mimetype'][$i])) {
216 $mime_map[$row['Field']]['mimetype'] = $_REQUEST['field_mimetype'][$i];
219 if (isset($_REQUEST['field_transformation'][$i])) {
220 $mime_map[$row['Field']]['transformation'] = $_REQUEST['field_transformation'][$i];
223 if (isset($_REQUEST['field_transformation_options'][$i])) {
224 $mime_map[$row['Field']]['transformation_options'] = $_REQUEST['field_transformation_options'][$i];
227 } elseif (isset($fields_meta[$i])) {
228 $row = $fields_meta[$i];
229 switch ($row['Default']) {
230 case null:
231 if ($row['Null'] == 'YES') {
232 $row['DefaultType'] = 'NULL';
233 $row['DefaultValue'] = '';
234 // SHOW FULL COLUMNS does not report the case when there is a DEFAULT value
235 // which is empty so we need to use the results of SHOW CREATE TABLE
236 } elseif (isset($row) && isset($analyzed_sql[0]['create_table_fields'][$row['Field']]['default_value'])) {
237 $row['DefaultType'] = 'USER_DEFINED';
238 $row['DefaultValue'] = $row['Default'];
239 } else {
240 $row['DefaultType'] = 'NONE';
241 $row['DefaultValue'] = '';
243 break;
244 case 'CURRENT_TIMESTAMP':
245 $row['DefaultType'] = 'CURRENT_TIMESTAMP';
246 $row['DefaultValue'] = '';
247 break;
248 default:
249 $row['DefaultType'] = 'USER_DEFINED';
250 $row['DefaultValue'] = $row['Default'];
251 break;
255 if (isset($row['Type'])) {
256 $extracted_fieldspec = PMA_extractFieldSpec($row['Type']);
257 if ($extracted_fieldspec['type'] == 'bit') {
258 $row['Default'] = PMA_convert_bit_default_value($row['Default']);
261 // Cell index: If certain fields get left out, the counter shouldn't change.
262 $ci = 0;
263 // Everytime a cell shall be left out the STRG-jumping feature, $ci_offset
264 // has to be incremented ($ci_offset++)
265 $ci_offset = -1;
267 // old column name
268 if ($is_backup) {
269 if (! empty($true_selected[$i])) {
270 $_form_params['field_orig[' . $i . ']'] = $true_selected[$i];
271 } elseif (isset($row['Field'])) {
272 $_form_params['field_orig[' . $i . ']'] = $row['Field'];
273 } else {
274 $_form_params['field_orig[' . $i . ']'] = '';
278 // column name
279 $content_cells[$i][$ci] = '<input id="field_' . $i . '_' . ($ci - $ci_offset) . '"'
280 . ' type="text" name="field_name[' . $i . ']"'
281 . ' maxlength="64" class="textfield" title="' . __('Column') . '"'
282 . ' size="' . ($GLOBALS['cfg']['DefaultPropDisplay'] == 'horizontal' ? '10' : '30') . '"'
283 . ' value="' . (isset($row['Field']) ? htmlspecialchars($row['Field']) : '') . '"'
284 . ' />';
285 $ci++;
287 // column type
288 $select_id = 'field_' . $i . '_' . ($ci - $ci_offset);
289 $content_cells[$i][$ci] = '<select class="column_type" name="field_type[' . $i . ']"'
290 .' id="' . $select_id . '">';
292 if (empty($row['Type'])) {
293 // creating a column
294 $row['Type'] = '';
295 $type = '';
296 } else {
297 $type = $row['Type'];
300 if (! empty($row['Type'])) {
301 $type = $extracted_fieldspec['type'];
302 if ('set' == $extracted_fieldspec['type'] || 'enum' == $extracted_fieldspec['type']) {
303 $length = $extracted_fieldspec['spec_in_brackets'];
304 } else {
305 $type = $extracted_fieldspec['print_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 $length_to_display = $length;
341 $content_cells[$i][$ci] = '<input id="field_' . $i . '_' . ($ci - $ci_offset) . '"'
342 . ' type="text" name="field_length[' . $i . ']" size="' . $length_values_input_size . '"'
343 . ' value="' . htmlspecialchars($length_to_display) . '"'
344 . ' class="textfield" />'
345 . '<p class="enum_notice" id="enum_notice_' . $i . '_' . ($ci - $ci_offset) . '">';
346 $content_cells[$i][$ci] .= __('ENUM or SET data too long?')
347 . '<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"> '
348 . __('Get more editing space') . '</a></p>';
349 $ci++;
351 // column default
353 * having NULL enabled does not implicit having Default with NULL
355 if (isset($row)
356 && ! isset($row['Default']) && isset($row['Null']) && $row['Null'] == 'YES') {
357 $row['Default'] = 'NULL';
361 // old column default
362 if ($is_backup) {
363 $_form_params['field_default_orig[' . $i . ']'] =
364 (isset($row['Default']) ? $row['Default'] : '');
367 // here we put 'NONE' as the default value of drop-down; otherwise
368 // users would have problems if they forget to enter the default
369 // value (example, for an INT)
370 $default_options = array(
371 'NONE' => _pgettext('for default', 'None'),
372 'USER_DEFINED' => __('As defined:'),
373 'NULL' => 'NULL',
374 'CURRENT_TIMESTAMP' => 'CURRENT_TIMESTAMP',
377 // for a TIMESTAMP, do not show the string "CURRENT_TIMESTAMP" as a default value
378 if ($type_upper == 'TIMESTAMP'
379 && ! empty($default_current_timestamp)
380 && isset($row['Default'])) {
381 $row['Default'] = '';
384 if ($type_upper == 'BIT') {
385 $row['DefaultValue'] = PMA_convert_bit_default_value($row['DefaultValue']);
388 $content_cells[$i][$ci] = '<select name="field_default_type[' . $i . ']">';
389 foreach ($default_options as $key => $value) {
390 $content_cells[$i][$ci] .= '<option value="' . $key . '"';
391 // is only set when we go back to edit a field's structure
392 if (isset($row['DefaultType']) && $row['DefaultType'] == $key) {
393 $content_cells[$i][$ci] .= ' selected="selected"';
395 $content_cells[$i][$ci] .= ' >' . $value . '</option>';
397 $content_cells[$i][$ci] .= '</select>';
398 $content_cells[$i][$ci] .= '<br />';
399 $content_cells[$i][$ci] .= '<input id="field_' . $i . '_' . ($ci - $ci_offset) . '"'
400 . ' type="text" name="field_default_value[' . $i . ']" size="12"'
401 . ' value="' . (isset($row['DefaultValue']) ? htmlspecialchars($row['DefaultValue']) : '') . '"'
402 . ' class="textfield" />';
403 $ci++;
405 // column collation
406 $tmp_collation = empty($row['Collation']) ? null : $row['Collation'];
407 $content_cells[$i][$ci] = PMA_generateCharsetDropdownBox(
408 PMA_CSDROPDOWN_COLLATION, 'field_collation[' . $i . ']',
409 'field_' . $i . '_' . ($ci - $ci_offset), $tmp_collation, false);
410 unset($tmp_collation);
411 $ci++;
413 // column attribute
414 $content_cells[$i][$ci] = '<select style="font-size: 70%;"'
415 . ' name="field_attribute[' . $i . ']"'
416 . ' id="field_' . $i . '_' . ($ci - $ci_offset) . '">';
418 $attribute = '';
419 if (isset($extracted_fieldspec)) {
420 $attribute = $extracted_fieldspec['attribute'];
423 if (isset($row['Extra']) && $row['Extra'] == 'on update CURRENT_TIMESTAMP') {
424 $attribute = 'on update CURRENT_TIMESTAMP';
427 if (isset($submit_attribute) && $submit_attribute != false) {
428 $attribute = $submit_attribute;
431 // here, we have a TIMESTAMP that SHOW FULL COLUMNS reports as having the
432 // NULL attribute, but SHOW CREATE TABLE says the contrary. Believe
433 // the latter.
434 if (PMA_MYSQL_INT_VERSION < 50025
435 && isset($row['Field'])
436 && isset($analyzed_sql[0]['create_table_fields'][$row['Field']]['type'])
437 && $analyzed_sql[0]['create_table_fields'][$row['Field']]['type'] == 'TIMESTAMP'
438 && $analyzed_sql[0]['create_table_fields'][$row['Field']]['timestamp_not_null'] == true) {
439 $row['Null'] = '';
442 // MySQL 4.1.2+ TIMESTAMP options
443 // (if on_update_current_timestamp is set, then it's TRUE)
444 if (isset($row['Field'])
445 && isset($analyzed_sql[0]['create_table_fields'][$row['Field']]['on_update_current_timestamp'])) {
446 $attribute = 'on update CURRENT_TIMESTAMP';
448 if ((isset($row['Field'])
449 && isset($analyzed_sql[0]['create_table_fields'][$row['Field']]['default_current_timestamp']))
450 || (isset($submit_default_current_timestamp) && $submit_default_current_timestamp)) {
451 $default_current_timestamp = true;
452 } else {
453 $default_current_timestamp = false;
456 $cnt_attribute_types = count($cfg['AttributeTypes']);
457 for ($j = 0; $j < $cnt_attribute_types; $j++) {
458 $content_cells[$i][$ci] .= ' <option value="'. $cfg['AttributeTypes'][$j] . '"';
459 if (strtoupper($attribute) == strtoupper($cfg['AttributeTypes'][$j])) {
460 $content_cells[$i][$ci] .= ' selected="selected"';
462 $content_cells[$i][$ci] .= '>' . $cfg['AttributeTypes'][$j] . '</option>';
465 $content_cells[$i][$ci] .= '</select>';
466 $ci++;
468 // column NULL
469 $content_cells[$i][$ci] = '<input name="field_null[' . $i . ']"'
470 . ' id="field_' . $i . '_' . ($ci - $ci_offset) . '"';
472 if (! empty($row['Null']) && $row['Null'] != 'NO' && $row['Null'] != 'NOT NULL') {
473 $content_cells[$i][$ci] .= ' checked="checked"';
476 $content_cells[$i][$ci] .= ' type="checkbox" value="NULL" />';
477 $ci++;
479 // column indexes
480 // See my other comment about removing this 'if'.
481 if (!$is_backup) {
482 $content_cells[$i][$ci] = '<select name="field_key[' . $i . ']"'
483 . ' id="field_' . $i . '_' . ($ci - $ci_offset) . '">';
484 $content_cells[$i][$ci] .= '<option value="none_' . $i . '">---</option>';
486 $content_cells[$i][$ci] .= '<option value="primary_' . $i . '" title="' . __('Primary') . '"';
487 if (isset($row['Key']) && $row['Key'] == 'PRI') {
488 $content_cells[$i][$ci] .= ' selected="selected"';
490 $content_cells[$i][$ci] .= '>PRIMARY</option>';
492 $content_cells[$i][$ci] .= '<option value="unique_' . $i . '" title="' . __('Unique') . '"';
493 if (isset($row['Key']) && $row['Key'] == 'UNI') {
494 $content_cells[$i][$ci] .= ' selected="selected"';
496 $content_cells[$i][$ci] .= '>UNIQUE</option>';
498 $content_cells[$i][$ci] .= '<option value="index_' . $i . '" title="' . __('Index') . '"';
499 if (isset($row['Key']) && $row['Key'] == 'MUL') {
500 $content_cells[$i][$ci] .= ' selected="selected"';
502 $content_cells[$i][$ci] .= '>INDEX</option>';
504 if (!PMA_DRIZZLE) {
505 $content_cells[$i][$ci] .= '<option value="fulltext_' . $i . '" title="' . __('Fulltext') . '"';
506 if (isset($row['Key']) && $row['Key'] == 'FULLTEXT') {
507 $content_cells[$i][$ci] .= ' selected="selected"';
509 $content_cells[$i][$ci] .= '>FULLTEXT</option>';
512 $content_cells[$i][$ci] .= '</select>';
513 $ci++;
514 } // end if ($action ==...)
516 // column auto_increment
517 $content_cells[$i][$ci] = '<input name="field_extra[' . $i . ']"'
518 . ' id="field_' . $i . '_' . ($ci - $ci_offset) . '"';
520 if (isset($row['Extra']) && strtolower($row['Extra']) == 'auto_increment') {
521 $content_cells[$i][$ci] .= ' checked="checked"';
524 $content_cells[$i][$ci] .= ' type="checkbox" value="AUTO_INCREMENT" />';
525 $ci++;
527 // column comments
528 $content_cells[$i][$ci] = '<input id="field_' . $i . '_' . ($ci - $ci_offset) . '"'
529 . ' type="text" name="field_comments[' . $i . ']" size="12"'
530 . ' value="' . (isset($row['Field']) && is_array($comments_map) && isset($comments_map[$row['Field']]) ? htmlspecialchars($comments_map[$row['Field']]) : '') . '"'
531 . ' class="textfield" />';
532 $ci++;
534 // column MIME-types
535 if ($cfgRelation['mimework'] && $cfg['BrowseMIME'] && $cfgRelation['commwork']) {
536 $content_cells[$i][$ci] = '<select id="field_' . $i . '_' . ($ci - $ci_offset) . '" size="1" name="field_mimetype[' . $i . ']">';
537 $content_cells[$i][$ci] .= ' <option value="">&nbsp;</option>';
539 if (is_array($available_mime['mimetype'])) {
540 foreach ($available_mime['mimetype'] AS $mimekey => $mimetype) {
541 $checked = (isset($row['Field']) && isset($mime_map[$row['Field']]['mimetype']) && ($mime_map[$row['Field']]['mimetype'] == str_replace('/', '_', $mimetype)) ? 'selected ' : '');
542 $content_cells[$i][$ci] .= ' <option value="' . str_replace('/', '_', $mimetype) . '" ' . $checked . '>' . htmlspecialchars($mimetype) . '</option>';
546 $content_cells[$i][$ci] .= '</select>';
547 $ci++;
549 $content_cells[$i][$ci] = '<select id="field_' . $i . '_' . ($ci - $ci_offset) . '" size="1" name="field_transformation[' . $i . ']">';
550 $content_cells[$i][$ci] .= ' <option value="" title="' . __('None') . '"></option>';
551 if (is_array($available_mime['transformation'])) {
552 foreach ($available_mime['transformation'] AS $mimekey => $transform) {
553 $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 ' : '');
554 $tooltip = 'strTransformation_' . strtolower(str_replace('.inc.php', '', $available_mime['transformation_file'][$mimekey]));
555 $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 . '()');
556 $content_cells[$i][$ci] .= '<option value="' . $available_mime['transformation_file'][$mimekey] . '" ' . $checked . ' title="' . htmlspecialchars($tooltip) . '">' . htmlspecialchars($transform) . '</option>';
560 $content_cells[$i][$ci] .= '</select>';
561 $ci++;
563 $content_cells[$i][$ci] = '<input id="field_' . $i . '_' . ($ci - $ci_offset) . '"'
564 . ' type="text" name="field_transformation_options[' . $i . ']"'
565 . ' size="16" class="textfield"'
566 . ' value="' . (isset($row['Field']) && isset($mime_map[$row['Field']]['transformation_options']) ? htmlspecialchars($mime_map[$row['Field']]['transformation_options']) : '') . '"'
567 . ' />';
568 //$ci++;
570 } // end for
573 <script src="./js/keyhandler.js" type="text/javascript"></script>
574 <script type="text/javascript">
575 // <![CDATA[
576 var switch_movement = <?php echo $display_type == 'horizontal' ? '0' : '1'; ?>;
577 document.onkeydown = onKeyDownArrowsHandler;
578 // ]]>
579 </script>
581 <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"' : ''); ?>>
582 <?php
583 echo PMA_generate_common_hidden_inputs($_form_params);
584 unset($_form_params);
585 if ($action == 'tbl_create.php') {
587 <table>
588 <tr valign="top">
589 <th><?php echo __('Table name'); ?>:&nbsp;</th>
590 </tr>
591 <tr><td><input type="text" name="table" size="40" maxlength="80"
592 value="<?php echo (isset($_REQUEST['table']) ? htmlspecialchars($_REQUEST['table']) : ''); ?>"
593 class="textfield" />
594 </td>
595 <td>
596 <?php if ($action == 'tbl_create.php' || $action == 'tbl_addfield.php') { ?>
597 <?php echo sprintf(__('Add %s column(s)'), '<input type="text" id="added_fields" name="added_fields" size="2" value="1" onfocus="this.select()" />'); ?>
598 <input type="submit" name="submit_num_fields" value="<?php echo __('Go'); ?>"
599 onclick="return checkFormElementInRange(this.form, 'added_fields', '<?php echo str_replace('\'', '\\\'', __('You have to add at least one column.')); ?>', 1)"
601 <?php } ?>
602 </td>
603 </tr>
604 </table>
605 <?php
609 if (is_array($content_cells) && is_array($header_cells)) {
610 // last row is for javascript insert
611 //$empty_row = array_pop($content_cells);
613 echo '<table id="table_columns" class="noclick">';
614 echo '<caption class="tblHeaders">' . __('Structure') . PMA_showMySQLDocu('SQL-Syntax', 'CREATE_TABLE') . '</caption>';
616 if ($display_type == 'horizontal') {
618 <tr>
619 <?php foreach ($header_cells as $header_val) { ?>
620 <th><?php echo $header_val; ?></th>
621 <?php } ?>
622 </tr>
623 <?php
625 $odd_row = true;
626 foreach ($content_cells as $content_row) {
627 echo '<tr class="' . ($odd_row ? 'odd' : 'even') . '">';
628 $odd_row = ! $odd_row;
630 if (is_array($content_row)) {
631 foreach ($content_row as $content_row_val) {
633 <td align="center"><?php echo $content_row_val; ?></td>
634 <?php
637 echo '</tr>';
639 } else {
640 $i = 0;
641 $odd_row = true;
642 foreach ($header_cells as $header_val) {
643 echo '<tr class="' . ($odd_row ? 'odd' : 'even') . '">';
644 $odd_row = ! $odd_row;
646 <th><?php echo $header_val; ?></th>
647 <?php
648 foreach ($content_cells as $content_cell) {
649 if (isset($content_cell[$i]) && $content_cell[$i] != '') {
651 <td><?php echo $content_cell[$i]; ?></td>
652 <?php
655 echo '</tr>';
656 $i++;
660 </table>
661 <br />
662 <?php
666 * needs to be finished
669 if ($display_type == 'horizontal') {
670 $new_field = '';
671 foreach ($empty_row as $content_row_val) {
672 $new_field .= '<td align="center">' . $content_row_val . '</td>';
675 <script type="text/javascript">
676 // <![CDATA[
677 var odd_row = <?php echo $odd_row; ?>;
679 function addField()
681 var new_fields = document.getElementById('added_fields').value;
682 var new_field_container = document.getElementById('table_columns');
683 var new_field = '<?php echo preg_replace('|\s+|', ' ', preg_replace('|\'|', '\\\'', $new_field)); ?>';
684 var i = 0;
685 for (i = 0; i < new_fields; i++) {
686 if (odd_row) {
687 new_field_container.innerHTML += '<tr class="odd">' + new_field + '</tr>';
688 } else {
689 new_field_container.innerHTML += '<tr class="even">' + new_field + '</tr>';
691 odd_row = ! odd_row;
694 return true;
696 // ]]>
697 </script>
698 <?php
702 if ($action == 'tbl_create.php') {
704 <table>
705 <tr valign="top">
706 <th><?php echo __('Table comments'); ?>:&nbsp;</th>
707 <td width="25">&nbsp;</td>
708 <th><?php echo __('Storage Engine'); ?>:
709 <?php echo PMA_showMySQLDocu('Storage_engines', 'Storage_engines'); ?>
710 </th>
711 <td width="25">&nbsp;</td>
712 <th><?php echo __('Collation') ;?>:&nbsp;</th>
713 </tr>
714 <tr><td><input type="text" name="comment" size="40" maxlength="80"
715 value="<?php echo (isset($_REQUEST['comment']) ? htmlspecialchars($_REQUEST['comment']) : ''); ?>"
716 class="textfield" />
717 </td>
718 <td width="25">&nbsp;</td>
719 <td>
720 <?php
721 echo PMA_StorageEngine::getHtmlSelect('tbl_type', null,
722 (isset($_REQUEST['tbl_type']) ? $_REQUEST['tbl_type'] : null));
724 </td>
725 <td width="25">&nbsp;</td>
726 <td>
727 <?php
728 echo PMA_generateCharsetDropdownBox(PMA_CSDROPDOWN_COLLATION, 'tbl_collation',
729 null, (isset($_REQUEST['tbl_collation']) ? $_REQUEST['tbl_collation'] : null), false, 3);
731 </td>
732 </tr>
733 <?php
734 if (PMA_Partition::havePartitioning()) {
736 <tr valign="top">
737 <th><?php echo __('PARTITION definition'); ?>:&nbsp;<?php echo PMA_showMySQLDocu('Partitioning', 'Partitioning'); ?>
738 </th>
739 </tr>
740 <tr>
741 <td>
742 <textarea name="partition_definition" id="partitiondefinition"
743 cols="<?php echo $GLOBALS['cfg']['TextareaCols'];?>"
744 rows="<?php echo $GLOBALS['cfg']['TextareaRows'];?>"
745 dir="<?php echo $GLOBALS['text_dir'];?>"><?php echo (isset($_REQUEST['partition_definition']) ? htmlspecialchars($_REQUEST['partition_definition']) : ''); ?></textarea>
746 </td>
747 </tr>
748 <?php
751 </table>
752 <br />
753 <?php
754 } // end if ($action == 'tbl_create.php')
757 <fieldset class="tblFooters">
758 <input type="submit" name="do_save_data" value="<?php echo __('Save'); ?>" />
759 </fieldset>
760 <div id="properties_message"></div>
761 </form>
763 <div id="enum_editor">
764 <a class="close_enum_editor"><?php echo __('Close'); ?></a>
765 <h3><?php printf(__('Values for the column "%s"'), isset($row['Field']) ? htmlspecialchars($row['Field']) : ""); ?></h3>
766 <p><?php echo __('Enter each value in a separate field.'); ?></p>
767 <div id="values"></div>
768 <p><a class="add_value"><?php echo __('+ Add a value'); ?></a></p>
769 <input type="submit" value="<?php echo __('Go'); ?>" /> <a class="cancel_enum_editor"><?php echo __('Cancel'); ?></a>
770 </div>
772 <div id="popup_background"></div>