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.php'; // used for file listing
22 require_once './libraries/bookmark.lib.php'; // used for file listing
25 * prints the sql query boxes
27 * @usedby server_sql.php
30 * @usedby tbl_structure.php
31 * @usedby tbl_tracking.php
32 * @usedby querywindow.php
33 * @param boolean|string $query query to display in the textarea
34 * or true to display last executed
35 * @param boolean|string $display_tab sql|files|history|full|false
36 * what part to display
37 * false if not inside querywindow
38 * @param string $delimiter
40 function PMA_sqlQueryForm($query = true, $display_tab = false, $delimiter = ';')
42 // check tab to display if inside querywindow
44 $display_tab = 'full';
45 $is_querywindow = false;
47 $is_querywindow = true;
51 if (true === $query) {
52 $query = $GLOBALS['sql_query'];
55 // set enctype to multipart for file uploads
56 if ($GLOBALS['is_upload']) {
57 $enctype = ' enctype="multipart/form-data"';
64 if (! strlen($GLOBALS['db'])) {
65 // prepare for server related
66 $goto = empty($GLOBALS['goto']) ?
67 'server_sql.php' : $GLOBALS['goto'];
68 } elseif (! strlen($GLOBALS['table'])) {
69 // prepare for db related
71 $goto = empty($GLOBALS['goto']) ?
72 'db_sql.php' : $GLOBALS['goto'];
74 $table = $GLOBALS['table'];
76 $goto = empty($GLOBALS['goto']) ?
77 'tbl_sql.php' : $GLOBALS['goto'];
82 if ($is_querywindow) {
84 <form method
="post" id
="sqlqueryform" target
="frame_content"
85 action
="import.php"<?php
echo $enctype; ?
> name
="sqlform"
86 onsubmit
="var save_name = window.opener.parent.frame_content.name;
87 window.opener.parent.frame_content.name = save_name + '<?php echo time(); ?>';
88 this.target = window.opener.parent.frame_content.name;
89 return checkSqlQuery(this)">
92 echo '<form method="post" action="import.php" ' . $enctype;
93 if ($GLOBALS['cfg']['AjaxEnable']) {
96 echo ' id="sqlqueryform" name="sqlform">' . "\n";
99 if ($is_querywindow) {
100 echo '<input type="hidden" name="focus_querywindow" value="true" />'
102 if ($display_tab != 'sql' && $display_tab != 'full') {
103 echo '<input type="hidden" name="sql_query" value="" />' . "\n";
104 echo '<input type="hidden" name="show_query" value="1" />' . "\n";
107 echo '<input type="hidden" name="is_js_confirmed" value="0" />' . "\n"
108 .PMA_generate_common_hidden_inputs($db, $table) . "\n"
109 .'<input type="hidden" name="pos" value="0" />' . "\n"
110 .'<input type="hidden" name="goto" value="'
111 .htmlspecialchars($goto) . '" />' . "\n"
112 .'<input type="hidden" name="message_to_show" value="'
113 . __('Your SQL query has been executed successfully') . '" />' . "\n"
114 .'<input type="hidden" name="prev_sql_query" value="'
115 . htmlspecialchars($query) . '" />' . "\n";
118 if ($display_tab === 'full' ||
$display_tab === 'sql') {
119 PMA_sqlQueryFormInsert($query, $is_querywindow, $delimiter);
123 if ($display_tab === 'files' && $GLOBALS['is_upload']) {
124 PMA_sqlQueryFormUpload();
128 if ($display_tab === 'full' ||
$display_tab === 'history') {
129 if (! empty($GLOBALS['cfg']['Bookmark'])) {
130 PMA_sqlQueryFormBookmark();
134 // Encoding setting form appended by Y.Kawada
135 if (function_exists('PMA_set_enc_form')) {
136 echo PMA_set_enc_form(' ');
139 echo '</form>' . "\n";
140 if ($is_querywindow) {
142 <script type
="text/javascript">
145 window
.opener
.parent
.insertQuery();
152 // print an empty div, which will be later filled with the sql query results by ajax
153 echo '<div id="sqlqueryresults"></div>';
157 * prints querybox fieldset
159 * @usedby PMA_sqlQueryForm()
160 * @param string $query query to display in the textarea
161 * @param boolean $is_querywindow if inside querywindow or not
162 * @param string $delimiter default delimiter to use
164 function PMA_sqlQueryFormInsert($query = '', $is_querywindow = false, $delimiter = ';')
167 // enable auto select text in textarea
168 if ($GLOBALS['cfg']['TextareaAutoSelect']) {
169 $auto_sel = ' onclick="selectContent(this, sql_box_locked, true)"';
174 // enable locking if inside query window
175 if ($is_querywindow) {
176 $locking = ' onkeypress="document.sqlform.elements[\'LockFromUpdate\'].'
178 $height = $GLOBALS['cfg']['TextareaRows'] * 1.25;
181 $height = $GLOBALS['cfg']['TextareaRows'] * 2;
186 $fields_list = array();
187 if (! strlen($GLOBALS['db'])) {
188 // prepare for server related
189 $legend = sprintf(__('Run SQL query/queries on server %s'),
190 '"' . htmlspecialchars(
191 ! empty($GLOBALS['cfg']['Servers'][$GLOBALS['server']]['verbose']) ?
$GLOBALS['cfg']['Servers'][$GLOBALS['server']]['verbose'] : $GLOBALS['cfg']['Servers'][$GLOBALS['server']]['host']) . '"');
192 } elseif (! strlen($GLOBALS['table'])) {
193 // prepare for db related
194 $db = $GLOBALS['db'];
195 // if you want navigation:
196 $tmp_db_link = '<a href="' . $GLOBALS['cfg']['DefaultTabDatabase']
197 . '?' . PMA_generate_common_url($db) . '"';
198 if ($is_querywindow) {
199 $tmp_db_link .= ' target="_self"'
200 . ' onclick="this.target=window.opener.frame_content.name"';
203 . htmlspecialchars($db) . '</a>';
205 // $tmp_db_link = htmlspecialchars($db);
206 $legend = sprintf(__('Run SQL query/queries on database %s'), $tmp_db_link);
208 $query = PMA_expandUserString($GLOBALS['cfg']['DefaultQueryDatabase'], 'PMA_backquote');
211 $table = $GLOBALS['table'];
212 $db = $GLOBALS['db'];
213 // Get the list and number of fields
214 // we do a try_query here, because we could be in the query window,
215 // trying to synchonize and the table has not yet been created
216 $fields_list = PMA_DBI_get_columns($db, $GLOBALS['table'], null, true);
218 $tmp_db_link = '<a href="' . $GLOBALS['cfg']['DefaultTabDatabase']
219 . '?' . PMA_generate_common_url($db) . '"';
220 if ($is_querywindow) {
221 $tmp_db_link .= ' target="_self"'
222 . ' onclick="this.target=window.opener.frame_content.name"';
225 . htmlspecialchars($db) . '</a>';
227 // $tmp_db_link = htmlspecialchars($db);
228 $legend = sprintf(__('Run SQL query/queries on database %s'), $tmp_db_link);
230 $query = PMA_expandUserString($GLOBALS['cfg']['DefaultQueryTable'], 'PMA_backquote');
233 $legend .= ': ' . PMA_showMySQLDocu('SQL-Syntax', 'SELECT');
235 if (count($fields_list)) {
236 $sqlquerycontainer_id = 'sqlquerycontainer';
238 $sqlquerycontainer_id = 'sqlquerycontainerfull';
241 echo '<a name="querybox"></a>' . "\n"
242 .'<div id="queryboxcontainer">' . "\n"
243 .'<fieldset id="querybox">' . "\n";
244 echo '<legend>' . $legend . '</legend>' . "\n";
245 echo '<div id="queryfieldscontainer">' . "\n";
246 echo '<div id="' . $sqlquerycontainer_id . '">' . "\n"
247 .'<textarea tabindex="100" name="sql_query" id="sqlquery"'
248 .' cols="' . $GLOBALS['cfg']['TextareaCols'] . '"'
249 .' rows="' . $height . '"'
250 .' dir="' . $GLOBALS['text_dir'] . '"'
251 .$auto_sel . $locking . '>' . htmlspecialchars($query) . '</textarea>' . "\n";
252 // Add buttons to generate query easily for select all,single select,insert,update and delete
253 if (count($fields_list)) {
254 echo '<input type="button" value="SELECT *" id="selectall" class="sqlbutton" />';
255 echo '<input type="button" value="SELECT" id="select" class="sqlbutton" />';
256 echo '<input type="button" value="INSERT" id="insert" class="sqlbutton" />';
257 echo '<input type="button" value="UPDATE" id="update" class="sqlbutton" />';
258 echo '<input type="button" value="DELETE" id="delete" class="sqlbutton" />';
260 echo '<input type="button" value="' . __('Clear') . '" id="clear" class="sqlbutton" />';
261 echo '</div>' . "\n";
263 if (count($fields_list)) {
264 echo '<div id="tablefieldscontainer">' . "\n"
265 .'<label>' . __('Columns') . '</label>' . "\n"
266 .'<select id="tablefields" name="dummy" '
267 .'size="' . ($GLOBALS['cfg']['TextareaRows'] - 2) . '" '
268 .'multiple="multiple" ondblclick="insertValueQuery()">' . "\n";
269 foreach ($fields_list as $field) {
270 echo '<option value="'
271 .PMA_backquote(htmlspecialchars($field['Field'])) . '"';
272 if (isset($field['Field']) && strlen($field['Field']) && isset($field['Comment'])) {
273 echo ' title="' . htmlspecialchars($field['Comment']) . '"';
275 echo '>' . htmlspecialchars($field['Field']) . '</option>' . "\n";
277 echo '</select>' . "\n"
278 .'<div id="tablefieldinsertbuttoncontainer">' . "\n";
279 if ($GLOBALS['cfg']['PropertiesIconic']) {
280 echo '<input type="button" name="insert" value="<<"'
281 .' onclick="insertValueQuery()"'
282 .' title="' . __('Insert') . '" />' . "\n";
284 echo '<input type="button" name="insert"'
285 .' value="' . __('Insert') . '"'
286 .' onclick="insertValueQuery()" />' . "\n";
292 echo '<div class="clearfloat"></div>' . "\n";
293 echo '</div>' . "\n";
295 if (! empty($GLOBALS['cfg']['Bookmark'])) {
297 <div id
="bookmarkoptions">
298 <div
class="formelement">
299 <label
for="bkm_label">
300 <?php
echo __('Bookmark this SQL query'); ?
>:</label
>
301 <input type
="text" name
="bkm_label" id
="bkm_label" tabindex
="110" value
="" />
303 <div
class="formelement">
304 <input type
="checkbox" name
="bkm_all_users" tabindex
="111" id
="id_bkm_all_users"
306 <label
for="id_bkm_all_users">
307 <?php
echo __('Let every user access this bookmark'); ?
></label
>
309 <div
class="formelement">
310 <input type
="checkbox" name
="bkm_replace" tabindex
="112" id
="id_bkm_replace"
312 <label
for="id_bkm_replace">
313 <?php
echo __('Replace existing bookmark of same name'); ?
></label
>
319 echo '<div class="clearfloat"></div>' . "\n";
320 echo '</fieldset>' . "\n"
323 echo '<fieldset id="queryboxfooter" class="tblFooters">' . "\n";
324 echo '<div class="formelement">' . "\n";
325 if ($is_querywindow) {
327 <script type
="text/javascript">
329 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> ');
334 echo '</div>' . "\n";
335 echo '<div class="formelement">' . "\n";
336 echo '<label for="id_sql_delimiter">[ ' . __('Delimiter')
338 echo '<input type="text" name="sql_delimiter" tabindex="131" size="3" '
339 .'value="' . $delimiter . '" '
340 .'id="id_sql_delimiter" /> ]' . "\n";
342 echo '<input type="checkbox" name="show_query" value="1" '
343 .'id="checkbox_show_query" tabindex="132" checked="checked" />' . "\n"
344 .'<label for="checkbox_show_query">' . __('Show this query here again')
347 if (! $is_querywindow) {
348 echo '<input type="checkbox" name="retain_query_box" value="1" '
349 . 'id="retain_query_box" tabindex="133" '
350 . ($GLOBALS['cfg']['RetainQueryBox'] === false ?
'' : ' checked="checked"')
352 . '<label for="retain_query_box">' . __('Retain query box')
355 echo '</div>' . "\n";
356 echo '<input type="submit" id="button_submit_query" name="SQL" tabindex="200" value="' . __('Go') . '" />'
358 echo '<div class="clearfloat"></div>' . "\n";
359 echo '</fieldset>' . "\n";
363 * prints bookmark fieldset
365 * @usedby PMA_sqlQueryForm()
367 function PMA_sqlQueryFormBookmark()
369 $bookmark_list = PMA_Bookmark_getList($GLOBALS['db']);
370 if (! $bookmark_list ||
count($bookmark_list) < 1) {
374 echo '<fieldset id="bookmarkoptions">';
376 echo __('Bookmarked SQL query') . '</legend>' . "\n";
377 echo '<div class="formelement">';
378 echo '<select name="id_bookmark" id="id_bookmark">' . "\n";
379 echo '<option value=""> </option>' . "\n";
380 foreach ($bookmark_list as $key => $value) {
381 echo '<option value="' . htmlspecialchars($key) . '">'
382 .htmlspecialchars($value) . '</option>' . "\n";
384 // is required for correct display with styles/line height
385 echo '</select> ' . "\n";
386 echo '</div>' . "\n";
387 echo '<div class="formelement">' . "\n";
389 if ($GLOBALS['cfg']['ReplaceHelpImg']) {
390 echo ' <a href="./Documentation.html#faqbookmark"'
391 .' target="documentation">'
392 . PMA_getImage('b_help.png', __('Documentation')) . '</a>';
394 echo ' (<a href="./Documentation.html#faqbookmark"'
395 .' target="documentation">' . __('Documentation') . '</a>): ';
397 echo '<input type="text" name="bookmark_variable" class="textfield"'
398 .' size="10" />' . "\n";
399 echo '</div>' . "\n";
400 echo '<div class="formelement">' . "\n";
401 echo '<input type="radio" name="action_bookmark" value="0"'
402 .' id="radio_bookmark_exe" checked="checked" />'
403 .'<label for="radio_bookmark_exe">' . __('Submit')
405 echo '<input type="radio" name="action_bookmark" value="1"'
406 .' id="radio_bookmark_view" />'
407 .'<label for="radio_bookmark_view">' . __('View only')
409 echo '<input type="radio" name="action_bookmark" value="2"'
410 .' id="radio_bookmark_del" />'
411 .'<label for="radio_bookmark_del">' . __('Delete')
413 echo '</div>' . "\n";
414 echo '<div class="clearfloat"></div>' . "\n";
415 echo '</fieldset>' . "\n";
417 echo '<fieldset id="bookmarkoptionsfooter" class="tblFooters">' . "\n";
418 echo '<input type="submit" name="SQL" id="button_submit_bookmark" value="' . __('Go') . '" />';
419 echo '<div class="clearfloat"></div>' . "\n";
420 echo '</fieldset>' . "\n";
424 * prints bookmark fieldset
426 * @usedby PMA_sqlQueryForm()
428 function PMA_sqlQueryFormUpload()
432 $matcher = '@\.sql(\.(' . PMA_supportedDecompressions() . '))?$@'; // we allow only SQL here
434 if (!empty($GLOBALS['cfg']['UploadDir'])) {
435 $files = PMA_getFileSelectOptions(PMA_userDir($GLOBALS['cfg']['UploadDir']), $matcher, (isset($timeout_passed) && $timeout_passed && isset($local_import_file)) ?
$local_import_file : '');
441 echo '<fieldset id="">';
443 echo __('Browse your computer:') . '</legend>';
444 echo '<div class="formelement">';
445 echo '<input type="file" name="sql_file" class="textfield" /> ';
446 echo PMA_displayMaximumUploadSize($GLOBALS['max_upload_size']);
447 // some browsers should respect this :)
448 echo PMA_generateHiddenMaxFileSize($GLOBALS['max_upload_size']) . "\n";
451 if ($files === false) {
452 $errors[] = PMA_Message
::error( __('The directory you set for upload work cannot be reached'));
453 } elseif (!empty($files)) {
454 echo '<div class="formelement">';
455 echo '<strong>' . __('web server upload directory') .':</strong>' . "\n";
456 echo '<select size="1" name="sql_localfile">' . "\n";
457 echo '<option value="" selected="selected"></option>' . "\n";
459 echo '</select>' . "\n";
463 echo '<div class="clearfloat"></div>' . "\n";
467 echo '<fieldset id="" class="tblFooters">';
468 echo __('Character set of the file:') . "\n";
469 echo PMA_generateCharsetDropdownBox(PMA_CSDROPDOWN_CHARSET
,
470 'charset_of_file', null, 'utf8', false);
471 echo '<input type="submit" name="SQL" value="' . __('Go')
473 echo '<div class="clearfloat"></div>' . "\n";
476 foreach ($errors as $error) {