Translated using Weblate (Portuguese (Brazil))
[phpmyadmin.git] / tbl_addfield.php
blob2a0590deaaa154cdceec9bbe0f909cb2674d40c8
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 /**
10 * Get some core libraries
12 require_once 'libraries/common.inc.php';
14 $response = PMA_Response::getInstance();
15 $header = $response->getHeader();
16 $scripts = $header->getScripts();
17 $scripts->addFile('tbl_structure.js');
19 // Check parameters
20 PMA_Util::checkParameters(array('db', 'table'));
23 /**
24 * Defines the url to return to in case of error in a sql statement
26 $err_url = 'tbl_sql.php?' . PMA_URL_getCommon($db, $table);
28 /**
29 * The form used to define the field to add has been submitted
31 $abort = false;
33 // check number of fields to be created
34 if (isset($_REQUEST['submit_num_fields'])) {
35 if (isset($_REQUEST['orig_after_field'])) {
36 $_REQUEST['after_field'] = $_REQUEST['orig_after_field'];
38 if (isset($_REQUEST['orig_field_where'])) {
39 $_REQUEST['field_where'] = $_REQUEST['orig_field_where'];
41 $num_fields = $_REQUEST['orig_num_fields'] + $_REQUEST['added_fields'];
42 $regenerate = true;
43 } elseif (isset($_REQUEST['num_fields']) && intval($_REQUEST['num_fields']) > 0) {
44 $num_fields = (int) $_REQUEST['num_fields'];
45 } else {
46 $num_fields = 1;
49 if (isset($_REQUEST['do_save_data'])) {
50 //avoid an incorrect calling of PMA_updateColumns() via
51 //tbl_structure.php below
52 unset($_REQUEST['do_save_data']);
54 include_once 'libraries/create_addfield.lib.php';
56 list($result, $sql_query) = PMA_tryColumnCreationQuery($db, $table, $err_url);
58 if ($result === true) {
59 // If comments were sent, enable relation stuff
60 include_once 'libraries/transformations.lib.php';
62 // Update comment table for mime types [MIME]
63 if (isset($_REQUEST['field_mimetype'])
64 && is_array($_REQUEST['field_mimetype'])
65 && $cfg['BrowseMIME']
66 ) {
67 foreach ($_REQUEST['field_mimetype'] as $fieldindex => $mimetype) {
68 if (isset($_REQUEST['field_name'][$fieldindex])
69 && strlen($_REQUEST['field_name'][$fieldindex])
70 ) {
71 PMA_setMIME(
72 $db, $table,
73 $_REQUEST['field_name'][$fieldindex],
74 $mimetype,
75 $_REQUEST['field_transformation'][$fieldindex],
76 $_REQUEST['field_transformation_options'][$fieldindex]
82 // Go back to the structure sub-page
83 $message = PMA_Message::success(
84 __('Table %1$s has been altered successfully')
86 $message->addParam($table);
87 $response->addJSON('message', $message);
88 $response->addJSON(
89 'sql_query',
90 PMA_Util::getMessage(null, $sql_query)
92 exit;
93 } else {
94 $error_message_html = PMA_Util::mysqlDie('', '', '', $err_url, false);
95 $response->addHTML($error_message_html);
96 exit;
98 } // end do alter table
101 * Displays the form used to define the new field
103 if ($abort == false) {
105 * Gets tables informations
107 include_once 'libraries/tbl_common.inc.php';
108 include_once 'libraries/tbl_info.inc.php';
110 $active_page = 'tbl_structure.php';
112 * Display the form
114 $action = 'tbl_addfield.php';
115 include_once 'libraries/tbl_columns_definition_form.inc.php';