tbl_create.php 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118
  1. <?php
  2. /* vim: set expandtab sw=4 ts=4 sts=4: */
  3. /**
  4. * Displays table create form and handles it
  5. *
  6. * @package PhpMyAdmin
  7. */
  8. use PhpMyAdmin\Core;
  9. use PhpMyAdmin\CreateAddField;
  10. use PhpMyAdmin\Response;
  11. use PhpMyAdmin\Transformations;
  12. use PhpMyAdmin\Url;
  13. use PhpMyAdmin\Util;
  14. /**
  15. * Get some core libraries
  16. */
  17. require_once 'libraries/common.inc.php';
  18. // Check parameters
  19. Util::checkParameters(array('db'));
  20. /* Check if database name is empty */
  21. if (strlen($db) === 0) {
  22. Util::mysqlDie(
  23. __('The database name is empty!'), '', false, 'index.php'
  24. );
  25. }
  26. /**
  27. * Selects the database to work with
  28. */
  29. if (!$GLOBALS['dbi']->selectDb($db)) {
  30. Util::mysqlDie(
  31. sprintf(__('\'%s\' database does not exist.'), htmlspecialchars($db)),
  32. '',
  33. false,
  34. 'index.php'
  35. );
  36. }
  37. if ($GLOBALS['dbi']->getColumns($db, $table)) {
  38. // table exists already
  39. Util::mysqlDie(
  40. sprintf(__('Table %s already exists!'), htmlspecialchars($table)),
  41. '',
  42. false,
  43. 'db_structure.php' . Url::getCommon(array('db' => $db))
  44. );
  45. }
  46. $createAddField = new CreateAddField($GLOBALS['dbi']);
  47. // for libraries/tbl_columns_definition_form.inc.php
  48. // check number of fields to be created
  49. $num_fields = $createAddField->getNumberOfFieldsFromRequest();
  50. $action = 'tbl_create.php';
  51. /**
  52. * The form used to define the structure of the table has been submitted
  53. */
  54. if (isset($_POST['do_save_data'])) {
  55. // lower_case_table_names=1 `DB` becomes `db`
  56. if ($GLOBALS['dbi']->getLowerCaseNames() === '1') {
  57. $db = mb_strtolower(
  58. $db
  59. );
  60. $table = mb_strtolower(
  61. $table
  62. );
  63. }
  64. $sql_query = $createAddField->getTableCreationQuery($db, $table);
  65. // If there is a request for SQL previewing.
  66. if (isset($_POST['preview_sql'])) {
  67. Core::previewSQL($sql_query);
  68. }
  69. // Executes the query
  70. $result = $GLOBALS['dbi']->tryQuery($sql_query);
  71. if ($result) {
  72. // Update comment table for mime types [MIME]
  73. if (isset($_POST['field_mimetype'])
  74. && is_array($_POST['field_mimetype'])
  75. && $cfg['BrowseMIME']
  76. ) {
  77. foreach ($_POST['field_mimetype'] as $fieldindex => $mimetype) {
  78. if (isset($_POST['field_name'][$fieldindex])
  79. && strlen($_POST['field_name'][$fieldindex]) > 0
  80. ) {
  81. Transformations::setMIME(
  82. $db, $table,
  83. $_POST['field_name'][$fieldindex], $mimetype,
  84. $_POST['field_transformation'][$fieldindex],
  85. $_POST['field_transformation_options'][$fieldindex],
  86. $_POST['field_input_transformation'][$fieldindex],
  87. $_POST['field_input_transformation_options'][$fieldindex]
  88. );
  89. }
  90. }
  91. }
  92. } else {
  93. $response = Response::getInstance();
  94. $response->setRequestStatus(false);
  95. $response->addJSON('message', $GLOBALS['dbi']->getError());
  96. }
  97. exit;
  98. } // end do create table
  99. //This global variable needs to be reset for the headerclass to function properly
  100. $GLOBAL['table'] = '';
  101. /**
  102. * Displays the form used to define the structure of the table
  103. */
  104. require 'libraries/tbl_columns_definition_form.inc.php';