2 /* vim: set expandtab sw=4 ts=4 sts=4: */
4 * Displays table create form and handles it
10 use PhpMyAdmin\Response
;
11 use PhpMyAdmin\Transformations
;
15 * Get some core libraries
17 require_once 'libraries/common.inc.php';
18 require_once 'libraries/create_addfield.lib.php';
21 PhpMyAdmin\Util
::checkParameters(array('db'));
23 /* Check if database name is empty */
24 if (strlen($db) === 0) {
25 PhpMyAdmin\Util
::mysqlDie(
26 __('The database name is empty!'), '', false, 'index.php'
31 * Selects the database to work with
33 if (!$GLOBALS['dbi']->selectDb($db)) {
34 PhpMyAdmin\Util
::mysqlDie(
35 sprintf(__('\'%s\' database does not exist.'), htmlspecialchars($db)),
42 if ($GLOBALS['dbi']->getColumns($db, $table)) {
43 // table exists already
44 PhpMyAdmin\Util
::mysqlDie(
45 sprintf(__('Table %s already exists!'), htmlspecialchars($table)),
48 'db_structure.php' . Url
::getCommon(array('db' => $db))
52 // for libraries/tbl_columns_definition_form.inc.php
53 // check number of fields to be created
54 $num_fields = PMA_getNumberOfFieldsFromRequest();
56 $action = 'tbl_create.php';
59 * The form used to define the structure of the table has been submitted
61 if (isset($_REQUEST['do_save_data'])) {
62 $sql_query = PMA_getTableCreationQuery($db, $table);
64 // If there is a request for SQL previewing.
65 if (isset($_REQUEST['preview_sql'])) {
66 Core
::previewSQL($sql_query);
69 $result = $GLOBALS['dbi']->tryQuery($sql_query);
72 // Update comment table for mime types [MIME]
73 if (isset($_REQUEST['field_mimetype'])
74 && is_array($_REQUEST['field_mimetype'])
77 foreach ($_REQUEST['field_mimetype'] as $fieldindex => $mimetype) {
78 if (isset($_REQUEST['field_name'][$fieldindex])
79 && strlen($_REQUEST['field_name'][$fieldindex]) > 0
81 Transformations
::setMIME(
83 $_REQUEST['field_name'][$fieldindex], $mimetype,
84 $_REQUEST['field_transformation'][$fieldindex],
85 $_REQUEST['field_transformation_options'][$fieldindex],
86 $_REQUEST['field_input_transformation'][$fieldindex],
87 $_REQUEST['field_input_transformation_options'][$fieldindex]
93 $response = Response
::getInstance();
94 $response->setRequestStatus(false);
95 $response->addJSON('message', $GLOBALS['dbi']->getError());
98 } // end do create table
100 //This global variable needs to be reset for the headerclass to function properly
101 $GLOBAL['table'] = '';
104 * Displays the form used to define the structure of the table
106 require 'libraries/tbl_columns_definition_form.inc.php';