display_structure.inc.php 7.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269
  1. <?php
  2. /* vim: set expandtab sw=4 ts=4 sts=4: */
  3. /**
  4. * Displays the table structure ('show table' works correct since 3.23.03)
  5. *
  6. * @package PhpMyAdmin
  7. */
  8. require_once 'libraries/common.inc.php';
  9. require_once 'libraries/mysql_charsets.inc.php';
  10. require_once 'libraries/structure.lib.php';
  11. require_once 'libraries/index.lib.php';
  12. require_once 'libraries/tbl_info.inc.php';
  13. if (! defined('PHPMYADMIN')) {
  14. exit;
  15. }
  16. /* TABLE INFORMATION */
  17. // table header
  18. $HideStructureActions = '';
  19. if ($GLOBALS['cfg']['HideStructureActions'] === true) {
  20. $HideStructureActions .= ' HideStructureActions';
  21. }
  22. $html_form = '<form method="post" action="tbl_structure.php" name="fieldsForm" '
  23. . 'id="fieldsForm" class="ajax' . $HideStructureActions . '">';
  24. $response->addHTML($html_form);
  25. $response->addHTML(PMA_URL_getHiddenInputs($db, $table));
  26. $tabletype = '<input type="hidden" name="table_type" value=';
  27. if ($db_is_system_schema) {
  28. $tabletype .= '"information_schema" />';
  29. } else if ($tbl_is_view) {
  30. $tabletype .= '"view" />';
  31. } else {
  32. $tabletype .= '"table" />';
  33. }
  34. $response->addHTML($tabletype);
  35. $tablestructure = '<table id="tablestructure" class="data">';
  36. $response->addHTML($tablestructure);
  37. $response->addHTML(
  38. PMA_getHtmlForTableStructureHeader(
  39. $db_is_system_schema,
  40. $tbl_is_view
  41. )
  42. );
  43. $response->addHTML('<tbody>');
  44. // table body
  45. // prepare comments
  46. $comments_map = array();
  47. $mime_map = array();
  48. if ($GLOBALS['cfg']['ShowPropertyComments']) {
  49. include_once 'libraries/transformations.lib.php';
  50. $comments_map = PMA_getComments($db, $table);
  51. if ($cfgRelation['mimework'] && $cfg['BrowseMIME']) {
  52. $mime_map = PMA_getMIME($db, $table, true);
  53. }
  54. }
  55. $rownum = 0;
  56. $columns_list = array();
  57. $save_row = array();
  58. $odd_row = true;
  59. foreach ($fields as $row) {
  60. $save_row[] = $row;
  61. $rownum++;
  62. $columns_list[] = $row['Field'];
  63. $type = $row['Type'];
  64. $extracted_columnspec = PMA_Util::extractColumnSpec($row['Type']);
  65. if ('set' == $extracted_columnspec['type']
  66. || 'enum' == $extracted_columnspec['type']
  67. ) {
  68. $type_nowrap = '';
  69. } else {
  70. $type_nowrap = ' class="nowrap"';
  71. }
  72. $type = $extracted_columnspec['print_type'];
  73. if (empty($type)) {
  74. $type = ' ';
  75. }
  76. $field_charset = '';
  77. if ($extracted_columnspec['can_contain_collation']
  78. && ! empty($row['Collation'])
  79. ) {
  80. $field_charset = $row['Collation'];
  81. }
  82. // Display basic mimetype [MIME]
  83. if ($cfgRelation['commwork']
  84. && $cfgRelation['mimework']
  85. && $cfg['BrowseMIME']
  86. && isset($mime_map[$row['Field']]['mimetype'])
  87. ) {
  88. $type_mime = '<br />MIME: '
  89. . str_replace('_', '/', $mime_map[$row['Field']]['mimetype']);
  90. } else {
  91. $type_mime = '';
  92. }
  93. $attribute = $extracted_columnspec['attribute'];
  94. // prepare a common variable to reuse below; however,
  95. // in case of a VIEW, $analyzed_sql[0]['create_table_fields'] is empty
  96. if (isset($analyzed_sql[0]['create_table_fields'][$row['Field']])) {
  97. $tempField = $analyzed_sql[0]['create_table_fields'][$row['Field']];
  98. } else {
  99. $tempField = array();
  100. }
  101. // MySQL 4.1.2+ TIMESTAMP options
  102. // (if on_update_current_timestamp is set, then it's TRUE)
  103. if (isset($tempField['on_update_current_timestamp'])) {
  104. $attribute = 'on update CURRENT_TIMESTAMP';
  105. }
  106. // here, we have a TIMESTAMP that SHOW FULL COLUMNS reports as having the
  107. // NULL attribute, but SHOW CREATE TABLE says the contrary. Believe
  108. // the latter.
  109. if (! empty($tempField['type'])
  110. && $tempField['type'] == 'TIMESTAMP'
  111. && $tempField['timestamp_not_null']
  112. ) {
  113. $row['Null'] = '';
  114. }
  115. if (! isset($row['Default'])) {
  116. if ($row['Null'] == 'YES') {
  117. $row['Default'] = '<i>NULL</i>';
  118. }
  119. } else {
  120. $row['Default'] = htmlspecialchars($row['Default']);
  121. }
  122. $field_encoded = urlencode($row['Field']);
  123. $field_name = htmlspecialchars($row['Field']);
  124. $displayed_field_name = $field_name;
  125. // underline commented fields and display a hover-title (CSS only)
  126. if (isset($comments_map[$row['Field']])) {
  127. $displayed_field_name = '<span class="commented_column" title="'
  128. . htmlspecialchars($comments_map[$row['Field']]) . '">'
  129. . $field_name . '</span>';
  130. }
  131. if ($primary && $primary->hasColumn($field_name)) {
  132. $displayed_field_name = '<u>' . $field_name . '</u>';
  133. }
  134. $response->addHTML(
  135. '<tr class="' . ($odd_row ? 'odd': 'even') . '">'
  136. );
  137. $odd_row = !$odd_row;
  138. $response->addHTML(
  139. PMA_getHtmlTableStructureRow(
  140. $row, $rownum, $displayed_field_name,
  141. $type_nowrap, $extracted_columnspec, $type_mime,
  142. $field_charset, $attribute, $tbl_is_view,
  143. $db_is_system_schema, $url_query, $field_encoded, $titles, $table
  144. )
  145. );
  146. if (! $tbl_is_view && ! $db_is_system_schema) {
  147. $response->addHTML(
  148. PMA_getHtmlForActionsInTableStructure(
  149. $type, $tbl_storage_engine, $primary,
  150. $field_name, $url_query, $titles, $row, $rownum,
  151. $hidden_titles, $columns_with_unique_index
  152. )
  153. );
  154. } // end if (! $tbl_is_view && ! $db_is_system_schema)
  155. $response->addHTML('</tr>');
  156. unset($field_charset);
  157. } // end foreach
  158. $response->addHTML('</tbody></table>');
  159. $response->addHTML(
  160. PMA_getHtmlForCheckAllTableColumn(
  161. $pmaThemeImage, $text_dir, $tbl_is_view,
  162. $db_is_system_schema, $tbl_storage_engine
  163. )
  164. );
  165. $response->addHTML(
  166. '</form><hr />'
  167. );
  168. $response->addHTML(
  169. PMA_getHtmlDivForMoveColumnsDialog()
  170. );
  171. /**
  172. * Work on the table
  173. */
  174. $response->addHTML('<div id="structure-action-links">');
  175. if ($tbl_is_view) {
  176. $response->addHTML(PMA_getHtmlForEditView($url_params));
  177. }
  178. $response->addHTML(
  179. PMA_getHtmlForOptionalActionLinks(
  180. $url_query, $tbl_is_view, $db_is_system_schema,
  181. $tbl_storage_engine, $cfgRelation
  182. )
  183. );
  184. $response->addHTML('</div>');
  185. if (! $tbl_is_view && ! $db_is_system_schema) {
  186. $response->addHTML('<br />');
  187. $response->addHTML(PMA_getHtmlForAddColumn($columns_list));
  188. }
  189. /**
  190. * Displays indexes
  191. */
  192. if (! $tbl_is_view
  193. && ! $db_is_system_schema
  194. && 'ARCHIVE' != $tbl_storage_engine
  195. ) {
  196. //return the list of index
  197. $response->addJSON(
  198. 'indexes_list',
  199. PMA_Index::getView($GLOBALS['table'], $GLOBALS['db'])
  200. );
  201. $response->addHTML(PMA_getHtmlForDisplayIndexes());
  202. }
  203. /**
  204. * Displays Space usage and row statistics
  205. */
  206. // BEGIN - Calc Table Space
  207. // Get valid statistics whatever is the table type
  208. if ($cfg['ShowStats']) {
  209. //get table stats in HTML format
  210. $tablestats = PMA_getHtmlForDisplayTableStats(
  211. $showtable, $table_info_num_rows, $tbl_is_view,
  212. $db_is_system_schema, $tbl_storage_engine,
  213. $url_query, $tbl_collation
  214. );
  215. //returning the response in JSON format to be used by Ajax
  216. $response->addJSON('tableStat', $tablestats);
  217. $response->addHTML($tablestats);
  218. }
  219. // END - Calc Table Space
  220. $response->addHTML(
  221. '<div class="clearfloat"></div>'
  222. );
  223. ?>