Rename left.php to navigation.php and modify all calls to that. Only config variables...
[phpmyadmin/crack.git] / querywindow.php
blob25b2ccb94ded4a598534ee6da6ddb8e384966437
1 <?php
2 /* $Id$ */
3 // vim: expandtab sw=4 ts=4 sts=4:
5 require_once('./libraries/common.lib.php');
7 $is_superuser = PMA_isSuperuser();
9 /**
10 * Gets the variables sent to this script, retains the db name that may have
11 * been defined as startup option and include a core library
13 if (isset($db) && strlen($db)) {
14 $db_start = $db;
18 /**
19 * Gets a core script and starts output buffering work
21 require_once './libraries/sql_query_form.lib.php';
22 require_once('./libraries/ob.lib.php');
23 if ( $GLOBALS['cfg']['OBGzip'] ) {
24 $ob_mode = PMA_outBufferModeGet();
25 if ( $ob_mode ) {
26 PMA_outBufferPre( $ob_mode );
30 require_once('./libraries/relation.lib.php');
31 $cfgRelation = PMA_getRelationsParam();
34 // initialize some variables
35 $_sql_history = array();
36 $_input_query_history = array();
38 // garvin: For re-usability, moved http-headers and stylesheets
39 // to a seperate file. It can now be included by libraries/header.inc.php,
40 // querywindow.php.
42 require_once('./libraries/header_http.inc.php');
43 require_once('./libraries/header_meta_style.inc.php');
45 <script type="text/javascript" language="javascript">
46 //<![CDATA[
47 function query_auto_commit() {
48 document.getElementById( 'sqlqueryform' ).target = window.opener.frame_content.name;
49 document.getElementById( 'sqlqueryform' ).submit();
50 return;
53 function query_tab_commit(tab) {
54 document.getElementById('hiddenqueryform').querydisplay_tab.value = tab;
55 document.getElementById('hiddenqueryform').submit();
56 return false;
59 // js form validation stuff
60 /**/
61 var errorMsg0 = '<?php echo str_replace('\'', '\\\'', $GLOBALS['strFormEmpty']); ?>';
62 var errorMsg1 = '<?php echo str_replace('\'', '\\\'', $GLOBALS['strNotNumber']); ?>';
63 var noDropDbMsg = '<?php echo (!$is_superuser && !$GLOBALS['cfg']['AllowUserDropDatabase'])
64 ? str_replace('\'', '\\\'', $GLOBALS['strNoDropDatabases']) : ''; ?>';
65 var confirmMsg = '<?php echo $GLOBALS['cfg']['Confirm']
66 ? str_replace('\'', '\\\'', $GLOBALS['strDoYouReally']) : ''; ?>';
67 /**/
69 <?php
70 if ( empty( $querydisplay_tab ) ) {
71 $onload = 'onload="resize();"';
73 function resize() {
75 // for Gecko
76 if ( typeof( self.sizeToContent ) == 'function' ) {
77 self.sizeToContent();
78 //self.scrollbars.visible = false;
79 // give some more space ... to prevent 'fli(pp/ck)ing'
80 self.resizeBy( 10, 50 );
81 return;
84 // for IE, Opera
85 if (document.getElementById && typeof(document.getElementById('querywindowcontainer')) != 'undefined' ) {
87 // get content size
88 var newWidth = document.getElementById('querywindowcontainer').offsetWidth;
89 var newHeight = document.getElementById('querywindowcontainer').offsetHeight;
91 // set size to contentsize
92 // plus some offset for scrollbars, borders, statusbar, menus ...
93 self.resizeTo( newWidth + 45, newHeight + 75 );
96 <?php
97 } else {
98 $onload = '';
101 //]]>
102 </script>
103 <script src="./js/functions.js" type="text/javascript" language="javascript"></script>
104 </head>
106 <body id="bodyquerywindow" <?php echo $onload; ?> >
107 <div id="querywindowcontainer">
108 <?php
109 if ( !isset($no_js) ) {
110 $querydisplay_tab = (isset($querydisplay_tab) ? $querydisplay_tab : $GLOBALS['cfg']['QueryWindowDefTab']);
112 $tabs = array();
113 $tabs['sql']['icon'] = 'b_sql.png';
114 $tabs['sql']['text'] = $strSQL;
115 $tabs['sql']['link'] = '#';
116 $tabs['sql']['attr'] = 'onclick="javascript:query_tab_commit(\'sql\');return false;"';
117 $tabs['sql']['active'] = (bool) ( $querydisplay_tab == 'sql' );
118 $tabs['import']['icon'] = 'b_import.png';
119 $tabs['import']['text'] = $strImportFiles;
120 $tabs['import']['link'] = '#';
121 $tabs['import']['attr'] = 'onclick="javascript:query_tab_commit(\'files\');return false;"';
122 $tabs['import']['active'] = (bool) ( $querydisplay_tab == 'files' );
123 $tabs['history']['icon'] = 'b_bookmark.png';
124 $tabs['history']['text'] = $strQuerySQLHistory;
125 $tabs['history']['link'] = '#';
126 $tabs['history']['attr'] = 'onclick="javascript:query_tab_commit(\'history\');return false;"';
127 $tabs['history']['active'] = (bool) ( $querydisplay_tab == 'history' );
129 if ( $GLOBALS['cfg']['QueryWindowDefTab'] == 'full' ) {
130 $tabs['all']['text'] = $strAll;
131 $tabs['all']['link'] = '#';
132 $tabs['all']['attr'] = 'onclick="javascript:query_tab_commit(\'full\');return false;"';
133 $tabs['all']['active'] = (bool) ( $querydisplay_tab == 'full' );
136 echo PMA_getTabs( $tabs );
137 unset( $tabs );
138 } else {
139 $querydisplay_tab = 'full';
142 if ( true == $GLOBALS['cfg']['PropertiesIconic'] ) {
143 $titles['Change'] =
144 '<img class="icon" width="16" height="16" src="' . $pmaThemeImage
145 . 'b_edit.png" alt="' . $strChange . '" title="' . $strChange
146 . '" />';
148 if ( 'both' === $GLOBALS['cfg']['PropertiesIconic'] ) {
149 $titles['Change'] .= $strChange;
151 } else {
152 $titles['Change'] = $strChange;
155 // Hidden forms and query frame interaction stuff
157 if ( ! empty( $query_history_latest ) && ! empty( $query_history_latest_db ) ) {
158 if ( $GLOBALS['cfg']['QueryHistoryDB'] && $cfgRelation['historywork'] ) {
159 PMA_setHistory((isset($query_history_latest_db) ? $query_history_latest_db : ''),
160 (isset($query_history_latest_table) ? $query_history_latest_table : ''),
161 $GLOBALS['cfg']['Server']['user'],
162 $query_history_latest );
165 $_input_query_history[$query_history_latest] = array(
166 'db' => $query_history_latest_db,
167 'table' => isset($query_history_latest_table) ? $query_history_latest_table : '',
170 $_sql_history[$query_history_latest] = array(
171 'db' => $query_history_latest_db,
172 'table' => isset($query_history_latest_table) ? $query_history_latest_table : '',
175 $sql_query = urldecode($query_history_latest);
176 $db = $query_history_latest_db;
177 $table = $query_history_latest_table;
178 } elseif ( ! empty( $query_history_latest ) ) {
179 $sql_query = urldecode($query_history_latest);
182 if (isset($sql_query)) {
183 $show_query = 1;
186 if ( $GLOBALS['cfg']['QueryHistoryDB'] && $cfgRelation['historywork'] ) {
188 $temp_history = PMA_getHistory( $GLOBALS['cfg']['Server']['user'] );
189 if (is_array($temp_history) && count($temp_history) > 0) {
190 foreach ($temp_history AS $history_nr => $history_array) {
191 if ( ! isset( $_sql_history[$history_array['sqlquery']] ) ) {
192 $_sql_history[$history_array['sqlquery']] = array(
193 'db' => $history_array['db'],
194 'table' => isset( $history_array['table'] ) ? $history_array['table'] : '',
200 } else {
202 if (isset($query_history) && is_array($query_history)) {
203 $current_index = count($query_history);
204 foreach ($query_history AS $query_no => $query_sql) {
205 if ( ! isset( $_input_query_history[$query_sql] ) ) {
206 $_input_query_history[$query_sql] = array(
207 'db' => $query_history_db[$query_no],
208 'table' => isset($query_history_table[$query_no]) ? $query_history_table[$query_no] : '',
210 $_sql_history[$query_sql] = array(
211 'db' => $query_history_db[$query_no],
212 'table' => isset( $query_history_table[$query_no] ) ? $query_history_table[$query_no] : '',
214 } // end if check if this item exists
215 } // end while print history
216 } // end if history exists
217 } // end if DB-based history
219 $url_query = PMA_generate_common_url(isset($db) ? $db : '', isset($table) ? $table : '');
220 if (!isset($goto)) {
221 $goto = '';
224 require_once './libraries/bookmark.lib.php';
226 if (isset($no_js) && $no_js) {
227 // ... we redirect to appropriate query sql page
228 // works only full if $db and $table is also stored/grabbed from $_COOKIE
229 if ( isset( $table ) && strlen($table) ) {
230 require './tbl_properties.php';
231 } elseif ( isset($db) && strlen($db) ) {
232 require './db_details.php';
233 } else {
234 require './server_sql.php';
236 exit;
240 * Defines the query to be displayed in the query textarea
242 if ( ! empty( $show_query ) ) {
243 $query_to_display = $sql_query;
244 } else {
245 $query_to_display = '';
247 unset( $sql_query );
249 PMA_sqlQueryForm( $query_to_display, $querydisplay_tab );
251 // Hidden forms and query frame interaction stuff
252 if (isset($auto_commit) && $auto_commit == 'true') {
254 <script type="text/javascript" language="javascript">
255 //<![CDATA[
256 query_auto_commit();
257 //]]>
258 </script>
259 <?php
262 if ( count( $_sql_history ) > 0
263 && ( $querydisplay_tab == 'history' || $querydisplay_tab == 'full' ) ) {
264 $tab = isset($querydisplay_tab) && $querydisplay_tab != 'full' ? 'sql' : 'full';
265 echo $strQuerySQLHistory . ':<br />' . "\n"
266 .'<ul>';
267 foreach ( $_sql_history as $sql => $query ) {
268 echo '<li>' . "\n";
269 // edit link
270 echo '<a href="#" onclick="'
271 .' document.getElementById(\'hiddenqueryform\').'
272 .'querydisplay_tab.value = \'' . $tab . '\';'
273 .' document.getElementById(\'hiddenqueryform\').'
274 .'query_history_latest.value = \''
275 . preg_replace('/(\r|\n)+/i', '\\n',
276 PMA_jsFormat($sql, false) ) . '\';'
277 .' document.getElementById(\'hiddenqueryform\').'
278 .'auto_commit.value = \'false\';'
279 .' document.getElementById(\'hiddenqueryform\').'
280 .'db.value = \'' . htmlspecialchars( $query['db'] ) . '\';'
281 .' document.getElementById(\'hiddenqueryform\').'
282 .'query_history_latest_db.value = \''
283 . htmlspecialchars( $query['db'] ) . '\';'
284 .' document.getElementById(\'hiddenqueryform\').'
285 .'table.value = \'' . htmlspecialchars( $query['table'] ) . '\';'
286 .' document.getElementById(\'hiddenqueryform\').'
287 .'query_history_latest_table.value = \''
288 . htmlspecialchars( $query['table'] ) . '\';'
289 .' document.getElementById(\'hiddenqueryform\').submit();'
290 .' return false;">' . $titles['Change'] . '</a>';
291 // execute link
292 echo '<a href="#" onclick="'
293 .' document.getElementById(\'hiddenqueryform\').'
294 .'querydisplay_tab.value = \'' . $tab . '\';'
295 .' document.getElementById(\'hiddenqueryform\').'
296 .'query_history_latest.value = \''
297 . preg_replace('/(\r|\n)+/i', '\\r\\n',
298 PMA_jsFormat($sql, false) ) . '\';'
299 .' document.getElementById(\'hiddenqueryform\').'
300 .'auto_commit.value = \'true\';'
301 .' document.getElementById(\'hiddenqueryform\').'
302 .'db.value = \'' . htmlspecialchars( $query['db'] ) . '\';'
303 .' document.getElementById(\'hiddenqueryform\').'
304 .'query_history_latest_db.value = \''
305 . htmlspecialchars( $query['db'] ) . '\';'
306 .' document.getElementById(\'hiddenqueryform\').'
307 .'table.value = \'' . htmlspecialchars( $query['table'] ) . '\';'
308 .' document.getElementById(\'hiddenqueryform\').'
309 .'query_history_latest_table.value = \''
310 . htmlspecialchars( $query['table'] ) . '\';'
311 .' document.getElementById(\'hiddenqueryform\').submit();'
312 .' return false;">[' . htmlspecialchars( $query['db'] ) . '] '
313 . urldecode( $sql ) . '</a>' . "\n";
315 echo '</li>' . "\n";
317 unset( $tab, $_sql_history, $sql, $query );
318 echo '</ul>' . "\n";
321 <form action="querywindow.php" method="post" name="querywindow" id="hiddenqueryform">
322 <?php
323 echo PMA_generate_common_hidden_inputs('', '') . "\n";
324 foreach ( $_input_query_history as $sql => $history ) {
325 echo '<input type="hidden" name="query_history[]" value="'
326 . $sql . '" />' . "\n";
327 echo '<input type="hidden" name="query_history_db[]" value="'
328 . htmlspecialchars( $history['db'] ) . '" />' . "\n";
329 echo '<input type="hidden" name="query_history_table[]" value="'
330 . htmlspecialchars( $history['table'] ) . '" />' . "\n";
332 unset( $_input_query_history, $sql, $history );
334 <input type="hidden" name="db" value="<?php echo (! isset($db) ? '' : htmlspecialchars($db)); ?>" />
335 <input type="hidden" name="table" value="<?php echo (! isset($table) ? '' : htmlspecialchars($table)); ?>" />
337 <input type="hidden" name="query_history_latest" value="" />
338 <input type="hidden" name="query_history_latest_db" value="" />
339 <input type="hidden" name="query_history_latest_table" value="" />
341 <input type="hidden" name="previous_db" value="<?php echo htmlspecialchars($db); ?>" />
343 <input type="hidden" name="auto_commit" value="false" />
344 <input type="hidden" name="querydisplay_tab" value="<?php echo $querydisplay_tab; ?>" />
345 </form>
346 <?php
348 </div>
349 </body>
350 </html>
352 <?php
355 * Close MySql connections
357 if (isset($controllink) && $controllink) {
358 PMA_DBI_close($controllink);
360 if (isset($userlink) && $userlink) {
361 PMA_DBI_close($userlink);
366 * Sends bufferized data
368 if ( $GLOBALS['cfg']['OBGzip'] && isset( $ob_mode ) && $ob_mode ) {
369 PMA_outBufferPost($ob_mode);