Translated using Weblate (Lithuanian)
[phpmyadmin.git] / tbl_create.php
blobbceb3752256a7450cf594357ab263402e2bb1611
1 <?php
2 /* vim: set expandtab sw=4 ts=4 sts=4: */
3 /**
4 * Displays table create form and handles it
6 * @package PhpMyAdmin
7 */
8 declare(strict_types=1);
10 use PhpMyAdmin\Config;
11 use PhpMyAdmin\Core;
12 use PhpMyAdmin\CreateAddField;
13 use PhpMyAdmin\DatabaseInterface;
14 use PhpMyAdmin\Response;
15 use PhpMyAdmin\Transformations;
16 use PhpMyAdmin\Url;
17 use PhpMyAdmin\Util;
19 if (! defined('ROOT_PATH')) {
20 define('ROOT_PATH', __DIR__ . DIRECTORY_SEPARATOR);
23 require_once ROOT_PATH . 'libraries/common.inc.php';
25 /** @var Response $response */
26 $response = $containerBuilder->get(Response::class);
28 /** @var DatabaseInterface $dbi */
29 $dbi = $containerBuilder->get(DatabaseInterface::class);
31 // Check parameters
32 Util::checkParameters(['db']);
34 /** @var Transformations $transformations */
35 $transformations = $containerBuilder->get('transformations');
37 /** @var string $db */
38 $db = $containerBuilder->getParameter('db');
40 /** @var string $table */
41 $table = $containerBuilder->getParameter('table');
43 /** @var Config $config */
44 $config = $containerBuilder->get('config');
45 $cfg = $config->settings;
47 /* Check if database name is empty */
48 if (strlen($db) === 0) {
49 Util::mysqlDie(
50 __('The database name is empty!'),
51 '',
52 false,
53 'index.php'
57 /**
58 * Selects the database to work with
60 if (! $dbi->selectDb($db)) {
61 Util::mysqlDie(
62 sprintf(__('\'%s\' database does not exist.'), htmlspecialchars($db)),
63 '',
64 false,
65 'index.php'
69 if ($dbi->getColumns($db, $table)) {
70 // table exists already
71 Util::mysqlDie(
72 sprintf(__('Table %s already exists!'), htmlspecialchars($table)),
73 '',
74 false,
75 'db_structure.php' . Url::getCommon(['db' => $db])
79 $createAddField = new CreateAddField($dbi);
81 // for libraries/tbl_columns_definition_form.inc.php
82 // check number of fields to be created
83 $num_fields = $createAddField->getNumberOfFieldsFromRequest();
85 $action = 'tbl_create.php';
87 /**
88 * The form used to define the structure of the table has been submitted
90 if (isset($_POST['do_save_data'])) {
91 // lower_case_table_names=1 `DB` becomes `db`
92 if ($dbi->getLowerCaseNames() === '1') {
93 $db = mb_strtolower(
94 $db
96 $table = mb_strtolower(
97 $table
100 $sql_query = $createAddField->getTableCreationQuery($db, $table);
102 // If there is a request for SQL previewing.
103 if (isset($_POST['preview_sql'])) {
104 Core::previewSQL($sql_query);
106 // Executes the query
107 $result = $dbi->tryQuery($sql_query);
109 if ($result) {
110 // Update comment table for mime types [MIME]
111 if (isset($_POST['field_mimetype'])
112 && is_array($_POST['field_mimetype'])
113 && $cfg['BrowseMIME']
115 foreach ($_POST['field_mimetype'] as $fieldindex => $mimetype) {
116 if (isset($_POST['field_name'][$fieldindex])
117 && strlen($_POST['field_name'][$fieldindex]) > 0
119 $transformations->setMime(
120 $db,
121 $table,
122 $_POST['field_name'][$fieldindex],
123 $mimetype,
124 $_POST['field_transformation'][$fieldindex],
125 $_POST['field_transformation_options'][$fieldindex],
126 $_POST['field_input_transformation'][$fieldindex],
127 $_POST['field_input_transformation_options'][$fieldindex]
132 } else {
133 $response->setRequestStatus(false);
134 $response->addJSON('message', $dbi->getError());
136 exit;
137 } // end do create table
139 //This global variable needs to be reset for the headerclass to function properly
140 $GLOBAL['table'] = '';
143 * Displays the form used to define the structure of the table
145 require ROOT_PATH . 'libraries/tbl_columns_definition_form.inc.php';