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
20 * @param Array $url_params links parameters
24 function PMA_getLogSelector($binary_log_file_names, $url_params)
27 if (count($binary_log_file_names) > 1) {
28 $html .= '<form action="server_binlog.php" method="get">';
29 $html .= PMA_generate_common_hidden_inputs($url_params);
30 $html .= '<fieldset><legend>';
31 $html .= __('Select binary log to view');
32 $html .= '</legend><select name="log">';
34 foreach ($binary_log_file_names as $each_log) {
35 $html .= '<option value="' . $each_log['Log_name'] . '"';
36 if ($each_log['Log_name'] == $_REQUEST['log']) {
37 $html .= ' selected="selected"';
39 $html .= '>' . $each_log['Log_name'];
40 if (isset($each_log['File_size'])) {
41 $full_size +
= $each_log['File_size'];
45 PMA_Util
::formatByteDown(
46 $each_log['File_size'], 3, 2
53 $html .= '</select> ';
54 $html .= count($binary_log_file_names) . ' ' . __('Files') . ', ';
57 ' ', PMA_Util
::formatByteDown($full_size)
60 $html .= '</fieldset>';
61 $html .= '<fieldset class="tblFooters">';
62 $html .= '<input type="submit" value="' . __('Go') . '" />';
63 $html .= '</fieldset>';
71 * Returns the html for binary log information.
73 * @param Array $binary_log_file_names Binary logs file names
75 * @param Array $url_params links parameters
79 function PMA_getLogInfo($binary_log_file_names, $url_params)
82 * Need to find the real end of rows?
84 if (! isset($_REQUEST['pos'])) {
87 /* We need this to be a integer */
88 $pos = (int) $_REQUEST['pos'];
91 $sql_query = 'SHOW BINLOG EVENTS';
92 if (! empty($_REQUEST['log'])) {
93 $sql_query .= ' IN \'' . $_REQUEST['log'] . '\'';
95 if ($GLOBALS['cfg']['MaxRows'] !== 'all') {
96 $sql_query .= ' LIMIT ' . $pos . ', ' . (int) $GLOBALS['cfg']['MaxRows'];
102 $result = $GLOBALS['dbi']->query($sql_query);
105 * prepare some vars for displaying the result table
107 // Gets the list of fields properties
108 if (isset($result) && $result) {
109 $num_rows = $GLOBALS['dbi']->numRows($result);
114 if (empty($_REQUEST['dontlimitchars'])) {
115 $dontlimitchars = false;
117 $dontlimitchars = true;
118 $url_params['dontlimitchars'] = 1;
122 $html = PMA_Util
::getMessage(PMA_Message
::success(), $sql_query);
123 $html .= '<table cellpadding="2" cellspacing="1" id="binlogTable">'
126 . '<td colspan="6" class="center">';
128 $html .= PMA_getNavigationRow($url_params, $pos, $num_rows, $dontlimitchars);
133 . '<th>' . __('Log name') . '</th>'
134 . '<th>' . __('Position') . '</th>'
135 . '<th>' . __('Event type') . '</th>'
136 . '<th>' . __('Server ID') . '</th>'
137 . '<th>' . __('Original position') . '</th>'
138 . '<th>' . __('Information') . '</th>'
143 $html .= PMA_getAllLogItemInfo($result, $dontlimitchars);
152 * Returns the html for Navigation Row.
154 * @param Array $url_params Links parameters
156 * @param int $pos Position to display
158 * @param int $num_rows Number of results row
160 * @param bool $dontlimitchars Whether limit chars
164 function PMA_getNavigationRow($url_params, $pos, $num_rows, $dontlimitchars)
167 // we do not know how much rows are in the binlog
168 // so we can just force 'NEXT' button
170 $this_url_params = $url_params;
171 if ($pos > $GLOBALS['cfg']['MaxRows']) {
172 $this_url_params['pos'] = $pos - $GLOBALS['cfg']['MaxRows'];
175 $html .= '<a href="server_binlog.php'
176 . PMA_generate_common_url($this_url_params) . '"';
177 if ($GLOBALS['cfg']['NavigationBarIconic']) {
178 $html .= ' title="' . _pgettext('Previous page', 'Previous') . '">';
180 $html .= '>' . _pgettext('Previous page', 'Previous');
181 } // end if... else...
182 $html .= ' < </a> - ';
185 $this_url_params = $url_params;
187 $this_url_params['pos'] = $pos;
189 if ($dontlimitchars) {
190 unset($this_url_params['dontlimitchars']);
191 $tempTitle = __('Truncate Shown Queries');
192 $tempImgMode = 'partial';
194 $this_url_params['dontlimitchars'] = 1;
195 $tempTitle = __('Show Full Queries');
196 $tempImgMode = 'full';
198 $html .= '<a href="server_binlog.php' . PMA_generate_common_url($this_url_params)
199 . '" title="' . $tempTitle . '">'
200 . '<img src="' .$GLOBALS['pmaThemeImage'] . 's_' . $tempImgMode . 'text.png"'
201 . 'alt="' . $tempTitle . '" /></a>';
203 // we do not now how much rows are in the binlog
204 // so we can just force 'NEXT' button
205 if ($num_rows >= $GLOBALS['cfg']['MaxRows']) {
206 $this_url_params = $url_params;
207 $this_url_params['pos'] = $pos +
$GLOBALS['cfg']['MaxRows'];
208 $html .= ' - <a href="server_binlog.php'
209 . PMA_generate_common_url($this_url_params)
211 if ($GLOBALS['cfg']['NavigationBarIconic']) {
212 $html .= ' title="' . _pgettext('Next page', 'Next') . '">';
214 $html .= '>' . _pgettext('Next page', 'Next');
215 } // end if... else...
216 $html .= ' > </a>';
223 * Returns the html for all binary log items.
225 * @param resource $result MySQL Query result
227 * @param bool $dontlimitchars Whether limit chars
231 function PMA_getAllLogItemInfo($result, $dontlimitchars)
235 while ($value = $GLOBALS['dbi']->fetchAssoc($result)) {
236 if (! $dontlimitchars
237 && PMA_strlen($value['Info']) > $GLOBALS['cfg']['LimitChars']
239 $value['Info'] = PMA_substr(
240 $value['Info'], 0, $GLOBALS['cfg']['LimitChars']
244 $html .= '<tr class="noclick ' . ($odd_row ?
'odd' : 'even') . '">'
245 . '<td> ' . $value['Log_name'] . ' </td>'
246 . '<td class="right"> ' . $value['Pos'] . ' </td>'
247 . '<td> ' . $value['Event_type'] . ' </td>'
248 . '<td class="right"> ' . $value['Server_id'] . ' </td>'
249 . '<td class="right"> '
250 . (isset($value['Orig_log_pos'])
251 ?
$value['Orig_log_pos'] : $value['End_log_pos'])
253 . '<td><code class="sql"><pre> ' . htmlspecialchars($value['Info'])
254 . ' </pre></code></td>'
257 $odd_row = !$odd_row;