Translated using Weblate (Slovenian)
[phpmyadmin.git] / libraries / server_status_processes.lib.php
blobc773d48d6dbf163d6ee0d76267deef55d8936a63
1 <?php
2 /* vim: set expandtab sw=4 ts=4 sts=4: */
4 /**
5 * functions for displaying processes list
7 * @usedby server_status_processes.php
9 * @package PhpMyAdmin
11 if (! defined('PHPMYADMIN')) {
12 exit;
15 /**
16 * Prints html for server status processes
18 * @return string
20 function PMA_getHtmlForServerProcesses()
22 $retval = PMA_getHtmlForServerProcesslist();
24 $notice = PMA_Message::notice(
25 __(
26 'Note: Enabling the auto refresh here might cause '
27 . 'heavy traffic between the web server and the MySQL server.'
29 )->getDisplay();
30 $retval .= $notice . '<div class="tabLinks">';
31 $retval .= '<label>' . __('Refresh rate') . ': ';
32 $retval .= PMA_ServerStatusData::getHtmlForRefreshList(
33 'refreshRate',
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');
40 $retval .= '</a>';
41 $retval .= '</div>';
42 return $retval;
45 /**
46 * Prints Server Process list
48 * @return string
50 function PMA_getHtmlForServerProcesslist()
52 $url_params = array();
54 $show_full_sql = ! empty($_REQUEST['full']);
55 if ($show_full_sql) {
56 $url_params['full'] = 1;
57 $full_text_link = 'server_status_processes.php' . PMA_URL_getCommon(
58 array(), 'html', '?'
60 } else {
61 $full_text_link = 'server_status_processes.php' . PMA_URL_getCommon(
62 array('full' => 1)
66 // This array contains display name and real column name of each
67 // sortable column in the table
68 $sortable_columns = array(
69 array(
70 'column_name' => __('ID'),
71 'order_by_field' => 'Id'
73 array(
74 'column_name' => __('User'),
75 'order_by_field' => 'User'
77 array(
78 'column_name' => __('Host'),
79 'order_by_field' => 'Host'
81 array(
82 'column_name' => __('Database'),
83 'order_by_field' => 'db'
85 array(
86 'column_name' => __('Command'),
87 'order_by_field' => 'Command'
89 array(
90 'column_name' => __('Time'),
91 'order_by_field' => 'Time'
93 array(
94 'column_name' => __('Status'),
95 'order_by_field' => 'State'
97 array(
98 'column_name' => __('SQL query'),
99 'order_by_field' => 'Info'
102 $sortableColCount = count($sortable_columns);
104 if (PMA_DRIZZLE) {
105 $left_str = 'left(p.info, '
106 . (int)$GLOBALS['cfg']['MaxCharactersInDisplayedSQL'] . ')';
107 $sql_query = "SELECT
108 p.id AS Id,
109 p.username AS User,
110 p.host AS Host,
111 p.db AS db,
112 p.command AS Command,
113 p.time AS Time,
114 p.state AS State,"
115 . ($show_full_sql ? 's.query' : $left_str )
116 . " AS Info FROM data_dictionary.PROCESSLIST p "
117 . ($show_full_sql
118 ? 'LEFT JOIN data_dictionary.SESSIONS s ON s.session_id = p.id'
119 : '');
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'];
126 } else {
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>';
151 $retval .= '<tr>';
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';
164 $retval .= '<th>';
165 $columnUrl = PMA_URL_getCommon($column);
166 $retval .= '<a href="server_status_processes.php' . $columnUrl . '" ';
167 if ($is_sorted) {
168 $retval .= 'onmouseout="$(\'.soimg\').toggle()" '
169 . 'onmouseover="$(\'.soimg\').toggle()"';
171 $retval .= '>';
173 $retval .= $column['column_name'];
175 if ($is_sorted) {
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 . '" />';
190 $retval .= '</a>';
192 if (! PMA_DRIZZLE && (0 === --$sortableColCount)) {
193 $retval .= '<a href="' . $full_text_link . '">';
194 if ($show_full_sql) {
195 $retval .= PMA_Util::getImage(
196 's_partialtext.png',
197 __('Truncate Shown Queries')
199 } else {
200 $retval .= PMA_Util::getImage(
201 's_fulltext.png',
202 __('Show Full Queries')
205 $retval .= '</a>';
207 $retval .= '</th>';
210 $retval .= '</tr>';
211 $retval .= '</thead>';
212 $retval .= '<tbody>';
214 $odd_row = true;
215 while ($process = $GLOBALS['dbi']->fetchAssoc($result)) {
216 $retval .= PMA_getHtmlForServerProcessItem(
217 $process,
218 $odd_row,
219 $show_full_sql
221 $odd_row = ! $odd_row;
223 $retval .= '</tbody>';
224 $retval .= '</table>';
226 return $retval;
230 * Returns the html for the list filter
232 * @return string
234 function PMA_getHtmlForProcessListFilter()
236 $showExecuting = '';
237 if (! empty($_REQUEST['showExecuting'])) {
238 $showExecuting = ' checked="checked"';
241 $url_params = array(
242 'showExecuting' => 1,
243 'ajax_request' => true
246 $retval = '';
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>';
258 $retval .= '</div>';
259 $retval .= '</form>';
260 $retval .= '</fieldset>';
262 return $retval;
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
272 * @return string
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]);
290 $url_params = array(
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>';
310 $retval .= '<td>';
312 if (empty($process['Info'])) {
313 $retval .= '---';
314 } else {
315 $retval .= PMA_Util::formatSql($process['Info'], ! $show_full_sql);
317 $retval .= '</td>';
318 $retval .= '</tr>';
320 return $retval;