2 /* vim: set expandtab sw=4 ts=4 sts=4: */
4 * functions for displaying the sql query form
6 * @usedby server_sql.php
9 * @usedby tbl_structure.php
10 * @usedby tbl_tracking.php
11 * @usedby querywindow.php
14 if (! defined('PHPMYADMIN')) {
21 require_once './libraries/file_listing.lib.php'; // used for file listing
22 require_once './libraries/bookmark.lib.php'; // used for bookmarks
25 * Prints the sql query boxes
27 * @param boolean|string $query query to display in the textarea
28 * or true to display last executed
29 * @param boolean|string $display_tab sql|files|history|full|false
30 * what part to display
31 * false if not inside querywindow
32 * @param string $delimiter delimeter
36 * @usedby server_sql.php
39 * @usedby tbl_structure.php
40 * @usedby tbl_tracking.php
41 * @usedby querywindow.php
43 function PMA_sqlQueryForm($query = true, $display_tab = false, $delimiter = ';')
45 // check tab to display if inside querywindow
47 $display_tab = 'full';
48 $is_querywindow = false;
50 $is_querywindow = true;
54 if (true === $query) {
55 $query = $GLOBALS['sql_query'];
58 // set enctype to multipart for file uploads
59 if ($GLOBALS['is_upload']) {
60 $enctype = ' enctype="multipart/form-data"';
67 if (! strlen($GLOBALS['db'])) {
68 // prepare for server related
69 $goto = empty($GLOBALS['goto']) ?
70 'server_sql.php' : $GLOBALS['goto'];
71 } elseif (! strlen($GLOBALS['table'])) {
72 // prepare for db related
74 $goto = empty($GLOBALS['goto']) ?
75 'db_sql.php' : $GLOBALS['goto'];
77 $table = $GLOBALS['table'];
79 $goto = empty($GLOBALS['goto']) ?
80 'tbl_sql.php' : $GLOBALS['goto'];
85 if ($is_querywindow) {
87 <form method
="post" id
="sqlqueryform" target
="frame_content"
88 action
="import.php"<?php
echo $enctype; ?
> name
="sqlform"
89 onsubmit
="var save_name = window.opener.parent.frame_content.name;
90 window.opener.parent.frame_content.name = save_name + '<?php echo time(); ?>';
91 this.target = window.opener.parent.frame_content.name;
92 return checkSqlQuery(this)">
95 echo '<form method="post" action="import.php" ' . $enctype;
97 echo ' id="sqlqueryform" name="sqlform">' . "\n";
100 if ($is_querywindow) {
101 echo '<input type="hidden" name="focus_querywindow" value="true" />'
103 if ($display_tab != 'sql' && $display_tab != 'full') {
104 echo '<input type="hidden" name="sql_query" value="" />' . "\n";
105 echo '<input type="hidden" name="show_query" value="1" />' . "\n";
108 echo '<input type="hidden" name="is_js_confirmed" value="0" />' . "\n"
109 .PMA_generate_common_hidden_inputs($db, $table) . "\n"
110 .'<input type="hidden" name="pos" value="0" />' . "\n"
111 .'<input type="hidden" name="goto" value="'
112 .htmlspecialchars($goto) . '" />' . "\n"
113 .'<input type="hidden" name="message_to_show" value="'
114 . __('Your SQL query has been executed successfully') . '" />' . "\n"
115 .'<input type="hidden" name="prev_sql_query" value="'
116 . htmlspecialchars($query) . '" />' . "\n";
119 if ($display_tab === 'full' ||
$display_tab === 'sql') {
120 PMA_sqlQueryFormInsert($query, $is_querywindow, $delimiter);
124 if ($display_tab === 'files' && $GLOBALS['is_upload']) {
125 PMA_sqlQueryFormUpload();
129 if ($display_tab === 'full' ||
$display_tab === 'history') {
130 if (! empty($GLOBALS['cfg']['Bookmark'])) {
131 PMA_sqlQueryFormBookmark();
135 // Encoding setting form appended by Y.Kawada
136 if (function_exists('PMA_set_enc_form')) {
137 echo PMA_set_enc_form(' ');
140 echo '</form>' . "\n";
142 // print an empty div, which will be later filled with
143 // the sql query results by ajax
144 echo '<div id="sqlqueryresults"></div>';
148 * Prints querybox fieldset
150 * @param string $query query to display in the textarea
151 * @param boolean $is_querywindow if inside querywindow or not
152 * @param string $delimiter default delimiter to use
156 * @usedby PMA_sqlQueryForm()
158 function PMA_sqlQueryFormInsert(
159 $query = '', $is_querywindow = false, $delimiter = ';'
161 // enable auto select text in textarea
162 if ($GLOBALS['cfg']['TextareaAutoSelect']) {
163 $auto_sel = ' onclick="selectContent(this, sql_box_locked, true)"';
168 // enable locking if inside query window
169 if ($is_querywindow) {
170 $locking = ' onkeypress="document.sqlform.elements[\'LockFromUpdate\'].'
172 $height = $GLOBALS['cfg']['TextareaRows'] * 1.25;
175 $height = $GLOBALS['cfg']['TextareaRows'] * 2;
180 $fields_list = array();
181 if (! strlen($GLOBALS['db'])) {
182 // prepare for server related
184 __('Run SQL query/queries on server %s'),
185 '"' . htmlspecialchars(
186 ! empty($GLOBALS['cfg']['Servers'][$GLOBALS['server']]['verbose'])
187 ?
$GLOBALS['cfg']['Servers'][$GLOBALS['server']]['verbose']
188 : $GLOBALS['cfg']['Servers'][$GLOBALS['server']]['host']
191 } elseif (! strlen($GLOBALS['table'])) {
192 // prepare for db related
193 $db = $GLOBALS['db'];
194 // if you want navigation:
195 $tmp_db_link = '<a href="' . $GLOBALS['cfg']['DefaultTabDatabase']
196 . '?' . PMA_generate_common_url($db) . '"';
197 if ($is_querywindow) {
198 $tmp_db_link .= ' target="_self"'
199 . ' onclick="this.target=window.opener.frame_content.name"';
202 . htmlspecialchars($db) . '</a>';
204 // $tmp_db_link = htmlspecialchars($db);
205 $legend = sprintf(__('Run SQL query/queries on database %s'), $tmp_db_link);
207 $query = PMA_Util
::expandUserString(
208 $GLOBALS['cfg']['DefaultQueryDatabase'], 'backquote'
212 $table = $GLOBALS['table'];
213 $db = $GLOBALS['db'];
214 // Get the list and number of fields
215 // we do a try_query here, because we could be in the query window,
216 // trying to synchonize and the table has not yet been created
217 $fields_list = PMA_DBI_get_columns($db, $GLOBALS['table'], null, true);
219 $tmp_db_link = '<a href="' . $GLOBALS['cfg']['DefaultTabDatabase']
220 . '?' . PMA_generate_common_url($db) . '"';
221 if ($is_querywindow) {
222 $tmp_db_link .= ' target="_self"'
223 . ' onclick="this.target=window.opener.frame_content.name"';
226 . htmlspecialchars($db) . '</a>';
228 // $tmp_db_link = htmlspecialchars($db);
229 $legend = sprintf(__('Run SQL query/queries on database %s'), $tmp_db_link);
231 $query = PMA_Util
::expandUserString(
232 $GLOBALS['cfg']['DefaultQueryTable'], 'backquote'
236 $legend .= ': ' . PMA_Util
::showMySQLDocu('SQL-Syntax', 'SELECT');
238 if (count($fields_list)) {
239 $sqlquerycontainer_id = 'sqlquerycontainer';
241 $sqlquerycontainer_id = 'sqlquerycontainerfull';
244 echo '<a id="querybox"></a>' . "\n"
245 .'<div id="queryboxcontainer">' . "\n"
246 .'<fieldset id="queryboxf">' . "\n";
247 echo '<legend>' . $legend . '</legend>' . "\n";
248 echo '<div id="queryfieldscontainer">' . "\n";
249 echo '<div id="' . $sqlquerycontainer_id . '">' . "\n"
250 .'<textarea tabindex="100" name="sql_query" id="sqlquery"'
251 .' cols="' . $GLOBALS['cfg']['TextareaCols'] . '"'
252 .' rows="' . $height . '"'
253 .' dir="' . $GLOBALS['text_dir'] . '"'
254 .$auto_sel . $locking . '>'
255 . htmlspecialchars($query)
256 . '</textarea>' . "\n";
257 // Add buttons to generate query easily for
258 // select all, single select, insert, update and delete
259 if (count($fields_list)) {
260 echo '<input type="button" value="SELECT *" id="selectall" class="button sqlbutton" />';
261 echo '<input type="button" value="SELECT" id="select" class="button sqlbutton" />';
262 echo '<input type="button" value="INSERT" id="insert" class="button sqlbutton" />';
263 echo '<input type="button" value="UPDATE" id="update" class="button sqlbutton" />';
264 echo '<input type="button" value="DELETE" id="delete" class="button sqlbutton" />';
266 echo '<input type="button" value="' . __('Clear') . '" id="clear" class="button sqlbutton" />';
267 echo '</div>' . "\n";
269 if (count($fields_list)) {
270 echo '<div id="tablefieldscontainer">' . "\n"
271 .'<label>' . __('Columns') . '</label>' . "\n"
272 .'<select id="tablefields" name="dummy" '
273 .'size="' . ($GLOBALS['cfg']['TextareaRows'] - 2) . '" '
274 .'multiple="multiple" ondblclick="insertValueQuery()">' . "\n";
275 foreach ($fields_list as $field) {
276 echo '<option value="'
277 .PMA_Util
::backquote(htmlspecialchars($field['Field'])) . '"';
278 if (isset($field['Field'])
279 && strlen($field['Field'])
280 && isset($field['Comment'])
282 echo ' title="' . htmlspecialchars($field['Comment']) . '"';
284 echo '>' . htmlspecialchars($field['Field']) . '</option>' . "\n";
286 echo '</select>' . "\n"
287 .'<div id="tablefieldinsertbuttoncontainer">' . "\n";
288 if ($GLOBALS['cfg']['PropertiesIconic']) {
289 echo '<input type="button" class="button" name="insert" value="<<"'
290 .' onclick="insertValueQuery()"'
291 .' title="' . __('Insert') . '" />' . "\n";
293 echo '<input type="button" class="button" name="insert"'
294 .' value="' . __('Insert') . '"'
295 .' onclick="insertValueQuery()" />' . "\n";
301 echo '<div class="clearfloat"></div>' . "\n";
302 echo '</div>' . "\n";
304 if (! empty($GLOBALS['cfg']['Bookmark'])) {
306 <div id
="bookmarkoptions">
307 <div
class="formelement">
308 <label
for="bkm_label">
309 <?php
echo __('Bookmark this SQL query'); ?
>:</label
>
310 <input type
="text" name
="bkm_label" id
="bkm_label" tabindex
="110" value
="" />
312 <div
class="formelement">
313 <input type
="checkbox" name
="bkm_all_users" tabindex
="111" id
="id_bkm_all_users" value
="true" />
314 <label
for="id_bkm_all_users">
315 <?php
echo __('Let every user access this bookmark'); ?
></label
>
317 <div
class="formelement">
318 <input type
="checkbox" name
="bkm_replace" tabindex
="112" id
="id_bkm_replace"
320 <label
for="id_bkm_replace">
321 <?php
echo __('Replace existing bookmark of same name'); ?
></label
>
327 echo '<div class="clearfloat"></div>' . "\n";
328 echo '</fieldset>' . "\n"
331 echo '<fieldset id="queryboxfooter" class="tblFooters">' . "\n";
332 echo '<div class="formelement">' . "\n";
333 if ($is_querywindow) {
335 <script type
="text/javascript">
337 document
.writeln(' <input type="checkbox" name="LockFromUpdate" checked="checked" tabindex="120" id="checkbox_lock" /> <label for="checkbox_lock"><?php echo __('Do not overwrite this query from outside the window
'); ?></label> ');
342 echo '</div>' . "\n";
343 echo '<div class="formelement">' . "\n";
344 echo '<label for="id_sql_delimiter">[ ' . __('Delimiter')
346 echo '<input type="text" name="sql_delimiter" tabindex="131" size="3" '
347 .'value="' . $delimiter . '" '
348 .'id="id_sql_delimiter" /> ]' . "\n";
350 echo '<input type="checkbox" name="show_query" value="1" '
351 .'id="checkbox_show_query" tabindex="132" checked="checked" />' . "\n"
352 .'<label for="checkbox_show_query">' . __('Show this query here again')
355 if (! $is_querywindow) {
356 echo '<input type="checkbox" name="retain_query_box" value="1" '
357 . 'id="retain_query_box" tabindex="133" '
358 . ($GLOBALS['cfg']['RetainQueryBox'] === false
359 ?
'' : ' checked="checked"')
361 . '<label for="retain_query_box">' . __('Retain query box')
364 echo '</div>' . "\n";
365 echo '<input type="submit" id="button_submit_query" name="SQL" tabindex="200" value="' . __('Go') . '" />'
367 echo '<div class="clearfloat"></div>' . "\n";
368 echo '</fieldset>' . "\n";
372 * Prints bookmark fieldset
376 * @usedby PMA_sqlQueryForm()
378 function PMA_sqlQueryFormBookmark()
380 $bookmark_list = PMA_Bookmark_getList($GLOBALS['db']);
381 if (! $bookmark_list ||
count($bookmark_list) < 1) {
385 echo '<fieldset id="bookmarkoptions">';
387 echo __('Bookmarked SQL query') . '</legend>' . "\n";
388 echo '<div class="formelement">';
389 echo '<select name="id_bookmark" id="id_bookmark">' . "\n";
390 echo '<option value=""> </option>' . "\n";
391 foreach ($bookmark_list as $key => $value) {
392 echo '<option value="' . htmlspecialchars($key) . '">'
393 .htmlspecialchars($value) . '</option>' . "\n";
395 // is required for correct display with styles/line height
396 echo '</select> ' . "\n";
397 echo '</div>' . "\n";
398 echo '<div class="formelement">' . "\n";
400 echo PMA_Util
::showDocu('faq', 'faqbookmark');
401 echo '<input type="text" name="bookmark_variable" class="textfield"'
402 .' size="10" />' . "\n";
403 echo '</div>' . "\n";
404 echo '<div class="formelement">' . "\n";
405 echo '<input type="radio" name="action_bookmark" value="0"'
406 .' id="radio_bookmark_exe" checked="checked" />'
407 .'<label for="radio_bookmark_exe">' . __('Submit')
409 echo '<input type="radio" name="action_bookmark" value="1"'
410 .' id="radio_bookmark_view" />'
411 .'<label for="radio_bookmark_view">' . __('View only')
413 echo '<input type="radio" name="action_bookmark" value="2"'
414 .' id="radio_bookmark_del" />'
415 .'<label for="radio_bookmark_del">' . __('Delete')
417 echo '</div>' . "\n";
418 echo '<div class="clearfloat"></div>' . "\n";
419 echo '</fieldset>' . "\n";
421 echo '<fieldset id="bookmarkoptionsfooter" class="tblFooters">' . "\n";
422 echo '<input type="submit" name="SQL" id="button_submit_bookmark" value="' . __('Go') . '" />';
423 echo '<div class="clearfloat"></div>' . "\n";
424 echo '</fieldset>' . "\n";
428 * Prints bookmark fieldset
432 * @usedby PMA_sqlQueryForm()
434 function PMA_sqlQueryFormUpload()
436 global $timeout_passed, $local_import_file;
440 // we allow only SQL here
441 $matcher = '@\.sql(\.(' . PMA_supportedDecompressions() . '))?$@';
443 if (!empty($GLOBALS['cfg']['UploadDir'])) {
444 $files = PMA_getFileSelectOptions(
445 PMA_Util
::userDir($GLOBALS['cfg']['UploadDir']), $matcher,
446 (isset($timeout_passed) && $timeout_passed && isset($local_import_file))
455 echo '<fieldset id="">';
457 echo __('Browse your computer:') . '</legend>';
458 echo '<div class="formelement">';
459 echo '<input type="file" name="sql_file" class="textfield" /> ';
460 echo PMA_Util
::getFormattedMaximumUploadSize($GLOBALS['max_upload_size']);
461 // some browsers should respect this :)
462 echo PMA_Util
::generateHiddenMaxFileSize($GLOBALS['max_upload_size']) . "\n";
465 if ($files === false) {
466 $errors[] = PMA_Message
::error(__('The directory you set for upload work cannot be reached'));
467 } elseif (!empty($files)) {
468 echo '<div class="formelement">';
469 echo '<strong>' . __('web server upload directory') .':</strong>' . "\n";
470 echo '<select size="1" name="sql_localfile">' . "\n";
471 echo '<option value="" selected="selected"></option>' . "\n";
473 echo '</select>' . "\n";
477 echo '<div class="clearfloat"></div>' . "\n";
481 echo '<fieldset id="" class="tblFooters">';
482 echo __('Character set of the file:') . "\n";
483 echo PMA_generateCharsetDropdownBox(
484 PMA_CSDROPDOWN_CHARSET
,
485 'charset_of_file', null, 'utf8', false
487 echo '<input type="submit" name="SQL" value="' . __('Go')
489 echo '<div class="clearfloat"></div>' . "\n";
492 foreach ($errors as $error) {