tbl_create.php 2.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697
  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. /**
  9. * Get some core libraries
  10. */
  11. require_once 'libraries/common.inc.php';
  12. require_once 'libraries/create_addfield.lib.php';
  13. // Check parameters
  14. PMA_Util::checkParameters(array('db'));
  15. /* Check if database name is empty */
  16. if (strlen($db) == 0) {
  17. PMA_Util::mysqlDie(
  18. __('The database name is empty!'), '', '', 'index.php'
  19. );
  20. }
  21. /**
  22. * Selects the database to work with
  23. */
  24. if (!$GLOBALS['dbi']->selectDb($db)) {
  25. PMA_Util::mysqlDie(
  26. sprintf(__('\'%s\' database does not exist.'), htmlspecialchars($db)),
  27. '',
  28. '',
  29. 'index.php'
  30. );
  31. }
  32. if ($GLOBALS['dbi']->getColumns($db, $table)) {
  33. // table exists already
  34. PMA_Util::mysqlDie(
  35. sprintf(__('Table %s already exists!'), htmlspecialchars($table)),
  36. '',
  37. '',
  38. 'db_structure.php?' . PMA_URL_getCommon($db)
  39. );
  40. }
  41. // for libraries/tbl_columns_definition_form.inc.php
  42. // check number of fields to be created
  43. $num_fields = PMA_getNumberOfFieldsFromRequest();
  44. $action = 'tbl_create.php';
  45. /**
  46. * The form used to define the structure of the table has been submitted
  47. */
  48. if (isset($_REQUEST['do_save_data'])) {
  49. $sql_query = PMA_getTableCreationQuery($db, $table);
  50. // Executes the query
  51. $result = $GLOBALS['dbi']->tryQuery($sql_query);
  52. if ($result) {
  53. // If comments were sent, enable relation stuff
  54. include_once 'libraries/transformations.lib.php';
  55. // Update comment table for mime types [MIME]
  56. if (isset($_REQUEST['field_mimetype'])
  57. && is_array($_REQUEST['field_mimetype'])
  58. && $cfg['BrowseMIME']
  59. ) {
  60. foreach ($_REQUEST['field_mimetype'] as $fieldindex => $mimetype) {
  61. if (isset($_REQUEST['field_name'][$fieldindex])
  62. && strlen($_REQUEST['field_name'][$fieldindex])
  63. ) {
  64. PMA_setMIME(
  65. $db, $table, $_REQUEST['field_name'][$fieldindex], $mimetype,
  66. $_REQUEST['field_transformation'][$fieldindex],
  67. $_REQUEST['field_transformation_options'][$fieldindex]
  68. );
  69. }
  70. }
  71. }
  72. } else {
  73. $response = PMA_Response::getInstance();
  74. $response->isSuccess(false);
  75. $response->addJSON('message', $GLOBALS['dbi']->getError());
  76. }
  77. exit;
  78. } // end do create table
  79. //This global variable needs to be reset for the headerclass to function properly
  80. $GLOBAL['table'] = '';
  81. /**
  82. * Displays the form used to define the structure of the table
  83. */
  84. require 'libraries/tbl_columns_definition_form.inc.php';
  85. ?>