Merge branch 'QA_4_7'
[phpmyadmin.git] / tbl_create.php
blob19920607723c07912900141313004ca8d36ec093
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\Response;
11 use PhpMyAdmin\Transformations;
12 use PhpMyAdmin\Url;
14 /**
15 * Get some core libraries
17 require_once 'libraries/common.inc.php';
18 require_once 'libraries/create_addfield.lib.php';
20 // Check parameters
21 PhpMyAdmin\Util::checkParameters(array('db'));
23 /* Check if database name is empty */
24 if (strlen($db) === 0) {
25 PhpMyAdmin\Util::mysqlDie(
26 __('The database name is empty!'), '', false, 'index.php'
30 /**
31 * Selects the database to work with
33 if (!$GLOBALS['dbi']->selectDb($db)) {
34 PhpMyAdmin\Util::mysqlDie(
35 sprintf(__('\'%s\' database does not exist.'), htmlspecialchars($db)),
36 '',
37 false,
38 'index.php'
42 if ($GLOBALS['dbi']->getColumns($db, $table)) {
43 // table exists already
44 PhpMyAdmin\Util::mysqlDie(
45 sprintf(__('Table %s already exists!'), htmlspecialchars($table)),
46 '',
47 false,
48 'db_structure.php' . Url::getCommon(array('db' => $db))
52 // for libraries/tbl_columns_definition_form.inc.php
53 // check number of fields to be created
54 $num_fields = PMA_getNumberOfFieldsFromRequest();
56 $action = 'tbl_create.php';
58 /**
59 * The form used to define the structure of the table has been submitted
61 if (isset($_REQUEST['do_save_data'])) {
62 $sql_query = PMA_getTableCreationQuery($db, $table);
64 // If there is a request for SQL previewing.
65 if (isset($_REQUEST['preview_sql'])) {
66 Core::previewSQL($sql_query);
68 // Executes the query
69 $result = $GLOBALS['dbi']->tryQuery($sql_query);
71 if ($result) {
72 // Update comment table for mime types [MIME]
73 if (isset($_REQUEST['field_mimetype'])
74 && is_array($_REQUEST['field_mimetype'])
75 && $cfg['BrowseMIME']
76 ) {
77 foreach ($_REQUEST['field_mimetype'] as $fieldindex => $mimetype) {
78 if (isset($_REQUEST['field_name'][$fieldindex])
79 && strlen($_REQUEST['field_name'][$fieldindex]) > 0
80 ) {
81 Transformations::setMIME(
82 $db, $table,
83 $_REQUEST['field_name'][$fieldindex], $mimetype,
84 $_REQUEST['field_transformation'][$fieldindex],
85 $_REQUEST['field_transformation_options'][$fieldindex],
86 $_REQUEST['field_input_transformation'][$fieldindex],
87 $_REQUEST['field_input_transformation_options'][$fieldindex]
92 } else {
93 $response = Response::getInstance();
94 $response->setRequestStatus(false);
95 $response->addJSON('message', $GLOBALS['dbi']->getError());
97 exit;
98 } // end do create table
100 //This global variable needs to be reset for the headerclass to function properly
101 $GLOBAL['table'] = '';
104 * Displays the form used to define the structure of the table
106 require 'libraries/tbl_columns_definition_form.inc.php';