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 $html .= '<div id="querymessage"></div>';
220 // Add buttons to generate query easily for
221 // select all, single select, insert, update and delete
222 if (count($fields_list)) {
223 $html .= '<input type="button" value="SELECT *" id="selectall"'
224 . ' class="button sqlbutton" />';
225 $html .= '<input type="button" value="SELECT" id="select"'
226 . ' class="button sqlbutton" />';
227 $html .= '<input type="button" value="INSERT" id="insert"'
228 . ' class="button sqlbutton" />';
229 $html .= '<input type="button" value="UPDATE" id="update"'
230 . ' class="button sqlbutton" />';
231 $html .= '<input type="button" value="DELETE" id="delete"'
232 . ' class="button sqlbutton" />';
234 $html .= '<input type="button" value="' . __('Clear') . '" id="clear"'
235 . ' class="button sqlbutton" />';
236 if ($GLOBALS['cfg']['CodemirrorEnable']) {
237 $html .= '<input type="button" value="' . __('Format') . '" id="format"'
238 . ' class="button sqlbutton" />';
240 $html .= '<input type="button" value="' . __('Get auto-saved query') . '" id="saved"'
241 . ' class="button sqlbutton" />';
242 $html .= '</div>' . "\n";
244 if (count($fields_list)) {
245 $html .= '<div id="tablefieldscontainer">'
246 . '<label>' . __('Columns') . '</label>'
247 . '<select id="tablefields" name="dummy" '
248 . 'size="' . ($GLOBALS['cfg']['TextareaRows'] - 2) . '" '
249 . 'multiple="multiple" ondblclick="insertValueQuery()">';
250 foreach ($fields_list as $field) {
251 $html .= '<option value="'
252 . PMA_Util
::backquote(htmlspecialchars($field['Field'])) . '"';
253 if (isset($field['Field'])
254 && /*overload*/mb_strlen($field['Field'])
255 && isset($field['Comment'])
257 $html .= ' title="' . htmlspecialchars($field['Comment']) . '"';
259 $html .= '>' . htmlspecialchars($field['Field']) . '</option>' . "\n";
262 . '<div id="tablefieldinsertbuttoncontainer">';
263 if (PMA_Util
::showIcons('ActionLinksMode')) {
264 $html .= '<input type="button" class="button" name="insert"'
265 . ' value="<<" onclick="insertValueQuery()"'
266 . ' title="' . __('Insert') . '" />';
268 $html .= '<input type="button" class="button" name="insert"'
269 . ' value="' . __('Insert') . '"'
270 . ' onclick="insertValueQuery()" />';
272 $html .= '</div>' . "\n"
276 $html .= '<div class="clearfloat"></div>' . "\n";
277 $html .= '</div>' . "\n";
279 $cfgBookmark = PMA_Bookmark_getParams();
281 $html .= '<div id="bookmarkoptions">';
282 $html .= '<div class="formelement">';
283 $html .= '<label for="bkm_label">'
284 . __('Bookmark this SQL query:') . '</label>';
285 $html .= '<input type="text" name="bkm_label" id="bkm_label"'
286 . ' tabindex="110" value="" />';
288 $html .= '<div class="formelement">';
289 $html .= '<input type="checkbox" name="bkm_all_users" tabindex="111"'
290 . ' id="id_bkm_all_users" value="true" />';
291 $html .= '<label for="id_bkm_all_users">'
292 . __('Let every user access this bookmark') . '</label>';
294 $html .= '<div class="formelement">';
295 $html .= '<input type="checkbox" name="bkm_replace" tabindex="112"'
296 . ' id="id_bkm_replace" value="true" />';
297 $html .= '<label for="id_bkm_replace">'
298 . __('Replace existing bookmark of same name') . '</label>';
303 $html .= '<div class="clearfloat"></div>' . "\n";
304 $html .= '</fieldset>' . "\n"
307 $html .= '<fieldset id="queryboxfooter" class="tblFooters">' . "\n";
308 $html .= '<div class="formelement">' . "\n";
310 $html .= '</div>' . "\n";
311 $html .= '<div class="formelement">' . "\n";
312 $html .= '<label for="id_sql_delimiter">[ ' . __('Delimiter')
314 $html .= '<input type="text" name="sql_delimiter" tabindex="131" size="3" '
315 . 'value="' . $delimiter . '" '
316 . 'id="id_sql_delimiter" /> ]';
318 $html .= '<input type="checkbox" name="show_query" value="1" '
319 . 'id="checkbox_show_query" tabindex="132" checked="checked" />'
320 . '<label for="checkbox_show_query">' . __('Show this query here again')
323 $html .= '<input type="checkbox" name="retain_query_box" value="1" '
324 . 'id="retain_query_box" tabindex="133" '
325 . ($GLOBALS['cfg']['RetainQueryBox'] === false
326 ?
'' : ' checked="checked"')
328 . '<label for="retain_query_box">' . __('Retain query box')
331 $html .= '<input type="checkbox" name="rollback_query" value="1" '
332 . 'id="rollback_query" tabindex="134" />'
333 . '<label for="rollback_query">' . __('Rollback when finished')
336 $html .= '</div>' . "\n";
337 $html .= '<input type="submit" id="button_submit_query" name="SQL"';
339 $html .= ' tabindex="200" value="' . __('Go') . '" />' . "\n";
340 $html .= '<div class="clearfloat"></div>' . "\n";
341 $html .= '</fieldset>' . "\n";
347 * return HTML for sql Query Form Bookmark
349 * @return string|null
351 * @usedby PMA_getHtmlForSqlQueryForm()
353 function PMA_getHtmlForSqlQueryFormBookmark()
355 $bookmark_list = PMA_Bookmark_getList($GLOBALS['db']);
356 if (! $bookmark_list ||
count($bookmark_list) < 1) {
360 $html = '<fieldset id="fieldsetBookmarkOptions">';
362 $html .= __('Bookmarked SQL query') . '</legend>' . "\n";
363 $html .= '<div class="formelement">';
364 $html .= '<select name="id_bookmark" id="id_bookmark">' . "\n";
365 $html .= '<option value=""> </option>' . "\n";
366 foreach ($bookmark_list as $key => $value) {
367 $html .= '<option value="' . htmlspecialchars($key) . '">'
368 . htmlspecialchars($value) . '</option>' . "\n";
370 // is required for correct display with styles/line height
371 $html .= '</select> ' . "\n";
372 $html .= '</div>' . "\n";
373 $html .= '<div class="formelement">' . "\n";
374 $html .= __('Variable');
375 $html .= PMA_Util
::showDocu('faq', 'faqbookmark');
376 $html .= '<input type="text" name="bookmark_variable" class="textfield"'
377 . ' size="10" />' . "\n";
378 $html .= '</div>' . "\n";
379 $html .= '<div class="formelement">' . "\n";
380 $html .= '<input type="radio" name="action_bookmark" value="0"'
381 . ' id="radio_bookmark_exe" checked="checked" />'
382 . '<label for="radio_bookmark_exe">' . __('Submit')
384 $html .= '<input type="radio" name="action_bookmark" value="1"'
385 . ' id="radio_bookmark_view" />'
386 . '<label for="radio_bookmark_view">' . __('View only')
388 $html .= '<input type="radio" name="action_bookmark" value="2"'
389 . ' id="radio_bookmark_del" />'
390 . '<label for="radio_bookmark_del">' . __('Delete')
392 $html .= '</div>' . "\n";
393 $html .= '<div class="clearfloat"></div>' . "\n";
394 $html .= '</fieldset>' . "\n";
396 $html .= '<fieldset id="fieldsetBookmarkOptionsFooter" class="tblFooters">';
397 $html .= '<input type="submit" name="SQL" id="button_submit_bookmark" value="'
399 $html .= '<div class="clearfloat"></div>' . "\n";
400 $html .= '</fieldset>' . "\n";
406 * return HTML for Sql Query Form Upload
410 * @usedby PMA_getHtmlForSqlQueryForm()
412 function PMA_getHtmlForSqlQueryFormUpload()
414 global $timeout_passed, $local_import_file;
418 // we allow only SQL here
419 $matcher = '@\.sql(\.(' . PMA_supportedDecompressions() . '))?$@';
421 if (!empty($GLOBALS['cfg']['UploadDir'])) {
422 $files = PMA_getFileSelectOptions(
423 PMA_Util
::userDir($GLOBALS['cfg']['UploadDir']), $matcher,
424 (isset($timeout_passed) && $timeout_passed && isset($local_import_file))
433 $html = '<fieldset id="">';
435 $html .= __('Browse your computer:') . '</legend>';
436 $html .= '<div class="formelement">';
437 $html .= '<input type="file" name="sql_file" class="textfield" /> ';
438 $html .= PMA_Util
::getFormattedMaximumUploadSize($GLOBALS['max_upload_size']);
439 // some browsers should respect this :)
440 $html .= PMA_Util
::generateHiddenMaxFileSize($GLOBALS['max_upload_size']) . "\n";
443 if ($files === false) {
444 $errors[] = PMA_Message
::error(
445 __('The directory you set for upload work cannot be reached.')
447 } elseif (!empty($files)) {
448 $html .= '<div class="formelement">';
449 $html .= '<strong>' . __('web server upload directory:') . '</strong>';
450 $html .= '<select size="1" name="sql_localfile">' . "\n";
451 $html .= '<option value="" selected="selected"></option>' . "\n";
453 $html .= '</select>' . "\n";
457 $html .= '<div class="clearfloat"></div>' . "\n";
458 $html .= '</fieldset>';
460 $html .= '<fieldset id="" class="tblFooters">';
461 $html .= __('Character set of the file:') . "\n";
462 $html .= PMA_generateCharsetDropdownBox(
463 PMA_CSDROPDOWN_CHARSET
,
464 'charset_of_file', null, 'utf8', false
466 $html .= '<input type="submit" name="SQL" value="' . __('Go')
468 $html .= '<div class="clearfloat"></div>' . "\n";
469 $html .= '</fieldset>';
471 foreach ($errors as $error) {
472 $html .= $error->getDisplay();