2 /* vim: set expandtab sw=4 ts=4 sts=4: */
4 * set of functions used by tbl_columns_definitions_form.inc.php
8 if (!defined('PHPMYADMIN')) {
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)
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;
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;
61 * Function to get html for table comments, storage engine, collation and
62 * partition definition
66 function PMA_getHtmlForTableConfigurations()
70 . '<th>' . __('Table comments:') . '</th>'
71 . '<td width="25"> </td>'
72 . '<th>' . __('Storage Engine:')
73 . PMA_Util
::showMySQLDocu('Storage_engines')
75 . '<td width="25"> </td>'
76 . '<th>' . __('Collation:') . '</th>'
78 . '<tr><td><input type="text" name="comment" size="40" maxlength="80"'
80 . (isset($_REQUEST['comment'])
81 ?
htmlspecialchars($_REQUEST['comment'])
83 . '" class="textfield" />'
85 . '<td width="25"> </td>'
87 . PMA_StorageEngine
::getHtmlSelect(
88 'tbl_storage_engine', null,
89 (isset($_REQUEST['tbl_storage_engine'])
90 ?
$_REQUEST['tbl_storage_engine']
95 . '<td width="25"> </td>'
97 . PMA_generateCharsetDropdownBox(
98 PMA_CSDROPDOWN_COLLATION
, 'tbl_collation', null,
99 (isset($_REQUEST['tbl_collation'])
100 ?
$_REQUEST['tbl_collation']
108 if (PMA_Partition
::havePartitioning()) {
109 $html .= '<tr class="vtop">'
110 . '<th>' . __('PARTITION definition:') . ' '
111 . PMA_Util
::showMySQLDocu('Partitioning')
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'])
134 * Function to get html for the footer
138 function PMA_getHtmlForFooter()
140 $html = '<fieldset class="tblFooters">'
141 . '<input type="submit" name="do_save_data" value="' . __('Save') . '" />'
143 . '<div id="properties_message"></div>'
146 $html .= '<div id="popup_background"></div>';
152 * Function to get html for table create table name and number of fields
156 function PMA_getHtmlForTableNameAndNoOfColumns()
159 . '<tr class="vmiddle">'
160 . '<td>' . __('Table name')
161 . ': <input type="text" name="table" size="40" maxlength="80"'
163 . (isset($_REQUEST['table']) ?
htmlspecialchars($_REQUEST['table']) : '')
164 . '" class="textfield" autofocus required />'
168 __('Add %s column(s)'), '<input type="text" id="added_fields" '
169 . 'name="added_fields" size="2" value="1" onfocus="this.select'
173 $html .= '<input type="submit" name="submit_num_fields"'
174 . 'value="' . __('Go') . '"'
176 . ' checkFormElementInRange(this.form, \'added_fields\', \''
178 '\'', '\\\'', __('You have to add at least one column.')
189 * Function to get html for table field definitions
191 * @param array $header_cells header cells
192 * @param array $content_cells content cells
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>';
203 foreach ($header_cells as $header_val) {
204 $html .= '<th>' . $header_val . '</th>';
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>';
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
236 function PMA_getHtmlForTableCreateOrAddField($action, $form_params, $content_cells,
239 $html = '<form method="post" action="' . $action . '" class="'
240 . ($action == 'tbl_create.php' ?
'create_table' : 'append_fields')
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();
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
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\''
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.
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']) {
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">',
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\''
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
353 function PMA_getMoveColumns($db, $table)
355 $move_columns_sql_query = 'SELECT * FROM '
356 . PMA_Util
::backquote($db)
358 . PMA_Util
::backquote($table)
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
374 function PMA_getRowDataForRegeneration($columnNumber, $submit_fulltext)
376 $columnMeta['Field'] = isset($_REQUEST['field_name'][$columnNumber])
377 ?
$_REQUEST['field_name'][$columnNumber]
379 $columnMeta['Type'] = isset($_REQUEST['field_type'][$columnNumber])
380 ?
$_REQUEST['field_type'][$columnNumber]
382 $columnMeta['Collation'] = isset($_REQUEST['field_collation'][$columnNumber])
383 ?
$_REQUEST['field_collation'][$columnNumber]
385 $columnMeta['Null'] = isset($_REQUEST['field_null'][$columnNumber])
386 ?
$_REQUEST['field_null'][$columnNumber]
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) {
395 $columnMeta['Key'] = 'PRI';
398 $columnMeta['Key'] = 'MUL';
401 $columnMeta['Key'] = 'UNI';
404 $columnMeta['Key'] = 'FULLTEXT';
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]
415 $columnMeta['DefaultValue']
416 = isset($_REQUEST['field_default_value'][$columnNumber])
417 ?
$_REQUEST['field_default_value'][$columnNumber]
420 switch ($columnMeta['DefaultType']) {
422 $columnMeta['Default'] = null;
424 case 'USER_DEFINED' :
425 $columnMeta['Default'] = $columnMeta['DefaultValue'];
428 case 'CURRENT_TIMESTAMP' :
429 $columnMeta['Default'] = $columnMeta['DefaultType'];
434 = (isset($_REQUEST['field_extra'][$columnNumber])
435 ?
$_REQUEST['field_extra'][$columnNumber]
437 $columnMeta['Comment']
438 = (isset($submit_fulltext[$columnNumber])
439 && ($submit_fulltext[$columnNumber] == $columnNumber)
447 * Function to get submit properties for regenerating previous when error occurred.
449 * @param int $columnNumber coulmn number
453 function PMA_getSubmitPropertiesForRegeneration($columnNumber)
456 = (isset($_REQUEST['field_length'][$columnNumber])
457 ?
$_REQUEST['field_length'][$columnNumber]
460 = (isset($_REQUEST['field_attribute'][$columnNumber])
461 ?
$_REQUEST['field_attribute'][$columnNumber]
464 $submit_default_current_timestamp
465 = (isset($_REQUEST['field_default_current_timestamp'][$columnNumber])
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
485 function PMA_handleRegeneration($columnNumber, $submit_fulltext, $comments_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];
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
529 function PMA_getColumnMetaForDefault($columnMeta, $isDefault)
531 switch ($columnMeta['Default']) {
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'];
543 $columnMeta['DefaultType'] = 'NONE';
544 $columnMeta['DefaultValue'] = '';
547 case 'CURRENT_TIMESTAMP':
548 $columnMeta['DefaultType'] = 'CURRENT_TIMESTAMP';
549 $columnMeta['DefaultValue'] = '';
552 $columnMeta['DefaultType'] = 'USER_DEFINED';
553 $columnMeta['DefaultValue'] = $columnMeta['Default'];
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
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') . '"'
577 . (isset($columnMeta['Field'])
578 ?
htmlspecialchars($columnMeta['Field']) : '')
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
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>';
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
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'])
622 $mime_map[$columnMeta['Field']]
623 ['transformation_options']
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 . '"'
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
649 function PMA_getHtmlForMimeType($columnNumber, $ci, $ci_offset,
650 $available_mime, $columnMeta, $mime_map
652 $html = '<select id="field_' . $columnNumber . '_'
654 . '" size="1" name="field_mimetype[' . $columnNumber . ']">';
655 $html .= ' <option value=""> </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))
665 $html .= ' <option value="'
666 . str_replace('/', '_', $mimetype) . '" ' . $checked . '>'
667 . htmlspecialchars($mimetype) . '</option>';
671 $html .= '</select>';
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
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')
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'])
702 $available_mime['transformation_file'][$mimekey]
704 $mime_map[$columnMeta['Field']]['transformation']
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>';
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
734 function PMA_getHtmlForMoveColumn($columnNumber, $ci, $ci_offset, $move_columns,
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"> </option>';
741 // find index of current column
743 for ($mi = 0, $cols = count($move_columns); $mi < $cols; $mi++
) {
744 if ($move_columns[$mi]->name
== $columnMeta['Field']) {
745 $current_index = $mi;
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++
) {
755 '<option value="' . htmlspecialchars($move_columns[$mi]->name
) . '"'
756 . (($current_index == $mi ||
$current_index == $mi +
1)
757 ?
' disabled="disabled"'
764 $move_columns[$mi]->name
771 $html .= '</select>';
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
787 function PMA_getHtmlForColumnComment($columnNumber, $ci, $ci_offset, $columnMeta,
790 $html = '<input id="field_' . $columnNumber . '_' . ($ci - $ci_offset)
791 . '"' . ' type="text" name="field_comments[' . $columnNumber
793 . ' value="' . (isset($columnMeta['Field'])
794 && is_array($comments_map)
795 && isset($comments_map[$columnMeta['Field']])
796 ?
htmlspecialchars($comments_map[$columnMeta['Field']])
798 . ' class="textfield" />';
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
813 function PMA_getHtmlForColumnAutoIncrement($columnNumber, $ci, $ci_offset,
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" />';
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
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'
855 $html .= PMA_getHtmlForIndexTypeOption(
856 $columnNumber, $columnMeta, 'Fulltext', 'FULLTEXT'
860 $html .= '</select>';
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
876 function PMA_getHtmlForIndexTypeOption($columnNumber, $columnMeta, $type, $key)
878 $html = '<option value="' . strtolower($type) . '_' . $columnNumber
881 if (isset($columnMeta['Key']) && $columnMeta['Key'] == $key) {
882 $html .= ' selected="selected"';
884 $html .= '>' . strtoupper($type) . '</option>';
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
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"/>';
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
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) . '">';
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
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']];
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;
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++
) {
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>';
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
1013 function PMA_getHtmlForColumnCollation($columnNumber, $ci, $ci_offset, $columnMeta)
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
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
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(
1045 . ' class="textfield" />'
1046 . '<p class="enum_notice" id="enum_notice_' . $columnNumber . '_'
1047 . ($ci - $ci_offset)
1049 $html .= __('ENUM or SET data too long?')
1050 . '<a href="#" class="open_enum_editor"> '
1051 . __('Get more editing space') . '</a>'
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
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:'),
1079 'CURRENT_TIMESTAMP' => 'CURRENT_TIMESTAMP',
1082 // for a TIMESTAMP, do not show the string "CURRENT_TIMESTAMP" as a default
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>';
1111 $html .= '<input type="text"'
1112 . ' name="field_default_value[' . $columnNumber . ']" size="12"'
1113 . ' value="' . (isset($columnMeta['DefaultValue'])
1114 ?
htmlspecialchars($columnMeta['DefaultValue'])
1116 . ' class="textfield default_value" />';
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
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.
1152 // Everytime a cell shall be left out the STRG-jumping feature, $ci_offset
1153 // has to be incremented ($ci_offset++)
1156 $content_cell = array();
1159 $content_cell[$ci] = PMA_getHtmlForColumnName(
1160 $columnNumber, $ci, $ci_offset, isset($columnMeta) ?
$columnMeta : null
1165 $content_cell[$ci] = PMA_getHtmlForColumnType(
1166 $columnNumber, $ci, $ci_offset, $type_upper
1171 $content_cell[$ci] = PMA_getHtmlForColumnLength(
1172 $columnNumber, $ci, $ci_offset, $length_values_input_size, $length
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
1186 $content_cell[$ci] = PMA_getHtmlForColumnCollation(
1187 $columnNumber, $ci, $ci_offset, $columnMeta
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
1204 $content_cell[$ci] = PMA_getHtmlForColumnNull(
1205 $columnNumber, $ci, $ci_offset, isset($columnMeta) ?
$columnMeta : null
1210 // See my other comment about this 'if'.
1212 $content_cell[$ci] = PMA_getHtmlForColumnIndexes(
1213 $columnNumber, $ci, $ci_offset, $columnMeta
1216 } // end if ($action ==...)
1218 // column auto_increment
1219 $content_cell[$ci] = PMA_getHtmlForColumnAutoIncrement(
1220 $columnNumber, $ci, $ci_offset, $columnMeta
1225 $content_cell[$ci] = PMA_getHtmlForColumnComment(
1226 $columnNumber, $ci, $ci_offset, isset($columnMeta) ?
$columnMeta : null,
1232 if (isset($fields_meta)) {
1233 $content_cell[$ci] = PMA_getHtmlForMoveColumn(
1234 $columnNumber, $ci, $ci_offset, $move_columns, $columnMeta
1239 if ($cfgRelation['mimework']
1240 && $GLOBALS['cfg']['BrowseMIME']
1241 && $cfgRelation['commwork']
1244 $content_cell[$ci] = PMA_getHtmlForMimeType(
1245 $columnNumber, $ci, $ci_offset, $available_mime, $columnMeta, $mime_map
1249 // Column Browser transformation
1250 $content_cell[$ci] = PMA_getHtmlForBrowserTransformation(
1251 $columnNumber, $ci, $ci_offset, $available_mime, $columnMeta, $mime_map
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
1274 function PMA_getFormParamsForOldColumn($columnMeta, $length, $form_params)
1276 if (isset($columnMeta['Field'])) {
1277 $form_params['field_orig[' . $columnNumber . ']']
1278 = $columnMeta['Field'];
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;