2 /* vim: set expandtab sw=4 ts=4 sts=4: */
5 * functions for displaying processes list
7 * @usedby server_status_processes.php
11 if (! defined('PHPMYADMIN')) {
16 * Prints html for server status processes
20 function PMA_getHtmlForServerProcesses()
22 $retval = PMA_getHtmlForServerProcesslist();
24 $notice = PMA_Message
::notice(
26 'Note: Enabling the auto refresh here might cause '
27 . 'heavy traffic between the web server and the MySQL server.'
30 $retval .= $notice . '<div class="tabLinks">';
31 $retval .= '<label>' . __('Refresh rate') . ': ';
32 $retval .= PMA_ServerStatusData
::getHtmlForRefreshList(
35 Array(2, 3, 4, 5, 10, 20, 40, 60, 120, 300, 600, 1200)
37 $retval .= '</label>';
38 $retval .= '<a id="toggleRefresh" href="#">';
39 $retval .= PMA_Util
::getImage('play.png') . __('Start auto refresh');
46 * Prints Server Process list
50 function PMA_getHtmlForServerProcesslist()
52 $url_params = array();
54 $show_full_sql = ! empty($_REQUEST['full']);
56 $url_params['full'] = 1;
57 $full_text_link = 'server_status_processes.php' . PMA_URL_getCommon(
61 $full_text_link = 'server_status_processes.php' . PMA_URL_getCommon(
66 // This array contains display name and real column name of each
67 // sortable column in the table
68 $sortable_columns = array(
70 'column_name' => __('ID'),
71 'order_by_field' => 'Id'
74 'column_name' => __('User'),
75 'order_by_field' => 'User'
78 'column_name' => __('Host'),
79 'order_by_field' => 'Host'
82 'column_name' => __('Database'),
83 'order_by_field' => 'db'
86 'column_name' => __('Command'),
87 'order_by_field' => 'Command'
90 'column_name' => __('Time'),
91 'order_by_field' => 'Time'
94 'column_name' => __('Status'),
95 'order_by_field' => 'State'
98 'column_name' => __('SQL query'),
99 'order_by_field' => 'Info'
102 $sortableColCount = count($sortable_columns);
105 $left_str = 'left(p.info, '
106 . (int)$GLOBALS['cfg']['MaxCharactersInDisplayedSQL'] . ')';
112 p.command AS Command,
115 . ($show_full_sql ?
's.query' : $left_str )
116 . " AS Info FROM data_dictionary.PROCESSLIST p "
118 ?
'LEFT JOIN data_dictionary.SESSIONS s ON s.session_id = p.id'
120 if (! empty($_REQUEST['order_by_field'])
121 && ! empty($_REQUEST['sort_order'])
123 $sql_query .= ' ORDER BY p.' . $_REQUEST['order_by_field'] . ' '
124 . $_REQUEST['sort_order'];
127 $sql_query = $show_full_sql
128 ?
'SHOW FULL PROCESSLIST'
129 : 'SHOW PROCESSLIST';
130 if ((! empty($_REQUEST['order_by_field'])
131 && ! empty($_REQUEST['sort_order']))
132 ||
(! empty($_REQUEST['showExecuting']))
134 $sql_query = 'SELECT * FROM `INFORMATION_SCHEMA`.`PROCESSLIST` ';
136 if (! empty($_REQUEST['showExecuting'])) {
137 $sql_query .= ' WHERE state = "executing" ';
139 if (! empty($_REQUEST['order_by_field']) && ! empty($_REQUEST['sort_order'])) {
140 $sql_query .= ' ORDER BY '
141 . PMA_Util
::backquote($_REQUEST['order_by_field'])
142 . ' ' . $_REQUEST['sort_order'];
146 $result = $GLOBALS['dbi']->query($sql_query);
148 $retval = '<table id="tableprocesslist" '
149 . 'class="data clearfloat noclick sortable">';
150 $retval .= '<thead>';
152 $retval .= '<th>' . __('Processes') . '</th>';
153 foreach ($sortable_columns as $column) {
155 $is_sorted = ! empty($_REQUEST['order_by_field'])
156 && ! empty($_REQUEST['sort_order'])
157 && ($_REQUEST['order_by_field'] == $column['order_by_field']);
159 $column['sort_order'] = 'ASC';
160 if ($is_sorted && $_REQUEST['sort_order'] === 'ASC') {
161 $column['sort_order'] = 'DESC';
165 $columnUrl = PMA_URL_getCommon($column);
166 $retval .= '<a href="server_status_processes.php' . $columnUrl . '" ';
168 $retval .= 'onmouseout="$(\'.soimg\').toggle()" '
169 . 'onmouseover="$(\'.soimg\').toggle()"';
173 $retval .= $column['column_name'];
176 $asc_display_style = 'inline';
177 $desc_display_style = 'none';
178 if ($_REQUEST['sort_order'] === 'DESC') {
179 $desc_display_style = 'inline';
180 $asc_display_style = 'none';
182 $retval .= '<img class="icon ic_s_desc soimg" alt="'
183 . __('Descending') . '" title="" src="themes/dot.gif" '
184 . 'style="display: ' . $desc_display_style . '" />';
185 $retval .= '<img class="icon ic_s_asc soimg hide" alt="'
186 . __('Ascending') . '" title="" src="themes/dot.gif" '
187 . 'style="display: ' . $asc_display_style . '" />';
192 if (! PMA_DRIZZLE
&& (0 === --$sortableColCount)) {
193 $retval .= '<a href="' . $full_text_link . '">';
194 if ($show_full_sql) {
195 $retval .= PMA_Util
::getImage(
197 __('Truncate Shown Queries')
200 $retval .= PMA_Util
::getImage(
202 __('Show Full Queries')
211 $retval .= '</thead>';
212 $retval .= '<tbody>';
215 while ($process = $GLOBALS['dbi']->fetchAssoc($result)) {
216 $retval .= PMA_getHtmlForServerProcessItem(
221 $odd_row = ! $odd_row;
223 $retval .= '</tbody>';
224 $retval .= '</table>';
230 * Returns the html for the list filter
234 function PMA_getHtmlForProcessListFilter()
237 if (! empty($_REQUEST['showExecuting'])) {
238 $showExecuting = ' checked="checked"';
242 'showExecuting' => 1,
243 'ajax_request' => true
247 $retval .= '<fieldset id="tableFilter">';
248 $retval .= '<legend>' . __('Filters') . '</legend>';
249 $retval .= '<form action="server_status_processes.php?'
250 . PMA_URL_getCommon($url_params) . '">';
251 $retval .= '<input type="submit" value="' . __('Refresh') . '" />';
252 $retval .= '<div class="formelement">';
253 $retval .= '<input' . $showExecuting . ' type="checkbox" name="showExecuting"'
254 . ' id="showExecuting" class="autosubmit"/>';
255 $retval .= '<label for="showExecuting">';
256 $retval .= __('Show only active');
257 $retval .= '</label>';
259 $retval .= '</form>';
260 $retval .= '</fieldset>';
266 * Prints Every Item of Server Process
268 * @param Array $process data of Every Item of Server Process
269 * @param bool $odd_row display odd row or not
270 * @param bool $show_full_sql show full sql or not
274 function PMA_getHtmlForServerProcessItem($process, $odd_row, $show_full_sql)
276 // Array keys need to modify due to the way it has used
277 // to display column values
278 if ((! empty($_REQUEST['order_by_field']) && ! empty($_REQUEST['sort_order']))
279 ||
(! empty($_REQUEST['showExecuting']))
281 foreach (array_keys($process) as $key) {
282 $new_key = ucfirst(/*overload*/mb_strtolower($key));
283 if ($new_key !== $key) {
284 $process[$new_key] = $process[$key];
285 unset($process[$key]);
291 'kill' => $process['Id'],
292 'ajax_request' => true
294 $kill_process = 'server_status_processes.php' . PMA_URL_getCommon($url_params);
296 $retval = '<tr class="' . ($odd_row ?
'odd' : 'even') . '">';
297 $retval .= '<td><a class="ajax kill_process" href="' . $kill_process . '">'
298 . __('Kill') . '</a></td>';
299 $retval .= '<td class="value">' . $process['Id'] . '</td>';
300 $retval .= '<td>' . htmlspecialchars($process['User']) . '</td>';
301 $retval .= '<td>' . htmlspecialchars($process['Host']) . '</td>';
302 $retval .= '<td>' . ((! isset($process['db'])
303 ||
!/*overload*/mb_strlen($process['db']))
304 ?
'<i>' . __('None') . '</i>'
305 : htmlspecialchars($process['db'])) . '</td>';
306 $retval .= '<td>' . htmlspecialchars($process['Command']) . '</td>';
307 $retval .= '<td class="value">' . $process['Time'] . '</td>';
308 $processStatusStr = empty($process['State']) ?
'---' : $process['State'];
309 $retval .= '<td>' . $processStatusStr . '</td>';
312 if (empty($process['Info'])) {
315 $retval .= PMA_Util
::formatSql($process['Info'], ! $show_full_sql);