Revert "Provide proper function list in Insert dropdowns and proper column types...
[phpmyadmin.git] / libraries / tbl_properties.inc.php
blobda3d93945a09f778e0c8ae9ddcfcd99f0afa525a
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 if (is_int($cfg['DefaultPropDisplay'])) {
31 if ($num_fields <= $cfg['DefaultPropDisplay']) {
32 $display_type = 'vertical';
33 } else {
34 $display_type = 'horizontal';
36 } else {
37 $display_type = $cfg['DefaultPropDisplay'];
40 if ('horizontal' == $display_type) {
41 $length_values_input_size = 8;
42 } else {
43 $length_values_input_size = 30;
46 $_form_params = array(
47 'db' => $db,
50 if ($action == 'tbl_create.php') {
51 $_form_params['reload'] = 1;
52 } elseif ($action == 'tbl_addfield.php') {
53 $_form_params['field_where'] = $_REQUEST['field_where'];
54 $_form_params['after_field'] = $_REQUEST['after_field'];
55 $_form_params['table'] = $table;
56 } else {
57 $_form_params['table'] = $table;
60 if (isset($num_fields)) {
61 $_form_params['orig_num_fields'] = $num_fields;
64 if (isset($_REQUEST['field_where'])) {
65 $_form_params['orig_field_where'] = $_REQUEST['field_where'];
68 if (isset($_REQUEST['after_field'])) {
69 $_form_params['orig_after_field'] = $_REQUEST['after_field'];
72 if (isset($selected) && is_array($selected)) {
73 foreach ($selected as $o_fld_nr => $o_fld_val) {
74 $_form_params['selected[' . $o_fld_nr . ']'] = $o_fld_val;
75 if (! isset($true_selected)) {
76 $_form_params['true_selected[' . $o_fld_nr . ']'] = $o_fld_val;
80 if (isset($true_selected) && is_array($true_selected)) {
81 foreach ($true_selected as $o_fld_nr => $o_fld_val) {
82 $_form_params['true_selected[' . $o_fld_nr . ']'] = $o_fld_val;
85 } elseif (isset($_REQUEST['field'])) {
86 $_form_params['orig_field'] = $_REQUEST['field'];
87 if (isset($orig_field)) {
88 $_form_params['true_selected[]'] = $orig_field;
89 } else {
90 $_form_params['true_selected[]'] = $_REQUEST['field'];
94 $is_backup = ($action != 'tbl_create.php' && $action != 'tbl_addfield.php');
96 $header_cells = array();
97 $content_cells = array();
99 $header_cells[] = __('Name');
100 $header_cells[] = __('Type')
101 . ($GLOBALS['cfg']['ReplaceHelpImg']
102 ? PMA_showMySQLDocu('SQL-Syntax', 'data-types')
103 : '<br /><span style="font-weight: normal">' . PMA_showMySQLDocu('SQL-Syntax', 'data-types')
104 . '</span>');
105 $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\').'));
106 $header_cells[] = __('Default') . PMA_showHint(__('For default values, please enter just a single value, without backslash escaping or quotes, using this format: a'));
107 $header_cells[] = __('Collation');
108 $header_cells[] = __('Attributes');
109 $header_cells[] = __('Null');
111 // We could remove this 'if' and let the key information be shown and
112 // editable. However, for this to work, tbl_alter must be modified to use the
113 // key fields, as tbl_addfield does.
115 if (!$is_backup) {
116 $header_cells[] = __('Index');
119 $header_cells[] = '<abbr title="AUTO_INCREMENT">' . ($display_type == 'horizontal' ? 'A_I' : 'AUTO_INCREMENT') . '</abbr>';
121 require_once './libraries/transformations.lib.php';
122 $cfgRelation = PMA_getRelationsParam();
124 $comments_map = array();
125 $mime_map = array();
126 $available_mime = array();
128 $comments_map = PMA_getComments($db, $table);
129 $header_cells[] = __('Comments');
131 if ($cfgRelation['mimework'] && $cfg['BrowseMIME']) {
132 $mime_map = PMA_getMIME($db, $table);
133 $available_mime = PMA_getAvailableMIMEtypes();
135 $hint = '<br />' .
136 sprintf(__('For a list of available transformation options and their MIME type transformations, click on %stransformation descriptions%s'),
137 '<a href="transformation_overview.php?'
138 . PMA_generate_common_url($db, $table) . '" target="_blank">',
139 '</a>');
142 $header_cells[] = __('MIME type');
143 $header_cells[] = __('Browser transformation');
144 $header_cells[] = __('Transformation options')
145 . 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);
148 // workaround for field_fulltext, because its submitted indizes contain
149 // the index as a value, not a key. Inserted here for easier maintaineance
150 // and less code to change in existing files.
151 if (isset($field_fulltext) && is_array($field_fulltext)) {
152 foreach ($field_fulltext as $fulltext_nr => $fulltext_indexkey) {
153 $submit_fulltext[$fulltext_indexkey] = $fulltext_indexkey;
157 for ($i = 0; $i < $num_fields; $i++) {
158 if (! empty($regenerate)) {
159 // An error happened with previous inputs, so we will restore the data
160 // to embed it once again in this form.
162 $row['Field'] = (isset($_REQUEST['field_name'][$i]) ? $_REQUEST['field_name'][$i] : false);
163 $row['Type'] = (isset($_REQUEST['field_type'][$i]) ? $_REQUEST['field_type'][$i] : false);
164 $row['Collation'] = (isset($_REQUEST['field_collation'][$i]) ? $_REQUEST['field_collation'][$i] : '');
165 $row['Null'] = (isset($_REQUEST['field_null'][$i]) ? $_REQUEST['field_null'][$i] : '');
167 if (isset($_REQUEST['field_key'][$i]) && $_REQUEST['field_key'][$i] == 'primary_' . $i) {
168 $row['Key'] = 'PRI';
169 } elseif (isset($_REQUEST['field_key'][$i]) && $_REQUEST['field_key'][$i] == 'index_' . $i) {
170 $row['Key'] = 'MUL';
171 } elseif (isset($_REQUEST['field_key'][$i]) && $_REQUEST['field_key'][$i] == 'unique_' . $i) {
172 $row['Key'] = 'UNI';
173 } elseif (isset($_REQUEST['field_key'][$i]) && $_REQUEST['field_key'][$i] == 'fulltext_' . $i) {
174 $row['Key'] = 'FULLTEXT';
175 } else {
176 $row['Key'] = '';
179 // put None in the drop-down for Default, when someone adds a field
180 $row['DefaultType'] = (isset($_REQUEST['field_default_type'][$i]) ? $_REQUEST['field_default_type'][$i] : 'NONE');
181 $row['DefaultValue'] = (isset($_REQUEST['field_default_value'][$i]) ? $_REQUEST['field_default_value'][$i] : '');
183 switch ($row['DefaultType']) {
184 case 'NONE' :
185 $row['Default'] = null;
186 break;
187 case 'USER_DEFINED' :
188 $row['Default'] = $row['DefaultValue'];
189 break;
190 case 'NULL' :
191 case 'CURRENT_TIMESTAMP' :
192 $row['Default'] = $row['DefaultType'];
193 break;
196 $row['Extra'] = (isset($_REQUEST['field_extra'][$i]) ? $_REQUEST['field_extra'][$i] : false);
197 $row['Comment'] = (isset($submit_fulltext[$i]) && ($submit_fulltext[$i] == $i) ? 'FULLTEXT' : false);
199 $submit_length = (isset($_REQUEST['field_length'][$i]) ? $_REQUEST['field_length'][$i] : false);
200 $submit_attribute = (isset($_REQUEST['field_attribute'][$i]) ? $_REQUEST['field_attribute'][$i] : false);
202 $submit_default_current_timestamp = (isset($_REQUEST['field_default_current_timestamp'][$i]) ? true : false);
204 if (isset($_REQUEST['field_comments'][$i])) {
205 $comments_map[$row['Field']] = $_REQUEST['field_comments'][$i];
208 if (isset($_REQUEST['field_mimetype'][$i])) {
209 $mime_map[$row['Field']]['mimetype'] = $_REQUEST['field_mimetype'][$i];
212 if (isset($_REQUEST['field_transformation'][$i])) {
213 $mime_map[$row['Field']]['transformation'] = $_REQUEST['field_transformation'][$i];
216 if (isset($_REQUEST['field_transformation_options'][$i])) {
217 $mime_map[$row['Field']]['transformation_options'] = $_REQUEST['field_transformation_options'][$i];
220 } elseif (isset($fields_meta[$i])) {
221 $row = $fields_meta[$i];
222 switch ($row['Default']) {
223 case null:
224 if ($row['Null'] == 'YES') {
225 $row['DefaultType'] = 'NULL';
226 $row['DefaultValue'] = '';
227 // SHOW FULL COLUMNS does not report the case when there is a DEFAULT value
228 // which is empty so we need to use the results of SHOW CREATE TABLE
229 } elseif (isset($row) && isset($analyzed_sql[0]['create_table_fields'][$row['Field']]['default_value'])) {
230 $row['DefaultType'] = 'USER_DEFINED';
231 $row['DefaultValue'] = $row['Default'];
232 } else {
233 $row['DefaultType'] = 'NONE';
234 $row['DefaultValue'] = '';
236 break;
237 case 'CURRENT_TIMESTAMP':
238 $row['DefaultType'] = 'CURRENT_TIMESTAMP';
239 $row['DefaultValue'] = '';
240 break;
241 default:
242 $row['DefaultType'] = 'USER_DEFINED';
243 $row['DefaultValue'] = $row['Default'];
244 break;
248 if (isset($row['Type'])) {
249 $extracted_fieldspec = PMA_extractFieldSpec($row['Type']);
250 if ($extracted_fieldspec['type'] == 'bit') {
251 $row['Default'] = PMA_convert_bit_default_value($row['Default']);
254 // Cell index: If certain fields get left out, the counter shouldn't change.
255 $ci = 0;
256 // Everytime a cell shall be left out the STRG-jumping feature, $ci_offset
257 // has to be incremented ($ci_offset++)
258 $ci_offset = -1;
260 // old column name
261 if ($is_backup) {
262 if (! empty($true_selected[$i])) {
263 $_form_params['field_orig[' . $i . ']'] = $true_selected[$i];
264 } elseif (isset($row['Field'])) {
265 $_form_params['field_orig[' . $i . ']'] = $row['Field'];
266 } else {
267 $_form_params['field_orig[' . $i . ']'] = '';
271 // column name
272 $content_cells[$i][$ci] = '<input id="field_' . $i . '_' . ($ci - $ci_offset) . '"'
273 . ' type="text" name="field_name[' . $i . ']"'
274 . ' maxlength="64" class="textfield" title="' . __('Column') . '"'
275 . ' size="' . ($GLOBALS['cfg']['DefaultPropDisplay'] == 'horizontal' ? '10' : '30') . '"'
276 . ' value="' . (isset($row['Field']) ? htmlspecialchars($row['Field']) : '') . '"'
277 . ' />';
278 $ci++;
280 // column type
281 $select_id = 'field_' . $i . '_' . ($ci - $ci_offset);
282 $content_cells[$i][$ci] = '<select class="column_type" name="field_type[' . $i . ']"'
283 .' id="' . $select_id . '">';
285 if (empty($row['Type'])) {
286 // creating a column
287 $row['Type'] = '';
288 $type = '';
289 } else {
290 $type = $row['Type'];
293 if (! empty($row['Type'])) {
294 $type = $extracted_fieldspec['type'];
295 if ('set' == $extracted_fieldspec['type'] || 'enum' == $extracted_fieldspec['type']) {
296 $length = $extracted_fieldspec['spec_in_brackets'];
297 } else {
298 // strip the "BINARY" attribute, except if we find "BINARY(" because
299 // this would be a BINARY or VARBINARY field type
300 $type = preg_replace('@BINARY([^\(])@i', '', $type);
301 $type = preg_replace('@ZEROFILL@i', '', $type);
302 $type = preg_replace('@UNSIGNED@i', '', $type);
303 $length = $extracted_fieldspec['spec_in_brackets'];
304 } // end if else
305 } else {
306 // creating a column
307 $length = '';
310 // some types, for example longtext, are reported as
311 // "longtext character set latin7" when their charset and / or collation
312 // differs from the ones of the corresponding database.
313 $tmp = strpos($type, 'character set');
314 if ($tmp) {
315 $type = substr($type, 0, $tmp - 1);
318 if (isset($submit_length) && $submit_length != false) {
319 $length = $submit_length;
322 // rtrim the type, for cases like "float unsigned"
323 $type = rtrim($type);
324 $type_upper = strtoupper($type);
326 $content_cells[$i][$ci] .= PMA_getSupportedDatatypes(true, $type_upper);
327 $content_cells[$i][$ci] .= ' </select>';
328 $ci++;
330 // old column length
331 if ($is_backup) {
332 $_form_params['field_length_orig[' . $i . ']'] = $length;
335 // column length
336 if (isset($extracted_fieldspec) && ('set' == $extracted_fieldspec['type'] || 'enum' == $extracted_fieldspec['type'])) {
337 $binary = 0;
338 $unsigned = 0;
339 $zerofill = 0;
340 } else {
341 $binary = false;
342 $unsigned = stristr($row['Type'], 'unsigned');
343 $zerofill = stristr($row['Type'], 'zerofill');
345 $length_to_display = $length;
347 $content_cells[$i][$ci] = '<input id="field_' . $i . '_' . ($ci - $ci_offset) . '"'
348 . ' type="text" name="field_length[' . $i . ']" size="' . $length_values_input_size . '"'
349 . ' value="' . htmlspecialchars($length_to_display) . '"'
350 . ' class="textfield" />'
351 . '<p class="enum_notice" id="enum_notice_' . $i . '_' . ($ci - $ci_offset) . '">';
352 $content_cells[$i][$ci] .= __('ENUM or SET data too long?')
353 . '<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"> '
354 . __('Get more editing space') . '</a></p>';
355 $ci++;
357 // column default
359 * having NULL enabled does not implicit having Default with NULL
361 if (isset($row)
362 && ! isset($row['Default']) && isset($row['Null']) && $row['Null'] == 'YES') {
363 $row['Default'] = 'NULL';
367 // old column default
368 if ($is_backup) {
369 $_form_params['field_default_orig[' . $i . ']'] =
370 (isset($row['Default']) ? $row['Default'] : '');
373 // here we put 'NONE' as the default value of drop-down; otherwise
374 // users would have problems if they forget to enter the default
375 // value (example, for an INT)
376 $default_options = array(
377 'NONE' => _pgettext('for default', 'None'),
378 'USER_DEFINED' => __('As defined:'),
379 'NULL' => 'NULL',
380 'CURRENT_TIMESTAMP' => 'CURRENT_TIMESTAMP',
383 // for a TIMESTAMP, do not show the string "CURRENT_TIMESTAMP" as a default value
384 if ($type_upper == 'TIMESTAMP'
385 && ! empty($default_current_timestamp)
386 && isset($row['Default'])) {
387 $row['Default'] = '';
390 if ($type_upper == 'BIT') {
391 $row['DefaultValue'] = PMA_convert_bit_default_value($row['DefaultValue']);
394 $content_cells[$i][$ci] = '<select name="field_default_type[' . $i . ']">';
395 foreach ($default_options as $key => $value) {
396 $content_cells[$i][$ci] .= '<option value="' . $key . '"';
397 // is only set when we go back to edit a field's structure
398 if (isset($row['DefaultType']) && $row['DefaultType'] == $key) {
399 $content_cells[$i][$ci] .= ' selected="selected"';
401 $content_cells[$i][$ci] .= ' >' . $value . '</option>';
403 $content_cells[$i][$ci] .= '</select>';
404 $content_cells[$i][$ci] .= '<br />';
405 $content_cells[$i][$ci] .= '<input id="field_' . $i . '_' . ($ci - $ci_offset) . '"'
406 . ' type="text" name="field_default_value[' . $i . ']" size="12"'
407 . ' value="' . (isset($row['DefaultValue']) ? htmlspecialchars($row['DefaultValue']) : '') . '"'
408 . ' class="textfield" />';
409 $ci++;
411 // column collation
412 $tmp_collation = empty($row['Collation']) ? null : $row['Collation'];
413 $content_cells[$i][$ci] = PMA_generateCharsetDropdownBox(
414 PMA_CSDROPDOWN_COLLATION, 'field_collation[' . $i . ']',
415 'field_' . $i . '_' . ($ci - $ci_offset), $tmp_collation, false);
416 unset($tmp_collation);
417 $ci++;
419 // column attribute
420 $content_cells[$i][$ci] = '<select style="font-size: 70%;"'
421 . ' name="field_attribute[' . $i . ']"'
422 . ' id="field_' . $i . '_' . ($ci - $ci_offset) . '">';
424 $attribute = '';
425 if ($binary) {
426 $attribute = 'BINARY';
428 if ($unsigned) {
429 $attribute = 'UNSIGNED';
431 if ($zerofill) {
432 $attribute = 'UNSIGNED ZEROFILL';
434 if (isset($row['Extra']) && $row['Extra'] == 'on update CURRENT_TIMESTAMP') {
435 $attribute = 'on update CURRENT_TIMESTAMP';
438 if (isset($submit_attribute) && $submit_attribute != false) {
439 $attribute = $submit_attribute;
442 // here, we have a TIMESTAMP that SHOW FULL COLUMNS reports as having the
443 // NULL attribute, but SHOW CREATE TABLE says the contrary. Believe
444 // the latter.
445 if (PMA_MYSQL_INT_VERSION < 50025
446 && isset($row['Field'])
447 && isset($analyzed_sql[0]['create_table_fields'][$row['Field']]['type'])
448 && $analyzed_sql[0]['create_table_fields'][$row['Field']]['type'] == 'TIMESTAMP'
449 && $analyzed_sql[0]['create_table_fields'][$row['Field']]['timestamp_not_null'] == true) {
450 $row['Null'] = '';
453 // MySQL 4.1.2+ TIMESTAMP options
454 // (if on_update_current_timestamp is set, then it's TRUE)
455 if (isset($row['Field'])
456 && isset($analyzed_sql[0]['create_table_fields'][$row['Field']]['on_update_current_timestamp'])) {
457 $attribute = 'on update CURRENT_TIMESTAMP';
459 if ((isset($row['Field'])
460 && isset($analyzed_sql[0]['create_table_fields'][$row['Field']]['default_current_timestamp']))
461 || (isset($submit_default_current_timestamp) && $submit_default_current_timestamp)) {
462 $default_current_timestamp = true;
463 } else {
464 $default_current_timestamp = false;
467 $cnt_attribute_types = count($cfg['AttributeTypes']);
468 for ($j = 0; $j < $cnt_attribute_types; $j++) {
469 $content_cells[$i][$ci] .= ' <option value="'. $cfg['AttributeTypes'][$j] . '"';
470 if (strtoupper($attribute) == strtoupper($cfg['AttributeTypes'][$j])) {
471 $content_cells[$i][$ci] .= ' selected="selected"';
473 $content_cells[$i][$ci] .= '>' . $cfg['AttributeTypes'][$j] . '</option>';
476 $content_cells[$i][$ci] .= '</select>';
477 $ci++;
479 // column NULL
480 $content_cells[$i][$ci] = '<input name="field_null[' . $i . ']"'
481 . ' id="field_' . $i . '_' . ($ci - $ci_offset) . '"';
483 if (! empty($row['Null']) && $row['Null'] != 'NO' && $row['Null'] != 'NOT NULL') {
484 $content_cells[$i][$ci] .= ' checked="checked"';
487 $content_cells[$i][$ci] .= ' type="checkbox" value="NULL" />';
488 $ci++;
490 // column indexes
491 // See my other comment about removing this 'if'.
492 if (!$is_backup) {
493 $content_cells[$i][$ci] = '<select name="field_key[' . $i . ']"'
494 . ' id="field_' . $i . '_' . ($ci - $ci_offset) . '">';
495 $content_cells[$i][$ci] .= '<option value="none_' . $i . '">---</option>';
497 $content_cells[$i][$ci] .= '<option value="primary_' . $i . '" title="' . __('Primary') . '"';
498 if (isset($row['Key']) && $row['Key'] == 'PRI') {
499 $content_cells[$i][$ci] .= ' selected="selected"';
501 $content_cells[$i][$ci] .= '>PRIMARY</option>';
503 $content_cells[$i][$ci] .= '<option value="unique_' . $i . '" title="' . __('Unique') . '"';
504 if (isset($row['Key']) && $row['Key'] == 'UNI') {
505 $content_cells[$i][$ci] .= ' selected="selected"';
507 $content_cells[$i][$ci] .= '>UNIQUE</option>';
509 $content_cells[$i][$ci] .= '<option value="index_' . $i . '" title="' . __('Index') . '"';
510 if (isset($row['Key']) && $row['Key'] == 'MUL') {
511 $content_cells[$i][$ci] .= ' selected="selected"';
513 $content_cells[$i][$ci] .= '>INDEX</option>';
515 if (!PMA_DRIZZLE) {
516 $content_cells[$i][$ci] .= '<option value="fulltext_' . $i . '" title="' . __('Fulltext') . '"';
517 if (isset($row['Key']) && $row['Key'] == 'FULLTEXT') {
518 $content_cells[$i][$ci] .= ' selected="selected"';
520 $content_cells[$i][$ci] .= '>FULLTEXT</option>';
523 $content_cells[$i][$ci] .= '</select>';
524 $ci++;
525 } // end if ($action ==...)
527 // column auto_increment
528 $content_cells[$i][$ci] = '<input name="field_extra[' . $i . ']"'
529 . ' id="field_' . $i . '_' . ($ci - $ci_offset) . '"';
531 if (isset($row['Extra']) && strtolower($row['Extra']) == 'auto_increment') {
532 $content_cells[$i][$ci] .= ' checked="checked"';
535 $content_cells[$i][$ci] .= ' type="checkbox" value="AUTO_INCREMENT" />';
536 $ci++;
538 // column comments
539 $content_cells[$i][$ci] = '<input id="field_' . $i . '_' . ($ci - $ci_offset) . '"'
540 . ' type="text" name="field_comments[' . $i . ']" size="12"'
541 . ' value="' . (isset($row['Field']) && is_array($comments_map) && isset($comments_map[$row['Field']]) ? htmlspecialchars($comments_map[$row['Field']]) : '') . '"'
542 . ' class="textfield" />';
543 $ci++;
545 // column MIME-types
546 if ($cfgRelation['mimework'] && $cfg['BrowseMIME'] && $cfgRelation['commwork']) {
547 $content_cells[$i][$ci] = '<select id="field_' . $i . '_' . ($ci - $ci_offset) . '" size="1" name="field_mimetype[' . $i . ']">';
548 $content_cells[$i][$ci] .= ' <option value="">&nbsp;</option>';
550 if (is_array($available_mime['mimetype'])) {
551 foreach ($available_mime['mimetype'] AS $mimekey => $mimetype) {
552 $checked = (isset($row['Field']) && isset($mime_map[$row['Field']]['mimetype']) && ($mime_map[$row['Field']]['mimetype'] == str_replace('/', '_', $mimetype)) ? 'selected ' : '');
553 $content_cells[$i][$ci] .= ' <option value="' . str_replace('/', '_', $mimetype) . '" ' . $checked . '>' . htmlspecialchars($mimetype) . '</option>';
557 $content_cells[$i][$ci] .= '</select>';
558 $ci++;
560 $content_cells[$i][$ci] = '<select id="field_' . $i . '_' . ($ci - $ci_offset) . '" size="1" name="field_transformation[' . $i . ']">';
561 $content_cells[$i][$ci] .= ' <option value="" title="' . __('None') . '"></option>';
562 if (is_array($available_mime['transformation'])) {
563 foreach ($available_mime['transformation'] AS $mimekey => $transform) {
564 $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 ' : '');
565 $tooltip = 'strTransformation_' . strtolower(str_replace('.inc.php', '', $available_mime['transformation_file'][$mimekey]));
566 $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 . '()');
567 $content_cells[$i][$ci] .= '<option value="' . $available_mime['transformation_file'][$mimekey] . '" ' . $checked . ' title="' . htmlspecialchars($tooltip) . '">' . htmlspecialchars($transform) . '</option>';
571 $content_cells[$i][$ci] .= '</select>';
572 $ci++;
574 $content_cells[$i][$ci] = '<input id="field_' . $i . '_' . ($ci - $ci_offset) . '"'
575 . ' type="text" name="field_transformation_options[' . $i . ']"'
576 . ' size="16" class="textfield"'
577 . ' value="' . (isset($row['Field']) && isset($mime_map[$row['Field']]['transformation_options']) ? htmlspecialchars($mime_map[$row['Field']]['transformation_options']) : '') . '"'
578 . ' />';
579 //$ci++;
581 } // end for
584 <script src="./js/keyhandler.js" type="text/javascript"></script>
585 <script type="text/javascript">
586 // <![CDATA[
587 var switch_movement = <?php echo $display_type == 'horizontal' ? '0' : '1'; ?>;
588 document.onkeydown = onKeyDownArrowsHandler;
589 // ]]>
590 </script>
592 <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"' : ''); ?>>
593 <?php
594 echo PMA_generate_common_hidden_inputs($_form_params);
595 unset($_form_params);
596 if ($action == 'tbl_create.php') {
598 <table>
599 <tr valign="top">
600 <th><?php echo __('Table name'); ?>:&nbsp;</th>
601 </tr>
602 <tr><td><input type="text" name="table" size="40" maxlength="80"
603 value="<?php echo (isset($_REQUEST['table']) ? htmlspecialchars($_REQUEST['table']) : ''); ?>"
604 class="textfield" />
605 </td>
606 <td>
607 <?php if ($action == 'tbl_create.php' || $action == 'tbl_addfield.php') { ?>
608 <?php echo sprintf(__('Add %s column(s)'), '<input type="text" id="added_fields" name="added_fields" size="2" value="1" onfocus="this.select()" />'); ?>
609 <input type="submit" name="submit_num_fields" value="<?php echo __('Go'); ?>"
610 onclick="return checkFormElementInRange(this.form, 'added_fields', '<?php echo str_replace('\'', '\\\'', __('You have to add at least one column.')); ?>', 1)"
612 <?php } ?>
613 </td>
614 </tr>
615 </table>
616 <?php
620 if (is_array($content_cells) && is_array($header_cells)) {
621 // last row is for javascript insert
622 //$empty_row = array_pop($content_cells);
624 echo '<table id="table_columns">';
625 echo '<caption class="tblHeaders">' . __('Structure') . PMA_showMySQLDocu('SQL-Syntax', 'CREATE_TABLE') . '</caption>';
627 if ($display_type == 'horizontal') {
629 <tr>
630 <?php foreach ($header_cells as $header_val) { ?>
631 <th><?php echo $header_val; ?></th>
632 <?php } ?>
633 </tr>
634 <?php
636 $odd_row = true;
637 foreach ($content_cells as $content_row) {
638 echo '<tr class="' . ($odd_row ? 'odd' : 'even') . ' noclick">';
639 $odd_row = ! $odd_row;
641 if (is_array($content_row)) {
642 foreach ($content_row as $content_row_val) {
644 <td align="center"><?php echo $content_row_val; ?></td>
645 <?php
648 echo '</tr>';
650 } else {
651 $i = 0;
652 $odd_row = true;
653 foreach ($header_cells as $header_val) {
654 echo '<tr class="' . ($odd_row ? 'odd' : 'even') . ' noclick">';
655 $odd_row = ! $odd_row;
657 <th><?php echo $header_val; ?></th>
658 <?php
659 foreach ($content_cells as $content_cell) {
660 if (isset($content_cell[$i]) && $content_cell[$i] != '') {
662 <td><?php echo $content_cell[$i]; ?></td>
663 <?php
666 echo '</tr>';
667 $i++;
671 </table>
672 <br />
673 <?php
677 * needs to be finished
680 if ($display_type == 'horizontal') {
681 $new_field = '';
682 foreach ($empty_row as $content_row_val) {
683 $new_field .= '<td align="center">' . $content_row_val . '</td>';
686 <script type="text/javascript">
687 // <![CDATA[
688 var odd_row = <?php echo $odd_row; ?>;
690 function addField() {
691 var new_fields = document.getElementById('added_fields').value;
692 var new_field_container = document.getElementById('table_columns');
693 var new_field = '<?php echo preg_replace('|\s+|', ' ', preg_replace('|\'|', '\\\'', $new_field)); ?>';
694 var i = 0;
695 for (i = 0; i < new_fields; i++) {
696 if (odd_row) {
697 new_field_container.innerHTML += '<tr class="odd">' + new_field + '</tr>';
698 } else {
699 new_field_container.innerHTML += '<tr class="even">' + new_field + '</tr>';
701 odd_row = ! odd_row;
704 return true;
706 // ]]>
707 </script>
708 <?php
712 if ($action == 'tbl_create.php') {
714 <table>
715 <tr valign="top">
716 <th><?php echo __('Table comments'); ?>:&nbsp;</th>
717 <td width="25">&nbsp;</td>
718 <th><?php echo __('Storage Engine'); ?>:
719 <?php echo PMA_showMySQLDocu('Storage_engines', 'Storage_engines'); ?>
720 </th>
721 <td width="25">&nbsp;</td>
722 <th><?php echo __('Collation') ;?>:&nbsp;</th>
723 </tr>
724 <tr><td><input type="text" name="comment" size="40" maxlength="80"
725 value="<?php echo (isset($_REQUEST['comment']) ? htmlspecialchars($_REQUEST['comment']) : ''); ?>"
726 class="textfield" />
727 </td>
728 <td width="25">&nbsp;</td>
729 <td>
730 <?php
731 echo PMA_StorageEngine::getHtmlSelect('tbl_type', null,
732 (isset($_REQUEST['tbl_type']) ? $_REQUEST['tbl_type'] : null));
734 </td>
735 <td width="25">&nbsp;</td>
736 <td>
737 <?php
738 echo PMA_generateCharsetDropdownBox(PMA_CSDROPDOWN_COLLATION, 'tbl_collation',
739 null, (isset($_REQUEST['tbl_collation']) ? $_REQUEST['tbl_collation'] : null), false, 3);
741 </td>
742 </tr>
743 <?php
744 if (PMA_Partition::havePartitioning()) {
746 <tr valign="top">
747 <th><?php echo __('PARTITION definition'); ?>:&nbsp;<?php echo PMA_showMySQLDocu('Partitioning', 'Partitioning'); ?>
748 </th>
749 </tr>
750 <tr>
751 <td>
752 <textarea name="partition_definition" id="partitiondefinition"
753 cols="<?php echo $GLOBALS['cfg']['TextareaCols'];?>"
754 rows="<?php echo $GLOBALS['cfg']['TextareaRows'];?>"
755 dir="<?php echo $GLOBALS['text_dir'];?>"><?php echo (isset($_REQUEST['partition_definition']) ? htmlspecialchars($_REQUEST['partition_definition']) : ''); ?></textarea>
756 </td>
757 </tr>
758 <?php
761 </table>
762 <br />
763 <?php
764 } // end if ($action == 'tbl_create.php')
767 <fieldset class="tblFooters">
768 <input type="submit" name="do_save_data" value="<?php echo __('Save'); ?>" />
769 </fieldset>
770 <div id="properties_message"></div>
771 </form>
773 <div id="enum_editor">
774 <a class="close_enum_editor"><?php echo __('Close'); ?></a>
775 <h3><?php printf(__('Values for the column "%s"'), isset($row['Field']) ? htmlspecialchars($row['Field']) : ""); ?></h3>
776 <p><?php echo __('Enter each value in a separate field.'); ?></p>
777 <div id="values"></div>
778 <p><a class="add_value"><?php echo __('+ Add a value'); ?></a></p>
779 <input type="submit" value="<?php echo __('Go'); ?>" /> <a class="cancel_enum_editor"><?php echo __('Cancel'); ?></a>
780 </div>
782 <div id="popup_background"></div>