2 /* vim: set expandtab sw=4 ts=4 sts=4: */
4 * Displays add field form and handles it
8 declare(strict_types
=1);
10 use PhpMyAdmin\Config
;
11 use PhpMyAdmin\CreateAddField
;
12 use PhpMyAdmin\DatabaseInterface
;
13 use PhpMyAdmin\Message
;
14 use PhpMyAdmin\Response
;
15 use PhpMyAdmin\Transformations
;
19 if (! defined('ROOT_PATH')) {
20 define('ROOT_PATH', __DIR__
. DIRECTORY_SEPARATOR
);
23 require_once ROOT_PATH
. 'libraries/common.inc.php';
25 /** @var Response $response */
26 $response = $containerBuilder->get(Response
::class);
28 /** @var DatabaseInterface $dbi */
29 $dbi = $containerBuilder->get(DatabaseInterface
::class);
31 $header = $response->getHeader();
32 $scripts = $header->getScripts();
33 $scripts->addFile('table/structure.js');
36 Util
::checkParameters(['db', 'table']);
38 /** @var Transformations $transformations */
39 $transformations = $containerBuilder->get('transformations');
41 /** @var string $db */
42 $db = $containerBuilder->getParameter('db');
44 /** @var string $table */
45 $table = $containerBuilder->getParameter('table');
47 /** @var Config $config */
48 $config = $containerBuilder->get('config');
49 $cfg = $config->settings
;
52 * Defines the url to return to in case of error in a sql statement
54 $err_url = 'tbl_sql.php' . Url
::getCommon(
62 * The form used to define the field to add has been submitted
66 // check number of fields to be created
67 if (isset($_POST['submit_num_fields'])) {
68 if (isset($_POST['orig_after_field'])) {
69 $_POST['after_field'] = $_POST['orig_after_field'];
71 if (isset($_POST['orig_field_where'])) {
72 $_POST['field_where'] = $_POST['orig_field_where'];
75 intval($_POST['orig_num_fields']) +
intval($_POST['added_fields']),
79 } elseif (isset($_POST['num_fields']) && intval($_POST['num_fields']) > 0) {
80 $num_fields = min(4096, intval($_POST['num_fields']));
85 if (isset($_POST['do_save_data'])) {
86 //avoid an incorrect calling of PMA_updateColumns() via
87 //tbl_structure.php below
88 unset($_POST['do_save_data']);
90 $createAddField = new CreateAddField($dbi);
92 list($result, $sql_query) = $createAddField->tryColumnCreationQuery($db, $table, $err_url);
94 if ($result === true) {
95 // Update comment table for mime types [MIME]
96 if (isset($_POST['field_mimetype'])
97 && is_array($_POST['field_mimetype'])
100 foreach ($_POST['field_mimetype'] as $fieldindex => $mimetype) {
101 if (isset($_POST['field_name'][$fieldindex])
102 && strlen($_POST['field_name'][$fieldindex]) > 0
104 $transformations->setMime(
107 $_POST['field_name'][$fieldindex],
109 $_POST['field_transformation'][$fieldindex],
110 $_POST['field_transformation_options'][$fieldindex],
111 $_POST['field_input_transformation'][$fieldindex],
112 $_POST['field_input_transformation_options'][$fieldindex]
118 // Go back to the structure sub-page
119 $message = Message
::success(
120 __('Table %1$s has been altered successfully.')
122 $message->addParam($table);
125 Util
::getMessage($message, $sql_query, 'success')
129 $error_message_html = Util
::mysqlDie(
136 $response->addHTML($error_message_html);
137 $response->setRequestStatus(false);
140 } // end do alter table
143 * Displays the form used to define the new field
145 if ($abort === false) {
147 * Gets tables information
149 include_once ROOT_PATH
. 'libraries/tbl_common.inc.php';
151 $active_page = 'tbl_structure.php';
155 $action = 'tbl_addfield.php';
156 include_once ROOT_PATH
. 'libraries/tbl_columns_definition_form.inc.php';