Translation update done using Pootle.
[phpmyadmin.git] / libraries / sql_query_form.lib.php
blob9005f7d125f34dd36b6f23c9460c4af48b861f58
1 <?php
2 /* vim: set expandtab sw=4 ts=4 sts=4: */
3 /**
4 * functions for displaying the sql query form
6 * @usedby server_sql.php
7 * @usedby db_sql.php
8 * @usedby tbl_sql.php
9 * @usedby tbl_structure.php
10 * @usedby tbl_tracking.php
11 * @usedby querywindow.php
12 * @package PhpMyAdmin
14 if (! defined('PHPMYADMIN')) {
15 exit;
18 /**
21 require_once './libraries/file_listing.php'; // used for file listing
22 require_once './libraries/bookmark.lib.php'; // used for file listing
24 /**
25 * prints the sql query boxes
27 * @usedby server_sql.php
28 * @usedby db_sql.php
29 * @usedby tbl_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
43 if (! $display_tab) {
44 $display_tab = 'full';
45 $is_querywindow = false;
46 } else {
47 $is_querywindow = true;
50 // query to show
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"';
58 } else {
59 $enctype = '';
62 $table = '';
63 $db = '';
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
70 $db = $GLOBALS['db'];
71 $goto = empty($GLOBALS['goto']) ?
72 'db_sql.php' : $GLOBALS['goto'];
73 } else {
74 $table = $GLOBALS['table'];
75 $db = $GLOBALS['db'];
76 $goto = empty($GLOBALS['goto']) ?
77 'tbl_sql.php' : $GLOBALS['goto'];
81 // start output
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)">
90 <?php
91 } else {
92 echo '<form method="post" action="import.php" ' . $enctype;
93 if ($GLOBALS['cfg']['AjaxEnable']) {
94 echo ' class="ajax"';
96 echo ' id="sqlqueryform" name="sqlform">' . "\n";
99 if ($is_querywindow) {
100 echo '<input type="hidden" name="focus_querywindow" value="true" />'
101 ."\n";
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";
117 // display querybox
118 if ($display_tab === 'full' || $display_tab === 'sql') {
119 PMA_sqlQueryFormInsert($query, $is_querywindow, $delimiter);
122 // display uploads
123 if ($display_tab === 'files' && $GLOBALS['is_upload']) {
124 PMA_sqlQueryFormUpload();
127 // Bookmark Support
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">
143 //<![CDATA[
144 if (window.opener) {
145 window.opener.parent.insertQuery();
147 //]]>
148 </script>
149 <?php
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)"';
170 } else {
171 $auto_sel = '';
174 // enable locking if inside query window
175 if ($is_querywindow) {
176 $locking = ' onkeypress="document.sqlform.elements[\'LockFromUpdate\'].'
177 .'checked = true;"';
178 $height = $GLOBALS['cfg']['TextareaRows'] * 1.25;
179 } else {
180 $locking = '';
181 $height = $GLOBALS['cfg']['TextareaRows'] * 2;
184 $table = '';
185 $db = '';
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 '&quot;' . htmlspecialchars(
191 ! empty($GLOBALS['cfg']['Servers'][$GLOBALS['server']]['verbose']) ? $GLOBALS['cfg']['Servers'][$GLOBALS['server']]['verbose'] : $GLOBALS['cfg']['Servers'][$GLOBALS['server']]['host']) . '&quot;');
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"';
202 $tmp_db_link .= '>'
203 . htmlspecialchars($db) . '</a>';
204 // else use
205 // $tmp_db_link = htmlspecialchars($db);
206 $legend = sprintf(__('Run SQL query/queries on database %s'), $tmp_db_link);
207 if (empty($query)) {
208 $query = PMA_expandUserString($GLOBALS['cfg']['DefaultQueryDatabase'], 'PMA_backquote');
210 } else {
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"';
224 $tmp_db_link .= '>'
225 . htmlspecialchars($db) . '</a>';
226 // else use
227 // $tmp_db_link = htmlspecialchars($db);
228 $legend = sprintf(__('Run SQL query/queries on database %s'), $tmp_db_link);
229 if (empty($query)) {
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';
237 } else {
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="&lt;&lt;"'
281 .' onclick="insertValueQuery()"'
282 .' title="' . __('Insert') . '" />' . "\n";
283 } else {
284 echo '<input type="button" name="insert"'
285 .' value="' . __('Insert') . '"'
286 .' onclick="insertValueQuery()" />' . "\n";
288 echo '</div>' . "\n"
289 .'</div>' . "\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="" />
302 </div>
303 <div class="formelement">
304 <input type="checkbox" name="bkm_all_users" tabindex="111" id="id_bkm_all_users"
305 value="true" />
306 <label for="id_bkm_all_users">
307 <?php echo __('Let every user access this bookmark'); ?></label>
308 </div>
309 <div class="formelement">
310 <input type="checkbox" name="bkm_replace" tabindex="112" id="id_bkm_replace"
311 value="true" />
312 <label for="id_bkm_replace">
313 <?php echo __('Replace existing bookmark of same name'); ?></label>
314 </div>
315 </div>
316 <?php
319 echo '<div class="clearfloat"></div>' . "\n";
320 echo '</fieldset>' . "\n"
321 .'</div>' . "\n";
323 echo '<fieldset id="queryboxfooter" class="tblFooters">' . "\n";
324 echo '<div class="formelement">' . "\n";
325 if ($is_querywindow) {
327 <script type="text/javascript">
328 //<![CDATA[
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> ');
330 //]]>
331 </script>
332 <?php
334 echo '</div>' . "\n";
335 echo '<div class="formelement">' . "\n";
336 echo '<label for="id_sql_delimiter">[ ' . __('Delimiter')
337 .'</label>' . "\n";
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')
345 .'</label>' . "\n";
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"')
351 . ' />'
352 . '<label for="retain_query_box">' . __('Retain query box')
353 . '</label>';
355 echo '</div>' . "\n";
356 echo '<input type="submit" id="button_submit_query" name="SQL" tabindex="200" value="' . __('Go') . '" />'
357 ."\n";
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) {
371 return;
374 echo '<fieldset id="bookmarkoptions">';
375 echo '<legend>';
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="">&nbsp;</option>' . "\n";
380 foreach ($bookmark_list as $key => $value) {
381 echo '<option value="' . htmlspecialchars($key) . '">'
382 .htmlspecialchars($value) . '</option>' . "\n";
384 // &nbsp; is required for correct display with styles/line height
385 echo '</select>&nbsp;' . "\n";
386 echo '</div>' . "\n";
387 echo '<div class="formelement">' . "\n";
388 echo __('Variable');
389 if ($GLOBALS['cfg']['ReplaceHelpImg']) {
390 echo ' <a href="./Documentation.html#faqbookmark"'
391 .' target="documentation">'
392 . PMA_getImage('b_help.png', __('Documentation')) . '</a>';
393 } else {
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')
404 .'</label>' . "\n";
405 echo '<input type="radio" name="action_bookmark" value="1"'
406 .' id="radio_bookmark_view" />'
407 .'<label for="radio_bookmark_view">' . __('View only')
408 .'</label>' . "\n";
409 echo '<input type="radio" name="action_bookmark" value="2"'
410 .' id="radio_bookmark_del" />'
411 .'<label for="radio_bookmark_del">' . __('Delete')
412 .'</label>' . "\n";
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()
430 $errors = array ();
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 : '');
436 } else {
437 $files = '';
440 // start output
441 echo '<fieldset id="">';
442 echo '<legend>';
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";
449 echo '</div>';
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";
458 echo $files;
459 echo '</select>' . "\n";
460 echo '</div>';
463 echo '<div class="clearfloat"></div>' . "\n";
464 echo '</fieldset>';
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')
472 .'" />' . "\n";
473 echo '<div class="clearfloat"></div>' . "\n";
474 echo '</fieldset>';
476 foreach ($errors as $error) {
477 $error->display();