build_html_for_db.lib.php 6.0 KB

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