Translated using Weblate (Ukrainian)
[phpmyadmin.git] / tbl_create.php
blob89264ac2653555733d12e6660b3000f719c6abe4
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\Core;
11 use PhpMyAdmin\CreateAddField;
12 use PhpMyAdmin\Response;
13 use PhpMyAdmin\Transformations;
14 use PhpMyAdmin\Url;
15 use PhpMyAdmin\Util;
17 /**
18 * Get some core libraries
20 require_once 'libraries/common.inc.php';
22 // Check parameters
23 Util::checkParameters(['db']);
25 $transformations = new Transformations();
27 /* Check if database name is empty */
28 if (strlen($db) === 0) {
29 Util::mysqlDie(
30 __('The database name is empty!'),
31 '',
32 false,
33 'index.php'
37 /**
38 * Selects the database to work with
40 if (!$GLOBALS['dbi']->selectDb($db)) {
41 Util::mysqlDie(
42 sprintf(__('\'%s\' database does not exist.'), htmlspecialchars($db)),
43 '',
44 false,
45 'index.php'
49 if ($GLOBALS['dbi']->getColumns($db, $table)) {
50 // table exists already
51 Util::mysqlDie(
52 sprintf(__('Table %s already exists!'), htmlspecialchars($table)),
53 '',
54 false,
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';
67 /**
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);
77 // Executes the query
78 $result = $GLOBALS['dbi']->tryQuery($sql_query);
80 if ($result) {
81 // Update comment table for mime types [MIME]
82 if (isset($_REQUEST['field_mimetype'])
83 && is_array($_REQUEST['field_mimetype'])
84 && $cfg['BrowseMIME']
85 ) {
86 foreach ($_REQUEST['field_mimetype'] as $fieldindex => $mimetype) {
87 if (isset($_REQUEST['field_name'][$fieldindex])
88 && strlen($_REQUEST['field_name'][$fieldindex]) > 0
89 ) {
90 $transformations->setMime(
91 $db,
92 $table,
93 $_REQUEST['field_name'][$fieldindex],
94 $mimetype,
95 $_REQUEST['field_transformation'][$fieldindex],
96 $_REQUEST['field_transformation_options'][$fieldindex],
97 $_REQUEST['field_input_transformation'][$fieldindex],
98 $_REQUEST['field_input_transformation_options'][$fieldindex]
103 } else {
104 $response = Response::getInstance();
105 $response->setRequestStatus(false);
106 $response->addJSON('message', $GLOBALS['dbi']->getError());
108 exit;
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';