Clear display on session timeout even when unsaved changes are pending.
[openemr.git] / phpmyadmin / libraries / server_status_processes.lib.php
bloba5cdf73e7731847543e29d463122771623ec2d38
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 auto refreshing processes list
18 * @return string
20 function PMA_getHtmlForProcessListAutoRefresh()
22 $notice = PMA_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 .= PMA_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 .= PMA_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' . PMA_URL_getCommon(
56 array(), 'html', '?'
58 } else {
59 $full_text_link = 'server_status_processes.php' . PMA_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 if (PMA_DRIZZLE) {
107 $left_str = 'left(p.info, '
108 . (int)$GLOBALS['cfg']['MaxCharactersInDisplayedSQL'] . ')';
109 $sql_query = "SELECT
110 p.id AS Id,
111 p.username AS User,
112 p.host AS Host,
113 p.db AS db,
114 p.command AS Command,
115 p.time AS Time,
116 p.state AS State,"
117 . ($show_full_sql ? 's.query' : $left_str )
118 . " AS Info FROM data_dictionary.PROCESSLIST p "
119 . ($show_full_sql
120 ? 'LEFT JOIN data_dictionary.SESSIONS s ON s.session_id = p.id'
121 : '');
122 if (! empty($_REQUEST['showExecuting'])) {
123 $sql_query .= ' WHERE p.state = "executing" ';
125 if (! empty($_REQUEST['order_by_field'])
126 && ! empty($_REQUEST['sort_order'])
128 $sql_query .= ' ORDER BY p.' . $_REQUEST['order_by_field'] . ' '
129 . $_REQUEST['sort_order'];
131 } else {
132 $sql_query = $show_full_sql
133 ? 'SHOW FULL PROCESSLIST'
134 : 'SHOW PROCESSLIST';
135 if ((! empty($_REQUEST['order_by_field'])
136 && ! empty($_REQUEST['sort_order']))
137 || (! empty($_REQUEST['showExecuting']))
139 $sql_query = 'SELECT * FROM `INFORMATION_SCHEMA`.`PROCESSLIST` ';
141 if (! empty($_REQUEST['showExecuting'])) {
142 $sql_query .= ' WHERE state = "executing" ';
144 if (!empty($_REQUEST['order_by_field']) && !empty($_REQUEST['sort_order'])) {
145 $sql_query .= ' ORDER BY '
146 . PMA_Util::backquote($_REQUEST['order_by_field'])
147 . ' ' . $_REQUEST['sort_order'];
151 $result = $GLOBALS['dbi']->query($sql_query);
153 $retval = '<table id="tableprocesslist" '
154 . 'class="data clearfloat noclick sortable">';
155 $retval .= '<thead>';
156 $retval .= '<tr>';
157 $retval .= '<th>' . __('Processes') . '</th>';
158 foreach ($sortable_columns as $column) {
160 $is_sorted = ! empty($_REQUEST['order_by_field'])
161 && ! empty($_REQUEST['sort_order'])
162 && ($_REQUEST['order_by_field'] == $column['order_by_field']);
164 $column['sort_order'] = 'ASC';
165 if ($is_sorted && $_REQUEST['sort_order'] === 'ASC') {
166 $column['sort_order'] = 'DESC';
169 $retval .= '<th>';
170 $columnUrl = PMA_URL_getCommon($column);
171 $retval .= '<a href="server_status_processes.php' . $columnUrl . '" ';
172 if ($is_sorted) {
173 $retval .= 'onmouseout="$(\'.soimg\').toggle()" '
174 . 'onmouseover="$(\'.soimg\').toggle()"';
176 $retval .= '>';
178 $retval .= $column['column_name'];
180 if ($is_sorted) {
181 $asc_display_style = 'inline';
182 $desc_display_style = 'none';
183 if ($_REQUEST['sort_order'] === 'DESC') {
184 $desc_display_style = 'inline';
185 $asc_display_style = 'none';
187 $retval .= '<img class="icon ic_s_desc soimg" alt="'
188 . __('Descending') . '" title="" src="themes/dot.gif" '
189 . 'style="display: ' . $desc_display_style . '" />';
190 $retval .= '<img class="icon ic_s_asc soimg hide" alt="'
191 . __('Ascending') . '" title="" src="themes/dot.gif" '
192 . 'style="display: ' . $asc_display_style . '" />';
195 $retval .= '</a>';
197 if (! PMA_DRIZZLE && (0 === --$sortableColCount)) {
198 $retval .= '<a href="' . $full_text_link . '">';
199 if ($show_full_sql) {
200 $retval .= PMA_Util::getImage(
201 's_partialtext.png',
202 __('Truncate Shown Queries')
204 } else {
205 $retval .= PMA_Util::getImage(
206 's_fulltext.png',
207 __('Show Full Queries')
210 $retval .= '</a>';
212 $retval .= '</th>';
215 $retval .= '</tr>';
216 $retval .= '</thead>';
217 $retval .= '<tbody>';
219 $odd_row = true;
220 while ($process = $GLOBALS['dbi']->fetchAssoc($result)) {
221 $retval .= PMA_getHtmlForServerProcessItem(
222 $process,
223 $odd_row,
224 $show_full_sql
226 $odd_row = ! $odd_row;
228 $retval .= '</tbody>';
229 $retval .= '</table>';
231 return $retval;
235 * Returns the html for the list filter
237 * @return string
239 function PMA_getHtmlForProcessListFilter()
241 $showExecuting = '';
242 if (! empty($_REQUEST['showExecuting'])) {
243 $showExecuting = ' checked="checked"';
246 $url_params = array(
247 'ajax_request' => true
250 $retval = '';
251 $retval .= '<fieldset id="tableFilter">';
252 $retval .= '<legend>' . __('Filters') . '</legend>';
253 $retval .= '<form action="server_status_processes.php'
254 . PMA_URL_getCommon($url_params) . '">';
255 $retval .= '<input type="submit" value="' . __('Refresh') . '" />';
256 $retval .= '<div class="formelement">';
257 $retval .= '<input' . $showExecuting . ' type="checkbox" name="showExecuting"'
258 . ' id="showExecuting" class="autosubmit"/>';
259 $retval .= '<label for="showExecuting">';
260 $retval .= __('Show only active');
261 $retval .= '</label>';
262 $retval .= '</div>';
263 $retval .= '</form>';
264 $retval .= '</fieldset>';
266 return $retval;
270 * Prints Every Item of Server Process
272 * @param Array $process data of Every Item of Server Process
273 * @param bool $odd_row display odd row or not
274 * @param bool $show_full_sql show full sql or not
276 * @return string
278 function PMA_getHtmlForServerProcessItem($process, $odd_row, $show_full_sql)
280 // Array keys need to modify due to the way it has used
281 // to display column values
282 if ((! empty($_REQUEST['order_by_field']) && ! empty($_REQUEST['sort_order']))
283 || (! empty($_REQUEST['showExecuting']))
285 foreach (array_keys($process) as $key) {
286 $new_key = ucfirst(/*overload*/mb_strtolower($key));
287 if ($new_key !== $key) {
288 $process[$new_key] = $process[$key];
289 unset($process[$key]);
294 $url_params = array(
295 'kill' => $process['Id'],
296 'ajax_request' => true
298 $kill_process = 'server_status_processes.php' . PMA_URL_getCommon($url_params);
300 $retval = '<tr class="' . ($odd_row ? 'odd' : 'even') . '">';
301 $retval .= '<td><a class="ajax kill_process" href="' . $kill_process . '">'
302 . __('Kill') . '</a></td>';
303 $retval .= '<td class="value">' . $process['Id'] . '</td>';
304 $retval .= '<td>' . htmlspecialchars($process['User']) . '</td>';
305 $retval .= '<td>' . htmlspecialchars($process['Host']) . '</td>';
306 $retval .= '<td>' . ((! isset($process['db'])
307 || !/*overload*/mb_strlen($process['db']))
308 ? '<i>' . __('None') . '</i>'
309 : htmlspecialchars($process['db'])) . '</td>';
310 $retval .= '<td>' . htmlspecialchars($process['Command']) . '</td>';
311 $retval .= '<td class="value">' . $process['Time'] . '</td>';
312 $processStatusStr = empty($process['State']) ? '---' : $process['State'];
313 $retval .= '<td>' . $processStatusStr . '</td>';
314 $processProgress = empty($process['Progress']) ? '---' : $process['Progress'];
315 $retval .= '<td>' . $processProgress . '</td>';
316 $retval .= '<td>';
318 if (empty($process['Info'])) {
319 $retval .= '---';
320 } else {
321 $retval .= PMA_Util::formatSql($process['Info'], ! $show_full_sql);
323 $retval .= '</td>';
324 $retval .= '</tr>';
326 return $retval;