diff --git a/libraries/tbl_columns_definition_form.inc.php b/libraries/tbl_columns_definition_form.inc.php index d22e82a2e3..0fe95993b4 100644 --- a/libraries/tbl_columns_definition_form.inc.php +++ b/libraries/tbl_columns_definition_form.inc.php @@ -48,42 +48,6 @@ $_form_params = PMA_getFormsParameters( $is_backup = ($action != 'tbl_create.php' && $action != 'tbl_addfield.php'); -$header_cells = array(); -$content_cells = array(); - -$header_cells[] = __('Name'); -$header_cells[] = __('Type') - . PMA_Util::showMySQLDocu('SQL-Syntax', 'data-types'); -$header_cells[] = __('Length/Values') - . PMA_Util::showHint( - __( - 'If column type is "enum" or "set", please enter the values using' - . ' this format: \'a\',\'b\',\'c\'…
If you ever need to put' - . ' a backslash ("\") or a single quote ("\'") amongst those values,' - . ' precede it with a backslash (for example \'\\\\xyz\' or \'a\\\'b\').' - ) - ); -$header_cells[] = __('Default') - . PMA_Util::showHint( - __( - 'For default values, please enter just a single value,' - . ' without backslash escaping or quotes, using this format: a' - ) - ); -$header_cells[] = __('Collation'); -$header_cells[] = __('Attributes'); -$header_cells[] = __('Null'); - -// We could remove this 'if' and let the key information be shown and -// editable. However, for this to work, structure.lib.php must be modified -// to use the key fields, as tbl_addfield does. - -if (! $is_backup) { - $header_cells[] = __('Index'); -} - -$header_cells[] = 'A_I'; - require_once './libraries/transformations.lib.php'; $cfgRelation = PMA_getRelationsParam(); @@ -92,54 +56,21 @@ $mime_map = array(); $available_mime = array(); $comments_map = PMA_getComments($db, $table); -$header_cells[] = __('Comments'); if (isset($fields_meta)) { - // for moving, load all available column names - $move_columns_sql_query = 'SELECT * FROM ' - . PMA_Util::backquote($db) - . '.' - . PMA_Util::backquote($table) - . ' LIMIT 1'; - $move_columns_sql_result = $GLOBALS['dbi']->tryQuery($move_columns_sql_query); - $move_columns = $GLOBALS['dbi']->getFieldsMeta($move_columns_sql_result); - unset($move_columns_sql_query, $move_columns_sql_result); - - $header_cells[] = __('Move column'); + $move_columns = PMA_getMoveColumns($db, $table); } if ($cfgRelation['mimework'] && $GLOBALS['cfg']['BrowseMIME']) { $mime_map = PMA_getMIME($db, $table); $available_mime = PMA_getAvailableMIMEtypes(); - - $hint = '
' - . sprintf( - __( - 'For a list of available transformation options and their MIME' - . ' type transformations, click on %stransformation descriptions%s' - ), - '', - '' - ); - - - $header_cells[] = __('MIME type'); - $header_cells[] = __('Browser transformation'); - $header_cells[] = __('Transformation options') - . PMA_Util::showHint( - __( - 'Please enter the values for transformation options using this' - . ' format: \'a\', 100, b,\'c\'…
If you ever need to put' - . ' a backslash ("\") or a single quote ("\'") amongst those' - . ' values, precede it with a backslash (for example \'\\\\xyz\'' - . ' or \'a\\\'b\').' - ) - . $hint - ); } +$header_cells = PMA_getHeaderCells( + $is_backup, isset($fields_meta) ? $fields_meta : null, + $cfgRelation['mimework'], $db, $table +); + // workaround for field_fulltext, because its submitted indices contain // the index as a value, not a key. Inserted here for easier maintaineance // and less code to change in existing files. @@ -151,105 +82,12 @@ if (isset($field_fulltext) && is_array($field_fulltext)) { for ($i = 0; $i < $num_fields; $i++) { if (! empty($regenerate)) { - // An error happened with previous inputs, so we will restore the data - // to embed it once again in this form. - - $row['Field'] = isset($_REQUEST['field_name'][$i]) - ? $_REQUEST['field_name'][$i] - : false; - $row['Type'] = isset($_REQUEST['field_type'][$i]) - ? $_REQUEST['field_type'][$i] - : false; - $row['Collation'] = isset($_REQUEST['field_collation'][$i]) - ? $_REQUEST['field_collation'][$i] - : ''; - $row['Null'] = isset($_REQUEST['field_null'][$i]) - ? $_REQUEST['field_null'][$i] - : ''; - - if (isset($_REQUEST['field_key'][$i]) - && $_REQUEST['field_key'][$i] == 'primary_' . $i - ) { - $row['Key'] = 'PRI'; - } elseif (isset($_REQUEST['field_key'][$i]) - && $_REQUEST['field_key'][$i] == 'index_' . $i - ) { - $row['Key'] = 'MUL'; - } elseif (isset($_REQUEST['field_key'][$i]) - && $_REQUEST['field_key'][$i] == 'unique_' . $i - ) { - $row['Key'] = 'UNI'; - } elseif (isset($_REQUEST['field_key'][$i]) - && $_REQUEST['field_key'][$i] == 'fulltext_' . $i - ) { - $row['Key'] = 'FULLTEXT'; - } else { - $row['Key'] = ''; - } - - // put None in the drop-down for Default, when someone adds a field - $row['DefaultType'] = isset($_REQUEST['field_default_type'][$i]) - ? $_REQUEST['field_default_type'][$i] - : 'NONE'; - $row['DefaultValue'] = isset($_REQUEST['field_default_value'][$i]) - ? $_REQUEST['field_default_value'][$i] - : ''; - - switch ($row['DefaultType']) { - case 'NONE' : - $row['Default'] = null; - break; - case 'USER_DEFINED' : - $row['Default'] = $row['DefaultValue']; - break; - case 'NULL' : - case 'CURRENT_TIMESTAMP' : - $row['Default'] = $row['DefaultType']; - break; - } - - $row['Extra'] - = (isset($_REQUEST['field_extra'][$i]) - ? $_REQUEST['field_extra'][$i] - : false); - $row['Comment'] - = (isset($submit_fulltext[$i]) - && ($submit_fulltext[$i] == $i) - ? 'FULLTEXT' - : false); - - $submit_length - = (isset($_REQUEST['field_length'][$i]) - ? $_REQUEST['field_length'][$i] - : false); - $submit_attribute - = (isset($_REQUEST['field_attribute'][$i]) - ? $_REQUEST['field_attribute'][$i] - : false); - - $submit_default_current_timestamp - = (isset($_REQUEST['field_default_current_timestamp'][$i]) - ? true - : false); - - if (isset($_REQUEST['field_comments'][$i])) { - $comments_map[$row['Field']] = $_REQUEST['field_comments'][$i]; - } - - if (isset($_REQUEST['field_mimetype'][$i])) { - $mime_map[$row['Field']]['mimetype'] = $_REQUEST['field_mimetype'][$i]; - } - - if (isset($_REQUEST['field_transformation'][$i])) { - $mime_map[$row['Field']]['transformation'] - = $_REQUEST['field_transformation'][$i]; - } - - if (isset($_REQUEST['field_transformation_options'][$i])) { - $mime_map[$row['Field']]['transformation_options'] - = $_REQUEST['field_transformation_options'][$i]; - } - + list($row, $submit_length, $submit_attribute, + $submit_default_current_timestamp, $comments_map, $mime_map) + = PMA_handleRegeneration( + isset($available_mime) ? $mime_map : null, + $comments_map, $mime_map + ); } elseif (isset($fields_meta[$i])) { $row = $fields_meta[$i]; switch ($row['Default']) { diff --git a/libraries/tbl_columns_definition_form.lib.php b/libraries/tbl_columns_definition_form.lib.php index 9eede0b338..dcac9f3f46 100644 --- a/libraries/tbl_columns_definition_form.lib.php +++ b/libraries/tbl_columns_definition_form.lib.php @@ -188,8 +188,8 @@ function PMA_getHtmlForTableNameAndNoOfColumns() /** * Function to get html for table field definitions * - * @param array $header_cells - * @param array $content_cells + * @param array $header_cells header cells + * @param array $content_cells content cells * * @return string */ @@ -257,4 +257,254 @@ function PMA_getHtmlForTableCreateOrAddField($action, $form_params, $content_cel return $html; } + +/** + * Function to get header cells + * + * @param bool $is_backup whether backup or not + * @param array $fields_meta fields meta data + * @param bool $mimework whether mimework or not + * @param string $db current database + * @param string $table current table + * + * @return string + */ +function PMA_getHeaderCells($is_backup, $fields_meta, $mimework, $db, $table) +{ + $header_cells = array(); + $header_cells[] = __('Name'); + $header_cells[] = __('Type') + . PMA_Util::showMySQLDocu('SQL-Syntax', 'data-types'); + $header_cells[] = __('Length/Values') + . PMA_Util::showHint( + __( + 'If column type is "enum" or "set", please enter the values using' + . ' this format: \'a\',\'b\',\'c\'…
If you ever need to put' + . ' a backslash ("\") or a single quote ("\'") amongst those' + . ' values, precede it with a backslash (for example \'\\\\xyz\'' + . ' or \'a\\\'b\').' + ) + ); + $header_cells[] = __('Default') + . PMA_Util::showHint( + __( + 'For default values, please enter just a single value,' + . ' without backslash escaping or quotes, using this format: a' + ) + ); + $header_cells[] = __('Collation'); + $header_cells[] = __('Attributes'); + $header_cells[] = __('Null'); + + // We could remove this 'if' and let the key information be shown and + // editable. However, for this to work, structure.lib.php must be modified + // to use the key fields, as tbl_addfield does. + if (! $is_backup) { + $header_cells[] = __('Index'); + } + + $header_cells[] = 'A_I'; + $header_cells[] = __('Comments'); + + if (isset($fields_meta)) { + $header_cells[] = __('Move column'); + } + + if ($mimework && $GLOBALS['cfg']['BrowseMIME']) { + $hint = '
' + . sprintf( + __( + 'For a list of available transformation options and their MIME' + . ' type transformations, click on' + . ' %stransformation descriptions%s' + ), + '', + '' + ); + + $header_cells[] = __('MIME type'); + $header_cells[] = __('Browser transformation'); + $header_cells[] = __('Transformation options') + . PMA_Util::showHint( + __( + 'Please enter the values for transformation options using this' + . ' format: \'a\', 100, b,\'c\'…
If you ever need to put' + . ' a backslash ("\") or a single quote ("\'") amongst those' + . ' values, precede it with a backslash (for example \'\\\\xyz\'' + . ' or \'a\\\'b\').' + ) + . $hint + ); + } + + return $header_cells; +} + +/** + * Function for moving, load all available column names + * + * @param string $db current database + * @param string $table current table + * + * @return array + */ +function PMA_getMoveColumns($db, $table) +{ + $move_columns_sql_query = 'SELECT * FROM ' + . PMA_Util::backquote($db) + . '.' + . PMA_Util::backquote($table) + . ' LIMIT 1'; + $move_columns_sql_result = $GLOBALS['dbi']->tryQuery($move_columns_sql_query); + $move_columns = $GLOBALS['dbi']->getFieldsMeta($move_columns_sql_result); + + return $move_columns; +} + +/** + * Function to get row data for regenerating previous when error occured. + * + * @param array $submit_fulltext submit full text + * + * @return array + */ +function PMA_getRowDataForRegeneration($submit_fulltext) +{ + $row['Field'] = isset($_REQUEST['field_name'][$i]) + ? $_REQUEST['field_name'][$i] + : false; + $row['Type'] = isset($_REQUEST['field_type'][$i]) + ? $_REQUEST['field_type'][$i] + : false; + $row['Collation'] = isset($_REQUEST['field_collation'][$i]) + ? $_REQUEST['field_collation'][$i] + : ''; + $row['Null'] = isset($_REQUEST['field_null'][$i]) + ? $_REQUEST['field_null'][$i] + : ''; + + if (isset($_REQUEST['field_key'][$i]) + && $_REQUEST['field_key'][$i] == 'primary_' . $i + ) { + $row['Key'] = 'PRI'; + } elseif (isset($_REQUEST['field_key'][$i]) + && $_REQUEST['field_key'][$i] == 'index_' . $i + ) { + $row['Key'] = 'MUL'; + } elseif (isset($_REQUEST['field_key'][$i]) + && $_REQUEST['field_key'][$i] == 'unique_' . $i + ) { + $row['Key'] = 'UNI'; + } elseif (isset($_REQUEST['field_key'][$i]) + && $_REQUEST['field_key'][$i] == 'fulltext_' . $i + ) { + $row['Key'] = 'FULLTEXT'; + } else { + $row['Key'] = ''; + } + + // put None in the drop-down for Default, when someone adds a field + $row['DefaultType'] = isset($_REQUEST['field_default_type'][$i]) + ? $_REQUEST['field_default_type'][$i] + : 'NONE'; + $row['DefaultValue'] = isset($_REQUEST['field_default_value'][$i]) + ? $_REQUEST['field_default_value'][$i] + : ''; + + switch ($row['DefaultType']) { + case 'NONE' : + $row['Default'] = null; + break; + case 'USER_DEFINED' : + $row['Default'] = $row['DefaultValue']; + break; + case 'NULL' : + case 'CURRENT_TIMESTAMP' : + $row['Default'] = $row['DefaultType']; + break; + } + + $row['Extra'] + = (isset($_REQUEST['field_extra'][$i]) + ? $_REQUEST['field_extra'][$i] + : false); + $row['Comment'] + = (isset($submit_fulltext[$i]) + && ($submit_fulltext[$i] == $i) + ? 'FULLTEXT' + : false); + + return $row; +} + +/** + * Function to get submit properties for regenerating previous when error occured. + * + * @return array + */ +function PMA_getSubmitPropertiesForRegeneration() +{ + $submit_length + = (isset($_REQUEST['field_length'][$i]) + ? $_REQUEST['field_length'][$i] + : false); + $submit_attribute + = (isset($_REQUEST['field_attribute'][$i]) + ? $_REQUEST['field_attribute'][$i] + : false); + + $submit_default_current_timestamp + = (isset($_REQUEST['field_default_current_timestamp'][$i]) + ? true + : false); + + return array( + $submit_length, $submit_attribute, $submit_default_current_timestamp + ); +} + +/** + * An error happened with previous inputs, so we will restore the data + * to embed it once again in this form. + * + * @param array $submit_fulltext submit full text + * @param array $comments_map comments map + * @param array $mime_map mime map + * + * @return array + */ +function PMA_handleRegeneration($submit_fulltext, $comments_map, $mime_map) +{ + $row = PMA_getRowDataForRegeneration( + isset($submit_fulltext) ? $submit_fulltext : null + ); + + list($submit_length, $submit_attribute, $submit_default_current_timestamp) + = PMA_getSubmitPropertiesForRegeneration(); + + if (isset($_REQUEST['field_comments'][$i])) { + $comments_map[$row['Field']] = $_REQUEST['field_comments'][$i]; + } + + if (isset($_REQUEST['field_mimetype'][$i])) { + $mime_map[$row['Field']]['mimetype'] = $_REQUEST['field_mimetype'][$i]; + } + + if (isset($_REQUEST['field_transformation'][$i])) { + $mime_map[$row['Field']]['transformation'] + = $_REQUEST['field_transformation'][$i]; + } + + if (isset($_REQUEST['field_transformation_options'][$i])) { + $mime_map[$row['Field']]['transformation_options'] + = $_REQUEST['field_transformation_options'][$i]; + } + + return array( + $row, $submit_length, $submit_attribute, $submit_default_current_timestamp, + $comments_map, $mime_map + ); +} ?>