UPDATE 4.4.0.0
[phpmyadmin.git] / libraries / tbl_columns_definition_form.lib.php
blob4090efd160fdb73500f32f066217e51b30cc3820
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(
24 $db, $table, $action, $num_fields, $selected
25 ) {
26 $form_params = array(
27 'db' => $db
30 if ($action == 'tbl_create.php') {
31 $form_params['reload'] = 1;
32 } elseif ($action == 'tbl_addfield.php') {
33 $form_params['field_where'] = $_REQUEST['field_where'];
34 $form_params['after_field'] = $_REQUEST['after_field'];
35 $form_params['table'] = $table;
36 } else {
37 $form_params['table'] = $table;
40 if (isset($num_fields)) {
41 $form_params['orig_num_fields'] = $num_fields;
44 if (isset($_REQUEST['field_where'])) {
45 $form_params['orig_field_where'] = $_REQUEST['field_where'];
48 if (isset($_REQUEST['after_field'])) {
49 $form_params['orig_after_field'] = $_REQUEST['after_field'];
52 if (isset($selected) && is_array($selected)) {
53 foreach ($selected as $o_fld_nr => $o_fld_val) {
54 $form_params['selected[' . $o_fld_nr . ']'] = $o_fld_val;
58 return $form_params;
61 /**
62 * Function to get html for table comments, storage engine, collation and
63 * partition definition
65 * @return string
67 function PMA_getHtmlForTableConfigurations()
69 $html = '<table>';
70 $html .= '<tr class="vtop">'
71 . '<th>' . __('Table comments:') . '</th>'
72 . '<td width="25">&nbsp;</td>'
73 . '<th>' . __('Collation:') . '</th>'
74 . '<td width="25">&nbsp;</td>'
75 . '<th>'
76 . __('Storage Engine:')
77 . PMA_Util::showMySQLDocu('Storage_engines')
78 . '</th>'
79 . '<td width="25">&nbsp;</td>'
80 . '<th>'
81 . __('Connection:')
82 . PMA_Util::showMySQLDocu('federated-create-connection')
83 . '</th>'
84 . '</tr>';
86 $html .= '<tr>'
87 . '<td><input type="text" name="comment" size="40" maxlength="80"'
88 . ' value="'
89 . (isset($_REQUEST['comment'])
90 ? htmlspecialchars($_REQUEST['comment'])
91 : '')
92 . '" class="textfield" />'
93 . '</td>'
94 . '<td width="25">&nbsp;</td>'
95 . '<td>'
96 . PMA_generateCharsetDropdownBox(
97 PMA_CSDROPDOWN_COLLATION, 'tbl_collation', null,
98 (isset($_REQUEST['tbl_collation'])
99 ? $_REQUEST['tbl_collation']
100 : null
102 false
104 . '</td>'
105 . '<td width="25">&nbsp;</td>'
106 . '<td>'
107 . PMA_StorageEngine::getHtmlSelect(
108 'tbl_storage_engine', null,
109 (isset($_REQUEST['tbl_storage_engine'])
110 ? $_REQUEST['tbl_storage_engine']
111 : null
114 . '</td>'
115 . '<td width="25">&nbsp;</td>'
116 . '<td><input type="text" name="connection" size="40"'
117 . ' value="' . (isset($_REQUEST['connection'])
118 ? htmlspecialchars($_REQUEST['connection'])
119 : '') . '"'
120 . ' placeholder="scheme://user_name[:password]@host_name[:port_num]/db_name/tbl_name"'
121 . ' class="textfield" required="required" />'
122 . '</td>'
123 . '</tr>';
125 if (PMA_Partition::havePartitioning()) {
126 $html .= '<tr class="vtop">'
127 . '<th>' . __('PARTITION definition:') . '&nbsp;'
128 . PMA_Util::showMySQLDocu('Partitioning')
129 . '</th>'
130 . '</tr>'
131 . '<tr>'
132 . '<td>'
133 . '<textarea name="partition_definition" id="partitiondefinition"'
134 . ' cols="' . $GLOBALS['cfg']['TextareaCols'] . '"'
135 . ' rows="' . $GLOBALS['cfg']['TextareaRows'] . '"'
136 . ' dir="' . $GLOBALS['text_dir'] . '">'
137 . (isset($_REQUEST['partition_definition'])
138 ? htmlspecialchars($_REQUEST['partition_definition'])
139 : '')
140 . '</textarea>'
141 . '</td>'
142 . '</tr>';
144 $html .= '</table>'
145 . '<br />';
147 return $html;
151 * Function to get html for the footer
153 * @return string
155 function PMA_getHtmlForFooter()
157 $html = '<fieldset class="tblFooters">'
158 . '<input type="button" class="preview_sql" value="'
159 . __('Preview SQL') . '" />'
160 . '<input type="submit" name="do_save_data" value="' . __('Save') . '" />'
161 . '</fieldset>'
162 . '<div id="properties_message"></div>'
163 . '</form>';
165 $html .= '<div id="popup_background"></div>';
167 return $html;
171 * Function to get html for table create table name and number of fields
173 * @return string
175 function PMA_getHtmlForTableNameAndNoOfColumns()
177 $html = '<table>'
178 . '<tr class="vmiddle">'
179 . '<td>' . __('Table name')
180 . ':&nbsp;<input type="text" name="table" size="40" maxlength="80"'
181 . ' value="'
182 . (isset($_REQUEST['table']) ? htmlspecialchars($_REQUEST['table']) : '')
183 . '" class="textfield" autofocus required />'
184 . '</td>'
185 . '<td>';
186 $html .= sprintf(
187 __('Add %s column(s)'), '<input type="text" id="added_fields" '
188 . 'name="added_fields" size="2" value="1" onfocus="this.select'
189 . '()" />'
192 $html .= '<input type="button" name="submit_num_fields"'
193 . 'value="' . __('Go') . '" />';
195 $html .= '</td>'
196 . '</tr>'
197 . '</table>';
199 return $html;
203 * Function to get html for table field definitions
205 * @param array $header_cells header cells
206 * @param array $content_cells content cells
208 * @return string
210 function PMA_getHtmlForTableFieldDefinitions($header_cells, $content_cells)
212 $html = '<table id="table_columns" class="noclick">';
213 $html .= '<caption class="tblHeaders">' . __('Structure')
214 . PMA_Util::showMySQLDocu('CREATE_TABLE') . '</caption>';
216 $html .= '<tr>';
217 foreach ($header_cells as $header_val) {
218 $html .= '<th>' . $header_val . '</th>';
220 $html .= '</tr>';
222 $odd_row = true;
223 foreach ($content_cells as $content_row) {
224 $html .= '<tr class="' . ($odd_row ? 'odd' : 'even') . '">';
225 $odd_row = ! $odd_row;
227 if (is_array($content_row)) {
228 foreach ($content_row as $content_row_val) {
229 $html .= '<td class="center">' . $content_row_val . '</td>';
232 $html .= '</tr>';
234 $html .= '</table>'
235 . '<br />';
237 return $html;
241 * Function to get html for the create table or field add view
243 * @param string $action action
244 * @param array $form_params forms parameters
245 * @param array $content_cells content cells
246 * @param array $header_cells header cells
248 * @return string
250 function PMA_getHtmlForTableCreateOrAddField($action, $form_params, $content_cells,
251 $header_cells
253 $html = '<form method="post" action="' . $action . '" class="'
254 . ($action == 'tbl_create.php' ? 'create_table' : 'append_fields')
255 . '_form ajax lock-page">';
256 $html .= PMA_URL_getHiddenInputs($form_params);
257 $html .= '<input type="hidden" name="primary_indexes" value="[]">';
258 $html .= '<input type="hidden" name="unique_indexes" value="[]">';
259 $html .= '<input type="hidden" name="indexes" value="[]">';
260 $html .= '<input type="hidden" name="fulltext_indexes" value="[]">';
262 if ($action == 'tbl_create.php') {
263 $html .= PMA_getHtmlForTableNameAndNoOfColumns();
266 if (is_array($content_cells) && is_array($header_cells)) {
267 $html .= PMA_getHtmlForTableFieldDefinitions($header_cells, $content_cells);
270 if ($action == 'tbl_create.php') {
271 $html .= PMA_getHtmlForTableConfigurations();
274 $html .= PMA_getHtmlForFooter();
276 return $html;
280 * Function to get header cells
282 * @param bool $is_backup whether backup or not
283 * @param array|null $columnMeta column meta data
284 * @param bool $mimework whether mimework or not
285 * @param string $db current database
286 * @param string $table current table
288 * @return array
290 function PMA_getHeaderCells($is_backup, $columnMeta, $mimework, $db, $table)
292 $header_cells = array();
293 $header_cells[] = __('Name');
294 $header_cells[] = __('Type')
295 . PMA_Util::showMySQLDocu('data-types');
296 $header_cells[] = __('Length/Values')
297 . PMA_Util::showHint(
299 'If column type is "enum" or "set", please enter the values using'
300 . ' this format: \'a\',\'b\',\'c\'…<br />If you ever need to put'
301 . ' a backslash ("\") or a single quote ("\'") amongst those'
302 . ' values, precede it with a backslash (for example \'\\\\xyz\''
303 . ' or \'a\\\'b\').'
306 $header_cells[] = __('Default')
307 . PMA_Util::showHint(
309 'For default values, please enter just a single value,'
310 . ' without backslash escaping or quotes, using this format: a'
313 $header_cells[] = __('Collation');
314 $header_cells[] = __('Attributes');
315 $header_cells[] = __('Null');
317 // We could remove this 'if' and let the key information be shown and
318 // editable. However, for this to work, structure.lib.php must be modified
319 // to use the key fields, as tbl_addfield does.
320 if (! $is_backup) {
321 $header_cells[] = __('Index');
324 $header_cells[] = '<abbr title="AUTO_INCREMENT">A_I</abbr>';
325 $header_cells[] = __('Comments');
327 if (isset($columnMeta)) {
328 $header_cells[] = __('Move column');
331 if ($mimework && $GLOBALS['cfg']['BrowseMIME']) {
332 $header_cells[] = __('MIME type');
333 $header_link = '<a href="transformation_overview.php'
334 . PMA_URL_getCommon(array('db' => $db, 'table' => $table))
335 . '#%s" title="' . __(
336 'List of available transformations and their options'
338 . '" target="_blank">%s</a>';
339 $transformations_hint = PMA_Util::showHint(
341 'Please enter the values for transformation options using this'
342 . ' format: \'a\', 100, b,\'c\'…<br />If you ever need to put'
343 . ' a backslash ("\") or a single quote ("\'") amongst those'
344 . ' values, precede it with a backslash (for example \'\\\\xyz\''
345 . ' or \'a\\\'b\').'
348 $header_cells[] = sprintf(
349 $header_link, 'transformation', __('Browser display transformation')
351 $header_cells[] = __('Browser display transformation options')
352 . $transformations_hint;
353 $header_cells[] = sprintf(
354 $header_link, 'input_transformation', __('Input transformation')
356 $header_cells[] = __('Input transformation options')
357 . $transformations_hint;
360 return $header_cells;
364 * Function for moving, load all available column names
366 * @param string $db current database
367 * @param string $table current table
369 * @return array
371 function PMA_getMoveColumns($db, $table)
373 $move_columns_sql_query = 'SELECT * FROM '
374 . PMA_Util::backquote($db)
375 . '.'
376 . PMA_Util::backquote($table)
377 . ' LIMIT 1';
378 $move_columns_sql_result = $GLOBALS['dbi']->tryQuery($move_columns_sql_query);
379 $move_columns = $GLOBALS['dbi']->getFieldsMeta($move_columns_sql_result);
381 return $move_columns;
385 * Function to get row data for regenerating previous when error occurred.
387 * @param int $columnNumber column number
388 * @param array $submit_fulltext submit full text
390 * @return array
392 function PMA_getRowDataForRegeneration($columnNumber, $submit_fulltext)
394 $columnMeta = array();
395 $columnMeta['Field'] = isset($_REQUEST['field_name'][$columnNumber])
396 ? $_REQUEST['field_name'][$columnNumber]
397 : false;
398 $columnMeta['Type'] = isset($_REQUEST['field_type'][$columnNumber])
399 ? $_REQUEST['field_type'][$columnNumber]
400 : false;
401 $columnMeta['Collation'] = isset($_REQUEST['field_collation'][$columnNumber])
402 ? $_REQUEST['field_collation'][$columnNumber]
403 : '';
404 $columnMeta['Null'] = isset($_REQUEST['field_null'][$columnNumber])
405 ? $_REQUEST['field_null'][$columnNumber]
406 : '';
408 $columnMeta['Key'] = '';
409 if (isset($_REQUEST['field_key'][$columnNumber])) {
410 $parts = explode('_', $_REQUEST['field_key'][$columnNumber], 2);
411 if (count($parts) == 2 && $parts[1] == $columnNumber) {
412 switch ($parts[0]) {
413 case 'primary':
414 $columnMeta['Key'] = 'PRI';
415 break;
416 case 'index':
417 $columnMeta['Key'] = 'MUL';
418 break;
419 case 'unique':
420 $columnMeta['Key'] = 'UNI';
421 break;
422 case 'fulltext':
423 $columnMeta['Key'] = 'FULLTEXT';
424 break;
429 // put None in the drop-down for Default, when someone adds a field
430 $columnMeta['DefaultType']
431 = isset($_REQUEST['field_default_type'][$columnNumber])
432 ? $_REQUEST['field_default_type'][$columnNumber]
433 : 'NONE';
434 $columnMeta['DefaultValue']
435 = isset($_REQUEST['field_default_value'][$columnNumber])
436 ? $_REQUEST['field_default_value'][$columnNumber]
437 : '';
439 switch ($columnMeta['DefaultType']) {
440 case 'NONE' :
441 $columnMeta['Default'] = null;
442 break;
443 case 'USER_DEFINED' :
444 $columnMeta['Default'] = $columnMeta['DefaultValue'];
445 break;
446 case 'NULL' :
447 case 'CURRENT_TIMESTAMP' :
448 $columnMeta['Default'] = $columnMeta['DefaultType'];
449 break;
452 $columnMeta['Extra']
453 = (isset($_REQUEST['field_extra'][$columnNumber])
454 ? $_REQUEST['field_extra'][$columnNumber]
455 : false);
456 $columnMeta['Comment']
457 = (isset($submit_fulltext[$columnNumber])
458 && ($submit_fulltext[$columnNumber] == $columnNumber)
459 ? 'FULLTEXT'
460 : false);
462 return $columnMeta;
466 * Function to get submit properties for regenerating previous when error occurred.
468 * @param int $columnNumber column number
470 * @return array
472 function PMA_getSubmitPropertiesForRegeneration($columnNumber)
474 $submit_length
475 = (isset($_REQUEST['field_length'][$columnNumber])
476 ? $_REQUEST['field_length'][$columnNumber]
477 : false);
478 $submit_attribute
479 = (isset($_REQUEST['field_attribute'][$columnNumber])
480 ? $_REQUEST['field_attribute'][$columnNumber]
481 : false);
483 $submit_default_current_timestamp
484 = (isset($_REQUEST['field_default_current_timestamp'][$columnNumber])
485 ? true
486 : false);
488 return array(
489 $submit_length, $submit_attribute, $submit_default_current_timestamp
494 * An error happened with previous inputs, so we will restore the data
495 * to embed it once again in this form.
497 * @param int $columnNumber column number
498 * @param array $submit_fulltext submit full text
499 * @param array $comments_map comments map
500 * @param array $mime_map mime map
502 * @return array
504 function PMA_handleRegeneration($columnNumber, $submit_fulltext, $comments_map,
505 $mime_map
507 $columnMeta = PMA_getRowDataForRegeneration(
508 $columnNumber, isset($submit_fulltext) ? $submit_fulltext : null
511 list($submit_length, $submit_attribute, $submit_default_current_timestamp)
512 = PMA_getSubmitPropertiesForRegeneration($columnNumber);
514 if (isset($_REQUEST['field_comments'][$columnNumber])) {
515 $comments_map[$columnMeta['Field']]
516 = $_REQUEST['field_comments'][$columnNumber];
519 if (isset($_REQUEST['field_mimetype'][$columnNumber])) {
520 $mime_map[$columnMeta['Field']]['mimetype']
521 = $_REQUEST['field_mimetype'][$columnNumber];
524 if (isset($_REQUEST['field_transformation'][$columnNumber])) {
525 $mime_map[$columnMeta['Field']]['transformation']
526 = $_REQUEST['field_transformation'][$columnNumber];
529 if (isset($_REQUEST['field_transformation_options'][$columnNumber])) {
530 $mime_map[$columnMeta['Field']]['transformation_options']
531 = $_REQUEST['field_transformation_options'][$columnNumber];
534 return array(
535 $columnMeta, $submit_length, $submit_attribute,
536 $submit_default_current_timestamp, $comments_map, $mime_map
541 * Function to update default value info in $columnMeta and get this array
543 * @param array $columnMeta column meta
544 * @param bool $isDefault whether the row value is default
546 * @return array
548 function PMA_getColumnMetaForDefault($columnMeta, $isDefault)
550 switch ($columnMeta['Default']) {
551 case null:
552 if ($columnMeta['Null'] == 'YES') {
553 $columnMeta['DefaultType'] = 'NULL';
554 $columnMeta['DefaultValue'] = '';
555 // SHOW FULL COLUMNS does not report the case
556 // when there is a DEFAULT value which is empty so we need to use the
557 // results of SHOW CREATE TABLE
558 } elseif ($isDefault) {
559 $columnMeta['DefaultType'] = 'USER_DEFINED';
560 $columnMeta['DefaultValue'] = $columnMeta['Default'];
561 } else {
562 $columnMeta['DefaultType'] = 'NONE';
563 $columnMeta['DefaultValue'] = '';
565 break;
566 case 'CURRENT_TIMESTAMP':
567 $columnMeta['DefaultType'] = 'CURRENT_TIMESTAMP';
568 $columnMeta['DefaultValue'] = '';
569 break;
570 default:
571 $columnMeta['DefaultType'] = 'USER_DEFINED';
572 $columnMeta['DefaultValue'] = $columnMeta['Default'];
573 break;
576 return $columnMeta;
580 * Function to get html for the column name
582 * @param int $columnNumber column number
583 * @param int $ci cell index
584 * @param int $ci_offset cell index offset
585 * @param array|null $columnMeta column meta
586 * @param array $cfgRelation configuration relation
588 * @return string
590 function PMA_getHtmlForColumnName(
591 $columnNumber, $ci, $ci_offset, $columnMeta, $cfgRelation
593 $title = '';
594 if (isset($columnMeta['column_status'])) {
595 if ($columnMeta['column_status']['isReferenced']) {
596 $title .= sprintf(
597 __('Referenced by %s.'),
598 implode(",", $columnMeta['column_status']['references'])
601 if ($columnMeta['column_status']['isForeignKey']) {
602 if (!empty($title)) {
603 $title .= "\n";
605 $title .= __('Is a foreign key.');
608 if (empty($title)) {
609 $title = __('Column');
611 $html = '<input' . (isset($columnMeta['column_status'])
612 && !$columnMeta['column_status']['isEditable']?' disabled="disabled" ':' ')
613 . 'id="field_' . $columnNumber . '_' . ($ci - $ci_offset)
614 . '"' . ' type="text" name="field_name[' . $columnNumber . ']"'
615 . ' maxlength="64" class="textfield" title="' . $title . '"'
616 . ' size="10"'
617 . ' value="'
618 . (isset($columnMeta['Field'])
619 ? htmlspecialchars($columnMeta['Field']) : '')
620 . '"' . ' />';
621 if (isset($cfgRelation['central_columnswork'])
622 && $cfgRelation['central_columnswork']
623 && !(isset($columnMeta['column_status'])
624 && !$columnMeta['column_status']['isEditable'])
626 $html .= '<p style="font-size:80%;margin:5px 2px" '
627 . 'id="central_columns_' . $columnNumber . '_'
628 . ($ci - $ci_offset)
629 . '">';
630 $html .= '<a data-maxrows="' . $GLOBALS['cfg']['MaxRows'] . '" '
631 . 'href="#" class="central_columns_dialog"> '
632 . __('Pick from Central Columns') . '</a>'
633 . '</p>';
635 return $html;
639 * Function to get html for the column type
641 * @param int $columnNumber column number
642 * @param int $ci cell index
643 * @param int $ci_offset cell index offset
644 * @param string $type_upper type inuppercase
645 * @param array $columnMeta meta data
647 * @return string
649 function PMA_getHtmlForColumnType($columnNumber, $ci, $ci_offset,
650 $type_upper, $columnMeta
652 $select_id = 'field_' . $columnNumber . '_' . ($ci - $ci_offset);
653 $html = '<select' . (isset($columnMeta['column_status'])
654 && !$columnMeta['column_status']['isEditable']?' disabled="disabled" ':' ')
655 . 'class="column_type" name="field_type['
656 . $columnNumber . ']"' . ' id="' . $select_id . '">';
657 $html .= PMA_Util::getSupportedDatatypes(true, $type_upper);
658 $html .= ' </select>';
660 return $html;
664 * Function to get html for transformation option
666 * @param int $columnNumber column number
667 * @param int $ci cell index
668 * @param int $ci_offset cell index offset
669 * @param array|null $columnMeta column meta
670 * @param array $mime_map mime map
671 * @param string $type_prefix prefix for type of transformation
672 * '' or 'input'
674 * @return string
676 function PMA_getHtmlForTransformationOption($columnNumber, $ci, $ci_offset,
677 $columnMeta, $mime_map, $type_prefix
679 $options_key = $type_prefix . 'transformation_options';
680 $val = isset($columnMeta['Field'])
681 && isset($mime_map[$columnMeta['Field']][$options_key])
682 ? htmlspecialchars(
683 $mime_map[$columnMeta['Field']]
684 [$options_key]
686 : '';
688 $html = '<input id="field_' . $columnNumber . '_'
689 . ($ci - $ci_offset) . '"' . ' type="text" '
690 . 'name="field_' . $options_key . '[' . $columnNumber . ']"'
691 . ' size="16" class="textfield"'
692 . ' value="' . $val . '"'
693 . ' />';
695 return $html;
699 * Function to get html for mime type
701 * @param int $columnNumber column number
702 * @param int $ci cell index
703 * @param int $ci_offset cell index offset
704 * @param array $available_mime available mime
705 * @param array $columnMeta column meta
706 * @param array $mime_map mime map
708 * @return string
710 function PMA_getHtmlForMimeType($columnNumber, $ci, $ci_offset,
711 $available_mime, $columnMeta, $mime_map
713 $html = '<select id="field_' . $columnNumber . '_'
714 . ($ci - $ci_offset)
715 . '" size="1" name="field_mimetype[' . $columnNumber . ']">';
716 $html .= ' <option value="">&nbsp;</option>';
718 if (isset($available_mime['mimetype'])
719 && is_array($available_mime['mimetype'])
721 foreach ($available_mime['mimetype'] as $mimetype) {
722 $checked = (isset($columnMeta['Field'])
723 && isset($mime_map[$columnMeta['Field']]['mimetype'])
724 && ($mime_map[$columnMeta['Field']]['mimetype']
725 == str_replace('/', '_', $mimetype))
726 ? 'selected '
727 : '');
728 $html .= ' <option value="'
729 . str_replace('/', '_', $mimetype) . '" ' . $checked . '>'
730 . htmlspecialchars($mimetype) . '</option>';
734 $html .= '</select>';
736 return $html;
740 * Function to get html for transformations
742 * @param int $columnNumber column number
743 * @param int $ci cell index
744 * @param int $ci_offset cell index offset
745 * @param array $available_mime available mime
746 * @param array|null $columnMeta column meta
747 * @param array $mime_map mime map
748 * @param string $type_prefix prefix for type of transformation
749 * '' or 'input'
751 * @return string
753 function PMA_getHtmlForTransformation($columnNumber, $ci, $ci_offset,
754 $available_mime, $columnMeta, $mime_map, $type_prefix
756 $type = $type_prefix . 'transformation';
757 $html = '<select id="field_' . $columnNumber . '_'
758 . ($ci - $ci_offset) . '" size="1" name="field_' . $type
759 . '[' . $columnNumber . ']">';
760 $html .= ' <option value="" title="' . __('None')
761 . '"></option>';
762 if (isset($available_mime[$type]) && is_array($available_mime[$type])) {
763 foreach ($available_mime[$type] as $mimekey => $transform) {
764 $checked = isset($columnMeta['Field'])
765 && isset($mime_map[$columnMeta['Field']][$type])
766 && preg_match(
767 '@' . preg_quote(
768 $available_mime[$type . '_file'][$mimekey]
769 ) . '3?@i',
770 $mime_map[$columnMeta['Field']][$type]
772 ? 'selected '
773 : '';
774 $tooltip = PMA_getTransformationDescription(
775 $available_mime[$type . '_file'][$mimekey], false
777 $html .= '<option value="'
778 . $available_mime[$type . '_file'][$mimekey] . '" '
779 . $checked . ' title="' . htmlspecialchars($tooltip) . '">'
780 . htmlspecialchars($transform) . '</option>';
784 $html .= '</select>';
786 return $html;
790 * Function to get html for move column
792 * @param int $columnNumber column number
793 * @param int $ci cell index
794 * @param int $ci_offset cell index offset
795 * @param array $move_columns move columns
796 * @param array $columnMeta column meta
798 * @return string
800 function PMA_getHtmlForMoveColumn($columnNumber, $ci, $ci_offset, $move_columns,
801 $columnMeta
803 $html = '<select id="field_' . $columnNumber . '_'
804 . ($ci - $ci_offset) . '"' . ' name="field_move_to[' . $columnNumber
805 . ']" size="1" width="5em">'
806 . '<option value="" selected="selected">&nbsp;</option>';
807 // find index of current column
808 $current_index = 0;
809 for ($mi = 0, $cols = count($move_columns); $mi < $cols; $mi++) {
810 if ($move_columns[$mi]->name == $columnMeta['Field']) {
811 $current_index = $mi;
812 break;
816 $html .= '<option value="-first"'
817 . ($current_index == 0 ? ' disabled="disabled"' : '')
818 . '>' . __('first') . '</option>';
819 for ($mi = 0, $cols = count($move_columns); $mi < $cols; $mi++) {
820 $html .=
821 '<option value="' . htmlspecialchars($move_columns[$mi]->name) . '"'
822 . (($current_index == $mi || $current_index == $mi + 1)
823 ? ' disabled="disabled"'
824 : '')
825 . '>'
826 . sprintf(
827 __('after %s'),
828 PMA_Util::backquote(
829 htmlspecialchars(
830 $move_columns[$mi]->name
834 . '</option>';
837 $html .= '</select>';
839 return $html;
843 * Function to get html for column comment
845 * @param int $columnNumber column number
846 * @param int $ci cell index
847 * @param int $ci_offset cell index offset
848 * @param array $columnMeta column meta
849 * @param array $comments_map comments map
851 * @return string
853 function PMA_getHtmlForColumnComment($columnNumber, $ci, $ci_offset, $columnMeta,
854 $comments_map
856 $html = '<input id="field_' . $columnNumber . '_' . ($ci - $ci_offset)
857 . '"' . ' type="text" name="field_comments[' . $columnNumber
858 . ']" size="12"'
859 . ' value="' . (isset($columnMeta['Field'])
860 && is_array($comments_map)
861 && isset($comments_map[$columnMeta['Field']])
862 ? htmlspecialchars($comments_map[$columnMeta['Field']])
863 : '') . '"'
864 . ' class="textfield" />';
866 return $html;
870 * Function get html for column auto increment
872 * @param int $columnNumber column number
873 * @param int $ci cell index
874 * @param int $ci_offset cell index offset
875 * @param array $columnMeta column meta
877 * @return string
879 function PMA_getHtmlForColumnAutoIncrement($columnNumber, $ci, $ci_offset,
880 $columnMeta
882 $html = '<input name="field_extra[' . $columnNumber . ']"'
883 . ' id="field_' . $columnNumber . '_' . ($ci - $ci_offset) . '"';
884 if (isset($columnMeta['Extra'])
885 && /*overload*/mb_strtolower($columnMeta['Extra']) == 'auto_increment'
887 $html .= ' checked="checked"';
890 $html .= ' type="checkbox" value="AUTO_INCREMENT" />';
892 return $html;
896 * Function to get html for the column indexes
898 * @param int $columnNumber column number
899 * @param int $ci cell index
900 * @param int $ci_offset cell index offset
901 * @param array $columnMeta column meta
903 * @return string
905 function PMA_getHtmlForColumnIndexes($columnNumber, $ci, $ci_offset, $columnMeta)
907 $html = '<select name="field_key[' . $columnNumber . ']"'
908 . ' id="field_' . $columnNumber . '_' . ($ci - $ci_offset)
909 . '" data-index="">';
910 $html .= '<option value="none_' . $columnNumber . '">---</option>';
912 $html .= PMA_getHtmlForIndexTypeOption(
913 $columnNumber, $columnMeta, 'Primary', 'PRI'
915 $html .= PMA_getHtmlForIndexTypeOption(
916 $columnNumber, $columnMeta, 'Unique', 'UNI'
918 $html .= PMA_getHtmlForIndexTypeOption(
919 $columnNumber, $columnMeta, 'Index', 'MUL'
921 if (!PMA_DRIZZLE) {
922 $html .= PMA_getHtmlForIndexTypeOption(
923 $columnNumber, $columnMeta, 'Fulltext', 'FULLTEXT'
927 $html .= '</select>';
929 return $html;
933 * Function to get html for the index options
935 * @param int $columnNumber column number
936 * @param array $columnMeta column meta
937 * @param string $type index type
938 * @param string $key column meta key
940 * @return string
943 function PMA_getHtmlForIndexTypeOption($columnNumber, $columnMeta, $type, $key)
945 $typeToLower = /*overload*/mb_strtolower($type);
946 $typeToUpper = /*overload*/mb_strtoupper($type);
947 $html = '<option value="' . $typeToLower . '_' . $columnNumber
948 . '" title="' . __($type) . '"';
949 if (isset($columnMeta['Key']) && $columnMeta['Key'] == $key) {
950 $html .= ' selected="selected"';
952 $html .= '>' . $typeToUpper . '</option>';
954 return $html;
959 * Function to get html for column null
961 * @param int $columnNumber column number
962 * @param int $ci cell index
963 * @param int $ci_offset cell index offset
964 * @param array $columnMeta column meta
966 * @return string
968 function PMA_getHtmlForColumnNull($columnNumber, $ci, $ci_offset, $columnMeta)
970 $html = '<input name="field_null[' . $columnNumber . ']"'
971 . ' id="field_' . $columnNumber . '_' . ($ci - $ci_offset) . '"';
972 if (! empty($columnMeta['Null'])
973 && $columnMeta['Null'] != 'NO'
974 && $columnMeta['Null'] != 'NOT NULL'
976 $html .= ' checked="checked"';
979 $html .= ' type="checkbox" value="NULL" class="allow_null"/>';
981 return $html;
985 * Function to get html for column attribute
987 * @param int $columnNumber column number
988 * @param int $ci cell index
989 * @param int $ci_offset cell index offset
990 * @param array $extracted_columnspec extracted column
991 * @param array $columnMeta column meta
992 * @param bool $submit_attribute submit attribute
993 * @param array $analyzed_sql analyzed sql
995 * @return string
997 function PMA_getHtmlForColumnAttribute($columnNumber, $ci, $ci_offset,
998 $extracted_columnspec, $columnMeta, $submit_attribute, $analyzed_sql
1000 $html = '<select style="width: 7em;"'
1001 . ' name="field_attribute[' . $columnNumber . ']"'
1002 . ' id="field_' . $columnNumber . '_' . ($ci - $ci_offset) . '">';
1004 $attribute = '';
1005 if (isset($extracted_columnspec['attribute'])) {
1006 $attribute = $extracted_columnspec['attribute'];
1009 if (isset($columnMeta['Extra'])
1010 && $columnMeta['Extra'] == 'on update CURRENT_TIMESTAMP'
1012 $attribute = 'on update CURRENT_TIMESTAMP';
1015 if (isset($submit_attribute) && $submit_attribute != false) {
1016 $attribute = $submit_attribute;
1019 // here, we have a TIMESTAMP that SHOW FULL COLUMNS reports as having the
1020 // NULL attribute, but SHOW CREATE TABLE says the contrary. Believe
1021 // the latter.
1022 $create_table_fields = $analyzed_sql[0]['create_table_fields'];
1024 // MySQL 4.1.2+ TIMESTAMP options
1025 // (if on_update_current_timestamp is set, then it's TRUE)
1026 if (isset($columnMeta['Field'])) {
1027 $field = $create_table_fields[$columnMeta['Field']];
1030 if (isset($field)
1031 && isset($field['on_update_current_timestamp'])
1033 $attribute = 'on update CURRENT_TIMESTAMP';
1036 $attribute_types = $GLOBALS['PMA_Types']->getAttributes();
1037 $cnt_attribute_types = count($attribute_types);
1038 for ($j = 0; $j < $cnt_attribute_types; $j++) {
1039 $html .= ' <option value="' . $attribute_types[$j] . '"';
1040 $attrUpper = /*overload*/mb_strtoupper($attribute);
1041 if ($attrUpper == /*overload*/mb_strtoupper($attribute_types[$j])) {
1042 $html .= ' selected="selected"';
1044 $html .= '>' . $attribute_types[$j] . '</option>';
1047 $html .= '</select>';
1049 return $html;
1053 * Function to get html for column collation
1055 * @param int $columnNumber column number
1056 * @param int $ci cell index
1057 * @param int $ci_offset cell index offset
1058 * @param array $columnMeta column meta
1060 * @return string
1062 function PMA_getHtmlForColumnCollation($columnNumber, $ci, $ci_offset, $columnMeta)
1064 $tmp_collation
1065 = empty($columnMeta['Collation']) ? null : $columnMeta['Collation'];
1066 $html = PMA_generateCharsetDropdownBox(
1067 PMA_CSDROPDOWN_COLLATION, 'field_collation[' . $columnNumber . ']',
1068 'field_' . $columnNumber . '_' . ($ci - $ci_offset), $tmp_collation, false
1071 return $html;
1075 * Function get html for column length
1077 * @param int $columnNumber column number
1078 * @param int $ci cell index
1079 * @param int $ci_offset cell index offset
1080 * @param int $length_values_input_size length values input size
1081 * @param int $length_to_display length to display
1083 * @return string
1085 function PMA_getHtmlForColumnLength($columnNumber, $ci, $ci_offset,
1086 $length_values_input_size, $length_to_display
1088 $html = '<input id="field_' . $columnNumber . '_' . ($ci - $ci_offset)
1089 . '"' . ' type="text" name="field_length[' . $columnNumber . ']" size="'
1090 . $length_values_input_size . '"' . ' value="' . htmlspecialchars(
1091 $length_to_display
1093 . '"'
1094 . ' class="textfield" />'
1095 . '<p class="enum_notice" id="enum_notice_' . $columnNumber . '_'
1096 . ($ci - $ci_offset)
1097 . '">';
1098 $html .= '<a href="#" class="open_enum_editor"> '
1099 . __('Edit ENUM/SET values') . '</a>'
1100 . '</p>';
1102 return $html;
1106 * Function to get html for the default column
1108 * @param int $columnNumber column number
1109 * @param int $ci cell index
1110 * @param int $ci_offset cell index offset
1111 * @param string $type_upper type upper
1112 * @param string $default_current_timestamp default current timestamp
1113 * @param array $columnMeta column meta
1115 * @return string
1117 function PMA_getHtmlForColumnDefault($columnNumber, $ci, $ci_offset, $type_upper,
1118 $default_current_timestamp, $columnMeta
1120 // here we put 'NONE' as the default value of drop-down; otherwise
1121 // users would have problems if they forget to enter the default
1122 // value (example, for an INT)
1123 $default_options = array(
1124 'NONE' => _pgettext('for default', 'None'),
1125 'USER_DEFINED' => __('As defined:'),
1126 'NULL' => 'NULL',
1127 'CURRENT_TIMESTAMP' => 'CURRENT_TIMESTAMP',
1130 // for a TIMESTAMP, do not show the string "CURRENT_TIMESTAMP" as a default
1131 // value
1132 if ($type_upper == 'TIMESTAMP'
1133 && ! empty($default_current_timestamp)
1134 && isset($columnMeta['Default'])
1136 $columnMeta['Default'] = '';
1137 } elseif ($type_upper == 'BIT') {
1138 $columnMeta['DefaultValue']
1139 = PMA_Util::convertBitDefaultValue($columnMeta['DefaultValue']);
1140 } elseif ($type_upper == 'BINARY' || $type_upper == 'VARBINARY') {
1141 $columnMeta['DefaultValue'] = bin2hex($columnMeta['DefaultValue']);
1144 $html = '<select name="field_default_type[' . $columnNumber
1145 . ']" id="field_' . $columnNumber . '_' . ($ci - $ci_offset)
1146 . '" class="default_type">';
1147 foreach ($default_options as $key => $value) {
1148 $html .= '<option value="' . $key . '"';
1149 // is only set when we go back to edit a field's structure
1150 if (isset($columnMeta['DefaultType'])
1151 && $columnMeta['DefaultType'] == $key
1153 $html .= ' selected="selected"';
1155 $html .= ' >' . $value . '</option>';
1157 $html .= '</select>';
1158 $html .= '<br />';
1160 $value = isset($columnMeta['DefaultValue'])
1161 ? htmlspecialchars($columnMeta['DefaultValue'])
1162 : '';
1163 if ($GLOBALS['cfg']['CharEditing'] == 'textarea') {
1164 $html .= '<textarea'
1165 . ' name="field_default_value[' . $columnNumber . ']" cols="15"'
1166 . ' class="textfield default_value">'
1167 . $value
1168 . '</textarea>';
1169 } else {
1170 $html .= '<input type="text"'
1171 . ' name="field_default_value[' . $columnNumber . ']" size="12"'
1172 . ' value="' . $value . '"'
1173 . ' class="textfield default_value" />';
1176 return $html;
1180 * Function to get html for column attributes
1182 * @param int $columnNumber column number
1183 * @param array $columnMeta column meta
1184 * @param string $type_upper type upper
1185 * @param int $length_values_input_size length values input size
1186 * @param int $length length
1187 * @param string $default_current_timestamp default current time stamp
1188 * @param array|null $extracted_columnspec extracted column spec
1189 * @param string $submit_attribute submit attribute
1190 * @param array|null $analyzed_sql analyzed sql
1191 * @param array $comments_map comments map
1192 * @param array|null $fields_meta fields map
1193 * @param bool $is_backup is backup
1194 * @param array $move_columns move columns
1195 * @param array $cfgRelation configuration relation
1196 * @param array $available_mime available mime
1197 * @param array $mime_map mime map
1199 * @return array
1201 function PMA_getHtmlForColumnAttributes($columnNumber, $columnMeta, $type_upper,
1202 $length_values_input_size, $length, $default_current_timestamp,
1203 $extracted_columnspec, $submit_attribute, $analyzed_sql,
1204 $comments_map, $fields_meta, $is_backup,
1205 $move_columns, $cfgRelation, $available_mime, $mime_map
1207 // Cell index: If certain fields get left out, the counter shouldn't change.
1208 $ci = 0;
1209 // Every time a cell shall be left out the STRG-jumping feature, $ci_offset
1210 // has to be incremented ($ci_offset++)
1211 $ci_offset = -1;
1213 $content_cell = array();
1215 // column name
1216 $content_cell[$ci] = PMA_getHtmlForColumnName(
1217 $columnNumber, $ci, $ci_offset, isset($columnMeta) ? $columnMeta : null,
1218 $cfgRelation
1220 $ci++;
1222 // column type
1223 $content_cell[$ci] = PMA_getHtmlForColumnType(
1224 $columnNumber, $ci, $ci_offset, $type_upper,
1225 isset($columnMeta) ? $columnMeta : null
1227 $ci++;
1229 // column length
1230 $content_cell[$ci] = PMA_getHtmlForColumnLength(
1231 $columnNumber, $ci, $ci_offset, $length_values_input_size, $length
1233 $ci++;
1235 // column default
1236 $content_cell[$ci] = PMA_getHtmlForColumnDefault(
1237 $columnNumber, $ci, $ci_offset,
1238 isset($type_upper) ? $type_upper : null,
1239 isset($default_current_timestamp) ? $default_current_timestamp : null,
1240 isset($columnMeta) ? $columnMeta : null
1242 $ci++;
1244 // column collation
1245 $content_cell[$ci] = PMA_getHtmlForColumnCollation(
1246 $columnNumber, $ci, $ci_offset, $columnMeta
1248 $ci++;
1250 // column attribute
1251 $content_cell[$ci] = PMA_getHtmlForColumnAttribute(
1252 $columnNumber, $ci, $ci_offset,
1253 isset($extracted_columnspec) ? $extracted_columnspec : null,
1254 isset($columnMeta) ? $columnMeta : null,
1255 isset($submit_attribute) ? $submit_attribute : null,
1256 isset($analyzed_sql) ? $analyzed_sql : null
1258 $ci++;
1260 // column NULL
1261 $content_cell[$ci] = PMA_getHtmlForColumnNull(
1262 $columnNumber, $ci, $ci_offset, isset($columnMeta) ? $columnMeta : null
1264 $ci++;
1266 // column indexes
1267 // See my other comment about this 'if'.
1268 if (!$is_backup) {
1269 $content_cell[$ci] = PMA_getHtmlForColumnIndexes(
1270 $columnNumber, $ci, $ci_offset, $columnMeta
1272 $ci++;
1273 } // end if ($action ==...)
1275 // column auto_increment
1276 $content_cell[$ci] = PMA_getHtmlForColumnAutoIncrement(
1277 $columnNumber, $ci, $ci_offset, $columnMeta
1279 $ci++;
1281 // column comments
1282 $content_cell[$ci] = PMA_getHtmlForColumnComment(
1283 $columnNumber, $ci, $ci_offset, isset($columnMeta) ? $columnMeta : null,
1284 $comments_map
1286 $ci++;
1288 // move column
1289 if (isset($fields_meta)) {
1290 $content_cell[$ci] = PMA_getHtmlForMoveColumn(
1291 $columnNumber, $ci, $ci_offset, $move_columns, $columnMeta
1293 $ci++;
1296 if ($cfgRelation['mimework']
1297 && $GLOBALS['cfg']['BrowseMIME']
1298 && $cfgRelation['commwork']
1300 // Column Mime-type
1301 $content_cell[$ci] = PMA_getHtmlForMimeType(
1302 $columnNumber, $ci, $ci_offset, $available_mime, $columnMeta, $mime_map
1304 $ci++;
1306 // Column Browser transformation
1307 $content_cell[$ci] = PMA_getHtmlForTransformation(
1308 $columnNumber, $ci, $ci_offset, $available_mime,
1309 $columnMeta, $mime_map, ''
1311 $ci++;
1313 // column Transformation options
1314 $content_cell[$ci] = PMA_getHtmlForTransformationOption(
1315 $columnNumber, $ci, $ci_offset, $columnMeta, $mime_map, ''
1317 $ci++;
1319 // Column Input transformation
1320 $content_cell[$ci] = PMA_getHtmlForTransformation(
1321 $columnNumber, $ci, $ci_offset, $available_mime,
1322 $columnMeta, $mime_map, 'input_'
1324 $ci++;
1326 // column Input transformation options
1327 $content_cell[$ci] = PMA_getHtmlForTransformationOption(
1328 $columnNumber, $ci, $ci_offset, $columnMeta, $mime_map, 'input_'
1332 return $content_cell;
1336 * Function to get form parameters for old column
1338 * @param array $columnMeta column meta
1339 * @param int $length length
1340 * @param array $form_params form parameters
1341 * @param int $columnNumber column/field number
1342 * @param string $type type in lowercase without the length
1343 * @param array $extracted_columnspec details about the column spec
1345 * @return array
1347 function PMA_getFormParamsForOldColumn(
1348 $columnMeta, $length, $form_params, $columnNumber, $type,
1349 $extracted_columnspec
1351 // old column name
1352 if (isset($columnMeta['Field'])) {
1353 $form_params['field_orig[' . $columnNumber . ']']
1354 = $columnMeta['Field'];
1355 if (isset($columnMeta['column_status'])
1356 && !$columnMeta['column_status']['isEditable']
1358 $form_params['field_name[' . $columnNumber . ']']
1359 = $columnMeta['Field'];
1361 } else {
1362 $form_params['field_orig[' . $columnNumber . ']'] = '';
1365 // old column type
1366 if (isset($columnMeta['Type'])) {
1367 // keep in uppercase because the new type will be in uppercase
1368 $form_params['field_type_orig[' . $columnNumber . ']']
1369 = /*overload*/mb_strtoupper($type);
1370 if (isset($columnMeta['column_status'])
1371 && !$columnMeta['column_status']['isEditable']
1373 $form_params['field_type[' . $columnNumber . ']']
1374 = /*overload*/mb_strtoupper($type);
1376 } else {
1377 $form_params['field_type_orig[' . $columnNumber . ']'] = '';
1380 // old column length
1381 $form_params['field_length_orig[' . $columnNumber . ']'] = $length;
1383 // old column default
1384 $form_params['field_default_value_orig[' . $columnNumber . ']']
1385 = (isset($columnMeta['Default']) ? $columnMeta['Default'] : '');
1386 $form_params['field_default_type_orig[' . $columnNumber . ']']
1387 = (isset($columnMeta['DefaultType']) ? $columnMeta['DefaultType'] : '');
1389 // old column collation
1390 if (isset($columnMeta['Collation'])) {
1391 $form_params['field_collation_orig[' . $columnNumber . ']']
1392 = $columnMeta['Collation'];
1393 } else {
1394 $form_params['field_collation_orig[' . $columnNumber . ']'] = '';
1397 // old column attribute
1398 if (isset($extracted_columnspec['attribute'])) {
1399 $form_params['field_attribute_orig[' . $columnNumber . ']']
1400 = trim($extracted_columnspec['attribute']);
1401 } else {
1402 $form_params['field_attribute_orig[' . $columnNumber . ']'] = '';
1405 // old column null
1406 if (isset($columnMeta['Null'])) {
1407 $form_params['field_null_orig[' . $columnNumber . ']']
1408 = $columnMeta['Null'];
1409 } else {
1410 $form_params['field_null_orig[' . $columnNumber . ']'] = '';
1413 // old column extra (for auto_increment)
1414 if (isset($columnMeta['Extra'])) {
1415 $form_params['field_extra_orig[' . $columnNumber . ']']
1416 = $columnMeta['Extra'];
1417 } else {
1418 $form_params['field_extra_orig[' . $columnNumber . ']'] = '';
1421 // old column comment
1422 if (isset($columnMeta['Comment'])) {
1423 $form_params['field_comments_orig[' . $columnNumber . ']']
1424 = $columnMeta['Comment'];
1425 } else {
1426 $form_params['field_comment_orig[' . $columnNumber . ']'] = '';
1429 return $form_params;