Merge remote-tracking branch 'origin/master' into drizzle
[phpmyadmin.git] / libraries / tbl_properties.inc.php
blob98f27be5e02aea0ead926dd93c7ed5d3bd433365
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 // strip the "BINARY" attribute, except if we find "BINARY(" because
306 // this would be a BINARY or VARBINARY field type
307 $type = preg_replace('@BINARY([^\(])@i', '', $type);
308 $type = preg_replace('@ZEROFILL@i', '', $type);
309 $type = preg_replace('@UNSIGNED@i', '', $type);
310 $length = $extracted_fieldspec['spec_in_brackets'];
311 } // end if else
312 } else {
313 // creating a column
314 $length = '';
317 // some types, for example longtext, are reported as
318 // "longtext character set latin7" when their charset and / or collation
319 // differs from the ones of the corresponding database.
320 $tmp = strpos($type, 'character set');
321 if ($tmp) {
322 $type = substr($type, 0, $tmp - 1);
325 if (isset($submit_length) && $submit_length != false) {
326 $length = $submit_length;
329 // rtrim the type, for cases like "float unsigned"
330 $type = rtrim($type);
331 $type_upper = strtoupper($type);
333 $content_cells[$i][$ci] .= PMA_getSupportedDatatypes(true, $type_upper);
334 $content_cells[$i][$ci] .= ' </select>';
335 $ci++;
337 // old column length
338 if ($is_backup) {
339 $_form_params['field_length_orig[' . $i . ']'] = $length;
342 // column length
343 if (isset($extracted_fieldspec) && ('set' == $extracted_fieldspec['type'] || 'enum' == $extracted_fieldspec['type'])) {
344 $binary = 0;
345 $unsigned = 0;
346 $zerofill = 0;
347 } else {
348 $binary = false;
349 $unsigned = stristr($row['Type'], 'unsigned');
350 $zerofill = stristr($row['Type'], 'zerofill');
352 $length_to_display = $length;
354 $content_cells[$i][$ci] = '<input id="field_' . $i . '_' . ($ci - $ci_offset) . '"'
355 . ' type="text" name="field_length[' . $i . ']" size="' . $length_values_input_size . '"'
356 . ' value="' . htmlspecialchars($length_to_display) . '"'
357 . ' class="textfield" />'
358 . '<p class="enum_notice" id="enum_notice_' . $i . '_' . ($ci - $ci_offset) . '">';
359 $content_cells[$i][$ci] .= __('ENUM or SET data too long?')
360 . '<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"> '
361 . __('Get more editing space') . '</a></p>';
362 $ci++;
364 // column default
366 * having NULL enabled does not implicit having Default with NULL
368 if (isset($row)
369 && ! isset($row['Default']) && isset($row['Null']) && $row['Null'] == 'YES') {
370 $row['Default'] = 'NULL';
374 // old column default
375 if ($is_backup) {
376 $_form_params['field_default_orig[' . $i . ']'] =
377 (isset($row['Default']) ? $row['Default'] : '');
380 // here we put 'NONE' as the default value of drop-down; otherwise
381 // users would have problems if they forget to enter the default
382 // value (example, for an INT)
383 $default_options = array(
384 'NONE' => _pgettext('for default', 'None'),
385 'USER_DEFINED' => __('As defined:'),
386 'NULL' => 'NULL',
387 'CURRENT_TIMESTAMP' => 'CURRENT_TIMESTAMP',
390 // for a TIMESTAMP, do not show the string "CURRENT_TIMESTAMP" as a default value
391 if ($type_upper == 'TIMESTAMP'
392 && ! empty($default_current_timestamp)
393 && isset($row['Default'])) {
394 $row['Default'] = '';
397 if ($type_upper == 'BIT') {
398 $row['DefaultValue'] = PMA_convert_bit_default_value($row['DefaultValue']);
401 $content_cells[$i][$ci] = '<select name="field_default_type[' . $i . ']">';
402 foreach ($default_options as $key => $value) {
403 $content_cells[$i][$ci] .= '<option value="' . $key . '"';
404 // is only set when we go back to edit a field's structure
405 if (isset($row['DefaultType']) && $row['DefaultType'] == $key) {
406 $content_cells[$i][$ci] .= ' selected="selected"';
408 $content_cells[$i][$ci] .= ' >' . $value . '</option>';
410 $content_cells[$i][$ci] .= '</select>';
411 $content_cells[$i][$ci] .= '<br />';
412 $content_cells[$i][$ci] .= '<input id="field_' . $i . '_' . ($ci - $ci_offset) . '"'
413 . ' type="text" name="field_default_value[' . $i . ']" size="12"'
414 . ' value="' . (isset($row['DefaultValue']) ? htmlspecialchars($row['DefaultValue']) : '') . '"'
415 . ' class="textfield" />';
416 $ci++;
418 // column collation
419 $tmp_collation = empty($row['Collation']) ? null : $row['Collation'];
420 $content_cells[$i][$ci] = PMA_generateCharsetDropdownBox(
421 PMA_CSDROPDOWN_COLLATION, 'field_collation[' . $i . ']',
422 'field_' . $i . '_' . ($ci - $ci_offset), $tmp_collation, false);
423 unset($tmp_collation);
424 $ci++;
426 // column attribute
427 $content_cells[$i][$ci] = '<select style="font-size: 70%;"'
428 . ' name="field_attribute[' . $i . ']"'
429 . ' id="field_' . $i . '_' . ($ci - $ci_offset) . '">';
431 $attribute = '';
432 if ($binary) {
433 $attribute = 'BINARY';
435 if ($unsigned) {
436 $attribute = 'UNSIGNED';
438 if ($zerofill) {
439 $attribute = 'UNSIGNED ZEROFILL';
441 if (isset($row['Extra']) && $row['Extra'] == 'on update CURRENT_TIMESTAMP') {
442 $attribute = 'on update CURRENT_TIMESTAMP';
445 if (isset($submit_attribute) && $submit_attribute != false) {
446 $attribute = $submit_attribute;
449 // here, we have a TIMESTAMP that SHOW FULL COLUMNS reports as having the
450 // NULL attribute, but SHOW CREATE TABLE says the contrary. Believe
451 // the latter.
452 if (PMA_MYSQL_INT_VERSION < 50025
453 && isset($row['Field'])
454 && isset($analyzed_sql[0]['create_table_fields'][$row['Field']]['type'])
455 && $analyzed_sql[0]['create_table_fields'][$row['Field']]['type'] == 'TIMESTAMP'
456 && $analyzed_sql[0]['create_table_fields'][$row['Field']]['timestamp_not_null'] == true) {
457 $row['Null'] = '';
460 // MySQL 4.1.2+ TIMESTAMP options
461 // (if on_update_current_timestamp is set, then it's TRUE)
462 if (isset($row['Field'])
463 && isset($analyzed_sql[0]['create_table_fields'][$row['Field']]['on_update_current_timestamp'])) {
464 $attribute = 'on update CURRENT_TIMESTAMP';
466 if ((isset($row['Field'])
467 && isset($analyzed_sql[0]['create_table_fields'][$row['Field']]['default_current_timestamp']))
468 || (isset($submit_default_current_timestamp) && $submit_default_current_timestamp)) {
469 $default_current_timestamp = true;
470 } else {
471 $default_current_timestamp = false;
474 $cnt_attribute_types = count($cfg['AttributeTypes']);
475 for ($j = 0; $j < $cnt_attribute_types; $j++) {
476 $content_cells[$i][$ci] .= ' <option value="'. $cfg['AttributeTypes'][$j] . '"';
477 if (strtoupper($attribute) == strtoupper($cfg['AttributeTypes'][$j])) {
478 $content_cells[$i][$ci] .= ' selected="selected"';
480 $content_cells[$i][$ci] .= '>' . $cfg['AttributeTypes'][$j] . '</option>';
483 $content_cells[$i][$ci] .= '</select>';
484 $ci++;
486 // column NULL
487 $content_cells[$i][$ci] = '<input name="field_null[' . $i . ']"'
488 . ' id="field_' . $i . '_' . ($ci - $ci_offset) . '"';
490 if (! empty($row['Null']) && $row['Null'] != 'NO' && $row['Null'] != 'NOT NULL') {
491 $content_cells[$i][$ci] .= ' checked="checked"';
494 $content_cells[$i][$ci] .= ' type="checkbox" value="NULL" />';
495 $ci++;
497 // column indexes
498 // See my other comment about removing this 'if'.
499 if (!$is_backup) {
500 $content_cells[$i][$ci] = '<select name="field_key[' . $i . ']"'
501 . ' id="field_' . $i . '_' . ($ci - $ci_offset) . '">';
502 $content_cells[$i][$ci] .= '<option value="none_' . $i . '">---</option>';
504 $content_cells[$i][$ci] .= '<option value="primary_' . $i . '" title="' . __('Primary') . '"';
505 if (isset($row['Key']) && $row['Key'] == 'PRI') {
506 $content_cells[$i][$ci] .= ' selected="selected"';
508 $content_cells[$i][$ci] .= '>PRIMARY</option>';
510 $content_cells[$i][$ci] .= '<option value="unique_' . $i . '" title="' . __('Unique') . '"';
511 if (isset($row['Key']) && $row['Key'] == 'UNI') {
512 $content_cells[$i][$ci] .= ' selected="selected"';
514 $content_cells[$i][$ci] .= '>UNIQUE</option>';
516 $content_cells[$i][$ci] .= '<option value="index_' . $i . '" title="' . __('Index') . '"';
517 if (isset($row['Key']) && $row['Key'] == 'MUL') {
518 $content_cells[$i][$ci] .= ' selected="selected"';
520 $content_cells[$i][$ci] .= '>INDEX</option>';
522 if (!PMA_DRIZZLE) {
523 $content_cells[$i][$ci] .= '<option value="fulltext_' . $i . '" title="' . __('Fulltext') . '"';
524 if (isset($row['Key']) && $row['Key'] == 'FULLTEXT') {
525 $content_cells[$i][$ci] .= ' selected="selected"';
527 $content_cells[$i][$ci] .= '>FULLTEXT</option>';
530 $content_cells[$i][$ci] .= '</select>';
531 $ci++;
532 } // end if ($action ==...)
534 // column auto_increment
535 $content_cells[$i][$ci] = '<input name="field_extra[' . $i . ']"'
536 . ' id="field_' . $i . '_' . ($ci - $ci_offset) . '"';
538 if (isset($row['Extra']) && strtolower($row['Extra']) == 'auto_increment') {
539 $content_cells[$i][$ci] .= ' checked="checked"';
542 $content_cells[$i][$ci] .= ' type="checkbox" value="AUTO_INCREMENT" />';
543 $ci++;
545 // column comments
546 $content_cells[$i][$ci] = '<input id="field_' . $i . '_' . ($ci - $ci_offset) . '"'
547 . ' type="text" name="field_comments[' . $i . ']" size="12"'
548 . ' value="' . (isset($row['Field']) && is_array($comments_map) && isset($comments_map[$row['Field']]) ? htmlspecialchars($comments_map[$row['Field']]) : '') . '"'
549 . ' class="textfield" />';
550 $ci++;
552 // column MIME-types
553 if ($cfgRelation['mimework'] && $cfg['BrowseMIME'] && $cfgRelation['commwork']) {
554 $content_cells[$i][$ci] = '<select id="field_' . $i . '_' . ($ci - $ci_offset) . '" size="1" name="field_mimetype[' . $i . ']">';
555 $content_cells[$i][$ci] .= ' <option value="">&nbsp;</option>';
557 if (is_array($available_mime['mimetype'])) {
558 foreach ($available_mime['mimetype'] AS $mimekey => $mimetype) {
559 $checked = (isset($row['Field']) && isset($mime_map[$row['Field']]['mimetype']) && ($mime_map[$row['Field']]['mimetype'] == str_replace('/', '_', $mimetype)) ? 'selected ' : '');
560 $content_cells[$i][$ci] .= ' <option value="' . str_replace('/', '_', $mimetype) . '" ' . $checked . '>' . htmlspecialchars($mimetype) . '</option>';
564 $content_cells[$i][$ci] .= '</select>';
565 $ci++;
567 $content_cells[$i][$ci] = '<select id="field_' . $i . '_' . ($ci - $ci_offset) . '" size="1" name="field_transformation[' . $i . ']">';
568 $content_cells[$i][$ci] .= ' <option value="" title="' . __('None') . '"></option>';
569 if (is_array($available_mime['transformation'])) {
570 foreach ($available_mime['transformation'] AS $mimekey => $transform) {
571 $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 ' : '');
572 $tooltip = 'strTransformation_' . strtolower(str_replace('.inc.php', '', $available_mime['transformation_file'][$mimekey]));
573 $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 . '()');
574 $content_cells[$i][$ci] .= '<option value="' . $available_mime['transformation_file'][$mimekey] . '" ' . $checked . ' title="' . htmlspecialchars($tooltip) . '">' . htmlspecialchars($transform) . '</option>';
578 $content_cells[$i][$ci] .= '</select>';
579 $ci++;
581 $content_cells[$i][$ci] = '<input id="field_' . $i . '_' . ($ci - $ci_offset) . '"'
582 . ' type="text" name="field_transformation_options[' . $i . ']"'
583 . ' size="16" class="textfield"'
584 . ' value="' . (isset($row['Field']) && isset($mime_map[$row['Field']]['transformation_options']) ? htmlspecialchars($mime_map[$row['Field']]['transformation_options']) : '') . '"'
585 . ' />';
586 //$ci++;
588 } // end for
591 <script src="./js/keyhandler.js" type="text/javascript"></script>
592 <script type="text/javascript">
593 // <![CDATA[
594 var switch_movement = <?php echo $display_type == 'horizontal' ? '0' : '1'; ?>;
595 document.onkeydown = onKeyDownArrowsHandler;
596 // ]]>
597 </script>
599 <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"' : ''); ?>>
600 <?php
601 echo PMA_generate_common_hidden_inputs($_form_params);
602 unset($_form_params);
603 if ($action == 'tbl_create.php') {
605 <table>
606 <tr valign="top">
607 <th><?php echo __('Table name'); ?>:&nbsp;</th>
608 </tr>
609 <tr><td><input type="text" name="table" size="40" maxlength="80"
610 value="<?php echo (isset($_REQUEST['table']) ? htmlspecialchars($_REQUEST['table']) : ''); ?>"
611 class="textfield" />
612 </td>
613 <td>
614 <?php if ($action == 'tbl_create.php' || $action == 'tbl_addfield.php') { ?>
615 <?php echo sprintf(__('Add %s column(s)'), '<input type="text" id="added_fields" name="added_fields" size="2" value="1" onfocus="this.select()" />'); ?>
616 <input type="submit" name="submit_num_fields" value="<?php echo __('Go'); ?>"
617 onclick="return checkFormElementInRange(this.form, 'added_fields', '<?php echo str_replace('\'', '\\\'', __('You have to add at least one column.')); ?>', 1)"
619 <?php } ?>
620 </td>
621 </tr>
622 </table>
623 <?php
627 if (is_array($content_cells) && is_array($header_cells)) {
628 // last row is for javascript insert
629 //$empty_row = array_pop($content_cells);
631 echo '<table id="table_columns" class="noclick">';
632 echo '<caption class="tblHeaders">' . __('Structure') . PMA_showMySQLDocu('SQL-Syntax', 'CREATE_TABLE') . '</caption>';
634 if ($display_type == 'horizontal') {
636 <tr>
637 <?php foreach ($header_cells as $header_val) { ?>
638 <th><?php echo $header_val; ?></th>
639 <?php } ?>
640 </tr>
641 <?php
643 $odd_row = true;
644 foreach ($content_cells as $content_row) {
645 echo '<tr class="' . ($odd_row ? 'odd' : 'even') . '">';
646 $odd_row = ! $odd_row;
648 if (is_array($content_row)) {
649 foreach ($content_row as $content_row_val) {
651 <td align="center"><?php echo $content_row_val; ?></td>
652 <?php
655 echo '</tr>';
657 } else {
658 $i = 0;
659 $odd_row = true;
660 foreach ($header_cells as $header_val) {
661 echo '<tr class="' . ($odd_row ? 'odd' : 'even') . '">';
662 $odd_row = ! $odd_row;
664 <th><?php echo $header_val; ?></th>
665 <?php
666 foreach ($content_cells as $content_cell) {
667 if (isset($content_cell[$i]) && $content_cell[$i] != '') {
669 <td><?php echo $content_cell[$i]; ?></td>
670 <?php
673 echo '</tr>';
674 $i++;
678 </table>
679 <br />
680 <?php
684 * needs to be finished
687 if ($display_type == 'horizontal') {
688 $new_field = '';
689 foreach ($empty_row as $content_row_val) {
690 $new_field .= '<td align="center">' . $content_row_val . '</td>';
693 <script type="text/javascript">
694 // <![CDATA[
695 var odd_row = <?php echo $odd_row; ?>;
697 function addField() {
698 var new_fields = document.getElementById('added_fields').value;
699 var new_field_container = document.getElementById('table_columns');
700 var new_field = '<?php echo preg_replace('|\s+|', ' ', preg_replace('|\'|', '\\\'', $new_field)); ?>';
701 var i = 0;
702 for (i = 0; i < new_fields; i++) {
703 if (odd_row) {
704 new_field_container.innerHTML += '<tr class="odd">' + new_field + '</tr>';
705 } else {
706 new_field_container.innerHTML += '<tr class="even">' + new_field + '</tr>';
708 odd_row = ! odd_row;
711 return true;
713 // ]]>
714 </script>
715 <?php
719 if ($action == 'tbl_create.php') {
721 <table>
722 <tr valign="top">
723 <th><?php echo __('Table comments'); ?>:&nbsp;</th>
724 <td width="25">&nbsp;</td>
725 <th><?php echo __('Storage Engine'); ?>:
726 <?php echo PMA_showMySQLDocu('Storage_engines', 'Storage_engines'); ?>
727 </th>
728 <td width="25">&nbsp;</td>
729 <th><?php echo __('Collation') ;?>:&nbsp;</th>
730 </tr>
731 <tr><td><input type="text" name="comment" size="40" maxlength="80"
732 value="<?php echo (isset($_REQUEST['comment']) ? htmlspecialchars($_REQUEST['comment']) : ''); ?>"
733 class="textfield" />
734 </td>
735 <td width="25">&nbsp;</td>
736 <td>
737 <?php
738 echo PMA_StorageEngine::getHtmlSelect('tbl_type', null,
739 (isset($_REQUEST['tbl_type']) ? $_REQUEST['tbl_type'] : null));
741 </td>
742 <td width="25">&nbsp;</td>
743 <td>
744 <?php
745 echo PMA_generateCharsetDropdownBox(PMA_CSDROPDOWN_COLLATION, 'tbl_collation',
746 null, (isset($_REQUEST['tbl_collation']) ? $_REQUEST['tbl_collation'] : null), false, 3);
748 </td>
749 </tr>
750 <?php
751 if (PMA_Partition::havePartitioning()) {
753 <tr valign="top">
754 <th><?php echo __('PARTITION definition'); ?>:&nbsp;<?php echo PMA_showMySQLDocu('Partitioning', 'Partitioning'); ?>
755 </th>
756 </tr>
757 <tr>
758 <td>
759 <textarea name="partition_definition" id="partitiondefinition"
760 cols="<?php echo $GLOBALS['cfg']['TextareaCols'];?>"
761 rows="<?php echo $GLOBALS['cfg']['TextareaRows'];?>"
762 dir="<?php echo $GLOBALS['text_dir'];?>"><?php echo (isset($_REQUEST['partition_definition']) ? htmlspecialchars($_REQUEST['partition_definition']) : ''); ?></textarea>
763 </td>
764 </tr>
765 <?php
768 </table>
769 <br />
770 <?php
771 } // end if ($action == 'tbl_create.php')
774 <fieldset class="tblFooters">
775 <input type="submit" name="do_save_data" value="<?php echo __('Save'); ?>" />
776 </fieldset>
777 <div id="properties_message"></div>
778 </form>
780 <div id="enum_editor">
781 <a class="close_enum_editor"><?php echo __('Close'); ?></a>
782 <h3><?php printf(__('Values for the column "%s"'), isset($row['Field']) ? htmlspecialchars($row['Field']) : ""); ?></h3>
783 <p><?php echo __('Enter each value in a separate field.'); ?></p>
784 <div id="values"></div>
785 <p><a class="add_value"><?php echo __('+ Add a value'); ?></a></p>
786 <input type="submit" value="<?php echo __('Go'); ?>" /> <a class="cancel_enum_editor"><?php echo __('Cancel'); ?></a>
787 </div>
789 <div id="popup_background"></div>