added japanese language
[openemr.git] / phpmyadmin / libraries / tbl_columns_definition_form.lib.php
blob67863534375445d05093c874c25c8cba12c62994
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 $header_cells[] = __('MIME type');
315 $header_cells[] = '<a href="transformation_overview.php?'
316 . PMA_URL_getCommon($db, $table)
317 . '" title="' . __(
318 'List of available transformations and their options'
320 . '" target="_blank">'
321 . __('Browser transformation')
322 . '</a>';
323 $header_cells[] = __('Transformation options')
324 . PMA_Util::showHint(
326 'Please enter the values for transformation options using this'
327 . ' format: \'a\', 100, b,\'c\'…<br />If you ever need to put'
328 . ' a backslash ("\") or a single quote ("\'") amongst those'
329 . ' values, precede it with a backslash (for example \'\\\\xyz\''
330 . ' or \'a\\\'b\').'
335 return $header_cells;
339 * Function for moving, load all available column names
341 * @param string $db current database
342 * @param string $table current table
344 * @return array
346 function PMA_getMoveColumns($db, $table)
348 $move_columns_sql_query = 'SELECT * FROM '
349 . PMA_Util::backquote($db)
350 . '.'
351 . PMA_Util::backquote($table)
352 . ' LIMIT 1';
353 $move_columns_sql_result = $GLOBALS['dbi']->tryQuery($move_columns_sql_query);
354 $move_columns = $GLOBALS['dbi']->getFieldsMeta($move_columns_sql_result);
356 return $move_columns;
360 * Function to get row data for regenerating previous when error occurred.
362 * @param int $columnNumber column number
363 * @param array $submit_fulltext submit full text
365 * @return array
367 function PMA_getRowDataForRegeneration($columnNumber, $submit_fulltext)
369 $columnMeta = array();
370 $columnMeta['Field'] = isset($_REQUEST['field_name'][$columnNumber])
371 ? $_REQUEST['field_name'][$columnNumber]
372 : false;
373 $columnMeta['Type'] = isset($_REQUEST['field_type'][$columnNumber])
374 ? $_REQUEST['field_type'][$columnNumber]
375 : false;
376 $columnMeta['Collation'] = isset($_REQUEST['field_collation'][$columnNumber])
377 ? $_REQUEST['field_collation'][$columnNumber]
378 : '';
379 $columnMeta['Null'] = isset($_REQUEST['field_null'][$columnNumber])
380 ? $_REQUEST['field_null'][$columnNumber]
381 : '';
383 $columnMeta['Key'] = '';
384 if (isset($_REQUEST['field_key'][$columnNumber])) {
385 $parts = explode('_', $_REQUEST['field_key'][$columnNumber], 2);
386 if (count($parts) == 2 && $parts[1] == $columnNumber) {
387 switch ($parts[0]) {
388 case 'primary':
389 $columnMeta['Key'] = 'PRI';
390 break;
391 case 'index':
392 $columnMeta['Key'] = 'MUL';
393 break;
394 case 'unique':
395 $columnMeta['Key'] = 'UNI';
396 break;
397 case 'fulltext':
398 $columnMeta['Key'] = 'FULLTEXT';
399 break;
404 // put None in the drop-down for Default, when someone adds a field
405 $columnMeta['DefaultType']
406 = isset($_REQUEST['field_default_type'][$columnNumber])
407 ? $_REQUEST['field_default_type'][$columnNumber]
408 : 'NONE';
409 $columnMeta['DefaultValue']
410 = isset($_REQUEST['field_default_value'][$columnNumber])
411 ? $_REQUEST['field_default_value'][$columnNumber]
412 : '';
414 switch ($columnMeta['DefaultType']) {
415 case 'NONE' :
416 $columnMeta['Default'] = null;
417 break;
418 case 'USER_DEFINED' :
419 $columnMeta['Default'] = $columnMeta['DefaultValue'];
420 break;
421 case 'NULL' :
422 case 'CURRENT_TIMESTAMP' :
423 $columnMeta['Default'] = $columnMeta['DefaultType'];
424 break;
427 $columnMeta['Extra']
428 = (isset($_REQUEST['field_extra'][$columnNumber])
429 ? $_REQUEST['field_extra'][$columnNumber]
430 : false);
431 $columnMeta['Comment']
432 = (isset($submit_fulltext[$columnNumber])
433 && ($submit_fulltext[$columnNumber] == $columnNumber)
434 ? 'FULLTEXT'
435 : false);
437 return $columnMeta;
441 * Function to get submit properties for regenerating previous when error occurred.
443 * @param int $columnNumber column number
445 * @return array
447 function PMA_getSubmitPropertiesForRegeneration($columnNumber)
449 $submit_length
450 = (isset($_REQUEST['field_length'][$columnNumber])
451 ? $_REQUEST['field_length'][$columnNumber]
452 : false);
453 $submit_attribute
454 = (isset($_REQUEST['field_attribute'][$columnNumber])
455 ? $_REQUEST['field_attribute'][$columnNumber]
456 : false);
458 $submit_default_current_timestamp
459 = (isset($_REQUEST['field_default_current_timestamp'][$columnNumber])
460 ? true
461 : false);
463 return array(
464 $submit_length, $submit_attribute, $submit_default_current_timestamp
469 * An error happened with previous inputs, so we will restore the data
470 * to embed it once again in this form.
472 * @param int $columnNumber column number
473 * @param array $submit_fulltext submit full text
474 * @param array $comments_map comments map
475 * @param array $mime_map mime map
477 * @return array
479 function PMA_handleRegeneration($columnNumber, $submit_fulltext, $comments_map,
480 $mime_map
482 $columnMeta = PMA_getRowDataForRegeneration(
483 $columnNumber, isset($submit_fulltext) ? $submit_fulltext : null
486 list($submit_length, $submit_attribute, $submit_default_current_timestamp)
487 = PMA_getSubmitPropertiesForRegeneration($columnNumber);
489 if (isset($_REQUEST['field_comments'][$columnNumber])) {
490 $comments_map[$columnMeta['Field']]
491 = $_REQUEST['field_comments'][$columnNumber];
494 if (isset($_REQUEST['field_mimetype'][$columnNumber])) {
495 $mime_map[$columnMeta['Field']]['mimetype']
496 = $_REQUEST['field_mimetype'][$columnNumber];
499 if (isset($_REQUEST['field_transformation'][$columnNumber])) {
500 $mime_map[$columnMeta['Field']]['transformation']
501 = $_REQUEST['field_transformation'][$columnNumber];
504 if (isset($_REQUEST['field_transformation_options'][$columnNumber])) {
505 $mime_map[$columnMeta['Field']]['transformation_options']
506 = $_REQUEST['field_transformation_options'][$columnNumber];
509 return array(
510 $columnMeta, $submit_length, $submit_attribute,
511 $submit_default_current_timestamp, $comments_map, $mime_map
516 * Function to update default value info in $columnMeta and get this array
518 * @param array $columnMeta column meta
519 * @param bool $isDefault whether the row value is default
521 * @return array
523 function PMA_getColumnMetaForDefault($columnMeta, $isDefault)
525 switch ($columnMeta['Default']) {
526 case null:
527 if ($columnMeta['Null'] == 'YES') {
528 $columnMeta['DefaultType'] = 'NULL';
529 $columnMeta['DefaultValue'] = '';
530 // SHOW FULL COLUMNS does not report the case
531 // when there is a DEFAULT value which is empty so we need to use the
532 // results of SHOW CREATE TABLE
533 } elseif ($isDefault) {
534 $columnMeta['DefaultType'] = 'USER_DEFINED';
535 $columnMeta['DefaultValue'] = $columnMeta['Default'];
536 } else {
537 $columnMeta['DefaultType'] = 'NONE';
538 $columnMeta['DefaultValue'] = '';
540 break;
541 case 'CURRENT_TIMESTAMP':
542 $columnMeta['DefaultType'] = 'CURRENT_TIMESTAMP';
543 $columnMeta['DefaultValue'] = '';
544 break;
545 default:
546 $columnMeta['DefaultType'] = 'USER_DEFINED';
547 $columnMeta['DefaultValue'] = $columnMeta['Default'];
548 break;
551 return $columnMeta;
555 * Function to get html for the column name
557 * @param int $columnNumber column number
558 * @param int $ci cell index
559 * @param int $ci_offset cell index offset
560 * @param array $columnMeta column meta
562 * @return string
564 function PMA_getHtmlForColumnName($columnNumber, $ci, $ci_offset, $columnMeta)
566 $title = '';
567 if (isset($columnMeta['column_status'])) {
568 if ($columnMeta['column_status']['isReferenced']) {
569 $title .= sprintf(
570 __('Referenced by %s.'),
571 implode(",", $columnMeta['column_status']['references'])
574 if ($columnMeta['column_status']['isForeignKey']) {
575 if (!empty($title)) {
576 $title .= "\n";
578 $title .= __('Is a foreign key.');
581 if (empty($title)) {
582 $title = __('Column');
584 $html = '<input' . (isset($columnMeta['column_status'])
585 && !$columnMeta['column_status']['isEditable']?' disabled="disabled" ':' ')
586 . 'id="field_' . $columnNumber . '_' . ($ci - $ci_offset)
587 . '"' . ' type="text" name="field_name[' . $columnNumber . ']"'
588 . ' maxlength="64" class="textfield" title="' . $title . '"'
589 . ' size="10"'
590 . ' value="'
591 . (isset($columnMeta['Field'])
592 ? htmlspecialchars($columnMeta['Field']) : '')
593 . '"' . ' />';
595 return $html;
599 * Function to get html for the column type
601 * @param int $columnNumber column number
602 * @param int $ci cell index
603 * @param int $ci_offset cell index offset
604 * @param string $type_upper type inuppercase
605 * @param array $columnMeta meta data
607 * @return string
609 function PMA_getHtmlForColumnType($columnNumber, $ci, $ci_offset,
610 $type_upper, $columnMeta
612 $select_id = 'field_' . $columnNumber . '_' . ($ci - $ci_offset);
613 $html = '<select' . (isset($columnMeta['column_status'])
614 && !$columnMeta['column_status']['isEditable']?' disabled="disabled" ':' ')
615 . 'class="column_type" name="field_type['
616 . $columnNumber . ']"' . ' id="' . $select_id . '">';
617 $html .= PMA_Util::getSupportedDatatypes(true, $type_upper);
618 $html .= ' </select>';
620 return $html;
624 * Function to get html for transformation option
626 * @param int $columnNumber column number
627 * @param int $ci cell index
628 * @param int $ci_offset cell index offset
629 * @param array $columnMeta column meta
630 * @param array $mime_map mime map
632 * @return string
634 function PMA_getHtmlForTransformationOption($columnNumber, $ci, $ci_offset,
635 $columnMeta, $mime_map
637 $val = isset($columnMeta['Field'])
638 && isset($mime_map[$columnMeta['Field']]['transformation_options'])
639 ? htmlspecialchars(
640 $mime_map[$columnMeta['Field']]
641 ['transformation_options']
643 : '';
645 $html = '<input id="field_' . $columnNumber . '_'
646 . ($ci - $ci_offset) . '"' . ' type="text" '
647 . 'name="field_transformation_options[' . $columnNumber . ']"'
648 . ' size="16" class="textfield"'
649 . ' value="' . $val . '"'
650 . ' />';
652 return $html;
656 * Function to get html for mime type
658 * @param int $columnNumber column number
659 * @param int $ci cell index
660 * @param int $ci_offset cell index offset
661 * @param array $available_mime available mime
662 * @param array $columnMeta column meta
663 * @param array $mime_map mime map
665 * @return string
667 function PMA_getHtmlForMimeType($columnNumber, $ci, $ci_offset,
668 $available_mime, $columnMeta, $mime_map
670 $html = '<select id="field_' . $columnNumber . '_'
671 . ($ci - $ci_offset)
672 . '" size="1" name="field_mimetype[' . $columnNumber . ']">';
673 $html .= ' <option value="">&nbsp;</option>';
675 if (is_array($available_mime['mimetype'])) {
676 foreach ($available_mime['mimetype'] as $mimetype) {
677 $checked = (isset($columnMeta['Field'])
678 && isset($mime_map[$columnMeta['Field']]['mimetype'])
679 && ($mime_map[$columnMeta['Field']]['mimetype']
680 == str_replace('/', '_', $mimetype))
681 ? 'selected '
682 : '');
683 $html .= ' <option value="'
684 . str_replace('/', '_', $mimetype) . '" ' . $checked . '>'
685 . htmlspecialchars($mimetype) . '</option>';
689 $html .= '</select>';
691 return $html;
695 * Function to get html for browser transformation
697 * @param int $columnNumber column number
698 * @param int $ci cell index
699 * @param int $ci_offset cell index offset
700 * @param array $available_mime available mime
701 * @param array $columnMeta column meta
702 * @param array $mime_map mime map
704 * @return string
706 function PMA_getHtmlForBrowserTransformation($columnNumber, $ci, $ci_offset,
707 $available_mime, $columnMeta, $mime_map
709 $html = '<select id="field_' . $columnNumber . '_'
710 . ($ci - $ci_offset) . '" size="1" name="field_transformation['
711 . $columnNumber . ']">';
712 $html .= ' <option value="" title="' . __('None')
713 . '"></option>';
714 if (is_array($available_mime['transformation'])) {
715 foreach ($available_mime['transformation'] as $mimekey => $transform) {
716 $checked = isset($columnMeta['Field'])
717 && isset($mime_map[$columnMeta['Field']]['transformation'])
718 && preg_match(
719 '@' . preg_quote(
720 $available_mime['transformation_file'][$mimekey]
721 ) . '3?@i',
722 $mime_map[$columnMeta['Field']]['transformation']
724 ? 'selected '
725 : '';
726 $tooltip = PMA_getTransformationDescription(
727 $available_mime['transformation_file'][$mimekey], false
729 $html .= '<option value="'
730 . $available_mime['transformation_file'][$mimekey] . '" '
731 . $checked . ' title="' . htmlspecialchars($tooltip) . '">'
732 . htmlspecialchars($transform) . '</option>';
736 $html .= '</select>';
738 return $html;
742 * Function to get html for move column
744 * @param int $columnNumber column number
745 * @param int $ci cell index
746 * @param int $ci_offset cell index offset
747 * @param array $move_columns move columns
748 * @param array $columnMeta column meta
750 * @return string
752 function PMA_getHtmlForMoveColumn($columnNumber, $ci, $ci_offset, $move_columns,
753 $columnMeta
755 $html = '<select id="field_' . $columnNumber . '_'
756 . ($ci - $ci_offset) . '"' . ' name="field_move_to[' . $columnNumber
757 . ']" size="1" width="5em">'
758 . '<option value="" selected="selected">&nbsp;</option>';
759 // find index of current column
760 $current_index = 0;
761 for ($mi = 0, $cols = count($move_columns); $mi < $cols; $mi++) {
762 if ($move_columns[$mi]->name == $columnMeta['Field']) {
763 $current_index = $mi;
764 break;
768 $html .= '<option value="-first"'
769 . ($current_index == 0 ? ' disabled="disabled"' : '')
770 . '>' . __('first') . '</option>';
771 for ($mi = 0, $cols = count($move_columns); $mi < $cols; $mi++) {
772 $html .=
773 '<option value="' . htmlspecialchars($move_columns[$mi]->name) . '"'
774 . (($current_index == $mi || $current_index == $mi + 1)
775 ? ' disabled="disabled"'
776 : '')
777 . '>'
778 . sprintf(
779 __('after %s'),
780 PMA_Util::backquote(
781 htmlspecialchars(
782 $move_columns[$mi]->name
786 . '</option>';
789 $html .= '</select>';
791 return $html;
795 * Function to get html for column comment
797 * @param int $columnNumber column number
798 * @param int $ci cell index
799 * @param int $ci_offset cell index offset
800 * @param array $columnMeta column meta
801 * @param array $comments_map comments map
803 * @return string
805 function PMA_getHtmlForColumnComment($columnNumber, $ci, $ci_offset, $columnMeta,
806 $comments_map
808 $html = '<input id="field_' . $columnNumber . '_' . ($ci - $ci_offset)
809 . '"' . ' type="text" name="field_comments[' . $columnNumber
810 . ']" size="12"'
811 . ' value="' . (isset($columnMeta['Field'])
812 && is_array($comments_map)
813 && isset($comments_map[$columnMeta['Field']])
814 ? htmlspecialchars($comments_map[$columnMeta['Field']])
815 : '') . '"'
816 . ' class="textfield" />';
818 return $html;
822 * Function get html for column auto increment
824 * @param int $columnNumber column number
825 * @param int $ci cell index
826 * @param int $ci_offset cell index offset
827 * @param array $columnMeta column meta
829 * @return string
831 function PMA_getHtmlForColumnAutoIncrement($columnNumber, $ci, $ci_offset,
832 $columnMeta
834 $html = '<input name="field_extra[' . $columnNumber . ']"'
835 . ' id="field_' . $columnNumber . '_' . ($ci - $ci_offset) . '"';
836 if (isset($columnMeta['Extra'])
837 && strtolower($columnMeta['Extra']) == 'auto_increment'
839 $html .= ' checked="checked"';
842 $html .= ' type="checkbox" value="AUTO_INCREMENT" />';
844 return $html;
848 * Function to get html for the column indexes
850 * @param int $columnNumber column number
851 * @param int $ci cell index
852 * @param int $ci_offset cell index offset
853 * @param array $columnMeta column meta
855 * @return string
857 function PMA_getHtmlForColumnIndexes($columnNumber, $ci, $ci_offset, $columnMeta)
859 $html = '<select name="field_key[' . $columnNumber . ']"'
860 . ' id="field_' . $columnNumber . '_' . ($ci - $ci_offset) . '">';
861 $html .= '<option value="none_' . $columnNumber . '">---</option>';
863 $html .= PMA_getHtmlForIndexTypeOption(
864 $columnNumber, $columnMeta, 'Primary', 'PRI'
866 $html .= PMA_getHtmlForIndexTypeOption(
867 $columnNumber, $columnMeta, 'Unique', 'UNI'
869 $html .= PMA_getHtmlForIndexTypeOption(
870 $columnNumber, $columnMeta, 'Index', 'MUL'
872 if (!PMA_DRIZZLE) {
873 $html .= PMA_getHtmlForIndexTypeOption(
874 $columnNumber, $columnMeta, 'Fulltext', 'FULLTEXT'
878 $html .= '</select>';
880 return $html;
884 * Function to get html for the index options
886 * @param int $columnNumber column number
887 * @param array $columnMeta column meta
888 * @param string $type index type
889 * @param string $key column meta key
891 * @return string
894 function PMA_getHtmlForIndexTypeOption($columnNumber, $columnMeta, $type, $key)
896 $html = '<option value="' . strtolower($type) . '_' . $columnNumber
897 . '" title="'
898 . __($type) . '"';
899 if (isset($columnMeta['Key']) && $columnMeta['Key'] == $key) {
900 $html .= ' selected="selected"';
902 $html .= '>' . strtoupper($type) . '</option>';
904 return $html;
909 * Function to get html for column null
911 * @param int $columnNumber column number
912 * @param int $ci cell index
913 * @param int $ci_offset cell index offset
914 * @param array $columnMeta column meta
916 * @return string
918 function PMA_getHtmlForColumnNull($columnNumber, $ci, $ci_offset, $columnMeta)
920 $html = '<input name="field_null[' . $columnNumber . ']"'
921 . ' id="field_' . $columnNumber . '_' . ($ci - $ci_offset) . '"';
922 if (! empty($columnMeta['Null'])
923 && $columnMeta['Null'] != 'NO'
924 && $columnMeta['Null'] != 'NOT NULL'
926 $html .= ' checked="checked"';
929 $html .= ' type="checkbox" value="NULL" class="allow_null"/>';
931 return $html;
935 * Function to get html for column attribute
937 * @param int $columnNumber column number
938 * @param int $ci cell index
939 * @param int $ci_offset cell index offset
940 * @param array $extracted_columnspec extracted column
941 * @param array $columnMeta column meta
942 * @param bool $submit_attribute submit attribute
943 * @param array $analyzed_sql analyzed sql
944 * @param bool $submit_default_current_timestamp submit default current time stamp
946 * @return string
948 function PMA_getHtmlForColumnAttribute($columnNumber, $ci, $ci_offset,
949 $extracted_columnspec, $columnMeta, $submit_attribute, $analyzed_sql,
950 $submit_default_current_timestamp
952 $html = '<select style="font-size: 70%;"'
953 . ' name="field_attribute[' . $columnNumber . ']"'
954 . ' id="field_' . $columnNumber . '_' . ($ci - $ci_offset) . '">';
956 $attribute = '';
957 if (isset($extracted_columnspec['attribute'])) {
958 $attribute = $extracted_columnspec['attribute'];
961 if (isset($columnMeta['Extra'])
962 && $columnMeta['Extra'] == 'on update CURRENT_TIMESTAMP'
964 $attribute = 'on update CURRENT_TIMESTAMP';
967 if (isset($submit_attribute) && $submit_attribute != false) {
968 $attribute = $submit_attribute;
971 // here, we have a TIMESTAMP that SHOW FULL COLUMNS reports as having the
972 // NULL attribute, but SHOW CREATE TABLE says the contrary. Believe
973 // the latter.
974 $create_table_fields = $analyzed_sql[0]['create_table_fields'];
975 if (PMA_MYSQL_INT_VERSION < 50025
976 && isset($columnMeta['Field'])
977 && isset($create_table_fields[$columnMeta['Field']]['type'])
978 && $create_table_fields[$columnMeta['Field']]['type'] == 'TIMESTAMP'
979 && $create_table_fields[$columnMeta['Field']]['timestamp_not_null'] == true
981 $columnMeta['Null'] = '';
984 // MySQL 4.1.2+ TIMESTAMP options
985 // (if on_update_current_timestamp is set, then it's TRUE)
986 if (isset($columnMeta['Field'])) {
987 $field = $create_table_fields[$columnMeta['Field']];
990 if (isset($field)
991 && isset($field['on_update_current_timestamp'])
993 $attribute = 'on update CURRENT_TIMESTAMP';
995 if ((isset($columnMeta['Field'])
996 && isset($field['default_current_timestamp']))
997 || (isset($submit_default_current_timestamp)
998 && $submit_default_current_timestamp)
1000 $default_current_timestamp = true;
1001 } else {
1002 $default_current_timestamp = false;
1005 $attribute_types = $GLOBALS['PMA_Types']->getAttributes();
1006 $cnt_attribute_types = count($attribute_types);
1007 for ($j = 0; $j < $cnt_attribute_types; $j++) {
1008 $html
1009 .= ' <option value="' . $attribute_types[$j] . '"';
1010 if (strtoupper($attribute) == strtoupper($attribute_types[$j])) {
1011 $html .= ' selected="selected"';
1013 $html .= '>' . $attribute_types[$j] . '</option>';
1016 $html .= '</select>';
1018 return $html;
1022 * Function to get html for column collation
1024 * @param int $columnNumber column number
1025 * @param int $ci cell index
1026 * @param int $ci_offset cell index offset
1027 * @param array $columnMeta column meta
1029 * @return string
1031 function PMA_getHtmlForColumnCollation($columnNumber, $ci, $ci_offset, $columnMeta)
1033 $tmp_collation
1034 = empty($columnMeta['Collation']) ? null : $columnMeta['Collation'];
1035 $html = PMA_generateCharsetDropdownBox(
1036 PMA_CSDROPDOWN_COLLATION, 'field_collation[' . $columnNumber . ']',
1037 'field_' . $columnNumber . '_' . ($ci - $ci_offset), $tmp_collation, false
1040 return $html;
1044 * Function get html for column length
1046 * @param int $columnNumber column number
1047 * @param int $ci cell index
1048 * @param int $ci_offset cell index offset
1049 * @param int $length_values_input_size length values input size
1050 * @param int $length_to_display length to disply
1052 * @return string
1054 function PMA_getHtmlForColumnLength($columnNumber, $ci, $ci_offset,
1055 $length_values_input_size, $length_to_display
1057 $html = '<input id="field_' . $columnNumber . '_' . ($ci - $ci_offset)
1058 . '"' . ' type="text" name="field_length[' . $columnNumber . ']" size="'
1059 . $length_values_input_size . '"' . ' value="' . htmlspecialchars(
1060 $length_to_display
1062 . '"'
1063 . ' class="textfield" />'
1064 . '<p class="enum_notice" id="enum_notice_' . $columnNumber . '_'
1065 . ($ci - $ci_offset)
1066 . '">';
1067 $html .= '<a href="#" class="open_enum_editor"> '
1068 . __('Edit ENUM/SET values') . '</a>'
1069 . '</p>';
1071 return $html;
1075 * Function to get html for the default column
1077 * @param int $columnNumber column number
1078 * @param int $ci cell index
1079 * @param int $ci_offset cell index offset
1080 * @param string $type_upper type upper
1081 * @param string $default_current_timestamp default current timestamp
1082 * @param array $columnMeta column meta
1084 * @return string
1086 function PMA_getHtmlForColumnDefault($columnNumber, $ci, $ci_offset, $type_upper,
1087 $default_current_timestamp, $columnMeta
1089 // here we put 'NONE' as the default value of drop-down; otherwise
1090 // users would have problems if they forget to enter the default
1091 // value (example, for an INT)
1092 $default_options = array(
1093 'NONE' => _pgettext('for default', 'None'),
1094 'USER_DEFINED' => __('As defined:'),
1095 'NULL' => 'NULL',
1096 'CURRENT_TIMESTAMP' => 'CURRENT_TIMESTAMP',
1099 // for a TIMESTAMP, do not show the string "CURRENT_TIMESTAMP" as a default
1100 // value
1101 if ($type_upper == 'TIMESTAMP'
1102 && ! empty($default_current_timestamp)
1103 && isset($columnMeta['Default'])
1105 $columnMeta['Default'] = '';
1108 if ($type_upper == 'BIT') {
1109 $columnMeta['DefaultValue']
1110 = PMA_Util::convertBitDefaultValue($columnMeta['DefaultValue']);
1113 $html = '<select name="field_default_type[' . $columnNumber
1114 . ']" id="field_' . $columnNumber . '_' . ($ci - $ci_offset)
1115 . '" class="default_type">';
1116 foreach ($default_options as $key => $value) {
1117 $html .= '<option value="' . $key . '"';
1118 // is only set when we go back to edit a field's structure
1119 if (isset($columnMeta['DefaultType'])
1120 && $columnMeta['DefaultType'] == $key
1122 $html .= ' selected="selected"';
1124 $html .= ' >' . $value . '</option>';
1126 $html .= '</select>';
1127 $html .= '<br />';
1129 $value = isset($columnMeta['DefaultValue'])
1130 ? htmlspecialchars($columnMeta['DefaultValue'])
1131 : '';
1132 if ($GLOBALS['cfg']['CharEditing'] == 'textarea') {
1133 $html .= '<textarea'
1134 . ' name="field_default_value[' . $columnNumber . ']" cols="15"'
1135 . ' class="textfield default_value">'
1136 . $value
1137 . '</textarea>';
1138 } else {
1139 $html .= '<input type="text"'
1140 . ' name="field_default_value[' . $columnNumber . ']" size="12"'
1141 . ' value="' . $value . '"'
1142 . ' class="textfield default_value" />';
1145 return $html;
1149 * Function to get html for column attributes
1151 * @param int $columnNumber column number
1152 * @param array $columnMeta column meta
1153 * @param string $type_upper type upper
1154 * @param int $length_values_input_size length values input size
1155 * @param int $length length
1156 * @param string $default_current_timestamp default current time stamp
1157 * @param array $extracted_columnspec extracted column spec
1158 * @param string $submit_attribute submit attribute
1159 * @param array $analyzed_sql analyzed sql
1160 * @param string $submit_default_current_timestamp submit default current time stamp
1161 * @param array $comments_map comments map
1162 * @param array $fields_meta fields map
1163 * @param bool $is_backup is backup
1164 * @param array $move_columns move columns
1165 * @param array $cfgRelation configuration relation
1166 * @param array $available_mime available mime
1167 * @param array $mime_map mime map
1169 * @return array
1171 function PMA_getHtmlForColumnAttributes($columnNumber, $columnMeta, $type_upper,
1172 $length_values_input_size, $length, $default_current_timestamp,
1173 $extracted_columnspec, $submit_attribute, $analyzed_sql,
1174 $submit_default_current_timestamp, $comments_map, $fields_meta, $is_backup,
1175 $move_columns, $cfgRelation, $available_mime, $mime_map
1177 // Cell index: If certain fields get left out, the counter shouldn't change.
1178 $ci = 0;
1179 // Everytime a cell shall be left out the STRG-jumping feature, $ci_offset
1180 // has to be incremented ($ci_offset++)
1181 $ci_offset = -1;
1183 $content_cell = array();
1185 // column name
1186 $content_cell[$ci] = PMA_getHtmlForColumnName(
1187 $columnNumber, $ci, $ci_offset, isset($columnMeta) ? $columnMeta : null
1189 $ci++;
1191 // column type
1192 $content_cell[$ci] = PMA_getHtmlForColumnType(
1193 $columnNumber, $ci, $ci_offset, $type_upper, isset($columnMeta) ? $columnMeta : null
1195 $ci++;
1197 // column length
1198 $content_cell[$ci] = PMA_getHtmlForColumnLength(
1199 $columnNumber, $ci, $ci_offset, $length_values_input_size, $length
1201 $ci++;
1203 // column default
1204 $content_cell[$ci] = PMA_getHtmlForColumnDefault(
1205 $columnNumber, $ci, $ci_offset,
1206 isset($type_upper) ? $type_upper : null,
1207 isset($default_current_timestamp) ? $default_current_timestamp : null,
1208 isset($columnMeta) ? $columnMeta : null
1210 $ci++;
1212 // column collation
1213 $content_cell[$ci] = PMA_getHtmlForColumnCollation(
1214 $columnNumber, $ci, $ci_offset, $columnMeta
1216 $ci++;
1218 // column attribute
1219 $content_cell[$ci] = PMA_getHtmlForColumnAttribute(
1220 $columnNumber, $ci, $ci_offset,
1221 isset($extracted_columnspec) ? $extracted_columnspec : null,
1222 isset($columnMeta) ? $columnMeta : null,
1223 isset($submit_attribute) ? $submit_attribute : null,
1224 isset($analyzed_sql) ? $analyzed_sql : null,
1225 isset($submit_default_current_timestamp)
1226 ? $submit_default_current_timestamp : null
1228 $ci++;
1230 // column NULL
1231 $content_cell[$ci] = PMA_getHtmlForColumnNull(
1232 $columnNumber, $ci, $ci_offset, isset($columnMeta) ? $columnMeta : null
1234 $ci++;
1236 // column indexes
1237 // See my other comment about this 'if'.
1238 if (!$is_backup) {
1239 $content_cell[$ci] = PMA_getHtmlForColumnIndexes(
1240 $columnNumber, $ci, $ci_offset, $columnMeta
1242 $ci++;
1243 } // end if ($action ==...)
1245 // column auto_increment
1246 $content_cell[$ci] = PMA_getHtmlForColumnAutoIncrement(
1247 $columnNumber, $ci, $ci_offset, $columnMeta
1249 $ci++;
1251 // column comments
1252 $content_cell[$ci] = PMA_getHtmlForColumnComment(
1253 $columnNumber, $ci, $ci_offset, isset($columnMeta) ? $columnMeta : null,
1254 $comments_map
1256 $ci++;
1258 // move column
1259 if (isset($fields_meta)) {
1260 $content_cell[$ci] = PMA_getHtmlForMoveColumn(
1261 $columnNumber, $ci, $ci_offset, $move_columns, $columnMeta
1263 $ci++;
1266 if ($cfgRelation['mimework']
1267 && $GLOBALS['cfg']['BrowseMIME']
1268 && $cfgRelation['commwork']
1270 // Column Mime-type
1271 $content_cell[$ci] = PMA_getHtmlForMimeType(
1272 $columnNumber, $ci, $ci_offset, $available_mime, $columnMeta, $mime_map
1274 $ci++;
1276 // Column Browser transformation
1277 $content_cell[$ci] = PMA_getHtmlForBrowserTransformation(
1278 $columnNumber, $ci, $ci_offset, $available_mime, $columnMeta, $mime_map
1280 $ci++;
1282 // column Transformation options
1283 $content_cell[$ci] = PMA_getHtmlForTransformationOption(
1284 $columnNumber, $ci, $ci_offset, isset($columnMeta) ? $columnMeta : null,
1285 isset($mime_map) ? $mime_map : null
1289 return $content_cell;
1293 * Function to get form parameters for old column
1295 * @param array $columnMeta column meta
1296 * @param int $length length
1297 * @param array $form_params form parameters
1298 * @param int $columnNumber column/field number
1299 * @param string $type type in lowercase without the length
1300 * @param array $extracted_columnspec details about the column spec
1302 * @return array
1304 function PMA_getFormParamsForOldColumn(
1305 $columnMeta, $length, $form_params, $columnNumber, $type,
1306 $extracted_columnspec
1308 // old column name
1309 if (isset($columnMeta['Field'])) {
1310 $form_params['field_orig[' . $columnNumber . ']']
1311 = $columnMeta['Field'];
1312 if (isset($columnMeta['column_status'])
1313 && !$columnMeta['column_status']['isEditable']
1315 $form_params['field_name[' . $columnNumber . ']']
1316 = $columnMeta['Field'];
1318 } else {
1319 $form_params['field_orig[' . $columnNumber . ']'] = '';
1321 // old column type
1322 if (isset($columnMeta['Type'])) {
1323 // keep in uppercase because the new type will be in uppercase
1324 $form_params['field_type_orig[' . $columnNumber . ']']
1325 = strtoupper($type);
1326 if (isset($columnMeta['column_status'])
1327 && !$columnMeta['column_status']['isEditable']
1329 $form_params['field_type[' . $columnNumber . ']']
1330 = strtoupper($type);
1332 } else {
1333 $form_params['field_type_orig[' . $columnNumber . ']'] = '';
1336 // old column length
1337 $form_params['field_length_orig[' . $columnNumber . ']'] = $length;
1339 // old column default
1340 $form_params['field_default_value_orig[' . $columnNumber . ']']
1341 = (isset($columnMeta['Default']) ? $columnMeta['Default'] : '');
1342 $form_params['field_default_type_orig[' . $columnNumber . ']']
1343 = (isset($columnMeta['DefaultType']) ? $columnMeta['DefaultType'] : '');
1345 // old column collation
1346 if (isset($columnMeta['Collation'])) {
1347 $form_params['field_collation_orig[' . $columnNumber . ']']
1348 = $columnMeta['Collation'];
1349 } else {
1350 $form_params['field_collation_orig[' . $columnNumber . ']'] = '';
1353 // old column attribute
1354 if (isset($extracted_columnspec['attribute'])) {
1355 $form_params['field_attribute_orig[' . $columnNumber . ']']
1356 = trim($extracted_columnspec['attribute']);
1357 } else {
1358 $form_params['field_attribute_orig[' . $columnNumber . ']'] = '';
1361 // old column null
1362 if (isset($columnMeta['Null'])) {
1363 $form_params['field_null_orig[' . $columnNumber . ']']
1364 = $columnMeta['Null'];
1365 } else {
1366 $form_params['field_null_orig[' . $columnNumber . ']'] = '';
1369 // old column extra (for auto_increment)
1370 if (isset($columnMeta['Extra'])) {
1371 $form_params['field_extra_orig[' . $columnNumber . ']']
1372 = $columnMeta['Extra'];
1373 } else {
1374 $form_params['field_extra_orig[' . $columnNumber . ']'] = '';
1377 // old column comment
1378 if (isset($columnMeta['Comment'])) {
1379 $form_params['field_comments_orig[' . $columnNumber . ']']
1380 = $columnMeta['Comment'];
1381 } else {
1382 $form_params['field_comment_orig[' . $columnNumber . ']'] = '';
1385 return $form_params;