2016-10-22 14:57:10 +00:00
|
|
|
<?php
|
|
|
|
/* vim: set expandtab sw=4 ts=4 sts=4: */
|
|
|
|
/**
|
|
|
|
* Displays table create form and handles it
|
|
|
|
*
|
|
|
|
* @package PhpMyAdmin
|
|
|
|
*/
|
2018-04-14 09:18:00 +00:00
|
|
|
|
|
|
|
use PhpMyAdmin\Core;
|
|
|
|
use PhpMyAdmin\CreateAddField;
|
|
|
|
use PhpMyAdmin\Response;
|
|
|
|
use PhpMyAdmin\Transformations;
|
|
|
|
use PhpMyAdmin\Url;
|
|
|
|
use PhpMyAdmin\Util;
|
2016-10-22 14:57:10 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Get some core libraries
|
|
|
|
*/
|
|
|
|
require_once 'libraries/common.inc.php';
|
|
|
|
|
|
|
|
// Check parameters
|
2018-04-14 09:18:00 +00:00
|
|
|
Util::checkParameters(array('db'));
|
2016-10-22 14:57:10 +00:00
|
|
|
|
|
|
|
/* Check if database name is empty */
|
2017-04-20 10:55:30 +00:00
|
|
|
if (strlen($db) === 0) {
|
2018-04-14 09:18:00 +00:00
|
|
|
Util::mysqlDie(
|
2016-10-22 14:57:10 +00:00
|
|
|
__('The database name is empty!'), '', false, 'index.php'
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Selects the database to work with
|
|
|
|
*/
|
|
|
|
if (!$GLOBALS['dbi']->selectDb($db)) {
|
2018-04-14 09:18:00 +00:00
|
|
|
Util::mysqlDie(
|
2016-10-22 14:57:10 +00:00
|
|
|
sprintf(__('\'%s\' database does not exist.'), htmlspecialchars($db)),
|
|
|
|
'',
|
|
|
|
false,
|
|
|
|
'index.php'
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
if ($GLOBALS['dbi']->getColumns($db, $table)) {
|
|
|
|
// table exists already
|
2018-04-14 09:18:00 +00:00
|
|
|
Util::mysqlDie(
|
2016-10-22 14:57:10 +00:00
|
|
|
sprintf(__('Table %s already exists!'), htmlspecialchars($table)),
|
|
|
|
'',
|
|
|
|
false,
|
2018-04-14 09:18:00 +00:00
|
|
|
'db_structure.php' . Url::getCommon(array('db' => $db))
|
2016-10-22 14:57:10 +00:00
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2018-04-14 09:18:00 +00:00
|
|
|
$createAddField = new CreateAddField($GLOBALS['dbi']);
|
|
|
|
|
2016-10-22 14:57:10 +00:00
|
|
|
// for libraries/tbl_columns_definition_form.inc.php
|
|
|
|
// check number of fields to be created
|
2018-04-14 09:18:00 +00:00
|
|
|
$num_fields = $createAddField->getNumberOfFieldsFromRequest();
|
2016-10-22 14:57:10 +00:00
|
|
|
|
|
|
|
$action = 'tbl_create.php';
|
|
|
|
|
|
|
|
/**
|
|
|
|
* The form used to define the structure of the table has been submitted
|
|
|
|
*/
|
2018-12-16 14:31:03 +00:00
|
|
|
if (isset($_POST['do_save_data'])) {
|
2019-12-08 07:14:01 +00:00
|
|
|
// lower_case_table_names=1 `DB` becomes `db`
|
|
|
|
if ($GLOBALS['dbi']->getLowerCaseNames() === '1') {
|
|
|
|
$db = mb_strtolower(
|
|
|
|
$db
|
|
|
|
);
|
|
|
|
$table = mb_strtolower(
|
|
|
|
$table
|
|
|
|
);
|
|
|
|
}
|
2018-04-14 09:18:00 +00:00
|
|
|
$sql_query = $createAddField->getTableCreationQuery($db, $table);
|
2016-10-22 14:57:10 +00:00
|
|
|
|
|
|
|
// If there is a request for SQL previewing.
|
2018-12-16 14:31:03 +00:00
|
|
|
if (isset($_POST['preview_sql'])) {
|
2018-04-14 09:18:00 +00:00
|
|
|
Core::previewSQL($sql_query);
|
2016-10-22 14:57:10 +00:00
|
|
|
}
|
|
|
|
// Executes the query
|
|
|
|
$result = $GLOBALS['dbi']->tryQuery($sql_query);
|
|
|
|
|
|
|
|
if ($result) {
|
|
|
|
// Update comment table for mime types [MIME]
|
2018-12-16 14:31:03 +00:00
|
|
|
if (isset($_POST['field_mimetype'])
|
|
|
|
&& is_array($_POST['field_mimetype'])
|
2016-10-22 14:57:10 +00:00
|
|
|
&& $cfg['BrowseMIME']
|
|
|
|
) {
|
2018-12-16 14:31:03 +00:00
|
|
|
foreach ($_POST['field_mimetype'] as $fieldindex => $mimetype) {
|
|
|
|
if (isset($_POST['field_name'][$fieldindex])
|
|
|
|
&& strlen($_POST['field_name'][$fieldindex]) > 0
|
2016-10-22 14:57:10 +00:00
|
|
|
) {
|
2018-04-14 09:18:00 +00:00
|
|
|
Transformations::setMIME(
|
2016-10-22 14:57:10 +00:00
|
|
|
$db, $table,
|
2018-12-16 14:31:03 +00:00
|
|
|
$_POST['field_name'][$fieldindex], $mimetype,
|
|
|
|
$_POST['field_transformation'][$fieldindex],
|
|
|
|
$_POST['field_transformation_options'][$fieldindex],
|
|
|
|
$_POST['field_input_transformation'][$fieldindex],
|
|
|
|
$_POST['field_input_transformation_options'][$fieldindex]
|
2016-10-22 14:57:10 +00:00
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
} else {
|
2017-04-20 10:55:30 +00:00
|
|
|
$response = Response::getInstance();
|
2016-10-22 14:57:10 +00:00
|
|
|
$response->setRequestStatus(false);
|
|
|
|
$response->addJSON('message', $GLOBALS['dbi']->getError());
|
|
|
|
}
|
|
|
|
exit;
|
|
|
|
} // end do create table
|
|
|
|
|
|
|
|
//This global variable needs to be reset for the headerclass to function properly
|
|
|
|
$GLOBAL['table'] = '';
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Displays the form used to define the structure of the table
|
|
|
|
*/
|
|
|
|
require 'libraries/tbl_columns_definition_form.inc.php';
|