2 /* vim: set expandtab sw=4 ts=4 sts=4: */
4 * this file is register_globals safe
6 * @todo move JavaScript out of here into .js files
13 require_once './libraries/common.inc.php';
15 $is_superuser = PMA_isSuperuser();
18 * Gets a core script and starts output buffering work
20 require_once './libraries/sql_query_form.lib.php';
23 * starts output buffering if requested and supported
25 require_once './libraries/ob.lib.php';
29 * load relation params
31 $cfgRelation = PMA_getRelationsParam();
34 * load bookmark support
36 require_once './libraries/bookmark.lib.php';
38 $querydisplay_tabs = array(
45 if (isset($_REQUEST['querydisplay_tab'])
46 && in_array($_REQUEST['querydisplay_tab'], $querydisplay_tabs)) {
47 $querydisplay_tab = $_REQUEST['querydisplay_tab'];
49 $querydisplay_tab = $GLOBALS['cfg']['QueryWindowDefTab'];
53 * $_REQUEST['no_js'] is set if open new window by JavaScript failed
54 * so this page is loaded in main frame
56 $no_js = PMA_ifSetOr($_REQUEST['no_js'], false);
59 $querydisplay_tab = 'full';
63 $tabs['sql']['icon'] = 'b_sql.png';
64 $tabs['sql']['text'] = __('SQL');
65 $tabs['sql']['fragment'] = '#';
66 $tabs['sql']['attr'] = 'onclick="javascript:PMA_querywindowCommit(\'sql\');return false;"';
67 $tabs['sql']['active'] = (bool) ($querydisplay_tab == 'sql');
68 $tabs['import']['icon'] = 'b_import.png';
69 $tabs['import']['text'] = __('Import files');
70 $tabs['import']['fragment'] = '#';
71 $tabs['import']['attr'] = 'onclick="javascript:PMA_querywindowCommit(\'files\');return false;"';
72 $tabs['import']['active'] = (bool) ($querydisplay_tab == 'files');
73 $tabs['history']['icon'] = 'b_bookmark.png';
74 $tabs['history']['text'] = __('SQL history');
75 $tabs['history']['fragment'] = '#';
76 $tabs['history']['attr'] = 'onclick="javascript:PMA_querywindowCommit(\'history\');return false;"';
77 $tabs['history']['active'] = (bool) ($querydisplay_tab == 'history');
79 if ($GLOBALS['cfg']['QueryWindowDefTab'] == 'full') {
80 $tabs['all']['text'] = __('All');
81 $tabs['all']['fragment'] = '#';
82 $tabs['all']['attr'] = 'onclick="javascript:PMA_querywindowCommit(\'full\');return false;"';
83 $tabs['all']['active'] = (bool) ($querydisplay_tab == 'full');
87 if ($GLOBALS['cfg']['PropertiesIconic']) {
89 '<img class="icon" width="16" height="16" src="' . $pmaThemeImage
90 . 'b_edit.png" alt="' . __('Change') . '" title="' . __('Change')
93 if ('both' === $GLOBALS['cfg']['PropertiesIconic']) {
94 $titles['Change'] .= __('Change') . ' ';
97 $titles['Change'] = __('Change') . ' ';
100 $url_query = PMA_generate_common_url($db, $table);
102 if (! empty($sql_query)) {
107 // ... we redirect to appropriate query sql page
108 // works only full if $db and $table is also stored/grabbed from $_COOKIE
109 if (strlen($table)) {
110 require './tbl_sql.php';
111 } elseif (strlen($db)) {
112 require './db_sql.php';
114 require './server_sql.php';
120 * Defines the query to be displayed in the query textarea
122 if (! empty($show_query)) {
123 $query_to_display = $sql_query;
125 $query_to_display = '';
130 * prepare JavaScript functionality
132 $js_include[] = 'common.js';
133 $js_include[] = 'querywindow.js';
135 if (PMA_isValid($_REQUEST['auto_commit'], 'identical', 'true')) {
136 $js_events[] = array(
138 'function' => 'PMA_queryAutoCommit',
141 if (PMA_isValid($_REQUEST['init'])) {
142 $js_events[] = array(
144 'function' => 'PMA_querywindowResize',
147 // always set focus to the textarea
148 if ($querydisplay_tab == 'sql' ||
$querydisplay_tab == 'full') {
149 $js_events[] = array(
151 'function' => 'PMA_querywindowSetFocus',
156 * start HTTP/HTML output
158 require_once './libraries/header_http.inc.php';
159 require_once './libraries/header_meta_style.inc.php';
160 require_once './libraries/header_scripts.inc.php';
164 <body id
="bodyquerywindow">
165 <div id
="querywindowcontainer">
169 echo PMA_generate_html_tabs($tabs, array());
173 PMA_sqlQueryForm($query_to_display, $querydisplay_tab);
175 // Hidden forms and query frame interaction stuff
177 $_sql_history = PMA_getHistory($GLOBALS['cfg']['Server']['user']);
178 if (! empty($_sql_history)
179 && ($querydisplay_tab == 'history' ||
$querydisplay_tab == 'full')) {
180 $tab = $querydisplay_tab != 'full' ?
'sql' : 'full';
181 echo __('SQL history') . ':<br />'
183 foreach ($_sql_history as $query) {
188 'querydisplay_tab' => $tab,
189 'sql_query' => $query['sqlquery'],
190 'db' => $query['db'],
191 'table' => $query['table'],
193 echo '<a href="querywindow.php' . PMA_generate_common_url($url_params)
194 . '">' . $titles['Change'] . '</a>';
197 $url_params['auto_commit'] = 'true';
198 echo '<a href="import.php' . PMA_generate_common_url($url_params) . '"'
199 . ' target="frame_content">';
201 if (! empty($query['db'])) {
203 echo htmlspecialchars(PMA_backquote($query['db']));
204 if (! empty($query['table'])) {
205 echo '.' . htmlspecialchars(PMA_backquote($query['table']));
209 if (strlen($query['sqlquery']) > 120) {
210 echo '<span title="' . htmlspecialchars($query['sqlquery']) . '">';
211 echo htmlspecialchars(substr($query['sqlquery'], 0, 50)) . ' [...] ';
212 echo htmlspecialchars(substr($query['sqlquery'], -50));
215 echo htmlspecialchars($query['sqlquery']);
220 unset($tab, $_sql_history, $query);
224 <form action
="querywindow.php" method
="post" name
="hiddenqueryform"
225 id
="hiddenqueryform">
226 <?php
echo PMA_generate_common_hidden_inputs('', ''); ?
>
227 <input type
="hidden" name
="db" value
="<?php echo htmlspecialchars($db); ?>" />
228 <input type
="hidden" name
="table" value
="<?php echo htmlspecialchars($table); ?>" />
229 <input type
="hidden" name
="sql_query" value
="" />
230 <input type
="hidden" name
="querydisplay_tab" value
="<?php echo $querydisplay_tab; ?>" />