Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Newer
Older
100644 274 lines (245 sloc) 8.207 kb
905f966 Marc Delisle new
lem9 authored
1 <?php
2 /* vim: set expandtab sw=4 ts=4 sts=4: */
3 /**
4 * this file is register_globals save
5 *
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 */
43
44 /**
45 *
46 */
47 require_once './libraries/common.inc.php';
48
49 $is_superuser = PMA_isSuperuser();
50
51 /**
52 * Gets a core script and starts output buffering work
53 */
54 require_once './libraries/sql_query_form.lib.php';
55
56 /**
57 * starts output buffering if requested and supported
58 */
59 require_once './libraries/ob.lib.php';
60 PMA_outBufferPre();
61
62 /**
63 * load relations
64 */
65 require_once './libraries/relation.lib.php';
66 $cfgRelation = PMA_getRelationsParam();
67
68 /**
69 * load bookmark support
70 */
71 require_once './libraries/bookmark.lib.php';
72
73 $querydisplay_tabs = array(
74 'sql',
75 'files',
76 'history',
77 'full',
78 );
79
80 if (isset($_REQUEST['querydisplay_tab'])
81 && in_array($_REQUEST['querydisplay_tab'], $querydisplay_tabs)) {
82 $querydisplay_tab = $_REQUEST['querydisplay_tab'];
83 } else {
84 $querydisplay_tab = $GLOBALS['cfg']['QueryWindowDefTab'];
85 }
86
87 /**
88 * $_REQUEST['no_js'] is set if open new window by JavaScript failed
89 * so this page is loaded in main frame
90 */
91 $no_js = PMA_ifSetOr($_REQUEST['no_js'], false);
92
93 if ($no_js) {
94 $querydisplay_tab = 'full';
95 $tabs = false;
96 } else {
97 $tabs = array();
98 $tabs['sql']['icon'] = 'b_sql.png';
99 $tabs['sql']['text'] = $GLOBALS['strSQL'];
100 $tabs['sql']['fragment'] = '#';
101 $tabs['sql']['attr'] = 'onclick="javascript:PMA_querywindowCommit(\'sql\');return false;"';
102 $tabs['sql']['active'] = (bool) ($querydisplay_tab == 'sql');
103 $tabs['import']['icon'] = 'b_import.png';
104 $tabs['import']['text'] = $GLOBALS['strImportFiles'];
105 $tabs['import']['fragment'] = '#';
106 $tabs['import']['attr'] = 'onclick="javascript:PMA_querywindowCommit(\'files\');return false;"';
107 $tabs['import']['active'] = (bool) ($querydisplay_tab == 'files');
108 $tabs['history']['icon'] = 'b_bookmark.png';
109 $tabs['history']['text'] = $GLOBALS['strQuerySQLHistory'];
110 $tabs['history']['fragment'] = '#';
111 $tabs['history']['attr'] = 'onclick="javascript:PMA_querywindowCommit(\'history\');return false;"';
112 $tabs['history']['active'] = (bool) ($querydisplay_tab == 'history');
113
114 if ($GLOBALS['cfg']['QueryWindowDefTab'] == 'full') {
115 $tabs['all']['text'] = $GLOBALS['strAll'];
116 $tabs['all']['fragment'] = '#';
117 $tabs['all']['attr'] = 'onclick="javascript:PMA_querywindowCommit(\'full\');return false;"';
118 $tabs['all']['active'] = (bool) ($querydisplay_tab == 'full');
119 }
120 }
121
122 if ($GLOBALS['cfg']['PropertiesIconic']) {
123 $titles['Change'] =
124 '<img class="icon" width="16" height="16" src="' . $pmaThemeImage
125 . 'b_edit.png" alt="' . $GLOBALS['strChange'] . '" title="' . $GLOBALS['strChange']
126 . '" />';
127
128 if ('both' === $GLOBALS['cfg']['PropertiesIconic']) {
129 $titles['Change'] .= $GLOBALS['strChange'];
130 }
131 } else {
132 $titles['Change'] = $GLOBALS['strChange'];
133 }
134
135 $url_query = PMA_generate_common_url($db, $table);
136
137 if (! empty($sql_query)) {
138 $show_query = 1;
139 }
140
141 if ($no_js) {
142 // ... we redirect to appropriate query sql page
143 // works only full if $db and $table is also stored/grabbed from $_COOKIE
144 if (strlen($table)) {
145 require './tbl_sql.php';
146 } elseif (strlen($db)) {
147 require './db_sql.php';
148 } else {
149 require './server_sql.php';
150 }
151 exit;
152 }
153
154 /**
155 * Defines the query to be displayed in the query textarea
156 */
157 if (! empty($show_query)) {
158 $query_to_display = $sql_query;
159 } else {
160 $query_to_display = '';
161 }
162 $sql_query = '';
163
164 /**
165 * prepare JavaScript functionality
166 */
167 $js_include[] = 'common.js';
168 $js_include[] = 'functions.js';
169 $js_include[] = 'querywindow.js';
170
171 if (PMA_isValid($_REQUEST['auto_commit'], 'identical', 'true')) {
172 $js_events[] = array(
173 'object' => 'window',
174 'event' => 'load',
175 'function' => 'PMA_queryAutoCommit',
176 );
177 }
178 if (PMA_isValid($_REQUEST['init'])) {
179 $js_events[] = array(
180 'object' => 'window',
181 'event' => 'load',
182 'function' => 'PMA_querywindowResize',
183 );
184 }
185 // always set focus to the textarea
186 if ($querydisplay_tab == 'sql' || $querydisplay_tab == 'full') {
187 $js_events[] = array(
188 'object' => 'window',
189 'event' => 'load',
190 'function' => 'PMA_querywindowSetFocus',
191 );
192 }
193
194 /**
195 * start HTTP/HTML output
196 */
197 require_once './libraries/header_http.inc.php';
198 require_once './libraries/header_meta_style.inc.php';
199 require_once './libraries/header_scripts.inc.php';
200 ?>
201 </head>
202
203 <body id="bodyquerywindow">
204 <div id="querywindowcontainer">
205 <?php
206
207 if ($tabs) {
1944593 Marc Delisle forgot a parameter
lem9 authored
208 echo PMA_getTabs($tabs, array());
905f966 Marc Delisle new
lem9 authored
209 unset($tabs);
210 }
211
212 PMA_sqlQueryForm($query_to_display, $querydisplay_tab);
213
214 // Hidden forms and query frame interaction stuff
215
216 $_sql_history = PMA_getHistory($GLOBALS['cfg']['Server']['user']);
217 if (! empty($_sql_history)
218 && ($querydisplay_tab == 'history' || $querydisplay_tab == 'full')) {
219 $tab = $querydisplay_tab != 'full' ? 'sql' : 'full';
220 echo $GLOBALS['strQuerySQLHistory'] . ':<br />' . "\n"
221 .'<ul>';
222 foreach ($_sql_history as $query) {
223 echo '<li>' . "\n";
224
225 // edit link
226 $url_params = array(
227 'querydisplay_tab' => $tab,
228 'sql_query' => $query['sqlquery'],
229 'db' => $query['db'],
230 'table' => $query['table'],
231 );
232 echo '<a href="querywindow.php' . PMA_generate_common_url($url_params)
233 . '">' . $titles['Change'] . '</a>';
234
235 // execute link
236 $url_params['auto_commit'] = 'true';
237 echo '<a href="import.php' . PMA_generate_common_url($url_params) . '"'
238 . ' target="frame_content">';
239
240 if (! empty($query['db'])) {
241 echo '[';
242 echo htmlspecialchars(PMA_backquote($query['db']));
243 if (! empty($query['table'])) {
244 echo '.' . htmlspecialchars(PMA_backquote($query['table']));
245 }
246 echo '] ';
247 }
248 if (strlen($query['sqlquery']) > 120) {
249 echo '<span title="' . htmlspecialchars($query['sqlquery']) . '">';
250 echo htmlspecialchars(substr($query['sqlquery'], 0, 50)) . ' [...] ';
251 echo htmlspecialchars(substr($query['sqlquery'], -50));
252 echo '</span>';
253 } else {
254 echo htmlspecialchars($query['sqlquery']);
255 }
256 echo '</a>' . "\n";
257 echo '</li>' . "\n";
258 }
259 unset($tab, $_sql_history, $query);
260 echo '</ul>' . "\n";
261 }
262 ?>
263 <form action="querywindow.php" method="post" name="hiddenqueryform"
264 id="hiddenqueryform">
265 <?php echo PMA_generate_common_hidden_inputs('', ''); ?>
266 <input type="hidden" name="db" value="<?php echo htmlspecialchars($db); ?>" />
267 <input type="hidden" name="table" value="<?php echo htmlspecialchars($table); ?>" />
268 <input type="hidden" name="sql_query" value="" />
269 <input type="hidden" name="querydisplay_tab" value="<?php echo $querydisplay_tab; ?>" />
270 </form>
271 </div>
272 </body>
273 </html>
Something went wrong with that request. Please try again.