Translated using Weblate (Turkish)
[phpmyadmin.git] / tbl_addfield.php
blob448e5a7391ccc666d5793aee557fa271d0344a8b
1 <?php
2 /* vim: set expandtab sw=4 ts=4 sts=4: */
3 /**
4 * Displays add field form and handles it
6 * @package PhpMyAdmin
7 */
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;
16 use PhpMyAdmin\Url;
17 use PhpMyAdmin\Util;
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');
35 // Check parameters
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;
51 /**
52 * Defines the url to return to in case of error in a sql statement
54 $err_url = 'tbl_sql.php' . Url::getCommon(
56 'db' => $db,
57 'table' => $table,
61 /**
62 * The form used to define the field to add has been submitted
64 $abort = false;
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'];
74 $num_fields = min(
75 intval($_POST['orig_num_fields']) + intval($_POST['added_fields']),
76 4096
78 $regenerate = true;
79 } elseif (isset($_POST['num_fields']) && intval($_POST['num_fields']) > 0) {
80 $num_fields = min(4096, intval($_POST['num_fields']));
81 } else {
82 $num_fields = 1;
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'])
98 && $cfg['BrowseMIME']
99 ) {
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(
105 $db,
106 $table,
107 $_POST['field_name'][$fieldindex],
108 $mimetype,
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);
123 $response->addJSON(
124 'message',
125 Util::getMessage($message, $sql_query, 'success')
127 exit;
128 } else {
129 $error_message_html = Util::mysqlDie(
132 false,
133 $err_url,
134 false
136 $response->addHTML($error_message_html);
137 $response->setRequestStatus(false);
138 exit;
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';
153 * Display the form
155 $action = 'tbl_addfield.php';
156 include_once ROOT_PATH . 'libraries/tbl_columns_definition_form.inc.php';