3 // vim: expandtab sw=4 ts=4 sts=4:
5 * functions for displaying the sql query form
7 * @usedby server_sql.php
8 * @usedby db_details.php
9 * @usedby tbl_properties.php
10 * @usedby tbl_properties_structure.php
11 * @usedby querywindow.php
14 require_once('./libraries/file_listing.php'); // used for file listing
17 * prints the sql query boxes
19 * @usedby server_sql.php
20 * @usedby db_details.php
21 * @usedby tbl_properties.php
22 * @usedby tbl_properties_structure.php
23 * @usedby querywindow.php
24 * @uses $GLOBALS['table']
25 * @uses $GLOBALS['db']
26 * @uses $GLOBALS['server']
27 * @uses $GLOBALS['goto']
28 * @uses $GLOBALS['is_upload'] from common.lib.php
29 * @uses $GLOBALS['sql_query'] from grab_globals.lib.php
30 * @uses $GLOBALS['cfg']['DefaultQueryTable']
31 * @uses $GLOBALS['cfg']['DefaultQueryDatabase']
32 * @uses $GLOBALS['cfg']['Servers']
33 * @uses $GLOBALS['cfg']['DefaultTabDatabase']
34 * @uses $GLOBALS['cfg']['DefaultQueryDatabase']
35 * @uses $GLOBALS['cfg']['DefaultQueryTable']
36 * @uses $GLOBALS['cfg']['Bookmark']['db']
37 * @uses $GLOBALS['cfg']['Bookmark']['table']
38 * @uses $GLOBALS['strSuccess']
39 * @uses PMA_generate_common_url()
40 * @uses PMA_backquote()
41 * @uses PMA_DBI_fetch_result()
42 * @uses PMA_showMySQLDocu()
43 * @uses PMA_generate_common_hidden_inputs()
44 * @uses PMA_sqlQueryFormBookmark()
45 * @uses PMA_sqlQueryFormInsert()
46 * @uses PMA_sqlQueryFormUpload()
47 * @uses PMA_DBI_QUERY_STORE
48 * @uses PMA_set_enc_form()
50 * @uses htmlspecialchars()
53 * @uses function_exists()
54 * @param boolean|string $query query to display in the textarea
55 * or true to display last executed
56 * @param boolean|string $display_tab sql|files|history|full|FALSE
57 * what part to display
58 * false if not inside querywindow
60 function PMA_sqlQueryForm( $query = true, $display_tab = false ) {
61 // check tab to display if inside querywindow
62 if ( ! $display_tab ) {
63 $display_tab = 'full';
64 $is_querywindow = false;
66 $is_querywindow = true;
70 if ( true === $query ) {
71 $query = empty( $GLOBALS['sql_query'] ) ?
'' : $GLOBALS['sql_query'];
74 // set enctype to multipart for file uploads
75 if ( $GLOBALS['is_upload'] ) {
76 $enctype = ' enctype="multipart/form-data"';
83 if ( empty( $GLOBALS['db'] ) ) {
84 // prepare for server related
85 $goto = empty( $GLOBALS['goto'] ) ?
86 'server_sql.php' : $GLOBALS['goto'];
88 elseif ( empty( $GLOBALS['table'] ) ) {
89 // prepare for db related
91 $goto = empty( $GLOBALS['goto'] ) ?
92 'db_details.php' : $GLOBALS['goto'];
94 $table = $GLOBALS['table'];
96 $goto = empty( $GLOBALS['goto'] ) ?
97 'tbl_properties.php' : $GLOBALS['goto'];
102 if ( $is_querywindow ) {
104 <form method
="post" id
="sqlqueryform"
105 target
="phpmain<?php echo md5( $GLOBALS['cfg']['PmaAbsoluteUri'] ); ?>"
106 action
="import.php"<?php
echo $enctype; ?
> name
="sqlform"
107 onsubmit
="this.target=window.opener.frames[1].name;
108 return checkSqlQuery( this );" >
111 echo '<form method="post" action="import.php" ' . $enctype . ' id="sqlqueryform"'
112 .' onsubmit="return checkSqlQuery(this)" name="sqlform">' . "\n";
115 if ( $is_querywindow ) {
116 echo '<input type="hidden" name="focus_querywindow" value="true" />'
118 if ( $display_tab != 'sql' && $display_tab != 'full' ) {
119 echo '<input type="hidden" name="sql_query" value="" />' . "\n";
120 echo '<input type="hidden" name="show_query" value="1" />' . "\n";
123 echo '<input type="hidden" name="is_js_confirmed" value="0" />' . "\n"
124 .PMA_generate_common_hidden_inputs( $db, $table ) . "\n"
125 .'<input type="hidden" name="pos" value="0" />' . "\n"
126 .'<input type="hidden" name="goto" value="'
127 .htmlspecialchars( $goto ) . '" />' . "\n"
128 .'<input type="hidden" name="zero_rows" value="'
129 . htmlspecialchars( $GLOBALS['strSuccess'] ) . '" />' . "\n"
130 .'<input type="hidden" name="prev_sql_query" value="'
131 . htmlspecialchars( $query ) . '" />' . "\n";
134 if ( $display_tab === 'full' ||
$display_tab === 'sql' ) {
135 PMA_sqlQueryFormInsert( $query, $is_querywindow );
139 if ( $display_tab === 'files' && $GLOBALS['is_upload'] ) {
140 PMA_sqlQueryFormUpload();
144 if ( $display_tab === 'full' ||
$display_tab === 'history' ) {
145 if ( ! empty( $GLOBALS['cfg']['Bookmark'] )
146 && $GLOBALS['cfg']['Bookmark']['db']
147 && $GLOBALS['cfg']['Bookmark']['table'] ) {
148 PMA_sqlQueryFormBookmark();
152 // Encoding setting form appended by Y.Kawada
153 if ( function_exists('PMA_set_enc_form') ) {
154 echo PMA_set_enc_form(' ');
157 echo '</form>' . "\n";
161 * prints querybox fieldset
163 * @usedby PMA_sqlQueryForm()
164 * @uses $GLOBALS['text_dir']
165 * @uses $GLOBALS['cfg']['TextareaAutoSelect']
166 * @uses $GLOBALS['cfg']['TextareaCols']
167 * @uses $GLOBALS['cfg']['TextareaRows']
168 * @uses $GLOBALS['strShowThisQuery']
169 * @uses $GLOBALS['strGo']
170 * @uses PMA_availableDatabases()
172 * @uses PMA_USR_BROWSER_AGENT
173 * @uses PMA_USR_BROWSER_VER
174 * @uses PMA_availableDatabases()
175 * @uses htmlspecialchars()
176 * @param string $query query to display in the textarea
177 * @param boolean $is_querywindow if inside querywindow or not
179 function PMA_sqlQueryFormInsert( $query = '', $is_querywindow = false ) {
181 // enable auto select text in textarea
182 if ( $GLOBALS['cfg']['TextareaAutoSelect'] ) {
183 $auto_sel = ' onfocus="selectContent( this, sql_box_locked, true )"';
188 // enable locking if inside query window
189 if ( $is_querywindow ) {
190 $locking = ' onkeypress="document.sqlform.elements[\'LockFromUpdate\'].'
198 $fields_list = array();
199 if ( empty( $GLOBALS['db'] ) ) {
200 // prepare for server related
201 $legend = sprintf( $GLOBALS['strRunSQLQueryOnServer'],
203 $GLOBALS['cfg']['Servers'][$GLOBALS['server']]['host'] ) );
205 elseif ( empty( $GLOBALS['table'] ) ) {
206 // prepare for db related
207 $db = $GLOBALS['db'];
208 // if you want navigation:
209 $strDBLink = '<a href="' . $GLOBALS['cfg']['DefaultTabDatabase']
210 . '?' . PMA_generate_common_url( $db ) . '"';
211 if ( $is_querywindow ) {
212 $strDBLink .= ' target="_self"'
213 . ' onclick="this.target=window.opener.frames[1].name"';
216 . htmlspecialchars( $db ) . '</a>';
218 // $strDBLink = htmlspecialchars( $db );
219 $legend = sprintf( $GLOBALS['strRunSQLQuery'], $strDBLink );
220 if ( empty( $query ) ) {
221 $query = str_replace( '%d',
222 PMA_backquote( $db ), $GLOBALS['cfg']['DefaultQueryDatabase'] );
225 $table = $GLOBALS['table'];
226 $db = $GLOBALS['db'];
227 // Get the list and number of fields
228 // we do a try_query here, because we could be in the query window,
229 // trying to synchonize and the table has not yet been created
230 $fields_list = PMA_DBI_fetch_result(
231 'SHOW FULL COLUMNS FROM ' . PMA_backquote( $db )
232 . '.' . PMA_backquote( $GLOBALS['table'] ));
234 $strDBLink = '<a href="' . $GLOBALS['cfg']['DefaultTabDatabase']
235 . '?' . PMA_generate_common_url( $db ) . '"';
236 if ( $is_querywindow ) {
237 $strDBLink .= ' target="_self"'
238 . ' onclick="this.target=window.opener.frames[1].name"';
241 . htmlspecialchars( $db ) . '</a>';
243 // $strDBLink = htmlspecialchars( $db );
244 $legend = sprintf( $GLOBALS['strRunSQLQuery'], $strDBLink );
245 if ( empty( $query ) && count( $fields_list ) ) {
246 $field_names = array();
247 foreach ( $fields_list as $field ) {
248 $field_names[] = PMA_backquote($field['Field']);
251 str_replace( '%d', PMA_backquote( $db ),
252 str_replace( '%t', PMA_backquote( $table ),
254 implode( ', ', $field_names ),
255 $GLOBALS['cfg']['DefaultQueryTable'] ) ) );
259 $legend .= ': ' . PMA_showMySQLDocu( 'SQL-Syntax', 'SELECT' );
261 if ( count( $fields_list ) ) {
262 $sqlquerycontainer_id = 'sqlquerycontainer';
264 $sqlquerycontainer_id = 'sqlquerycontainerfull';
267 echo '<a name="querybox"></a>' . "\n"
268 .'<div id="queryboxcontainer">' . "\n"
269 .'<fieldset id="querybox">' . "\n";
270 echo '<legend>' . $legend . '</legend>' . "\n";
271 echo '<div id="queryfieldscontainer">' . "\n";
272 echo '<div id="' . $sqlquerycontainer_id . '">' . "\n"
273 .'<textarea name="sql_query" id="sqlquery"'
274 .' cols="' . $GLOBALS['cfg']['TextareaCols'] . '"'
275 .' rows="' . $GLOBALS['cfg']['TextareaRows'] . '"'
276 .' dir="' . $GLOBALS['text_dir'] . '"'
277 .$auto_sel . $locking . '>' . $query . '</textarea>' . "\n";
278 echo '</div>' . "\n";
280 if ( count( $fields_list ) ) {
281 echo '<div id="tablefieldscontainer">' . "\n"
282 .'<label>' . $GLOBALS['strFields'] . '</label>' . "\n"
283 .'<select id="tablefields" name="dummy" '
284 .'size="' . ($GLOBALS['cfg']['TextareaRows'] - 2) . '" '
285 .'multiple="multiple" ondblclick="insertValueQuery()">' . "\n";
286 foreach ( $fields_list as $field ) {
287 echo '<option value="'
288 .PMA_backquote( htmlspecialchars( $field['Field'] ) ) . '"';
289 if ( ! empty( $field['Field'] ) && isset($field['Comment']) ) {
290 echo ' title="' . htmlspecialchars( $field['Comment'] ) . '"';
292 echo '>' . htmlspecialchars( $field['Field'] ) . '</option>' . "\n";
294 echo '</select>' . "\n"
295 .'<div id="tablefieldinsertbuttoncontainer">' . "\n";
296 if ( $GLOBALS['cfg']['PropertiesIconic'] ) {
297 echo '<input type="button" name="insert" value="<<"'
298 .' onclick="insertValueQuery()"'
299 .' title="' . $GLOBALS['strInsert'] . '" />' . "\n";
301 echo '<input type="button" name="insert"'
302 .' value="' . $GLOBALS['strInsert'] . '"'
303 .' onclick="insertValueQuery()" />' . "\n";
309 echo '<div class="clearfloat"></div>' . "\n";
310 echo '</div>' . "\n";
312 if ( ! empty( $GLOBALS['cfg']['Bookmark'] )
313 && $GLOBALS['cfg']['Bookmark']['db']
314 && $GLOBALS['cfg']['Bookmark']['table'] ) {
316 <div id
="bookmarkoptions">
317 <div
class="formelement">
318 <label
for="bkm_label">
319 <?php
echo $GLOBALS['strBookmarkThis']; ?
>:</label
>
320 <input type
="text" name
="bkm_label" id
="bkm_label" value
="" />
322 <div
class="formelement">
323 <input type
="checkbox" name
="bkm_all_users" id
="id_bkm_all_users"
325 <label
for="id_bkm_all_users">
326 <?php
echo $GLOBALS['strBookmarkAllUsers']; ?
></label
>
328 <div
class="formelement">
329 <input type
="checkbox" name
="bkm_replace" id
="id_bkm_replace"
331 <label
for="id_bkm_replace">
332 <?php
echo $GLOBALS['strBookmarkReplace']; ?
></label
>
338 echo '<div class="clearfloat"></div>' . "\n";
339 echo '</fieldset>' . "\n"
342 echo '<fieldset id="queryboxfooter" class="tblFooters">' . "\n";
343 echo '<div class="formelement">' . "\n";
344 if ( $is_querywindow ) {
346 <script type
="text/javascript">
348 document
.writeln(' <input type="checkbox" name="LockFromUpdate" value="1" id="checkbox_lock" /> <label for="checkbox_lock"><?php echo $GLOBALS['strQueryWindowLock
']; ?></label> ');
353 echo '</div>' . "\n";
354 echo '<div class="formelement">' . "\n";
355 echo '<input type="checkbox" name="show_query" value="1" '
356 .'id="checkbox_show_query" checked="checked" />' . "\n"
357 .'<label for="checkbox_show_query">' . $GLOBALS['strShowThisQuery']
359 echo '</div>' . "\n";
360 echo '<input type="submit" name="SQL" value="' . $GLOBALS['strGo'] . '" />'
362 echo '<div class="clearfloat"></div>' . "\n";
363 echo '</fieldset>' . "\n";
367 * prints bookmark fieldset
369 * @usedby PMA_sqlQueryForm()
370 * @uses PMA_listBookmarks()
371 * @uses $GLOBALS['db']
372 * @uses $GLOBALS['pmaThemeImage']
373 * @uses $GLOBALS['cfg']['Bookmark']
374 * @uses $GLOBALS['cfg']['ReplaceHelpImg']
375 * @uses $GLOBALS['strBookmarkQuery']
376 * @uses $GLOBALS['strBookmarkView']
377 * @uses $GLOBALS['strDelete']
378 * @uses $GLOBALS['strDocu']
379 * @uses $GLOBALS['strGo']
380 * @uses $GLOBALS['strSubmit']
381 * @uses $GLOBALS['strVar']
383 * @uses htmlspecialchars()
385 function PMA_sqlQueryFormBookmark() {
386 $bookmark_list = PMA_listBookmarks(isset($GLOBALS['db']) ?
$GLOBALS['db'] : '', $GLOBALS['cfg']['Bookmark'] );
387 if ( ! $bookmark_list ||
count( $bookmark_list ) < 1 ) {
391 echo '<fieldset id="bookmarkoptions">';
393 echo $GLOBALS['strBookmarkQuery'] . '</legend>' . "\n";
394 echo '<div class="formelement">';
395 echo '<select name="id_bookmark">' . "\n";
396 echo '<option value=""></option>' . "\n";
397 foreach ( $bookmark_list as $key => $value ) {
398 echo '<option value="' . htmlspecialchars( $key ) . '">'
399 .htmlspecialchars( $value ) . '</option>' . "\n";
401 // is required for correct display with styles/line height
402 echo '</select> ' . "\n";
403 echo '</div>' . "\n";
404 echo '<div class="formelement">' . "\n";
405 echo $GLOBALS['strVar'];
406 if ( $GLOBALS['cfg']['ReplaceHelpImg'] ) {
407 echo ' <a href="./Documentation.html#faqbookmark"'
408 .' target="documentation">'
409 .'<img class="icon" src="' . $GLOBALS['pmaThemeImage'] . 'b_help.png"'
410 .' border="0" width="11" height="11" align="middle"'
411 .' alt="' . $GLOBALS['strDocu'] . '" /></a> ';
413 echo ' (<a href="./Documentation.html#faqbookmark"'
414 .' target="documentation">' . $GLOBALS['strDocu'] . '</a>): ';
416 echo '<input type="text" name="bookmark_variable" class="textfield"'
417 .' size="10" />' . "\n";
418 echo '</div>' . "\n";
419 echo '<div class="formelement">' . "\n";
420 echo '<input type="radio" name="action_bookmark" value="0"'
421 .' id="radio_bookmark_exe" checked="checked" />'
422 .'<label for="radio_bookmark_exe">' . $GLOBALS['strSubmit']
424 echo '<input type="radio" name="action_bookmark" value="1"'
425 .' id="radio_bookmark_view" />'
426 .'<label for="radio_bookmark_view">' . $GLOBALS['strBookmarkView']
428 echo '<input type="radio" name="action_bookmark" value="2"'
429 .' id="radio_bookmark_del" />'
430 .'<label for="radio_bookmark_del">' . $GLOBALS['strDelete']
432 echo '</div>' . "\n";
433 echo '<div class="clearfloat"></div>' . "\n";
434 echo '</fieldset>' . "\n";
436 echo '<fieldset id="bookmarkoptionsfooter" class="tblFooters">' . "\n";
437 echo '<input type="submit" name="SQL" value="' . $GLOBALS['strGo'] . '" />';
438 echo '<div class="clearfloat"></div>' . "\n";
439 echo '</fieldset>' . "\n";
443 * prints bookmark fieldset
445 * @usedby PMA_sqlQueryForm()
446 * @uses $GLOBALS['cfg']['GZipDump']
447 * @uses $GLOBALS['cfg']['BZipDump']
448 * @uses $GLOBALS['cfg']['UploadDir']
449 * @uses $GLOBALS['cfg']['AvailableCharsets']
450 * @uses $GLOBALS['cfg']['AllowAnywhereRecoding']
451 * @uses $GLOBALS['strAutodetect']
452 * @uses $GLOBALS['strBzip']
453 * @uses $GLOBALS['strCharsetOfFile']
454 * @uses $GLOBALS['strCompression']
455 * @uses $GLOBALS['strError']
456 * @uses $GLOBALS['strGo']
457 * @uses $GLOBALS['strGzip']
458 * @uses $GLOBALS['strLocationTextfile']
459 * @uses $GLOBALS['strWebServerUploadDirectory']
460 * @uses $GLOBALS['strWebServerUploadDirectoryError']
461 * @uses $GLOBALS['allow_recoding']
462 * @uses $GLOBALS['charset']
463 * @uses $GLOBALS['max_upload_size']
464 * @uses PMA_supportedDecompressions()
465 * @uses PMA_getFileSelectOptions()
466 * @uses PMA_displayMaximumUploadSize()
467 * @uses PMA_generateCharsetDropdownBox()
468 * @uses PMA_generateHiddenMaxFileSize()
469 * @uses PMA_MYSQL_INT_VERSION
470 * @uses PMA_CSDROPDOWN_CHARSET
473 function PMA_sqlQueryFormUpload() {
476 $matcher = '@\.sql(\.(' . PMA_supportedDecompressions() . '))?$@'; // we allow only SQL here
478 if (!empty($GLOBALS['cfg']['UploadDir'])) {
479 $files = PMA_getFileSelectOptions(PMA_userDir($GLOBALS['cfg']['UploadDir']), $matcher, (isset($timeout_passed) && $timeout_passed && isset($local_import_file)) ?
$local_import_file : '');
485 echo '<fieldset id="">';
487 echo $GLOBALS['strLocationTextfile'] . '</legend>';
488 echo '<div class="formelement">';
489 echo '<input type="file" name="sql_file" class="textfield" /> ';
490 echo PMA_displayMaximumUploadSize( $GLOBALS['max_upload_size'] );
491 // some browsers should respect this :)
492 echo PMA_generateHiddenMaxFileSize( $GLOBALS['max_upload_size'] ) . "\n";
495 if ($files === FALSE) {
496 $errors[$GLOBALS['strError']] = $GLOBALS['strWebServerUploadDirectoryError'];
497 } elseif (!empty($files)) {
498 echo '<div class="formelement">';
499 echo '<strong>' . $GLOBALS['strWebServerUploadDirectory'] .':</strong>' . "\n";
500 echo '<select size="1" name="sql_localfile">' . "\n";
501 echo '<option value="" selected="selected"></option>' . "\n";
503 echo '</select>' . "\n";
507 echo '<div class="clearfloat"></div>' . "\n";
511 echo '<fieldset id="" class="tblFooters">';
512 if ( PMA_MYSQL_INT_VERSION
< 40100
513 && $GLOBALS['cfg']['AllowAnywhereRecoding']
514 && $GLOBALS['allow_recoding'] ) {
515 echo $GLOBALS['strCharsetOfFile'] . "\n"
516 . '<select name="charset_of_file" size="1">' . "\n";
517 foreach( $GLOBALS['cfg']['AvailableCharsets'] as $temp_charset ) {
518 echo '<option value="' . $temp_charset . '"';
519 if ( $temp_charset == $GLOBALS['charset'] ) {
520 echo ' selected="selected"';
522 echo '>' . $temp_charset . '</option>' . "\n";
524 echo '</select>' . "\n";
525 } elseif ( PMA_MYSQL_INT_VERSION
>= 40100 ) {
526 echo $GLOBALS['strCharsetOfFile'] . "\n";
527 echo PMA_generateCharsetDropdownBox( PMA_CSDROPDOWN_CHARSET
,
528 'charset_of_file', NULL, 'utf8', FALSE );
529 } // end if (recoding)
530 echo '<input type="submit" name="SQL" value="' . $GLOBALS['strGo']
532 echo '<div class="clearfloat"></div>' . "\n";
535 foreach( $errors as $error => $message ) {
536 echo '<div>' . $error . '</div>';
537 echo '<div>' . $message . '</div>';