Add ChangeLog entry for 1f817e8690757a
[phpmyadmin.git] / tbl_addfield.php
blobf231b6956463cf6a3fd14c338d494e4633f92a38
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 /**
30 * Defines the url to return to in case of error in a sql statement
32 $err_url = 'tbl_sql.php' . Url::getCommon(
33 array(
34 'db' => $db, 'table' => $table
38 /**
39 * The form used to define the field to add has been submitted
41 $abort = false;
43 // check number of fields to be created
44 if (isset($_POST['submit_num_fields'])) {
45 if (isset($_POST['orig_after_field'])) {
46 $_POST['after_field'] = $_POST['orig_after_field'];
48 if (isset($_POST['orig_field_where'])) {
49 $_POST['field_where'] = $_POST['orig_field_where'];
51 $num_fields = min(
52 intval($_POST['orig_num_fields']) + intval($_POST['added_fields']),
53 4096
55 $regenerate = true;
56 } elseif (isset($_POST['num_fields']) && intval($_POST['num_fields']) > 0) {
57 $num_fields = min(4096, intval($_POST['num_fields']));
58 } else {
59 $num_fields = 1;
62 if (isset($_POST['do_save_data'])) {
63 //avoid an incorrect calling of PMA_updateColumns() via
64 //tbl_structure.php below
65 unset($_POST['do_save_data']);
67 $createAddField = new CreateAddField($GLOBALS['dbi']);
69 list($result, $sql_query) = $createAddField->tryColumnCreationQuery($db, $table, $err_url);
71 if ($result === true) {
72 // Update comment table for mime types [MIME]
73 if (isset($_POST['field_mimetype'])
74 && is_array($_POST['field_mimetype'])
75 && $cfg['BrowseMIME']
76 ) {
77 foreach ($_POST['field_mimetype'] as $fieldindex => $mimetype) {
78 if (isset($_POST['field_name'][$fieldindex])
79 && strlen($_POST['field_name'][$fieldindex]) > 0
80 ) {
81 Transformations::setMIME(
82 $db, $table,
83 $_POST['field_name'][$fieldindex],
84 $mimetype,
85 $_POST['field_transformation'][$fieldindex],
86 $_POST['field_transformation_options'][$fieldindex],
87 $_POST['field_input_transformation'][$fieldindex],
88 $_POST['field_input_transformation_options'][$fieldindex]
94 // Go back to the structure sub-page
95 $message = Message::success(
96 __('Table %1$s has been altered successfully.')
98 $message->addParam($table);
99 $response->addJSON(
100 'message',
101 Util::getMessage($message, $sql_query, 'success')
103 exit;
104 } else {
105 $error_message_html = Util::mysqlDie(
108 false,
109 $err_url,
110 false
112 $response->addHTML($error_message_html);
113 $response->setRequestStatus(false);
114 exit;
116 } // end do alter table
119 * Displays the form used to define the new field
121 if ($abort == false) {
123 * Gets tables information
125 include_once 'libraries/tbl_common.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';