Merge pull request #431 from xmujay/0609_monitor
[phpmyadmin/aamir.git] / libraries / server_bin_log.lib.php
bloba1dcdfc585caa6dccce397c6dab15dfaf82c07c6
1 <?php
2 /* vim: set expandtab sw=4 ts=4 sts=4: */
4 /**
5 * functions for displaying server binary log
7 * @usedby server_binlog.php
8 *
9 * @package PhpMyAdmin
11 if (! defined('PHPMYADMIN')) {
12 exit;
15 /**
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
22 * @return string
24 function PMA_getLogSelector($binary_log_file_names, $url_params)
26 $html = "";
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">';
33 $full_size = 0;
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'];
42 $html .= ' ('
43 . implode(
44 ' ',
45 PMA_Util::formatByteDown(
46 $each_log['File_size'], 3, 2
49 . ')';
51 $html .= '</option>';
53 $html .= '</select> ';
54 $html .= count($binary_log_file_names) . ' ' . __('Files') . ', ';
55 if ($full_size > 0) {
56 $html .= implode(
57 ' ', PMA_Util::formatByteDown($full_size)
60 $html .= '</fieldset>';
61 $html .= '<fieldset class="tblFooters">';
62 $html .= '<input type="submit" value="' . __('Go') . '" />';
63 $html .= '</fieldset>';
64 $html .= '</form>';
67 return $html;
70 /**
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
77 * @return string
79 function PMA_getLogInfo($binary_log_file_names, $url_params)
81 /**
82 * Need to find the real end of rows?
84 if (! isset($_REQUEST['pos'])) {
85 $pos = 0;
86 } else {
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'];
99 /**
100 * Sends the query
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);
110 } else {
111 $num_rows = 0;
114 if (empty($_REQUEST['dontlimitchars'])) {
115 $dontlimitchars = false;
116 } else {
117 $dontlimitchars = true;
118 $url_params['dontlimitchars'] = 1;
121 //html output
122 $html = PMA_Util::getMessage(PMA_Message::success(), $sql_query);
123 $html .= '<table cellpadding="2" cellspacing="1" id="binlogTable">'
124 . '<thead>'
125 . '<tr>'
126 . '<td colspan="6" class="center">';
128 $html .= PMA_getNavigationRow($url_params, $pos, $num_rows, $dontlimitchars);
130 $html .= '</td>'
131 . '</tr>'
132 . '<tr>'
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>'
139 . '</tr>'
140 . '</thead>'
141 . '<tbody>';
143 $html .= PMA_getAllLogItemInfo($result, $dontlimitchars);
145 $html .= '</tbody>'
146 . '</table>';
148 return $html;
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
162 * @return string
164 function PMA_getNavigationRow($url_params, $pos, $num_rows, $dontlimitchars)
166 $html = "";
167 // we do not know how much rows are in the binlog
168 // so we can just force 'NEXT' button
169 if ($pos > 0) {
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') . '">';
179 } else {
180 $html .= '>' . _pgettext('Previous page', 'Previous');
181 } // end if... else...
182 $html .= ' &lt; </a> - ';
185 $this_url_params = $url_params;
186 if ($pos > 0) {
187 $this_url_params['pos'] = $pos;
189 if ($dontlimitchars) {
190 unset($this_url_params['dontlimitchars']);
191 $tempTitle = __('Truncate Shown Queries');
192 $tempImgMode = 'partial';
193 } else {
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)
210 . '"';
211 if ($GLOBALS['cfg']['NavigationBarIconic']) {
212 $html .= ' title="' . _pgettext('Next page', 'Next') . '">';
213 } else {
214 $html .= '>' . _pgettext('Next page', 'Next');
215 } // end if... else...
216 $html .= ' &gt; </a>';
219 return $html;
223 * Returns the html for all binary log items.
225 * @param resource $result MySQL Query result
227 * @param bool $dontlimitchars Whether limit chars
229 * @return string
231 function PMA_getAllLogItemInfo($result, $dontlimitchars)
233 $html = "";
234 $odd_row = true;
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']
241 ) . '...';
244 $html .= '<tr class="noclick ' . ($odd_row ? 'odd' : 'even') . '">'
245 . '<td>&nbsp;' . $value['Log_name'] . '&nbsp;</td>'
246 . '<td class="right">&nbsp;' . $value['Pos'] . '&nbsp;</td>'
247 . '<td>&nbsp;' . $value['Event_type'] . '&nbsp;</td>'
248 . '<td class="right">&nbsp;' . $value['Server_id'] . '&nbsp;</td>'
249 . '<td class="right">&nbsp;'
250 . (isset($value['Orig_log_pos'])
251 ? $value['Orig_log_pos'] : $value['End_log_pos'])
252 . '&nbsp;</td>'
253 . '<td><code class="sql"><pre>&nbsp;' . htmlspecialchars($value['Info'])
254 . '&nbsp;</pre></code></td>'
255 . '</tr>';
257 $odd_row = !$odd_row;
259 return $html;