Translated using Weblate (Danish)
[phpmyadmin.git] / libraries / tbl_columns_definition_form.lib.php
blobbd8f14f5f6f40d41f871ce0fd6ee72b87010ee7b
1 <?php
2 /* vim: set expandtab sw=4 ts=4 sts=4: */
3 /**
4 * set of functions used by tbl_columns_definitions_form.inc.php
6 * @package PhpMyAdmin
7 */
8 if (!defined('PHPMYADMIN')) {
9 exit;
12 /**
13 * Function to get form parameters
15 * @param string $db database
16 * @param string $table table
17 * @param string $action action
18 * @param int $num_fields number of fields
19 * @param bool $selected selected
21 * @return array $form_params form parameters
23 function PMA_getFormsParameters($db, $table, $action, $num_fields, $selected)
25 $form_params = array(
26 'db' => $db
29 if ($action == 'tbl_create.php') {
30 $form_params['reload'] = 1;
31 } elseif ($action == 'tbl_addfield.php') {
32 $form_params['field_where'] = $_REQUEST['field_where'];
33 $form_params['after_field'] = $_REQUEST['after_field'];
34 $form_params['table'] = $table;
35 } else {
36 $form_params['table'] = $table;
39 if (isset($num_fields)) {
40 $form_params['orig_num_fields'] = $num_fields;
43 if (isset($_REQUEST['field_where'])) {
44 $form_params['orig_field_where'] = $_REQUEST['field_where'];
47 if (isset($_REQUEST['after_field'])) {
48 $form_params['orig_after_field'] = $_REQUEST['after_field'];
51 if (isset($selected) && is_array($selected)) {
52 foreach ($selected as $o_fld_nr => $o_fld_val) {
53 $form_params['selected[' . $o_fld_nr . ']'] = $o_fld_val;
57 return $form_params;
60 /**
61 * Function to get html for table comments, storage engine, collation and
62 * partition definition
64 * @return string
66 function PMA_getHtmlForTableConfigurations()
68 $html = '<table>'
69 . '<tr class="vtop">'
70 . '<th>' . __('Table comments:') . '</th>'
71 . '<td width="25">&nbsp;</td>'
72 . '<th>' . __('Storage Engine:')
73 . PMA_Util::showMySQLDocu('Storage_engines')
74 . '</th>'
75 . '<td width="25">&nbsp;</td>'
76 . '<th>' . __('Collation:') . '</th>'
77 . '</tr>'
78 . '<tr><td><input type="text" name="comment" size="40" maxlength="80"'
79 . ' value="'
80 . (isset($_REQUEST['comment'])
81 ? htmlspecialchars($_REQUEST['comment'])
82 : '')
83 . '" class="textfield" />'
84 . '</td>'
85 . '<td width="25">&nbsp;</td>'
86 . '<td>'
87 . PMA_StorageEngine::getHtmlSelect(
88 'tbl_storage_engine', null,
89 (isset($_REQUEST['tbl_storage_engine'])
90 ? $_REQUEST['tbl_storage_engine']
91 : null
94 . '</td>'
95 . '<td width="25">&nbsp;</td>'
96 . '<td>'
97 . PMA_generateCharsetDropdownBox(
98 PMA_CSDROPDOWN_COLLATION, 'tbl_collation', null,
99 (isset($_REQUEST['tbl_collation'])
100 ? $_REQUEST['tbl_collation']
101 : null
103 false, 3
105 . '</td>'
106 . '</tr>';
108 if (PMA_Partition::havePartitioning()) {
109 $html .= '<tr class="vtop">'
110 . '<th>' . __('PARTITION definition:') . '&nbsp;'
111 . PMA_Util::showMySQLDocu('Partitioning')
112 . '</th>'
113 . '</tr>'
114 . '<tr>'
115 . '<td>'
116 . '<textarea name="partition_definition" id="partitiondefinition"'
117 . ' cols="' . $GLOBALS['cfg']['TextareaCols'] . '"'
118 . ' rows="' . $GLOBALS['cfg']['TextareaRows'] . '"'
119 . ' dir="' . $GLOBALS['text_dir'] . '">'
120 . (isset($_REQUEST['partition_definition'])
121 ? htmlspecialchars($_REQUEST['partition_definition'])
122 : '')
123 . '</textarea>'
124 . '</td>'
125 . '</tr>';
127 $html .= '</table>'
128 . '<br />';
130 return $html;
134 * Function to get html for the footer
136 * @return string
138 function PMA_getHtmlForFooter()
140 $html = '<fieldset class="tblFooters">'
141 . '<input type="submit" name="do_save_data" value="' . __('Save') . '" />'
142 . '</fieldset>'
143 . '<div id="properties_message"></div>'
144 . '</form>';
146 $html .= '<div id="popup_background"></div>';
148 return $html;
152 * Function to get html for table create table name and number of fields
154 * @return string
156 function PMA_getHtmlForTableNameAndNoOfColumns()
158 $html = '<table>'
159 . '<tr class="vmiddle">'
160 . '<td>' . __('Table name')
161 . ':&nbsp;<input type="text" name="table" size="40" maxlength="80"'
162 . ' value="'
163 . (isset($_REQUEST['table']) ? htmlspecialchars($_REQUEST['table']) : '')
164 . '" class="textfield" autofocus required />'
165 . '</td>'
166 . '<td>';
167 $html .= sprintf(
168 __('Add %s column(s)'), '<input type="text" id="added_fields" '
169 . 'name="added_fields" size="2" value="1" onfocus="this.select'
170 . '()" />'
173 $html .= '<input type="submit" name="submit_num_fields"'
174 . 'value="' . __('Go') . '"'
175 . ' onclick="return'
176 . ' checkFormElementInRange(this.form, \'added_fields\', \''
177 . str_replace(
178 '\'', '\\\'', __('You have to add at least one column.')
179 ) . '\', 1)" />';
181 $html .= '</td>'
182 . '</tr>'
183 . '</table>';
185 return $html;
189 * Function to get html for table field definitions
191 * @param array $header_cells header cells
192 * @param array $content_cells content cells
194 * @return string
196 function PMA_getHtmlForTableFieldDefinitions($header_cells, $content_cells)
198 $html = '<table id="table_columns" class="noclick">';
199 $html .= '<caption class="tblHeaders">' . __('Structure')
200 . PMA_Util::showMySQLDocu('CREATE_TABLE') . '</caption>';
202 $html .= '<tr>';
203 foreach ($header_cells as $header_val) {
204 $html .= '<th>' . $header_val . '</th>';
206 $html .= '</tr>';
208 $odd_row = true;
209 foreach ($content_cells as $content_row) {
210 $html .= '<tr class="' . ($odd_row ? 'odd' : 'even') . '">';
211 $odd_row = ! $odd_row;
213 if (is_array($content_row)) {
214 foreach ($content_row as $content_row_val) {
215 $html .= '<td class="center">' . $content_row_val . '</td>';
218 $html .= '</tr>';
220 $html .= '</table>'
221 . '<br />';
223 return $html;
227 * Function to get html for the create table or field add view
229 * @param string $action action
230 * @param array $form_params forms parameters
231 * @param array $content_cells content cells
232 * @param array $header_cells header cells
234 * @return string
236 function PMA_getHtmlForTableCreateOrAddField($action, $form_params, $content_cells,
237 $header_cells
239 $html = '<form method="post" action="' . $action . '" class="'
240 . ($action == 'tbl_create.php' ? 'create_table' : 'append_fields')
241 . '_form ajax">';
242 $html .= PMA_URL_getHiddenInputs($form_params);
244 if ($action == 'tbl_create.php') {
245 $html .= PMA_getHtmlForTableNameAndNoOfColumns();
248 if (is_array($content_cells) && is_array($header_cells)) {
249 $html .= PMA_getHtmlForTableFieldDefinitions($header_cells, $content_cells);
252 if ($action == 'tbl_create.php') {
253 $html .= PMA_getHtmlForTableConfigurations();
256 $html .= PMA_getHtmlForFooter();
258 return $html;
262 * Function to get header cells
264 * @param bool $is_backup whether backup or not
265 * @param array $columnMeta column meta data
266 * @param bool $mimework whether mimework or not
267 * @param string $db current database
268 * @param string $table current table
270 * @return array
272 function PMA_getHeaderCells($is_backup, $columnMeta, $mimework, $db, $table)
274 $header_cells = array();
275 $header_cells[] = __('Name');
276 $header_cells[] = __('Type')
277 . PMA_Util::showMySQLDocu('data-types');
278 $header_cells[] = __('Length/Values')
279 . PMA_Util::showHint(
281 'If column type is "enum" or "set", please enter the values using'
282 . ' this format: \'a\',\'b\',\'c\'…<br />If you ever need to put'
283 . ' a backslash ("\") or a single quote ("\'") amongst those'
284 . ' values, precede it with a backslash (for example \'\\\\xyz\''
285 . ' or \'a\\\'b\').'
288 $header_cells[] = __('Default')
289 . PMA_Util::showHint(
291 'For default values, please enter just a single value,'
292 . ' without backslash escaping or quotes, using this format: a'
295 $header_cells[] = __('Collation');
296 $header_cells[] = __('Attributes');
297 $header_cells[] = __('Null');
299 // We could remove this 'if' and let the key information be shown and
300 // editable. However, for this to work, structure.lib.php must be modified
301 // to use the key fields, as tbl_addfield does.
302 if (! $is_backup) {
303 $header_cells[] = __('Index');
306 $header_cells[] = '<abbr title="AUTO_INCREMENT">A_I</abbr>';
307 $header_cells[] = __('Comments');
309 if (isset($columnMeta)) {
310 $header_cells[] = __('Move column');
313 if ($mimework && $GLOBALS['cfg']['BrowseMIME']) {
314 $hint = '<br />'
315 . sprintf(
317 'For a list of available transformation options and their MIME'
318 . ' type transformations, click on'
319 . ' %stransformation descriptions%s'
321 '<a href="transformation_overview.php?'
322 . PMA_URL_getCommon($db, $table)
323 . '" target="_blank">',
324 '</a>'
327 $header_cells[] = __('MIME type');
328 $header_cells[] = __('Browser transformation');
329 $header_cells[] = __('Transformation options')
330 . PMA_Util::showHint(
332 'Please enter the values for transformation options using this'
333 . ' format: \'a\', 100, b,\'c\'…<br />If you ever need to put'
334 . ' a backslash ("\") or a single quote ("\'") amongst those'
335 . ' values, precede it with a backslash (for example \'\\\\xyz\''
336 . ' or \'a\\\'b\').'
338 . $hint
342 return $header_cells;
346 * Function for moving, load all available column names
348 * @param string $db current database
349 * @param string $table current table
351 * @return array
353 function PMA_getMoveColumns($db, $table)
355 $move_columns_sql_query = 'SELECT * FROM '
356 . PMA_Util::backquote($db)
357 . '.'
358 . PMA_Util::backquote($table)
359 . ' LIMIT 1';
360 $move_columns_sql_result = $GLOBALS['dbi']->tryQuery($move_columns_sql_query);
361 $move_columns = $GLOBALS['dbi']->getFieldsMeta($move_columns_sql_result);
363 return $move_columns;
367 * Function to get row data for regenerating previous when error occurred.
369 * @param int $columnNumber coulmn number
370 * @param array $submit_fulltext submit full text
372 * @return array
374 function PMA_getRowDataForRegeneration($columnNumber, $submit_fulltext)
376 $columnMeta['Field'] = isset($_REQUEST['field_name'][$columnNumber])
377 ? $_REQUEST['field_name'][$columnNumber]
378 : false;
379 $columnMeta['Type'] = isset($_REQUEST['field_type'][$columnNumber])
380 ? $_REQUEST['field_type'][$columnNumber]
381 : false;
382 $columnMeta['Collation'] = isset($_REQUEST['field_collation'][$columnNumber])
383 ? $_REQUEST['field_collation'][$columnNumber]
384 : '';
385 $columnMeta['Null'] = isset($_REQUEST['field_null'][$columnNumber])
386 ? $_REQUEST['field_null'][$columnNumber]
387 : '';
389 $columnMeta['Key'] = '';
390 if (isset($_REQUEST['field_key'][$columnNumber])) {
391 $parts = explode($_REQUEST['field_key'][$columnNumber], '_', 2);
392 if (count($parts) == 2 && $parts[1] == $columnNumber) {
393 switch ($parts[0]) {
394 case 'primary':
395 $columnMeta['Key'] = 'PRI';
396 break;
397 case 'index':
398 $columnMeta['Key'] = 'MUL';
399 break;
400 case 'unique':
401 $columnMeta['Key'] = 'UNI';
402 break;
403 case 'fulltext':
404 $columnMeta['Key'] = 'FULLTEXT';
405 break;
410 // put None in the drop-down for Default, when someone adds a field
411 $columnMeta['DefaultType']
412 = isset($_REQUEST['field_default_type'][$columnNumber])
413 ? $_REQUEST['field_default_type'][$columnNumber]
414 : 'NONE';
415 $columnMeta['DefaultValue']
416 = isset($_REQUEST['field_default_value'][$columnNumber])
417 ? $_REQUEST['field_default_value'][$columnNumber]
418 : '';
420 switch ($columnMeta['DefaultType']) {
421 case 'NONE' :
422 $columnMeta['Default'] = null;
423 break;
424 case 'USER_DEFINED' :
425 $columnMeta['Default'] = $columnMeta['DefaultValue'];
426 break;
427 case 'NULL' :
428 case 'CURRENT_TIMESTAMP' :
429 $columnMeta['Default'] = $columnMeta['DefaultType'];
430 break;
433 $columnMeta['Extra']
434 = (isset($_REQUEST['field_extra'][$columnNumber])
435 ? $_REQUEST['field_extra'][$columnNumber]
436 : false);
437 $columnMeta['Comment']
438 = (isset($submit_fulltext[$columnNumber])
439 && ($submit_fulltext[$columnNumber] == $columnNumber)
440 ? 'FULLTEXT'
441 : false);
443 return $columnMeta;
447 * Function to get submit properties for regenerating previous when error occurred.
449 * @param int $columnNumber coulmn number
451 * @return array
453 function PMA_getSubmitPropertiesForRegeneration($columnNumber)
455 $submit_length
456 = (isset($_REQUEST['field_length'][$columnNumber])
457 ? $_REQUEST['field_length'][$columnNumber]
458 : false);
459 $submit_attribute
460 = (isset($_REQUEST['field_attribute'][$columnNumber])
461 ? $_REQUEST['field_attribute'][$columnNumber]
462 : false);
464 $submit_default_current_timestamp
465 = (isset($_REQUEST['field_default_current_timestamp'][$columnNumber])
466 ? true
467 : false);
469 return array(
470 $submit_length, $submit_attribute, $submit_default_current_timestamp
475 * An error happened with previous inputs, so we will restore the data
476 * to embed it once again in this form.
478 * @param int $columnNumber coulmn number
479 * @param array $submit_fulltext submit full text
480 * @param array $comments_map comments map
481 * @param array $mime_map mime map
483 * @return array
485 function PMA_handleRegeneration($columnNumber, $submit_fulltext, $comments_map,
486 $mime_map
488 $columnMeta = PMA_getRowDataForRegeneration(
489 $columnNumber, isset($submit_fulltext) ? $submit_fulltext : null
492 list($submit_length, $submit_attribute, $submit_default_current_timestamp)
493 = PMA_getSubmitPropertiesForRegeneration($columnNumber);
495 if (isset($_REQUEST['field_comments'][$columnNumber])) {
496 $comments_map[$columnMeta['Field']]
497 = $_REQUEST['field_comments'][$columnNumber];
500 if (isset($_REQUEST['field_mimetype'][$columnNumber])) {
501 $mime_map[$columnMeta['Field']]['mimetype']
502 = $_REQUEST['field_mimetype'][$columnNumber];
505 if (isset($_REQUEST['field_transformation'][$columnNumber])) {
506 $mime_map[$columnMeta['Field']]['transformation']
507 = $_REQUEST['field_transformation'][$columnNumber];
510 if (isset($_REQUEST['field_transformation_options'][$columnNumber])) {
511 $mime_map[$columnMeta['Field']]['transformation_options']
512 = $_REQUEST['field_transformation_options'][$columnNumber];
515 return array(
516 $columnMeta, $submit_length, $submit_attribute,
517 $submit_default_current_timestamp, $comments_map, $mime_map
522 * Function to get row data for $columnMeta set
524 * @param array $columnMeta column meta
525 * @param bool $isDefault whether the row value is default
527 * @return array
529 function PMA_getColumnMetaForDefault($columnMeta, $isDefault)
531 switch ($columnMeta['Default']) {
532 case null:
533 if ($columnMeta['Null'] == 'YES') {
534 $columnMeta['DefaultType'] = 'NULL';
535 $columnMeta['DefaultValue'] = '';
536 // SHOW FULL COLUMNS does not report the case
537 // when there is a DEFAULT value which is empty so we need to use the
538 // results of SHOW CREATE TABLE
539 } elseif ($isDefault) {
540 $columnMeta['DefaultType'] = 'USER_DEFINED';
541 $columnMeta['DefaultValue'] = $columnMeta['Default'];
542 } else {
543 $columnMeta['DefaultType'] = 'NONE';
544 $columnMeta['DefaultValue'] = '';
546 break;
547 case 'CURRENT_TIMESTAMP':
548 $columnMeta['DefaultType'] = 'CURRENT_TIMESTAMP';
549 $columnMeta['DefaultValue'] = '';
550 break;
551 default:
552 $columnMeta['DefaultType'] = 'USER_DEFINED';
553 $columnMeta['DefaultValue'] = $columnMeta['Default'];
554 break;
557 return $columnMeta;
561 * Function to get html for the column name
563 * @param int $columnNumber column number
564 * @param int $ci cell index
565 * @param int $ci_offset cell index offset
566 * @param array $columnMeta column meta
568 * @return string
570 function PMA_getHtmlForColumnName($columnNumber, $ci, $ci_offset, $columnMeta)
572 $html = '<input id="field_' . $columnNumber . '_' . ($ci - $ci_offset)
573 . '"' . ' type="text" name="field_name[' . $columnNumber . ']"'
574 . ' maxlength="64" class="textfield" title="' . __('Column') . '"'
575 . ' size="10"'
576 . ' value="'
577 . (isset($columnMeta['Field'])
578 ? htmlspecialchars($columnMeta['Field']) : '')
579 . '"' . ' />';
581 return $html;
585 * Function to get html for the column type
587 * @param int $columnNumber column number
588 * @param int $ci cell index
589 * @param int $ci_offset cell index offset
590 * @param string $type_upper type inuppercase
592 * @return string
594 function PMA_getHtmlForColumnType($columnNumber, $ci, $ci_offset, $type_upper)
596 $select_id = 'field_' . $columnNumber . '_' . ($ci - $ci_offset);
597 $html = '<select class="column_type" name="field_type[' .
598 $columnNumber . ']"' .' id="' . $select_id . '">';
599 $html .= PMA_Util::getSupportedDatatypes(true, $type_upper);
600 $html .= ' </select>';
602 return $html;
606 * Function to get html for transformation option
608 * @param int $columnNumber column number
609 * @param int $ci cell index
610 * @param int $ci_offset cell index offset
611 * @param array $columnMeta column meta
612 * @param array $mime_map mime map
614 * @return string
616 function PMA_getHtmlForTransformationOption($columnNumber, $ci, $ci_offset,
617 $columnMeta, $mime_map
619 $val = isset($columnMeta['Field'])
620 && isset($mime_map[$columnMeta['Field']]['transformation_options'])
621 ? htmlspecialchars(
622 $mime_map[$columnMeta['Field']]
623 ['transformation_options']
625 : '';
627 $html = '<input id="field_' . $columnNumber . '_'
628 . ($ci - $ci_offset) . '"' . ' type="text" '
629 . 'name="field_transformation_options[' . $columnNumber . ']"'
630 . ' size="16" class="textfield"'
631 . ' value="' . $val . '"'
632 . ' />';
634 return $html;
638 * Function to get html for mime type
640 * @param int $columnNumber column number
641 * @param int $ci cell index
642 * @param int $ci_offset cell index offset
643 * @param array $available_mime available mime
644 * @param array $columnMeta column meta
645 * @param array $mime_map mime map
647 * @return string
649 function PMA_getHtmlForMimeType($columnNumber, $ci, $ci_offset,
650 $available_mime, $columnMeta, $mime_map
652 $html = '<select id="field_' . $columnNumber . '_'
653 . ($ci - $ci_offset)
654 . '" size="1" name="field_mimetype[' . $columnNumber . ']">';
655 $html .= ' <option value="">&nbsp;</option>';
657 if (is_array($available_mime['mimetype'])) {
658 foreach ($available_mime['mimetype'] as $mimetype) {
659 $checked = (isset($columnMeta['Field'])
660 && isset($mime_map[$columnMeta['Field']]['mimetype'])
661 && ($mime_map[$columnMeta['Field']]['mimetype']
662 == str_replace('/', '_', $mimetype))
663 ? 'selected '
664 : '');
665 $html .= ' <option value="'
666 . str_replace('/', '_', $mimetype) . '" ' . $checked . '>'
667 . htmlspecialchars($mimetype) . '</option>';
671 $html .= '</select>';
673 return $html;
677 * Function to get html for browser transformation
679 * @param int $columnNumber column number
680 * @param int $ci cell index
681 * @param int $ci_offset cell index offset
682 * @param array $available_mime available mime
683 * @param array $columnMeta column meta
684 * @param array $mime_map mime map
686 * @return string
688 function PMA_getHtmlForBrowserTransformation($columnNumber, $ci, $ci_offset,
689 $available_mime, $columnMeta, $mime_map
691 $html = '<select id="field_' . $columnNumber . '_'
692 . ($ci - $ci_offset) . '" size="1" name="field_transformation['
693 . $columnNumber . ']">';
694 $html .= ' <option value="" title="' . __('None')
695 . '"></option>';
696 if (is_array($available_mime['transformation'])) {
697 foreach ($available_mime['transformation'] as $mimekey => $transform) {
698 $checked = isset($columnMeta['Field'])
699 && isset($mime_map[$columnMeta['Field']]['transformation'])
700 && preg_match(
701 '@' . preg_quote(
702 $available_mime['transformation_file'][$mimekey]
703 ) . '3?@i',
704 $mime_map[$columnMeta['Field']]['transformation']
706 ? 'selected '
707 : '';
708 $tooltip = PMA_getTransformationDescription(
709 $available_mime['transformation_file'][$mimekey], false
711 $html .= '<option value="'
712 . $available_mime['transformation_file'][$mimekey] . '" '
713 . $checked . ' title="' . htmlspecialchars($tooltip) . '">'
714 . htmlspecialchars($transform) . '</option>';
718 $html .= '</select>';
720 return $html;
724 * Function to get html for move column
726 * @param int $columnNumber column number
727 * @param int $ci cell index
728 * @param int $ci_offset cell index offset
729 * @param array $move_columns move columns
730 * @param array $columnMeta column meta
732 * @return string
734 function PMA_getHtmlForMoveColumn($columnNumber, $ci, $ci_offset, $move_columns,
735 $columnMeta
737 $html = '<select id="field_' . $columnNumber . '_'
738 . ($ci - $ci_offset) . '"' . ' name="field_move_to[' . $columnNumber
739 . ']" size="1" width="5em">'
740 . '<option value="" selected="selected">&nbsp;</option>';
741 // find index of current column
742 $current_index = 0;
743 for ($mi = 0, $cols = count($move_columns); $mi < $cols; $mi++) {
744 if ($move_columns[$mi]->name == $columnMeta['Field']) {
745 $current_index = $mi;
746 break;
750 $html .= '<option value="-first"'
751 . ($current_index == 0 ? ' disabled="disabled"' : '')
752 . '>' . __('first') . '</option>';
753 for ($mi = 0, $cols = count($move_columns); $mi < $cols; $mi++) {
754 $html .=
755 '<option value="' . htmlspecialchars($move_columns[$mi]->name) . '"'
756 . (($current_index == $mi || $current_index == $mi + 1)
757 ? ' disabled="disabled"'
758 : '')
759 .'>'
760 . sprintf(
761 __('after %s'),
762 PMA_Util::backquote(
763 htmlspecialchars(
764 $move_columns[$mi]->name
768 . '</option>';
771 $html .= '</select>';
773 return $html;
777 * Function to get html for column comment
779 * @param int $columnNumber column number
780 * @param int $ci cell index
781 * @param int $ci_offset cell index offset
782 * @param array $columnMeta column meta
783 * @param array $comments_map comments map
785 * @return string
787 function PMA_getHtmlForColumnComment($columnNumber, $ci, $ci_offset, $columnMeta,
788 $comments_map
790 $html = '<input id="field_' . $columnNumber . '_' . ($ci - $ci_offset)
791 . '"' . ' type="text" name="field_comments[' . $columnNumber
792 . ']" size="12"'
793 . ' value="' . (isset($columnMeta['Field'])
794 && is_array($comments_map)
795 && isset($comments_map[$columnMeta['Field']])
796 ? htmlspecialchars($comments_map[$columnMeta['Field']])
797 : '') . '"'
798 . ' class="textfield" />';
800 return $html;
804 * Function get html for column auto increment
806 * @param int $columnNumber column number
807 * @param int $ci cell index
808 * @param int $ci_offset cell index offset
809 * @param array $columnMeta column meta
811 * @return string
813 function PMA_getHtmlForColumnAutoIncrement($columnNumber, $ci, $ci_offset,
814 $columnMeta
816 $html = '<input name="field_extra[' . $columnNumber . ']"'
817 . ' id="field_' . $columnNumber . '_' . ($ci - $ci_offset) . '"';
818 if (isset($columnMeta['Extra'])
819 && strtolower($columnMeta['Extra']) == 'auto_increment'
821 $html .= ' checked="checked"';
824 $html .= ' type="checkbox" value="AUTO_INCREMENT" />';
826 return $html;
830 * Function to get html for the column indexes
832 * @param int $columnNumber column number
833 * @param int $ci cell index
834 * @param int $ci_offset cell index offset
835 * @param array $columnMeta column meta
837 * @return string
839 function PMA_getHtmlForColumnIndexes($columnNumber, $ci, $ci_offset, $columnMeta)
841 $html = '<select name="field_key[' . $columnNumber . ']"'
842 . ' id="field_' . $columnNumber . '_' . ($ci - $ci_offset) . '">';
843 $html .= '<option value="none_' . $columnNumber . '">---</option>';
845 $html .= PMA_getHtmlForIndexTypeOption(
846 $columnNumber, $columnMeta, 'Primary', 'PRI'
848 $html .= PMA_getHtmlForIndexTypeOption(
849 $columnNumber, $columnMeta, 'Unique', 'UNI'
851 $html .= PMA_getHtmlForIndexTypeOption(
852 $columnNumber, $columnMeta, 'Index', 'MUL'
854 if (!PMA_DRIZZLE) {
855 $html .= PMA_getHtmlForIndexTypeOption(
856 $columnNumber, $columnMeta, 'Fulltext', 'FULLTEXT'
860 $html .= '</select>';
862 return $html;
866 * Function to get html for the index options
868 * @param int $columnNumber column number
869 * @param array $columnMeta column meta
870 * @param string $type index type
871 * @param string $key column meta key
873 * @return string
876 function PMA_getHtmlForIndexTypeOption($columnNumber, $columnMeta, $type, $key)
878 $html = '<option value="' . strtolower($type) . '_' . $columnNumber
879 . '" title="'
880 . __($type) . '"';
881 if (isset($columnMeta['Key']) && $columnMeta['Key'] == $key) {
882 $html .= ' selected="selected"';
884 $html .= '>' . strtoupper($type) . '</option>';
886 return $html;
891 * Function to get html for column null
893 * @param int $columnNumber column number
894 * @param int $ci cell index
895 * @param int $ci_offset cell index offset
896 * @param array $columnMeta column meta
898 * @return string
900 function PMA_getHtmlForColumnNull($columnNumber, $ci, $ci_offset, $columnMeta)
902 $html = '<input name="field_null[' . $columnNumber . ']"'
903 . ' id="field_' . $columnNumber . '_' . ($ci - $ci_offset) . '"';
904 if (! empty($columnMeta['Null'])
905 && $columnMeta['Null'] != 'NO'
906 && $columnMeta['Null'] != 'NOT NULL'
908 $html .= ' checked="checked"';
911 $html .= ' type="checkbox" value="NULL" class="allow_null"/>';
913 return $html;
917 * Function to get html for column attribute
919 * @param int $columnNumber column number
920 * @param int $ci cell index
921 * @param int $ci_offset cell index offset
922 * @param array $extracted_columnspec extracted column
923 * @param array $columnMeta column meta
924 * @param bool $submit_attribute submit attribute
925 * @param array $analyzed_sql analyzed sql
926 * @param bool $submit_default_current_timestamp submit default current time stamp
928 * @return string
930 function PMA_getHtmlForColumnAttribute($columnNumber, $ci, $ci_offset,
931 $extracted_columnspec, $columnMeta, $submit_attribute, $analyzed_sql,
932 $submit_default_current_timestamp
934 $html = '<select style="font-size: 70%;"'
935 . ' name="field_attribute[' . $columnNumber . ']"'
936 . ' id="field_' . $columnNumber . '_' . ($ci - $ci_offset) . '">';
938 $attribute = '';
939 if (isset($extracted_columnspec)) {
940 $attribute = $extracted_columnspec['attribute'];
943 if (isset($columnMeta['Extra'])
944 && $columnMeta['Extra'] == 'on update CURRENT_TIMESTAMP'
946 $attribute = 'on update CURRENT_TIMESTAMP';
949 if (isset($submit_attribute) && $submit_attribute != false) {
950 $attribute = $submit_attribute;
953 // here, we have a TIMESTAMP that SHOW FULL COLUMNS reports as having the
954 // NULL attribute, but SHOW CREATE TABLE says the contrary. Believe
955 // the latter.
956 $create_table_fields = $analyzed_sql[0]['create_table_fields'];
957 if (PMA_MYSQL_INT_VERSION < 50025
958 && isset($columnMeta['Field'])
959 && isset($create_table_fields[$columnMeta['Field']]['type'])
960 && $create_table_fields[$columnMeta['Field']]['type'] == 'TIMESTAMP'
961 && $create_table_fields[$columnMeta['Field']]['timestamp_not_null'] == true
963 $columnMeta['Null'] = '';
966 // MySQL 4.1.2+ TIMESTAMP options
967 // (if on_update_current_timestamp is set, then it's TRUE)
968 if (isset($columnMeta['Field'])) {
969 $field = $create_table_fields[$columnMeta['Field']];
972 if (isset($field)
973 && isset($field['on_update_current_timestamp'])
975 $attribute = 'on update CURRENT_TIMESTAMP';
977 if ((isset($columnMeta['Field'])
978 && isset($field['default_current_timestamp']))
979 || (isset($submit_default_current_timestamp)
980 && $submit_default_current_timestamp)
982 $default_current_timestamp = true;
983 } else {
984 $default_current_timestamp = false;
987 $attribute_types = $GLOBALS['PMA_Types']->getAttributes();
988 $cnt_attribute_types = count($attribute_types);
989 for ($j = 0; $j < $cnt_attribute_types; $j++) {
990 $html
991 .= ' <option value="' . $attribute_types[$j] . '"';
992 if (strtoupper($attribute) == strtoupper($attribute_types[$j])) {
993 $html .= ' selected="selected"';
995 $html .= '>' . $attribute_types[$j] . '</option>';
998 $html .= '</select>';
1000 return $html;
1004 * Function to get html for column collation
1006 * @param int $columnNumber column number
1007 * @param int $ci cell index
1008 * @param int $ci_offset cell index offset
1009 * @param array $columnMeta column meta
1011 * @return string
1013 function PMA_getHtmlForColumnCollation($columnNumber, $ci, $ci_offset, $columnMeta)
1015 $tmp_collation
1016 = empty($columnMeta['Collation']) ? null : $columnMeta['Collation'];
1017 $html = PMA_generateCharsetDropdownBox(
1018 PMA_CSDROPDOWN_COLLATION, 'field_collation[' . $columnNumber . ']',
1019 'field_' . $columnNumber . '_' . ($ci - $ci_offset), $tmp_collation, false
1022 return $html;
1026 * Function get html for column length
1028 * @param int $columnNumber column number
1029 * @param int $ci cell index
1030 * @param int $ci_offset cell index offset
1031 * @param int $length_values_input_size length values input size
1032 * @param int $length_to_display length to disply
1034 * @return string
1036 function PMA_getHtmlForColumnLength($columnNumber, $ci, $ci_offset,
1037 $length_values_input_size, $length_to_display
1039 $html = '<input id="field_' . $columnNumber . '_' . ($ci - $ci_offset)
1040 . '"' . ' type="text" name="field_length[' . $columnNumber . ']" size="'
1041 . $length_values_input_size . '"' . ' value="' . htmlspecialchars(
1042 $length_to_display
1044 . '"'
1045 . ' class="textfield" />'
1046 . '<p class="enum_notice" id="enum_notice_' . $columnNumber . '_'
1047 . ($ci - $ci_offset)
1048 . '">';
1049 $html .= __('ENUM or SET data too long?')
1050 . '<a href="#" class="open_enum_editor"> '
1051 . __('Get more editing space') . '</a>'
1052 . '</p>';
1054 return $html;
1058 * Function to get html for the default column
1060 * @param int $columnNumber column number
1061 * @param int $ci cell index
1062 * @param int $ci_offset cell index offset
1063 * @param string $type_upper type upper
1064 * @param string $default_current_timestamp default current timestamp
1065 * @param array $columnMeta column meta
1067 * @return string
1069 function PMA_getHtmlForColumnDefault($columnNumber, $ci, $ci_offset, $type_upper,
1070 $default_current_timestamp, $columnMeta
1072 // here we put 'NONE' as the default value of drop-down; otherwise
1073 // users would have problems if they forget to enter the default
1074 // value (example, for an INT)
1075 $default_options = array(
1076 'NONE' => _pgettext('for default', 'None'),
1077 'USER_DEFINED' => __('As defined:'),
1078 'NULL' => 'NULL',
1079 'CURRENT_TIMESTAMP' => 'CURRENT_TIMESTAMP',
1082 // for a TIMESTAMP, do not show the string "CURRENT_TIMESTAMP" as a default
1083 // value
1084 if ($type_upper == 'TIMESTAMP'
1085 && ! empty($default_current_timestamp)
1086 && isset($columnMeta['Default'])
1088 $columnMeta['Default'] = '';
1091 if ($type_upper == 'BIT') {
1092 $columnMeta['DefaultValue']
1093 = PMA_Util::convertBitDefaultValue($columnMeta['DefaultValue']);
1096 $html = '<select name="field_default_type[' . $columnNumber
1097 . ']" id="field_' . $columnNumber . '_' . ($ci - $ci_offset)
1098 . '" class="default_type">';
1099 foreach ($default_options as $key => $value) {
1100 $html .= '<option value="' . $key . '"';
1101 // is only set when we go back to edit a field's structure
1102 if (isset($columnMeta['DefaultType'])
1103 && $columnMeta['DefaultType'] == $key
1105 $html .= ' selected="selected"';
1107 $html .= ' >' . $value . '</option>';
1109 $html .= '</select>';
1110 $html .= '<br />';
1111 $html .= '<input type="text"'
1112 . ' name="field_default_value[' . $columnNumber . ']" size="12"'
1113 . ' value="' . (isset($columnMeta['DefaultValue'])
1114 ? htmlspecialchars($columnMeta['DefaultValue'])
1115 : '') . '"'
1116 . ' class="textfield default_value" />';
1118 return $html;
1122 * Function to get html for column attributes
1124 * @param int $columnNumber column number
1125 * @param array $columnMeta column meta
1126 * @param string $type_upper type upper
1127 * @param int $length_values_input_size length values input size
1128 * @param int $length length
1129 * @param string $default_current_timestamp default current time stamp
1130 * @param array $extracted_columnspec extracted column spec
1131 * @param string $submit_attribute submit attribute
1132 * @param array $analyzed_sql analyzed sql
1133 * @param string $submit_default_current_timestamp submit default current time stamp
1134 * @param array $comments_map comments map
1135 * @param array $fields_meta fields map
1136 * @param bool $is_backup is backup
1137 * @param array $move_columns move columns
1138 * @param array $cfgRelation configuration relation
1139 * @param array $available_mime available mime
1140 * @param array $mime_map mime map
1142 * @return array
1144 function PMA_getHtmlForColumnAttributes($columnNumber, $columnMeta, $type_upper,
1145 $length_values_input_size, $length, $default_current_timestamp,
1146 $extracted_columnspec, $submit_attribute, $analyzed_sql,
1147 $submit_default_current_timestamp, $comments_map, $fields_meta, $is_backup,
1148 $move_columns, $cfgRelation, $available_mime, $mime_map
1150 // Cell index: If certain fields get left out, the counter shouldn't change.
1151 $ci = 0;
1152 // Everytime a cell shall be left out the STRG-jumping feature, $ci_offset
1153 // has to be incremented ($ci_offset++)
1154 $ci_offset = -1;
1156 $content_cell = array();
1158 // column name
1159 $content_cell[$ci] = PMA_getHtmlForColumnName(
1160 $columnNumber, $ci, $ci_offset, isset($columnMeta) ? $columnMeta : null
1162 $ci++;
1164 // column type
1165 $content_cell[$ci] = PMA_getHtmlForColumnType(
1166 $columnNumber, $ci, $ci_offset, $type_upper
1168 $ci++;
1170 // column length
1171 $content_cell[$ci] = PMA_getHtmlForColumnLength(
1172 $columnNumber, $ci, $ci_offset, $length_values_input_size, $length
1174 $ci++;
1176 // column default
1177 $content_cell[$ci] = PMA_getHtmlForColumnDefault(
1178 $columnNumber, $ci, $ci_offset,
1179 isset($type_upper) ? $type_upper : null,
1180 isset($default_current_timestamp) ? $default_current_timestamp : null,
1181 isset($columnMeta) ? $columnMeta : null
1183 $ci++;
1185 // column collation
1186 $content_cell[$ci] = PMA_getHtmlForColumnCollation(
1187 $columnNumber, $ci, $ci_offset, $columnMeta
1189 $ci++;
1191 // column attribute
1192 $content_cell[$ci] = PMA_getHtmlForColumnAttribute(
1193 $columnNumber, $ci, $ci_offset,
1194 isset($extracted_columnspec) ? $extracted_columnspec : null,
1195 isset($columnMeta) ? $columnMeta : null,
1196 isset($submit_attribute) ? $submit_attribute : null,
1197 isset($analyzed_sql) ? $analyzed_sql : null,
1198 isset($submit_default_current_timestamp)
1199 ? $submit_default_current_timestamp : null
1201 $ci++;
1203 // column NULL
1204 $content_cell[$ci] = PMA_getHtmlForColumnNull(
1205 $columnNumber, $ci, $ci_offset, isset($columnMeta) ? $columnMeta : null
1207 $ci++;
1209 // column indexes
1210 // See my other comment about this 'if'.
1211 if (!$is_backup) {
1212 $content_cell[$ci] = PMA_getHtmlForColumnIndexes(
1213 $columnNumber, $ci, $ci_offset, $columnMeta
1215 $ci++;
1216 } // end if ($action ==...)
1218 // column auto_increment
1219 $content_cell[$ci] = PMA_getHtmlForColumnAutoIncrement(
1220 $columnNumber, $ci, $ci_offset, $columnMeta
1222 $ci++;
1224 // column comments
1225 $content_cell[$ci] = PMA_getHtmlForColumnComment(
1226 $columnNumber, $ci, $ci_offset, isset($columnMeta) ? $columnMeta : null,
1227 $comments_map
1229 $ci++;
1231 // move column
1232 if (isset($fields_meta)) {
1233 $content_cell[$ci] = PMA_getHtmlForMoveColumn(
1234 $columnNumber, $ci, $ci_offset, $move_columns, $columnMeta
1236 $ci++;
1239 if ($cfgRelation['mimework']
1240 && $GLOBALS['cfg']['BrowseMIME']
1241 && $cfgRelation['commwork']
1243 // Column Mime-type
1244 $content_cell[$ci] = PMA_getHtmlForMimeType(
1245 $columnNumber, $ci, $ci_offset, $available_mime, $columnMeta, $mime_map
1247 $ci++;
1249 // Column Browser transformation
1250 $content_cell[$ci] = PMA_getHtmlForBrowserTransformation(
1251 $columnNumber, $ci, $ci_offset, $available_mime, $columnMeta, $mime_map
1253 $ci++;
1255 // column Transformation options
1256 $content_cell[$ci] = PMA_getHtmlForTransformationOption(
1257 $columnNumber, $ci, $ci_offset, isset($columnMeta) ? $columnMeta : null,
1258 isset($mime_map) ? $mime_map : null
1262 return $content_cell;
1266 * Function to get form parameters for old column
1268 * @param array $columnMeta column meta
1269 * @param int $length length
1270 * @param array $form_params form parameters
1272 * @return array
1274 function PMA_getFormParamsForOldColumn($columnMeta, $length, $form_params)
1276 if (isset($columnMeta['Field'])) {
1277 $form_params['field_orig[' . $columnNumber . ']']
1278 = $columnMeta['Field'];
1279 } else {
1280 $form_params['field_orig[' . $columnNumber . ']'] = '';
1282 // old column length
1283 $form_params['field_length_orig[' . $columnNumber . ']'] = $length;
1285 // old column default
1286 $form_params['field_default_orig[' . $columnNumber . ']']
1287 = (isset($columnMeta['Default']) ? $columnMeta['Default'] : '');
1289 return $form_params;