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 // for libraries/tbl_columns_definition_form.inc.php
54 // check number of fields to be created
55 $num_fields = CreateAddField
::getNumberOfFieldsFromRequest();
57 $action = 'tbl_create.php';
60 * The form used to define the structure of the table has been submitted
62 if (isset($_REQUEST['do_save_data'])) {
63 $sql_query = CreateAddField
::getTableCreationQuery($db, $table);
65 // If there is a request for SQL previewing.
66 if (isset($_REQUEST['preview_sql'])) {
67 Core
::previewSQL($sql_query);
70 $result = $GLOBALS['dbi']->tryQuery($sql_query);
73 // Update comment table for mime types [MIME]
74 if (isset($_REQUEST['field_mimetype'])
75 && is_array($_REQUEST['field_mimetype'])
78 foreach ($_REQUEST['field_mimetype'] as $fieldindex => $mimetype) {
79 if (isset($_REQUEST['field_name'][$fieldindex])
80 && strlen($_REQUEST['field_name'][$fieldindex]) > 0
82 Transformations
::setMIME(
84 $_REQUEST['field_name'][$fieldindex], $mimetype,
85 $_REQUEST['field_transformation'][$fieldindex],
86 $_REQUEST['field_transformation_options'][$fieldindex],
87 $_REQUEST['field_input_transformation'][$fieldindex],
88 $_REQUEST['field_input_transformation_options'][$fieldindex]
94 $response = Response
::getInstance();
95 $response->setRequestStatus(false);
96 $response->addJSON('message', $GLOBALS['dbi']->getError());
99 } // end do create table
101 //This global variable needs to be reset for the headerclass to function properly
102 $GLOBAL['table'] = '';
105 * Displays the form used to define the structure of the table
107 require 'libraries/tbl_columns_definition_form.inc.php';