2 /* vim: set expandtab sw=4 ts=4 sts=4: */
4 * Displays add field form and handles it
9 use PhpMyAdmin\CreateAddField
;
10 use PhpMyAdmin\Response
;
11 use PhpMyAdmin\Transformations
;
15 * Get some core libraries
17 require_once 'libraries/common.inc.php';
19 $response = Response
::getInstance();
20 $header = $response->getHeader();
21 $scripts = $header->getScripts();
22 $scripts->addFile('tbl_structure.js');
25 PhpMyAdmin\Util
::checkParameters(array('db', 'table'));
29 * Defines the url to return to in case of error in a sql statement
31 $err_url = 'tbl_sql.php' . Url
::getCommon(
33 'db' => $db, 'table' => $table
38 * The form used to define the field to add has been submitted
42 // check number of fields to be created
43 if (isset($_REQUEST['submit_num_fields'])) {
44 if (isset($_REQUEST['orig_after_field'])) {
45 $_REQUEST['after_field'] = $_REQUEST['orig_after_field'];
47 if (isset($_REQUEST['orig_field_where'])) {
48 $_REQUEST['field_where'] = $_REQUEST['orig_field_where'];
51 intval($_REQUEST['orig_num_fields']) +
intval($_REQUEST['added_fields']),
55 } elseif (isset($_REQUEST['num_fields']) && intval($_REQUEST['num_fields']) > 0) {
56 $num_fields = min(4096, intval($_REQUEST['num_fields']));
61 if (isset($_REQUEST['do_save_data'])) {
62 //avoid an incorrect calling of PMA_updateColumns() via
63 //tbl_structure.php below
64 unset($_REQUEST['do_save_data']);
66 list($result, $sql_query) = CreateAddField
::tryColumnCreationQuery($db, $table, $err_url);
68 if ($result === true) {
69 // Update comment table for mime types [MIME]
70 if (isset($_REQUEST['field_mimetype'])
71 && is_array($_REQUEST['field_mimetype'])
74 foreach ($_REQUEST['field_mimetype'] as $fieldindex => $mimetype) {
75 if (isset($_REQUEST['field_name'][$fieldindex])
76 && strlen($_REQUEST['field_name'][$fieldindex]) > 0
78 Transformations
::setMIME(
80 $_REQUEST['field_name'][$fieldindex],
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 = PhpMyAdmin\Message
::success(
93 __('Table %1$s has been altered successfully.')
95 $message->addParam($table);
98 PhpMyAdmin\Util
::getMessage($message, $sql_query, 'success')
102 $error_message_html = PhpMyAdmin\Util
::mysqlDie(
109 $response->addHTML($error_message_html);
110 $response->setRequestStatus(false);
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';
124 $active_page = 'tbl_structure.php';
128 $action = 'tbl_addfield.php';
129 include_once 'libraries/tbl_columns_definition_form.inc.php';