tbl_create.php 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109
  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. $sql_query = $createAddField->getTableCreationQuery($db, $table);
  56. // If there is a request for SQL previewing.
  57. if (isset($_POST['preview_sql'])) {
  58. Core::previewSQL($sql_query);
  59. }
  60. // Executes the query
  61. $result = $GLOBALS['dbi']->tryQuery($sql_query);
  62. if ($result) {
  63. // Update comment table for mime types [MIME]
  64. if (isset($_POST['field_mimetype'])
  65. && is_array($_POST['field_mimetype'])
  66. && $cfg['BrowseMIME']
  67. ) {
  68. foreach ($_POST['field_mimetype'] as $fieldindex => $mimetype) {
  69. if (isset($_POST['field_name'][$fieldindex])
  70. && strlen($_POST['field_name'][$fieldindex]) > 0
  71. ) {
  72. Transformations::setMIME(
  73. $db, $table,
  74. $_POST['field_name'][$fieldindex], $mimetype,
  75. $_POST['field_transformation'][$fieldindex],
  76. $_POST['field_transformation_options'][$fieldindex],
  77. $_POST['field_input_transformation'][$fieldindex],
  78. $_POST['field_input_transformation_options'][$fieldindex]
  79. );
  80. }
  81. }
  82. }
  83. } else {
  84. $response = Response::getInstance();
  85. $response->setRequestStatus(false);
  86. $response->addJSON('message', $GLOBALS['dbi']->getError());
  87. }
  88. exit;
  89. } // end do create table
  90. //This global variable needs to be reset for the headerclass to function properly
  91. $GLOBAL['table'] = '';
  92. /**
  93. * Displays the form used to define the structure of the table
  94. */
  95. require 'libraries/tbl_columns_definition_form.inc.php';