Translated using Weblate (Ukrainian)
[phpmyadmin.git] / tbl_addfield.php
blob159090a0e94dde77e5536c7cbbe580f013b7da9e
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 */
9 use PhpMyAdmin\CreateAddField;
10 use PhpMyAdmin\Response;
11 use PhpMyAdmin\Transformations;
12 use PhpMyAdmin\Url;
14 /**
15 * Get some core libraries
17 require_once 'libraries/common.inc.php';
19 $response = Response::getInstance();
20 $header = $response->getHeader();
21 $scripts = $header->getScripts();
22 $scripts->addFile('tbl_structure.js');
24 // Check parameters
25 PhpMyAdmin\Util::checkParameters(array('db', 'table'));
28 /**
29 * Defines the url to return to in case of error in a sql statement
31 $err_url = 'tbl_sql.php' . Url::getCommon(
32 array(
33 'db' => $db, 'table' => $table
37 /**
38 * The form used to define the field to add has been submitted
40 $abort = false;
42 // check number of fields to be created
43 if (isset($_REQUEST['submit_num_fields'])) {
44 if (isset($_REQUEST['orig_after_field'])) {
45 $_REQUEST['after_field'] = $_REQUEST['orig_after_field'];
47 if (isset($_REQUEST['orig_field_where'])) {
48 $_REQUEST['field_where'] = $_REQUEST['orig_field_where'];
50 $num_fields = min(
51 intval($_REQUEST['orig_num_fields']) + intval($_REQUEST['added_fields']),
52 4096
54 $regenerate = true;
55 } elseif (isset($_REQUEST['num_fields']) && intval($_REQUEST['num_fields']) > 0) {
56 $num_fields = min(4096, intval($_REQUEST['num_fields']));
57 } else {
58 $num_fields = 1;
61 if (isset($_REQUEST['do_save_data'])) {
62 //avoid an incorrect calling of PMA_updateColumns() via
63 //tbl_structure.php below
64 unset($_REQUEST['do_save_data']);
66 list($result, $sql_query) = CreateAddField::tryColumnCreationQuery($db, $table, $err_url);
68 if ($result === true) {
69 // Update comment table for mime types [MIME]
70 if (isset($_REQUEST['field_mimetype'])
71 && is_array($_REQUEST['field_mimetype'])
72 && $cfg['BrowseMIME']
73 ) {
74 foreach ($_REQUEST['field_mimetype'] as $fieldindex => $mimetype) {
75 if (isset($_REQUEST['field_name'][$fieldindex])
76 && strlen($_REQUEST['field_name'][$fieldindex]) > 0
77 ) {
78 Transformations::setMIME(
79 $db, $table,
80 $_REQUEST['field_name'][$fieldindex],
81 $mimetype,
82 $_REQUEST['field_transformation'][$fieldindex],
83 $_REQUEST['field_transformation_options'][$fieldindex],
84 $_REQUEST['field_input_transformation'][$fieldindex],
85 $_REQUEST['field_input_transformation_options'][$fieldindex]
91 // Go back to the structure sub-page
92 $message = PhpMyAdmin\Message::success(
93 __('Table %1$s has been altered successfully.')
95 $message->addParam($table);
96 $response->addJSON(
97 'message',
98 PhpMyAdmin\Util::getMessage($message, $sql_query, 'success')
100 exit;
101 } else {
102 $error_message_html = PhpMyAdmin\Util::mysqlDie(
105 false,
106 $err_url,
107 false
109 $response->addHTML($error_message_html);
110 $response->setRequestStatus(false);
111 exit;
113 } // end do alter table
116 * Displays the form used to define the new field
118 if ($abort == false) {
120 * Gets tables information
122 include_once 'libraries/tbl_common.inc.php';
124 $active_page = 'tbl_structure.php';
126 * Display the form
128 $action = 'tbl_addfield.php';
129 include_once 'libraries/tbl_columns_definition_form.inc.php';