2 /* vim: set expandtab sw=4 ts=4 sts=4: */
4 * Displays table create form and handles it
10 use PhpMyAdmin\CreateAddField
;
11 use PhpMyAdmin\Response
;
12 use PhpMyAdmin\Transformations
;
17 * Get some core libraries
19 require_once 'libraries/common.inc.php';
22 Util
::checkParameters(array('db'));
24 /* Check if database name is empty */
25 if (strlen($db) === 0) {
27 __('The database name is empty!'), '', false, 'index.php'
32 * Selects the database to work with
34 if (!$GLOBALS['dbi']->selectDb($db)) {
36 sprintf(__('\'%s\' database does not exist.'), htmlspecialchars($db)),
43 if ($GLOBALS['dbi']->getColumns($db, $table)) {
44 // table exists already
46 sprintf(__('Table %s already exists!'), htmlspecialchars($table)),
49 'db_structure.php' . Url
::getCommon(array('db' => $db))
53 $createAddField = new CreateAddField($GLOBALS['dbi']);
55 // for libraries/tbl_columns_definition_form.inc.php
56 // check number of fields to be created
57 $num_fields = $createAddField->getNumberOfFieldsFromRequest();
59 $action = 'tbl_create.php';
62 * The form used to define the structure of the table has been submitted
64 if (isset($_POST['do_save_data'])) {
65 // lower_case_table_names=1 `DB` becomes `db`
66 if ($GLOBALS['dbi']->getLowerCaseNames() === '1') {
70 $table = mb_strtolower(
74 $sql_query = $createAddField->getTableCreationQuery($db, $table);
76 // If there is a request for SQL previewing.
77 if (isset($_POST['preview_sql'])) {
78 Core
::previewSQL($sql_query);
81 $result = $GLOBALS['dbi']->tryQuery($sql_query);
84 // Update comment table for mime types [MIME]
85 if (isset($_POST['field_mimetype'])
86 && is_array($_POST['field_mimetype'])
89 foreach ($_POST['field_mimetype'] as $fieldindex => $mimetype) {
90 if (isset($_POST['field_name'][$fieldindex])
91 && strlen($_POST['field_name'][$fieldindex]) > 0
93 Transformations
::setMIME(
95 $_POST['field_name'][$fieldindex], $mimetype,
96 $_POST['field_transformation'][$fieldindex],
97 $_POST['field_transformation_options'][$fieldindex],
98 $_POST['field_input_transformation'][$fieldindex],
99 $_POST['field_input_transformation_options'][$fieldindex]
105 $response = Response
::getInstance();
106 $response->setRequestStatus(false);
107 $response->addJSON('message', $GLOBALS['dbi']->getError());
110 } // end do create table
112 //This global variable needs to be reset for the headerclass to function properly
113 $GLOBAL['table'] = '';
116 * Displays the form used to define the structure of the table
118 require 'libraries/tbl_columns_definition_form.inc.php';