Translated using Weblate (Slovenian)
[phpmyadmin.git] / tbl_addfield.php
blobe7ea1deab4528945f55bd35f35acd04b25e4f00d
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\CreateAddField;
11 use PhpMyAdmin\DatabaseInterface;
12 use PhpMyAdmin\Di\Container;
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 /**
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');
41 // Check parameters
42 Util::checkParameters(['db', 'table']);
44 $transformations = new Transformations();
46 /**
47 * Defines the url to return to in case of error in a sql statement
49 $err_url = 'tbl_sql.php' . Url::getCommon(
51 'db' => $db,
52 'table' => $table,
56 /**
57 * The form used to define the field to add has been submitted
59 $abort = false;
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'];
69 $num_fields = min(
70 intval($_POST['orig_num_fields']) + intval($_POST['added_fields']),
71 4096
73 $regenerate = true;
74 } elseif (isset($_POST['num_fields']) && intval($_POST['num_fields']) > 0) {
75 $num_fields = min(4096, intval($_POST['num_fields']));
76 } else {
77 $num_fields = 1;
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'])
93 && $cfg['BrowseMIME']
94 ) {
95 foreach ($_POST['field_mimetype'] as $fieldindex => $mimetype) {
96 if (isset($_POST['field_name'][$fieldindex])
97 && strlen($_POST['field_name'][$fieldindex]) > 0
98 ) {
99 $transformations->setMime(
100 $db,
101 $table,
102 $_POST['field_name'][$fieldindex],
103 $mimetype,
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);
118 $response->addJSON(
119 'message',
120 Util::getMessage($message, $sql_query, 'success')
122 exit;
123 } else {
124 $error_message_html = Util::mysqlDie(
127 false,
128 $err_url,
129 false
131 $response->addHTML($error_message_html);
132 $response->setRequestStatus(false);
133 exit;
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';
148 * Display the form
150 $action = 'tbl_addfield.php';
151 include_once ROOT_PATH . 'libraries/tbl_columns_definition_form.inc.php';