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
13 if (! defined('PHPMYADMIN')) {
20 require_once './libraries/file_listing.lib.php'; // used for file listing
21 require_once './libraries/bookmark.lib.php'; // used for bookmarks
24 * return HTML for the sql query boxes
26 * @param boolean|string $query query to display in the textarea
27 * or true to display last executed
28 * @param boolean|string $display_tab sql|files|history|full|false
29 * what part to display
30 * false if not inside querywindow
31 * @param string $delimiter delimiter
35 * @usedby server_sql.php
38 * @usedby tbl_structure.php
39 * @usedby tbl_tracking.php
41 function PMA_getHtmlForSqlQueryForm(
42 $query = true, $display_tab = false, $delimiter = ';'
46 $display_tab = 'full';
49 if (true === $query) {
50 $query = $GLOBALS['sql_query'];
53 // set enctype to multipart for file uploads
54 if ($GLOBALS['is_upload']) {
55 $enctype = ' enctype="multipart/form-data"';
62 if (! /*overload*/mb_strlen($GLOBALS['db'])) {
63 // prepare for server related
64 $goto = empty($GLOBALS['goto']) ?
65 'server_sql.php' : $GLOBALS['goto'];
66 } elseif (! /*overload*/mb_strlen($GLOBALS['table'])) {
67 // prepare for db related
69 $goto = empty($GLOBALS['goto']) ?
70 'db_sql.php' : $GLOBALS['goto'];
72 $table = $GLOBALS['table'];
74 $goto = empty($GLOBALS['goto']) ?
75 'tbl_sql.php' : $GLOBALS['goto'];
79 $html .= '<form method="post" action="import.php" ' . $enctype;
80 $html .= ' class="ajax lock-page"';
81 $html .= ' id="sqlqueryform" name="sqlform">' . "\n";
83 $html .= '<input type="hidden" name="is_js_confirmed" value="0" />'
84 . "\n" . PMA_URL_getHiddenInputs($db, $table) . "\n"
85 . '<input type="hidden" name="pos" value="0" />' . "\n"
86 . '<input type="hidden" name="goto" value="'
87 . htmlspecialchars($goto) . '" />' . "\n"
88 . '<input type="hidden" name="message_to_show" value="'
89 . __('Your SQL query has been executed successfully.') . '" />'
90 . "\n" . '<input type="hidden" name="prev_sql_query" value="'
91 . htmlspecialchars($query) . '" />' . "\n";
94 if ($display_tab === 'full' ||
$display_tab === 'sql') {
95 $html .= PMA_getHtmlForSqlQueryFormInsert(
101 if ($display_tab === 'files' && $GLOBALS['is_upload']) {
102 $html .= PMA_getHtmlForSqlQueryFormUpload();
106 if ($display_tab === 'full' ||
$display_tab === 'history') {
107 $cfgBookmark = PMA_Bookmark_getParams();
109 $html .= PMA_getHtmlForSqlQueryFormBookmark();
113 // Encoding setting form appended by Y.Kawada
114 if (function_exists('PMA_Kanji_encodingForm')) {
115 $html .= PMA_Kanji_encodingForm();
118 $html .= '</form>' . "\n";
119 // print an empty div, which will be later filled with
120 // the sql query results by ajax
121 $html .= '<div id="sqlqueryresultsouter"></div>';
127 * return HTML for Sql Query Form Insert
129 * @param string $query query to display in the textarea
130 * @param string $delimiter default delimiter to use
134 * @usedby PMA_getHtmlForSqlQueryForm()
136 function PMA_getHtmlForSqlQueryFormInsert(
137 $query = '', $delimiter = ';'
139 // enable auto select text in textarea
140 if ($GLOBALS['cfg']['TextareaAutoSelect']) {
141 $auto_sel = ' onclick="selectContent(this, sql_box_locked, true);"';
147 $height = $GLOBALS['cfg']['TextareaRows'] * 2;
149 $fields_list = array();
150 if (! /*overload*/mb_strlen($GLOBALS['db'])) {
151 // prepare for server related
153 __('Run SQL query/queries on server %s'),
154 '"' . htmlspecialchars(
155 ! empty($GLOBALS['cfg']['Servers'][$GLOBALS['server']]['verbose'])
156 ?
$GLOBALS['cfg']['Servers'][$GLOBALS['server']]['verbose']
157 : $GLOBALS['cfg']['Servers'][$GLOBALS['server']]['host']
160 } elseif (! /*overload*/mb_strlen($GLOBALS['table'])) {
161 // prepare for db related
162 $db = $GLOBALS['db'];
163 // if you want navigation:
164 $tmp_db_link = '<a href="' . $GLOBALS['cfg']['DefaultTabDatabase']
165 . PMA_URL_getCommon(array('db' => $db)) . '"';
167 . htmlspecialchars($db) . '</a>';
169 // $tmp_db_link = htmlspecialchars($db);
170 $legend = sprintf(__('Run SQL query/queries on database %s'), $tmp_db_link);
172 $query = PMA_Util
::expandUserString(
173 $GLOBALS['cfg']['DefaultQueryDatabase'], 'backquote'
177 $db = $GLOBALS['db'];
178 // Get the list and number of fields
179 // we do a try_query here, because we could be in the query window,
180 // trying to synchronize and the table has not yet been created
181 $fields_list = $GLOBALS['dbi']->getColumns(
182 $db, $GLOBALS['table'], null, true
185 $tmp_db_link = '<a href="' . $GLOBALS['cfg']['DefaultTabDatabase']
186 . PMA_URL_getCommon(array('db' => $db)) . '"';
188 . htmlspecialchars($db) . '</a>';
190 // $tmp_db_link = htmlspecialchars($db);
191 $legend = sprintf(__('Run SQL query/queries on database %s'), $tmp_db_link);
193 $query = PMA_Util
::expandUserString(
194 $GLOBALS['cfg']['DefaultQueryTable'], 'backquote'
198 $legend .= ': ' . PMA_Util
::showMySQLDocu('SELECT');
200 if (count($fields_list)) {
201 $sqlquerycontainer_id = 'sqlquerycontainer';
203 $sqlquerycontainer_id = 'sqlquerycontainerfull';
206 $html = '<a id="querybox"></a>'
207 . '<div id="queryboxcontainer">'
208 . '<fieldset id="queryboxf">';
209 $html .= '<legend>' . $legend . '</legend>';
210 $html .= '<div id="queryfieldscontainer">';
211 $html .= '<div id="' . $sqlquerycontainer_id . '">'
212 . '<textarea tabindex="100" name="sql_query" id="sqlquery"'
213 . ' cols="' . $GLOBALS['cfg']['TextareaCols'] . '"'
214 . ' rows="' . $height . '"'
215 . ' dir="' . $GLOBALS['text_dir'] . '"'
216 . $auto_sel . $locking . '>'
217 . htmlspecialchars($query)
219 // Add buttons to generate query easily for
220 // select all, single select, insert, update and delete
221 if (count($fields_list)) {
222 $html .= '<input type="button" value="SELECT *" id="selectall"'
223 . ' class="button sqlbutton" />';
224 $html .= '<input type="button" value="SELECT" id="select"'
225 . ' class="button sqlbutton" />';
226 $html .= '<input type="button" value="INSERT" id="insert"'
227 . ' class="button sqlbutton" />';
228 $html .= '<input type="button" value="UPDATE" id="update"'
229 . ' class="button sqlbutton" />';
230 $html .= '<input type="button" value="DELETE" id="delete"'
231 . ' class="button sqlbutton" />';
233 $html .= '<input type="button" value="' . __('Clear') . '" id="clear"'
234 . ' class="button sqlbutton" />';
235 $html .= '</div>' . "\n";
237 if (count($fields_list)) {
238 $html .= '<div id="tablefieldscontainer">'
239 . '<label>' . __('Columns') . '</label>'
240 . '<select id="tablefields" name="dummy" '
241 . 'size="' . ($GLOBALS['cfg']['TextareaRows'] - 2) . '" '
242 . 'multiple="multiple" ondblclick="insertValueQuery()">';
243 foreach ($fields_list as $field) {
244 $html .= '<option value="'
245 . PMA_Util
::backquote(htmlspecialchars($field['Field'])) . '"';
246 if (isset($field['Field'])
247 && /*overload*/mb_strlen($field['Field'])
248 && isset($field['Comment'])
250 $html .= ' title="' . htmlspecialchars($field['Comment']) . '"';
252 $html .= '>' . htmlspecialchars($field['Field']) . '</option>' . "\n";
255 . '<div id="tablefieldinsertbuttoncontainer">';
256 if (PMA_Util
::showIcons('ActionLinksMode')) {
257 $html .= '<input type="button" class="button" name="insert"'
258 . ' value="<<" onclick="insertValueQuery()"'
259 . ' title="' . __('Insert') . '" />';
261 $html .= '<input type="button" class="button" name="insert"'
262 . ' value="' . __('Insert') . '"'
263 . ' onclick="insertValueQuery()" />';
265 $html .= '</div>' . "\n"
269 $html .= '<div class="clearfloat"></div>' . "\n";
270 $html .= '</div>' . "\n";
272 $cfgBookmark = PMA_Bookmark_getParams();
274 $html .= '<div id="bookmarkoptions">';
275 $html .= '<div class="formelement">';
276 $html .= '<label for="bkm_label">'
277 . __('Bookmark this SQL query:') . '</label>';
278 $html .= '<input type="text" name="bkm_label" id="bkm_label"'
279 . ' tabindex="110" value="" />';
281 $html .= '<div class="formelement">';
282 $html .= '<input type="checkbox" name="bkm_all_users" tabindex="111"'
283 . ' id="id_bkm_all_users" value="true" />';
284 $html .= '<label for="id_bkm_all_users">'
285 . __('Let every user access this bookmark') . '</label>';
287 $html .= '<div class="formelement">';
288 $html .= '<input type="checkbox" name="bkm_replace" tabindex="112"'
289 . ' id="id_bkm_replace" value="true" />';
290 $html .= '<label for="id_bkm_replace">'
291 . __('Replace existing bookmark of same name') . '</label>';
296 $html .= '<div class="clearfloat"></div>' . "\n";
297 $html .= '</fieldset>' . "\n"
300 $html .= '<fieldset id="queryboxfooter" class="tblFooters">' . "\n";
301 $html .= '<div class="formelement">' . "\n";
303 $html .= '</div>' . "\n";
304 $html .= '<div class="formelement">' . "\n";
305 $html .= '<label for="id_sql_delimiter">[ ' . __('Delimiter')
307 $html .= '<input type="text" name="sql_delimiter" tabindex="131" size="3" '
308 . 'value="' . $delimiter . '" '
309 . 'id="id_sql_delimiter" /> ]';
311 $html .= '<input type="checkbox" name="show_query" value="1" '
312 . 'id="checkbox_show_query" tabindex="132" checked="checked" />'
313 . '<label for="checkbox_show_query">' . __('Show this query here again')
316 $html .= '<input type="checkbox" name="retain_query_box" value="1" '
317 . 'id="retain_query_box" tabindex="133" '
318 . ($GLOBALS['cfg']['RetainQueryBox'] === false
319 ?
'' : ' checked="checked"')
321 . '<label for="retain_query_box">' . __('Retain query box')
324 $html .= '<input type="checkbox" name="rollback_query" value="1" '
325 . 'id="rollback_query" tabindex="134" />'
326 . '<label for="rollback_query">' . __('Rollback when finished')
329 $html .= '</div>' . "\n";
330 $html .= '<input type="submit" id="button_submit_query" name="SQL"';
332 $html .= ' tabindex="200" value="' . __('Go') . '" />' . "\n";
333 $html .= '<div class="clearfloat"></div>' . "\n";
334 $html .= '</fieldset>' . "\n";
340 * return HTML for sql Query Form Bookmark
342 * @return string|null
344 * @usedby PMA_getHtmlForSqlQueryForm()
346 function PMA_getHtmlForSqlQueryFormBookmark()
348 $bookmark_list = PMA_Bookmark_getList($GLOBALS['db']);
349 if (! $bookmark_list ||
count($bookmark_list) < 1) {
353 $html = '<fieldset id="fieldsetBookmarkOptions">';
355 $html .= __('Bookmarked SQL query') . '</legend>' . "\n";
356 $html .= '<div class="formelement">';
357 $html .= '<select name="id_bookmark" id="id_bookmark">' . "\n";
358 $html .= '<option value=""> </option>' . "\n";
359 foreach ($bookmark_list as $key => $value) {
360 $html .= '<option value="' . htmlspecialchars($key) . '">'
361 . htmlspecialchars($value) . '</option>' . "\n";
363 // is required for correct display with styles/line height
364 $html .= '</select> ' . "\n";
365 $html .= '</div>' . "\n";
366 $html .= '<div class="formelement">' . "\n";
367 $html .= __('Variable');
368 $html .= PMA_Util
::showDocu('faq', 'faqbookmark');
369 $html .= '<input type="text" name="bookmark_variable" class="textfield"'
370 . ' size="10" />' . "\n";
371 $html .= '</div>' . "\n";
372 $html .= '<div class="formelement">' . "\n";
373 $html .= '<input type="radio" name="action_bookmark" value="0"'
374 . ' id="radio_bookmark_exe" checked="checked" />'
375 . '<label for="radio_bookmark_exe">' . __('Submit')
377 $html .= '<input type="radio" name="action_bookmark" value="1"'
378 . ' id="radio_bookmark_view" />'
379 . '<label for="radio_bookmark_view">' . __('View only')
381 $html .= '<input type="radio" name="action_bookmark" value="2"'
382 . ' id="radio_bookmark_del" />'
383 . '<label for="radio_bookmark_del">' . __('Delete')
385 $html .= '</div>' . "\n";
386 $html .= '<div class="clearfloat"></div>' . "\n";
387 $html .= '</fieldset>' . "\n";
389 $html .= '<fieldset id="fieldsetBookmarkOptionsFooter" class="tblFooters">';
390 $html .= '<input type="submit" name="SQL" id="button_submit_bookmark" value="'
392 $html .= '<div class="clearfloat"></div>' . "\n";
393 $html .= '</fieldset>' . "\n";
399 * return HTML for Sql Query Form Upload
403 * @usedby PMA_getHtmlForSqlQueryForm()
405 function PMA_getHtmlForSqlQueryFormUpload()
407 global $timeout_passed, $local_import_file;
411 // we allow only SQL here
412 $matcher = '@\.sql(\.(' . PMA_supportedDecompressions() . '))?$@';
414 if (!empty($GLOBALS['cfg']['UploadDir'])) {
415 $files = PMA_getFileSelectOptions(
416 PMA_Util
::userDir($GLOBALS['cfg']['UploadDir']), $matcher,
417 (isset($timeout_passed) && $timeout_passed && isset($local_import_file))
426 $html = '<fieldset id="">';
428 $html .= __('Browse your computer:') . '</legend>';
429 $html .= '<div class="formelement">';
430 $html .= '<input type="file" name="sql_file" class="textfield" /> ';
431 $html .= PMA_Util
::getFormattedMaximumUploadSize($GLOBALS['max_upload_size']);
432 // some browsers should respect this :)
433 $html .= PMA_Util
::generateHiddenMaxFileSize($GLOBALS['max_upload_size']) . "\n";
436 if ($files === false) {
437 $errors[] = PMA_Message
::error(
438 __('The directory you set for upload work cannot be reached.')
440 } elseif (!empty($files)) {
441 $html .= '<div class="formelement">';
442 $html .= '<strong>' . __('web server upload directory:') . '</strong>';
443 $html .= '<select size="1" name="sql_localfile">' . "\n";
444 $html .= '<option value="" selected="selected"></option>' . "\n";
446 $html .= '</select>' . "\n";
450 $html .= '<div class="clearfloat"></div>' . "\n";
451 $html .= '</fieldset>';
453 $html .= '<fieldset id="" class="tblFooters">';
454 $html .= __('Character set of the file:') . "\n";
455 $html .= PMA_generateCharsetDropdownBox(
456 PMA_CSDROPDOWN_CHARSET
,
457 'charset_of_file', null, 'utf8', false
459 $html .= '<input type="submit" name="SQL" value="' . __('Go')
461 $html .= '<div class="clearfloat"></div>' . "\n";
462 $html .= '</fieldset>';
464 foreach ($errors as $error) {
465 $html .= $error->getDisplay();