Merge remote-tracking branch 'origin/QA_4_6' into QA_4_6
[phpmyadmin.git] / tbl_addfield.php
blob90424f57f2147b376ee4390e1ae3070bc5b919ef
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\libraries\Response::getInstance();
15 $header = $response->getHeader();
16 $scripts = $header->getScripts();
17 $scripts->addFile('tbl_structure.js');
19 // Check parameters
20 PMA\libraries\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(
27 array(
28 'db' => $db, 'table' => $table
32 /**
33 * The form used to define the field to add has been submitted
35 $abort = false;
37 // check number of fields to be created
38 if (isset($_REQUEST['submit_num_fields'])) {
39 if (isset($_REQUEST['orig_after_field'])) {
40 $_REQUEST['after_field'] = $_REQUEST['orig_after_field'];
42 if (isset($_REQUEST['orig_field_where'])) {
43 $_REQUEST['field_where'] = $_REQUEST['orig_field_where'];
45 $num_fields = min(
46 intval($_REQUEST['orig_num_fields']) + intval($_REQUEST['added_fields']),
47 4096
49 $regenerate = true;
50 } elseif (isset($_REQUEST['num_fields']) && intval($_REQUEST['num_fields']) > 0) {
51 $num_fields = min(4096, intval($_REQUEST['num_fields']));
52 } else {
53 $num_fields = 1;
56 if (isset($_REQUEST['do_save_data'])) {
57 //avoid an incorrect calling of PMA_updateColumns() via
58 //tbl_structure.php below
59 unset($_REQUEST['do_save_data']);
61 include_once 'libraries/create_addfield.lib.php';
63 list($result, $sql_query) = PMA_tryColumnCreationQuery($db, $table, $err_url);
65 if ($result === true) {
66 // If comments were sent, enable relation stuff
67 include_once 'libraries/transformations.lib.php';
69 // Update comment table for mime types [MIME]
70 if (isset($_REQUEST['field_mimetype'])
71 && is_array($_REQUEST['field_mimetype'])
72 && $cfg['BrowseMIME']
73 ) {
74 foreach ($_REQUEST['field_mimetype'] as $fieldindex => $mimetype) {
75 if (isset($_REQUEST['field_name'][$fieldindex])
76 && mb_strlen($_REQUEST['field_name'][$fieldindex])
77 ) {
78 PMA_setMIME(
79 $db, $table,
80 $_REQUEST['field_name'][$fieldindex],
81 $mimetype,
82 $_REQUEST['field_transformation'][$fieldindex],
83 $_REQUEST['field_transformation_options'][$fieldindex],
84 $_REQUEST['field_input_transformation'][$fieldindex],
85 $_REQUEST['field_input_transformation_options'][$fieldindex]
91 // Go back to the structure sub-page
92 $message = PMA\libraries\Message::success(
93 __('Table %1$s has been altered successfully.')
95 $message->addParam($table);
96 $response->addJSON(
97 'message',
98 PMA\libraries\Util::getMessage($message, $sql_query, 'success')
100 exit;
101 } else {
102 $error_message_html = PMA\libraries\Util::mysqlDie(
105 false,
106 $err_url,
107 false
109 $response->addHTML($error_message_html);
110 $response->setRequestStatus(false);
111 exit;
113 } // end do alter table
116 * Displays the form used to define the new field
118 if ($abort == false) {
120 * Gets tables information
122 include_once 'libraries/tbl_common.inc.php';
123 include_once 'libraries/tbl_info.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';