patch #2498350 [cleanup] XHTML cleanup
[phpmyadmin/crack.git] / querywindow.php
blob2c678fa05cded1f384bce0849da43e555fd49d83
1 <?php
2 /* vim: set expandtab sw=4 ts=4 sts=4: */
3 /**
4 * this file is register_globals save
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 $GLOBALS['strSQL']
16 * @uses $GLOBALS['strImportFiles']
17 * @uses $GLOBALS['strQuerySQLHistory']
18 * @uses $GLOBALS['strAll']
19 * @uses $GLOBALS['strChange']
20 * @uses $GLOBALS['strFormEmpty']
21 * @uses $GLOBALS['strNotNumber']
22 * @uses $GLOBALS['strNoDropDatabases']
23 * @uses $GLOBALS['strDoYouReally']
24 * @uses $GLOBALS['strQuerySQLHistory']
25 * @uses PMA_isSuperuser()
26 * @uses PMA_outBufferPre()
27 * @uses PMA_getRelationsParam()
28 * @uses PMA_isValid()
29 * @uses PMA_ifSetOr()
30 * @uses PMA_getHistory()
31 * @uses PMA_generate_common_url()
32 * @uses PMA_generate_common_hidden_inputs()
33 * @uses PMA_escapeJsString()
34 * @uses PMA_getTabs()
35 * @uses PMA_sqlQueryForm()
36 * @uses PMA_jsFormat()
37 * @uses in_array()
38 * @uses strlen()
39 * @uses preg_replace()
40 * @uses htmlspecialchars()
41 * @version $Id$
42 * @package phpMyAdmin
45 /**
48 require_once './libraries/common.inc.php';
50 $is_superuser = PMA_isSuperuser();
52 /**
53 * Gets a core script and starts output buffering work
55 require_once './libraries/sql_query_form.lib.php';
57 /**
58 * starts output buffering if requested and supported
60 require_once './libraries/ob.lib.php';
61 PMA_outBufferPre();
63 /**
64 * load relations
66 require_once './libraries/relation.lib.php';
67 $cfgRelation = PMA_getRelationsParam();
69 /**
70 * load bookmark support
72 require_once './libraries/bookmark.lib.php';
74 $querydisplay_tabs = array(
75 'sql',
76 'files',
77 'history',
78 'full',
81 if (isset($_REQUEST['querydisplay_tab'])
82 && in_array($_REQUEST['querydisplay_tab'], $querydisplay_tabs)) {
83 $querydisplay_tab = $_REQUEST['querydisplay_tab'];
84 } else {
85 $querydisplay_tab = $GLOBALS['cfg']['QueryWindowDefTab'];
88 /**
89 * $_REQUEST['no_js'] is set if open new window by JavaScript failed
90 * so this page is loaded in main frame
92 $no_js = PMA_ifSetOr($_REQUEST['no_js'], false);
94 if ($no_js) {
95 $querydisplay_tab = 'full';
96 $tabs = false;
97 } else {
98 $tabs = array();
99 $tabs['sql']['icon'] = 'b_sql.png';
100 $tabs['sql']['text'] = $GLOBALS['strSQL'];
101 $tabs['sql']['fragment'] = '#';
102 $tabs['sql']['attr'] = 'onclick="javascript:PMA_querywindowCommit(\'sql\');return false;"';
103 $tabs['sql']['active'] = (bool) ($querydisplay_tab == 'sql');
104 $tabs['import']['icon'] = 'b_import.png';
105 $tabs['import']['text'] = $GLOBALS['strImportFiles'];
106 $tabs['import']['fragment'] = '#';
107 $tabs['import']['attr'] = 'onclick="javascript:PMA_querywindowCommit(\'files\');return false;"';
108 $tabs['import']['active'] = (bool) ($querydisplay_tab == 'files');
109 $tabs['history']['icon'] = 'b_bookmark.png';
110 $tabs['history']['text'] = $GLOBALS['strQuerySQLHistory'];
111 $tabs['history']['fragment'] = '#';
112 $tabs['history']['attr'] = 'onclick="javascript:PMA_querywindowCommit(\'history\');return false;"';
113 $tabs['history']['active'] = (bool) ($querydisplay_tab == 'history');
115 if ($GLOBALS['cfg']['QueryWindowDefTab'] == 'full') {
116 $tabs['all']['text'] = $GLOBALS['strAll'];
117 $tabs['all']['fragment'] = '#';
118 $tabs['all']['attr'] = 'onclick="javascript:PMA_querywindowCommit(\'full\');return false;"';
119 $tabs['all']['active'] = (bool) ($querydisplay_tab == 'full');
123 if ($GLOBALS['cfg']['PropertiesIconic']) {
124 $titles['Change'] =
125 '<img class="icon" width="16" height="16" src="' . $pmaThemeImage
126 . 'b_edit.png" alt="' . $GLOBALS['strChange'] . '" title="' . $GLOBALS['strChange']
127 . '" />';
129 if ('both' === $GLOBALS['cfg']['PropertiesIconic']) {
130 $titles['Change'] .= $GLOBALS['strChange'];
132 } else {
133 $titles['Change'] = $GLOBALS['strChange'];
136 $url_query = PMA_generate_common_url($db, $table);
138 if (! empty($sql_query)) {
139 $show_query = 1;
142 if ($no_js) {
143 // ... we redirect to appropriate query sql page
144 // works only full if $db and $table is also stored/grabbed from $_COOKIE
145 if (strlen($table)) {
146 require './tbl_sql.php';
147 } elseif (strlen($db)) {
148 require './db_sql.php';
149 } else {
150 require './server_sql.php';
152 exit;
156 * Defines the query to be displayed in the query textarea
158 if (! empty($show_query)) {
159 $query_to_display = $sql_query;
160 } else {
161 $query_to_display = '';
163 $sql_query = '';
166 * prepare JavaScript functionality
168 $js_include[] = 'common.js';
169 $js_include[] = 'functions.js';
170 $js_include[] = 'querywindow.js';
172 if (PMA_isValid($_REQUEST['auto_commit'], 'identical', 'true')) {
173 $js_events[] = array(
174 'object' => 'window',
175 'event' => 'load',
176 'function' => 'PMA_queryAutoCommit',
179 if (PMA_isValid($_REQUEST['init'])) {
180 $js_events[] = array(
181 'object' => 'window',
182 'event' => 'load',
183 'function' => 'PMA_querywindowResize',
186 // always set focus to the textarea
187 if ($querydisplay_tab == 'sql' || $querydisplay_tab == 'full') {
188 $js_events[] = array(
189 'object' => 'window',
190 'event' => 'load',
191 'function' => 'PMA_querywindowSetFocus',
196 * start HTTP/HTML output
198 require_once './libraries/header_http.inc.php';
199 require_once './libraries/header_meta_style.inc.php';
200 require_once './libraries/header_scripts.inc.php';
202 </head>
204 <body id="bodyquerywindow">
205 <div id="querywindowcontainer">
206 <?php
208 if ($tabs) {
209 echo PMA_getTabs($tabs, array());
210 unset($tabs);
213 PMA_sqlQueryForm($query_to_display, $querydisplay_tab);
215 // Hidden forms and query frame interaction stuff
217 $_sql_history = PMA_getHistory($GLOBALS['cfg']['Server']['user']);
218 if (! empty($_sql_history)
219 && ($querydisplay_tab == 'history' || $querydisplay_tab == 'full')) {
220 $tab = $querydisplay_tab != 'full' ? 'sql' : 'full';
221 echo $GLOBALS['strQuerySQLHistory'] . ':<br />' . "\n"
222 .'<ul>';
223 foreach ($_sql_history as $query) {
224 echo '<li>' . "\n";
226 // edit link
227 $url_params = array(
228 'querydisplay_tab' => $tab,
229 'sql_query' => $query['sqlquery'],
230 'db' => $query['db'],
231 'table' => $query['table'],
233 echo '<a href="querywindow.php' . PMA_generate_common_url($url_params)
234 . '">' . $titles['Change'] . '</a>';
236 // execute link
237 $url_params['auto_commit'] = 'true';
238 echo '<a href="import.php' . PMA_generate_common_url($url_params) . '"'
239 . ' target="frame_content">';
241 if (! empty($query['db'])) {
242 echo '[';
243 echo htmlspecialchars(PMA_backquote($query['db']));
244 if (! empty($query['table'])) {
245 echo '.' . htmlspecialchars(PMA_backquote($query['table']));
247 echo '] ';
249 if (strlen($query['sqlquery']) > 120) {
250 echo '<span title="' . htmlspecialchars($query['sqlquery']) . '">';
251 echo htmlspecialchars(substr($query['sqlquery'], 0, 50)) . ' [...] ';
252 echo htmlspecialchars(substr($query['sqlquery'], -50));
253 echo '</span>';
254 } else {
255 echo htmlspecialchars($query['sqlquery']);
257 echo '</a>' . "\n";
258 echo '</li>' . "\n";
260 unset($tab, $_sql_history, $query);
261 echo '</ul>' . "\n";
264 <form action="querywindow.php" method="post" name="hiddenqueryform"
265 id="hiddenqueryform">
266 <?php echo PMA_generate_common_hidden_inputs('', ''); ?>
267 <input type="hidden" name="db" value="<?php echo htmlspecialchars($db); ?>" />
268 <input type="hidden" name="table" value="<?php echo htmlspecialchars($table); ?>" />
269 <input type="hidden" name="sql_query" value="" />
270 <input type="hidden" name="querydisplay_tab" value="<?php echo $querydisplay_tab; ?>" />
271 </form>
272 </div>
273 </body>
274 </html>