2 /* vim: set expandtab sw=4 ts=4 sts=4: */
4 * Display form for changing/adding table fields/columns.
5 * Included by tbl_addfield.php and tbl_create.php
9 if (! defined('PHPMYADMIN')) {
16 require_once './libraries/Util.class.php';
18 PMA_Util
::checkParameters(array('server', 'db', 'table', 'action', 'num_fields'));
21 * Initialize to avoid code execution path warnings
24 if (! isset($num_fields)) {
27 if (! isset($mime_map)) {
30 if (! isset($columnMeta)) {
31 $columnMeta = array();
33 if (! isset($content_cells)) {
34 $content_cells = array();
38 // Get available character sets and storage engines
39 require_once './libraries/mysql_charsets.inc.php';
40 require_once './libraries/StorageEngine.class.php';
43 * Class for partition management
45 require_once './libraries/Partition.class.php';
47 require_once './libraries/tbl_columns_definition_form.lib.php';
49 /** @var PMA_String $pmaString */
50 $pmaString = $GLOBALS['PMA_String'];
52 $length_values_input_size = 8;
54 $_form_params = PMA_getFormsParameters(
55 $db, $table, $action, isset($num_fields) ?
$num_fields : null,
56 isset($selected) ?
$selected : null
59 $is_backup = ($action != 'tbl_create.php' && $action != 'tbl_addfield.php');
61 require_once './libraries/transformations.lib.php';
62 $cfgRelation = PMA_getRelationsParam();
65 $comments_map = PMA_getComments($db, $table);
67 if (isset($fields_meta)) {
68 $move_columns = PMA_getMoveColumns($db, $table);
71 if ($cfgRelation['mimework'] && $GLOBALS['cfg']['BrowseMIME']) {
72 $mime_map = PMA_getMIME($db, $table);
73 $available_mime = PMA_getAvailableMIMEtypes();
76 $header_cells = PMA_getHeaderCells(
77 $is_backup, isset($fields_meta) ?
$fields_meta : null,
78 $cfgRelation['mimework'], $db, $table
81 // workaround for field_fulltext, because its submitted indices contain
82 // the index as a value, not a key. Inserted here for easier maintenance
83 // and less code to change in existing files.
84 if (isset($field_fulltext) && is_array($field_fulltext)) {
85 foreach ($field_fulltext as $fulltext_nr => $fulltext_indexkey) {
86 $submit_fulltext[$fulltext_indexkey] = $fulltext_indexkey;
89 if (isset($_REQUEST['submit_num_fields'])) {
90 //if adding new fields, set regenerate to keep the original values
94 $foreigners = PMA_getForeigners($db, $table, '', 'foreign');
95 $child_references = PMA_getChildReferences($db, $table);
96 for ($columnNumber = 0; $columnNumber < $num_fields; $columnNumber++
) {
97 if (! empty($regenerate)) {
98 list($columnMeta, $submit_length, $submit_attribute,
99 $submit_default_current_timestamp, $comments_map, $mime_map)
100 = PMA_handleRegeneration(
102 isset($available_mime) ?
$mime_map : null,
103 $comments_map, $mime_map
105 } elseif (isset($fields_meta[$columnNumber])) {
106 $columnMeta = PMA_getColumnMetaForDefault(
107 $fields_meta[$columnNumber],
108 isset($analyzed_sql[0]['create_table_fields']
109 [$fields_meta[$columnNumber]['Field']]['default_value'])
113 if (isset($columnMeta['Type'])) {
114 $extracted_columnspec = PMA_Util
::extractColumnSpec($columnMeta['Type']);
115 if ($extracted_columnspec['type'] == 'bit') {
116 $columnMeta['Default']
117 = PMA_Util
::convertBitDefaultValue($columnMeta['Default']);
119 $type = $extracted_columnspec['type'];
120 $length = $extracted_columnspec['spec_in_brackets'];
123 $columnMeta['Type'] = '';
126 $extracted_columnspec = array();
129 // some types, for example longtext, are reported as
130 // "longtext character set latin7" when their charset and / or collation
131 // differs from the ones of the corresponding database.
132 $tmp = /*overload*/mb_strpos($type, 'character set');
134 $type = /*overload*/mb_substr($type, 0, $tmp - 1);
136 // rtrim the type, for cases like "float unsigned"
137 $type = rtrim($type);
140 if (isset($submit_length) && $submit_length != false) {
141 $length = $submit_length;
144 // Variable tell if current column is bound in a foreign key constraint or not.
145 if (isset($columnMeta['Field']) && isset($_form_params['table'])) {
146 $columnMeta['column_status'] = PMA_checkChildForeignReferences(
148 $_form_params['table'],
149 $columnMeta['Field'],
154 // old column attributes
156 $_form_params = PMA_getFormParamsForOldColumn(
157 $columnMeta, $length, $_form_params, $columnNumber, $type,
158 $extracted_columnspec
162 $content_cells[$columnNumber] = PMA_getHtmlForColumnAttributes(
163 $columnNumber, isset($columnMeta) ?
$columnMeta : array(),
164 /*overload*/mb_strtoupper($type), $length_values_input_size, $length,
165 isset($default_current_timestamp) ?
$default_current_timestamp : null,
166 isset($extracted_columnspec) ?
$extracted_columnspec : null,
167 isset($submit_attribute) ?
$submit_attribute : null,
168 isset($analyzed_sql) ?
$analyzed_sql : null,
169 isset($submit_default_current_timestamp)
170 ?
$submit_default_current_timestamp : null,
171 $comments_map, isset($fields_meta) ?
$fields_meta : null, $is_backup,
172 isset($move_columns) ?
$move_columns : array(), $cfgRelation,
173 isset($available_mime) ?
$available_mime : array(),
174 isset($mime_map) ?
$mime_map : array()
177 $html = PMA_getHtmlForTableCreateOrAddField(
178 $action, $_form_params, $content_cells, $header_cells
181 unset($_form_params);
182 $response = PMA_Response
::getInstance();
183 $header = $response->getHeader();
184 $scripts = $header->getScripts();
185 $scripts->addFile('jquery/jquery.uitablefilter.js');
186 $scripts->addFile('indexes.js');
187 $response->addHTML($html);