Translated using Weblate (Norwegian Bokmål)
[phpmyadmin.git] / tbl_create.php
blob7addb7655d9f0d13015c079a05e7995aa2ddc00e
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 */
9 use PhpMyAdmin\Core;
10 use PhpMyAdmin\CreateAddField;
11 use PhpMyAdmin\Response;
12 use PhpMyAdmin\Transformations;
13 use PhpMyAdmin\Url;
14 use PhpMyAdmin\Util;
16 /**
17 * Get some core libraries
19 require_once 'libraries/common.inc.php';
21 // Check parameters
22 Util::checkParameters(array('db'));
24 $transformations = new Transformations();
26 /* Check if database name is empty */
27 if (strlen($db) === 0) {
28 Util::mysqlDie(
29 __('The database name is empty!'), '', false, 'index.php'
33 /**
34 * Selects the database to work with
36 if (!$GLOBALS['dbi']->selectDb($db)) {
37 Util::mysqlDie(
38 sprintf(__('\'%s\' database does not exist.'), htmlspecialchars($db)),
39 '',
40 false,
41 'index.php'
45 if ($GLOBALS['dbi']->getColumns($db, $table)) {
46 // table exists already
47 Util::mysqlDie(
48 sprintf(__('Table %s already exists!'), htmlspecialchars($table)),
49 '',
50 false,
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';
63 /**
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);
73 // Executes the query
74 $result = $GLOBALS['dbi']->tryQuery($sql_query);
76 if ($result) {
77 // Update comment table for mime types [MIME]
78 if (isset($_REQUEST['field_mimetype'])
79 && is_array($_REQUEST['field_mimetype'])
80 && $cfg['BrowseMIME']
81 ) {
82 foreach ($_REQUEST['field_mimetype'] as $fieldindex => $mimetype) {
83 if (isset($_REQUEST['field_name'][$fieldindex])
84 && strlen($_REQUEST['field_name'][$fieldindex]) > 0
85 ) {
86 $transformations->setMime(
87 $db, $table,
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]
97 } else {
98 $response = Response::getInstance();
99 $response->setRequestStatus(false);
100 $response->addJSON('message', $GLOBALS['dbi']->getError());
102 exit;
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';