new language: uzbek (cyrillic and latin)
[phpmyadmin/crack.git] / libraries / sql_query_form.lib.php
blobd82f1aeabdf94e3ebd107575e6612ecf5ca763cd
1 <?php
2 /* vim: set expandtab sw=4 ts=4 sts=4: */
3 /**
4 * functions for displaying the sql query form
6 * @version $Id$
7 * @usedby server_sql.php
8 * @usedby db_sql.php
9 * @usedby tbl_sql.php
10 * @usedby tbl_structure.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 querywindow.php
32 * @uses $GLOBALS['table']
33 * @uses $GLOBALS['db']
34 * @uses $GLOBALS['server']
35 * @uses $GLOBALS['goto']
36 * @uses $GLOBALS['is_upload'] from common.inc.php
37 * @uses $GLOBALS['sql_query'] from grab_globals.lib.php
38 * @uses $GLOBALS['cfg']['DefaultQueryTable']
39 * @uses $GLOBALS['cfg']['DefaultQueryDatabase']
40 * @uses $GLOBALS['cfg']['Servers']
41 * @uses $GLOBALS['cfg']['DefaultTabDatabase']
42 * @uses $GLOBALS['cfg']['DefaultQueryDatabase']
43 * @uses $GLOBALS['cfg']['DefaultQueryTable']
44 * @uses $GLOBALS['cfg']['Bookmark']
45 * @uses $GLOBALS['strSuccess']
46 * @uses PMA_generate_common_url()
47 * @uses PMA_backquote()
48 * @uses PMA_DBI_fetch_result()
49 * @uses PMA_showMySQLDocu()
50 * @uses PMA_generate_common_hidden_inputs()
51 * @uses PMA_sqlQueryFormBookmark()
52 * @uses PMA_sqlQueryFormInsert()
53 * @uses PMA_sqlQueryFormUpload()
54 * @uses PMA_DBI_QUERY_STORE
55 * @uses PMA_set_enc_form()
56 * @uses sprintf()
57 * @uses htmlspecialchars()
58 * @uses str_replace()
59 * @uses md5()
60 * @uses function_exists()
61 * @param boolean|string $query query to display in the textarea
62 * or true to display last executed
63 * @param boolean|string $display_tab sql|files|history|full|FALSE
64 * what part to display
65 * false if not inside querywindow
66 * @param string $delimiter
68 function PMA_sqlQueryForm($query = true, $display_tab = false, $delimiter = ';')
70 // check tab to display if inside querywindow
71 if (! $display_tab) {
72 $display_tab = 'full';
73 $is_querywindow = false;
74 } else {
75 $is_querywindow = true;
78 // query to show
79 if (true === $query) {
80 $query = $GLOBALS['sql_query'];
83 // set enctype to multipart for file uploads
84 if ($GLOBALS['is_upload']) {
85 $enctype = ' enctype="multipart/form-data"';
86 } else {
87 $enctype = '';
90 $table = '';
91 $db = '';
92 if (! strlen($GLOBALS['db'])) {
93 // prepare for server related
94 $goto = empty($GLOBALS['goto']) ?
95 'server_sql.php' : $GLOBALS['goto'];
96 } elseif (! strlen($GLOBALS['table'])) {
97 // prepare for db related
98 $db = $GLOBALS['db'];
99 $goto = empty($GLOBALS['goto']) ?
100 'db_sql.php' : $GLOBALS['goto'];
101 } else {
102 $table = $GLOBALS['table'];
103 $db = $GLOBALS['db'];
104 $goto = empty($GLOBALS['goto']) ?
105 'tbl_sql.php' : $GLOBALS['goto'];
109 // start output
110 if ($is_querywindow) {
112 <form method="post" id="sqlqueryform" target="frame_content"
113 action="import.php"<?php echo $enctype; ?> name="sqlform"
114 onsubmit="var save_name = window.opener.parent.frame_content.name;
115 window.opener.parent.frame_content.name = save_name + '<?php echo time(); ?>';
116 this.target = window.opener.parent.frame_content.name;
117 return checkSqlQuery(this)">
118 <?php
119 } else {
120 echo '<form method="post" action="import.php" ' . $enctype . ' id="sqlqueryform"'
121 .' onsubmit="return checkSqlQuery(this)" name="sqlform">' . "\n";
124 if ($is_querywindow) {
125 echo '<input type="hidden" name="focus_querywindow" value="true" />'
126 ."\n";
127 if ($display_tab != 'sql' && $display_tab != 'full') {
128 echo '<input type="hidden" name="sql_query" value="" />' . "\n";
129 echo '<input type="hidden" name="show_query" value="1" />' . "\n";
132 echo '<input type="hidden" name="is_js_confirmed" value="0" />' . "\n"
133 .PMA_generate_common_hidden_inputs($db, $table) . "\n"
134 .'<input type="hidden" name="pos" value="0" />' . "\n"
135 .'<input type="hidden" name="goto" value="'
136 .htmlspecialchars($goto) . '" />' . "\n"
137 .'<input type="hidden" name="zero_rows" value="'
138 . htmlspecialchars($GLOBALS['strSuccess']) . '" />' . "\n"
139 .'<input type="hidden" name="prev_sql_query" value="'
140 . htmlspecialchars($query) . '" />' . "\n";
142 // display querybox
143 if ($display_tab === 'full' || $display_tab === 'sql') {
144 PMA_sqlQueryFormInsert($query, $is_querywindow, $delimiter);
147 // display uploads
148 if ($display_tab === 'files' && $GLOBALS['is_upload']) {
149 PMA_sqlQueryFormUpload();
152 // Bookmark Support
153 if ($display_tab === 'full' || $display_tab === 'history') {
154 if (! empty($GLOBALS['cfg']['Bookmark'])) {
155 PMA_sqlQueryFormBookmark();
159 // Encoding setting form appended by Y.Kawada
160 if (function_exists('PMA_set_enc_form')) {
161 echo PMA_set_enc_form(' ');
164 echo '</form>' . "\n";
165 if ($is_querywindow) {
167 <script type="text/javascript">
168 //<![CDATA[
169 if (window.opener) {
170 window.opener.parent.insertQuery();
172 //]]>
173 </script>
174 <?php
179 * prints querybox fieldset
181 * @usedby PMA_sqlQueryForm()
182 * @uses $GLOBALS['text_dir']
183 * @uses $GLOBALS['cfg']['TextareaAutoSelect']
184 * @uses $GLOBALS['cfg']['TextareaCols']
185 * @uses $GLOBALS['cfg']['TextareaRows']
186 * @uses $GLOBALS['strShowThisQuery']
187 * @uses $GLOBALS['strGo']
188 * @uses PMA_USR_OS
189 * @uses PMA_USR_BROWSER_AGENT
190 * @uses PMA_USR_BROWSER_VER
191 * @uses htmlspecialchars()
192 * @param string $query query to display in the textarea
193 * @param boolean $is_querywindow if inside querywindow or not
194 * @param string $delimiter default delimiter to use
196 function PMA_sqlQueryFormInsert($query = '', $is_querywindow = false, $delimiter = ';')
199 // enable auto select text in textarea
200 if ($GLOBALS['cfg']['TextareaAutoSelect']) {
201 $auto_sel = ' onfocus="selectContent(this, sql_box_locked, true)"';
202 } else {
203 $auto_sel = '';
206 // enable locking if inside query window
207 if ($is_querywindow) {
208 $locking = ' onkeypress="document.sqlform.elements[\'LockFromUpdate\'].'
209 .'checked = true;"';
210 $height = $GLOBALS['cfg']['TextareaRows'] * 1.25;
211 } else {
212 $locking = '';
213 $height = $GLOBALS['cfg']['TextareaRows'] * 2;
216 $table = '';
217 $db = '';
218 $fields_list = array();
219 if (! strlen($GLOBALS['db'])) {
220 // prepare for server related
221 $legend = sprintf($GLOBALS['strRunSQLQueryOnServer'],
222 '&quot;' . htmlspecialchars(
223 ! empty($GLOBALS['cfg']['Servers'][$GLOBALS['server']]['verbose']) ? $GLOBALS['cfg']['Servers'][$GLOBALS['server']]['verbose'] : $GLOBALS['cfg']['Servers'][$GLOBALS['server']]['host']) . '&quot;');
224 } elseif (! strlen($GLOBALS['table'])) {
225 // prepare for db related
226 $db = $GLOBALS['db'];
227 // if you want navigation:
228 $strDBLink = '<a href="' . $GLOBALS['cfg']['DefaultTabDatabase']
229 . '?' . PMA_generate_common_url($db) . '"';
230 if ($is_querywindow) {
231 $strDBLink .= ' target="_self"'
232 . ' onclick="this.target=window.opener.frame_content.name"';
234 $strDBLink .= '>'
235 . htmlspecialchars($db) . '</a>';
236 // else use
237 // $strDBLink = htmlspecialchars($db);
238 $legend = sprintf($GLOBALS['strRunSQLQuery'], $strDBLink);
239 if (empty($query)) {
240 $query = str_replace('%d',
241 PMA_backquote($db), $GLOBALS['cfg']['DefaultQueryDatabase']);
243 } else {
244 $table = $GLOBALS['table'];
245 $db = $GLOBALS['db'];
246 // Get the list and number of fields
247 // we do a try_query here, because we could be in the query window,
248 // trying to synchonize and the table has not yet been created
249 $fields_list = PMA_DBI_fetch_result(
250 'SHOW FULL COLUMNS FROM ' . PMA_backquote($db)
251 . '.' . PMA_backquote($GLOBALS['table']));
253 $strDBLink = '<a href="' . $GLOBALS['cfg']['DefaultTabDatabase']
254 . '?' . PMA_generate_common_url($db) . '"';
255 if ($is_querywindow) {
256 $strDBLink .= ' target="_self"'
257 . ' onclick="this.target=window.opener.frame_content.name"';
259 $strDBLink .= '>'
260 . htmlspecialchars($db) . '</a>';
261 // else use
262 // $strDBLink = htmlspecialchars($db);
263 $legend = sprintf($GLOBALS['strRunSQLQuery'], $strDBLink);
264 if (empty($query) && count($fields_list)) {
265 $field_names = array();
266 foreach ($fields_list as $field) {
267 $field_names[] = PMA_backquote($field['Field']);
269 $query =
270 str_replace('%d', PMA_backquote($db),
271 str_replace('%t', PMA_backquote($table),
272 str_replace('%f',
273 implode(', ', $field_names),
274 $GLOBALS['cfg']['DefaultQueryTable'])));
275 unset($field_names);
278 $legend .= ': ' . PMA_showMySQLDocu('SQL-Syntax', 'SELECT');
280 if (count($fields_list)) {
281 $sqlquerycontainer_id = 'sqlquerycontainer';
282 } else {
283 $sqlquerycontainer_id = 'sqlquerycontainerfull';
286 echo '<a name="querybox"></a>' . "\n"
287 .'<div id="queryboxcontainer">' . "\n"
288 .'<fieldset id="querybox">' . "\n";
289 echo '<legend>' . $legend . '</legend>' . "\n";
290 echo '<div id="queryfieldscontainer">' . "\n";
291 echo '<div id="' . $sqlquerycontainer_id . '">' . "\n"
292 .'<textarea name="sql_query" id="sqlquery"'
293 .' cols="' . $GLOBALS['cfg']['TextareaCols'] . '"'
294 .' rows="' . $height . '"'
295 .' dir="' . $GLOBALS['text_dir'] . '"'
296 .$auto_sel . $locking . '>' . htmlspecialchars($query) . '</textarea>' . "\n";
297 echo '</div>' . "\n";
299 if (count($fields_list)) {
300 echo '<div id="tablefieldscontainer">' . "\n"
301 .'<label>' . $GLOBALS['strFields'] . '</label>' . "\n"
302 .'<select id="tablefields" name="dummy" '
303 .'size="' . ($GLOBALS['cfg']['TextareaRows'] - 2) . '" '
304 .'multiple="multiple" ondblclick="insertValueQuery()">' . "\n";
305 foreach ($fields_list as $field) {
306 echo '<option value="'
307 .PMA_backquote(htmlspecialchars($field['Field'])) . '"';
308 if (isset($field['Field']) && strlen($field['Field']) && isset($field['Comment'])) {
309 echo ' title="' . htmlspecialchars($field['Comment']) . '"';
311 echo '>' . htmlspecialchars($field['Field']) . '</option>' . "\n";
313 echo '</select>' . "\n"
314 .'<div id="tablefieldinsertbuttoncontainer">' . "\n";
315 if ($GLOBALS['cfg']['PropertiesIconic']) {
316 echo '<input type="button" name="insert" value="&lt;&lt;"'
317 .' onclick="insertValueQuery()"'
318 .' title="' . $GLOBALS['strInsert'] . '" />' . "\n";
319 } else {
320 echo '<input type="button" name="insert"'
321 .' value="' . $GLOBALS['strInsert'] . '"'
322 .' onclick="insertValueQuery()" />' . "\n";
324 echo '</div>' . "\n"
325 .'</div>' . "\n";
328 echo '<div class="clearfloat"></div>' . "\n";
329 echo '</div>' . "\n";
331 if (! empty($GLOBALS['cfg']['Bookmark'])) {
333 <div id="bookmarkoptions">
334 <div class="formelement">
335 <label for="bkm_label">
336 <?php echo $GLOBALS['strBookmarkThis']; ?>:</label>
337 <input type="text" name="bkm_label" id="bkm_label" value="" />
338 </div>
339 <div class="formelement">
340 <input type="checkbox" name="bkm_all_users" id="id_bkm_all_users"
341 value="true" />
342 <label for="id_bkm_all_users">
343 <?php echo $GLOBALS['strBookmarkAllUsers']; ?></label>
344 </div>
345 <div class="formelement">
346 <input type="checkbox" name="bkm_replace" id="id_bkm_replace"
347 value="true" />
348 <label for="id_bkm_replace">
349 <?php echo $GLOBALS['strBookmarkReplace']; ?></label>
350 </div>
351 </div>
352 <?php
355 echo '<div class="clearfloat"></div>' . "\n";
356 echo '</fieldset>' . "\n"
357 .'</div>' . "\n";
359 echo '<fieldset id="queryboxfooter" class="tblFooters">' . "\n";
360 echo '<div class="formelement">' . "\n";
361 if ($is_querywindow) {
363 <script type="text/javascript">
364 //<![CDATA[
365 document.writeln(' <input type="checkbox" name="LockFromUpdate" value="1" id="checkbox_lock" /> <label for="checkbox_lock"><?php echo $GLOBALS['strQueryWindowLock']; ?></label> ');
366 //]]>
367 </script>
368 <?php
370 echo '</div>' . "\n";
371 echo '<div class="formelement">' . "\n";
372 echo '<label for="id_sql_delimiter">[ ' . $GLOBALS['strDelimiter']
373 .'</label>' . "\n";
374 echo '<input type="text" name="sql_delimiter" size="3" '
375 .'value="' . $delimiter . '" '
376 .'id="id_sql_delimiter" /> ]' . "\n";
378 echo '<input type="checkbox" name="show_query" value="1" '
379 .'id="checkbox_show_query" checked="checked" />' . "\n"
380 .'<label for="checkbox_show_query">' . $GLOBALS['strShowThisQuery']
381 .'</label>' . "\n";
383 echo '</div>' . "\n";
384 echo '<input type="submit" name="SQL" value="' . $GLOBALS['strGo'] . '" />'
385 ."\n";
386 echo '<div class="clearfloat"></div>' . "\n";
387 echo '</fieldset>' . "\n";
391 * prints bookmark fieldset
393 * @usedby PMA_sqlQueryForm()
394 * @uses PMA_Bookmark_getList()
395 * @uses $GLOBALS['db']
396 * @uses $GLOBALS['pmaThemeImage']
397 * @uses $GLOBALS['cfg']['ReplaceHelpImg']
398 * @uses $GLOBALS['strBookmarkQuery']
399 * @uses $GLOBALS['strBookmarkView']
400 * @uses $GLOBALS['strDelete']
401 * @uses $GLOBALS['strDocu']
402 * @uses $GLOBALS['strGo']
403 * @uses $GLOBALS['strSubmit']
404 * @uses $GLOBALS['strVar']
405 * @uses count()
406 * @uses htmlspecialchars()
408 function PMA_sqlQueryFormBookmark()
410 $bookmark_list = PMA_Bookmark_getList($GLOBALS['db']);
411 if (! $bookmark_list || count($bookmark_list) < 1) {
412 return;
415 echo '<fieldset id="bookmarkoptions">';
416 echo '<legend>';
417 echo $GLOBALS['strBookmarkQuery'] . '</legend>' . "\n";
418 echo '<div class="formelement">';
419 echo '<select name="id_bookmark">' . "\n";
420 echo '<option value="">&nbsp;</option>' . "\n";
421 foreach ($bookmark_list as $key => $value) {
422 echo '<option value="' . htmlspecialchars($key) . '">'
423 .htmlspecialchars($value) . '</option>' . "\n";
425 // &nbsp; is required for correct display with styles/line height
426 echo '</select>&nbsp;' . "\n";
427 echo '</div>' . "\n";
428 echo '<div class="formelement">' . "\n";
429 echo $GLOBALS['strVar'];
430 if ($GLOBALS['cfg']['ReplaceHelpImg']) {
431 echo ' <a href="./Documentation.html#faqbookmark"'
432 .' target="documentation">'
433 .'<img class="icon" src="' . $GLOBALS['pmaThemeImage'] . 'b_help.png"'
434 .' border="0" width="11" height="11" align="middle"'
435 .' alt="' . $GLOBALS['strDocu'] . '" /></a> ';
436 } else {
437 echo ' (<a href="./Documentation.html#faqbookmark"'
438 .' target="documentation">' . $GLOBALS['strDocu'] . '</a>): ';
440 echo '<input type="text" name="bookmark_variable" class="textfield"'
441 .' size="10" />' . "\n";
442 echo '</div>' . "\n";
443 echo '<div class="formelement">' . "\n";
444 echo '<input type="radio" name="action_bookmark" value="0"'
445 .' id="radio_bookmark_exe" checked="checked" />'
446 .'<label for="radio_bookmark_exe">' . $GLOBALS['strSubmit']
447 .'</label>' . "\n";
448 echo '<input type="radio" name="action_bookmark" value="1"'
449 .' id="radio_bookmark_view" />'
450 .'<label for="radio_bookmark_view">' . $GLOBALS['strBookmarkView']
451 .'</label>' . "\n";
452 echo '<input type="radio" name="action_bookmark" value="2"'
453 .' id="radio_bookmark_del" />'
454 .'<label for="radio_bookmark_del">' . $GLOBALS['strDelete']
455 .'</label>' . "\n";
456 echo '</div>' . "\n";
457 echo '<div class="clearfloat"></div>' . "\n";
458 echo '</fieldset>' . "\n";
460 echo '<fieldset id="bookmarkoptionsfooter" class="tblFooters">' . "\n";
461 echo '<input type="submit" name="SQL" value="' . $GLOBALS['strGo'] . '" />';
462 echo '<div class="clearfloat"></div>' . "\n";
463 echo '</fieldset>' . "\n";
467 * prints bookmark fieldset
469 * @usedby PMA_sqlQueryForm()
470 * @uses $GLOBALS['cfg']['GZipDump']
471 * @uses $GLOBALS['cfg']['BZipDump']
472 * @uses $GLOBALS['cfg']['UploadDir']
473 * @uses $GLOBALS['cfg']['AvailableCharsets']
474 * @uses $GLOBALS['cfg']['AllowAnywhereRecoding']
475 * @uses $GLOBALS['strBzip']
476 * @uses $GLOBALS['strCharsetOfFile']
477 * @uses $GLOBALS['strCompression']
478 * @uses $GLOBALS['strError']
479 * @uses $GLOBALS['strGo']
480 * @uses $GLOBALS['strGzip']
481 * @uses $GLOBALS['strLocationTextfile']
482 * @uses $GLOBALS['strWebServerUploadDirectory']
483 * @uses $GLOBALS['strWebServerUploadDirectoryError']
484 * @uses $GLOBALS['charset']
485 * @uses $GLOBALS['max_upload_size']
486 * @uses PMA_supportedDecompressions()
487 * @uses PMA_getFileSelectOptions()
488 * @uses PMA_displayMaximumUploadSize()
489 * @uses PMA_generateCharsetDropdownBox()
490 * @uses PMA_generateHiddenMaxFileSize()
491 * @uses PMA_CSDROPDOWN_CHARSET
492 * @uses empty()
494 function PMA_sqlQueryFormUpload(){
495 $errors = array ();
497 $matcher = '@\.sql(\.(' . PMA_supportedDecompressions() . '))?$@'; // we allow only SQL here
499 if (!empty($GLOBALS['cfg']['UploadDir'])) {
500 $files = PMA_getFileSelectOptions(PMA_userDir($GLOBALS['cfg']['UploadDir']), $matcher, (isset($timeout_passed) && $timeout_passed && isset($local_import_file)) ? $local_import_file : '');
501 } else {
502 $files = '';
505 // start output
506 echo '<fieldset id="">';
507 echo '<legend>';
508 echo $GLOBALS['strLocationTextfile'] . '</legend>';
509 echo '<div class="formelement">';
510 echo '<input type="file" name="sql_file" class="textfield" /> ';
511 echo PMA_displayMaximumUploadSize($GLOBALS['max_upload_size']);
512 // some browsers should respect this :)
513 echo PMA_generateHiddenMaxFileSize($GLOBALS['max_upload_size']) . "\n";
514 echo '</div>';
516 if ($files === FALSE) {
517 $errors[] = PMA_Message::error('strWebServerUploadDirectoryError');
518 } elseif (!empty($files)) {
519 echo '<div class="formelement">';
520 echo '<strong>' . $GLOBALS['strWebServerUploadDirectory'] .':</strong>' . "\n";
521 echo '<select size="1" name="sql_localfile">' . "\n";
522 echo '<option value="" selected="selected"></option>' . "\n";
523 echo $files;
524 echo '</select>' . "\n";
525 echo '</div>';
528 echo '<div class="clearfloat"></div>' . "\n";
529 echo '</fieldset>';
532 echo '<fieldset id="" class="tblFooters">';
533 echo $GLOBALS['strCharsetOfFile'] . "\n";
534 echo PMA_generateCharsetDropdownBox(PMA_CSDROPDOWN_CHARSET,
535 'charset_of_file', null, 'utf8', FALSE);
536 echo '<input type="submit" name="SQL" value="' . $GLOBALS['strGo']
537 .'" />' . "\n";
538 echo '<div class="clearfloat"></div>' . "\n";
539 echo '</fieldset>';
541 foreach ($errors as $error) {
542 $error->display();