3 // vim: expandtab sw=4 ts=4 sts=4:
7 require_once('./libraries/common.lib.php');
8 require_once('./libraries/bookmark.lib.php');
10 if (!($cfg['QueryFrame'] && $cfg['QueryFrameJS'] && isset($is_inside_querywindow) && $is_inside_querywindow == TRUE && isset($querydisplay_tab) && ($querydisplay_tab == 'sql' ||
$querydisplay_tab == 'full'))) {
11 PMA_checkParameters(array('db','table','url_query'));
15 * Defines the query to be displayed in the query textarea
17 if (isset($show_query) && $show_query == '1') {
18 // This script has been called by read_dump.php
19 if (isset($sql_query_cpy)) {
20 $query_to_display = $sql_query_cpy;
24 $query_to_display = $sql_query;
27 $query_to_display = '';
32 * Get the list and number of fields
35 if (isset($db) && isset($table) && $table != '' && $db != '') {
36 $local_query = 'SHOW FIELDS FROM ' . PMA_backquote($table) . ' FROM ' . PMA_backquote($db);
37 $result = @PMA_mysql_query
($local_query);
39 PMA_mysqlDie('', $local_query, '', $err_url);
42 $fields_cnt = mysql_num_rows($result);
43 while ($row = PMA_mysql_fetch_array($result)) {
44 $fields_list[] = $row['Field'];
46 mysql_free_result($result);
53 // loic1: defines wether file upload is available or not
54 // ($is_upload now defined in common.lib.php)
56 if ($cfg['QueryFrame'] && $cfg['QueryFrameJS'] && isset($is_inside_querywindow) && $is_inside_querywindow == TRUE && isset($querydisplay_tab) && ($querydisplay_tab == 'sql' ||
$querydisplay_tab == 'full')) {
57 $locking = 'onKeyPress="document.sqlform.elements[\'LockFromUpdate\'].checked = true;"';
62 $auto_sel = ($cfg['TextareaAutoSelect']
63 // 2003-02-05 rabus: This causes big trouble with Opera 7 for
64 // Windows, so let's disable it there...
65 && !(PMA_USR_OS
== 'Win' && PMA_USR_BROWSER_AGENT
== 'OPERA' && PMA_USR_BROWSER_VER
>= 7))
66 ?
"\n" . ' onfocus="if (typeof(document.layers) == \'undefined\' || typeof(textarea_selected) == \'undefined\') {textarea_selected = 1; document.sqlform.elements[\'sql_query\'].select();}"'
68 $auto_sel .= ' ' . $locking;
70 // garvin: If non-JS query window is embedded, display a list of databases to choose from.
71 // Apart from that, a non-js query window sucks badly.
73 if ($cfg['QueryFrame'] && (!$cfg['QueryFrameJS'] && !$db ||
($cfg['QueryFrameJS'] && !$db))) {
75 * Get the list and number of available databases.
78 PMA_availableDatabases(); // this function is defined in "common.lib.php"
84 $queryframe_db_list = '<select size=1 name="db">';
85 for ($i = 0; $i < $num_dbs; $i++
) {
87 $queryframe_db_list .= '<option value="' . htmlspecialchars($t_db) . '">' . htmlspecialchars($t_db) . '</option>';
89 $queryframe_db_list .= '</select>';
91 $queryframe_db_list = '';
94 $queryframe_db_list = '';
99 if ($cfg['QueryFrame'] && $cfg['QueryFrameJS'] && isset($is_inside_querywindow) && $is_inside_querywindow) {
101 <script type
="text/javascript">
103 document
.writeln('<form method="post" target="phpmain' +
<?php
echo ((isset($is_inside_querywindow) && $is_inside_querywindow == TRUE) ?
'opener.' : '');?
>parent
.frames
.queryframe
.document
.hashform
.hash
.value +
'" action="read_dump.php"<?php if ($is_upload) echo ' enctype
="multipart/form-data"'; ?> onsubmit="return checkSqlQuery(this)" name="sqlform">');
107 <form method
="post" target
="phpmain<?php echo md5($cfg['PmaAbsoluteUri']); ?>" action
="read_dump.php"<?php
if ($is_upload) echo ' enctype="multipart/form-data"'; ?
> name
="sqlform">
112 <form method
="post" action
="read_dump.php"<?php
if ($is_upload) echo ' enctype="multipart/form-data"'; ?
> onsubmit
="return checkSqlQuery(this)" name
="sqlform">
116 <input type
="hidden" name
="is_js_confirmed" value
="0" />
117 <?php
echo PMA_generate_common_hidden_inputs($db, $table); ?
>
118 <input type
="hidden" name
="pos" value
="0" />
119 <input type
="hidden" name
="goto" value
="<?php echo $goto; ?>" />
120 <input type
="hidden" name
="zero_rows" value
="<?php echo $strSuccess; ?>" />
121 <input type
="hidden" name
="prev_sql_query" value
="<?php echo ((!empty($query_to_display)) ? urlencode($query_to_display) : ''); ?>" />
123 if (!isset($is_inside_querywindow) ||
124 (isset($is_inside_querywindow) && $is_inside_querywindow == TRUE && isset($querydisplay_tab) && ($querydisplay_tab == 'sql' ||
$querydisplay_tab == 'full'))) {
126 <!-- Query box
and bookmark support
-->
128 if (isset($is_inside_querywindow) && $is_inside_querywindow == TRUE) {
130 <input type
="hidden" name
="focus_querywindow" value
="true" />
134 <a name
="querybox"></a
>
135 <table cellpadding
="1" cellspacing
="1">
138 <?php
echo sprintf($strRunSQLQuery, htmlspecialchars($db)) . $queryframe_db_list . (isset($is_inside_querywindow) ?
'<br />' : ' ') . PMA_showMySQLDocu('Reference', 'SELECT'); ?
>
140 <textarea name
="sql_query" rows
="<?php echo $cfg['TextareaRows']; ?>" cols
="<?php echo (isset($is_inside_querywindow) && $is_inside_querywindow == TRUE ? ceil($cfg['TextareaCols'] * 1.25) : $cfg['TextareaCols'] * 2); ?>" wrap
="virtual" dir
="<?php echo $text_dir; ?>"<?php
echo $auto_sel; ?
>>
142 if (!empty($query_to_display)) {
143 echo htmlspecialchars($query_to_display);
144 } elseif (isset($table)) {
145 echo htmlspecialchars(str_replace('%d', PMA_backquote($db), str_replace('%t', PMA_backquote($table), $cfg['DefaultQueryTable'])));
147 echo htmlspecialchars(str_replace('%d', PMA_backquote($db), $cfg['DefaultQueryDatabase']));
151 <?php
if (isset($table) && $fields_cnt > 0) { ?
>
152 <td align
="center" valign
="top"><?php
echo (isset($is_inside_querywindow) ?
'<br />' : '') . $strFields; ?
>:<br
/>
153 <select name
="dummy" size
="4" multiple
>
156 for ($i = 0 ; $i < $fields_cnt; $i++
) {
158 . '<option value="' . PMA_backquote(htmlspecialchars($fields_list[$i])) . '">' . htmlspecialchars($fields_list[$i]) . '</option>' . "\n";
161 </select
><br
/><br
/>
162 <input type
="button" name
="insert" value
="<?php echo($strInsert); ?>" onclick
="insertValueQuery()" />
169 <input type
="checkbox" name
="show_query" value
="1" id
="checkbox_show_query" checked
="checked" /> 
;
170 <label
for="checkbox_show_query"><?php
echo $strShowThisQuery; ?
></label
><br
/>
172 if (isset($is_inside_querywindow) && $is_inside_querywindow == TRUE) {
174 <script type
="text/javascript">
175 document
.writeln('<input type="checkbox" name="LockFromUpdate" value="1" id="checkbox_lock" /> ');
176 document
.writeln(' <label for="checkbox_lock"><?php echo $strQueryWindowLock; ?></label><br />');
187 <input type
="hidden" name
="sql_query" value
="" />
188 <input type
="hidden" name
="show_query" value
="1" />
192 // loic1: displays import dump feature only if file upload available
193 if ($is_upload && (!isset($is_inside_querywindow) ||
194 (isset($is_inside_querywindow) && $is_inside_querywindow == TRUE && isset($querydisplay_tab) && ($querydisplay_tab == 'files' ||
$querydisplay_tab == 'full')))) {
196 echo ' ' . ((isset($is_inside_querywindow) && $is_inside_querywindow == TRUE && isset($querydisplay_tab) && $querydisplay_tab == 'full') ||
!isset($is_inside_querywindow) ?
'<i>' . $strOr . '</i>' : '') . ' ' . $strLocationTextfile . ' :<br />' . "\n";
198 <div style
="margin-bottom: 5px">
199 <input type
="file" name
="sql_file" class="textfield" /><br
/>
201 if (isset($is_inside_querywindow) && $is_inside_querywindow == TRUE) {
203 <input type
="hidden" name
="focus_querywindow" value
="true" />
207 $is_gzip = ($cfg['GZipDump'] && @function_exists
('gzopen'));
208 $is_bzip = ($cfg['BZipDump'] && @function_exists
('bzdecompress'));
209 if ($is_bzip ||
$is_gzip) {
210 echo ' ' . $strCompression . ':' . "\n"
211 . ' <input type="radio" id="radio_sql_file_compression_auto" name="sql_file_compression" value="" checked="checked" />' . "\n"
212 . ' <label for="radio_sql_file_compression_auto">' . $strAutodetect . '</label> ' . "\n"
213 . ' <input type="radio" id="radio_sql_file_compression_plain" name="sql_file_compression" value="text/plain" />' . "\n"
214 . ' <label for="radio_sql_file_compression_plain">' . $strNone . '</label> ' . "\n";
216 echo ' <input type="radio" id="radio_sql_file_compression_gzip" name="sql_file_compression" value="application/x-gzip" />' . "\n"
217 . ' <label for="radio_sql_file_compression_gzip">' . $strGzip . '</label> ' . "\n";
220 echo ' <input type="radio" id="radio_sql_file_compression_bzip" name="sql_file_compression" value="application/x-bzip" />' . "\n"
221 . ' <label for="radio_sql_file_compression_bzip">' . $strBzip . '</label> ' . "\n";
224 echo ' <input type="hidden" name="sql_file_compression" value="text/plain" />' . "\n";
232 // web-server upload directory
233 $is_upload_dir = false;
234 if (!empty($cfg['UploadDir']) && !isset($is_inside_querywindow) ||
235 (!empty($cfg['UploadDir']) && isset($is_inside_querywindow) && $is_inside_querywindow == TRUE && isset($querydisplay_tab) && ($querydisplay_tab == 'files' ||
$querydisplay_tab == 'full'))) {
237 if (substr($cfg['UploadDir'], -1) != '/') {
238 $cfg['UploadDir'] .= '/';
240 if ($handle = @opendir
($cfg['UploadDir'])) {
241 if (isset($is_inside_querywindow) && $is_inside_querywindow == TRUE) {
243 <input type
="hidden" name
="focus_querywindow" value
="true" />
248 while ($file = @readdir
($handle)) {
249 if (is_file($cfg['UploadDir'] . $file) && PMA_checkFileExtensions($file, '.sql')) {
250 if ($is_first == 0) {
251 $is_upload_dir = true;
253 echo ' ' . ((isset($is_inside_querywindow) && $is_inside_querywindow == TRUE && isset($querydisplay_tab) && $querydisplay_tab == 'full') ||
!isset($is_inside_querywindow) ?
'<i>' . $strOr . '</i>' : '') . ' ' . $strWebServerUploadDirectory . ' :<br />' . "\n";
254 echo ' <div style="margin-bottom: 5px">' . "\n";
255 echo ' <select size="1" name="sql_localfile">' . "\n";
256 echo ' <option value="" selected="selected"></option>' . "\n";
258 } // end if (is_first)
259 echo ' <option value="' . htmlspecialchars($file) . '">' . htmlspecialchars($file) . '</option>' . "\n";
261 } // end if (is_file)
264 echo ' </select>' . "\n"
265 . ' </div>' . "\n\n";
266 } // end if (isfirst > 0)
269 echo ' <div style="margin-bottom: 5px">' . "\n";
270 echo ' <font color="red">' . $strError . '</font><br />' . "\n";
271 echo ' ' . $strWebServerUploadDirectoryError . "\n";
272 echo ' </div>' . "\n";
274 } // end if (web-server upload directory)
277 // Encoding setting form appended by Y.Kawada
278 if (function_exists('PMA_set_enc_form')) {
279 echo PMA_set_enc_form(' ');
283 // Charset conversion options
284 if (($is_upload ||
$is_upload_dir) &&
285 (!isset($is_inside_querywindow) ||
286 (isset($is_inside_querywindow) && $is_inside_querywindow == TRUE && isset($querydisplay_tab) && ($querydisplay_tab == 'files' ||
$querydisplay_tab == 'full')))
287 && isset($db) && $db != ''){
288 if ($cfg['AllowAnywhereRecoding'] && $allow_recoding) {
290 echo ' <div style="margin-bottom: 5px">' . "\n";
291 $temp_charset = reset($cfg['AvailableCharsets']);
292 echo $strCharsetOfFile . "\n"
293 . ' <select name="charset_of_file" size="1">' . "\n"
294 . ' <option value="' . $temp_charset . '"';
295 if ($temp_charset == $charset) {
296 echo ' selected="selected"';
298 echo '>' . $temp_charset . '</option>' . "\n";
299 while ($temp_charset = next($cfg['AvailableCharsets'])) {
300 echo ' <option value="' . $temp_charset . '"';
301 if ($temp_charset == $charset) {
302 echo ' selected="selected"';
304 echo '>' . $temp_charset . '</option>' . "\n";
306 echo ' </select><br />' . "\n" . ' ';
307 echo ' </div>' . "\n";
308 } // end if (recoding)
312 $bookmark_go = FALSE;
313 if (!isset($is_inside_querywindow) ||
314 (isset($is_inside_querywindow) && $is_inside_querywindow == TRUE && isset($querydisplay_tab) && ($querydisplay_tab == 'history' ||
$querydisplay_tab == 'full'))) {
315 if ($cfg['Bookmark']['db'] && $cfg['Bookmark']['table']) {
316 if (($bookmark_list = PMA_listBookmarks($db, $cfg['Bookmark'])) && count($bookmark_list) > 0) {
318 echo " " . ((isset($is_inside_querywindow) && $is_inside_querywindow == TRUE && isset($querydisplay_tab) && $querydisplay_tab == 'full') ||
!isset($is_inside_querywindow) ?
"<i>$strOr</i>" : '') . " $strBookmarkQuery :<br />\n";
320 if (isset($is_inside_querywindow) && $is_inside_querywindow == TRUE) {
322 <input type
="hidden" name
="focus_querywindow" value
="true" />
326 echo ' <div style="margin-bottom: 5px">' . "\n";
327 echo ' <select name="id_bookmark" style="vertical-align: middle">' . "\n";
328 echo ' <option value=""></option>' . "\n";
329 foreach($bookmark_list AS $key => $value) {
330 echo ' <option value="' . $value . '">' . htmlspecialchars($key) . '</option>' . "\n";
332 echo ' </select>' . "<br />\n";
333 echo ' ' . $strVar . ' (<a href="./Documentation.html#faqbookmark" target="documentation">' . $strDocu . '</a>): <input type="text" name="bookmark_variable" class="textfield" size="10" />' . "\n";
334 echo ' <input type="radio" name="action_bookmark" value="0" id="radio_bookmark0" checked="checked" style="vertical-align: middle" /><label for="radio_bookmark0">' . $strSubmit . '</label>' . "\n";
335 echo ' <input type="radio" name="action_bookmark" value="1" id="radio_bookmark1" style="vertical-align: middle" /><label for="radio_bookmark1">' . $strBookmarkView . '</label>' . "\n";
336 echo ' <input type="radio" name="action_bookmark" value="2" id="radio_bookmark2" style="vertical-align: middle" /><label for="radio_bookmark2">' . $strDelete . '</label>' . "\n";
337 echo ' <br />' . "\n";
338 echo ' </div>' . "\n";
344 if (!isset($is_inside_querywindow) ||
(isset($is_inside_querywindow) && $is_inside_querywindow == TRUE && isset($querydisplay_tab) && (($querydisplay_tab == 'files') ||
$querydisplay_tab == 'sql' ||
$querydisplay_tab == 'full' ||
($querydisplay_tab == 'history' && $bookmark_go)))) {
345 if ($form_items > 0) {
350 <input type
="submit" name
="SQL" value
="<?php echo $strGo; ?>" />
353 if ( $cfg['Bookmark']['db']
354 && $cfg['Bookmark']['table']
355 && (!isset($is_inside_querywindow)
356 ||
( isset($is_inside_querywindow)
357 && $is_inside_querywindow == TRUE
358 && isset($querydisplay_tab)
359 //&& $querydisplay_tab != 'history'))) {
360 && $querydisplay_tab == 'sql'))) {
363 <input type
="submit" name
="SQLbookmark" value
="<?php echo $strGo . ' & ' . $strBookmarkThis; ?>" />
368 <legend
><?php
echo $strBookmarkOptions; ?
></legend
>
369 <?php
echo $strBookmarkLabel; ?
>: <input type
="text" name
="bkm_label" value
="" /><br
/>
370 <input type
="checkbox" name
="bkm_all_users" id
="id_bkm_all_users" value
="true" /><label
for="id_bkm_all_users"><?php
echo $strBookmarkAllUsers; ?
></label
>
380 // TODO: Add a more complete warning that no items (like for file import) where found.
381 // (After 2.5.2 release!)
382 echo $strWebServerUploadDirectoryError;
388 if (!isset($is_inside_querywindow) ||
389 (isset($is_inside_querywindow) && $is_inside_querywindow == TRUE && isset($querydisplay_tab) && ($querydisplay_tab == 'files' ||
$querydisplay_tab == 'full')) && isset($db) && $db != '') {
391 // loic1: displays import dump feature only if file upload available
392 $ldi_target = 'ldi_table.php?' . $url_query . (isset($is_inside_querywindow) && $is_inside_querywindow == TRUE ?
'&focus_querywindow=true' : '');
394 if ($is_upload && isset($db) && isset($table)) {
396 <!-- Insert a text file
-->
400 if ($cfg['QueryFrame'] && $cfg['QueryFrameJS']) {
403 <script type
="text/javascript">
404 document
.writeln('<div style="margin-bottom: 10px"><a href="<?php echo (isset($is_inside_querywindow) && $is_inside_querywindow == TRUE ? '#' : $ldi_target); ?>" <?php echo (isset($is_inside_querywindow) && $is_inside_querywindow == TRUE ? 'onclick="opener.parent.frames.phpmain\' + opener.parent.frames.queryframe.document.hashform.hash.value + \'.location.href = \\\'' . $ldi_target . '\\\'; return false;"' : ''); ?>><?php echo addslashes($strInsertTextfiles); ?></a></div>');
411 <script type
="text/javascript">
412 document
.writeln('<div style="margin-bottom: 10px"><a href="<?php echo (isset($is_inside_querywindow) && $is_inside_querywindow == TRUE ? '#' : $ldi_target); ?>" <?php echo (isset($is_inside_querywindow) && $is_inside_querywindow == TRUE ? 'onclick="opener.parent.frames.phpmain' . md5($cfg['PmaAbsoluteUri']) . '.location.href = \\\'' . $ldi_target . '\\\'; return false;"' : ''); ?>><?php echo addslashes($strInsertTextfiles); ?></a></div>');
420 <div style
="margin-bottom: 10px"><a href
="<?php echo $ldi_target; ?>"><?php
echo $strInsertTextfiles; ?
></a
></div
>