server_bin_log.lib.php 7.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244
  1. <?php
  2. /* vim: set expandtab sw=4 ts=4 sts=4: */
  3. /**
  4. * functions for displaying server binary log
  5. *
  6. * @usedby server_binlog.php
  7. *
  8. * @package PhpMyAdmin
  9. */
  10. if (! defined('PHPMYADMIN')) {
  11. exit;
  12. }
  13. /**
  14. * Returns the html for log selector.
  15. *
  16. * @param Array $binary_logs Binary logs file names
  17. * @param Array $url_params links parameters
  18. *
  19. * @return string
  20. */
  21. function PMA_getLogSelector($binary_logs, $url_params)
  22. {
  23. $html = "";
  24. if (count($binary_logs) > 1) {
  25. $html .= '<form action="server_binlog.php" method="get">';
  26. $html .= PMA_URL_getHiddenInputs($url_params);
  27. $html .= '<fieldset><legend>';
  28. $html .= __('Select binary log to view');
  29. $html .= '</legend><select name="log">';
  30. $full_size = 0;
  31. foreach ($binary_logs as $each_log) {
  32. $html .= '<option value="' . $each_log['Log_name'] . '"';
  33. if ($each_log['Log_name'] == $_REQUEST['log']) {
  34. $html .= ' selected="selected"';
  35. }
  36. $html .= '>' . $each_log['Log_name'];
  37. if (isset($each_log['File_size'])) {
  38. $full_size += $each_log['File_size'];
  39. $html .= ' ('
  40. . implode(
  41. ' ',
  42. PMA_Util::formatByteDown(
  43. $each_log['File_size'], 3, 2
  44. )
  45. )
  46. . ')';
  47. }
  48. $html .= '</option>';
  49. }
  50. $html .= '</select> ';
  51. $html .= count($binary_logs) . ' ' . __('Files') . ', ';
  52. if ($full_size > 0) {
  53. $html .= implode(
  54. ' ', PMA_Util::formatByteDown($full_size)
  55. );
  56. }
  57. $html .= '</fieldset>';
  58. $html .= '<fieldset class="tblFooters">';
  59. $html .= '<input type="submit" value="' . __('Go') . '" />';
  60. $html .= '</fieldset>';
  61. $html .= '</form>';
  62. }
  63. return $html;
  64. }
  65. /**
  66. * Returns the html for binary log information.
  67. *
  68. * @param Array $url_params links parameters
  69. *
  70. * @return string
  71. */
  72. function PMA_getLogInfo($url_params)
  73. {
  74. /**
  75. * Need to find the real end of rows?
  76. */
  77. if (! isset($_REQUEST['pos'])) {
  78. $pos = 0;
  79. } else {
  80. /* We need this to be a integer */
  81. $pos = (int) $_REQUEST['pos'];
  82. }
  83. $sql_query = 'SHOW BINLOG EVENTS';
  84. if (! empty($_REQUEST['log'])) {
  85. $sql_query .= ' IN \'' . $_REQUEST['log'] . '\'';
  86. }
  87. $sql_query .= ' LIMIT ' . $pos . ', ' . (int) $GLOBALS['cfg']['MaxRows'];
  88. /**
  89. * Sends the query
  90. */
  91. $result = $GLOBALS['dbi']->query($sql_query);
  92. /**
  93. * prepare some vars for displaying the result table
  94. */
  95. // Gets the list of fields properties
  96. if (isset($result) && $result) {
  97. $num_rows = $GLOBALS['dbi']->numRows($result);
  98. } else {
  99. $num_rows = 0;
  100. }
  101. if (empty($_REQUEST['dontlimitchars'])) {
  102. $dontlimitchars = false;
  103. } else {
  104. $dontlimitchars = true;
  105. $url_params['dontlimitchars'] = 1;
  106. }
  107. //html output
  108. $html = PMA_Util::getMessage(PMA_Message::success(), $sql_query);
  109. $html .= '<table cellpadding="2" cellspacing="1" id="binlogTable">'
  110. . '<thead>'
  111. . '<tr>'
  112. . '<td colspan="6" class="center">';
  113. $html .= PMA_getNavigationRow($url_params, $pos, $num_rows, $dontlimitchars);
  114. $html .= '</td>'
  115. . '</tr>'
  116. . '<tr>'
  117. . '<th>' . __('Log name') . '</th>'
  118. . '<th>' . __('Position') . '</th>'
  119. . '<th>' . __('Event type') . '</th>'
  120. . '<th>' . __('Server ID') . '</th>'
  121. . '<th>' . __('Original position') . '</th>'
  122. . '<th>' . __('Information') . '</th>'
  123. . '</tr>'
  124. . '</thead>'
  125. . '<tbody>';
  126. $html .= PMA_getAllLogItemInfo($result, $dontlimitchars);
  127. $html .= '</tbody>'
  128. . '</table>';
  129. return $html;
  130. }
  131. /**
  132. * Returns the html for Navigation Row.
  133. *
  134. * @param Array $url_params Links parameters
  135. * @param int $pos Position to display
  136. * @param int $num_rows Number of results row
  137. * @param bool $dontlimitchars Whether limit chars
  138. *
  139. * @return string
  140. */
  141. function PMA_getNavigationRow($url_params, $pos, $num_rows, $dontlimitchars)
  142. {
  143. $html = "";
  144. // we do not know how much rows are in the binlog
  145. // so we can just force 'NEXT' button
  146. if ($pos > 0) {
  147. $this_url_params = $url_params;
  148. if ($pos > $GLOBALS['cfg']['MaxRows']) {
  149. $this_url_params['pos'] = $pos - $GLOBALS['cfg']['MaxRows'];
  150. }
  151. $html .= '<a href="server_binlog.php'
  152. . PMA_URL_getCommon($this_url_params) . '"';
  153. if (PMA_Util::showIcons('TableNavigationLinksMode')) {
  154. $html .= ' title="' . _pgettext('Previous page', 'Previous') . '">';
  155. } else {
  156. $html .= '>' . _pgettext('Previous page', 'Previous');
  157. } // end if... else...
  158. $html .= ' &lt; </a> - ';
  159. }
  160. $this_url_params = $url_params;
  161. if ($pos > 0) {
  162. $this_url_params['pos'] = $pos;
  163. }
  164. if ($dontlimitchars) {
  165. unset($this_url_params['dontlimitchars']);
  166. $tempTitle = __('Truncate Shown Queries');
  167. $tempImgMode = 'partial';
  168. } else {
  169. $this_url_params['dontlimitchars'] = 1;
  170. $tempTitle = __('Show Full Queries');
  171. $tempImgMode = 'full';
  172. }
  173. $html .= '<a href="server_binlog.php' . PMA_URL_getCommon($this_url_params)
  174. . '" title="' . $tempTitle . '">'
  175. . '<img src="' . $GLOBALS['pmaThemeImage'] . 's_' . $tempImgMode . 'text.png"'
  176. . 'alt="' . $tempTitle . '" /></a>';
  177. // we do not now how much rows are in the binlog
  178. // so we can just force 'NEXT' button
  179. if ($num_rows >= $GLOBALS['cfg']['MaxRows']) {
  180. $this_url_params = $url_params;
  181. $this_url_params['pos'] = $pos + $GLOBALS['cfg']['MaxRows'];
  182. $html .= ' - <a href="server_binlog.php'
  183. . PMA_URL_getCommon($this_url_params)
  184. . '"';
  185. if (PMA_Util::showIcons('TableNavigationLinksMode')) {
  186. $html .= ' title="' . _pgettext('Next page', 'Next') . '">';
  187. } else {
  188. $html .= '>' . _pgettext('Next page', 'Next');
  189. } // end if... else...
  190. $html .= ' &gt; </a>';
  191. }
  192. return $html;
  193. }
  194. /**
  195. * Returns the html for all binary log items.
  196. *
  197. * @param resource $result MySQL Query result
  198. * @param bool $dontlimitchars Whether limit chars
  199. *
  200. * @return string
  201. */
  202. function PMA_getAllLogItemInfo($result, $dontlimitchars)
  203. {
  204. $html = "";
  205. $odd_row = true;
  206. while ($value = $GLOBALS['dbi']->fetchAssoc($result)) {
  207. $html .= '<tr class="noclick ' . ($odd_row ? 'odd' : 'even') . '">'
  208. . '<td>&nbsp;' . $value['Log_name'] . '&nbsp;</td>'
  209. . '<td class="right">&nbsp;' . $value['Pos'] . '&nbsp;</td>'
  210. . '<td>&nbsp;' . $value['Event_type'] . '&nbsp;</td>'
  211. . '<td class="right">&nbsp;' . $value['Server_id'] . '&nbsp;</td>'
  212. . '<td class="right">&nbsp;'
  213. . (isset($value['Orig_log_pos'])
  214. ? $value['Orig_log_pos'] : $value['End_log_pos'])
  215. . '&nbsp;</td>'
  216. . '<td>&nbsp;' . PMA_Util::formatSql($value['Info'], ! $dontlimitchars)
  217. . '&nbsp;</td></tr>';
  218. $odd_row = !$odd_row;
  219. }
  220. return $html;
  221. }
  222. ?>