Remove misleading comment on the "Rename database" interface
[phpmyadmin/ammaryasirr.git] / querywindow.php
blob0b92ad893b90f864e61725734e6cb8c6a6dc4b3d
1 <?php
2 /* vim: set expandtab sw=4 ts=4 sts=4: */
3 /**
4 * this file is register_globals safe
6 * @todo move JavaScript out of here into .js files
7 * @uses $cfg['QueryWindowDefTab']
8 * @uses $cfg['PropertiesIconic']
9 * @uses $cfg['QueryHistoryDB']
10 * @uses $cfg['Server']['user']
11 * @uses $cfg['AllowUserDropDatabase']
12 * @uses $cfg['Confirm']
13 * @uses $GLOBALS['db']
14 * @uses $GLOBALS['table']
15 * @uses PMA_isSuperuser()
16 * @uses PMA_outBufferPre()
17 * @uses PMA_getRelationsParam()
18 * @uses PMA_isValid()
19 * @uses PMA_ifSetOr()
20 * @uses PMA_getHistory()
21 * @uses PMA_generate_common_url()
22 * @uses PMA_generate_common_hidden_inputs()
23 * @uses PMA_escapeJsString()
24 * @uses PMA_generate_html_tabs()
25 * @uses PMA_sqlQueryForm()
26 * @uses PMA_jsFormat()
27 * @uses in_array()
28 * @uses strlen()
29 * @uses preg_replace()
30 * @uses htmlspecialchars()
31 * @package phpMyAdmin
34 /**
37 require_once './libraries/common.inc.php';
39 $is_superuser = PMA_isSuperuser();
41 /**
42 * Gets a core script and starts output buffering work
44 require_once './libraries/sql_query_form.lib.php';
46 /**
47 * starts output buffering if requested and supported
49 require_once './libraries/ob.lib.php';
50 PMA_outBufferPre();
52 /**
53 * load relation params
55 $cfgRelation = PMA_getRelationsParam();
57 /**
58 * load bookmark support
60 require_once './libraries/bookmark.lib.php';
62 $querydisplay_tabs = array(
63 'sql',
64 'files',
65 'history',
66 'full',
69 if (isset($_REQUEST['querydisplay_tab'])
70 && in_array($_REQUEST['querydisplay_tab'], $querydisplay_tabs)) {
71 $querydisplay_tab = $_REQUEST['querydisplay_tab'];
72 } else {
73 $querydisplay_tab = $GLOBALS['cfg']['QueryWindowDefTab'];
76 /**
77 * $_REQUEST['no_js'] is set if open new window by JavaScript failed
78 * so this page is loaded in main frame
80 $no_js = PMA_ifSetOr($_REQUEST['no_js'], false);
82 if ($no_js) {
83 $querydisplay_tab = 'full';
84 $tabs = false;
85 } else {
86 $tabs = array();
87 $tabs['sql']['icon'] = 'b_sql.png';
88 $tabs['sql']['text'] = __('SQL');
89 $tabs['sql']['fragment'] = '#';
90 $tabs['sql']['attr'] = 'onclick="javascript:PMA_querywindowCommit(\'sql\');return false;"';
91 $tabs['sql']['active'] = (bool) ($querydisplay_tab == 'sql');
92 $tabs['import']['icon'] = 'b_import.png';
93 $tabs['import']['text'] = __('Import files');
94 $tabs['import']['fragment'] = '#';
95 $tabs['import']['attr'] = 'onclick="javascript:PMA_querywindowCommit(\'files\');return false;"';
96 $tabs['import']['active'] = (bool) ($querydisplay_tab == 'files');
97 $tabs['history']['icon'] = 'b_bookmark.png';
98 $tabs['history']['text'] = __('SQL history');
99 $tabs['history']['fragment'] = '#';
100 $tabs['history']['attr'] = 'onclick="javascript:PMA_querywindowCommit(\'history\');return false;"';
101 $tabs['history']['active'] = (bool) ($querydisplay_tab == 'history');
103 if ($GLOBALS['cfg']['QueryWindowDefTab'] == 'full') {
104 $tabs['all']['text'] = __('All');
105 $tabs['all']['fragment'] = '#';
106 $tabs['all']['attr'] = 'onclick="javascript:PMA_querywindowCommit(\'full\');return false;"';
107 $tabs['all']['active'] = (bool) ($querydisplay_tab == 'full');
111 if ($GLOBALS['cfg']['PropertiesIconic']) {
112 $titles['Change'] =
113 '<img class="icon" width="16" height="16" src="' . $pmaThemeImage
114 . 'b_edit.png" alt="' . __('Change') . '" title="' . __('Change')
115 . '" />';
117 if ('both' === $GLOBALS['cfg']['PropertiesIconic']) {
118 $titles['Change'] .= __('Change') . ' ';
120 } else {
121 $titles['Change'] = __('Change') . ' ';
124 $url_query = PMA_generate_common_url($db, $table);
126 if (! empty($sql_query)) {
127 $show_query = 1;
130 if ($no_js) {
131 // ... we redirect to appropriate query sql page
132 // works only full if $db and $table is also stored/grabbed from $_COOKIE
133 if (strlen($table)) {
134 require './tbl_sql.php';
135 } elseif (strlen($db)) {
136 require './db_sql.php';
137 } else {
138 require './server_sql.php';
140 exit;
144 * Defines the query to be displayed in the query textarea
146 if (! empty($show_query)) {
147 $query_to_display = $sql_query;
148 } else {
149 $query_to_display = '';
151 $sql_query = '';
154 * prepare JavaScript functionality
156 $js_include[] = 'common.js';
157 $js_include[] = 'querywindow.js';
159 if (PMA_isValid($_REQUEST['auto_commit'], 'identical', 'true')) {
160 $js_events[] = array(
161 'event' => 'load',
162 'function' => 'PMA_queryAutoCommit',
165 if (PMA_isValid($_REQUEST['init'])) {
166 $js_events[] = array(
167 'event' => 'load',
168 'function' => 'PMA_querywindowResize',
171 // always set focus to the textarea
172 if ($querydisplay_tab == 'sql' || $querydisplay_tab == 'full') {
173 $js_events[] = array(
174 'event' => 'load',
175 'function' => 'PMA_querywindowSetFocus',
180 * start HTTP/HTML output
182 require_once './libraries/header_http.inc.php';
183 require_once './libraries/header_meta_style.inc.php';
184 require_once './libraries/header_scripts.inc.php';
186 </head>
188 <body id="bodyquerywindow">
189 <div id="querywindowcontainer">
190 <?php
192 if ($tabs) {
193 echo PMA_generate_html_tabs($tabs, array());
194 unset($tabs);
197 PMA_sqlQueryForm($query_to_display, $querydisplay_tab);
199 // Hidden forms and query frame interaction stuff
201 $_sql_history = PMA_getHistory($GLOBALS['cfg']['Server']['user']);
202 if (! empty($_sql_history)
203 && ($querydisplay_tab == 'history' || $querydisplay_tab == 'full')) {
204 $tab = $querydisplay_tab != 'full' ? 'sql' : 'full';
205 echo __('SQL history') . ':<br />'
206 . '<ul>';
207 foreach ($_sql_history as $query) {
208 echo '<li>' . "\n";
210 // edit link
211 $url_params = array(
212 'querydisplay_tab' => $tab,
213 'sql_query' => $query['sqlquery'],
214 'db' => $query['db'],
215 'table' => $query['table'],
217 echo '<a href="querywindow.php' . PMA_generate_common_url($url_params)
218 . '">' . $titles['Change'] . '</a>';
220 // execute link
221 $url_params['auto_commit'] = 'true';
222 echo '<a href="import.php' . PMA_generate_common_url($url_params) . '"'
223 . ' target="frame_content">';
225 if (! empty($query['db'])) {
226 echo '[';
227 echo htmlspecialchars(PMA_backquote($query['db']));
228 if (! empty($query['table'])) {
229 echo '.' . htmlspecialchars(PMA_backquote($query['table']));
231 echo '] ';
233 if (strlen($query['sqlquery']) > 120) {
234 echo '<span title="' . htmlspecialchars($query['sqlquery']) . '">';
235 echo htmlspecialchars(substr($query['sqlquery'], 0, 50)) . ' [...] ';
236 echo htmlspecialchars(substr($query['sqlquery'], -50));
237 echo '</span>';
238 } else {
239 echo htmlspecialchars($query['sqlquery']);
241 echo '</a>' . "\n";
242 echo '</li>' . "\n";
244 unset($tab, $_sql_history, $query);
245 echo '</ul>' . "\n";
248 <form action="querywindow.php" method="post" name="hiddenqueryform"
249 id="hiddenqueryform">
250 <?php echo PMA_generate_common_hidden_inputs('', ''); ?>
251 <input type="hidden" name="db" value="<?php echo htmlspecialchars($db); ?>" />
252 <input type="hidden" name="table" value="<?php echo htmlspecialchars($table); ?>" />
253 <input type="hidden" name="sql_query" value="" />
254 <input type="hidden" name="querydisplay_tab" value="<?php echo $querydisplay_tab; ?>" />
255 </form>
256 </div>
257 </body>
258 </html>