1. Check existence of mb_string, mysql and xml extensions before installation.
[openemr.git] / phpmyadmin / libraries / Console.class.php
blob2ab28fc28f498b5beadcc9109a63ce1b3e6d3039
1 <?php
2 /* vim: set expandtab sw=4 ts=4 sts=4: */
3 /**
4 * Used to render the console of PMA's pages
6 * @package PhpMyAdmin
7 */
8 if (! defined('PHPMYADMIN')) {
9 exit;
12 require_once 'libraries/Scripts.class.php';
13 require_once 'libraries/Util.class.php';
14 require_once 'libraries/bookmark.lib.php';
16 /**
17 * Class used to output the console
19 * @package PhpMyAdmin
21 class PMA_Console
23 /**
24 * Whether to display anything
26 * @access private
27 * @var bool
29 private $_isEnabled;
31 /**
32 * Creates a new class instance
34 public function __construct()
36 $this->_isEnabled = true;
39 /**
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.
44 * @access private
45 * @var bool
47 private $_isAjax;
49 /**
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
55 * @return void
57 public function setAjax($isAjax)
59 $this->_isAjax = !!$isAjax;
62 /**
63 * Disables the rendering of the footer
65 * @return void
67 public function disable()
69 $this->_isEnabled = false;
72 /**
73 * Renders the bookmark content
75 * @access public
76 * @return string
78 public static function getBookmarkContent()
80 $output = '';
81 $cfgBookmark = PMA_Bookmark_getParams();
82 if ($cfgBookmark) {
84 $tpl_bookmark_actions
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')
90 . '</span> '
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(
99 _ngettext(
100 'Total %d bookmark',
101 'Total %d bookmarks',
102 $count_bookmarks
104 $count_bookmarks
106 $private_message = sprintf(
107 '<span class="bookmark_label">%1$s</span>',
108 __('private')
110 $shared_message = sprintf(
111 '<span class="bookmark_label shared">%1$s</span>',
112 __('shared')
114 $output .= sprintf(
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'),
117 $bookmarks_message,
118 $private_message,
119 $shared_message
121 } else {
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'])
136 . '</span></div>';
139 return $output;
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');
153 * Gets the history
155 * @param string $tpl_query_actions the template for query actions
157 * @return string $output the generated HTML for history
159 * @access private
162 private function _getHistory($tpl_query_actions)
164 $output = '';
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' : '')
174 . '" targetdb="'
175 . htmlspecialchars($record['db'])
176 . '" targettable="' . htmlspecialchars($record['table'])
177 . '"><div class="action_content">'
178 . sprintf(
179 $tpl_query_actions,
180 htmlspecialchars($record['db']),
181 (isset($record['timevalue'])
182 ? $record['timevalue']
183 : __('During current session')
186 . '</div><span class="query">'
187 . htmlspecialchars($record['sqlquery'])
188 . '</span></div>';
191 return $output;
195 * Renders the console
197 * @access public
198 * @return string
200 public function getDisplay()
202 $output = '';
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')
211 . '</span> '
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">' . __(
223 'Queried time'
224 ) . ': <span>%s</span></span> ';
226 // Console toolbar
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>';
242 if ($cfgBookmark) {
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
252 // Console messages
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>'
260 . '</span></div>';
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>'
267 . '</div>';
268 $output .= '</div>'; // Messages end
270 // Dark the console while other cards cover it
271 $output .= '<div class="mid_layer"></div>';
273 // Debug SQL card
274 $output .= '<div class="card" id="debug_console">';
275 $output .= '<div class="toolbar">'
276 . '<div class="button order order_asc">'
277 . '<span>' . __('ascending') . '</span>'
278 . '</div>'
279 . '<div class="button order order_desc">'
280 . '<span>' . __('descending') . '</span>'
281 . '</div>'
282 . '<div class="text">'
283 . '<span>' . __('Order:') . '</span>'
284 . '</div>'
285 . '<div class="switch_button">'
286 . '<span>' . __('Debug SQL') . '</span>'
287 . '</div>'
288 . '<div class="button order_by sort_count">'
289 . '<span>' . __('Count') . '</span>'
290 . '</div>'
291 . '<div class="button order_by sort_exec">'
292 . '<span>' . __('Execution order') . '</span>'
293 . '</div>'
294 . '<div class="button order_by sort_time">'
295 . '<span>' . __('Time taken') . '</span>'
296 . '</div>'
297 . '<div class="text">'
298 . '<span>' . __('Order by:') . '</span>'
299 . '</div>'
300 . '<div class="button group_queries">'
301 . '<span>' . __('Group queries') . '</span>'
302 . '</div>'
303 . '<div class="button ungroup_queries">'
304 . '<span>' . __('Ungroup queries') . '</span>'
305 . '</div>'
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')
316 . '</span> '
317 . '<span class="action dbg_hide_trace">' . __('Hide trace')
318 . '</span> '
319 . '<span class="text count hide">' . __('Count:')
320 . ' <span></span></span>'
321 . '<span class="text time">' . __('Time taken:')
322 . ' <span></span></span>'
323 . '</div>'
324 . '</div>'; // Template
325 $output .= '</div>'; // Debug SQL card
327 // Bookmarks card:
329 if ($cfgBookmark) {
330 $output .= '<div class="card" id="pma_bookmarks">';
331 $output .= '<div class="toolbar">'
332 . '<div class="switch_button"><span>' . __('Bookmarks')
333 . '</span></div>';
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();
343 $output .= '</div>';
344 $output .= '<div class="mid_layer"></div>';
345 $output .= '<div class="card add">';
346 $output .= '<div class="toolbar">'
347 . '<div class="switch_button"><span>'
348 . __('Add bookmark')
349 . '</span></div>';
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>';
362 $output .= '</div>';
363 $output .= '</div>'; // Add bookmark card
364 $output .= '</div>'; // Bookmarks card
367 // Options card:
368 $output .= '<div class="card" id="pma_console_options">';
369 $output .= '<div class="toolbar">'
370 . '<div class="switch_button"><span>' . __('Options')
371 . '</span></div>';
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">'
384 . __(
385 'Execute queries on Enter and insert new line with Shift + '
386 . 'Enter. To make this permanent, view settings.'
387 ) . '</label><br>'
388 . '<label><input type="checkbox" name="dark_theme">'
389 . __('Switch to dark theme') . '</label><br>'
390 . '</div>';
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, '', '')
397 . '</div>'
398 . '</div>';
399 $output .= '</div></div>'; // #console and #pma_console_container ends
401 return $output;