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\CreateAddField
;
11 use PhpMyAdmin\DatabaseInterface
;
12 use PhpMyAdmin\Di\Container
;
13 use PhpMyAdmin\Message
;
14 use PhpMyAdmin\Response
;
15 use PhpMyAdmin\Transformations
;
19 if (! defined('ROOT_PATH')) {
20 define('ROOT_PATH', __DIR__
. DIRECTORY_SEPARATOR
);
24 * Get some core libraries
26 require_once ROOT_PATH
. 'libraries/common.inc.php';
28 $container = Container
::getDefaultContainer();
29 $container->set(Response
::class, Response
::getInstance());
31 /** @var Response $response */
32 $response = $container->get(Response
::class);
34 /** @var DatabaseInterface $dbi */
35 $dbi = $container->get(DatabaseInterface
::class);
37 $header = $response->getHeader();
38 $scripts = $header->getScripts();
39 $scripts->addFile('tbl_structure.js');
42 Util
::checkParameters(['db', 'table']);
44 $transformations = new Transformations();
47 * Defines the url to return to in case of error in a sql statement
49 $err_url = 'tbl_sql.php' . Url
::getCommon(
57 * The form used to define the field to add has been submitted
61 // check number of fields to be created
62 if (isset($_POST['submit_num_fields'])) {
63 if (isset($_POST['orig_after_field'])) {
64 $_POST['after_field'] = $_POST['orig_after_field'];
66 if (isset($_POST['orig_field_where'])) {
67 $_POST['field_where'] = $_POST['orig_field_where'];
70 intval($_POST['orig_num_fields']) +
intval($_POST['added_fields']),
74 } elseif (isset($_POST['num_fields']) && intval($_POST['num_fields']) > 0) {
75 $num_fields = min(4096, intval($_POST['num_fields']));
80 if (isset($_POST['do_save_data'])) {
81 //avoid an incorrect calling of PMA_updateColumns() via
82 //tbl_structure.php below
83 unset($_POST['do_save_data']);
85 $createAddField = new CreateAddField($dbi);
87 list($result, $sql_query) = $createAddField->tryColumnCreationQuery($db, $table, $err_url);
89 if ($result === true) {
90 // Update comment table for mime types [MIME]
91 if (isset($_POST['field_mimetype'])
92 && is_array($_POST['field_mimetype'])
95 foreach ($_POST['field_mimetype'] as $fieldindex => $mimetype) {
96 if (isset($_POST['field_name'][$fieldindex])
97 && strlen($_POST['field_name'][$fieldindex]) > 0
99 $transformations->setMime(
102 $_POST['field_name'][$fieldindex],
104 $_POST['field_transformation'][$fieldindex],
105 $_POST['field_transformation_options'][$fieldindex],
106 $_POST['field_input_transformation'][$fieldindex],
107 $_POST['field_input_transformation_options'][$fieldindex]
113 // Go back to the structure sub-page
114 $message = Message
::success(
115 __('Table %1$s has been altered successfully.')
117 $message->addParam($table);
120 Util
::getMessage($message, $sql_query, 'success')
124 $error_message_html = Util
::mysqlDie(
131 $response->addHTML($error_message_html);
132 $response->setRequestStatus(false);
135 } // end do alter table
138 * Displays the form used to define the new field
140 if ($abort == false) {
142 * Gets tables information
144 include_once ROOT_PATH
. 'libraries/tbl_common.inc.php';
146 $active_page = 'tbl_structure.php';
150 $action = 'tbl_addfield.php';
151 include_once ROOT_PATH
. 'libraries/tbl_columns_definition_form.inc.php';