Translated using Weblate (German)
[phpmyadmin.git] / tbl_addfield.php
blob7827652629506c6580ea6dc22b66cff97db6d20a
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\Response;
10 use PhpMyAdmin\Transformations;
11 use PhpMyAdmin\Url;
13 /**
14 * Get some core libraries
16 require_once 'libraries/common.inc.php';
18 $response = Response::getInstance();
19 $header = $response->getHeader();
20 $scripts = $header->getScripts();
21 $scripts->addFile('tbl_structure.js');
23 // Check parameters
24 PhpMyAdmin\Util::checkParameters(array('db', 'table'));
27 /**
28 * Defines the url to return to in case of error in a sql statement
30 $err_url = 'tbl_sql.php' . Url::getCommon(
31 array(
32 'db' => $db, 'table' => $table
36 /**
37 * The form used to define the field to add has been submitted
39 $abort = false;
41 // check number of fields to be created
42 if (isset($_REQUEST['submit_num_fields'])) {
43 if (isset($_REQUEST['orig_after_field'])) {
44 $_REQUEST['after_field'] = $_REQUEST['orig_after_field'];
46 if (isset($_REQUEST['orig_field_where'])) {
47 $_REQUEST['field_where'] = $_REQUEST['orig_field_where'];
49 $num_fields = min(
50 intval($_REQUEST['orig_num_fields']) + intval($_REQUEST['added_fields']),
51 4096
53 $regenerate = true;
54 } elseif (isset($_REQUEST['num_fields']) && intval($_REQUEST['num_fields']) > 0) {
55 $num_fields = min(4096, intval($_REQUEST['num_fields']));
56 } else {
57 $num_fields = 1;
60 if (isset($_REQUEST['do_save_data'])) {
61 //avoid an incorrect calling of PMA_updateColumns() via
62 //tbl_structure.php below
63 unset($_REQUEST['do_save_data']);
65 include_once 'libraries/create_addfield.lib.php';
67 list($result, $sql_query) = PMA_tryColumnCreationQuery($db, $table, $err_url);
69 if ($result === true) {
70 // Update comment table for mime types [MIME]
71 if (isset($_REQUEST['field_mimetype'])
72 && is_array($_REQUEST['field_mimetype'])
73 && $cfg['BrowseMIME']
74 ) {
75 foreach ($_REQUEST['field_mimetype'] as $fieldindex => $mimetype) {
76 if (isset($_REQUEST['field_name'][$fieldindex])
77 && strlen($_REQUEST['field_name'][$fieldindex]) > 0
78 ) {
79 Transformations::setMIME(
80 $db, $table,
81 $_REQUEST['field_name'][$fieldindex],
82 $mimetype,
83 $_REQUEST['field_transformation'][$fieldindex],
84 $_REQUEST['field_transformation_options'][$fieldindex],
85 $_REQUEST['field_input_transformation'][$fieldindex],
86 $_REQUEST['field_input_transformation_options'][$fieldindex]
92 // Go back to the structure sub-page
93 $message = PhpMyAdmin\Message::success(
94 __('Table %1$s has been altered successfully.')
96 $message->addParam($table);
97 $response->addJSON(
98 'message',
99 PhpMyAdmin\Util::getMessage($message, $sql_query, 'success')
101 exit;
102 } else {
103 $error_message_html = PhpMyAdmin\Util::mysqlDie(
106 false,
107 $err_url,
108 false
110 $response->addHTML($error_message_html);
111 $response->setRequestStatus(false);
112 exit;
114 } // end do alter table
117 * Displays the form used to define the new field
119 if ($abort == false) {
121 * Gets tables information
123 include_once 'libraries/tbl_common.inc.php';
125 $active_page = 'tbl_structure.php';
127 * Display the form
129 $action = 'tbl_addfield.php';
130 include_once 'libraries/tbl_columns_definition_form.inc.php';