2 /* vim: set expandtab sw=4 ts=4 sts=4: */
4 * Displays table create form and handles it
8 declare(strict_types
=1);
11 use PhpMyAdmin\CreateAddField
;
12 use PhpMyAdmin\Response
;
13 use PhpMyAdmin\Transformations
;
18 * Get some core libraries
20 require_once 'libraries/common.inc.php';
23 Util
::checkParameters(['db']);
25 $transformations = new Transformations();
27 /* Check if database name is empty */
28 if (strlen($db) === 0) {
30 __('The database name is empty!'),
38 * Selects the database to work with
40 if (!$GLOBALS['dbi']->selectDb($db)) {
42 sprintf(__('\'%s\' database does not exist.'), htmlspecialchars($db)),
49 if ($GLOBALS['dbi']->getColumns($db, $table)) {
50 // table exists already
52 sprintf(__('Table %s already exists!'), htmlspecialchars($table)),
55 'db_structure.php' . Url
::getCommon(['db' => $db])
59 $createAddField = new CreateAddField($GLOBALS['dbi']);
61 // for libraries/tbl_columns_definition_form.inc.php
62 // check number of fields to be created
63 $num_fields = $createAddField->getNumberOfFieldsFromRequest();
65 $action = 'tbl_create.php';
68 * The form used to define the structure of the table has been submitted
70 if (isset($_REQUEST['do_save_data'])) {
71 $sql_query = $createAddField->getTableCreationQuery($db, $table);
73 // If there is a request for SQL previewing.
74 if (isset($_REQUEST['preview_sql'])) {
75 Core
::previewSQL($sql_query);
78 $result = $GLOBALS['dbi']->tryQuery($sql_query);
81 // Update comment table for mime types [MIME]
82 if (isset($_REQUEST['field_mimetype'])
83 && is_array($_REQUEST['field_mimetype'])
86 foreach ($_REQUEST['field_mimetype'] as $fieldindex => $mimetype) {
87 if (isset($_REQUEST['field_name'][$fieldindex])
88 && strlen($_REQUEST['field_name'][$fieldindex]) > 0
90 $transformations->setMime(
93 $_REQUEST['field_name'][$fieldindex],
95 $_REQUEST['field_transformation'][$fieldindex],
96 $_REQUEST['field_transformation_options'][$fieldindex],
97 $_REQUEST['field_input_transformation'][$fieldindex],
98 $_REQUEST['field_input_transformation_options'][$fieldindex]
104 $response = Response
::getInstance();
105 $response->setRequestStatus(false);
106 $response->addJSON('message', $GLOBALS['dbi']->getError());
109 } // end do create table
111 //This global variable needs to be reset for the headerclass to function properly
112 $GLOBAL['table'] = '';
115 * Displays the form used to define the structure of the table
117 require 'libraries/tbl_columns_definition_form.inc.php';