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_log_file_names Binary logs file names
19 * @param Array $url_params links parameters
23 function PMA_getLogSelector($binary_log_file_names, $url_params)
26 if (count($binary_log_file_names) > 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_log_file_names 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_log_file_names) . ' ' . __('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 $binary_log_file_names Binary logs file names
73 * @param Array $url_params links parameters
77 function PMA_getLogInfo($binary_log_file_names, $url_params)
80 * Need to find the real end of rows?
82 if (! isset($_REQUEST['pos'])) {
85 /* We need this to be a integer */
86 $pos = (int) $_REQUEST['pos'];
89 $sql_query = 'SHOW BINLOG EVENTS';
90 if (! empty($_REQUEST['log'])) {
91 $sql_query .= ' IN \'' . $_REQUEST['log'] . '\'';
93 $sql_query .= ' LIMIT ' . $pos . ', ' . (int) $GLOBALS['cfg']['MaxRows'];
98 $result = $GLOBALS['dbi']->query($sql_query);
101 * prepare some vars for displaying the result table
103 // Gets the list of fields properties
104 if (isset($result) && $result) {
105 $num_rows = $GLOBALS['dbi']->numRows($result);
110 if (empty($_REQUEST['dontlimitchars'])) {
111 $dontlimitchars = false;
113 $dontlimitchars = true;
114 $url_params['dontlimitchars'] = 1;
118 $html = PMA_Util
::getMessage(PMA_Message
::success(), $sql_query);
119 $html .= '<table cellpadding="2" cellspacing="1" id="binlogTable">'
122 . '<td colspan="6" class="center">';
124 $html .= PMA_getNavigationRow($url_params, $pos, $num_rows, $dontlimitchars);
129 . '<th>' . __('Log name') . '</th>'
130 . '<th>' . __('Position') . '</th>'
131 . '<th>' . __('Event type') . '</th>'
132 . '<th>' . __('Server ID') . '</th>'
133 . '<th>' . __('Original position') . '</th>'
134 . '<th>' . __('Information') . '</th>'
139 $html .= PMA_getAllLogItemInfo($result, $dontlimitchars);
148 * Returns the html for Navigation Row.
150 * @param Array $url_params Links parameters
151 * @param int $pos Position to display
152 * @param int $num_rows Number of results row
153 * @param bool $dontlimitchars Whether limit chars
157 function PMA_getNavigationRow($url_params, $pos, $num_rows, $dontlimitchars)
160 // we do not know how much rows are in the binlog
161 // so we can just force 'NEXT' button
163 $this_url_params = $url_params;
164 if ($pos > $GLOBALS['cfg']['MaxRows']) {
165 $this_url_params['pos'] = $pos - $GLOBALS['cfg']['MaxRows'];
168 $html .= '<a href="server_binlog.php'
169 . PMA_URL_getCommon($this_url_params) . '"';
170 if (PMA_Util
::showIcons('TableNavigationLinksMode')) {
171 $html .= ' title="' . _pgettext('Previous page', 'Previous') . '">';
173 $html .= '>' . _pgettext('Previous page', 'Previous');
174 } // end if... else...
175 $html .= ' < </a> - ';
178 $this_url_params = $url_params;
180 $this_url_params['pos'] = $pos;
182 if ($dontlimitchars) {
183 unset($this_url_params['dontlimitchars']);
184 $tempTitle = __('Truncate Shown Queries');
185 $tempImgMode = 'partial';
187 $this_url_params['dontlimitchars'] = 1;
188 $tempTitle = __('Show Full Queries');
189 $tempImgMode = 'full';
191 $html .= '<a href="server_binlog.php' . PMA_URL_getCommon($this_url_params)
192 . '" title="' . $tempTitle . '">'
193 . '<img src="' .$GLOBALS['pmaThemeImage'] . 's_' . $tempImgMode . 'text.png"'
194 . 'alt="' . $tempTitle . '" /></a>';
196 // we do not now how much rows are in the binlog
197 // so we can just force 'NEXT' button
198 if ($num_rows >= $GLOBALS['cfg']['MaxRows']) {
199 $this_url_params = $url_params;
200 $this_url_params['pos'] = $pos +
$GLOBALS['cfg']['MaxRows'];
201 $html .= ' - <a href="server_binlog.php'
202 . PMA_URL_getCommon($this_url_params)
204 if (PMA_Util
::showIcons('TableNavigationLinksMode')) {
205 $html .= ' title="' . _pgettext('Next page', 'Next') . '">';
207 $html .= '>' . _pgettext('Next page', 'Next');
208 } // end if... else...
209 $html .= ' > </a>';
216 * Returns the html for all binary log items.
218 * @param resource $result MySQL Query result
219 * @param bool $dontlimitchars Whether limit chars
223 function PMA_getAllLogItemInfo($result, $dontlimitchars)
227 while ($value = $GLOBALS['dbi']->fetchAssoc($result)) {
228 $html .= '<tr class="noclick ' . ($odd_row ?
'odd' : 'even') . '">'
229 . '<td> ' . $value['Log_name'] . ' </td>'
230 . '<td class="right"> ' . $value['Pos'] . ' </td>'
231 . '<td> ' . $value['Event_type'] . ' </td>'
232 . '<td class="right"> ' . $value['Server_id'] . ' </td>'
233 . '<td class="right"> '
234 . (isset($value['Orig_log_pos'])
235 ?
$value['Orig_log_pos'] : $value['End_log_pos'])
237 . '<td> ' . PMA_Util
::formatSql($value['Info'], ! $dontlimitchars)
238 . ' </td></tr>';
240 $odd_row = !$odd_row;