build_html_for_db.lib.php 5.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180
  1. <?php
  2. /* vim: set expandtab sw=4 ts=4 sts=4: */
  3. /**
  4. *
  5. * @package PhpMyAdmin
  6. */
  7. if (! defined('PHPMYADMIN')) {
  8. exit;
  9. }
  10. /**
  11. * Prepares the $column_order array
  12. *
  13. * @return array
  14. */
  15. function PMA_getColumnOrder()
  16. {
  17. $column_order['DEFAULT_COLLATION_NAME'] = array(
  18. 'disp_name' => __('Collation'),
  19. 'description_function' => 'PMA_getCollationDescr',
  20. 'format' => 'string',
  21. 'footer' => PMA_getServerCollation(),
  22. );
  23. $column_order['SCHEMA_TABLES'] = array(
  24. 'disp_name' => __('Tables'),
  25. 'format' => 'number',
  26. 'footer' => 0,
  27. );
  28. $column_order['SCHEMA_TABLE_ROWS'] = array(
  29. 'disp_name' => __('Rows'),
  30. 'format' => 'number',
  31. 'footer' => 0,
  32. );
  33. $column_order['SCHEMA_DATA_LENGTH'] = array(
  34. 'disp_name' => __('Data'),
  35. 'format' => 'byte',
  36. 'footer' => 0,
  37. );
  38. $column_order['SCHEMA_INDEX_LENGTH'] = array(
  39. 'disp_name' => __('Indexes'),
  40. 'format' => 'byte',
  41. 'footer' => 0,
  42. );
  43. $column_order['SCHEMA_LENGTH'] = array(
  44. 'disp_name' => __('Total'),
  45. 'format' => 'byte',
  46. 'footer' => 0,
  47. );
  48. $column_order['SCHEMA_DATA_FREE'] = array(
  49. 'disp_name' => __('Overhead'),
  50. 'format' => 'byte',
  51. 'footer' => 0,
  52. );
  53. return $column_order;
  54. }
  55. /*
  56. * Builds the HTML td elements for one database to display in the list
  57. * of databases from server_databases.php (which can be modified by
  58. * db_create.php)
  59. *
  60. * @param array $current
  61. * @param boolean $is_superuser
  62. * @param string $url_query
  63. * @param array $column_order
  64. * @param array $replication_types
  65. * @param array $replication_info
  66. *
  67. * @return array $column_order, $out
  68. */
  69. function PMA_buildHtmlForDb(
  70. $current, $is_superuser, $url_query,
  71. $column_order, $replication_types, $replication_info
  72. ) {
  73. $out = '';
  74. if ($is_superuser || $GLOBALS['cfg']['AllowUserDropDatabase']) {
  75. $out .= '<td class="tool">';
  76. $out .= '<input type="checkbox" name="selected_dbs[]" class="checkall" '
  77. . 'title="' . htmlspecialchars($current['SCHEMA_NAME']) . '" '
  78. . 'value="' . htmlspecialchars($current['SCHEMA_NAME']) . '"';
  79. if (PMA_is_system_schema($current['SCHEMA_NAME'], true)) {
  80. $out .= ' disabled="disabled"';
  81. }
  82. $out .= ' /></td>';
  83. }
  84. $out .= '<td class="name">'
  85. . '<a href="' . $GLOBALS['cfg']['DefaultTabDatabase']
  86. . '?' . $url_query . '&amp;db='
  87. . urlencode($current['SCHEMA_NAME']) . '" title="'
  88. . sprintf(
  89. __('Jump to database'),
  90. htmlspecialchars($current['SCHEMA_NAME'])
  91. )
  92. . '">'
  93. . ' ' . htmlspecialchars($current['SCHEMA_NAME'])
  94. . '</a>'
  95. . '</td>';
  96. foreach ($column_order as $stat_name => $stat) {
  97. if (array_key_exists($stat_name, $current)) {
  98. if (is_numeric($stat['footer'])) {
  99. $column_order[$stat_name]['footer'] += $current[$stat_name];
  100. }
  101. if ($stat['format'] === 'byte') {
  102. list($value, $unit) = PMA_Util::formatByteDown(
  103. $current[$stat_name], 3, 1
  104. );
  105. } elseif ($stat['format'] === 'number') {
  106. $value = PMA_Util::formatNumber(
  107. $current[$stat_name], 0
  108. );
  109. } else {
  110. $value = htmlentities($current[$stat_name], 0);
  111. }
  112. $out .= '<td class="value">';
  113. if (isset($stat['description_function'])) {
  114. $out .= '<dfn title="'
  115. . $stat['description_function']($current[$stat_name]) . '">';
  116. }
  117. $out .= $value;
  118. if (isset($stat['description_function'])) {
  119. $out .= '</dfn>';
  120. }
  121. $out .= '</td>';
  122. if ($stat['format'] === 'byte') {
  123. $out .= '<td class="unit">' . $unit . '</td>';
  124. }
  125. }
  126. }
  127. foreach ($replication_types as $type) {
  128. if ($replication_info[$type]['status']) {
  129. $out .= '<td class="tool" style="text-align: center;">';
  130. $key = array_search(
  131. $current["SCHEMA_NAME"],
  132. $replication_info[$type]['Ignore_DB']
  133. );
  134. if (strlen($key) > 0) {
  135. $out .= PMA_Util::getIcon('s_cancel.png', __('Not replicated'));
  136. } else {
  137. $key = array_search(
  138. $current["SCHEMA_NAME"], $replication_info[$type]['Do_DB']
  139. );
  140. if (strlen($key) > 0
  141. || ($replication_info[$type]['Do_DB'][0] == ""
  142. && count($replication_info[$type]['Do_DB']) == 1)
  143. ) {
  144. // if ($key != null) did not work for index "0"
  145. $out .= PMA_Util::getIcon('s_success.png', __('Replicated'));
  146. }
  147. }
  148. $out .= '</td>';
  149. }
  150. }
  151. if ($is_superuser && !PMA_DRIZZLE) {
  152. $out .= '<td class="tool">'
  153. . '<a onclick="'
  154. . 'PMA_commonActions.setDb(\''
  155. . PMA_jsFormat($current['SCHEMA_NAME']) . '\');'
  156. . '" href="server_privileges.php?' . $url_query
  157. . '&amp;checkprivs=' . urlencode($current['SCHEMA_NAME'])
  158. . '" title="'
  159. . htmlspecialchars(sprintf(
  160. __('Check privileges for database "%s".'),
  161. $current['SCHEMA_NAME']
  162. ))
  163. . '">'
  164. . ' '
  165. . PMA_Util::getIcon('s_rights.png', __('Check Privileges'))
  166. . '</a></td>';
  167. }
  168. return array($column_order, $out);
  169. }
  170. ?>