Translated using Weblate (Slovenian)
[phpmyadmin.git] / libraries / server_status_processes.lib.php
blob7d31c582f44e889b15ade936023c80e8512314ec
1 <?php
2 /* vim: set expandtab sw=4 ts=4 sts=4: */
3 /**
4 * functions for displaying processes list
6 * @usedby server_status_processes.php
8 * @package PhpMyAdmin
9 */
10 use PMA\libraries\Message;
11 use PMA\libraries\ServerStatusData;
12 use PMA\libraries\Util;
13 use PMA\libraries\URL;
15 /**
16 * Prints html for auto refreshing processes list
18 * @return string
20 function PMA_getHtmlForProcessListAutoRefresh()
22 $notice = Message::notice(
23 __(
24 'Note: Enabling the auto refresh here might cause '
25 . 'heavy traffic between the web server and the MySQL server.'
27 )->getDisplay();
28 $retval = $notice . '<div class="tabLinks">';
29 $retval .= '<label>' . __('Refresh rate') . ': ';
30 $retval .= ServerStatusData::getHtmlForRefreshList(
31 'refreshRate',
33 Array(2, 3, 4, 5, 10, 20, 40, 60, 120, 300, 600, 1200)
35 $retval .= '</label>';
36 $retval .= '<a id="toggleRefresh" href="#">';
37 $retval .= Util::getImage('play.png') . __('Start auto refresh');
38 $retval .= '</a>';
39 $retval .= '</div>';
40 return $retval;
43 /**
44 * Prints Server Process list
46 * @return string
48 function PMA_getHtmlForServerProcesslist()
50 $url_params = array();
52 $show_full_sql = ! empty($_REQUEST['full']);
53 if ($show_full_sql) {
54 $url_params['full'] = 1;
55 $full_text_link = 'server_status_processes.php' . URL::getCommon(
56 array(), '?'
58 } else {
59 $full_text_link = 'server_status_processes.php' . URL::getCommon(
60 array('full' => 1)
64 // This array contains display name and real column name of each
65 // sortable column in the table
66 $sortable_columns = array(
67 array(
68 'column_name' => __('ID'),
69 'order_by_field' => 'Id'
71 array(
72 'column_name' => __('User'),
73 'order_by_field' => 'User'
75 array(
76 'column_name' => __('Host'),
77 'order_by_field' => 'Host'
79 array(
80 'column_name' => __('Database'),
81 'order_by_field' => 'db'
83 array(
84 'column_name' => __('Command'),
85 'order_by_field' => 'Command'
87 array(
88 'column_name' => __('Time'),
89 'order_by_field' => 'Time'
91 array(
92 'column_name' => __('Status'),
93 'order_by_field' => 'State'
95 array(
96 'column_name' => __('Progress'),
97 'order_by_field' => 'Progress'
99 array(
100 'column_name' => __('SQL query'),
101 'order_by_field' => 'Info'
104 $sortableColCount = count($sortable_columns);
106 $sql_query = $show_full_sql
107 ? 'SHOW FULL PROCESSLIST'
108 : 'SHOW PROCESSLIST';
109 if ((! empty($_REQUEST['order_by_field'])
110 && ! empty($_REQUEST['sort_order']))
111 || (! empty($_REQUEST['showExecuting']))
113 $sql_query = 'SELECT * FROM `INFORMATION_SCHEMA`.`PROCESSLIST` ';
115 if (! empty($_REQUEST['showExecuting'])) {
116 $sql_query .= ' WHERE state != "" ';
118 if (!empty($_REQUEST['order_by_field']) && !empty($_REQUEST['sort_order'])) {
119 $sql_query .= ' ORDER BY '
120 . Util::backquote($_REQUEST['order_by_field'])
121 . ' ' . $_REQUEST['sort_order'];
124 $result = $GLOBALS['dbi']->query($sql_query);
126 $retval = '<table id="tableprocesslist" '
127 . 'class="data clearfloat noclick sortable">';
128 $retval .= '<thead>';
129 $retval .= '<tr>';
130 $retval .= '<th>' . __('Processes') . '</th>';
131 foreach ($sortable_columns as $column) {
133 $is_sorted = ! empty($_REQUEST['order_by_field'])
134 && ! empty($_REQUEST['sort_order'])
135 && ($_REQUEST['order_by_field'] == $column['order_by_field']);
137 $column['sort_order'] = 'ASC';
138 if ($is_sorted && $_REQUEST['sort_order'] === 'ASC') {
139 $column['sort_order'] = 'DESC';
141 if (isset($_REQUEST['showExecuting'])) {
142 $column['showExecuting'] = 'on';
145 $retval .= '<th>';
146 $columnUrl = URL::getCommon($column);
147 $retval .= '<a href="server_status_processes.php' . $columnUrl . '" ';
148 if ($is_sorted) {
149 $retval .= 'onmouseout="$(\'.soimg\').toggle()" '
150 . 'onmouseover="$(\'.soimg\').toggle()"';
152 $retval .= '>';
154 $retval .= $column['column_name'];
156 if ($is_sorted) {
157 $asc_display_style = 'inline';
158 $desc_display_style = 'none';
159 if ($_REQUEST['sort_order'] === 'DESC') {
160 $desc_display_style = 'inline';
161 $asc_display_style = 'none';
163 $retval .= '<img class="icon ic_s_desc soimg" alt="'
164 . __('Descending') . '" title="" src="themes/dot.gif" '
165 . 'style="display: ' . $desc_display_style . '" />';
166 $retval .= '<img class="icon ic_s_asc soimg hide" alt="'
167 . __('Ascending') . '" title="" src="themes/dot.gif" '
168 . 'style="display: ' . $asc_display_style . '" />';
171 $retval .= '</a>';
173 if (0 === --$sortableColCount) {
174 $retval .= '<a href="' . $full_text_link . '">';
175 if ($show_full_sql) {
176 $retval .= Util::getImage(
177 's_partialtext.png',
178 __('Truncate Shown Queries')
180 } else {
181 $retval .= Util::getImage(
182 's_fulltext.png',
183 __('Show Full Queries')
186 $retval .= '</a>';
188 $retval .= '</th>';
191 $retval .= '</tr>';
192 $retval .= '</thead>';
193 $retval .= '<tbody>';
195 while ($process = $GLOBALS['dbi']->fetchAssoc($result)) {
196 $retval .= PMA_getHtmlForServerProcessItem(
197 $process,
198 $show_full_sql
201 $retval .= '</tbody>';
202 $retval .= '</table>';
204 return $retval;
208 * Returns the html for the list filter
210 * @return string
212 function PMA_getHtmlForProcessListFilter()
214 $showExecuting = '';
215 if (! empty($_REQUEST['showExecuting'])) {
216 $showExecuting = ' checked="checked"';
219 $url_params = array(
220 'ajax_request' => true,
221 'full' => (isset($_REQUEST['full']) ? $_REQUEST['full'] : ''),
222 'column_name' => (isset($_REQUEST['column_name']) ? $_REQUEST['column_name'] : ''),
223 'order_by_field'
224 => (isset($_REQUEST['order_by_field']) ? $_REQUEST['order_by_field'] : ''),
225 'sort_order' => (isset($_REQUEST['sort_order']) ? $_REQUEST['sort_order'] : ''),
228 $retval = '';
229 $retval .= '<fieldset id="tableFilter">';
230 $retval .= '<legend>' . __('Filters') . '</legend>';
231 $retval .= '<form action="server_status_processes.php'
232 . URL::getCommon($url_params) . '">';
233 $retval .= '<input type="submit" value="' . __('Refresh') . '" />';
234 $retval .= '<div class="formelement">';
235 $retval .= '<input' . $showExecuting . ' type="checkbox" name="showExecuting"'
236 . ' id="showExecuting" class="autosubmit"/>';
237 $retval .= '<label for="showExecuting">';
238 $retval .= __('Show only active');
239 $retval .= '</label>';
240 $retval .= '</div>';
241 $retval .= '</form>';
242 $retval .= '</fieldset>';
244 return $retval;
248 * Prints Every Item of Server Process
250 * @param array $process data of Every Item of Server Process
251 * @param bool $show_full_sql show full sql or not
253 * @return string
255 function PMA_getHtmlForServerProcessItem($process, $show_full_sql)
257 // Array keys need to modify due to the way it has used
258 // to display column values
259 if ((! empty($_REQUEST['order_by_field']) && ! empty($_REQUEST['sort_order']))
260 || (! empty($_REQUEST['showExecuting']))
262 foreach (array_keys($process) as $key) {
263 $new_key = ucfirst(mb_strtolower($key));
264 if ($new_key !== $key) {
265 $process[$new_key] = $process[$key];
266 unset($process[$key]);
271 $url_params = array(
272 'kill' => $process['Id'],
273 'ajax_request' => true
275 $kill_process = 'server_status_processes.php' . URL::getCommon($url_params);
277 $retval = '<tr>';
278 $retval .= '<td><a class="ajax kill_process" href="' . $kill_process . '">'
279 . __('Kill') . '</a></td>';
280 $retval .= '<td class="value">' . $process['Id'] . '</td>';
281 $retval .= '<td>' . htmlspecialchars($process['User']) . '</td>';
282 $retval .= '<td>' . htmlspecialchars($process['Host']) . '</td>';
283 $retval .= '<td>' . ((! isset($process['db'])
284 || strlen($process['db']) === 0)
285 ? '<i>' . __('None') . '</i>'
286 : htmlspecialchars($process['db'])) . '</td>';
287 $retval .= '<td>' . htmlspecialchars($process['Command']) . '</td>';
288 $retval .= '<td class="value">' . $process['Time'] . '</td>';
289 $processStatusStr = empty($process['State']) ? '---' : $process['State'];
290 $retval .= '<td>' . $processStatusStr . '</td>';
291 $processProgress = empty($process['Progress']) ? '---' : $process['Progress'];
292 $retval .= '<td>' . $processProgress . '</td>';
293 $retval .= '<td>';
295 if (empty($process['Info'])) {
296 $retval .= '---';
297 } else {
298 $retval .= Util::formatSql($process['Info'], ! $show_full_sql);
300 $retval .= '</td>';
301 $retval .= '</tr>';
303 return $retval;