2 /* vim: set expandtab sw=4 ts=4 sts=4: */
4 * Used to render the console of PMA's pages
8 if (! defined('PHPMYADMIN')) {
12 require_once 'libraries/Scripts.class.php';
13 require_once 'libraries/Util.class.php';
14 require_once 'libraries/bookmark.lib.php';
17 * Class used to output the console
24 * Whether to display anything
32 * Creates a new class instance
34 public function __construct()
36 $this->_isEnabled
= true;
40 * Whether we are servicing an ajax request.
41 * We can't simply use $GLOBALS['is_ajax_request']
42 * here since it may have not been initialised yet.
50 * Set the ajax flag to indicate whether
51 * we are servicing an ajax request
53 * @param bool $isAjax Whether we are servicing an ajax request
57 public function setAjax($isAjax)
59 $this->_isAjax
= !!$isAjax;
63 * Disables the rendering of the footer
67 public function disable()
69 $this->_isEnabled
= false;
73 * Renders the bookmark content
78 public static function getBookmarkContent()
81 $cfgBookmark = PMA_Bookmark_getParams();
85 = '<span class="action collapse">' . __('Collapse') . '</span> '
86 . '<span class="action expand">' . __('Expand') . '</span> '
87 . '<span class="action requery">' . __('Requery') . '</span> '
88 . '<span class="action edit_bookmark">' . __('Edit') . '</span> '
89 . '<span class="action delete_bookmark">' . __('Delete')
91 . '<span class="text targetdb">' . __('Database')
92 . ': <span>%s</span></span>';
94 $bookmarks = PMA_Bookmark_getList();
95 $output .= '<div class="message welcome"><span>';
96 $count_bookmarks = count($bookmarks);
97 if ($count_bookmarks > 0) {
98 $bookmarks_message = sprintf(
101 'Total %d bookmarks',
106 $private_message = sprintf(
107 '<span class="bookmark_label">%1$s</span>',
110 $shared_message = sprintf(
111 '<span class="bookmark_label shared">%1$s</span>',
115 /* l10n: First parameter will be replaced with the translation for Total and the number of bookmarks, second one with the translation for private and the third one, with the translation for shared */
116 __('%1$s, %2$s and %3$s bookmarks included'),
122 $output .= __('No bookmarks');
124 unset($count_bookmarks, $private_message, $shared_message);
125 $output .= '</span></div>';
126 foreach ($bookmarks as $val) {
127 $output .= '<div class="message collapsed bookmark" bookmarkid="'
128 . $val['id'] . '" targetdb="' . htmlspecialchars($val['db'])
129 . '"><div class="action_content">'
130 . sprintf($tpl_bookmark_actions, htmlspecialchars($val['db']))
131 . '</div><span class="bookmark_label '
132 . ($val['shared'] ?
'shared' : '') . '">'
133 . htmlspecialchars($val['label'])
134 . '</span> <span class="query">'
135 . htmlspecialchars($val['query'])
143 * Returns the list of JS scripts required by console
145 * @return array list of scripts
147 public function getScripts()
149 return array('console.js');
155 * @param string $tpl_query_actions the template for query actions
157 * @return string $output the generated HTML for history
162 private function _getHistory($tpl_query_actions)
166 $_sql_history = PMA_getHistory($GLOBALS['cfg']['Server']['user']);
167 if (! empty($_sql_history)) {
168 foreach (array_reverse($_sql_history) as $record) {
169 $isSelect = preg_match(
170 '@^SELECT[[:space:]]+@i', $record['sqlquery']
172 $output .= '<div class="message history collapsed hide'
173 . ($isSelect ?
' select' : '')
175 . htmlspecialchars($record['db'])
176 . '" targettable="' . htmlspecialchars($record['table'])
177 . '"><div class="action_content">'
180 htmlspecialchars($record['db']),
181 (isset($record['timevalue'])
182 ?
$record['timevalue']
183 : __('During current session')
186 . '</div><span class="query">'
187 . htmlspecialchars($record['sqlquery'])
195 * Renders the console
200 public function getDisplay()
203 if ((! $this->_isAjax
) && $this->_isEnabled
) {
204 $cfgBookmark = PMA_Bookmark_getParams();
205 $output .= '<div id="pma_console_container"><div id="pma_console">';
207 // The templates, use sprintf() to output them
208 // There're white space at the end of every <span>,
209 // for double-click selection
210 $tpl_query_actions = '<span class="action collapse">' . __('Collapse')
212 . '<span class="action expand">' . __('Expand') . '</span> '
213 . '<span class="action requery">' . __('Requery') . '</span> '
214 . '<span class="action edit">' . __('Edit') . '</span> '
215 . '<span class="action explain">' . __('Explain') . '</span> '
216 . '<span class="action profiling">' . __('Profiling') . '</span> '
217 . ($cfgBookmark ?
'<span class="action bookmark">'
218 . __('Bookmark') . '</span> ' : '')
219 . '<span class="text failed">' . __('Query failed') . '</span> '
220 . '<span class="text targetdb">' . __('Database')
221 . ': <span>%s</span></span> '
222 . '<span class="text query_time">' . __(
224 ) . ': <span>%s</span></span> ';
227 $output .= '<div class="toolbar collapsed">';
229 $output .= '<div class="switch_button console_switch">';
230 $output .= PMA_Util
::getImage('console.png', __('SQL Query Console'));
231 $output .= '<span>' . __('Console') . '</span></div>';
233 $output .= '<div class="button clear"><span>'
234 . __('Clear') . '</span></div>';
236 $output .= '<div class="button history"><span>'
237 . __('History') . '</span></div>';
239 $output .= '<div class="button options"><span>'
240 . __('Options') . '</span></div>';
243 $output .= '<div class="button bookmarks"><span>'
244 . __('Bookmarks') . '</span></div>';
247 $output .= '<div class="button debug hide"><span>'
248 . __('Debug SQL') . '</span></div>';
250 $output .= '</div>'; // Toolbar end
253 $output .= '<div class="content">';
254 $output .= '<div class="console_message_container">'
255 . '<div class="message welcome"><span>'
256 . '<span id="instructions-0">'
257 . __('Press Ctrl+Enter to execute query') . '</span>'
258 . '<span class="hide" id="instructions-1">'
259 . __('Press Enter to execute query') . '</span>'
262 $output .= $this->_getHistory($tpl_query_actions);
264 $output .= '</div>'; // .console_message_container
265 $output .= '<div class="query_input">'
266 . '<span class="console_query_input"></span>'
268 $output .= '</div>'; // Messages end
270 // Dark the console while other cards cover it
271 $output .= '<div class="mid_layer"></div>';
274 $output .= '<div class="card" id="debug_console">';
275 $output .= '<div class="toolbar">'
276 . '<div class="button order order_asc">'
277 . '<span>' . __('ascending') . '</span>'
279 . '<div class="button order order_desc">'
280 . '<span>' . __('descending') . '</span>'
282 . '<div class="text">'
283 . '<span>' . __('Order:') . '</span>'
285 . '<div class="switch_button">'
286 . '<span>' . __('Debug SQL') . '</span>'
288 . '<div class="button order_by sort_count">'
289 . '<span>' . __('Count') . '</span>'
291 . '<div class="button order_by sort_exec">'
292 . '<span>' . __('Execution order') . '</span>'
294 . '<div class="button order_by sort_time">'
295 . '<span>' . __('Time taken') . '</span>'
297 . '<div class="text">'
298 . '<span>' . __('Order by:') . '</span>'
300 . '<div class="button group_queries">'
301 . '<span>' . __('Group queries') . '</span>'
303 . '<div class="button ungroup_queries">'
304 . '<span>' . __('Ungroup queries') . '</span>'
306 . '</div>'; // Toolbar
307 $output .= '<div class="content debug">';
308 $output .= '<div class="message welcome"></div>';
309 $output .= '<div class="debugLog"></div>';
310 $output .= '</div>'; // Content
311 $output .= '<div class="templates">'
312 . '<div class="debug_query action_content">'
313 . '<span class="action collapse">' . __('Collapse') . '</span> '
314 . '<span class="action expand">' . __('Expand') . '</span> '
315 . '<span class="action dbg_show_trace">' . __('Show trace')
317 . '<span class="action dbg_hide_trace">' . __('Hide trace')
319 . '<span class="text count hide">' . __('Count:')
320 . ' <span></span></span>'
321 . '<span class="text time">' . __('Time taken:')
322 . ' <span></span></span>'
324 . '</div>'; // Template
325 $output .= '</div>'; // Debug SQL card
330 $output .= '<div class="card" id="pma_bookmarks">';
331 $output .= '<div class="toolbar">'
332 . '<div class="switch_button"><span>' . __('Bookmarks')
335 $output .= '<div class="button refresh"><span>'
336 . __('Refresh') . '</span></div>';
338 $output .= '<div class="button add"><span>'
339 . __('Add') . '</span></div>';
341 $output .= '</div><div class="content bookmark">';
342 $output .= $this->getBookmarkContent();
344 $output .= '<div class="mid_layer"></div>';
345 $output .= '<div class="card add">';
346 $output .= '<div class="toolbar">'
347 . '<div class="switch_button"><span>'
350 $output .= '</div><div class="content add_bookmark">'
351 . '<div class="options">'
352 . '<label>' . __('Label')
353 . ': <input type="text" name="label"></label> '
354 . '<label>' . __('Target database')
355 . ': <input type="text" name="targetdb"></label> '
356 . '<label><input type="checkbox" name="shared">'
357 . __('Share this bookmark') . '</label>'
358 . '<button type="submit" name="submit">Ok</button>'
359 . '</div>' // .options
360 . '<div class="query_input">'
361 . '<span class="bookmark_add_input"></span></div>';
363 $output .= '</div>'; // Add bookmark card
364 $output .= '</div>'; // Bookmarks card
368 $output .= '<div class="card" id="pma_console_options">';
369 $output .= '<div class="toolbar">'
370 . '<div class="switch_button"><span>' . __('Options')
373 $output .= '<div class="button default"><span>'
374 . __('Set default') . '</span></div>';
376 $output .= '</div><div class="content">'
377 . '<label><input type="checkbox" name="always_expand">'
378 . __('Always expand query messages') . '</label><br>'
379 . '<label><input type="checkbox" name="start_history">'
380 . __('Show query history at start') . '</label><br>'
381 . '<label><input type="checkbox" name="current_query">'
382 . __('Show current browsing query') . '</label><br>'
383 . '<label><input type="checkbox" name="enter_executes">'
385 'Execute queries on Enter and insert new line with Shift + '
386 . 'Enter. To make this permanent, view settings.'
388 . '<label><input type="checkbox" name="dark_theme">'
389 . __('Switch to dark theme') . '</label><br>'
391 $output .= '</div>'; // Options card
393 $output .= '<div class="templates">'
394 // Templates for console message actions
395 . '<div class="query_actions">'
396 . sprintf($tpl_query_actions, '', '')
399 $output .= '</div></div>'; // #console and #pma_console_container ends