250 |
kaklik |
1 |
<?php |
|
|
2 |
/* $Id: querywindow.php,v 2.34 2006/01/14 23:17:15 cybot_tm Exp $ */ |
|
|
3 |
// vim: expandtab sw=4 ts=4 sts=4: |
|
|
4 |
|
|
|
5 |
require_once('./libraries/common.lib.php'); |
|
|
6 |
|
|
|
7 |
/** |
|
|
8 |
* Gets the variables sent to this script, retains the db name that may have |
|
|
9 |
* been defined as startup option and include a core library |
|
|
10 |
*/ |
|
|
11 |
if (isset($db) && strlen($db)) { |
|
|
12 |
$db_start = $db; |
|
|
13 |
} |
|
|
14 |
|
|
|
15 |
|
|
|
16 |
/** |
|
|
17 |
* Gets a core script and starts output buffering work |
|
|
18 |
*/ |
|
|
19 |
require_once './libraries/sql_query_form.lib.php'; |
|
|
20 |
require_once('./libraries/ob.lib.php'); |
|
|
21 |
if ( $GLOBALS['cfg']['OBGzip'] ) { |
|
|
22 |
$ob_mode = PMA_outBufferModeGet(); |
|
|
23 |
if ( $ob_mode ) { |
|
|
24 |
PMA_outBufferPre( $ob_mode ); |
|
|
25 |
} |
|
|
26 |
} |
|
|
27 |
|
|
|
28 |
require_once('./libraries/relation.lib.php'); |
|
|
29 |
$cfgRelation = PMA_getRelationsParam(); |
|
|
30 |
|
|
|
31 |
|
|
|
32 |
// initialize some variables |
|
|
33 |
$_sql_history = array(); |
|
|
34 |
$_input_query_history = array(); |
|
|
35 |
|
|
|
36 |
/** |
|
|
37 |
* Get the list and number of available databases. |
|
|
38 |
* Skipped if no server selected: in this case no database should be displayed |
|
|
39 |
* before the user choose among available ones at the welcome screen. |
|
|
40 |
*/ |
|
|
41 |
if ($server > 0) { |
|
|
42 |
PMA_availableDatabases(); // this function is defined in "common.lib.php" |
|
|
43 |
} else { |
|
|
44 |
$num_dbs = 0; |
|
|
45 |
} |
|
|
46 |
|
|
|
47 |
// garvin: For re-usability, moved http-headers and stylesheets |
|
|
48 |
// to a seperate file. It can now be included by libraries/header.inc.php, |
|
|
49 |
// querywindow.php. |
|
|
50 |
|
|
|
51 |
require_once('./libraries/header_http.inc.php'); |
|
|
52 |
require_once('./libraries/header_meta_style.inc.php'); |
|
|
53 |
?> |
|
|
54 |
<script type="text/javascript" language="javascript"> |
|
|
55 |
//<![CDATA[ |
|
|
56 |
function query_auto_commit() { |
|
|
57 |
document.getElementById( 'sqlqueryform' ).target = window.opener.frames[1].name; |
|
|
58 |
document.getElementById( 'sqlqueryform' ).submit(); |
|
|
59 |
return; |
|
|
60 |
} |
|
|
61 |
|
|
|
62 |
function query_tab_commit(tab) { |
|
|
63 |
document.getElementById('hiddenqueryform').querydisplay_tab.value = tab; |
|
|
64 |
document.getElementById('hiddenqueryform').submit(); |
|
|
65 |
return false; |
|
|
66 |
} |
|
|
67 |
|
|
|
68 |
// js form validation stuff |
|
|
69 |
/**/ |
|
|
70 |
var errorMsg0 = '<?php echo str_replace('\'', '\\\'', $GLOBALS['strFormEmpty']); ?>'; |
|
|
71 |
var errorMsg1 = '<?php echo str_replace('\'', '\\\'', $GLOBALS['strNotNumber']); ?>'; |
|
|
72 |
var noDropDbMsg = '<?php echo !$GLOBALS['cfg']['AllowUserDropDatabase'] |
|
|
73 |
? str_replace('\'', '\\\'', $GLOBALS['strNoDropDatabases']) : ''; ?>'; |
|
|
74 |
var confirmMsg = '<?php echo $GLOBALS['cfg']['Confirm'] |
|
|
75 |
? str_replace('\'', '\\\'', $GLOBALS['strDoYouReally']) : ''; ?>'; |
|
|
76 |
/**/ |
|
|
77 |
|
|
|
78 |
<?php |
|
|
79 |
if ( empty( $querydisplay_tab ) ) { |
|
|
80 |
$onload = 'onload="resize();"'; |
|
|
81 |
?> |
|
|
82 |
function resize() { |
|
|
83 |
|
|
|
84 |
// for Gecko |
|
|
85 |
if ( typeof( self.sizeToContent ) == 'function' ) { |
|
|
86 |
self.sizeToContent(); |
|
|
87 |
//self.scrollbars.visible = false; |
|
|
88 |
// give some more space ... to prevent 'fli(pp/ck)ing' |
|
|
89 |
self.resizeBy( 10, 50 ); |
|
|
90 |
return; |
|
|
91 |
} |
|
|
92 |
|
|
|
93 |
// for IE, Opera |
|
|
94 |
if (document.getElementById && typeof(document.getElementById('querywindowcontainer')) != 'undefined' ) { |
|
|
95 |
|
|
|
96 |
// get content size |
|
|
97 |
var newWidth = document.getElementById('querywindowcontainer').offsetWidth; |
|
|
98 |
var newHeight = document.getElementById('querywindowcontainer').offsetHeight; |
|
|
99 |
|
|
|
100 |
// set size to contentsize |
|
|
101 |
// plus some offset for scrollbars, borders, statusbar, menus ... |
|
|
102 |
self.resizeTo( newWidth + 45, newHeight + 75 ); |
|
|
103 |
} |
|
|
104 |
} |
|
|
105 |
<?php |
|
|
106 |
} else { |
|
|
107 |
$onload = ''; |
|
|
108 |
} |
|
|
109 |
?> |
|
|
110 |
//]]> |
|
|
111 |
</script> |
|
|
112 |
<script src="./js/functions.js" type="text/javascript" language="javascript"></script> |
|
|
113 |
</head> |
|
|
114 |
|
|
|
115 |
<body id="bodyquerywindow" <?php echo $onload; ?> > |
|
|
116 |
<div id="querywindowcontainer"> |
|
|
117 |
<?php |
|
|
118 |
if ( !isset($no_js) ) { |
|
|
119 |
$querydisplay_tab = (isset($querydisplay_tab) ? $querydisplay_tab : $GLOBALS['cfg']['QueryWindowDefTab']); |
|
|
120 |
|
|
|
121 |
$tabs = array(); |
|
|
122 |
$tabs['sql']['icon'] = 'b_sql.png'; |
|
|
123 |
$tabs['sql']['text'] = $strSQL; |
|
|
124 |
$tabs['sql']['link'] = '#'; |
|
|
125 |
$tabs['sql']['attr'] = 'onclick="javascript:query_tab_commit(\'sql\');return false;"'; |
|
|
126 |
$tabs['sql']['active'] = (bool) ( $querydisplay_tab == 'sql' ); |
|
|
127 |
$tabs['import']['icon'] = 'b_import.png'; |
|
|
128 |
$tabs['import']['text'] = $strImportFiles; |
|
|
129 |
$tabs['import']['link'] = '#'; |
|
|
130 |
$tabs['import']['attr'] = 'onclick="javascript:query_tab_commit(\'files\');return false;"'; |
|
|
131 |
$tabs['import']['active'] = (bool) ( $querydisplay_tab == 'files' ); |
|
|
132 |
$tabs['history']['icon'] = 'b_bookmark.png'; |
|
|
133 |
$tabs['history']['text'] = $strQuerySQLHistory; |
|
|
134 |
$tabs['history']['link'] = '#'; |
|
|
135 |
$tabs['history']['attr'] = 'onclick="javascript:query_tab_commit(\'history\');return false;"'; |
|
|
136 |
$tabs['history']['active'] = (bool) ( $querydisplay_tab == 'history' ); |
|
|
137 |
|
|
|
138 |
if ( $GLOBALS['cfg']['QueryWindowDefTab'] == 'full' ) { |
|
|
139 |
$tabs['all']['text'] = $strAll; |
|
|
140 |
$tabs['all']['link'] = '#'; |
|
|
141 |
$tabs['all']['attr'] = 'onclick="javascript:query_tab_commit(\'full\');return false;"'; |
|
|
142 |
$tabs['all']['active'] = (bool) ( $querydisplay_tab == 'full' ); |
|
|
143 |
} |
|
|
144 |
|
|
|
145 |
echo PMA_getTabs( $tabs ); |
|
|
146 |
unset( $tabs ); |
|
|
147 |
} else { |
|
|
148 |
$querydisplay_tab = 'full'; |
|
|
149 |
} |
|
|
150 |
|
|
|
151 |
if ( true == $GLOBALS['cfg']['PropertiesIconic'] ) { |
|
|
152 |
$titles['Change'] = |
|
|
153 |
'<img class="icon" width="16" height="16" src="' . $pmaThemeImage |
|
|
154 |
. 'b_edit.png" alt="' . $strChange . '" title="' . $strChange |
|
|
155 |
. '" />'; |
|
|
156 |
|
|
|
157 |
if ( 'both' === $GLOBALS['cfg']['PropertiesIconic'] ) { |
|
|
158 |
$titles['Change'] .= $strChange; |
|
|
159 |
} |
|
|
160 |
} else { |
|
|
161 |
$titles['Change'] = $strChange; |
|
|
162 |
} |
|
|
163 |
|
|
|
164 |
// Hidden forms and query frame interaction stuff |
|
|
165 |
|
|
|
166 |
if ( ! empty( $query_history_latest ) && ! empty( $query_history_latest_db ) ) { |
|
|
167 |
if ( $GLOBALS['cfg']['QueryHistoryDB'] && $cfgRelation['historywork'] ) { |
|
|
168 |
PMA_setHistory((isset($query_history_latest_db) ? $query_history_latest_db : ''), |
|
|
169 |
(isset($query_history_latest_table) ? $query_history_latest_table : ''), |
|
|
170 |
$GLOBALS['cfg']['Server']['user'], |
|
|
171 |
$query_history_latest ); |
|
|
172 |
} |
|
|
173 |
|
|
|
174 |
$_input_query_history[$query_history_latest] = array( |
|
|
175 |
'db' => $query_history_latest_db, |
|
|
176 |
'table' => isset($query_history_latest_table) ? $query_history_latest_table : '', |
|
|
177 |
); |
|
|
178 |
|
|
|
179 |
$_sql_history[$query_history_latest] = array( |
|
|
180 |
'db' => $query_history_latest_db, |
|
|
181 |
'table' => isset($query_history_latest_table) ? $query_history_latest_table : '', |
|
|
182 |
); |
|
|
183 |
|
|
|
184 |
$sql_query = urldecode($query_history_latest); |
|
|
185 |
$db = $query_history_latest_db; |
|
|
186 |
$table = $query_history_latest_table; |
|
|
187 |
} elseif ( ! empty( $query_history_latest ) ) { |
|
|
188 |
$sql_query = urldecode($query_history_latest); |
|
|
189 |
} |
|
|
190 |
|
|
|
191 |
if (isset($sql_query)) { |
|
|
192 |
$show_query = 1; |
|
|
193 |
} |
|
|
194 |
|
|
|
195 |
if ( $GLOBALS['cfg']['QueryHistoryDB'] && $cfgRelation['historywork'] ) { |
|
|
196 |
|
|
|
197 |
$temp_history = PMA_getHistory( $GLOBALS['cfg']['Server']['user'] ); |
|
|
198 |
if (is_array($temp_history) && count($temp_history) > 0) { |
|
|
199 |
foreach ($temp_history AS $history_nr => $history_array) { |
|
|
200 |
if ( ! isset( $_sql_history[$history_array['sqlquery']] ) ) { |
|
|
201 |
$_sql_history[$history_array['sqlquery']] = array( |
|
|
202 |
'db' => $history_array['db'], |
|
|
203 |
'table' => isset( $history_array['table'] ) ? $history_array['table'] : '', |
|
|
204 |
); |
|
|
205 |
} |
|
|
206 |
} |
|
|
207 |
} |
|
|
208 |
|
|
|
209 |
} else { |
|
|
210 |
|
|
|
211 |
if (isset($query_history) && is_array($query_history)) { |
|
|
212 |
$current_index = count($query_history); |
|
|
213 |
foreach ($query_history AS $query_no => $query_sql) { |
|
|
214 |
if ( ! isset( $_input_query_history[$query_sql] ) ) { |
|
|
215 |
$_input_query_history[$query_sql] = array( |
|
|
216 |
'db' => $query_history_db[$query_no], |
|
|
217 |
'table' => isset($query_history_table[$query_no]) ? $query_history_table[$query_no] : '', |
|
|
218 |
); |
|
|
219 |
$_sql_history[$query_sql] = array( |
|
|
220 |
'db' => $query_history_db[$query_no], |
|
|
221 |
'table' => isset( $query_history_table[$query_no] ) ? $query_history_table[$query_no] : '', |
|
|
222 |
); |
|
|
223 |
} // end if check if this item exists |
|
|
224 |
} // end while print history |
|
|
225 |
} // end if history exists |
|
|
226 |
} // end if DB-based history |
|
|
227 |
|
|
|
228 |
$url_query = PMA_generate_common_url(isset($db) ? $db : '', isset($table) ? $table : ''); |
|
|
229 |
if (!isset($goto)) { |
|
|
230 |
$goto = ''; |
|
|
231 |
} |
|
|
232 |
|
|
|
233 |
require_once './libraries/bookmark.lib.php'; |
|
|
234 |
|
|
|
235 |
if (isset($no_js) && $no_js) { |
|
|
236 |
// ... we redirect to appropriate query sql page |
|
|
237 |
// works only full if $db and $table is also stored/grabbed from $_COOKIE |
|
|
238 |
if ( isset( $table ) && strlen($table) ) { |
|
|
239 |
require './tbl_properties.php'; |
|
|
240 |
} elseif ( isset($db) && strlen($db) ) { |
|
|
241 |
require './db_details.php'; |
|
|
242 |
} else { |
|
|
243 |
require './server_sql.php'; |
|
|
244 |
} |
|
|
245 |
exit; |
|
|
246 |
} |
|
|
247 |
|
|
|
248 |
/** |
|
|
249 |
* Defines the query to be displayed in the query textarea |
|
|
250 |
*/ |
|
|
251 |
if ( ! empty( $show_query ) ) { |
|
|
252 |
$query_to_display = $sql_query; |
|
|
253 |
} else { |
|
|
254 |
$query_to_display = ''; |
|
|
255 |
} |
|
|
256 |
unset( $sql_query ); |
|
|
257 |
|
|
|
258 |
PMA_sqlQueryForm( $query_to_display, $querydisplay_tab ); |
|
|
259 |
|
|
|
260 |
// Hidden forms and query frame interaction stuff |
|
|
261 |
if (isset($auto_commit) && $auto_commit == 'true') { |
|
|
262 |
?> |
|
|
263 |
<script type="text/javascript" language="javascript"> |
|
|
264 |
//<![CDATA[ |
|
|
265 |
query_auto_commit(); |
|
|
266 |
//]]> |
|
|
267 |
</script> |
|
|
268 |
<?php |
|
|
269 |
} |
|
|
270 |
|
|
|
271 |
if ( count( $_sql_history ) > 0 |
|
|
272 |
&& ( $querydisplay_tab == 'history' || $querydisplay_tab == 'full' ) ) { |
|
|
273 |
$tab = isset($querydisplay_tab) && $querydisplay_tab != 'full' ? 'sql' : 'full'; |
|
|
274 |
echo $strQuerySQLHistory . ':<br />' . "\n" |
|
|
275 |
.'<ul>'; |
|
|
276 |
foreach ( $_sql_history as $sql => $query ) { |
|
|
277 |
echo '<li>' . "\n"; |
|
|
278 |
// edit link |
|
|
279 |
echo '<a href="#" onclick="' |
|
|
280 |
.' document.getElementById(\'hiddenqueryform\').' |
|
|
281 |
.'querydisplay_tab.value = \'' . $tab . '\';' |
|
|
282 |
.' document.getElementById(\'hiddenqueryform\').' |
|
|
283 |
.'query_history_latest.value = \'' |
|
|
284 |
. preg_replace('/(\r|\n)+/i', '\\n', |
|
|
285 |
htmlentities( $sql, ENT_QUOTES ) ) . '\';' |
|
|
286 |
.' document.getElementById(\'hiddenqueryform\').' |
|
|
287 |
.'auto_commit.value = \'false\';' |
|
|
288 |
.' document.getElementById(\'hiddenqueryform\').' |
|
|
289 |
.'db.value = \'' . htmlspecialchars( $query['db'] ) . '\';' |
|
|
290 |
.' document.getElementById(\'hiddenqueryform\').' |
|
|
291 |
.'query_history_latest_db.value = \'' |
|
|
292 |
. htmlspecialchars( $query['db'] ) . '\';' |
|
|
293 |
.' document.getElementById(\'hiddenqueryform\').' |
|
|
294 |
.'table.value = \'' . htmlspecialchars( $query['table'] ) . '\';' |
|
|
295 |
.' document.getElementById(\'hiddenqueryform\').' |
|
|
296 |
.'query_history_latest_table.value = \'' |
|
|
297 |
. htmlspecialchars( $query['table'] ) . '\';' |
|
|
298 |
.' document.getElementById(\'hiddenqueryform\').submit();' |
|
|
299 |
.' return false;">' . $titles['Change'] . '</a>'; |
|
|
300 |
// execute link |
|
|
301 |
echo '<a href="#" onclick="' |
|
|
302 |
.' document.getElementById(\'hiddenqueryform\').' |
|
|
303 |
.'querydisplay_tab.value = \'' . $tab . '\';' |
|
|
304 |
.' document.getElementById(\'hiddenqueryform\').' |
|
|
305 |
.'query_history_latest.value = \'' |
|
|
306 |
. preg_replace('/(\r|\n)+/i', '\\r\\n', |
|
|
307 |
htmlentities( $sql, ENT_QUOTES ) ) . '\';' |
|
|
308 |
.' document.getElementById(\'hiddenqueryform\').' |
|
|
309 |
.'auto_commit.value = \'true\';' |
|
|
310 |
.' document.getElementById(\'hiddenqueryform\').' |
|
|
311 |
.'db.value = \'' . htmlspecialchars( $query['db'] ) . '\';' |
|
|
312 |
.' document.getElementById(\'hiddenqueryform\').' |
|
|
313 |
.'query_history_latest_db.value = \'' |
|
|
314 |
. htmlspecialchars( $query['db'] ) . '\';' |
|
|
315 |
.' document.getElementById(\'hiddenqueryform\').' |
|
|
316 |
.'table.value = \'' . htmlspecialchars( $query['table'] ) . '\';' |
|
|
317 |
.' document.getElementById(\'hiddenqueryform\').' |
|
|
318 |
.'query_history_latest_table.value = \'' |
|
|
319 |
. htmlspecialchars( $query['table'] ) . '\';' |
|
|
320 |
.' document.getElementById(\'hiddenqueryform\').submit();' |
|
|
321 |
.' return false;">[' . htmlspecialchars( $query['db'] ) . '] ' |
|
|
322 |
. urldecode( $sql ) . '</a>' . "\n"; |
|
|
323 |
|
|
|
324 |
echo '</li>' . "\n"; |
|
|
325 |
} |
|
|
326 |
unset( $tab, $_sql_history, $sql, $query ); |
|
|
327 |
echo '</ul>' . "\n"; |
|
|
328 |
} |
|
|
329 |
?> |
|
|
330 |
<form action="querywindow.php" method="post" name="querywindow" id="hiddenqueryform"> |
|
|
331 |
<?php |
|
|
332 |
echo PMA_generate_common_hidden_inputs('', '') . "\n"; |
|
|
333 |
foreach ( $_input_query_history as $sql => $history ) { |
|
|
334 |
echo '<input type="hidden" name="query_history[]" value="' |
|
|
335 |
. $sql . '" />' . "\n"; |
|
|
336 |
echo '<input type="hidden" name="query_history_db[]" value="' |
|
|
337 |
. htmlspecialchars( $history['db'] ) . '" />' . "\n"; |
|
|
338 |
echo '<input type="hidden" name="query_history_table[]" value="' |
|
|
339 |
. htmlspecialchars( $history['table'] ) . '" />' . "\n"; |
|
|
340 |
} |
|
|
341 |
unset( $_input_query_history, $sql, $history ); |
|
|
342 |
?> |
|
|
343 |
<input type="hidden" name="db" value="<?php echo (! isset($db) ? '' : htmlspecialchars($db)); ?>" /> |
|
|
344 |
<input type="hidden" name="table" value="<?php echo (! isset($table) ? '' : htmlspecialchars($table)); ?>" /> |
|
|
345 |
|
|
|
346 |
<input type="hidden" name="query_history_latest" value="" /> |
|
|
347 |
<input type="hidden" name="query_history_latest_db" value="" /> |
|
|
348 |
<input type="hidden" name="query_history_latest_table" value="" /> |
|
|
349 |
|
|
|
350 |
<input type="hidden" name="previous_db" value="<?php echo htmlspecialchars($db); ?>" /> |
|
|
351 |
|
|
|
352 |
<input type="hidden" name="auto_commit" value="false" /> |
|
|
353 |
<input type="hidden" name="querydisplay_tab" value="<?php echo $querydisplay_tab; ?>" /> |
|
|
354 |
</form> |
|
|
355 |
<?php |
|
|
356 |
?> |
|
|
357 |
</div> |
|
|
358 |
</body> |
|
|
359 |
</html> |
|
|
360 |
|
|
|
361 |
<?php |
|
|
362 |
|
|
|
363 |
/** |
|
|
364 |
* Close MySql connections |
|
|
365 |
*/ |
|
|
366 |
if (isset($controllink) && $controllink) { |
|
|
367 |
PMA_DBI_close($controllink); |
|
|
368 |
} |
|
|
369 |
if (isset($userlink) && $userlink) { |
|
|
370 |
PMA_DBI_close($userlink); |
|
|
371 |
} |
|
|
372 |
|
|
|
373 |
|
|
|
374 |
/** |
|
|
375 |
* Sends bufferized data |
|
|
376 |
*/ |
|
|
377 |
if ( $GLOBALS['cfg']['OBGzip'] && isset( $ob_mode ) && $ob_mode ) { |
|
|
378 |
PMA_outBufferPost($ob_mode); |
|
|
379 |
} |
|
|
380 |
?> |