3 // vim: expandtab sw=4 ts=4 sts=4:
5 require_once('./libraries/common.lib.php');
7 $is_superuser = PMA_isSuperuser();
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)) {
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();
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();
39 * Get the list and number of available databases.
40 * Skipped if no server selected: in this case no database should be displayed
41 * before the user choose among available ones at the welcome screen.
44 PMA_availableDatabases(); // this function is defined in "common.lib.php"
49 // garvin: For re-usability, moved http-headers and stylesheets
50 // to a seperate file. It can now be included by libraries/header.inc.php,
53 require_once('./libraries/header_http.inc.php');
54 require_once('./libraries/header_meta_style.inc.php');
56 <script type
="text/javascript" language
="javascript">
58 function query_auto_commit() {
59 document
.getElementById( 'sqlqueryform' ).target
= window
.opener
.frame_content
.name
;
60 document
.getElementById( 'sqlqueryform' ).submit();
64 function query_tab_commit(tab
) {
65 document
.getElementById('hiddenqueryform').querydisplay_tab
.value
= tab
;
66 document
.getElementById('hiddenqueryform').submit();
70 // js form validation stuff
72 var errorMsg0
= '<?php echo str_replace('\'
', '\\\'
', $GLOBALS['strFormEmpty
']); ?>';
73 var errorMsg1
= '<?php echo str_replace('\'
', '\\\'
', $GLOBALS['strNotNumber
']); ?>';
74 var noDropDbMsg
= '<?php echo (!$is_superuser && !$GLOBALS['cfg
']['AllowUserDropDatabase
'])
75 ? str_replace('\'
', '\\\'
', $GLOBALS['strNoDropDatabases
']) : ''; ?>';
76 var confirmMsg
= '<?php echo $GLOBALS['cfg
']['Confirm
']
77 ? str_replace('\'
', '\\\'
', $GLOBALS['strDoYouReally
']) : ''; ?>';
81 if ( empty( $querydisplay_tab ) ) {
82 $onload = 'onload="resize();"';
87 if ( typeof( self
.sizeToContent
) == 'function' ) {
89 //self.scrollbars.visible = false;
90 // give some more space ... to prevent 'fli(pp/ck)ing'
91 self
.resizeBy( 10, 50 );
96 if (document
.getElementById
&& typeof(document
.getElementById('querywindowcontainer')) != 'undefined' ) {
99 var newWidth
= document
.getElementById('querywindowcontainer').offsetWidth
;
100 var newHeight
= document
.getElementById('querywindowcontainer').offsetHeight
;
102 // set size to contentsize
103 // plus some offset for scrollbars, borders, statusbar, menus ...
104 self
.resizeTo( newWidth +
45, newHeight +
75 );
114 <script src
="./js/functions.js" type
="text/javascript" language
="javascript"></script
>
117 <body id
="bodyquerywindow" <?php
echo $onload; ?
> >
118 <div id
="querywindowcontainer">
120 if ( !isset($no_js) ) {
121 $querydisplay_tab = (isset($querydisplay_tab) ?
$querydisplay_tab : $GLOBALS['cfg']['QueryWindowDefTab']);
124 $tabs['sql']['icon'] = 'b_sql.png';
125 $tabs['sql']['text'] = $strSQL;
126 $tabs['sql']['link'] = '#';
127 $tabs['sql']['attr'] = 'onclick="javascript:query_tab_commit(\'sql\');return false;"';
128 $tabs['sql']['active'] = (bool) ( $querydisplay_tab == 'sql' );
129 $tabs['import']['icon'] = 'b_import.png';
130 $tabs['import']['text'] = $strImportFiles;
131 $tabs['import']['link'] = '#';
132 $tabs['import']['attr'] = 'onclick="javascript:query_tab_commit(\'files\');return false;"';
133 $tabs['import']['active'] = (bool) ( $querydisplay_tab == 'files' );
134 $tabs['history']['icon'] = 'b_bookmark.png';
135 $tabs['history']['text'] = $strQuerySQLHistory;
136 $tabs['history']['link'] = '#';
137 $tabs['history']['attr'] = 'onclick="javascript:query_tab_commit(\'history\');return false;"';
138 $tabs['history']['active'] = (bool) ( $querydisplay_tab == 'history' );
140 if ( $GLOBALS['cfg']['QueryWindowDefTab'] == 'full' ) {
141 $tabs['all']['text'] = $strAll;
142 $tabs['all']['link'] = '#';
143 $tabs['all']['attr'] = 'onclick="javascript:query_tab_commit(\'full\');return false;"';
144 $tabs['all']['active'] = (bool) ( $querydisplay_tab == 'full' );
147 echo PMA_getTabs( $tabs );
150 $querydisplay_tab = 'full';
153 if ( true == $GLOBALS['cfg']['PropertiesIconic'] ) {
155 '<img class="icon" width="16" height="16" src="' . $pmaThemeImage
156 . 'b_edit.png" alt="' . $strChange . '" title="' . $strChange
159 if ( 'both' === $GLOBALS['cfg']['PropertiesIconic'] ) {
160 $titles['Change'] .= $strChange;
163 $titles['Change'] = $strChange;
166 // Hidden forms and query frame interaction stuff
168 if ( ! empty( $query_history_latest ) && ! empty( $query_history_latest_db ) ) {
169 if ( $GLOBALS['cfg']['QueryHistoryDB'] && $cfgRelation['historywork'] ) {
170 PMA_setHistory((isset($query_history_latest_db) ?
$query_history_latest_db : ''),
171 (isset($query_history_latest_table) ?
$query_history_latest_table : ''),
172 $GLOBALS['cfg']['Server']['user'],
173 $query_history_latest );
176 $_input_query_history[$query_history_latest] = array(
177 'db' => $query_history_latest_db,
178 'table' => isset($query_history_latest_table) ?
$query_history_latest_table : '',
181 $_sql_history[$query_history_latest] = array(
182 'db' => $query_history_latest_db,
183 'table' => isset($query_history_latest_table) ?
$query_history_latest_table : '',
186 $sql_query = urldecode($query_history_latest);
187 $db = $query_history_latest_db;
188 $table = $query_history_latest_table;
189 } elseif ( ! empty( $query_history_latest ) ) {
190 $sql_query = urldecode($query_history_latest);
193 if (isset($sql_query)) {
197 if ( $GLOBALS['cfg']['QueryHistoryDB'] && $cfgRelation['historywork'] ) {
199 $temp_history = PMA_getHistory( $GLOBALS['cfg']['Server']['user'] );
200 if (is_array($temp_history) && count($temp_history) > 0) {
201 foreach ($temp_history AS $history_nr => $history_array) {
202 if ( ! isset( $_sql_history[$history_array['sqlquery']] ) ) {
203 $_sql_history[$history_array['sqlquery']] = array(
204 'db' => $history_array['db'],
205 'table' => isset( $history_array['table'] ) ?
$history_array['table'] : '',
213 if (isset($query_history) && is_array($query_history)) {
214 $current_index = count($query_history);
215 foreach ($query_history AS $query_no => $query_sql) {
216 if ( ! isset( $_input_query_history[$query_sql] ) ) {
217 $_input_query_history[$query_sql] = array(
218 'db' => $query_history_db[$query_no],
219 'table' => isset($query_history_table[$query_no]) ?
$query_history_table[$query_no] : '',
221 $_sql_history[$query_sql] = array(
222 'db' => $query_history_db[$query_no],
223 'table' => isset( $query_history_table[$query_no] ) ?
$query_history_table[$query_no] : '',
225 } // end if check if this item exists
226 } // end while print history
227 } // end if history exists
228 } // end if DB-based history
230 $url_query = PMA_generate_common_url(isset($db) ?
$db : '', isset($table) ?
$table : '');
235 require_once './libraries/bookmark.lib.php';
237 if (isset($no_js) && $no_js) {
238 // ... we redirect to appropriate query sql page
239 // works only full if $db and $table is also stored/grabbed from $_COOKIE
240 if ( isset( $table ) && strlen($table) ) {
241 require './tbl_properties.php';
242 } elseif ( isset($db) && strlen($db) ) {
243 require './db_details.php';
245 require './server_sql.php';
251 * Defines the query to be displayed in the query textarea
253 if ( ! empty( $show_query ) ) {
254 $query_to_display = $sql_query;
256 $query_to_display = '';
260 PMA_sqlQueryForm( $query_to_display, $querydisplay_tab );
262 // Hidden forms and query frame interaction stuff
263 if (isset($auto_commit) && $auto_commit == 'true') {
265 <script type
="text/javascript" language
="javascript">
273 if ( count( $_sql_history ) > 0
274 && ( $querydisplay_tab == 'history' ||
$querydisplay_tab == 'full' ) ) {
275 $tab = isset($querydisplay_tab) && $querydisplay_tab != 'full' ?
'sql' : 'full';
276 echo $strQuerySQLHistory . ':<br />' . "\n"
278 foreach ( $_sql_history as $sql => $query ) {
281 echo '<a href="#" onclick="'
282 .' document.getElementById(\'hiddenqueryform\').'
283 .'querydisplay_tab.value = \'' . $tab . '\';'
284 .' document.getElementById(\'hiddenqueryform\').'
285 .'query_history_latest.value = \''
286 . preg_replace('/(\r|\n)+/i', '\\n',
287 htmlentities( $sql, ENT_QUOTES
) ) . '\';'
288 .' document.getElementById(\'hiddenqueryform\').'
289 .'auto_commit.value = \'false\';'
290 .' document.getElementById(\'hiddenqueryform\').'
291 .'db.value = \'' . htmlspecialchars( $query['db'] ) . '\';'
292 .' document.getElementById(\'hiddenqueryform\').'
293 .'query_history_latest_db.value = \''
294 . htmlspecialchars( $query['db'] ) . '\';'
295 .' document.getElementById(\'hiddenqueryform\').'
296 .'table.value = \'' . htmlspecialchars( $query['table'] ) . '\';'
297 .' document.getElementById(\'hiddenqueryform\').'
298 .'query_history_latest_table.value = \''
299 . htmlspecialchars( $query['table'] ) . '\';'
300 .' document.getElementById(\'hiddenqueryform\').submit();'
301 .' return false;">' . $titles['Change'] . '</a>';
303 echo '<a href="#" onclick="'
304 .' document.getElementById(\'hiddenqueryform\').'
305 .'querydisplay_tab.value = \'' . $tab . '\';'
306 .' document.getElementById(\'hiddenqueryform\').'
307 .'query_history_latest.value = \''
308 . preg_replace('/(\r|\n)+/i', '\\r\\n',
309 htmlentities( $sql, ENT_QUOTES
) ) . '\';'
310 .' document.getElementById(\'hiddenqueryform\').'
311 .'auto_commit.value = \'true\';'
312 .' document.getElementById(\'hiddenqueryform\').'
313 .'db.value = \'' . htmlspecialchars( $query['db'] ) . '\';'
314 .' document.getElementById(\'hiddenqueryform\').'
315 .'query_history_latest_db.value = \''
316 . htmlspecialchars( $query['db'] ) . '\';'
317 .' document.getElementById(\'hiddenqueryform\').'
318 .'table.value = \'' . htmlspecialchars( $query['table'] ) . '\';'
319 .' document.getElementById(\'hiddenqueryform\').'
320 .'query_history_latest_table.value = \''
321 . htmlspecialchars( $query['table'] ) . '\';'
322 .' document.getElementById(\'hiddenqueryform\').submit();'
323 .' return false;">[' . htmlspecialchars( $query['db'] ) . '] '
324 . urldecode( $sql ) . '</a>' . "\n";
328 unset( $tab, $_sql_history, $sql, $query );
332 <form action
="querywindow.php" method
="post" name
="querywindow" id
="hiddenqueryform">
334 echo PMA_generate_common_hidden_inputs('', '') . "\n";
335 foreach ( $_input_query_history as $sql => $history ) {
336 echo '<input type="hidden" name="query_history[]" value="'
337 . $sql . '" />' . "\n";
338 echo '<input type="hidden" name="query_history_db[]" value="'
339 . htmlspecialchars( $history['db'] ) . '" />' . "\n";
340 echo '<input type="hidden" name="query_history_table[]" value="'
341 . htmlspecialchars( $history['table'] ) . '" />' . "\n";
343 unset( $_input_query_history, $sql, $history );
345 <input type
="hidden" name
="db" value
="<?php echo (! isset($db) ? '' : htmlspecialchars($db)); ?>" />
346 <input type
="hidden" name
="table" value
="<?php echo (! isset($table) ? '' : htmlspecialchars($table)); ?>" />
348 <input type
="hidden" name
="query_history_latest" value
="" />
349 <input type
="hidden" name
="query_history_latest_db" value
="" />
350 <input type
="hidden" name
="query_history_latest_table" value
="" />
352 <input type
="hidden" name
="previous_db" value
="<?php echo htmlspecialchars($db); ?>" />
354 <input type
="hidden" name
="auto_commit" value
="false" />
355 <input type
="hidden" name
="querydisplay_tab" value
="<?php echo $querydisplay_tab; ?>" />
366 * Close MySql connections
368 if (isset($controllink) && $controllink) {
369 PMA_DBI_close($controllink);
371 if (isset($userlink) && $userlink) {
372 PMA_DBI_close($userlink);
377 * Sends bufferized data
379 if ( $GLOBALS['cfg']['OBGzip'] && isset( $ob_mode ) && $ob_mode ) {
380 PMA_outBufferPost($ob_mode);