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 $html = '<form method="post" action="import.php" ' . $enctype;
96 $html .= ' class="ajax"';
97 $html .= ' id="sqlqueryform" name="sqlform">' . "\n";
100 if ($is_querywindow) {
101 $html .= '<input type="hidden" name="focus_querywindow"'
102 .' value="true" />' . "\n";
103 if ($display_tab != 'sql' && $display_tab != 'full') {
104 $html .= '<input type="hidden" name="sql_query"'
105 .' value="" />' . "\n";
106 $html .= '<input type="hidden" name="show_query"'
107 .' value="1" />' . "\n";
110 $html .= '<input type="hidden" name="is_js_confirmed" value="0" />'
111 . "\n" . PMA_generate_common_hidden_inputs($db, $table) . "\n"
112 .'<input type="hidden" name="pos" value="0" />' . "\n"
113 .'<input type="hidden" name="goto" value="'
114 .htmlspecialchars($goto) . '" />' . "\n"
115 .'<input type="hidden" name="message_to_show" value="'
116 . __('Your SQL query has been executed successfully') . '" />'
117 . "\n" .'<input type="hidden" name="prev_sql_query" value="'
118 . htmlspecialchars($query) . '" />' . "\n";
123 if ($display_tab === 'full' ||
$display_tab === 'sql') {
124 PMA_sqlQueryFormInsert($query, $is_querywindow, $delimiter);
128 if ($display_tab === 'files' && $GLOBALS['is_upload']) {
129 PMA_sqlQueryFormUpload();
133 if ($display_tab === 'full' ||
$display_tab === 'history') {
134 if (! empty($GLOBALS['cfg']['Bookmark'])) {
135 PMA_sqlQueryFormBookmark();
139 // Encoding setting form appended by Y.Kawada
140 if (function_exists('PMA_Kanji_encodingForm')) {
141 echo PMA_Kanji_encodingForm();
144 $html = '</form>' . "\n";
145 // print an empty div, which will be later filled with
146 // the sql query results by ajax
147 $html .= '<div id="sqlqueryresults"></div>';
152 * Prints querybox fieldset
154 * @param string $query query to display in the textarea
155 * @param boolean $is_querywindow if inside querywindow or not
156 * @param string $delimiter default delimiter to use
160 * @usedby PMA_sqlQueryForm()
162 function PMA_sqlQueryFormInsert(
163 $query = '', $is_querywindow = false, $delimiter = ';'
165 // enable auto select text in textarea
166 if ($GLOBALS['cfg']['TextareaAutoSelect']) {
167 $auto_sel = ' onclick="selectContent(this, sql_box_locked, true);"';
172 // enable locking if inside query window
173 if ($is_querywindow) {
174 $locking = ' onkeypress="document.sqlform.elements[\'LockFromUpdate\'].'
176 $height = $GLOBALS['cfg']['TextareaRows'] * 1.25;
179 $height = $GLOBALS['cfg']['TextareaRows'] * 2;
184 $fields_list = array();
185 if (! strlen($GLOBALS['db'])) {
186 // prepare for server related
188 __('Run SQL query/queries on server %s'),
189 '"' . htmlspecialchars(
190 ! empty($GLOBALS['cfg']['Servers'][$GLOBALS['server']]['verbose'])
191 ?
$GLOBALS['cfg']['Servers'][$GLOBALS['server']]['verbose']
192 : $GLOBALS['cfg']['Servers'][$GLOBALS['server']]['host']
195 } elseif (! strlen($GLOBALS['table'])) {
196 // prepare for db related
197 $db = $GLOBALS['db'];
198 // if you want navigation:
199 $tmp_db_link = '<a href="' . $GLOBALS['cfg']['DefaultTabDatabase']
200 . '?' . PMA_generate_common_url($db) . '"';
201 if ($is_querywindow) {
202 $tmp_db_link .= ' target="_self"'
203 . ' onclick="this.target=window.opener.frame_content.name"';
206 . htmlspecialchars($db) . '</a>';
208 // $tmp_db_link = htmlspecialchars($db);
209 $legend = sprintf(__('Run SQL query/queries on database %s'), $tmp_db_link);
211 $query = PMA_Util
::expandUserString(
212 $GLOBALS['cfg']['DefaultQueryDatabase'], 'backquote'
216 $table = $GLOBALS['table'];
217 $db = $GLOBALS['db'];
218 // Get the list and number of fields
219 // we do a try_query here, because we could be in the query window,
220 // trying to synchonize and the table has not yet been created
221 $fields_list = $GLOBALS['dbi']->getColumns($db, $GLOBALS['table'], null, true);
223 $tmp_db_link = '<a href="' . $GLOBALS['cfg']['DefaultTabDatabase']
224 . '?' . PMA_generate_common_url($db) . '"';
225 if ($is_querywindow) {
226 $tmp_db_link .= ' target="_self"'
227 . ' onclick="this.target=window.opener.frame_content.name"';
230 . htmlspecialchars($db) . '</a>';
232 // $tmp_db_link = htmlspecialchars($db);
233 $legend = sprintf(__('Run SQL query/queries on database %s'), $tmp_db_link);
235 $query = PMA_Util
::expandUserString(
236 $GLOBALS['cfg']['DefaultQueryTable'], 'backquote'
240 $legend .= ': ' . PMA_Util
::showMySQLDocu('SQL-Syntax', 'SELECT');
242 if (count($fields_list)) {
243 $sqlquerycontainer_id = 'sqlquerycontainer';
245 $sqlquerycontainer_id = 'sqlquerycontainerfull';
248 $html = '<a id="querybox"></a>'
249 . '<div id="queryboxcontainer">'
250 . '<fieldset id="queryboxf">';
251 $html .= '<legend>' . $legend . '</legend>';
252 $html .= '<div id="queryfieldscontainer">';
253 $html .= '<div id="' . $sqlquerycontainer_id . '">'
254 . '<textarea tabindex="100" name="sql_query" id="sqlquery"'
255 . ' cols="' . $GLOBALS['cfg']['TextareaCols'] . '"'
256 . ' rows="' . $height . '"'
257 . ' dir="' . $GLOBALS['text_dir'] . '"'
258 . $auto_sel . $locking . '>'
259 . htmlspecialchars($query)
261 // Add buttons to generate query easily for
262 // select all, single select, insert, update and delete
263 if (count($fields_list)) {
264 $html .= '<input type="button" value="SELECT *" id="selectall"'
265 . ' class="button sqlbutton" />';
266 $html .= '<input type="button" value="SELECT" id="select"'
267 . ' class="button sqlbutton" />';
268 $html .= '<input type="button" value="INSERT" id="insert"'
269 . ' class="button sqlbutton" />';
270 $html .= '<input type="button" value="UPDATE" id="update"'
271 . ' class="button sqlbutton" />';
272 $html .= '<input type="button" value="DELETE" id="delete"'
273 . ' class="button sqlbutton" />';
275 $html .= '<input type="button" value="' . __('Clear') . '" id="clear"'
276 . ' class="button sqlbutton" />';
277 $html .= '</div>' . "\n";
279 if (count($fields_list)) {
280 $html .= '<div id="tablefieldscontainer">'
281 . '<label>' . __('Columns') . '</label>'
282 . '<select id="tablefields" name="dummy" '
283 . 'size="' . ($GLOBALS['cfg']['TextareaRows'] - 2) . '" '
284 . 'multiple="multiple" ondblclick="insertValueQuery()">';
285 foreach ($fields_list as $field) {
286 $html .= '<option value="'
287 . PMA_Util
::backquote(htmlspecialchars($field['Field'])) . '"';
288 if (isset($field['Field'])
289 && strlen($field['Field'])
290 && isset($field['Comment'])
292 $html .= ' title="' . htmlspecialchars($field['Comment']) . '"';
294 $html .= '>' . htmlspecialchars($field['Field']) . '</option>' . "\n";
297 . '<div id="tablefieldinsertbuttoncontainer">';
298 if ($GLOBALS['cfg']['PropertiesIconic']) {
299 $html .= '<input type="button" class="button" name="insert"'
300 . ' value="<<" onclick="insertValueQuery()"'
301 . ' title="' . __('Insert') . '" />';
303 $html .= '<input type="button" class="button" name="insert"'
304 . ' value="' . __('Insert') . '"'
305 . ' onclick="insertValueQuery()" />';
307 $html .= '</div>' . "\n"
311 $html .= '<div class="clearfloat"></div>' . "\n";
312 $html .= '</div>' . "\n";
314 if (! empty($GLOBALS['cfg']['Bookmark'])) {
315 $html .= '<div id="bookmarkoptions">';
316 $html .= '<div class="formelement">';
317 $html .= '<label for="bkm_label">'
318 . __('Bookmark this SQL query:') . '</label>';
319 $html .= '<input type="text" name="bkm_label" id="bkm_label"'
320 . ' tabindex="110" value="" />';
322 $html .= '<div class="formelement">';
323 $html .= '<input type="checkbox" name="bkm_all_users" tabindex="111"'
324 . ' id="id_bkm_all_users" value="true" />';
325 $html .= '<label for="id_bkm_all_users">'
326 . __('Let every user access this bookmark') . '</label>';
328 $html .= '<div class="formelement">';
329 $html .= '<input type="checkbox" name="bkm_replace" tabindex="112"'
330 . ' id="id_bkm_replace" value="true" />';
331 $html .= '<label for="id_bkm_replace">'
332 . __('Replace existing bookmark of same name') . '</label>';
337 $html .= '<div class="clearfloat"></div>' . "\n";
338 $html .= '</fieldset>' . "\n"
341 $html .= '<fieldset id="queryboxfooter" class="tblFooters">' . "\n";
342 $html .= '<div class="formelement">' . "\n";
345 if ($is_querywindow) {
347 <script type
="text/javascript">
349 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> ');
354 $html = '</div>' . "\n";
355 $html .= '<div class="formelement">' . "\n";
356 $html .= '<label for="id_sql_delimiter">[ ' . __('Delimiter')
358 $html .= '<input type="text" name="sql_delimiter" tabindex="131" size="3" '
359 . 'value="' . $delimiter . '" '
360 . 'id="id_sql_delimiter" /> ]';
362 $html .= '<input type="checkbox" name="show_query" value="1" '
363 . 'id="checkbox_show_query" tabindex="132" checked="checked" />'
364 . '<label for="checkbox_show_query">' . __('Show this query here again')
367 if (! $is_querywindow) {
368 $html .= '<input type="checkbox" name="retain_query_box" value="1" '
369 . 'id="retain_query_box" tabindex="133" '
370 . ($GLOBALS['cfg']['RetainQueryBox'] === false
371 ?
'' : ' checked="checked"')
373 . '<label for="retain_query_box">' . __('Retain query box')
376 $html .= '</div>' . "\n";
377 $html .= '<input type="submit" id="button_submit_query" name="SQL" tabindex="200"'
378 . ' value="' . __('Go') . '" />' . "\n";
379 $html .= '<div class="clearfloat"></div>' . "\n";
380 $html .= '</fieldset>' . "\n";
385 * Prints bookmark fieldset
389 * @usedby PMA_sqlQueryForm()
391 function PMA_sqlQueryFormBookmark()
393 $bookmark_list = PMA_Bookmark_getList($GLOBALS['db']);
394 if (! $bookmark_list ||
count($bookmark_list) < 1) {
398 echo '<fieldset id="bookmarkoptions">';
400 echo __('Bookmarked SQL query') . '</legend>' . "\n";
401 echo '<div class="formelement">';
402 echo '<select name="id_bookmark" id="id_bookmark">' . "\n";
403 echo '<option value=""> </option>' . "\n";
404 foreach ($bookmark_list as $key => $value) {
405 echo '<option value="' . htmlspecialchars($key) . '">'
406 .htmlspecialchars($value) . '</option>' . "\n";
408 // is required for correct display with styles/line height
409 echo '</select> ' . "\n";
410 echo '</div>' . "\n";
411 echo '<div class="formelement">' . "\n";
413 echo PMA_Util
::showDocu('faq', 'faqbookmark');
414 echo '<input type="text" name="bookmark_variable" class="textfield"'
415 .' size="10" />' . "\n";
416 echo '</div>' . "\n";
417 echo '<div class="formelement">' . "\n";
418 echo '<input type="radio" name="action_bookmark" value="0"'
419 .' id="radio_bookmark_exe" checked="checked" />'
420 .'<label for="radio_bookmark_exe">' . __('Submit')
422 echo '<input type="radio" name="action_bookmark" value="1"'
423 .' id="radio_bookmark_view" />'
424 .'<label for="radio_bookmark_view">' . __('View only')
426 echo '<input type="radio" name="action_bookmark" value="2"'
427 .' id="radio_bookmark_del" />'
428 .'<label for="radio_bookmark_del">' . __('Delete')
430 echo '</div>' . "\n";
431 echo '<div class="clearfloat"></div>' . "\n";
432 echo '</fieldset>' . "\n";
434 echo '<fieldset id="bookmarkoptionsfooter" class="tblFooters">' . "\n";
435 echo '<input type="submit" name="SQL" id="button_submit_bookmark" value="' . __('Go') . '" />';
436 echo '<div class="clearfloat"></div>' . "\n";
437 echo '</fieldset>' . "\n";
441 * Prints bookmark fieldset
445 * @usedby PMA_sqlQueryForm()
447 function PMA_sqlQueryFormUpload()
449 global $timeout_passed, $local_import_file;
453 // we allow only SQL here
454 $matcher = '@\.sql(\.(' . PMA_supportedDecompressions() . '))?$@';
456 if (!empty($GLOBALS['cfg']['UploadDir'])) {
457 $files = PMA_getFileSelectOptions(
458 PMA_Util
::userDir($GLOBALS['cfg']['UploadDir']), $matcher,
459 (isset($timeout_passed) && $timeout_passed && isset($local_import_file))
468 echo '<fieldset id="">';
470 echo __('Browse your computer:') . '</legend>';
471 echo '<div class="formelement">';
472 echo '<input type="file" name="sql_file" class="textfield" /> ';
473 echo PMA_Util
::getFormattedMaximumUploadSize($GLOBALS['max_upload_size']);
474 // some browsers should respect this :)
475 echo PMA_Util
::generateHiddenMaxFileSize($GLOBALS['max_upload_size']) . "\n";
478 if ($files === false) {
479 $errors[] = PMA_Message
::error(__('The directory you set for upload work cannot be reached'));
480 } elseif (!empty($files)) {
481 echo '<div class="formelement">';
482 echo '<strong>' . __('web server upload directory:') .'</strong>' . "\n";
483 echo '<select size="1" name="sql_localfile">' . "\n";
484 echo '<option value="" selected="selected"></option>' . "\n";
486 echo '</select>' . "\n";
490 echo '<div class="clearfloat"></div>' . "\n";
494 echo '<fieldset id="" class="tblFooters">';
495 echo __('Character set of the file:') . "\n";
496 echo PMA_generateCharsetDropdownBox(
497 PMA_CSDROPDOWN_CHARSET
,
498 'charset_of_file', null, 'utf8', false
500 echo '<input type="submit" name="SQL" value="' . __('Go')
502 echo '<div class="clearfloat"></div>' . "\n";
505 foreach ($errors as $error) {