Translated using Weblate (Indonesian)
[phpmyadmin.git] / tbl_addfield.php
blob8bce9c240bd8f1732476027799bcae9c7ee1d8e2
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;
9 use PMA\libraries\Response;
11 /**
12 * Get some core libraries
14 require_once 'libraries/common.inc.php';
16 $response = Response::getInstance();
17 $header = $response->getHeader();
18 $scripts = $header->getScripts();
19 $scripts->addFile('tbl_structure.js');
21 // Check parameters
22 PMA\libraries\Util::checkParameters(array('db', 'table'));
25 /**
26 * Defines the url to return to in case of error in a sql statement
28 $err_url = 'tbl_sql.php' . URL::getCommon(
29 array(
30 'db' => $db, 'table' => $table
34 /**
35 * The form used to define the field to add has been submitted
37 $abort = false;
39 // check number of fields to be created
40 if (isset($_REQUEST['submit_num_fields'])) {
41 if (isset($_REQUEST['orig_after_field'])) {
42 $_REQUEST['after_field'] = $_REQUEST['orig_after_field'];
44 if (isset($_REQUEST['orig_field_where'])) {
45 $_REQUEST['field_where'] = $_REQUEST['orig_field_where'];
47 $num_fields = min(
48 intval($_REQUEST['orig_num_fields']) + intval($_REQUEST['added_fields']),
49 4096
51 $regenerate = true;
52 } elseif (isset($_REQUEST['num_fields']) && intval($_REQUEST['num_fields']) > 0) {
53 $num_fields = min(4096, intval($_REQUEST['num_fields']));
54 } else {
55 $num_fields = 1;
58 if (isset($_REQUEST['do_save_data'])) {
59 //avoid an incorrect calling of PMA_updateColumns() via
60 //tbl_structure.php below
61 unset($_REQUEST['do_save_data']);
63 include_once 'libraries/create_addfield.lib.php';
65 list($result, $sql_query) = PMA_tryColumnCreationQuery($db, $table, $err_url);
67 if ($result === true) {
68 // If comments were sent, enable relation stuff
69 include_once 'libraries/transformations.lib.php';
71 // Update comment table for mime types [MIME]
72 if (isset($_REQUEST['field_mimetype'])
73 && is_array($_REQUEST['field_mimetype'])
74 && $cfg['BrowseMIME']
75 ) {
76 foreach ($_REQUEST['field_mimetype'] as $fieldindex => $mimetype) {
77 if (isset($_REQUEST['field_name'][$fieldindex])
78 && strlen($_REQUEST['field_name'][$fieldindex]) > 0
79 ) {
80 PMA_setMIME(
81 $db, $table,
82 $_REQUEST['field_name'][$fieldindex],
83 $mimetype,
84 $_REQUEST['field_transformation'][$fieldindex],
85 $_REQUEST['field_transformation_options'][$fieldindex],
86 $_REQUEST['field_input_transformation'][$fieldindex],
87 $_REQUEST['field_input_transformation_options'][$fieldindex]
93 // Go back to the structure sub-page
94 $message = PMA\libraries\Message::success(
95 __('Table %1$s has been altered successfully.')
97 $message->addParam($table);
98 $response->addJSON(
99 'message',
100 PMA\libraries\Util::getMessage($message, $sql_query, 'success')
102 exit;
103 } else {
104 $error_message_html = PMA\libraries\Util::mysqlDie(
107 false,
108 $err_url,
109 false
111 $response->addHTML($error_message_html);
112 $response->setRequestStatus(false);
113 exit;
115 } // end do alter table
118 * Displays the form used to define the new field
120 if ($abort == false) {
122 * Gets tables information
124 include_once 'libraries/tbl_common.inc.php';
125 include_once 'libraries/tbl_info.inc.php';
127 $active_page = 'tbl_structure.php';
129 * Display the form
131 $action = 'tbl_addfield.php';
132 include_once 'libraries/tbl_columns_definition_form.inc.php';