3 // vim: expandtab sw=4 ts=4 sts=4:
7 if (!defined('PMA_COMMON_LIB_INCLUDED')) {
8 include('./libraries/common.lib.php3');
10 if (!defined('PMA_BOOKMARK_LIB_INCLUDED')) {
11 include('./libraries/bookmark.lib.php3');
14 PMA_checkParameters(array('db','table','url_query'));
17 * Defines the query to be displayed in the query textarea
19 if (isset($show_query) && $show_query == '1') {
20 // This script has been called by read_dump.php3
21 if (isset($sql_query_cpy)) {
22 $query_to_display = $sql_query_cpy;
26 $query_to_display = $sql_query;
29 $query_to_display = '';
34 * Get the list and number of fields
37 if (isset($db) && isset($table) && $table != '' && $db != '') {
38 $local_query = 'SHOW FIELDS FROM ' . PMA_backquote($table) . ' FROM ' . PMA_backquote($db);
39 $result = @PMA_mysql_query
($local_query);
41 PMA_mysqlDie('', $local_query, '', $err_url);
44 $fields_cnt = mysql_num_rows($result);
45 while ($row = PMA_mysql_fetch_array($result)) {
46 $fields_list[] = $row['Field'];
48 mysql_free_result($result);
55 // loic1: defines wether file upload is available or not
56 // ($is_upload now defined in common.lib.php3)
58 if ($cfg['QueryFrame'] && $cfg['QueryFrameJS'] && isset($is_inside_querywindow) && $is_inside_querywindow == TRUE && isset($querydisplay_tab) && ($querydisplay_tab == 'sql' ||
$querydisplay_tab == 'full')) {
59 $locking = 'onKeyPress="document.sqlform.elements[\'LockFromUpdate\'].checked = true;"';
64 $auto_sel = ($cfg['TextareaAutoSelect']
65 // 2003-02-05 rabus: This causes big trouble with Opera 7 for
66 // Windows, so let's disable it there...
67 && !(PMA_USR_OS
== 'Win' && PMA_USR_BROWSER_AGENT
== 'OPERA' && PMA_USR_BROWSER_VER
>= 7))
68 ?
"\n" . ' onfocus="if (typeof(document.layers) == \'undefined\' || typeof(textarea_selected) == \'undefined\') {textarea_selected = 1; document.sqlform.elements[\'sql_query\'].select();}"'
70 $auto_sel .= ' ' . $locking;
72 // garvin: If non-JS query window is embedded, display a list of databases to choose from.
73 // Apart from that, a non-js query window sucks badly.
75 if ($cfg['QueryFrame'] && (!$cfg['QueryFrameJS'] && !$db ||
($cfg['QueryFrameJS'] && !$db))) {
77 * Get the list and number of available databases.
80 PMA_availableDatabases(); // this function is defined in "common.lib.php3"
86 $queryframe_db_list = '<select size=1 name="db">';
87 for ($i = 0; $i < $num_dbs; $i++
) {
89 $queryframe_db_list .= '<option value="' . htmlspecialchars($t_db) . '">' . htmlspecialchars($t_db) . '</option>';
91 $queryframe_db_list .= '</select>';
93 $queryframe_db_list = '';
96 $queryframe_db_list = '';
101 if ($cfg['QueryFrame'] && $cfg['QueryFrameJS'] && isset($is_inside_querywindow) && $is_inside_querywindow) {
103 <script type
="text/javascript">
105 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.php3"<?php if ($is_upload) echo ' enctype
="multipart/form-data"'; ?> onsubmit="return checkSqlQuery(this)" name="sqlform">');
109 <form method
="post" target
="phpmain<?php echo md5($cfg['PmaAbsoluteUri']); ?>" action
="read_dump.php3"<?php
if ($is_upload) echo ' enctype="multipart/form-data"'; ?
> name
="sqlform">
114 <form method
="post" action
="read_dump.php3"<?php
if ($is_upload) echo ' enctype="multipart/form-data"'; ?
> onsubmit
="return checkSqlQuery(this)" name
="sqlform">
118 <input type
="hidden" name
="is_js_confirmed" value
="0" />
119 <?php
echo PMA_generate_common_hidden_inputs($db, $table); ?
>
120 <input type
="hidden" name
="pos" value
="0" />
121 <input type
="hidden" name
="goto" value
="<?php echo $goto; ?>" />
122 <input type
="hidden" name
="zero_rows" value
="<?php echo $strSuccess; ?>" />
123 <input type
="hidden" name
="prev_sql_query" value
="<?php echo ((!empty($query_to_display)) ? urlencode($query_to_display) : ''); ?>" />
125 if (!isset($is_inside_querywindow) ||
126 (isset($is_inside_querywindow) && $is_inside_querywindow == TRUE && isset($querydisplay_tab) && ($querydisplay_tab == 'sql' ||
$querydisplay_tab == 'full'))) {
128 <!-- Query box
and bookmark support
-->
130 if (isset($is_inside_querywindow) && $is_inside_querywindow == TRUE) {
132 <input type
="hidden" name
="focus_querywindow" value
="true" />
136 <a name
="querybox"></a
>
137 <table cellpadding
="1" cellspacing
="1">
140 <?php
echo sprintf($strRunSQLQuery, htmlspecialchars($db)) . $queryframe_db_list . (isset($is_inside_querywindow) ?
'<br />' : ' ') . PMA_showMySQLDocu('Reference', 'SELECT'); ?
>
142 <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; ?
>>
143 <?php
echo ((!empty($query_to_display)) ?
htmlspecialchars($query_to_display) : 'SELECT * FROM ' . htmlspecialchars(PMA_backquote($table)) . ' WHERE 1'); ?
></textarea
>
145 <?php
if (isset($table) && $fields_cnt > 0) { ?
>
146 <td align
="center" valign
="top"><?php
echo (isset($is_inside_querywindow) ?
'<br />' : '') . $strFields; ?
>:<br
/>
147 <select name
="dummy" size
="4" multiple
>
150 for ($i = 0 ; $i < $fields_cnt; $i++
) {
152 . '<option value="' . PMA_backquote(htmlspecialchars($fields_list[$i])) . '">' . htmlspecialchars($fields_list[$i]) . '</option>' . "\n";
155 </select
><br
/><br
/>
156 <input type
="button" name
="insert" value
="<?php echo($strInsert); ?>" onclick
="insertValueQuery()" />
163 <input type
="checkbox" name
="show_query" value
="1" id
="checkbox_show_query" checked
="checked" /> 
;
164 <label
for="checkbox_show_query"><?php
echo $strShowThisQuery; ?
></label
><br
/>
166 if (isset($is_inside_querywindow) && $is_inside_querywindow == TRUE) {
168 <script type
="text/javascript">
169 document
.writeln('<input type="checkbox" name="LockFromUpdate" value="1" id="checkbox_lock" /> ');
170 document
.writeln(' <label for="checkbox_lock"><?php echo $strQueryWindowLock; ?></label><br />');
181 <input type
="hidden" name
="sql_query" value
="" />
182 <input type
="hidden" name
="show_query" value
="1" />
186 // loic1: displays import dump feature only if file upload available
187 if ($is_upload && (!isset($is_inside_querywindow) ||
188 (isset($is_inside_querywindow) && $is_inside_querywindow == TRUE && isset($querydisplay_tab) && ($querydisplay_tab == 'files' ||
$querydisplay_tab == 'full')))) {
190 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";
192 <div style
="margin-bottom: 5px">
193 <input type
="file" name
="sql_file" class="textfield" /><br
/>
195 if (isset($is_inside_querywindow) && $is_inside_querywindow == TRUE) {
197 <input type
="hidden" name
="focus_querywindow" value
="true" />
201 $is_gzip = ($cfg['GZipDump'] && @function_exists
('gzopen'));
202 $is_bzip = ($cfg['BZipDump'] && @function_exists
('bzdecompress'));
203 if ($is_bzip ||
$is_gzip) {
204 echo ' ' . $strCompression . ':' . "\n"
205 . ' <input type="radio" id="radio_sql_file_compression_auto" name="sql_file_compression" value="" checked="checked" />' . "\n"
206 . ' <label for="radio_sql_file_compression_auto">' . $strAutodetect . '</label> ' . "\n"
207 . ' <input type="radio" id="radio_sql_file_compression_plain" name="sql_file_compression" value="text/plain" />' . "\n"
208 . ' <label for="radio_sql_file_compression_plain">' . $strNone . '</label> ' . "\n";
210 echo ' <input type="radio" id="radio_sql_file_compression_gzip" name="sql_file_compression" value="application/x-gzip" />' . "\n"
211 . ' <label for="radio_sql_file_compression_gzip">' . $strGzip . '</label> ' . "\n";
214 echo ' <input type="radio" id="radio_sql_file_compression_bzip" name="sql_file_compression" value="application/x-bzip" />' . "\n"
215 . ' <label for="radio_sql_file_compression_bzip">' . $strBzip . '</label> ' . "\n";
218 echo ' <input type="hidden" name="sql_file_compression" value="text/plain" />' . "\n";
226 // web-server upload directory
227 $is_upload_dir = false;
228 if ($cfg['UploadDir'] != '' && !isset($is_inside_querywindow) ||
229 ($cfg['UploadDir'] != '' && isset($is_inside_querywindow) && $is_inside_querywindow == TRUE && isset($querydisplay_tab) && ($querydisplay_tab == 'files' ||
$querydisplay_tab == 'full'))) {
231 if ($handle = @opendir
($cfg['UploadDir'])) {
232 if (isset($is_inside_querywindow) && $is_inside_querywindow == TRUE) {
234 <input type
="hidden" name
="focus_querywindow" value
="true" />
239 while ($file = @readdir
($handle)) {
240 if (is_file($cfg['UploadDir'] . $file) && substr($file, -4) == '.sql') {
241 if ($is_first == 0) {
242 $is_upload_dir = true;
244 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";
245 echo ' <div style="margin-bottom: 5px">' . "\n";
246 echo ' <select size="1" name="sql_localfile">' . "\n";
247 echo ' <option value="" selected="selected"></option>' . "\n";
249 } // end if (is_first)
250 echo ' <option value="' . htmlspecialchars($file) . '">' . htmlspecialchars($file) . '</option>' . "\n";
252 } // end if (is_file)
255 echo ' </select>' . "\n"
256 . ' </div>' . "\n\n";
257 } // end if (isfirst > 0)
260 echo ' <div style="margin-bottom: 5px">' . "\n";
261 echo ' <font color="red">' . $strError . '</font><br />' . "\n";
262 echo ' ' . $strWebServerUploadDirectoryError . "\n";
263 echo ' </div>' . "\n";
265 } // end if (web-server upload directory)
268 // Encoding setting form appended by Y.Kawada
269 if (function_exists('PMA_set_enc_form')) {
270 echo PMA_set_enc_form(' ');
274 // Charset conversion options
275 if (($is_upload ||
$is_upload_dir) &&
276 (!isset($is_inside_querywindow) ||
277 (isset($is_inside_querywindow) && $is_inside_querywindow == TRUE && isset($querydisplay_tab) && ($querydisplay_tab == 'files' ||
$querydisplay_tab == 'full')))
278 && isset($db) && $db != ''){
279 if ($cfg['AllowAnywhereRecoding'] && $allow_recoding) {
281 echo ' <div style="margin-bottom: 5px">' . "\n";
282 $temp_charset = reset($cfg['AvailableCharsets']);
283 echo $strCharsetOfFile . "\n"
284 . ' <select name="charset_of_file" size="1">' . "\n"
285 . ' <option value="' . $temp_charset . '"';
286 if ($temp_charset == $charset) {
287 echo ' selected="selected"';
289 echo '>' . $temp_charset . '</option>' . "\n";
290 while ($temp_charset = next($cfg['AvailableCharsets'])) {
291 echo ' <option value="' . $temp_charset . '"';
292 if ($temp_charset == $charset) {
293 echo ' selected="selected"';
295 echo '>' . $temp_charset . '</option>' . "\n";
297 echo ' </select><br />' . "\n" . ' ';
298 echo ' </div>' . "\n";
299 } // end if (recoding)
303 $bookmark_go = FALSE;
304 if (!isset($is_inside_querywindow) ||
305 (isset($is_inside_querywindow) && $is_inside_querywindow == TRUE && isset($querydisplay_tab) && ($querydisplay_tab == 'history' ||
$querydisplay_tab == 'full'))) {
306 if ($cfg['Bookmark']['db'] && $cfg['Bookmark']['table']) {
307 if (($bookmark_list = PMA_listBookmarks($db, $cfg['Bookmark'])) && count($bookmark_list) > 0) {
309 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";
311 if (isset($is_inside_querywindow) && $is_inside_querywindow == TRUE) {
313 <input type
="hidden" name
="focus_querywindow" value
="true" />
317 echo ' <div style="margin-bottom: 5px">' . "\n";
318 echo ' <select name="id_bookmark" style="vertical-align: middle">' . "\n";
319 echo ' <option value=""></option>' . "\n";
320 while (list($key, $value) = each($bookmark_list)) {
321 echo ' <option value="' . $value . '">' . htmlspecialchars($key) . '</option>' . "\n";
323 echo ' </select>' . "<br />\n";
324 echo ' ' . $strVar . ' (<a href="./Documentation.html#faqbookmark" target="documentation">' . $strDocu . '</a>): <input type="text" name="bookmark_variable" class="textfield" size="10" />' . "\n";
325 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";
326 echo ' <input type="radio" name="action_bookmark" value="1" id="radio_bookmark1" style="vertical-align: middle" /><label for="radio_bookmark1">' . $strBookmarkView . '</label>' . "\n";
327 echo ' <input type="radio" name="action_bookmark" value="2" id="radio_bookmark2" style="vertical-align: middle" /><label for="radio_bookmark2">' . $strDelete . '</label>' . "\n";
328 echo ' <br />' . "\n";
329 echo ' </div>' . "\n";
335 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)))) {
336 if ($form_items > 0) {
338 <input type
="submit" name
="SQL" value
="<?php echo $strGo; ?>" />
341 // TODO: Add a more complete warning that no items (like for file import) where found.
342 // (After 2.5.2 release!)
343 echo $strWebServerUploadDirectoryError;
349 if (!isset($is_inside_querywindow) ||
350 (isset($is_inside_querywindow) && $is_inside_querywindow == TRUE && isset($querydisplay_tab) && ($querydisplay_tab == 'files' ||
$querydisplay_tab == 'full')) && isset($db) && $db != '') {
352 // loic1: displays import dump feature only if file upload available
353 $ldi_target = 'ldi_table.php3?' . $url_query . (isset($is_inside_querywindow) && $is_inside_querywindow == TRUE ?
'&focus_querywindow=true' : '');
355 if ($is_upload && isset($db) && isset($table)) {
357 <!-- Insert a text file
-->
361 if ($cfg['QueryFrame'] && $cfg['QueryFrameJS']) {
364 <script type
="text/javascript">
365 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>');
372 <script type
="text/javascript">
373 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>');
381 <div style
="margin-bottom: 10px"><a href
="<?php echo $ldi_target; ?>"><?php
echo $strInsertTextfiles; ?
></a
></div
>