Translated using Weblate (French)
[phpmyadmin.git] / tbl_addfield.php
blob7e6c6e0c3d338bf41224a2e6e3b58710dfca2a87
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\Message;
11 use PhpMyAdmin\Response;
12 use PhpMyAdmin\Transformations;
13 use PhpMyAdmin\Url;
14 use PhpMyAdmin\Util;
16 /**
17 * Get some core libraries
19 require_once 'libraries/common.inc.php';
21 $response = Response::getInstance();
22 $header = $response->getHeader();
23 $scripts = $header->getScripts();
24 $scripts->addFile('tbl_structure.js');
26 // Check parameters
27 Util::checkParameters(array('db', 'table'));
29 $transformations = new Transformations();
31 /**
32 * Defines the url to return to in case of error in a sql statement
34 $err_url = 'tbl_sql.php' . Url::getCommon(
35 array(
36 'db' => $db, 'table' => $table
40 /**
41 * The form used to define the field to add has been submitted
43 $abort = false;
45 // check number of fields to be created
46 if (isset($_REQUEST['submit_num_fields'])) {
47 if (isset($_REQUEST['orig_after_field'])) {
48 $_REQUEST['after_field'] = $_REQUEST['orig_after_field'];
50 if (isset($_REQUEST['orig_field_where'])) {
51 $_REQUEST['field_where'] = $_REQUEST['orig_field_where'];
53 $num_fields = min(
54 intval($_REQUEST['orig_num_fields']) + intval($_REQUEST['added_fields']),
55 4096
57 $regenerate = true;
58 } elseif (isset($_REQUEST['num_fields']) && intval($_REQUEST['num_fields']) > 0) {
59 $num_fields = min(4096, intval($_REQUEST['num_fields']));
60 } else {
61 $num_fields = 1;
64 if (isset($_REQUEST['do_save_data'])) {
65 //avoid an incorrect calling of PMA_updateColumns() via
66 //tbl_structure.php below
67 unset($_REQUEST['do_save_data']);
69 $createAddField = new CreateAddField($GLOBALS['dbi']);
71 list($result, $sql_query) = $createAddField->tryColumnCreationQuery($db, $table, $err_url);
73 if ($result === true) {
74 // Update comment table for mime types [MIME]
75 if (isset($_REQUEST['field_mimetype'])
76 && is_array($_REQUEST['field_mimetype'])
77 && $cfg['BrowseMIME']
78 ) {
79 foreach ($_REQUEST['field_mimetype'] as $fieldindex => $mimetype) {
80 if (isset($_REQUEST['field_name'][$fieldindex])
81 && strlen($_REQUEST['field_name'][$fieldindex]) > 0
82 ) {
83 $transformations->setMime(
84 $db, $table,
85 $_REQUEST['field_name'][$fieldindex],
86 $mimetype,
87 $_REQUEST['field_transformation'][$fieldindex],
88 $_REQUEST['field_transformation_options'][$fieldindex],
89 $_REQUEST['field_input_transformation'][$fieldindex],
90 $_REQUEST['field_input_transformation_options'][$fieldindex]
96 // Go back to the structure sub-page
97 $message = Message::success(
98 __('Table %1$s has been altered successfully.')
100 $message->addParam($table);
101 $response->addJSON(
102 'message',
103 Util::getMessage($message, $sql_query, 'success')
105 exit;
106 } else {
107 $error_message_html = Util::mysqlDie(
110 false,
111 $err_url,
112 false
114 $response->addHTML($error_message_html);
115 $response->setRequestStatus(false);
116 exit;
118 } // end do alter table
121 * Displays the form used to define the new field
123 if ($abort == false) {
125 * Gets tables information
127 include_once 'libraries/tbl_common.inc.php';
129 $active_page = 'tbl_structure.php';
131 * Display the form
133 $action = 'tbl_addfield.php';
134 include_once 'libraries/tbl_columns_definition_form.inc.php';