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\Message
;
11 use PhpMyAdmin\Response
;
12 use PhpMyAdmin\Transformations
;
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');
27 Util
::checkParameters(array('db', 'table'));
29 $transformations = new Transformations();
32 * Defines the url to return to in case of error in a sql statement
34 $err_url = 'tbl_sql.php' . Url
::getCommon(
36 'db' => $db, 'table' => $table
41 * The form used to define the field to add has been submitted
45 // check number of fields to be created
46 if (isset($_REQUEST['submit_num_fields'])) {
47 if (isset($_REQUEST['orig_after_field'])) {
48 $_REQUEST['after_field'] = $_REQUEST['orig_after_field'];
50 if (isset($_REQUEST['orig_field_where'])) {
51 $_REQUEST['field_where'] = $_REQUEST['orig_field_where'];
54 intval($_REQUEST['orig_num_fields']) +
intval($_REQUEST['added_fields']),
58 } elseif (isset($_REQUEST['num_fields']) && intval($_REQUEST['num_fields']) > 0) {
59 $num_fields = min(4096, intval($_REQUEST['num_fields']));
64 if (isset($_REQUEST['do_save_data'])) {
65 //avoid an incorrect calling of PMA_updateColumns() via
66 //tbl_structure.php below
67 unset($_REQUEST['do_save_data']);
69 $createAddField = new CreateAddField($GLOBALS['dbi']);
71 list($result, $sql_query) = $createAddField->tryColumnCreationQuery($db, $table, $err_url);
73 if ($result === true) {
74 // Update comment table for mime types [MIME]
75 if (isset($_REQUEST['field_mimetype'])
76 && is_array($_REQUEST['field_mimetype'])
79 foreach ($_REQUEST['field_mimetype'] as $fieldindex => $mimetype) {
80 if (isset($_REQUEST['field_name'][$fieldindex])
81 && strlen($_REQUEST['field_name'][$fieldindex]) > 0
83 $transformations->setMime(
85 $_REQUEST['field_name'][$fieldindex],
87 $_REQUEST['field_transformation'][$fieldindex],
88 $_REQUEST['field_transformation_options'][$fieldindex],
89 $_REQUEST['field_input_transformation'][$fieldindex],
90 $_REQUEST['field_input_transformation_options'][$fieldindex]
96 // Go back to the structure sub-page
97 $message = Message
::success(
98 __('Table %1$s has been altered successfully.')
100 $message->addParam($table);
103 Util
::getMessage($message, $sql_query, 'success')
107 $error_message_html = Util
::mysqlDie(
114 $response->addHTML($error_message_html);
115 $response->setRequestStatus(false);
118 } // end do alter table
121 * Displays the form used to define the new field
123 if ($abort == false) {
125 * Gets tables information
127 include_once 'libraries/tbl_common.inc.php';
129 $active_page = 'tbl_structure.php';
133 $action = 'tbl_addfield.php';
134 include_once 'libraries/tbl_columns_definition_form.inc.php';