2 /* vim: set expandtab sw=4 ts=4 sts=4: */
4 * functions for displaying the sql query form
7 * @usedby server_sql.php
10 * @usedby tbl_structure.php
11 * @usedby querywindow.php
17 require_once './libraries/file_listing.php'; // used for file listing
18 require_once './libraries/bookmark.lib.php'; // used for file listing
21 * prints the sql query boxes
23 * @usedby server_sql.php
26 * @usedby tbl_structure.php
27 * @usedby querywindow.php
28 * @uses $GLOBALS['table']
29 * @uses $GLOBALS['db']
30 * @uses $GLOBALS['server']
31 * @uses $GLOBALS['goto']
32 * @uses $GLOBALS['is_upload'] from common.inc.php
33 * @uses $GLOBALS['sql_query'] from grab_globals.lib.php
34 * @uses $GLOBALS['cfg']['DefaultQueryTable']
35 * @uses $GLOBALS['cfg']['DefaultQueryDatabase']
36 * @uses $GLOBALS['cfg']['Servers']
37 * @uses $GLOBALS['cfg']['DefaultTabDatabase']
38 * @uses $GLOBALS['cfg']['DefaultQueryDatabase']
39 * @uses $GLOBALS['cfg']['DefaultQueryTable']
40 * @uses $GLOBALS['cfg']['Bookmark']['db']
41 * @uses $GLOBALS['cfg']['Bookmark']['table']
42 * @uses $GLOBALS['strSuccess']
43 * @uses PMA_generate_common_url()
44 * @uses PMA_backquote()
45 * @uses PMA_DBI_fetch_result()
46 * @uses PMA_showMySQLDocu()
47 * @uses PMA_generate_common_hidden_inputs()
48 * @uses PMA_sqlQueryFormBookmark()
49 * @uses PMA_sqlQueryFormInsert()
50 * @uses PMA_sqlQueryFormUpload()
51 * @uses PMA_DBI_QUERY_STORE
52 * @uses PMA_set_enc_form()
54 * @uses htmlspecialchars()
57 * @uses function_exists()
58 * @param boolean|string $query query to display in the textarea
59 * or true to display last executed
60 * @param boolean|string $display_tab sql|files|history|full|FALSE
61 * what part to display
62 * false if not inside querywindow
63 * @param string $delimiter
65 function PMA_sqlQueryForm($query = true, $display_tab = false, $delimiter = ';')
67 // check tab to display if inside querywindow
69 $display_tab = 'full';
70 $is_querywindow = false;
72 $is_querywindow = true;
76 if (true === $query) {
77 $query = $GLOBALS['sql_query'];
80 // set enctype to multipart for file uploads
81 if ($GLOBALS['is_upload']) {
82 $enctype = ' enctype="multipart/form-data"';
89 if (! strlen($GLOBALS['db'])) {
90 // prepare for server related
91 $goto = empty($GLOBALS['goto']) ?
92 'server_sql.php' : $GLOBALS['goto'];
93 } elseif (! strlen($GLOBALS['table'])) {
94 // prepare for db related
96 $goto = empty($GLOBALS['goto']) ?
97 'db_sql.php' : $GLOBALS['goto'];
99 $table = $GLOBALS['table'];
100 $db = $GLOBALS['db'];
101 $goto = empty($GLOBALS['goto']) ?
102 'tbl_sql.php' : $GLOBALS['goto'];
107 if ($is_querywindow) {
109 <form method
="post" id
="sqlqueryform" target
="frame_content"
110 action
="import.php"<?php
echo $enctype; ?
> name
="sqlform"
113 var save_name = window.opener.parent.frame_content.name;
114 window.opener.parent.frame_content.name = save_name + '<?php echo time(); ?>';
115 this.target = window.opener.parent.frame_content.name;
116 return checkSqlQuery(this);
120 echo '<form method="post" action="import.php" ' . $enctype . ' id="sqlqueryform"'
121 .' onsubmit="return checkSqlQuery(this)" name="sqlform">' . "\n";
124 if ($is_querywindow) {
125 echo '<input type="hidden" name="focus_querywindow" value="true" />'
127 if ($display_tab != 'sql' && $display_tab != 'full') {
128 echo '<input type="hidden" name="sql_query" value="" />' . "\n";
129 echo '<input type="hidden" name="show_query" value="1" />' . "\n";
132 echo '<input type="hidden" name="is_js_confirmed" value="0" />' . "\n"
133 .PMA_generate_common_hidden_inputs($db, $table) . "\n"
134 .'<input type="hidden" name="pos" value="0" />' . "\n"
135 .'<input type="hidden" name="goto" value="'
136 .htmlspecialchars($goto) . '" />' . "\n"
137 .'<input type="hidden" name="zero_rows" value="'
138 . htmlspecialchars($GLOBALS['strSuccess']) . '" />' . "\n"
139 .'<input type="hidden" name="prev_sql_query" value="'
140 . htmlspecialchars($query) . '" />' . "\n";
143 if ($display_tab === 'full' ||
$display_tab === 'sql') {
144 PMA_sqlQueryFormInsert($query, $is_querywindow, $delimiter);
148 if ($display_tab === 'files' && $GLOBALS['is_upload']) {
149 PMA_sqlQueryFormUpload();
153 if ($display_tab === 'full' ||
$display_tab === 'history') {
154 if (! empty($GLOBALS['cfg']['Bookmark'])
155 && $GLOBALS['cfg']['Bookmark']['db']
156 && $GLOBALS['cfg']['Bookmark']['table']) {
157 PMA_sqlQueryFormBookmark();
161 // Encoding setting form appended by Y.Kawada
162 if (function_exists('PMA_set_enc_form')) {
163 echo PMA_set_enc_form(' ');
166 echo '</form>' . "\n";
167 if ($is_querywindow) {
169 <script type
="text/javascript">
172 window
.opener
.parent
.insertQuery();
181 * prints querybox fieldset
183 * @usedby PMA_sqlQueryForm()
184 * @uses $GLOBALS['text_dir']
185 * @uses $GLOBALS['cfg']['TextareaAutoSelect']
186 * @uses $GLOBALS['cfg']['TextareaCols']
187 * @uses $GLOBALS['cfg']['TextareaRows']
188 * @uses $GLOBALS['strShowThisQuery']
189 * @uses $GLOBALS['strGo']
191 * @uses PMA_USR_BROWSER_AGENT
192 * @uses PMA_USR_BROWSER_VER
193 * @uses htmlspecialchars()
194 * @param string $query query to display in the textarea
195 * @param boolean $is_querywindow if inside querywindow or not
196 * @param string $delimiter default delimiter to use
198 function PMA_sqlQueryFormInsert($query = '', $is_querywindow = false, $delimiter = ';')
201 // enable auto select text in textarea
202 if ($GLOBALS['cfg']['TextareaAutoSelect']) {
203 $auto_sel = ' onfocus="selectContent(this, sql_box_locked, true)"';
208 // enable locking if inside query window
209 if ($is_querywindow) {
210 $locking = ' onkeypress="document.sqlform.elements[\'LockFromUpdate\'].'
212 $height = $GLOBALS['cfg']['TextareaRows'] * 1.25;
215 $height = $GLOBALS['cfg']['TextareaRows'] * 2;
220 $fields_list = array();
221 if (! strlen($GLOBALS['db'])) {
222 // prepare for server related
223 $legend = sprintf($GLOBALS['strRunSQLQueryOnServer'],
224 '"' . htmlspecialchars(
225 ! empty($GLOBALS['cfg']['Servers'][$GLOBALS['server']]['verbose']) ?
$GLOBALS['cfg']['Servers'][$GLOBALS['server']]['verbose'] : $GLOBALS['cfg']['Servers'][$GLOBALS['server']]['host']) . '"');
226 } elseif (! strlen($GLOBALS['table'])) {
227 // prepare for db related
228 $db = $GLOBALS['db'];
229 // if you want navigation:
230 $strDBLink = '<a href="' . $GLOBALS['cfg']['DefaultTabDatabase']
231 . '?' . PMA_generate_common_url($db) . '"';
232 if ($is_querywindow) {
233 $strDBLink .= ' target="_self"'
234 . ' onclick="this.target=window.opener.frame_content.name"';
237 . htmlspecialchars($db) . '</a>';
239 // $strDBLink = htmlspecialchars($db);
240 $legend = sprintf($GLOBALS['strRunSQLQuery'], $strDBLink);
242 $query = str_replace('%d',
243 PMA_backquote($db), $GLOBALS['cfg']['DefaultQueryDatabase']);
246 $table = $GLOBALS['table'];
247 $db = $GLOBALS['db'];
248 // Get the list and number of fields
249 // we do a try_query here, because we could be in the query window,
250 // trying to synchonize and the table has not yet been created
251 $fields_list = PMA_DBI_fetch_result(
252 'SHOW FULL COLUMNS FROM ' . PMA_backquote($db)
253 . '.' . PMA_backquote($GLOBALS['table']));
255 $strDBLink = '<a href="' . $GLOBALS['cfg']['DefaultTabDatabase']
256 . '?' . PMA_generate_common_url($db) . '"';
257 if ($is_querywindow) {
258 $strDBLink .= ' target="_self"'
259 . ' onclick="this.target=window.opener.frame_content.name"';
262 . htmlspecialchars($db) . '</a>';
264 // $strDBLink = htmlspecialchars($db);
265 $legend = sprintf($GLOBALS['strRunSQLQuery'], $strDBLink);
266 if (empty($query) && count($fields_list)) {
267 $field_names = array();
268 foreach ($fields_list as $field) {
269 $field_names[] = PMA_backquote($field['Field']);
272 str_replace('%d', PMA_backquote($db),
273 str_replace('%t', PMA_backquote($table),
275 implode(', ', $field_names),
276 $GLOBALS['cfg']['DefaultQueryTable'])));
280 $legend .= ': ' . PMA_showMySQLDocu('SQL-Syntax', 'SELECT');
282 if (count($fields_list)) {
283 $sqlquerycontainer_id = 'sqlquerycontainer';
285 $sqlquerycontainer_id = 'sqlquerycontainerfull';
288 echo '<a name="querybox"></a>' . "\n"
289 .'<div id="queryboxcontainer">' . "\n"
290 .'<fieldset id="querybox">' . "\n";
291 echo '<legend>' . $legend . '</legend>' . "\n";
292 echo '<div id="queryfieldscontainer">' . "\n";
293 echo '<div id="' . $sqlquerycontainer_id . '">' . "\n"
294 .'<textarea name="sql_query" id="sqlquery"'
295 .' cols="' . $GLOBALS['cfg']['TextareaCols'] . '"'
296 .' rows="' . $height . '"'
297 .' dir="' . $GLOBALS['text_dir'] . '"'
298 .$auto_sel . $locking . '>' . htmlspecialchars($query) . '</textarea>' . "\n";
299 echo '</div>' . "\n";
301 if (count($fields_list)) {
302 echo '<div id="tablefieldscontainer">' . "\n"
303 .'<label>' . $GLOBALS['strFields'] . '</label>' . "\n"
304 .'<select id="tablefields" name="dummy" '
305 .'size="' . ($GLOBALS['cfg']['TextareaRows'] - 2) . '" '
306 .'multiple="multiple" ondblclick="insertValueQuery()">' . "\n";
307 foreach ($fields_list as $field) {
308 echo '<option value="'
309 .PMA_backquote(htmlspecialchars($field['Field'])) . '"';
310 if (isset($field['Field']) && strlen($field['Field']) && isset($field['Comment'])) {
311 echo ' title="' . htmlspecialchars($field['Comment']) . '"';
313 echo '>' . htmlspecialchars($field['Field']) . '</option>' . "\n";
315 echo '</select>' . "\n"
316 .'<div id="tablefieldinsertbuttoncontainer">' . "\n";
317 if ($GLOBALS['cfg']['PropertiesIconic']) {
318 echo '<input type="button" name="insert" value="<<"'
319 .' onclick="insertValueQuery()"'
320 .' title="' . $GLOBALS['strInsert'] . '" />' . "\n";
322 echo '<input type="button" name="insert"'
323 .' value="' . $GLOBALS['strInsert'] . '"'
324 .' onclick="insertValueQuery()" />' . "\n";
330 echo '<div class="clearfloat"></div>' . "\n";
331 echo '</div>' . "\n";
333 if (! empty($GLOBALS['cfg']['Bookmark'])
334 && $GLOBALS['cfg']['Bookmark']['db']
335 && $GLOBALS['cfg']['Bookmark']['table']) {
337 <div id
="bookmarkoptions">
338 <div
class="formelement">
339 <label
for="bkm_label">
340 <?php
echo $GLOBALS['strBookmarkThis']; ?
>:</label
>
341 <input type
="text" name
="bkm_label" id
="bkm_label" value
="" />
343 <div
class="formelement">
344 <input type
="checkbox" name
="bkm_all_users" id
="id_bkm_all_users"
346 <label
for="id_bkm_all_users">
347 <?php
echo $GLOBALS['strBookmarkAllUsers']; ?
></label
>
349 <div
class="formelement">
350 <input type
="checkbox" name
="bkm_replace" id
="id_bkm_replace"
352 <label
for="id_bkm_replace">
353 <?php
echo $GLOBALS['strBookmarkReplace']; ?
></label
>
359 echo '<div class="clearfloat"></div>' . "\n";
360 echo '</fieldset>' . "\n"
363 echo '<fieldset id="queryboxfooter" class="tblFooters">' . "\n";
364 echo '<div class="formelement">' . "\n";
365 if ($is_querywindow) {
367 <script type
="text/javascript">
369 document
.writeln(' <input type="checkbox" name="LockFromUpdate" value="1" id="checkbox_lock" /> <label for="checkbox_lock"><?php echo $GLOBALS['strQueryWindowLock
']; ?></label> ');
374 echo '</div>' . "\n";
375 echo '<div class="formelement">' . "\n";
376 if (PMA_MYSQL_INT_VERSION
>= 50000) {
377 echo '<label for="id_sql_delimiter">[ ' . $GLOBALS['strDelimiter']
379 echo '<input type="text" name="sql_delimiter" size="3" '
380 .'value="' . $delimiter . '" '
381 .'id="id_sql_delimiter" /> ]' . "\n";
384 echo '<input type="checkbox" name="show_query" value="1" '
385 .'id="checkbox_show_query" checked="checked" />' . "\n"
386 .'<label for="checkbox_show_query">' . $GLOBALS['strShowThisQuery']
389 echo '</div>' . "\n";
390 echo '<input type="submit" name="SQL" value="' . $GLOBALS['strGo'] . '" />'
392 echo '<div class="clearfloat"></div>' . "\n";
393 echo '</fieldset>' . "\n";
397 * prints bookmark fieldset
399 * @usedby PMA_sqlQueryForm()
400 * @uses PMA_listBookmarks()
401 * @uses $GLOBALS['db']
402 * @uses $GLOBALS['pmaThemeImage']
403 * @uses $GLOBALS['cfg']['Bookmark']
404 * @uses $GLOBALS['cfg']['ReplaceHelpImg']
405 * @uses $GLOBALS['strBookmarkQuery']
406 * @uses $GLOBALS['strBookmarkView']
407 * @uses $GLOBALS['strDelete']
408 * @uses $GLOBALS['strDocu']
409 * @uses $GLOBALS['strGo']
410 * @uses $GLOBALS['strSubmit']
411 * @uses $GLOBALS['strVar']
413 * @uses htmlspecialchars()
415 function PMA_sqlQueryFormBookmark()
417 $bookmark_list = PMA_listBookmarks($GLOBALS['db'], $GLOBALS['cfg']['Bookmark']);
418 if (! $bookmark_list ||
count($bookmark_list) < 1) {
422 echo '<fieldset id="bookmarkoptions">';
424 echo $GLOBALS['strBookmarkQuery'] . '</legend>' . "\n";
425 echo '<div class="formelement">';
426 echo '<select name="id_bookmark">' . "\n";
427 echo '<option value=""> </option>' . "\n";
428 foreach ($bookmark_list as $key => $value) {
429 echo '<option value="' . htmlspecialchars($key) . '">'
430 .htmlspecialchars($value) . '</option>' . "\n";
432 // is required for correct display with styles/line height
433 echo '</select> ' . "\n";
434 echo '</div>' . "\n";
435 echo '<div class="formelement">' . "\n";
436 echo $GLOBALS['strVar'];
437 if ($GLOBALS['cfg']['ReplaceHelpImg']) {
438 echo ' <a href="./Documentation.html#faqbookmark"'
439 .' target="documentation">'
440 .'<img class="icon" src="' . $GLOBALS['pmaThemeImage'] . 'b_help.png"'
441 .' border="0" width="11" height="11" align="middle"'
442 .' alt="' . $GLOBALS['strDocu'] . '" /></a> ';
444 echo ' (<a href="./Documentation.html#faqbookmark"'
445 .' target="documentation">' . $GLOBALS['strDocu'] . '</a>): ';
447 echo '<input type="text" name="bookmark_variable" class="textfield"'
448 .' size="10" />' . "\n";
449 echo '</div>' . "\n";
450 echo '<div class="formelement">' . "\n";
451 echo '<input type="radio" name="action_bookmark" value="0"'
452 .' id="radio_bookmark_exe" checked="checked" />'
453 .'<label for="radio_bookmark_exe">' . $GLOBALS['strSubmit']
455 echo '<input type="radio" name="action_bookmark" value="1"'
456 .' id="radio_bookmark_view" />'
457 .'<label for="radio_bookmark_view">' . $GLOBALS['strBookmarkView']
459 echo '<input type="radio" name="action_bookmark" value="2"'
460 .' id="radio_bookmark_del" />'
461 .'<label for="radio_bookmark_del">' . $GLOBALS['strDelete']
463 echo '</div>' . "\n";
464 echo '<div class="clearfloat"></div>' . "\n";
465 echo '</fieldset>' . "\n";
467 echo '<fieldset id="bookmarkoptionsfooter" class="tblFooters">' . "\n";
468 echo '<input type="submit" name="SQL" value="' . $GLOBALS['strGo'] . '" />';
469 echo '<div class="clearfloat"></div>' . "\n";
470 echo '</fieldset>' . "\n";
474 * prints bookmark fieldset
476 * @usedby PMA_sqlQueryForm()
477 * @uses $GLOBALS['cfg']['GZipDump']
478 * @uses $GLOBALS['cfg']['BZipDump']
479 * @uses $GLOBALS['cfg']['UploadDir']
480 * @uses $GLOBALS['cfg']['AvailableCharsets']
481 * @uses $GLOBALS['cfg']['AllowAnywhereRecoding']
482 * @uses $GLOBALS['strBzip']
483 * @uses $GLOBALS['strCharsetOfFile']
484 * @uses $GLOBALS['strCompression']
485 * @uses $GLOBALS['strError']
486 * @uses $GLOBALS['strGo']
487 * @uses $GLOBALS['strGzip']
488 * @uses $GLOBALS['strLocationTextfile']
489 * @uses $GLOBALS['strWebServerUploadDirectory']
490 * @uses $GLOBALS['strWebServerUploadDirectoryError']
491 * @uses $GLOBALS['allow_recoding']
492 * @uses $GLOBALS['charset']
493 * @uses $GLOBALS['max_upload_size']
494 * @uses PMA_supportedDecompressions()
495 * @uses PMA_getFileSelectOptions()
496 * @uses PMA_displayMaximumUploadSize()
497 * @uses PMA_generateCharsetDropdownBox()
498 * @uses PMA_generateHiddenMaxFileSize()
499 * @uses PMA_MYSQL_INT_VERSION
500 * @uses PMA_CSDROPDOWN_CHARSET
503 function PMA_sqlQueryFormUpload(){
506 $matcher = '@\.sql(\.(' . PMA_supportedDecompressions() . '))?$@'; // we allow only SQL here
508 if (!empty($GLOBALS['cfg']['UploadDir'])) {
509 $files = PMA_getFileSelectOptions(PMA_userDir($GLOBALS['cfg']['UploadDir']), $matcher, (isset($timeout_passed) && $timeout_passed && isset($local_import_file)) ?
$local_import_file : '');
515 echo '<fieldset id="">';
517 echo $GLOBALS['strLocationTextfile'] . '</legend>';
518 echo '<div class="formelement">';
519 echo '<input type="file" name="sql_file" class="textfield" /> ';
520 echo PMA_displayMaximumUploadSize($GLOBALS['max_upload_size']);
521 // some browsers should respect this :)
522 echo PMA_generateHiddenMaxFileSize($GLOBALS['max_upload_size']) . "\n";
525 if ($files === FALSE) {
526 $errors[$GLOBALS['strError']] = $GLOBALS['strWebServerUploadDirectoryError'];
527 } elseif (!empty($files)) {
528 echo '<div class="formelement">';
529 echo '<strong>' . $GLOBALS['strWebServerUploadDirectory'] .':</strong>' . "\n";
530 echo '<select size="1" name="sql_localfile">' . "\n";
531 echo '<option value="" selected="selected"></option>' . "\n";
533 echo '</select>' . "\n";
537 echo '<div class="clearfloat"></div>' . "\n";
541 echo '<fieldset id="" class="tblFooters">';
542 if (PMA_MYSQL_INT_VERSION
< 40100
543 && $GLOBALS['cfg']['AllowAnywhereRecoding']
544 && $GLOBALS['allow_recoding']) {
545 echo $GLOBALS['strCharsetOfFile'] . "\n"
546 . '<select name="charset_of_file" size="1">' . "\n";
547 foreach ($GLOBALS['cfg']['AvailableCharsets'] as $temp_charset) {
548 echo '<option value="' . $temp_charset . '"';
549 if ($temp_charset == $GLOBALS['charset']) {
550 echo ' selected="selected"';
552 echo '>' . $temp_charset . '</option>' . "\n";
554 echo '</select>' . "\n";
555 } elseif (PMA_MYSQL_INT_VERSION
>= 40100) {
556 echo $GLOBALS['strCharsetOfFile'] . "\n";
557 echo PMA_generateCharsetDropdownBox(PMA_CSDROPDOWN_CHARSET
,
558 'charset_of_file', null, 'utf8', FALSE);
559 } // end if (recoding)
560 echo '<input type="submit" name="SQL" value="' . $GLOBALS['strGo']
562 echo '<div class="clearfloat"></div>' . "\n";
565 foreach ($errors as $error => $message) {
566 echo '<div>' . $error . '</div>';
567 echo '<div>' . $message . '</div>';