Fixed bug.
[phpmyadmin/crack.git] / querywindow.php3
blob6ec71ccadd0f2990e0677ccbf5480c36446ac22d
1 <?php
2 /* $Id$ */
3 // vim: expandtab sw=4 ts=4 sts=4:
6 /**
7 * Gets the variables sent to this script, retains the db name that may have
8 * been defined as startup option and include a core library
9 */
10 require('./libraries/grab_globals.lib.php3');
11 if (!empty($db)) {
12 $db_start = $db;
16 /**
17 * Gets a core script and starts output buffering work
19 require('./libraries/common.lib.php3');
20 require('./libraries/ob.lib.php3');
21 if ($cfg['OBGzip']) {
22 $ob_mode = PMA_outBufferModeGet();
23 if ($ob_mode) {
24 PMA_outBufferPre($ob_mode);
28 require('./libraries/relation.lib.php3');
29 $cfgRelation = PMA_getRelationsParam();
31 /**
32 * Get the list and number of available databases.
33 * Skipped if no server selected: in this case no database should be displayed
34 * before the user choose among available ones at the welcome screen.
36 if ($server > 0) {
37 PMA_availableDatabases(); // this function is defined in "common.lib.php3"
38 } else {
39 $num_dbs = 0;
43 /**
44 * Send http headers
46 // Don't use cache (required for Opera)
47 $now = gmdate('D, d M Y H:i:s') . ' GMT';
48 header('Expires: ' . $now);
49 header('Last-Modified: ' . $now);
50 header('Cache-Control: no-store, no-cache, must-revalidate, pre-check=0, post-check=0, max-age=0'); // HTTP/1.1
51 header('Pragma: no-cache'); // HTTP/1.0
52 // Define the charset to be used
53 header('Content-Type: text/html; charset=' . $charset);
55 /**
56 * Displays the frame
58 // Gets the font sizes to use
59 PMA_setFontSizes();
61 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
62 "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
63 <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="<?php echo $available_languages[$lang][2]; ?>" lang="<?php echo $available_languages[$lang][2]; ?>" dir="<?php echo $text_dir; ?>">
65 <head>
66 <title>phpMyAdmin</title>
67 <meta http-equiv="Content-Type" content="text/html; charset=<?php echo $charset; ?>" />
68 <base<?php if (!empty($cfg['PmaAbsoluteUri'])) echo ' href="' . $cfg['PmaAbsoluteUri'] . '"'; ?> />
69 <style type="text/css">
70 <!--
71 body {font-family: <?php echo $left_font_family; ?>; font-size: <?php echo $font_size; ?>}
72 div {font-family: <?php echo $left_font_family; ?>; font-size: <?php echo $font_size; ?>; color: #000000}
73 .heada {font-family: <?php echo $left_font_family; ?>; font-size: <?php echo $font_size; ?>; color: #000000}
74 .headaCnt {font-family: <?php echo $left_font_family; ?>; font-size: <?php echo $font_smaller; ?>; color: #000000}
75 .parent {font-family: <?php echo $left_font_family; ?>; color: #000000; text-decoration: none}
76 .child {font-family: <?php echo $left_font_family; ?>; font-size: <?php echo $font_smaller; ?>; color: #333399; text-decoration: none}
77 .item, .item:active, .item:hover, .tblItem, .tblItem:active {font-size: <?php echo $font_smaller; ?>; color: #333399; text-decoration: none}
78 .tblItem:hover {color: #FF0000; text-decoration: underline}
79 td.tab {
80 border-top: 1px solid #999;
81 border-right: 1px solid #666;
82 border-left: 1px solid #999;
83 border-bottom: none;
84 border-radius: 2px;
85 -moz-border-radius: 2px;
87 table.tabs {
88 border-top: none;
89 border-right: none;
90 border-left: none;
91 border-bottom: 1px solid #666;
94 //-->
95 </style>
97 <script type="text/javascript" language="javascript">
98 <?php
99 if ($cfg['QueryFrame'] && $cfg['QueryFrameJS'] && $cfg['QueryFrameDebug']) {
100 $js_db = (isset($db) ? $db : 'FALSE');
101 $js_table = (isset($table) ? $table : 'FALSE');
102 $js_server = (isset($server) ? $server : 'FALSE');
104 $js_true_db = '\' + document.querywindow.db.value + \'';
105 $js_true_table = '\' + document.querywindow.table.value + \'';
106 $js_true_server = '\' + document.querywindow.server.value + \'';
108 $js_parent = '\' + opener.location.href + \'';
109 $js_frame = '\' + opener.parent.location.href + \'';
111 function debug() {
112 alert('<?php echo sprintf($strQueryFrameDebugBox, $js_db, $js_table, $js_server, $js_true_db, $js_true_table, $js_true_server, $js_parent, $js_frame); ?>');
113 return false;
115 <?php
118 function query_auto_commit() {
119 document.sqlform.submit();
122 function query_tab_commit(tab) {
123 document.querywindow.querydisplay_tab.value = tab;
124 document.querywindow.submit();
125 return false;
128 // js form validation stuff
129 var errorMsg0 = '<?php echo str_replace('\'', '\\\'', $GLOBALS['strFormEmpty']); ?>';
130 var errorMsg1 = '<?php echo str_replace('\'', '\\\'', $GLOBALS['strNotNumber']); ?>';
131 var errorMsg2 = '<?php echo str_replace('\'', '\\\'', $GLOBALS['strNotValidNumber']); ?>';
132 var noDropDbMsg = '<?php echo((!$GLOBALS['cfg']['AllowUserDropDatabase']) ? str_replace('\'', '\\\'', $GLOBALS['strNoDropDatabases']) : ''); ?>';
133 var confirmMsg = '<?php echo(($GLOBALS['cfg']['Confirm']) ? str_replace('\'', '\\\'', $GLOBALS['strDoYouReally']) : ''); ?>';
134 //-->
135 </script>
136 <script src="libraries/functions.js" type="text/javascript" language="javascript"></script>
137 </head>
139 <body bgcolor="<?php echo ($cfg['QueryFrameJS'] ? $cfg['LeftBgColor'] : $cfg['RightBgColor']); ?>">
141 <?php
142 $querydisplay_tab = (isset($querydisplay_tab) ? $querydisplay_tab : $cfg['QueryWindowDefTab']);
144 if ($cfg['LightTabs']) {
145 echo '&nbsp;';
146 } else {
147 echo '<table border="0" cellspacing="0" cellpadding="3" width="100%" class="tabs">
148 <tr>
149 <td width="8">&nbsp;</td>';
151 echo "\n";
152 echo PMA_printTab($strSQL, '#', '', 'onClick="javascript:query_tab_commit(\'sql\');return false;"', '', (isset($querydisplay_tab) && $querydisplay_tab == 'sql' ? TRUE : FALSE));
153 echo PMA_printTab($strImportFiles, '#', '', 'onClick="javascript:query_tab_commit(\'files\');return false;"', '', (isset($querydisplay_tab) && $querydisplay_tab == 'files' ? TRUE : FALSE));
154 echo PMA_printTab($strQuerySQLHistory, '#', '', 'onClick="javascript:query_tab_commit(\'history\');return false;"', '', (isset($querydisplay_tab) && $querydisplay_tab == 'history' ? TRUE : FALSE));
155 echo PMA_printTab($strAll, '#', '', 'onClick="javascript:query_tab_commit(\'full\');return false;"', '', (isset($querydisplay_tab) && $querydisplay_tab == 'full' ? TRUE : FALSE));
157 if (!$cfg['LightTabs']) {
158 echo '</tr></table>';
159 } else {
160 echo '<br />';
164 <br />
166 <?php
167 // Hidden forms and query frame interaction stuff
168 if ($cfg['QueryFrame'] && $cfg['QueryFrameJS']) {
170 $input_query_history = array();
171 $sql_history = array();
172 $dup_sql = array();
174 if (isset($query_history_latest) && isset($query_history_latest_db) && $query_history_latest != '' && $query_history_latest_db != '') {
175 if ($cfg['QueryHistoryDB'] && $cfgRelation['historywork']) {
176 PMA_setHistory((isset($query_history_latest_db) ? $query_history_latest_db : ''), (isset($query_history_latest_table) ? $query_history_latest_table : ''), $cfg['Server']['user'], $query_history_latest);
179 $input_query_history[] = '<input type="hidden" name="query_history[]" value="' . $query_history_latest . '" />';
180 $input_query_history[] = '<input type="hidden" name="query_history_db[]" value="' . htmlspecialchars($query_history_latest_db) . '" />';
181 $input_query_history[] = '<input type="hidden" name="query_history_table[]" value="' . (isset($query_history_latest_table) ? htmlspecialchars($query_history_latest_table) : '') . '" />';
183 $sql_history[] = '<li><a href="#" onClick="document.querywindow.querydisplay_tab.value = \'' . (isset($querydisplay_tab) && $querydisplay_tab != 'full' ? 'sql' : 'full') . '\'; document.querywindow.query_history_latest.value = \'' . htmlspecialchars($query_history_latest) . '\'; document.querywindow.auto_commit.value = \'true\'; document.querywindow.db.value = \'' . htmlspecialchars($query_history_latest_db) . '\'; document.querywindow.query_history_latest_db.value = \'' . htmlspecialchars($query_history_latest_db) . '\'; document.querywindow.table.value = \'' . (isset($query_history_latest_table) ? htmlspecialchars($query_history_latest_table) : '') . '\'; document.querywindow.query_history_latest_table.value = \'' . (isset($query_history_latest_table) ? htmlspecialchars($query_history_latest_table) : '') . '\'; document.querywindow.submit(); return false;">[' . htmlspecialchars($query_history_latest_db) . '] ' . urldecode($query_history_latest) . '</a></li>' . "\n";
185 $sql_query = urldecode($query_history_latest);
186 $db = $query_history_latest_db;
187 $table = $query_history_latest_table;
188 $show_query = 1;
189 $dup_sql[$query_history_latest] = true;
192 if ($cfg['QueryHistoryDB'] && $cfgRelation['historywork']) {
194 $temp_history = PMA_getHistory($cfg['Server']['user']);
195 if (is_array($temp_history) && count($temp_history) > 0) {
196 @reset($temp_history);
197 while(@list($history_nr, $history_array) = @each($temp_history)) {
198 if (!isset($dup_sql[$history_array['sqlquery']])) {
199 $sql_history[] = '<li><a href="#" onClick="document.querywindow.querydisplay_tab.value = \'' . (isset($querydisplay_tab) && $querydisplay_tab != 'full' ? 'sql' : 'full') . '\'; document.querywindow.query_history_latest.value = \'' . htmlspecialchars($history_array['sqlquery']) . '\'; document.querywindow.auto_commit.value = \'true\'; document.querywindow.db.value = \'' . htmlspecialchars($history_array['db']) . '\'; document.querywindow.query_history_latest_db.value = \'' . htmlspecialchars($history_array['db']) . '\'; document.querywindow.table.value = \'' . (isset($history_array['table']) ? htmlspecialchars($history_array['table']) : '') . '\'; document.querywindow.query_history_latest_table.value = \'' . (isset($history_array['table']) ? htmlspecialchars($history_array['table']) : '') . '\'; document.querywindow.submit(); return false;">[' . htmlspecialchars($history_array['db']) . '] ' . urldecode($history_array['sqlquery']) . '</a></li>' . "\n";
200 $dup_sql[$history_array['sqlquery']] = true;
205 } else {
207 if (isset($query_history) && is_array($query_history)) {
208 $current_index = count($query_history);
209 @reset($query_history);
210 while(list($query_no, $query_sql) = each($query_history)) {
211 if (!isset($dup_sql[$query_sql])) {
213 $input_query_history[] = '<input type="hidden" name="query_history[]" value="' . $query_sql . '" />';
214 $input_query_history[] = '<input type="hidden" name="query_history_db[]" value="' . htmlspecialchars($query_history_db[$query_no]) . '" />';
215 $input_query_history[] = '<input type="hidden" name="query_history_table[]" value="' . (isset($query_history_table[$query_no]) ? htmlspecialchars($query_history_table[$query_no]) : '') . '" />';
217 $sql_history[] = '<li><a href="#" onClick="document.querywindow.querydisplay_tab.value = \'' . (isset($querydisplay_tab) && $querydisplay_tab != 'full' ? 'sql' : 'full') . '\'; document.querywindow.query_history_latest.value = \'' . htmlspecialchars($query_sql) . '\'; document.querywindow.auto_commit.value = \'true\'; document.querywindow.db.value = \'' . htmlspecialchars($query_history_db[$query_no]) . '\'; document.querywindow.query_history_latest_db.value = \'' . htmlspecialchars($query_history_db[$query_no]) . '\'; document.querywindow.table.value = \'' . (isset($query_history_table[$query_no]) ? htmlspecialchars($query_history_table[$query_no]) : '') . '\'; document.querywindow.query_history_latest_table.value = \'' . (isset($query_history_table[$query_no]) ? htmlspecialchars($query_history_table[$query_no]) : '') . '\'; document.querywindow.submit(); return false;">[' . htmlspecialchars($query_history_db[$query_no]) . '] ' . urldecode($query_sql) . '</a></li>' . "\n";
218 $dup_sql[$query_sql] = true;
219 } // end if check if this item exists
220 } // end while print history
221 } // end if history exists
223 } // end if DB-based history
226 $url_query = PMA_generate_common_url(isset($db) ? $db : '', isset($table) ? $table : '');
227 if (!isset($goto)) {
228 $goto = '';
231 require './libraries/bookmark.lib.php3';
232 $is_inside_querywindow = TRUE;
233 require './tbl_query_box.php3';
235 // Hidden forms and query frame interaction stuff
236 if ($cfg['QueryFrame'] && $cfg['QueryFrameJS']) {
237 if (isset($auto_commit) && $auto_commit == 'true') {
239 <script type="text/javascript" language="javascript">
240 query_auto_commit();
241 </script>
242 <?php
245 if (isset($sql_history) && isset($querydisplay_tab) && ($querydisplay_tab == 'history' || $querydisplay_tab == 'full') && is_array($sql_history) && count($sql_history) > 0) {
247 <li>
248 <div style="margin-bottom: 10px"><?php echo $strQuerySQLHistory . ':<br><ul>' . implode('', $sql_history) . '</ul>'; ?></div>
249 </li>
250 <?php
253 <form action="querywindow.php3" method="post" name="querywindow">
254 <?php
255 echo PMA_generate_common_hidden_inputs('', '');
256 if (count($input_query_history) > 0) {
257 echo implode("\n", $input_query_history);
260 <input type="hidden" name="db" value="<?php echo (isset($db) && $db != '' ? $db : ''); ?>" />
261 <input type="hidden" name="table" value="<?php echo (isset($table) && $table != '' ? $table : ''); ?>" />
263 <input type="hidden" name="query_history_latest" value="" />
264 <input type="hidden" name="query_history_latest_db" value="" />
265 <input type="hidden" name="query_history_latest_table" value="" />
267 <input type="hidden" name="previous_db" value="<?php echo htmlspecialchars($db); ?>" />
269 <input type="hidden" name="auto_commit" value="false" />
270 <input type="hidden" name="querydisplay_tab" value="<?php echo $querydisplay_tab; ?>" />
271 </form>
272 <?php
275 /* REMOVE ME */
276 if ($cfg['QueryFrame'] && $cfg['QueryFrameJS'] && $cfg['QueryFrameDebug']) {
278 <br>
279 <center>
280 <a href='#' onClick='return debug();'><?php echo $strQueryFrameDebug; ?></a>
281 </center>
282 <?php
284 /* REMOVE ME */
287 </body>
288 </html>
290 <?php
292 * Close MySql connections
294 if (isset($dbh) && $dbh) {
295 @mysql_close($dbh);
297 if (isset($userlink) && $userlink) {
298 @mysql_close($userlink);
303 * Sends bufferized data
305 if (isset($cfg['OBGzip']) && $cfg['OBGzip']
306 && isset($ob_mode) && $ob_mode) {
307 PMA_outBufferPost($ob_mode);