bug 784143
[phpmyadmin/crack.git] / querywindow.php3
blobb76fbc261017eefcb1937e01fd7467a7a11eabae
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;
42 // garvin: For re-usability, moved http-headers and stylesheets
43 // to a seperate file. It can now be included by header.inc.php3,
44 // queryframe.php3, querywindow.php3.
46 include('./libraries/header_http.inc.php3');
47 include('./libraries/header_meta_style.inc.php3');
50 <script type="text/javascript" language="javascript">
51 <?php
52 if ($cfg['QueryFrame'] && $cfg['QueryFrameJS'] && $cfg['QueryFrameDebug']) {
53 $js_db = (isset($db) ? $db : 'FALSE');
54 $js_table = (isset($table) ? $table : 'FALSE');
55 $js_server = (isset($server) ? $server : 'FALSE');
57 $js_true_db = '\' + document.querywindow.db.value + \'';
58 $js_true_table = '\' + document.querywindow.table.value + \'';
59 $js_true_server = '\' + document.querywindow.server.value + \'';
61 $js_parent = '\' + opener.location.href + \'';
62 $js_frame = '\' + opener.parent.location.href + \'';
64 function debug() {
65 alert('<?php echo sprintf($strQueryFrameDebugBox, $js_db, $js_table, $js_server, $js_true_db, $js_true_table, $js_true_server, $js_parent, $js_frame); ?>');
66 return false;
68 <?php
71 function query_auto_commit() {
72 document.sqlform.submit();
75 function query_tab_commit(tab) {
76 document.querywindow.querydisplay_tab.value = tab;
77 document.querywindow.submit();
78 return false;
81 // js form validation stuff
82 var errorMsg0 = '<?php echo str_replace('\'', '\\\'', $GLOBALS['strFormEmpty']); ?>';
83 var errorMsg1 = '<?php echo str_replace('\'', '\\\'', $GLOBALS['strNotNumber']); ?>';
84 var errorMsg2 = '<?php echo str_replace('\'', '\\\'', $GLOBALS['strNotValidNumber']); ?>';
85 var noDropDbMsg = '<?php echo((!$GLOBALS['cfg']['AllowUserDropDatabase']) ? str_replace('\'', '\\\'', $GLOBALS['strNoDropDatabases']) : ''); ?>';
86 var confirmMsg = '<?php echo(($GLOBALS['cfg']['Confirm']) ? str_replace('\'', '\\\'', $GLOBALS['strDoYouReally']) : ''); ?>';
87 //-->
88 </script>
89 <script src="libraries/functions.js" type="text/javascript" language="javascript"></script>
90 </head>
92 <body bgcolor="<?php echo ($cfg['QueryFrameJS'] ? $cfg['LeftBgColor'] : $cfg['RightBgColor']); ?>">
94 <?php
95 if ($cfg['QueryFrameJS'] && !isset($no_js)) {
96 $querydisplay_tab = (isset($querydisplay_tab) ? $querydisplay_tab : $cfg['QueryWindowDefTab']);
98 if ($cfg['LightTabs']) {
99 echo '&nbsp;';
100 } else {
101 echo '<table border="0" cellspacing="0" cellpadding="3" width="100%" class="tabs">
102 <tr>
103 <td width="8">&nbsp;</td>';
105 echo "\n";
106 echo PMA_printTab($strSQL, '#', '', 'onClick="javascript:query_tab_commit(\'sql\');return false;"', '', (isset($querydisplay_tab) && $querydisplay_tab == 'sql' ? TRUE : FALSE));
107 echo PMA_printTab($strImportFiles, '#', '', 'onClick="javascript:query_tab_commit(\'files\');return false;"', '', (isset($querydisplay_tab) && $querydisplay_tab == 'files' ? TRUE : FALSE));
108 echo PMA_printTab($strQuerySQLHistory, '#', '', 'onClick="javascript:query_tab_commit(\'history\');return false;"', '', (isset($querydisplay_tab) && $querydisplay_tab == 'history' ? TRUE : FALSE));
110 if ($cfg['QueryWindowDefTab'] == 'full') {
111 echo PMA_printTab($strAll, '#', '', 'onClick="javascript:query_tab_commit(\'full\');return false;"', '', (isset($querydisplay_tab) && $querydisplay_tab == 'full' ? TRUE : FALSE));
114 if (!$cfg['LightTabs']) {
115 echo '</tr></table>';
116 } else {
117 echo '<br />';
119 } else {
120 $querydisplay_tab = 'full';
124 <br />
126 <?php
127 // Hidden forms and query frame interaction stuff
128 if ($cfg['QueryFrame'] && $cfg['QueryFrameJS']) {
130 $input_query_history = array();
131 $sql_history = array();
132 $dup_sql = array();
134 if (isset($query_history_latest) && isset($query_history_latest_db) && $query_history_latest != '' && $query_history_latest_db != '') {
135 if ($cfg['QueryHistoryDB'] && $cfgRelation['historywork']) {
136 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);
139 $input_query_history[] = '<input type="hidden" name="query_history[]" value="' . $query_history_latest . '" />';
140 $input_query_history[] = '<input type="hidden" name="query_history_db[]" value="' . htmlspecialchars($query_history_latest_db) . '" />';
141 $input_query_history[] = '<input type="hidden" name="query_history_table[]" value="' . (isset($query_history_latest_table) ? htmlspecialchars($query_history_latest_table) : '') . '" />';
143 $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";
145 $sql_query = urldecode($query_history_latest);
146 $db = $query_history_latest_db;
147 $table = $query_history_latest_table;
148 $dup_sql[$query_history_latest] = true;
149 } elseif (isset($query_history_latest) && $query_history_latest != '') {
150 $sql_query = urldecode($query_history_latest);
153 if (isset($sql_query)) {
154 $show_query = 1;
157 if ($cfg['QueryHistoryDB'] && $cfgRelation['historywork']) {
159 $temp_history = PMA_getHistory($cfg['Server']['user']);
160 if (is_array($temp_history) && count($temp_history) > 0) {
161 @reset($temp_history);
162 while(@list($history_nr, $history_array) = @each($temp_history)) {
163 if (!isset($dup_sql[$history_array['sqlquery']])) {
164 $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";
165 $dup_sql[$history_array['sqlquery']] = true;
170 } else {
172 if (isset($query_history) && is_array($query_history)) {
173 $current_index = count($query_history);
174 @reset($query_history);
175 while(list($query_no, $query_sql) = each($query_history)) {
176 if (!isset($dup_sql[$query_sql])) {
178 $input_query_history[] = '<input type="hidden" name="query_history[]" value="' . $query_sql . '" />';
179 $input_query_history[] = '<input type="hidden" name="query_history_db[]" value="' . htmlspecialchars($query_history_db[$query_no]) . '" />';
180 $input_query_history[] = '<input type="hidden" name="query_history_table[]" value="' . (isset($query_history_table[$query_no]) ? htmlspecialchars($query_history_table[$query_no]) : '') . '" />';
182 $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";
183 $dup_sql[$query_sql] = true;
184 } // end if check if this item exists
185 } // end while print history
186 } // end if history exists
188 } // end if DB-based history
191 $url_query = PMA_generate_common_url(isset($db) ? $db : '', isset($table) ? $table : '');
192 if (!isset($goto)) {
193 $goto = '';
196 require './libraries/bookmark.lib.php3';
197 $is_inside_querywindow = TRUE;
198 require './tbl_query_box.php3';
200 // Hidden forms and query frame interaction stuff
201 if ($cfg['QueryFrame'] && $cfg['QueryFrameJS']) {
202 if (isset($auto_commit) && $auto_commit == 'true') {
204 <script type="text/javascript" language="javascript">
205 query_auto_commit();
206 </script>
207 <?php
210 if (isset($sql_history) && isset($querydisplay_tab) && ($querydisplay_tab == 'history' || $querydisplay_tab == 'full') && is_array($sql_history) && count($sql_history) > 0) {
212 <li>
213 <div style="margin-bottom: 10px"><?php echo $strQuerySQLHistory . ':<br><ul>' . implode('', $sql_history) . '</ul>'; ?></div>
214 </li>
215 <?php
218 <form action="querywindow.php3" method="post" name="querywindow">
219 <?php
220 echo PMA_generate_common_hidden_inputs('', '');
221 if (count($input_query_history) > 0) {
222 echo implode("\n", $input_query_history);
225 <input type="hidden" name="db" value="<?php echo (empty($db) ? '' : htmlspecialchars($db)); ?>" />
226 <input type="hidden" name="table" value="<?php echo (empty($table) ? '' : htmlspecialchars($table)); ?>" />
228 <input type="hidden" name="query_history_latest" value="" />
229 <input type="hidden" name="query_history_latest_db" value="" />
230 <input type="hidden" name="query_history_latest_table" value="" />
232 <input type="hidden" name="previous_db" value="<?php echo htmlspecialchars($db); ?>" />
234 <input type="hidden" name="auto_commit" value="false" />
235 <input type="hidden" name="querydisplay_tab" value="<?php echo $querydisplay_tab; ?>" />
236 </form>
237 <?php
240 /* REMOVE ME */
241 if ($cfg['QueryFrame'] && $cfg['QueryFrameJS'] && $cfg['QueryFrameDebug']) {
243 <br>
244 <center>
245 <a href='#' onClick='return debug();'><?php echo $strQueryFrameDebug; ?></a>
246 </center>
247 <?php
249 /* REMOVE ME */
252 </body>
253 </html>
255 <?php
257 * Close MySql connections
259 if (isset($dbh) && $dbh) {
260 @mysql_close($dbh);
262 if (isset($userlink) && $userlink) {
263 @mysql_close($userlink);
268 * Sends bufferized data
270 if (isset($cfg['OBGzip']) && $cfg['OBGzip']
271 && isset($ob_mode) && $ob_mode) {
272 PMA_outBufferPost($ob_mode);