Refactored ConfigFile class so that it is no longer a singleton
[phpmyadmin.git] / tbl_create.php
blobc380ce82198d06a46f89057583bacad5439fe6a5
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 /**
10 * Get some core libraries
12 require_once 'libraries/common.inc.php';
13 require_once 'libraries/create_addfield.lib.php';
15 // Check parameters
16 PMA_Util::checkParameters(array('db'));
18 /* Check if database name is empty */
19 if (strlen($db) == 0) {
20 PMA_Util::mysqlDie(
21 __('The database name is empty!'), '', '', 'index.php'
25 /**
26 * Selects the database to work with
28 if (!$GLOBALS['dbi']->selectDb($db)) {
29 PMA_Util::mysqlDie(
30 sprintf(__('\'%s\' database does not exist.'), htmlspecialchars($db)),
31 '',
32 '',
33 'index.php'
37 if ($GLOBALS['dbi']->getColumns($db, $table)) {
38 // table exists already
39 PMA_Util::mysqlDie(
40 sprintf(__('Table %s already exists!'), htmlspecialchars($table)),
41 '',
42 '',
43 'db_structure.php?' . PMA_URL_getCommon($db)
47 // for libraries/tbl_columns_definition_form.inc.php
48 // check number of fields to be created
49 $num_fields = PMA_getNumberOfFieldsFromRequest();
51 $action = 'tbl_create.php';
53 /**
54 * The form used to define the structure of the table has been submitted
56 if (isset($_REQUEST['do_save_data'])) {
57 $sql_query = PMA_getTableCreationQuery($db, $table);
58 // Executes the query
59 $result = $GLOBALS['dbi']->tryQuery($sql_query);
61 if ($result) {
62 // If comments were sent, enable relation stuff
63 include_once 'libraries/transformations.lib.php';
64 // Update comment table for mime types [MIME]
65 if (isset($_REQUEST['field_mimetype'])
66 && is_array($_REQUEST['field_mimetype'])
67 && $cfg['BrowseMIME']
68 ) {
69 foreach ($_REQUEST['field_mimetype'] as $fieldindex => $mimetype) {
70 if (isset($_REQUEST['field_name'][$fieldindex])
71 && strlen($_REQUEST['field_name'][$fieldindex])
72 ) {
73 PMA_setMIME(
74 $db, $table, $_REQUEST['field_name'][$fieldindex], $mimetype,
75 $_REQUEST['field_transformation'][$fieldindex],
76 $_REQUEST['field_transformation_options'][$fieldindex]
81 } else {
82 $response = PMA_Response::getInstance();
83 $response->isSuccess(false);
84 $response->addJSON('message', $GLOBALS['dbi']->getError());
86 exit;
87 } // end do create table
89 /**
90 * Displays the form used to define the structure of the table
92 require 'libraries/tbl_columns_definition_form.inc.php';