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 tbl_tracking.php
12 * @usedby querywindow.php
15 if (! defined('PHPMYADMIN')) {
22 require_once './libraries/file_listing.php'; // used for file listing
23 require_once './libraries/bookmark.lib.php'; // used for file listing
26 * prints the sql query boxes
28 * @usedby server_sql.php
31 * @usedby tbl_structure.php
32 * @usedby tbl_tracking.php
33 * @usedby querywindow.php
34 * @uses $GLOBALS['table']
35 * @uses $GLOBALS['db']
36 * @uses $GLOBALS['server']
37 * @uses $GLOBALS['goto']
38 * @uses $GLOBALS['is_upload'] from common.inc.php
39 * @uses $GLOBALS['sql_query'] from grab_globals.lib.php
40 * @uses $GLOBALS['cfg']['DefaultQueryTable']
41 * @uses $GLOBALS['cfg']['DefaultQueryDatabase']
42 * @uses $GLOBALS['cfg']['Servers']
43 * @uses $GLOBALS['cfg']['DefaultTabDatabase']
44 * @uses $GLOBALS['cfg']['DefaultQueryDatabase']
45 * @uses $GLOBALS['cfg']['DefaultQueryTable']
46 * @uses $GLOBALS['cfg']['Bookmark']
47 * @uses $GLOBALS['strSuccess']
48 * @uses PMA_generate_common_url()
49 * @uses PMA_backquote()
50 * @uses PMA_DBI_fetch_result()
51 * @uses PMA_showMySQLDocu()
52 * @uses PMA_generate_common_hidden_inputs()
53 * @uses PMA_sqlQueryFormBookmark()
54 * @uses PMA_sqlQueryFormInsert()
55 * @uses PMA_sqlQueryFormUpload()
56 * @uses PMA_DBI_QUERY_STORE
57 * @uses PMA_set_enc_form()
59 * @uses htmlspecialchars()
62 * @uses function_exists()
63 * @param boolean|string $query query to display in the textarea
64 * or true to display last executed
65 * @param boolean|string $display_tab sql|files|history|full|FALSE
66 * what part to display
67 * false if not inside querywindow
68 * @param string $delimiter
70 function PMA_sqlQueryForm($query = true, $display_tab = false, $delimiter = ';')
72 // check tab to display if inside querywindow
74 $display_tab = 'full';
75 $is_querywindow = false;
77 $is_querywindow = true;
81 if (true === $query) {
82 $query = $GLOBALS['sql_query'];
85 // set enctype to multipart for file uploads
86 if ($GLOBALS['is_upload']) {
87 $enctype = ' enctype="multipart/form-data"';
94 if (! strlen($GLOBALS['db'])) {
95 // prepare for server related
96 $goto = empty($GLOBALS['goto']) ?
97 'server_sql.php' : $GLOBALS['goto'];
98 } elseif (! strlen($GLOBALS['table'])) {
99 // prepare for db related
100 $db = $GLOBALS['db'];
101 $goto = empty($GLOBALS['goto']) ?
102 'db_sql.php' : $GLOBALS['goto'];
104 $table = $GLOBALS['table'];
105 $db = $GLOBALS['db'];
106 $goto = empty($GLOBALS['goto']) ?
107 'tbl_sql.php' : $GLOBALS['goto'];
112 if ($is_querywindow) {
114 <form method
="post" id
="sqlqueryform" target
="frame_content"
115 action
="import.php"<?php
echo $enctype; ?
> name
="sqlform"
116 onsubmit
="var save_name = window.opener.parent.frame_content.name;
117 window.opener.parent.frame_content.name = save_name + '<?php echo time(); ?>';
118 this.target = window.opener.parent.frame_content.name;
119 return checkSqlQuery(this)">
122 echo '<form method="post" action="import.php" ' . $enctype . ' id="sqlqueryform"'
123 .' onsubmit="return checkSqlQuery(this)" name="sqlform">' . "\n";
126 if ($is_querywindow) {
127 echo '<input type="hidden" name="focus_querywindow" value="true" />'
129 if ($display_tab != 'sql' && $display_tab != 'full') {
130 echo '<input type="hidden" name="sql_query" value="" />' . "\n";
131 echo '<input type="hidden" name="show_query" value="1" />' . "\n";
134 echo '<input type="hidden" name="is_js_confirmed" value="0" />' . "\n"
135 .PMA_generate_common_hidden_inputs($db, $table) . "\n"
136 .'<input type="hidden" name="pos" value="0" />' . "\n"
137 .'<input type="hidden" name="goto" value="'
138 .htmlspecialchars($goto) . '" />' . "\n"
139 .'<input type="hidden" name="zero_rows" value="'
140 . htmlspecialchars($GLOBALS['strSuccess']) . '" />' . "\n"
141 .'<input type="hidden" name="prev_sql_query" value="'
142 . htmlspecialchars($query) . '" />' . "\n";
145 if ($display_tab === 'full' ||
$display_tab === 'sql') {
146 PMA_sqlQueryFormInsert($query, $is_querywindow, $delimiter);
150 if ($display_tab === 'files' && $GLOBALS['is_upload']) {
151 PMA_sqlQueryFormUpload();
155 if ($display_tab === 'full' ||
$display_tab === 'history') {
156 if (! empty($GLOBALS['cfg']['Bookmark'])) {
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 // Add buttons to generate query easily for select all,single select,insert,update and delete
300 if(count($fields_list)) {
301 echo '<input type="button" value="SELECT *" id="selectall" class="sqlbutton" />';
302 echo '<input type="button" value="SELECT" id="select" class="sqlbutton" />';
303 echo '<input type="button" value="INSERT" id="insert" class="sqlbutton" />';
304 echo '<input type="button" value="UPDATE" id="update" class="sqlbutton" />';
305 echo '<input type="button" value="DELETE" id="delete" class="sqlbutton" />';
307 echo '</div>' . "\n";
309 echo '<script type="text/javascript">' . "\n"
310 .'//<![CDATA[' . "\n"
311 .'document.getElementById("sqlquery").focus();' . "\n"
315 if (count($fields_list)) {
316 echo '<div id="tablefieldscontainer">' . "\n"
317 .'<label>' . $GLOBALS['strFields'] . '</label>' . "\n"
318 .'<select id="tablefields" name="dummy" '
319 .'size="' . ($GLOBALS['cfg']['TextareaRows'] - 2) . '" '
320 .'multiple="multiple" ondblclick="insertValueQuery()">' . "\n";
321 foreach ($fields_list as $field) {
322 echo '<option value="'
323 .PMA_backquote(htmlspecialchars($field['Field'])) . '"';
324 if (isset($field['Field']) && strlen($field['Field']) && isset($field['Comment'])) {
325 echo ' title="' . htmlspecialchars($field['Comment']) . '"';
327 echo '>' . htmlspecialchars($field['Field']) . '</option>' . "\n";
329 echo '</select>' . "\n"
330 .'<div id="tablefieldinsertbuttoncontainer">' . "\n";
331 if ($GLOBALS['cfg']['PropertiesIconic']) {
332 echo '<input type="button" name="insert" value="<<"'
333 .' onclick="insertValueQuery()"'
334 .' title="' . $GLOBALS['strInsert'] . '" />' . "\n";
336 echo '<input type="button" name="insert"'
337 .' value="' . $GLOBALS['strInsert'] . '"'
338 .' onclick="insertValueQuery()" />' . "\n";
344 echo '<div class="clearfloat"></div>' . "\n";
345 echo '</div>' . "\n";
347 if (! empty($GLOBALS['cfg']['Bookmark'])) {
349 <div id
="bookmarkoptions">
350 <div
class="formelement">
351 <label
for="bkm_label">
352 <?php
echo $GLOBALS['strBookmarkThis']; ?
>:</label
>
353 <input type
="text" name
="bkm_label" id
="bkm_label" value
="" />
355 <div
class="formelement">
356 <input type
="checkbox" name
="bkm_all_users" id
="id_bkm_all_users"
358 <label
for="id_bkm_all_users">
359 <?php
echo $GLOBALS['strBookmarkAllUsers']; ?
></label
>
361 <div
class="formelement">
362 <input type
="checkbox" name
="bkm_replace" id
="id_bkm_replace"
364 <label
for="id_bkm_replace">
365 <?php
echo $GLOBALS['strBookmarkReplace']; ?
></label
>
371 echo '<div class="clearfloat"></div>' . "\n";
372 echo '</fieldset>' . "\n"
375 echo '<fieldset id="queryboxfooter" class="tblFooters">' . "\n";
376 echo '<div class="formelement">' . "\n";
377 if ($is_querywindow) {
379 <script type
="text/javascript">
381 document
.writeln(' <input type="checkbox" name="LockFromUpdate" value="1" id="checkbox_lock" /> <label for="checkbox_lock"><?php echo $GLOBALS['strQueryWindowLock
']; ?></label> ');
386 echo '</div>' . "\n";
387 echo '<div class="formelement">' . "\n";
388 echo '<label for="id_sql_delimiter">[ ' . $GLOBALS['strDelimiter']
390 echo '<input type="text" name="sql_delimiter" size="3" '
391 .'value="' . $delimiter . '" '
392 .'id="id_sql_delimiter" /> ]' . "\n";
394 echo '<input type="checkbox" name="show_query" value="1" '
395 .'id="checkbox_show_query" checked="checked" />' . "\n"
396 .'<label for="checkbox_show_query">' . $GLOBALS['strShowThisQuery']
399 echo '</div>' . "\n";
400 echo '<input type="submit" name="SQL" value="' . $GLOBALS['strGo'] . '" />'
402 echo '<div class="clearfloat"></div>' . "\n";
403 echo '</fieldset>' . "\n";
407 * prints bookmark fieldset
409 * @usedby PMA_sqlQueryForm()
410 * @uses PMA_Bookmark_getList()
411 * @uses $GLOBALS['db']
412 * @uses $GLOBALS['pmaThemeImage']
413 * @uses $GLOBALS['cfg']['ReplaceHelpImg']
414 * @uses $GLOBALS['strBookmarkQuery']
415 * @uses $GLOBALS['strBookmarkView']
416 * @uses $GLOBALS['strDelete']
417 * @uses $GLOBALS['strDocu']
418 * @uses $GLOBALS['strGo']
419 * @uses $GLOBALS['strSubmit']
420 * @uses $GLOBALS['strVar']
422 * @uses htmlspecialchars()
424 function PMA_sqlQueryFormBookmark()
426 $bookmark_list = PMA_Bookmark_getList($GLOBALS['db']);
427 if (! $bookmark_list ||
count($bookmark_list) < 1) {
431 echo '<fieldset id="bookmarkoptions">';
433 echo $GLOBALS['strBookmarkQuery'] . '</legend>' . "\n";
434 echo '<div class="formelement">';
435 echo '<select name="id_bookmark">' . "\n";
436 echo '<option value=""> </option>' . "\n";
437 foreach ($bookmark_list as $key => $value) {
438 echo '<option value="' . htmlspecialchars($key) . '">'
439 .htmlspecialchars($value) . '</option>' . "\n";
441 // is required for correct display with styles/line height
442 echo '</select> ' . "\n";
443 echo '</div>' . "\n";
444 echo '<div class="formelement">' . "\n";
445 echo $GLOBALS['strVar'];
446 if ($GLOBALS['cfg']['ReplaceHelpImg']) {
447 echo ' <a href="./Documentation.html#faqbookmark"'
448 .' target="documentation">'
449 .'<img class="icon" src="' . $GLOBALS['pmaThemeImage'] . 'b_help.png"'
450 .' border="0" width="11" height="11" align="middle"'
451 .' alt="' . $GLOBALS['strDocu'] . '" /></a> ';
453 echo ' (<a href="./Documentation.html#faqbookmark"'
454 .' target="documentation">' . $GLOBALS['strDocu'] . '</a>): ';
456 echo '<input type="text" name="bookmark_variable" class="textfield"'
457 .' size="10" />' . "\n";
458 echo '</div>' . "\n";
459 echo '<div class="formelement">' . "\n";
460 echo '<input type="radio" name="action_bookmark" value="0"'
461 .' id="radio_bookmark_exe" checked="checked" />'
462 .'<label for="radio_bookmark_exe">' . $GLOBALS['strSubmit']
464 echo '<input type="radio" name="action_bookmark" value="1"'
465 .' id="radio_bookmark_view" />'
466 .'<label for="radio_bookmark_view">' . $GLOBALS['strBookmarkView']
468 echo '<input type="radio" name="action_bookmark" value="2"'
469 .' id="radio_bookmark_del" />'
470 .'<label for="radio_bookmark_del">' . $GLOBALS['strDelete']
472 echo '</div>' . "\n";
473 echo '<div class="clearfloat"></div>' . "\n";
474 echo '</fieldset>' . "\n";
476 echo '<fieldset id="bookmarkoptionsfooter" class="tblFooters">' . "\n";
477 echo '<input type="submit" name="SQL" value="' . $GLOBALS['strGo'] . '" />';
478 echo '<div class="clearfloat"></div>' . "\n";
479 echo '</fieldset>' . "\n";
483 * prints bookmark fieldset
485 * @usedby PMA_sqlQueryForm()
486 * @uses $GLOBALS['cfg']['GZipDump']
487 * @uses $GLOBALS['cfg']['BZipDump']
488 * @uses $GLOBALS['cfg']['UploadDir']
489 * @uses $GLOBALS['cfg']['AvailableCharsets']
490 * @uses $GLOBALS['cfg']['AllowAnywhereRecoding']
491 * @uses $GLOBALS['strBzip']
492 * @uses $GLOBALS['strCharsetOfFile']
493 * @uses $GLOBALS['strCompression']
494 * @uses $GLOBALS['strError']
495 * @uses $GLOBALS['strGo']
496 * @uses $GLOBALS['strGzip']
497 * @uses $GLOBALS['strLocationTextfile']
498 * @uses $GLOBALS['strWebServerUploadDirectory']
499 * @uses $GLOBALS['strWebServerUploadDirectoryError']
500 * @uses $GLOBALS['charset']
501 * @uses $GLOBALS['max_upload_size']
502 * @uses PMA_supportedDecompressions()
503 * @uses PMA_getFileSelectOptions()
504 * @uses PMA_displayMaximumUploadSize()
505 * @uses PMA_generateCharsetDropdownBox()
506 * @uses PMA_generateHiddenMaxFileSize()
507 * @uses PMA_CSDROPDOWN_CHARSET
510 function PMA_sqlQueryFormUpload(){
513 $matcher = '@\.sql(\.(' . PMA_supportedDecompressions() . '))?$@'; // we allow only SQL here
515 if (!empty($GLOBALS['cfg']['UploadDir'])) {
516 $files = PMA_getFileSelectOptions(PMA_userDir($GLOBALS['cfg']['UploadDir']), $matcher, (isset($timeout_passed) && $timeout_passed && isset($local_import_file)) ?
$local_import_file : '');
522 echo '<fieldset id="">';
524 echo $GLOBALS['strLocationTextfile'] . '</legend>';
525 echo '<div class="formelement">';
526 echo '<input type="file" name="sql_file" class="textfield" /> ';
527 echo PMA_displayMaximumUploadSize($GLOBALS['max_upload_size']);
528 // some browsers should respect this :)
529 echo PMA_generateHiddenMaxFileSize($GLOBALS['max_upload_size']) . "\n";
532 if ($files === FALSE) {
533 $errors[] = PMA_Message
::error('strWebServerUploadDirectoryError');
534 } elseif (!empty($files)) {
535 echo '<div class="formelement">';
536 echo '<strong>' . $GLOBALS['strWebServerUploadDirectory'] .':</strong>' . "\n";
537 echo '<select size="1" name="sql_localfile">' . "\n";
538 echo '<option value="" selected="selected"></option>' . "\n";
540 echo '</select>' . "\n";
544 echo '<div class="clearfloat"></div>' . "\n";
548 echo '<fieldset id="" class="tblFooters">';
549 echo $GLOBALS['strCharsetOfFile'] . "\n";
550 echo PMA_generateCharsetDropdownBox(PMA_CSDROPDOWN_CHARSET
,
551 'charset_of_file', null, 'utf8', FALSE);
552 echo '<input type="submit" name="SQL" value="' . $GLOBALS['strGo']
554 echo '<div class="clearfloat"></div>' . "\n";
557 foreach ($errors as $error) {