Translated using Weblate (Estonian)
[phpmyadmin.git] / tbl_addfield.php
blob04ecb80dad1e5ee903b23c84b53dd12fa57d3701
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\Message;
12 use PhpMyAdmin\Response;
13 use PhpMyAdmin\Transformations;
14 use PhpMyAdmin\Url;
15 use PhpMyAdmin\Util;
17 /**
18 * Get some core libraries
20 require_once 'libraries/common.inc.php';
22 $response = Response::getInstance();
23 $header = $response->getHeader();
24 $scripts = $header->getScripts();
25 $scripts->addFile('tbl_structure.js');
27 // Check parameters
28 Util::checkParameters(['db', 'table']);
30 $transformations = new Transformations();
32 /**
33 * Defines the url to return to in case of error in a sql statement
35 $err_url = 'tbl_sql.php' . Url::getCommon(
37 'db' => $db, 'table' => $table
41 /**
42 * The form used to define the field to add has been submitted
44 $abort = false;
46 // check number of fields to be created
47 if (isset($_REQUEST['submit_num_fields'])) {
48 if (isset($_REQUEST['orig_after_field'])) {
49 $_REQUEST['after_field'] = $_REQUEST['orig_after_field'];
51 if (isset($_REQUEST['orig_field_where'])) {
52 $_REQUEST['field_where'] = $_REQUEST['orig_field_where'];
54 $num_fields = min(
55 intval($_REQUEST['orig_num_fields']) + intval($_REQUEST['added_fields']),
56 4096
58 $regenerate = true;
59 } elseif (isset($_REQUEST['num_fields']) && intval($_REQUEST['num_fields']) > 0) {
60 $num_fields = min(4096, intval($_REQUEST['num_fields']));
61 } else {
62 $num_fields = 1;
65 if (isset($_REQUEST['do_save_data'])) {
66 //avoid an incorrect calling of PMA_updateColumns() via
67 //tbl_structure.php below
68 unset($_REQUEST['do_save_data']);
70 $createAddField = new CreateAddField($GLOBALS['dbi']);
72 list($result, $sql_query) = $createAddField->tryColumnCreationQuery($db, $table, $err_url);
74 if ($result === true) {
75 // Update comment table for mime types [MIME]
76 if (isset($_REQUEST['field_mimetype'])
77 && is_array($_REQUEST['field_mimetype'])
78 && $cfg['BrowseMIME']
79 ) {
80 foreach ($_REQUEST['field_mimetype'] as $fieldindex => $mimetype) {
81 if (isset($_REQUEST['field_name'][$fieldindex])
82 && strlen($_REQUEST['field_name'][$fieldindex]) > 0
83 ) {
84 $transformations->setMime(
85 $db,
86 $table,
87 $_REQUEST['field_name'][$fieldindex],
88 $mimetype,
89 $_REQUEST['field_transformation'][$fieldindex],
90 $_REQUEST['field_transformation_options'][$fieldindex],
91 $_REQUEST['field_input_transformation'][$fieldindex],
92 $_REQUEST['field_input_transformation_options'][$fieldindex]
98 // Go back to the structure sub-page
99 $message = Message::success(
100 __('Table %1$s has been altered successfully.')
102 $message->addParam($table);
103 $response->addJSON(
104 'message',
105 Util::getMessage($message, $sql_query, 'success')
107 exit;
108 } else {
109 $error_message_html = Util::mysqlDie(
112 false,
113 $err_url,
114 false
116 $response->addHTML($error_message_html);
117 $response->setRequestStatus(false);
118 exit;
120 } // end do alter table
123 * Displays the form used to define the new field
125 if ($abort == false) {
127 * Gets tables information
129 include_once 'libraries/tbl_common.inc.php';
131 $active_page = 'tbl_structure.php';
133 * Display the form
135 $action = 'tbl_addfield.php';
136 include_once 'libraries/tbl_columns_definition_form.inc.php';