$scripts->addFile('querywindow.js'); if (PMA_isValid($_REQUEST['auto_commit'], 'identical', 'true')) { $scripts->addEvent('load', 'PMA_queryAutoCommit'); } // always set focus to the textarea if ($querydisplay_tab == 'sql' || $querydisplay_tab == 'full') { $scripts->addEvent('load', 'PMA_querywindowSetFocus'); } echo '<div id="querywindowcontainer">'; if ($tabs) { echo PMA_Util::getHtmlTabs($tabs, array(), 'topmenu', true); unset($tabs); } echo PMA_getHtmlForSqlQueryForm($query_to_display, $querydisplay_tab); // Hidden forms and query frame interaction stuff $_sql_history = PMA_getHistory($GLOBALS['cfg']['Server']['user']); if (!empty($_sql_history) && ($querydisplay_tab == 'history' || $querydisplay_tab == 'full')) { $tab = $querydisplay_tab != 'full' ? 'sql' : 'full'; echo __('SQL history:') . '<br />' . '<ul>'; foreach ($_sql_history as $query) { echo '<li>' . "\n"; // edit link $url_params = array('querydisplay_tab' => $tab, 'sql_query' => $query['sqlquery'], 'db' => $query['db'], 'table' => $query['table']); echo '<a href="querywindow.php' . PMA_URL_getCommon($url_params) . '">' . $titles['Change'] . '</a>'; // execute link $url_params['auto_commit'] = 'true'; echo '<a href="import.php' . PMA_URL_getCommon($url_params) . '"' . ' target="frame_content">'; if (!empty($query['db'])) { echo '['; echo htmlspecialchars(PMA_Util::backquote($query['db'])); if (!empty($query['table'])) {
$input_query_history[] = '<input type="hidden" name="query_history[]" value="' . $query_history_latest . '" />'; $input_query_history[] = '<input type="hidden" name="query_history_db[]" value="' . htmlspecialchars($query_history_latest_db) . '" />'; $input_query_history[] = '<input type="hidden" name="query_history_table[]" value="' . (isset($query_history_latest_table) ? htmlspecialchars($query_history_latest_table) : '') . '" />'; $sql_history[] = '<li>' . '<a href="#" onclick="document.querywindow.querydisplay_tab.value = \'' . (isset($querydisplay_tab) && $querydisplay_tab != 'full' ? 'sql' : 'full') . '\'; document.querywindow.query_history_latest.value = \'' . preg_replace('/(\\n)/i', ' ', addslashes(htmlspecialchars($query_history_latest))) . '\'; document.querywindow.auto_commit.value = \'false\'; document.querywindow.db.value = \'' . htmlspecialchars($query_history_latest_db) . '\'; document.querywindow.query_history_latest_db.value = \'' . htmlspecialchars($query_history_latest_db) . '\'; document.querywindow.table.value = \'' . (isset($query_history_latest_table) ? htmlspecialchars($query_history_latest_table) : '') . '\'; document.querywindow.query_history_latest_table.value = \'' . (isset($query_history_latest_table) ? htmlspecialchars($query_history_latest_table) : '') . '\'; document.querywindow.submit(); return false;">' . $titles['Change'] . '</a>' . ' <a href="#" onclick="document.querywindow.querydisplay_tab.value = \'' . (isset($querydisplay_tab) && $querydisplay_tab != 'full' ? 'sql' : 'full') . '\'; document.querywindow.query_history_latest.value = \'' . preg_replace('/(\\n)/i', ' ', addslashes(htmlspecialchars($query_history_latest))) . '\'; document.querywindow.auto_commit.value = \'true\'; document.querywindow.db.value = \'' . htmlspecialchars($query_history_latest_db) . '\'; document.querywindow.query_history_latest_db.value = \'' . htmlspecialchars($query_history_latest_db) . '\'; document.querywindow.table.value = \'' . (isset($query_history_latest_table) ? htmlspecialchars($query_history_latest_table) : '') . '\'; document.querywindow.query_history_latest_table.value = \'' . (isset($query_history_latest_table) ? htmlspecialchars($query_history_latest_table) : '') . '\'; document.querywindow.submit(); return false;">[' . htmlspecialchars($query_history_latest_db) . '] ' . urldecode($query_history_latest) . '</a>' . '</li>' . "\n"; $sql_query = urldecode($query_history_latest); $db = $query_history_latest_db; $table = $query_history_latest_table; $dup_sql[$query_history_latest] = true; } elseif (isset($query_history_latest) && $query_history_latest != '') { $sql_query = urldecode($query_history_latest); } if (isset($sql_query)) { $show_query = 1; } if ($cfg['QueryHistoryDB'] && $cfgRelation['historywork']) { $temp_history = PMA_getHistory($cfg['Server']['user']); if (is_array($temp_history) && count($temp_history) > 0) { foreach ($temp_history as $history_nr => $history_array) { if (!isset($dup_sql[$history_array['sqlquery']])) { $sql_history[] = '<li>' . '<a href="#" onclick="document.querywindow.querydisplay_tab.value = \'' . (isset($querydisplay_tab) && $querydisplay_tab != 'full' ? 'sql' : 'full') . '\'; document.querywindow.query_history_latest.value = \'' . preg_replace('/(\\n)/i', ' ', addslashes(htmlspecialchars($history_array['sqlquery']))) . '\'; document.querywindow.auto_commit.value = \'false\'; document.querywindow.db.value = \'' . htmlspecialchars($history_array['db']) . '\'; document.querywindow.query_history_latest_db.value = \'' . htmlspecialchars($history_array['db']) . '\'; document.querywindow.table.value = \'' . (isset($history_array['table']) ? htmlspecialchars($history_array['table']) : '') . '\'; document.querywindow.query_history_latest_table.value = \'' . (isset($history_array['table']) ? htmlspecialchars($history_array['table']) : '') . '\'; document.querywindow.submit(); return false;">' . $titles['Change'] . '</a>' . '<a href="#" onclick="document.querywindow.querydisplay_tab.value = \'' . (isset($querydisplay_tab) && $querydisplay_tab != 'full' ? 'sql' : 'full') . '\'; document.querywindow.query_history_latest.value = \'' . preg_replace('/(\\n)/i', ' ', addslashes(htmlspecialchars($history_array['sqlquery']))) . '\'; document.querywindow.auto_commit.value = \'true\'; document.querywindow.db.value = \'' . htmlspecialchars($history_array['db']) . '\'; document.querywindow.query_history_latest_db.value = \'' . htmlspecialchars($history_array['db']) . '\'; document.querywindow.table.value = \'' . (isset($history_array['table']) ? htmlspecialchars($history_array['table']) : '') . '\'; document.querywindow.query_history_latest_table.value = \'' . (isset($history_array['table']) ? htmlspecialchars($history_array['table']) : '') . '\'; document.querywindow.submit(); return false;">[' . htmlspecialchars($history_array['db']) . '] ' . urldecode($history_array['sqlquery']) . '</a>' . '</li>' . "\n"; $dup_sql[$history_array['sqlquery']] = true; } } } } else { if (isset($query_history) && is_array($query_history)) { $current_index = count($query_history); foreach ($query_history as $query_no => $query_sql) { if (!isset($dup_sql[$query_sql])) { $input_query_history[] = '<input type="hidden" name="query_history[]" value="' . $query_sql . '" />'; $input_query_history[] = '<input type="hidden" name="query_history_db[]" value="' . htmlspecialchars($query_history_db[$query_no]) . '" />';
/** * Renders the console * * @access public * @return string */ public function getDisplay() { $output = ''; if (!$this->_isAjax && $this->_isEnabled) { $cfgBookmark = PMA_Bookmark_getParams(); $output .= '<div id="pma_console_container"><div id="pma_console">'; // The templates, use sprintf() to output them // There're white space at the end of every <span>, // for double-click selection $tpl_query_actions = '<span class="action collapse">' . __('Collapse') . '</span> ' . '<span class="action expand">' . __('Expand') . '</span> ' . '<span class="action requery">' . __('Requery') . '</span> ' . '<span class="action edit">' . __('Edit') . '</span> ' . '<span class="action explain">' . __('Explain') . '</span> ' . '<span class="action profiling">' . __('Profiling') . '</span> ' . ($cfgBookmark ? '<span class="action bookmark">' . __('Bookmark') . '</span> ' : '') . '<span class="text failed">' . __('Query failed') . '</span> ' . '<span class="text targetdb">' . __('Database') . ': <span>%s</span></span> ' . '<span class="text query_time">' . __('Queried time') . ': <span>%s</span></span> '; // Console toolbar $output .= '<div class="toolbar collapsed">'; $output .= '<div class="switch_button console_switch">'; $output .= PMA_Util::getImage('console.png', __('SQL Query Console')); $output .= '<span>' . __('Console') . '</span></div>'; $output .= '<div class="button clear"><span>' . __('Clear') . '</span></div>'; $output .= '<div class="button history"><span>' . __('History') . '</span></div>'; $output .= '<div class="button options"><span>' . __('Options') . '</span></div>'; if ($cfgBookmark) { $output .= '<div class="button bookmarks"><span>' . __('Bookmarks') . '</span></div>'; } $output .= '</div>'; // Toolbar end // Console messages $output .= '<div class="content">'; $output .= '<div class="console_message_container">' . '<div class="message welcome"><span>' . '<span id="instructions-0">' . __('Press Ctrl+Enter to execute query') . '</span>' . '<span class="hide" id="instructions-1">' . __('Press Enter to execute query') . '</span>' . '</span></div>'; // History support $_sql_history = PMA_getHistory($GLOBALS['cfg']['Server']['user']); if ($_sql_history) { foreach (array_reverse($_sql_history) as $record) { $isSelect = preg_match('@^SELECT[[:space:]]+@i', $record['sqlquery']); $output .= '<div class="message history collapsed hide' . ($isSelect ? ' select' : '') . '" targetdb="' . htmlspecialchars($record['db']) . '" targettable="' . htmlspecialchars($record['table']) . '"><div class="action_content">' . sprintf($tpl_query_actions, htmlspecialchars($record['db']), isset($record['timevalue']) ? $record['timevalue'] : __('During current session')) . '</div><span class="query">' . htmlspecialchars($record['sqlquery']) . '</span></div>'; } } $output .= '</div>'; // .console_message_container $output .= '<div class="query_input">' . '<span class="console_query_input"></span>' . '</div>'; $output .= '</div>'; // Messages end // Dark the console while other cards cover it $output .= '<div class="mid_layer"></div>'; // Bookmarks card: if ($cfgBookmark) { $output .= '<div class="card" id="pma_bookmarks">'; $output .= '<div class="toolbar">' . '<div class="switch_button"><span>' . __('Bookmarks') . '</span></div>'; $output .= '<div class="button refresh"><span>' . __('Refresh') . '</span></div>'; $output .= '<div class="button add"><span>' . __('Add') . '</span></div>'; $output .= '</div><div class="content bookmark">'; $output .= $this->getBookmarkContent(); $output .= '</div>'; $output .= '<div class="mid_layer"></div>'; $output .= '<div class="card add">'; $output .= '<div class="toolbar">' . '<div class="switch_button"><span>' . __('Add bookmark') . '</span></div>'; $output .= '</div><div class="content add_bookmark">' . '<div class="options">' . '<label>' . __('Label') . ': <input type="text" name="label"></label> ' . '<label>' . __('Target database') . ': <input type="text" name="targetdb"></label> ' . '<label><input type="checkbox" name="shared">' . __('Share this bookmark') . '</label>' . '<button type="submit" name="submit">Ok</button>' . '</div>' . '<div class="query_input">' . '<span class="bookmark_add_input"></span></div>'; $output .= '</div>'; $output .= '</div>'; // Add bookmark card $output .= '</div>'; // Bookmarks card } // Options card: $output .= '<div class="card" id="pma_console_options">'; $output .= '<div class="toolbar">' . '<div class="switch_button"><span>' . __('Options') . '</span></div>'; $output .= '<div class="button default"><span>' . __('Set default') . '</span></div>'; $output .= '</div><div class="content">' . '<label><input type="checkbox" name="always_expand">' . __('Always expand query messages') . '</label><br>' . '<label><input type="checkbox" name="start_history">' . __('Show query history at start') . '</label><br>' . '<label><input type="checkbox" name="current_query">' . __('Show current browsing query') . '</label><br>' . '<label><input type="checkbox" name="enter_executes">' . __('Execute queries on Enter and insert new line with Shift + Enter. ' . 'To make this permanent, view settings.') . '</label><br>' . '<label><input type="checkbox" name="dark_theme">' . __('Switch to dark theme') . '</label><br>' . '</div>'; $output .= '</div>'; // Options card $output .= '<div class="templates">' . '<div class="query_actions">' . sprintf($tpl_query_actions, '', '') . '</div>' . '</div>'; $output .= '</div></div>'; // #console and #pma_console_container ends } return $output; }
/** * Gets the history * * @param string $tpl_query_actions the template for query actions * * @return string $output the generated HTML for history * * @access private * */ private function _getHistory($tpl_query_actions) { $output = ''; $_sql_history = PMA_getHistory($GLOBALS['cfg']['Server']['user']); if (!empty($_sql_history)) { foreach (array_reverse($_sql_history) as $record) { $isSelect = preg_match('@^SELECT[[:space:]]+@i', $record['sqlquery']); $output .= '<div class="message history collapsed hide' . ($isSelect ? ' select' : '') . '" targetdb="' . htmlspecialchars($record['db']) . '" targettable="' . htmlspecialchars($record['table']) . '"><div class="action_content">' . sprintf($tpl_query_actions, htmlspecialchars($record['db']), isset($record['timevalue']) ? $record['timevalue'] : __('During current session')) . '</div><span class="query">' . htmlspecialchars($record['sqlquery']) . '</span></div>'; } } return $output; }
/** * Renders the console * * @access public * @return string */ public function getDisplay() { if (!$this->_isAjax && $this->_isEnabled) { $cfgBookmark = Bookmark::getParams(); $image = Util::getImage('console.png', __('SQL Query Console')); $_sql_history = PMA_getHistory($GLOBALS['cfg']['Server']['user']); $bookmarkContent = static::getBookmarkContent(); return Template::get('console/display')->render(array('cfgBookmark' => $cfgBookmark, 'image' => $image, '_sql_history' => $_sql_history, 'bookmarkContent' => $bookmarkContent)); } return ''; }