Upgraded phpmyadmin to 4.0.4 (All Languages) - No modifications yet
[openemr.git] / phpmyadmin / libraries / tbl_columns_definition_form.inc.php
blob4acf33abf0c06e945ab660da422773cd4674d49c
1 <?php
2 /* vim: set expandtab sw=4 ts=4 sts=4: */
3 /**
4 * Display form for changing/adding table fields/columns.
5 * Included by tbl_addfield.php and tbl_create.php
7 * @package PhpMyAdmin
8 */
9 if (! defined('PHPMYADMIN')) {
10 exit;
13 /**
14 * Check parameters
16 require_once './libraries/Util.class.php';
18 PMA_Util::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 /**
31 * We are in transition between old-style echo and new-style PMA_Response
32 * so this script generates $html and at the bottom, either echos it
33 * or uses addHTML on it.
35 * Initialize $html in case this variable was used by a caller
36 * (yes, this script should be refactored into functions)
38 $html = '';
40 $length_values_input_size = 8;
42 $_form_params = array(
43 'db' => $db
46 if ($action == 'tbl_create.php') {
47 $_form_params['reload'] = 1;
48 } elseif ($action == 'tbl_addfield.php') {
49 $_form_params['field_where'] = $_REQUEST['field_where'];
50 $_form_params['after_field'] = $_REQUEST['after_field'];
51 $_form_params['table'] = $table;
52 } else {
53 $_form_params['table'] = $table;
56 if (isset($num_fields)) {
57 $_form_params['orig_num_fields'] = $num_fields;
60 if (isset($_REQUEST['field_where'])) {
61 $_form_params['orig_field_where'] = $_REQUEST['field_where'];
64 if (isset($_REQUEST['after_field'])) {
65 $_form_params['orig_after_field'] = $_REQUEST['after_field'];
68 if (isset($selected) && is_array($selected)) {
69 foreach ($selected as $o_fld_nr => $o_fld_val) {
70 $_form_params['selected[' . $o_fld_nr . ']'] = $o_fld_val;
71 if (! isset($true_selected)) {
72 $_form_params['true_selected[' . $o_fld_nr . ']'] = $o_fld_val;
76 if (isset($true_selected) && is_array($true_selected)) {
77 foreach ($true_selected as $o_fld_nr => $o_fld_val) {
78 $_form_params['true_selected[' . $o_fld_nr . ']'] = $o_fld_val;
81 } elseif (isset($_REQUEST['field'])) {
82 $_form_params['orig_field'] = $_REQUEST['field'];
83 if (isset($orig_field)) {
84 $_form_params['true_selected[]'] = $orig_field;
85 } else {
86 $_form_params['true_selected[]'] = $_REQUEST['field'];
90 $is_backup = ($action != 'tbl_create.php' && $action != 'tbl_addfield.php');
92 $header_cells = array();
93 $content_cells = array();
95 $header_cells[] = __('Name');
96 $header_cells[] = __('Type')
97 . PMA_Util::showMySQLDocu('SQL-Syntax', 'data-types');
98 $header_cells[] = __('Length/Values')
99 . PMA_Util::showHint(
101 'If column type is "enum" or "set", please enter the values using'
102 . ' this format: \'a\',\'b\',\'c\'…<br />If you ever need to put'
103 . ' a backslash ("\") or a single quote ("\'") amongst those values,'
104 . ' precede it with a backslash (for example \'\\\\xyz\' or \'a\\\'b\').'
107 $header_cells[] = __('Default')
108 . PMA_Util::showHint(
110 'For default values, please enter just a single value,'
111 . ' 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, structure.lib.php must be modified
120 // to use the key fields, as tbl_addfield does.
122 if (! $is_backup) {
123 $header_cells[] = __('Index');
126 $header_cells[] = '<abbr title="AUTO_INCREMENT">A_I</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 (isset($fields_meta)) {
139 // for moving, load all available column names
140 $move_columns_sql_query = 'SELECT * FROM '
141 . PMA_Util::backquote($db)
142 . '.'
143 . PMA_Util::backquote($table)
144 . ' LIMIT 1';
145 $move_columns_sql_result = PMA_DBI_try_query($move_columns_sql_query);
146 $move_columns = PMA_DBI_get_fields_meta($move_columns_sql_result);
147 unset($move_columns_sql_query, $move_columns_sql_result);
149 $header_cells[] = __('Move column');
152 if ($cfgRelation['mimework'] && $GLOBALS['cfg']['BrowseMIME']) {
153 $mime_map = PMA_getMIME($db, $table);
154 $available_mime = PMA_getAvailableMIMEtypes();
156 $hint = '<br />'
157 . sprintf(
159 'For a list of available transformation options and their MIME'
160 . ' type transformations, click on %stransformation descriptions%s'
162 '<a href="transformation_overview.php?'
163 . PMA_generate_common_url($db, $table)
164 . '" target="_blank">',
165 '</a>'
169 $header_cells[] = __('MIME type');
170 $header_cells[] = __('Browser transformation');
171 $header_cells[] = __('Transformation options')
172 . PMA_Util::showHint(
174 'Please enter the values for transformation options using this'
175 . ' format: \'a\', 100, b,\'c\'…<br />If you ever need to put'
176 . ' a backslash ("\") or a single quote ("\'") amongst those'
177 . ' values, precede it with a backslash (for example \'\\\\xyz\''
178 . ' or \'a\\\'b\').'
180 . $hint
184 // workaround for field_fulltext, because its submitted indices contain
185 // the index as a value, not a key. Inserted here for easier maintaineance
186 // and less code to change in existing files.
187 if (isset($field_fulltext) && is_array($field_fulltext)) {
188 foreach ($field_fulltext as $fulltext_nr => $fulltext_indexkey) {
189 $submit_fulltext[$fulltext_indexkey] = $fulltext_indexkey;
193 for ($i = 0; $i < $num_fields; $i++) {
194 if (! empty($regenerate)) {
195 // An error happened with previous inputs, so we will restore the data
196 // to embed it once again in this form.
198 $row['Field'] = isset($_REQUEST['field_name'][$i])
199 ? $_REQUEST['field_name'][$i]
200 : false;
201 $row['Type'] = isset($_REQUEST['field_type'][$i])
202 ? $_REQUEST['field_type'][$i]
203 : false;
204 $row['Collation'] = isset($_REQUEST['field_collation'][$i])
205 ? $_REQUEST['field_collation'][$i]
206 : '';
207 $row['Null'] = isset($_REQUEST['field_null'][$i])
208 ? $_REQUEST['field_null'][$i]
209 : '';
211 if (isset($_REQUEST['field_key'][$i])
212 && $_REQUEST['field_key'][$i] == 'primary_' . $i
214 $row['Key'] = 'PRI';
215 } elseif (isset($_REQUEST['field_key'][$i])
216 && $_REQUEST['field_key'][$i] == 'index_' . $i
218 $row['Key'] = 'MUL';
219 } elseif (isset($_REQUEST['field_key'][$i])
220 && $_REQUEST['field_key'][$i] == 'unique_' . $i
222 $row['Key'] = 'UNI';
223 } elseif (isset($_REQUEST['field_key'][$i])
224 && $_REQUEST['field_key'][$i] == 'fulltext_' . $i
226 $row['Key'] = 'FULLTEXT';
227 } else {
228 $row['Key'] = '';
231 // put None in the drop-down for Default, when someone adds a field
232 $row['DefaultType'] = isset($_REQUEST['field_default_type'][$i])
233 ? $_REQUEST['field_default_type'][$i]
234 : 'NONE';
235 $row['DefaultValue'] = isset($_REQUEST['field_default_value'][$i])
236 ? $_REQUEST['field_default_value'][$i]
237 : '';
239 switch ($row['DefaultType']) {
240 case 'NONE' :
241 $row['Default'] = null;
242 break;
243 case 'USER_DEFINED' :
244 $row['Default'] = $row['DefaultValue'];
245 break;
246 case 'NULL' :
247 case 'CURRENT_TIMESTAMP' :
248 $row['Default'] = $row['DefaultType'];
249 break;
252 $row['Extra']
253 = (isset($_REQUEST['field_extra'][$i])
254 ? $_REQUEST['field_extra'][$i]
255 : false);
256 $row['Comment']
257 = (isset($submit_fulltext[$i])
258 && ($submit_fulltext[$i] == $i)
259 ? 'FULLTEXT'
260 : false);
262 $submit_length
263 = (isset($_REQUEST['field_length'][$i])
264 ? $_REQUEST['field_length'][$i]
265 : false);
266 $submit_attribute
267 = (isset($_REQUEST['field_attribute'][$i])
268 ? $_REQUEST['field_attribute'][$i]
269 : false);
271 $submit_default_current_timestamp
272 = (isset($_REQUEST['field_default_current_timestamp'][$i])
273 ? true
274 : false);
276 if (isset($_REQUEST['field_comments'][$i])) {
277 $comments_map[$row['Field']] = $_REQUEST['field_comments'][$i];
280 if (isset($_REQUEST['field_mimetype'][$i])) {
281 $mime_map[$row['Field']]['mimetype'] = $_REQUEST['field_mimetype'][$i];
284 if (isset($_REQUEST['field_transformation'][$i])) {
285 $mime_map[$row['Field']]['transformation']
286 = $_REQUEST['field_transformation'][$i];
289 if (isset($_REQUEST['field_transformation_options'][$i])) {
290 $mime_map[$row['Field']]['transformation_options']
291 = $_REQUEST['field_transformation_options'][$i];
294 } elseif (isset($fields_meta[$i])) {
295 $row = $fields_meta[$i];
296 switch ($row['Default']) {
297 case null:
298 if ($row['Null'] == 'YES') {
299 $row['DefaultType'] = 'NULL';
300 $row['DefaultValue'] = '';
301 // SHOW FULL COLUMNS does not report the case
302 // when there is a DEFAULT value which is empty so we need to use the
303 // results of SHOW CREATE TABLE
304 } elseif (isset($row)
305 && isset($analyzed_sql[0]['create_table_fields'][$row['Field']]
306 ['default_value'])
308 $row['DefaultType'] = 'USER_DEFINED';
309 $row['DefaultValue'] = $row['Default'];
310 } else {
311 $row['DefaultType'] = 'NONE';
312 $row['DefaultValue'] = '';
314 break;
315 case 'CURRENT_TIMESTAMP':
316 $row['DefaultType'] = 'CURRENT_TIMESTAMP';
317 $row['DefaultValue'] = '';
318 break;
319 default:
320 $row['DefaultType'] = 'USER_DEFINED';
321 $row['DefaultValue'] = $row['Default'];
322 break;
326 if (isset($row['Type'])) {
327 $extracted_columnspec = PMA_Util::extractColumnSpec($row['Type']);
328 if ($extracted_columnspec['type'] == 'bit') {
329 $row['Default']
330 = PMA_Util::convertBitDefaultValue($row['Default']);
333 // Cell index: If certain fields get left out, the counter shouldn't change.
334 $ci = 0;
335 // Everytime a cell shall be left out the STRG-jumping feature, $ci_offset
336 // has to be incremented ($ci_offset++)
337 $ci_offset = -1;
339 // old column name
340 if ($is_backup) {
341 if (! empty($true_selected[$i])) {
342 $_form_params['field_orig[' . $i . ']'] = $true_selected[$i];
343 } elseif (isset($row['Field'])) {
344 $_form_params['field_orig[' . $i . ']'] = $row['Field'];
345 } else {
346 $_form_params['field_orig[' . $i . ']'] = '';
350 // column name
351 $content_cells[$i][$ci] = '<input id="field_' . $i . '_' . ($ci - $ci_offset)
352 . '"' . ' type="text" name="field_name[' . $i . ']"'
353 . ' maxlength="64" class="textfield" title="' . __('Column') . '"'
354 . ' size="10"'
355 . ' value="' . (isset($row['Field']) ? htmlspecialchars($row['Field']) : '')
356 . '"' . ' />';
357 $ci++;
359 // column type
360 $select_id = 'field_' . $i . '_' . ($ci - $ci_offset);
361 $content_cells[$i][$ci] = '<select class="column_type" name="field_type[' .
362 $i . ']"' .' id="' . $select_id . '">';
364 if (empty($row['Type'])) {
365 // creating a column
366 $row['Type'] = '';
367 $type = '';
368 $length = '';
369 } else {
370 $type = $extracted_columnspec['type'];
371 $length = $extracted_columnspec['spec_in_brackets'];
374 // some types, for example longtext, are reported as
375 // "longtext character set latin7" when their charset and / or collation
376 // differs from the ones of the corresponding database.
377 $tmp = strpos($type, 'character set');
378 if ($tmp) {
379 $type = substr($type, 0, $tmp - 1);
382 if (isset($submit_length) && $submit_length != false) {
383 $length = $submit_length;
386 // rtrim the type, for cases like "float unsigned"
387 $type = rtrim($type);
388 $type_upper = strtoupper($type);
390 $content_cells[$i][$ci]
391 .= PMA_Util::getSupportedDatatypes(true, $type_upper);
392 $content_cells[$i][$ci] .= ' </select>';
393 $ci++;
395 // old column length
396 if ($is_backup) {
397 $_form_params['field_length_orig[' . $i . ']'] = $length;
400 // column length
401 $length_to_display = $length;
403 $content_cells[$i][$ci] = '<input id="field_' . $i . '_' . ($ci - $ci_offset)
404 . '"' . ' type="text" name="field_length[' . $i . ']" size="'
405 . $length_values_input_size . '"' . ' value="' . htmlspecialchars(
406 $length_to_display
408 . '"'
409 . ' class="textfield" />'
410 . '<p class="enum_notice" id="enum_notice_' . $i . '_' . ($ci - $ci_offset)
411 . '">';
412 $content_cells[$i][$ci] .= __('ENUM or SET data too long?')
413 . '<a href="#" class="open_enum_editor"> '
414 . __('Get more editing space') . '</a>'
415 . '</p>';
416 $ci++;
418 // column default
420 // old column default
421 if ($is_backup) {
422 $_form_params['field_default_orig[' . $i . ']']
423 = (isset($row['Default']) ? $row['Default'] : '');
426 // here we put 'NONE' as the default value of drop-down; otherwise
427 // users would have problems if they forget to enter the default
428 // value (example, for an INT)
429 $default_options = array(
430 'NONE' => _pgettext('for default', 'None'),
431 'USER_DEFINED' => __('As defined:'),
432 'NULL' => 'NULL',
433 'CURRENT_TIMESTAMP' => 'CURRENT_TIMESTAMP',
436 // for a TIMESTAMP, do not show the string "CURRENT_TIMESTAMP" as a default value
437 if ($type_upper == 'TIMESTAMP'
438 && ! empty($default_current_timestamp)
439 && isset($row['Default'])
441 $row['Default'] = '';
444 if ($type_upper == 'BIT') {
445 $row['DefaultValue']
446 = PMA_Util::convertBitDefaultValue($row['DefaultValue']);
449 $content_cells[$i][$ci] = '<select name="field_default_type[' . $i
450 . ']" id="field_' . $i . '_' . ($ci - $ci_offset)
451 . '" class="default_type">';
452 foreach ($default_options as $key => $value) {
453 $content_cells[$i][$ci] .= '<option value="' . $key . '"';
454 // is only set when we go back to edit a field's structure
455 if (isset($row['DefaultType']) && $row['DefaultType'] == $key) {
456 $content_cells[$i][$ci] .= ' selected="selected"';
458 $content_cells[$i][$ci] .= ' >' . $value . '</option>';
460 $content_cells[$i][$ci] .= '</select>';
461 $content_cells[$i][$ci] .= '<br />';
462 $content_cells[$i][$ci] .= '<input type="text"'
463 . ' name="field_default_value[' . $i . ']" size="12"'
464 . ' value="' . (isset($row['DefaultValue'])
465 ? htmlspecialchars($row['DefaultValue'])
466 : '') . '"'
467 . ' class="textfield default_value" />';
468 $ci++;
470 // column collation
471 $tmp_collation = empty($row['Collation']) ? null : $row['Collation'];
472 $content_cells[$i][$ci] = PMA_generateCharsetDropdownBox(
473 PMA_CSDROPDOWN_COLLATION, 'field_collation[' . $i . ']',
474 'field_' . $i . '_' . ($ci - $ci_offset), $tmp_collation, false
476 unset($tmp_collation);
477 $ci++;
479 // column attribute
480 $content_cells[$i][$ci] = '<select style="font-size: 70%;"'
481 . ' name="field_attribute[' . $i . ']"'
482 . ' id="field_' . $i . '_' . ($ci - $ci_offset) . '">';
484 $attribute = '';
485 if (isset($extracted_columnspec)) {
486 $attribute = $extracted_columnspec['attribute'];
489 if (isset($row['Extra']) && $row['Extra'] == 'on update CURRENT_TIMESTAMP') {
490 $attribute = 'on update CURRENT_TIMESTAMP';
493 if (isset($submit_attribute) && $submit_attribute != false) {
494 $attribute = $submit_attribute;
497 // here, we have a TIMESTAMP that SHOW FULL COLUMNS reports as having the
498 // NULL attribute, but SHOW CREATE TABLE says the contrary. Believe
499 // the latter.
500 if (PMA_MYSQL_INT_VERSION < 50025
501 && isset($row['Field'])
502 && isset($analyzed_sql[0]['create_table_fields'][$row['Field']]['type'])
503 && $analyzed_sql[0]['create_table_fields'][$row['Field']]['type'] == 'TIMESTAMP'
504 && $analyzed_sql[0]['create_table_fields'][$row['Field']]['timestamp_not_null'] == true
506 $row['Null'] = '';
509 // MySQL 4.1.2+ TIMESTAMP options
510 // (if on_update_current_timestamp is set, then it's TRUE)
511 if (isset($row['Field'])
512 && isset($analyzed_sql[0]['create_table_fields'][$row['Field']]['on_update_current_timestamp'])
514 $attribute = 'on update CURRENT_TIMESTAMP';
516 if ((isset($row['Field'])
517 && isset($analyzed_sql[0]['create_table_fields'][$row['Field']]['default_current_timestamp']))
518 || (isset($submit_default_current_timestamp)
519 && $submit_default_current_timestamp)
521 $default_current_timestamp = true;
522 } else {
523 $default_current_timestamp = false;
526 $attribute_types = $GLOBALS['PMA_Types']->getAttributes();
527 $cnt_attribute_types = count($attribute_types);
528 for ($j = 0; $j < $cnt_attribute_types; $j++) {
529 $content_cells[$i][$ci]
530 .= ' <option value="' . $attribute_types[$j] . '"';
531 if (strtoupper($attribute) == strtoupper($attribute_types[$j])) {
532 $content_cells[$i][$ci] .= ' selected="selected"';
534 $content_cells[$i][$ci] .= '>' . $attribute_types[$j] . '</option>';
537 $content_cells[$i][$ci] .= '</select>';
538 $ci++;
540 // column NULL
541 $content_cells[$i][$ci] = '<input name="field_null[' . $i . ']"'
542 . ' id="field_' . $i . '_' . ($ci - $ci_offset) . '"';
544 if (! empty($row['Null'])
545 && $row['Null'] != 'NO'
546 && $row['Null'] != 'NOT NULL'
548 $content_cells[$i][$ci] .= ' checked="checked"';
551 $content_cells[$i][$ci] .= ' type="checkbox" value="NULL" class="allow_null"/>';
552 $ci++;
554 // column indexes
555 // See my other comment about removing this 'if'.
556 if (!$is_backup) {
557 $content_cells[$i][$ci] = '<select name="field_key[' . $i . ']"'
558 . ' id="field_' . $i . '_' . ($ci - $ci_offset) . '">';
559 $content_cells[$i][$ci] .= '<option value="none_' . $i . '">---</option>';
561 $content_cells[$i][$ci] .= '<option value="primary_' . $i . '" title="'
562 . __('Primary') . '"';
563 if (isset($row['Key']) && $row['Key'] == 'PRI') {
564 $content_cells[$i][$ci] .= ' selected="selected"';
566 $content_cells[$i][$ci] .= '>PRIMARY</option>';
568 $content_cells[$i][$ci] .= '<option value="unique_' . $i . '" title="'
569 . __('Unique') . '"';
570 if (isset($row['Key']) && $row['Key'] == 'UNI') {
571 $content_cells[$i][$ci] .= ' selected="selected"';
573 $content_cells[$i][$ci] .= '>UNIQUE</option>';
575 $content_cells[$i][$ci] .= '<option value="index_' . $i . '" title="'
576 . __('Index') . '"';
577 if (isset($row['Key']) && $row['Key'] == 'MUL') {
578 $content_cells[$i][$ci] .= ' selected="selected"';
580 $content_cells[$i][$ci] .= '>INDEX</option>';
582 if (!PMA_DRIZZLE) {
583 $content_cells[$i][$ci] .= '<option value="fulltext_' . $i . '" title="'
584 . __('Fulltext') . '"';
585 if (isset($row['Key']) && $row['Key'] == 'FULLTEXT') {
586 $content_cells[$i][$ci] .= ' selected="selected"';
588 $content_cells[$i][$ci] .= '>FULLTEXT</option>';
591 $content_cells[$i][$ci] .= '</select>';
592 $ci++;
593 } // end if ($action ==...)
595 // column auto_increment
596 $content_cells[$i][$ci] = '<input name="field_extra[' . $i . ']"'
597 . ' id="field_' . $i . '_' . ($ci - $ci_offset) . '"';
599 if (isset($row['Extra']) && strtolower($row['Extra']) == 'auto_increment') {
600 $content_cells[$i][$ci] .= ' checked="checked"';
603 $content_cells[$i][$ci] .= ' type="checkbox" value="AUTO_INCREMENT" />';
604 $ci++;
606 // column comments
607 $content_cells[$i][$ci] = '<input id="field_' . $i . '_' . ($ci - $ci_offset)
608 . '"' . ' type="text" name="field_comments[' . $i . ']" size="12"'
609 . ' value="' . (isset($row['Field'])
610 && is_array($comments_map)
611 && isset($comments_map[$row['Field']])
612 ? htmlspecialchars($comments_map[$row['Field']])
613 : '') . '"'
614 . ' class="textfield" />';
615 $ci++;
617 // move column
618 if (isset($fields_meta)) {
619 $content_cells[$i][$ci] = '<select id="field_' . $i . '_'
620 . ($ci - $ci_offset) . '"' . ' name="field_move_to[' . $i
621 . ']" size="1" width="5em">'
622 . '<option value="" selected="selected">&nbsp;</option>';
624 // find index of current column
625 $current_index = 0;
626 for ($mi = 0, $cols = count($move_columns); $mi < $cols; $mi++) {
627 if ($move_columns[$mi]->name == $row['Field']) {
628 $current_index = $mi;
629 break;
632 $content_cells[$i][$ci] .= '<option value="-first"'
633 . ($current_index == 0 ? ' disabled="disabled"' : '')
634 . '>' . __('first') . '</option>';
636 for ($mi = 0, $cols = count($move_columns); $mi < $cols; $mi++) {
637 $content_cells[$i][$ci] .=
638 '<option value="' . htmlspecialchars($move_columns[$mi]->name) . '"'
639 . (($current_index == $mi || $current_index == $mi + 1)
640 ? ' disabled="disabled"'
641 : '')
642 .'>'
643 . sprintf(
644 __('after %s'),
645 PMA_Util::backquote(
646 htmlspecialchars(
647 $move_columns[$mi]->name
651 . '</option>';
654 $content_cells[$i][$ci] .= '</select>';
655 $ci++;
658 // column MIME-types
659 if ($cfgRelation['mimework']
660 && $GLOBALS['cfg']['BrowseMIME']
661 && $cfgRelation['commwork']
663 $content_cells[$i][$ci] = '<select id="field_' . $i . '_'
664 . ($ci - $ci_offset) . '" size="1" name="field_mimetype[' . $i . ']">';
665 $content_cells[$i][$ci] .= ' <option value="">&nbsp;</option>';
667 if (is_array($available_mime['mimetype'])) {
668 foreach ($available_mime['mimetype'] as $mimekey => $mimetype) {
669 $checked = (isset($row['Field'])
670 && isset($mime_map[$row['Field']]['mimetype'])
671 && ($mime_map[$row['Field']]['mimetype']
672 == str_replace('/', '_', $mimetype))
673 ? 'selected '
674 : '');
675 $content_cells[$i][$ci] .= ' <option value="'
676 . str_replace('/', '_', $mimetype) . '" ' . $checked . '>'
677 . htmlspecialchars($mimetype) . '</option>';
681 $content_cells[$i][$ci] .= '</select>';
682 $ci++;
684 $content_cells[$i][$ci] = '<select id="field_' . $i . '_'
685 . ($ci - $ci_offset) . '" size="1" name="field_transformation['
686 . $i . ']">';
687 $content_cells[$i][$ci] .= ' <option value="" title="' . __('None')
688 . '"></option>';
689 if (is_array($available_mime['transformation'])) {
690 foreach ($available_mime['transformation'] as $mimekey => $transform) {
691 $checked = isset($row['Field'])
692 && isset($mime_map[$row['Field']]['transformation'])
693 && preg_match(
694 '@' . preg_quote(
695 $available_mime['transformation_file'][$mimekey]
696 ) . '3?@i',
697 $mime_map[$row['Field']]['transformation']
699 ? 'selected '
700 : '';
701 $tooltip = PMA_getTransformationDescription(
702 $available_mime['transformation_file'][$mimekey], false
704 $content_cells[$i][$ci] .= '<option value="'
705 . $available_mime['transformation_file'][$mimekey] . '" '
706 . $checked . ' title="' . htmlspecialchars($tooltip) . '">'
707 . htmlspecialchars($transform) . '</option>';
711 $content_cells[$i][$ci] .= '</select>';
712 $ci++;
714 $val = isset($row['Field'])
715 && isset($mime_map[$row['Field']]['transformation_options'])
716 ? htmlspecialchars($mime_map[$row['Field']]['transformation_options'])
717 : '';
718 $content_cells[$i][$ci] = '<input id="field_' . $i . '_'
719 . ($ci - $ci_offset) . '"' . ' type="text" '
720 . 'name="field_transformation_options[' . $i . ']"'
721 . ' size="16" class="textfield"'
722 . ' value="' . $val . '"'
723 . ' />';
724 //$ci++;
726 } // end for
728 $html .= '<form method="post" action="' . $action . '" class="'
729 . ($action == 'tbl_create.php' ? 'create_table' : 'append_fields')
730 . '_form ajax">';
732 $html .= PMA_generate_common_hidden_inputs($_form_params);
733 unset($_form_params);
734 if ($action == 'tbl_create.php') {
735 $html .= '<table>'
736 . '<tr class="vmiddle">'
737 . '<td>' . __('Table name')
738 . ':&nbsp;<input type="text" name="table" size="40" maxlength="80"'
739 . ' value="'
740 . (isset($_REQUEST['table']) ? htmlspecialchars($_REQUEST['table']) : '')
741 . '" class="textfield" autofocus />'
742 . '</td>'
743 . '<td>';
744 if ($action == 'tbl_create.php'
745 || $action == 'tbl_addfield.php'
747 $html .= sprintf(
748 __('Add %s column(s)'), '<input type="text" id="added_fields" '
749 . 'name="added_fields" size="2" value="1" onfocus="this.select'
750 . '()" />'
753 $html .= '<input type="submit" name="submit_num_fields"'
754 . 'value="' . __('Go') . '"'
755 . 'onclick="return'
756 . ' checkFormElementInRange(this.form, \'added_fields\', \''
757 . str_replace(
758 '\'', '\\\'', __('You have to add at least one column.')
759 ) . '\', 1)" />';
761 $html .= '</td>'
762 . '</tr>'
763 . '</table>';
766 if (is_array($content_cells) && is_array($header_cells)) {
767 // last row is for javascript insert
768 //$empty_row = array_pop($content_cells);
770 $html .= '<table id="table_columns" class="noclick">';
771 $html .= '<caption class="tblHeaders">' . __('Structure')
772 . PMA_Util::showMySQLDocu('SQL-Syntax', 'CREATE_TABLE') . '</caption>';
774 $html .= '<tr>';
775 foreach ($header_cells as $header_val) {
776 $html .= '<th>' . $header_val . '</th>';
778 $html .= '</tr>';
780 $odd_row = true;
781 foreach ($content_cells as $content_row) {
782 $html .= '<tr class="' . ($odd_row ? 'odd' : 'even') . '">';
783 $odd_row = ! $odd_row;
785 if (is_array($content_row)) {
786 foreach ($content_row as $content_row_val) {
787 $html .= '<td class="center">' . $content_row_val . '</td>';
790 $html .= '</tr>';
792 $html .= '</table>'
793 . '<br />';
797 * needs to be finished
800 if ($display_type == 'horizontal') {
801 $new_field = '';
802 foreach ($empty_row as $content_row_val) {
803 $new_field .= '<td class="center">' . $content_row_val . '</td>';
806 <script type="text/javascript">
807 // <![CDATA[
808 var odd_row = <?php echo $odd_row; ?>;
810 function addField()
812 var new_fields = document.getElementById('added_fields').value;
813 var new_field_container = document.getElementById('table_columns');
814 var new_field = '<?php echo preg_replace('|\s+|', ' ', preg_replace('|\'|', '\\\'', $new_field)); ?>';
815 var i = 0;
816 for (i = 0; i < new_fields; i++) {
817 if (odd_row) {
818 new_field_container.innerHTML += '<tr class="odd">' + new_field + '</tr>';
819 } else {
820 new_field_container.innerHTML += '<tr class="even">' + new_field + '</tr>';
822 odd_row = ! odd_row;
825 return true;
827 // ]]>
828 </script>
829 <?php
833 if ($action == 'tbl_create.php') {
834 $html .= '<table>'
835 . '<tr class="vtop">'
836 . '<th>' . __('Table comments') . ':&nbsp;</th>'
837 . '<td width="25">&nbsp;</td>'
838 . '<th>' . __('Storage Engine') . ':'
839 . PMA_Util::showMySQLDocu('Storage_engines', 'Storage_engines')
840 . '</th>'
841 . '<td width="25">&nbsp;</td>'
842 . '<th>' . __('Collation') . ':&nbsp;</th>'
843 . '</tr>'
844 . '<tr><td><input type="text" name="comment" size="40" maxlength="80"'
845 . 'value="'
846 . (isset($_REQUEST['comment'])
847 ? htmlspecialchars($_REQUEST['comment'])
848 : '')
849 . '" class="textfield" />'
850 . '</td>'
851 . '<td width="25">&nbsp;</td>'
852 . '<td>'
853 . PMA_StorageEngine::getHtmlSelect(
854 'tbl_storage_engine', null,
855 (isset($_REQUEST['tbl_storage_engine'])
856 ? $_REQUEST['tbl_storage_engine']
857 : null
860 . '</td>'
861 . '<td width="25">&nbsp;</td>'
862 . '<td>'
863 . PMA_generateCharsetDropdownBox(
864 PMA_CSDROPDOWN_COLLATION, 'tbl_collation', null,
865 (isset($_REQUEST['tbl_collation'])
866 ? $_REQUEST['tbl_collation']
867 : null
869 false, 3
871 . '</td>'
872 . '</tr>';
874 if (PMA_Partition::havePartitioning()) {
875 $html .= '<tr class="vtop">'
876 . '<th>' . __('PARTITION definition') . ':&nbsp;'
877 . PMA_Util::showMySQLDocu('Partitioning', 'Partitioning')
878 . '</th>'
879 . '</tr>'
880 . '<tr>'
881 . '<td>'
882 . '<textarea name="partition_definition" id="partitiondefinition"'
883 . ' cols="' . $GLOBALS['cfg']['TextareaCols'] . '"'
884 . ' rows="' . $GLOBALS['cfg']['TextareaRows'] . '"'
885 . ' dir="' . $GLOBALS['text_dir'] . '">'
886 . (isset($_REQUEST['partition_definition'])
887 ? htmlspecialchars($_REQUEST['partition_definition'])
888 : '')
889 . '</textarea>'
890 . '</td>'
891 . '</tr>';
893 $html .= '</table>'
894 . '<br />';
895 } // end if ($action == 'tbl_create.php')
897 $html .= '<fieldset class="tblFooters">'
898 . '<input type="submit" name="do_save_data" value="' . __('Save') . '" />'
899 . '</fieldset>'
900 . '<div id="properties_message"></div>'
901 . '</form>';
903 $html .= '<div id="popup_background"></div>';
905 PMA_Response::getInstance()->addHTML($html);