2 /* vim: set expandtab sw=4 ts=4 sts=4: */
5 * functions for displaying server binary log
7 * @usedby server_binlog.php
11 if (! defined('PHPMYADMIN')) {
16 * Returns the html for log selector.
18 * @param Array $binary_logs Binary logs file names
19 * @param Array $url_params links parameters
23 function PMA_getLogSelector($binary_logs, $url_params)
26 if (count($binary_logs) > 1) {
27 $html .= '<form action="server_binlog.php" method="get">';
28 $html .= PMA_URL_getHiddenInputs($url_params);
29 $html .= '<fieldset><legend>';
30 $html .= __('Select binary log to view');
31 $html .= '</legend><select name="log">';
33 foreach ($binary_logs as $each_log) {
34 $html .= '<option value="' . $each_log['Log_name'] . '"';
35 if ($each_log['Log_name'] == $_REQUEST['log']) {
36 $html .= ' selected="selected"';
38 $html .= '>' . $each_log['Log_name'];
39 if (isset($each_log['File_size'])) {
40 $full_size +
= $each_log['File_size'];
44 PMA_Util
::formatByteDown(
45 $each_log['File_size'], 3, 2
52 $html .= '</select> ';
53 $html .= count($binary_logs) . ' ' . __('Files') . ', ';
56 ' ', PMA_Util
::formatByteDown($full_size)
59 $html .= '</fieldset>';
60 $html .= '<fieldset class="tblFooters">';
61 $html .= '<input type="submit" value="' . __('Go') . '" />';
62 $html .= '</fieldset>';
70 * Returns the html for binary log information.
72 * @param Array $url_params links parameters
76 function PMA_getLogInfo($url_params)
79 * Need to find the real end of rows?
81 if (! isset($_REQUEST['pos'])) {
84 /* We need this to be a integer */
85 $pos = (int) $_REQUEST['pos'];
88 $sql_query = 'SHOW BINLOG EVENTS';
89 if (! empty($_REQUEST['log'])) {
90 $sql_query .= ' IN \'' . $_REQUEST['log'] . '\'';
92 $sql_query .= ' LIMIT ' . $pos . ', ' . (int) $GLOBALS['cfg']['MaxRows'];
97 $result = $GLOBALS['dbi']->query($sql_query);
100 * prepare some vars for displaying the result table
102 // Gets the list of fields properties
103 if (isset($result) && $result) {
104 $num_rows = $GLOBALS['dbi']->numRows($result);
109 if (empty($_REQUEST['dontlimitchars'])) {
110 $dontlimitchars = false;
112 $dontlimitchars = true;
113 $url_params['dontlimitchars'] = 1;
117 $html = PMA_Util
::getMessage(PMA_Message
::success(), $sql_query);
118 $html .= '<table cellpadding="2" cellspacing="1" id="binlogTable">'
121 . '<td colspan="6" class="center">';
123 $html .= PMA_getNavigationRow($url_params, $pos, $num_rows, $dontlimitchars);
128 . '<th>' . __('Log name') . '</th>'
129 . '<th>' . __('Position') . '</th>'
130 . '<th>' . __('Event type') . '</th>'
131 . '<th>' . __('Server ID') . '</th>'
132 . '<th>' . __('Original position') . '</th>'
133 . '<th>' . __('Information') . '</th>'
138 $html .= PMA_getAllLogItemInfo($result, $dontlimitchars);
147 * Returns the html for Navigation Row.
149 * @param Array $url_params Links parameters
150 * @param int $pos Position to display
151 * @param int $num_rows Number of results row
152 * @param bool $dontlimitchars Whether limit chars
156 function PMA_getNavigationRow($url_params, $pos, $num_rows, $dontlimitchars)
159 // we do not know how much rows are in the binlog
160 // so we can just force 'NEXT' button
162 $this_url_params = $url_params;
163 if ($pos > $GLOBALS['cfg']['MaxRows']) {
164 $this_url_params['pos'] = $pos - $GLOBALS['cfg']['MaxRows'];
167 $html .= '<a href="server_binlog.php'
168 . PMA_URL_getCommon($this_url_params) . '"';
169 if (PMA_Util
::showIcons('TableNavigationLinksMode')) {
170 $html .= ' title="' . _pgettext('Previous page', 'Previous') . '">';
172 $html .= '>' . _pgettext('Previous page', 'Previous');
173 } // end if... else...
174 $html .= ' < </a> - ';
177 $this_url_params = $url_params;
179 $this_url_params['pos'] = $pos;
181 if ($dontlimitchars) {
182 unset($this_url_params['dontlimitchars']);
183 $tempTitle = __('Truncate Shown Queries');
184 $tempImgMode = 'partial';
186 $this_url_params['dontlimitchars'] = 1;
187 $tempTitle = __('Show Full Queries');
188 $tempImgMode = 'full';
190 $html .= '<a href="server_binlog.php' . PMA_URL_getCommon($this_url_params)
191 . '" title="' . $tempTitle . '">'
192 . '<img src="' . $GLOBALS['pmaThemeImage'] . 's_' . $tempImgMode
193 . 'text.png" alt="' . $tempTitle . '" /></a>';
195 // we do not now how much rows are in the binlog
196 // so we can just force 'NEXT' button
197 if ($num_rows >= $GLOBALS['cfg']['MaxRows']) {
198 $this_url_params = $url_params;
199 $this_url_params['pos'] = $pos +
$GLOBALS['cfg']['MaxRows'];
200 $html .= ' - <a href="server_binlog.php'
201 . PMA_URL_getCommon($this_url_params)
203 if (PMA_Util
::showIcons('TableNavigationLinksMode')) {
204 $html .= ' title="' . _pgettext('Next page', 'Next') . '">';
206 $html .= '>' . _pgettext('Next page', 'Next');
207 } // end if... else...
208 $html .= ' > </a>';
215 * Returns the html for all binary log items.
217 * @param resource $result MySQL Query result
218 * @param bool $dontlimitchars Whether limit chars
222 function PMA_getAllLogItemInfo($result, $dontlimitchars)
226 while ($value = $GLOBALS['dbi']->fetchAssoc($result)) {
227 $html .= '<tr class="noclick ' . ($odd_row ?
'odd' : 'even') . '">'
228 . '<td> ' . $value['Log_name'] . ' </td>'
229 . '<td class="right"> ' . $value['Pos'] . ' </td>'
230 . '<td> ' . $value['Event_type'] . ' </td>'
231 . '<td class="right"> ' . $value['Server_id'] . ' </td>'
232 . '<td class="right"> '
233 . (isset($value['Orig_log_pos'])
234 ?
$value['Orig_log_pos'] : $value['End_log_pos'])
236 . '<td> ' . PMA_Util
::formatSql($value['Info'], ! $dontlimitchars)
237 . ' </td></tr>';
239 $odd_row = !$odd_row;