tbl_structure.php 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164
  1. <?php
  2. /* vim: set expandtab sw=4 ts=4 sts=4: */
  3. /**
  4. * Displays table structure infos like columns, indexes, size, rows
  5. * and allows manipulation of indexes and columns
  6. *
  7. * @package PhpMyAdmin
  8. */
  9. /**
  10. *
  11. */
  12. require_once 'libraries/common.inc.php';
  13. require_once 'libraries/mysql_charsets.inc.php';
  14. /**
  15. * Function implementations for this script
  16. */
  17. require_once 'libraries/structure.lib.php';
  18. require_once 'libraries/index.lib.php';
  19. require_once 'libraries/sql.lib.php';
  20. require_once 'libraries/bookmark.lib.php';
  21. $response = PMA_Response::getInstance();
  22. $header = $response->getHeader();
  23. $scripts = $header->getScripts();
  24. $scripts->addFile('tbl_structure.js');
  25. $scripts->addFile('indexes.js');
  26. /**
  27. * Handle column moving
  28. */
  29. if (isset($_REQUEST['move_columns'])
  30. && is_array($_REQUEST['move_columns'])
  31. && $response->isAjax()
  32. ) {
  33. PMA_moveColumns($db, $table);
  34. exit;
  35. }
  36. /**
  37. * A click on Change has been made for one column
  38. */
  39. if (isset($_REQUEST['change_column'])) {
  40. PMA_displayHtmlForColumnChange($db, $table, null, 'tbl_structure.php');
  41. exit;
  42. }
  43. /**
  44. * Modifications have been submitted -> updates the table
  45. */
  46. if (isset($_REQUEST['do_save_data'])) {
  47. $regenerate = PMA_updateColumns($db, $table);
  48. if ($regenerate) {
  49. // This happens when updating failed
  50. // @todo: do something appropriate
  51. } else {
  52. // continue to show the table's structure
  53. unset($_REQUEST['selected']);
  54. }
  55. }
  56. /**
  57. * handle multiple field commands if required
  58. *
  59. * submit_mult_*_x comes from IE if <input type="img" ...> is used
  60. */
  61. $submit_mult = PMA_getMultipleFieldCommandType();
  62. if (! empty($submit_mult)) {
  63. if (isset($_REQUEST['selected_fld'])) {
  64. if ($submit_mult == 'browse') {
  65. // browsing the table displaying only selected columns
  66. PMA_displayTableBrowseForSelectedColumns(
  67. $db, $table, $goto, $pmaThemeImage
  68. );
  69. } else {
  70. // handle multiple field commands
  71. // handle confirmation of deleting multiple columns
  72. $action = 'tbl_structure.php';
  73. include 'libraries/mult_submits.inc.php';
  74. /**
  75. * if $submit_mult == 'change', execution will have stopped
  76. * at this point
  77. */
  78. if (empty($message)) {
  79. $message = PMA_Message::success();
  80. }
  81. }
  82. } else {
  83. $response = PMA_Response::getInstance();
  84. $response->isSuccess(false);
  85. $response->addJSON('message', __('No column selected.'));
  86. }
  87. }
  88. /**
  89. * Gets the relation settings
  90. */
  91. $cfgRelation = PMA_getRelationsParam();
  92. /**
  93. * Runs common work
  94. */
  95. require_once 'libraries/tbl_common.inc.php';
  96. $url_query .= '&amp;goto=tbl_structure.php&amp;back=tbl_structure.php';
  97. $url_params['goto'] = 'tbl_structure.php';
  98. $url_params['back'] = 'tbl_structure.php';
  99. // Check column names for MySQL reserved words
  100. $reserved_word_column_messages = PMA_getReservedWordColumnNameMessages($db, $table);
  101. $response->addHTML($reserved_word_column_messages);
  102. /**
  103. * Prepares the table structure display
  104. */
  105. /**
  106. * Gets tables informations
  107. */
  108. require_once 'libraries/tbl_info.inc.php';
  109. require_once 'libraries/Index.class.php';
  110. // 2. Gets table keys and retains them
  111. // @todo should be: $server->db($db)->table($table)->primary()
  112. $primary = PMA_Index::getPrimary($table, $db);
  113. $columns_with_unique_index = PMA_getColumnsWithUniqueIndex($db, $table);
  114. // 3. Get fields
  115. $fields = (array) $GLOBALS['dbi']->getColumns($db, $table, null, true);
  116. // Get more complete field information
  117. // For now, this is done just for MySQL 4.1.2+ new TIMESTAMP options
  118. // but later, if the analyser returns more information, it
  119. // could be executed for any MySQL version and replace
  120. // the info given by SHOW FULL COLUMNS FROM.
  121. //
  122. // We also need this to correctly learn if a TIMESTAMP is NOT NULL, since
  123. // SHOW FULL COLUMNS or INFORMATION_SCHEMA incorrectly says NULL
  124. // and SHOW CREATE TABLE says NOT NULL (tested
  125. // in MySQL 4.0.25 and 5.0.21, http://bugs.mysql.com/20910).
  126. $show_create_table = $GLOBALS['dbi']->fetchValue(
  127. 'SHOW CREATE TABLE ' . PMA_Util::backquote($db) . '.'
  128. . PMA_Util::backquote($table),
  129. 0, 1
  130. );
  131. $analyzed_sql = PMA_SQP_analyze(PMA_SQP_parse($show_create_table));
  132. /**
  133. * prepare table infos
  134. */
  135. // action titles (image or string)
  136. $titles = PMA_getActionTitlesArray();
  137. // hidden action titles (image and string)
  138. $hidden_titles = PMA_getHiddenTitlesArray();
  139. //display table structure
  140. require_once 'libraries/display_structure.inc.php';
  141. ?>