db_datadict.php 5.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215
  1. <?php
  2. /* vim: set expandtab sw=4 ts=4 sts=4: */
  3. /**
  4. * Renders data dictionary
  5. *
  6. * @package PhpMyAdmin
  7. */
  8. use PhpMyAdmin\Relation;
  9. use PhpMyAdmin\Response;
  10. use PhpMyAdmin\Transformations;
  11. use PhpMyAdmin\Url;
  12. /**
  13. * Gets the variables sent or posted to this script, then displays headers
  14. */
  15. require_once 'libraries/common.inc.php';
  16. if (! isset($selected_tbl)) {
  17. include 'libraries/db_common.inc.php';
  18. list(
  19. $tables,
  20. $num_tables,
  21. $total_num_tables,
  22. $sub_part,
  23. $is_show_stats,
  24. $db_is_system_schema,
  25. $tooltip_truename,
  26. $tooltip_aliasname,
  27. $pos
  28. ) = PhpMyAdmin\Util::getDbInfo($db, isset($sub_part) ? $sub_part : '');
  29. }
  30. $response = Response::getInstance();
  31. $header = $response->getHeader();
  32. $header->enablePrintView();
  33. $relation = new Relation();
  34. /**
  35. * Gets the relations settings
  36. */
  37. $cfgRelation = $relation->getRelationsParam();
  38. /**
  39. * Check parameters
  40. */
  41. PhpMyAdmin\Util::checkParameters(array('db'));
  42. /**
  43. * Defines the url to return to in case of error in a sql statement
  44. */
  45. $err_url = 'db_sql.php' . Url::getCommon(array('db' => $db));
  46. if ($cfgRelation['commwork']) {
  47. $comment = $relation->getDbComment($db);
  48. /**
  49. * Displays DB comment
  50. */
  51. if ($comment) {
  52. echo '<p>' , __('Database comment')
  53. , '<br /><i>' , htmlspecialchars($comment) , '</i></p>';
  54. } // end if
  55. }
  56. /**
  57. * Selects the database and gets tables names
  58. */
  59. $GLOBALS['dbi']->selectDb($db);
  60. $tables = $GLOBALS['dbi']->getTables($db);
  61. $count = 0;
  62. foreach ($tables as $table) {
  63. $comments = $relation->getComments($db, $table);
  64. echo '<div>' , "\n";
  65. echo '<h2>' , htmlspecialchars($table) , '</h2>' , "\n";
  66. /**
  67. * Gets table information
  68. */
  69. $show_comment = $GLOBALS['dbi']->getTable($db, $table)
  70. ->getStatusInfo('TABLE_COMMENT');
  71. /**
  72. * Gets table keys and retains them
  73. */
  74. $GLOBALS['dbi']->selectDb($db);
  75. $indexes = $GLOBALS['dbi']->getTableIndexes($db, $table);
  76. list($primary, $pk_array, $indexes_info, $indexes_data)
  77. = PhpMyAdmin\Util::processIndexData($indexes);
  78. /**
  79. * Gets columns properties
  80. */
  81. $columns = $GLOBALS['dbi']->getColumns($db, $table);
  82. // Check if we can use Relations
  83. list($res_rel, $have_rel) = $relation->getRelationsAndStatus(
  84. ! empty($cfgRelation['relation']), $db, $table
  85. );
  86. /**
  87. * Displays the comments of the table if MySQL >= 3.23
  88. */
  89. if (!empty($show_comment)) {
  90. echo __('Table comments:') , ' ';
  91. echo htmlspecialchars($show_comment) , '<br /><br />';
  92. }
  93. /**
  94. * Displays the table structure
  95. */
  96. echo '<table width="100%" class="print">';
  97. echo '<tr><th width="50">' , __('Column') , '</th>';
  98. echo '<th width="80">' , __('Type') , '</th>';
  99. echo '<th width="40">' , __('Null') , '</th>';
  100. echo '<th width="70">' , __('Default') , '</th>';
  101. if ($have_rel) {
  102. echo ' <th>' , __('Links to') , '</th>' , "\n";
  103. }
  104. echo ' <th>' , __('Comments') , '</th>' , "\n";
  105. if ($cfgRelation['mimework']) {
  106. echo ' <th>MIME</th>' , "\n";
  107. }
  108. echo '</tr>';
  109. foreach ($columns as $row) {
  110. if ($row['Null'] == '') {
  111. $row['Null'] = 'NO';
  112. }
  113. $extracted_columnspec
  114. = PhpMyAdmin\Util::extractColumnSpec($row['Type']);
  115. // reformat mysql query output
  116. // set or enum types: slashes single quotes inside options
  117. $type = htmlspecialchars($extracted_columnspec['print_type']);
  118. $attribute = $extracted_columnspec['attribute'];
  119. if (! isset($row['Default'])) {
  120. if ($row['Null'] != 'NO') {
  121. $row['Default'] = '<i>NULL</i>';
  122. }
  123. } else {
  124. $row['Default'] = htmlspecialchars($row['Default']);
  125. }
  126. $column_name = $row['Field'];
  127. echo '<tr>';
  128. echo '<td class="nowrap">';
  129. echo htmlspecialchars($column_name);
  130. if (isset($pk_array[$row['Field']])) {
  131. echo ' <em>(' , __('Primary') , ')</em>';
  132. }
  133. echo '</td>';
  134. echo '<td'
  135. , PhpMyAdmin\Util::getClassForType(
  136. $extracted_columnspec['type']
  137. )
  138. , ' lang="en" dir="ltr">' , $type , '</td>';
  139. echo '<td>';
  140. echo (($row['Null'] == 'NO') ? __('No') : __('Yes'));
  141. echo '</td>';
  142. echo '<td class="nowrap">';
  143. if (isset($row['Default'])) {
  144. echo $row['Default'];
  145. }
  146. echo '</td>';
  147. if ($have_rel) {
  148. echo ' <td>';
  149. if ($foreigner = $relation->searchColumnInForeigners($res_rel, $column_name)) {
  150. echo htmlspecialchars(
  151. $foreigner['foreign_table']
  152. . ' -> '
  153. . $foreigner['foreign_field']
  154. );
  155. }
  156. echo '</td>' , "\n";
  157. }
  158. echo ' <td>';
  159. if (isset($comments[$column_name])) {
  160. echo htmlspecialchars($comments[$column_name]);
  161. }
  162. echo '</td>' , "\n";
  163. if ($cfgRelation['mimework']) {
  164. $mime_map = Transformations::getMIME($db, $table, true);
  165. echo ' <td>';
  166. if (isset($mime_map[$column_name])) {
  167. echo htmlspecialchars(
  168. str_replace('_', '/', $mime_map[$column_name]['mimetype'])
  169. );
  170. }
  171. echo '</td>' , "\n";
  172. }
  173. echo '</tr>';
  174. } // end foreach
  175. $count++;
  176. echo '</table>';
  177. // display indexes information
  178. if (count(PhpMyAdmin\Index::getFromTable($table, $db)) > 0) {
  179. echo PhpMyAdmin\Index::getHtmlForIndexes($table, $db, true);
  180. }
  181. echo '</div>';
  182. } //ends main while
  183. /**
  184. * Displays the footer
  185. */
  186. echo PhpMyAdmin\Util::getButton();