/public/phpmyadmin/libraries/build_html_for_db.lib.php

https://gitlab.com/qbarbosa/klindev · PHP · 185 lines · 145 code · 11 blank · 29 comment · 22 complexity · 181fb60ee44ec730d31d910162162989 MD5 · raw file

  1. <?php
  2. /* vim: set expandtab sw=4 ts=4 sts=4: */
  3. /**
  4. * HTML generator 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. // At this point we were preparing the display of Overhead using DATA_FREE
  51. // but its content does not represent the real overhead in the case
  52. // of InnoDB
  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 current database
  61. * @param boolean $is_superuser user status
  62. * @param string $url_query url query
  63. * @param array $column_order column order
  64. * @param array $replication_types replication types
  65. * @param array $replication_info 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 ($GLOBALS['dbi']->isSystemSchema($current['SCHEMA_NAME'], true)) {
  80. $out .= ' disabled="disabled"';
  81. }
  82. $out .= ' /></td>';
  83. }
  84. $out .= '<td class="name">'
  85. . '<a href="' . PMA_Util::getScriptNameForOption(
  86. $GLOBALS['cfg']['DefaultTabDatabase'], 'database'
  87. )
  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. $unit = '';
  101. if (is_numeric($stat['footer'])) {
  102. $column_order[$stat_name]['footer'] += $current[$stat_name];
  103. }
  104. if ($stat['format'] === 'byte') {
  105. list($value, $unit) = PMA_Util::formatByteDown(
  106. $current[$stat_name], 3, 1
  107. );
  108. } elseif ($stat['format'] === 'number') {
  109. $value = PMA_Util::formatNumber(
  110. $current[$stat_name], 0
  111. );
  112. } else {
  113. $value = htmlentities($current[$stat_name], 0);
  114. }
  115. $out .= '<td class="value">';
  116. if (isset($stat['description_function'])) {
  117. $out .= '<dfn title="'
  118. . $stat['description_function']($current[$stat_name]) . '">';
  119. }
  120. $out .= $value;
  121. if (isset($stat['description_function'])) {
  122. $out .= '</dfn>';
  123. }
  124. $out .= '</td>';
  125. if ($stat['format'] === 'byte') {
  126. $out .= '<td class="unit">' . $unit . '</td>';
  127. }
  128. }
  129. }
  130. foreach ($replication_types as $type) {
  131. if ($replication_info[$type]['status']) {
  132. $out .= '<td class="tool" style="text-align: center;">';
  133. $key = array_search(
  134. $current["SCHEMA_NAME"],
  135. $replication_info[$type]['Ignore_DB']
  136. );
  137. if (/*overload*/mb_strlen($key) > 0) {
  138. $out .= PMA_Util::getIcon('s_cancel.png', __('Not replicated'));
  139. } else {
  140. $key = array_search(
  141. $current["SCHEMA_NAME"], $replication_info[$type]['Do_DB']
  142. );
  143. if (/*overload*/mb_strlen($key) > 0
  144. || (isset($replication_info[$type]['Do_DB'][0])
  145. && $replication_info[$type]['Do_DB'][0] == ""
  146. && count($replication_info[$type]['Do_DB']) == 1)
  147. ) {
  148. // if ($key != null) did not work for index "0"
  149. $out .= PMA_Util::getIcon('s_success.png', __('Replicated'));
  150. }
  151. }
  152. $out .= '</td>';
  153. }
  154. }
  155. if ($is_superuser && !PMA_DRIZZLE) {
  156. $out .= '<td class="tool">'
  157. . '<a onclick="'
  158. . 'PMA_commonActions.setDb(\''
  159. . PMA_jsFormat($current['SCHEMA_NAME']) . '\');'
  160. . '" href="server_privileges.php' . $url_query
  161. . '&amp;db=' . urlencode($current['SCHEMA_NAME'])
  162. . '&amp;checkprivsdb=' . urlencode($current['SCHEMA_NAME'])
  163. . '" title="'
  164. . sprintf(
  165. __('Check privileges for database "%s".'),
  166. htmlspecialchars($current['SCHEMA_NAME'])
  167. )
  168. . '">'
  169. . ' '
  170. . PMA_Util::getIcon('s_rights.png', __('Check privileges'))
  171. . '</a></td>';
  172. }
  173. return array($column_order, $out);
  174. }