Translated using Weblate (Finnish)
[phpmyadmin.git] / tbl_addfield.php
blob2ec8a2972bb027385782e2d5bc679ce7f9a58b25
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 use PMA\libraries\URL;
10 /**
11 * Get some core libraries
13 require_once 'libraries/common.inc.php';
15 $response = PMA\libraries\Response::getInstance();
16 $header = $response->getHeader();
17 $scripts = $header->getScripts();
18 $scripts->addFile('tbl_structure.js');
20 // Check parameters
21 PMA\libraries\Util::checkParameters(array('db', 'table'));
24 /**
25 * Defines the url to return to in case of error in a sql statement
27 $err_url = 'tbl_sql.php' . URL::getCommon(
28 array(
29 'db' => $db, 'table' => $table
33 /**
34 * The form used to define the field to add has been submitted
36 $abort = false;
38 // check number of fields to be created
39 if (isset($_REQUEST['submit_num_fields'])) {
40 if (isset($_REQUEST['orig_after_field'])) {
41 $_REQUEST['after_field'] = $_REQUEST['orig_after_field'];
43 if (isset($_REQUEST['orig_field_where'])) {
44 $_REQUEST['field_where'] = $_REQUEST['orig_field_where'];
46 $num_fields = $_REQUEST['orig_num_fields'] + $_REQUEST['added_fields'];
47 $regenerate = true;
48 } elseif (isset($_REQUEST['num_fields']) && intval($_REQUEST['num_fields']) > 0) {
49 $num_fields = (int) $_REQUEST['num_fields'];
50 } else {
51 $num_fields = 1;
54 if (isset($_REQUEST['do_save_data'])) {
55 //avoid an incorrect calling of PMA_updateColumns() via
56 //tbl_structure.php below
57 unset($_REQUEST['do_save_data']);
59 include_once 'libraries/create_addfield.lib.php';
61 list($result, $sql_query) = PMA_tryColumnCreationQuery($db, $table, $err_url);
63 if ($result === true) {
64 // If comments were sent, enable relation stuff
65 include_once 'libraries/transformations.lib.php';
67 // Update comment table for mime types [MIME]
68 if (isset($_REQUEST['field_mimetype'])
69 && is_array($_REQUEST['field_mimetype'])
70 && $cfg['BrowseMIME']
71 ) {
72 foreach ($_REQUEST['field_mimetype'] as $fieldindex => $mimetype) {
73 if (isset($_REQUEST['field_name'][$fieldindex])
74 && mb_strlen($_REQUEST['field_name'][$fieldindex])
75 ) {
76 PMA_setMIME(
77 $db, $table,
78 $_REQUEST['field_name'][$fieldindex],
79 $mimetype,
80 $_REQUEST['field_transformation'][$fieldindex],
81 $_REQUEST['field_transformation_options'][$fieldindex],
82 $_REQUEST['field_input_transformation'][$fieldindex],
83 $_REQUEST['field_input_transformation_options'][$fieldindex]
89 // Go back to the structure sub-page
90 $message = PMA\libraries\Message::success(
91 __('Table %1$s has been altered successfully.')
93 $message->addParam($table);
94 $response->addJSON(
95 'message',
96 PMA\libraries\Util::getMessage($message, $sql_query, 'success')
98 exit;
99 } else {
100 $error_message_html = PMA\libraries\Util::mysqlDie(
103 false,
104 $err_url,
105 false
107 $response->addHTML($error_message_html);
108 $response->setRequestStatus(false);
109 exit;
111 } // end do alter table
114 * Displays the form used to define the new field
116 if ($abort == false) {
118 * Gets tables information
120 include_once 'libraries/tbl_common.inc.php';
121 include_once 'libraries/tbl_info.inc.php';
123 $active_page = 'tbl_structure.php';
125 * Display the form
127 $action = 'tbl_addfield.php';
128 include_once 'libraries/tbl_columns_definition_form.inc.php';