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 $transformations = new Transformations();
26 /* Check if database name is empty */
27 if (strlen($db) === 0) {
29 __('The database name is empty!'), '', false, 'index.php'
34 * Selects the database to work with
36 if (!$GLOBALS['dbi']->selectDb($db)) {
38 sprintf(__('\'%s\' database does not exist.'), htmlspecialchars($db)),
45 if ($GLOBALS['dbi']->getColumns($db, $table)) {
46 // table exists already
48 sprintf(__('Table %s already exists!'), htmlspecialchars($table)),
51 'db_structure.php' . Url
::getCommon(array('db' => $db))
55 $createAddField = new CreateAddField($GLOBALS['dbi']);
57 // for libraries/tbl_columns_definition_form.inc.php
58 // check number of fields to be created
59 $num_fields = $createAddField->getNumberOfFieldsFromRequest();
61 $action = 'tbl_create.php';
64 * The form used to define the structure of the table has been submitted
66 if (isset($_REQUEST['do_save_data'])) {
67 $sql_query = $createAddField->getTableCreationQuery($db, $table);
69 // If there is a request for SQL previewing.
70 if (isset($_REQUEST['preview_sql'])) {
71 Core
::previewSQL($sql_query);
74 $result = $GLOBALS['dbi']->tryQuery($sql_query);
77 // Update comment table for mime types [MIME]
78 if (isset($_REQUEST['field_mimetype'])
79 && is_array($_REQUEST['field_mimetype'])
82 foreach ($_REQUEST['field_mimetype'] as $fieldindex => $mimetype) {
83 if (isset($_REQUEST['field_name'][$fieldindex])
84 && strlen($_REQUEST['field_name'][$fieldindex]) > 0
86 $transformations->setMime(
88 $_REQUEST['field_name'][$fieldindex], $mimetype,
89 $_REQUEST['field_transformation'][$fieldindex],
90 $_REQUEST['field_transformation_options'][$fieldindex],
91 $_REQUEST['field_input_transformation'][$fieldindex],
92 $_REQUEST['field_input_transformation_options'][$fieldindex]
98 $response = Response
::getInstance();
99 $response->setRequestStatus(false);
100 $response->addJSON('message', $GLOBALS['dbi']->getError());
103 } // end do create table
105 //This global variable needs to be reset for the headerclass to function properly
106 $GLOBAL['table'] = '';
109 * Displays the form used to define the structure of the table
111 require 'libraries/tbl_columns_definition_form.inc.php';