54
55
* @param boolean|string $query query to display in the textarea
55
56
* or true to display last executed
56
57
* @param boolean|string $display_tab sql|files|history|full|FALSE
57
* what part to display
58
* what part to display
58
59
* false if not inside querywindow
60
function PMA_sqlQueryForm( $query = true, $display_tab = false ) {
61
function PMA_sqlQueryForm($query = true, $display_tab = false)
61
63
// check tab to display if inside querywindow
62
if ( ! $display_tab ) {
63
65
$display_tab = 'full';
64
66
$is_querywindow = false;
66
68
$is_querywindow = true;
70
if ( true === $query ) {
71
$query = empty( $GLOBALS['sql_query'] ) ? '' : $GLOBALS['sql_query'];
72
if (true === $query) {
73
$query = empty($GLOBALS['sql_query']) ? '' : $GLOBALS['sql_query'];
74
76
// set enctype to multipart for file uploads
75
if ( $GLOBALS['is_upload'] ) {
77
if ($GLOBALS['is_upload']) {
76
78
$enctype = ' enctype="multipart/form-data"';
83
if ( empty( $GLOBALS['db'] ) ) {
85
if (! isset($GLOBALS['db']) || ! strlen($GLOBALS['db'])) {
84
86
// prepare for server related
85
$goto = empty( $GLOBALS['goto'] ) ?
87
$goto = empty($GLOBALS['goto']) ?
86
88
'server_sql.php' : $GLOBALS['goto'];
88
elseif ( empty( $GLOBALS['table'] ) ) {
89
} elseif (! isset($GLOBALS['table']) || ! strlen($GLOBALS['table'])) {
89
90
// prepare for db related
90
91
$db = $GLOBALS['db'];
91
$goto = empty( $GLOBALS['goto'] ) ?
92
$goto = empty($GLOBALS['goto']) ?
92
93
'db_details.php' : $GLOBALS['goto'];
94
95
$table = $GLOBALS['table'];
95
96
$db = $GLOBALS['db'];
96
$goto = empty( $GLOBALS['goto'] ) ?
97
$goto = empty($GLOBALS['goto']) ?
97
98
'tbl_properties.php' : $GLOBALS['goto'];
102
if ( $is_querywindow ) {
103
if ($is_querywindow) {
104
<form method="post" id="sqlqueryform"
105
target="phpmain<?php echo md5( $GLOBALS['cfg']['PmaAbsoluteUri'] ); ?>"
105
<form method="post" id="sqlqueryform" target="frame_content"
106
106
action="import.php"<?php echo $enctype; ?> name="sqlform"
107
onsubmit="this.target=window.opener.frames[1].name;
107
onsubmit="var save_name = window.opener.parent.frames[1].name;
108
window.opener.parent.frames[1].name = save_name + '<?php echo time(); ?>';
109
this.target = window.opener.parent.frames[1].name;
108
110
return checkSqlQuery( this );" >
111
113
echo '<form method="post" action="import.php" ' . $enctype . ' id="sqlqueryform"'
112
114
.' onsubmit="return checkSqlQuery(this)" name="sqlform">' . "\n";
115
if ( $is_querywindow ) {
117
if ($is_querywindow) {
116
118
echo '<input type="hidden" name="focus_querywindow" value="true" />'
118
if ( $display_tab != 'sql' && $display_tab != 'full' ) {
120
if ($display_tab != 'sql' && $display_tab != 'full') {
119
121
echo '<input type="hidden" name="sql_query" value="" />' . "\n";
120
122
echo '<input type="hidden" name="show_query" value="1" />' . "\n";
123
125
echo '<input type="hidden" name="is_js_confirmed" value="0" />' . "\n"
124
.PMA_generate_common_hidden_inputs( $db, $table ) . "\n"
126
.PMA_generate_common_hidden_inputs($db, $table) . "\n"
125
127
.'<input type="hidden" name="pos" value="0" />' . "\n"
126
.'<input type="hidden" name="goto" value="'
127
.htmlspecialchars( $goto ) . '" />' . "\n"
128
.'<input type="hidden" name="zero_rows" value="'
129
. htmlspecialchars( $GLOBALS['strSuccess'] ) . '" />' . "\n"
130
.'<input type="hidden" name="prev_sql_query" value="'
131
. htmlspecialchars( $query ) . '" />' . "\n";
128
.'<input type="hidden" name="goto" value="'
129
.htmlspecialchars($goto) . '" />' . "\n"
130
.'<input type="hidden" name="zero_rows" value="'
131
. htmlspecialchars($GLOBALS['strSuccess']) . '" />' . "\n"
132
.'<input type="hidden" name="prev_sql_query" value="'
133
. htmlspecialchars($query) . '" />' . "\n";
133
135
// display querybox
134
if ( $display_tab === 'full' || $display_tab === 'sql' ) {
135
PMA_sqlQueryFormInsert( $query, $is_querywindow );
136
if ($display_tab === 'full' || $display_tab === 'sql') {
137
PMA_sqlQueryFormInsert($query, $is_querywindow);
138
140
// display uploads
139
if ( $display_tab === 'files' && $GLOBALS['is_upload'] ) {
141
if ($display_tab === 'files' && $GLOBALS['is_upload']) {
140
142
PMA_sqlQueryFormUpload();
143
145
// Bookmark Support
144
if ( $display_tab === 'full' || $display_tab === 'history' ) {
145
if ( ! empty( $GLOBALS['cfg']['Bookmark'] )
146
if ($display_tab === 'full' || $display_tab === 'history') {
147
if (! empty( $GLOBALS['cfg']['Bookmark'])
146
148
&& $GLOBALS['cfg']['Bookmark']['db']
147
&& $GLOBALS['cfg']['Bookmark']['table'] ) {
149
&& $GLOBALS['cfg']['Bookmark']['table']) {
148
150
PMA_sqlQueryFormBookmark();
152
154
// Encoding setting form appended by Y.Kawada
153
if ( function_exists('PMA_set_enc_form') ) {
155
if (function_exists('PMA_set_enc_form')) {
154
156
echo PMA_set_enc_form(' ');
157
159
echo '</form>' . "\n";
161
163
* prints querybox fieldset
163
* @usedby PMA_sqlQueryForm()
165
* @usedby PMA_sqlQueryForm()
164
166
* @uses $GLOBALS['text_dir']
165
167
* @uses $GLOBALS['cfg']['TextareaAutoSelect']
166
168
* @uses $GLOBALS['cfg']['TextareaCols']
176
178
* @param string $query query to display in the textarea
177
179
* @param boolean $is_querywindow if inside querywindow or not
179
function PMA_sqlQueryFormInsert( $query = '', $is_querywindow = false ) {
181
function PMA_sqlQueryFormInsert($query = '', $is_querywindow = false)
181
184
// enable auto select text in textarea
182
if ( $GLOBALS['cfg']['TextareaAutoSelect'] ) {
185
if ($GLOBALS['cfg']['TextareaAutoSelect']) {
183
186
$auto_sel = ' onfocus="selectContent( this, sql_box_locked, true )"';
188
191
// enable locking if inside query window
189
if ( $is_querywindow ) {
192
if ($is_querywindow) {
190
193
$locking = ' onkeypress="document.sqlform.elements[\'LockFromUpdate\'].'
191
194
.'checked = true;"';
198
201
$fields_list = array();
199
if ( empty( $GLOBALS['db'] ) ) {
202
if (! isset($GLOBALS['db']) || ! strlen($GLOBALS['db'])) {
200
203
// prepare for server related
201
$legend = sprintf( $GLOBALS['strRunSQLQueryOnServer'],
204
$legend = sprintf($GLOBALS['strRunSQLQueryOnServer'],
202
205
htmlspecialchars(
203
$GLOBALS['cfg']['Servers'][$GLOBALS['server']]['host'] ) );
205
elseif ( empty( $GLOBALS['table'] ) ) {
206
$GLOBALS['cfg']['Servers'][$GLOBALS['server']]['host']));
207
} elseif (! isset($GLOBALS['table']) || ! strlen($GLOBALS['table'])) {
206
208
// prepare for db related
207
209
$db = $GLOBALS['db'];
208
210
// if you want navigation:
209
$strDBLink = '<a href="' . $GLOBALS['cfg']['DefaultTabDatabase']
210
. '?' . PMA_generate_common_url( $db ) . '"';
211
if ( $is_querywindow ) {
211
$strDBLink = '<a href="' . $GLOBALS['cfg']['DefaultTabDatabase']
212
. '?' . PMA_generate_common_url($db) . '"';
213
if ($is_querywindow) {
212
214
$strDBLink .= ' target="_self"'
213
215
. ' onclick="this.target=window.opener.frames[1].name"';
215
217
$strDBLink .= '>'
216
. htmlspecialchars( $db ) . '</a>';
218
. htmlspecialchars($db) . '</a>';
218
// $strDBLink = htmlspecialchars( $db );
219
$legend = sprintf( $GLOBALS['strRunSQLQuery'], $strDBLink );
220
if ( empty( $query ) ) {
221
$query = str_replace( '%d',
222
PMA_backquote( $db ), $GLOBALS['cfg']['DefaultQueryDatabase'] );
220
// $strDBLink = htmlspecialchars($db);
221
$legend = sprintf($GLOBALS['strRunSQLQuery'], $strDBLink);
223
$query = str_replace('%d',
224
PMA_backquote($db), $GLOBALS['cfg']['DefaultQueryDatabase']);
225
227
$table = $GLOBALS['table'];
227
229
// Get the list and number of fields
228
230
// we do a try_query here, because we could be in the query window,
229
231
// trying to synchonize and the table has not yet been created
230
$fields_list = PMA_DBI_fetch_result(
231
'SHOW FULL COLUMNS FROM ' . PMA_backquote( $db )
232
. '.' . PMA_backquote( $GLOBALS['table'] ));
234
$strDBLink = '<a href="' . $GLOBALS['cfg']['DefaultTabDatabase']
235
. '?' . PMA_generate_common_url( $db ) . '"';
236
if ( $is_querywindow ) {
232
$fields_list = PMA_DBI_fetch_result(
233
'SHOW FULL COLUMNS FROM ' . PMA_backquote($db)
234
. '.' . PMA_backquote($GLOBALS['table']));
236
$strDBLink = '<a href="' . $GLOBALS['cfg']['DefaultTabDatabase']
237
. '?' . PMA_generate_common_url($db) . '"';
238
if ($is_querywindow) {
237
239
$strDBLink .= ' target="_self"'
238
240
. ' onclick="this.target=window.opener.frames[1].name"';
240
242
$strDBLink .= '>'
241
. htmlspecialchars( $db ) . '</a>';
243
. htmlspecialchars($db) . '</a>';
243
// $strDBLink = htmlspecialchars( $db );
244
$legend = sprintf( $GLOBALS['strRunSQLQuery'], $strDBLink );
245
if ( empty( $query ) && count( $fields_list ) ) {
245
// $strDBLink = htmlspecialchars($db);
246
$legend = sprintf($GLOBALS['strRunSQLQuery'], $strDBLink);
247
if (empty($query) && count($fields_list)) {
246
248
$field_names = array();
247
foreach ( $fields_list as $field ) {
249
foreach ($fields_list as $field) {
248
250
$field_names[] = PMA_backquote($field['Field']);
251
str_replace( '%d', PMA_backquote( $db ),
252
str_replace( '%t', PMA_backquote( $table ),
254
implode( ', ', $field_names ),
255
$GLOBALS['cfg']['DefaultQueryTable'] ) ) );
253
str_replace('%d', PMA_backquote($db),
254
str_replace('%t', PMA_backquote($table),
256
implode(', ', $field_names ),
257
$GLOBALS['cfg']['DefaultQueryTable'])));
256
258
unset($field_names);
259
$legend .= ': ' . PMA_showMySQLDocu( 'SQL-Syntax', 'SELECT' );
261
$legend .= ': ' . PMA_showMySQLDocu('SQL-Syntax', 'SELECT');
261
if ( count( $fields_list ) ) {
263
if (count($fields_list)) {
262
264
$sqlquerycontainer_id = 'sqlquerycontainer';
264
266
$sqlquerycontainer_id = 'sqlquerycontainerfull';
267
269
echo '<a name="querybox"></a>' . "\n"
268
270
.'<div id="queryboxcontainer">' . "\n"
269
271
.'<fieldset id="querybox">' . "\n";
271
273
echo '<div id="queryfieldscontainer">' . "\n";
272
274
echo '<div id="' . $sqlquerycontainer_id . '">' . "\n"
273
275
.'<textarea name="sql_query" id="sqlquery"'
274
.' cols="' . $GLOBALS['cfg']['TextareaCols'] . '"'
275
.' rows="' . $GLOBALS['cfg']['TextareaRows'] . '"'
276
.' dir="' . $GLOBALS['text_dir'] . '"'
277
.$auto_sel . $locking . '>' . $query . '</textarea>' . "\n";
276
.' cols="' . $GLOBALS['cfg']['TextareaCols'] . '"'
277
.' rows="' . $GLOBALS['cfg']['TextareaRows'] . '"'
278
.' dir="' . $GLOBALS['text_dir'] . '"'
279
.$auto_sel . $locking . '>' . htmlspecialchars($query) . '</textarea>' . "\n";
278
280
echo '</div>' . "\n";
280
if ( count( $fields_list ) ) {
282
if (count($fields_list)) {
281
283
echo '<div id="tablefieldscontainer">' . "\n"
282
284
.'<label>' . $GLOBALS['strFields'] . '</label>' . "\n"
283
285
.'<select id="tablefields" name="dummy" '
284
286
.'size="' . ($GLOBALS['cfg']['TextareaRows'] - 2) . '" '
285
287
.'multiple="multiple" ondblclick="insertValueQuery()">' . "\n";
286
foreach ( $fields_list as $field ) {
287
echo '<option value="'
288
.PMA_backquote( htmlspecialchars( $field['Field'] ) ) . '"';
289
if ( ! empty( $field['Field'] ) && isset($field['Comment']) ) {
290
echo ' title="' . htmlspecialchars( $field['Comment'] ) . '"';
288
foreach ($fields_list as $field) {
289
echo '<option value="'
290
.PMA_backquote(htmlspecialchars($field['Field'])) . '"';
291
if (isset($field['Field']) && strlen($field['Field']) && isset($field['Comment'])) {
292
echo ' title="' . htmlspecialchars($field['Comment']) . '"';
292
294
echo '>' . htmlspecialchars( $field['Field'] ) . '</option>' . "\n";
383
385
* @uses htmlspecialchars()
385
function PMA_sqlQueryFormBookmark() {
387
function PMA_sqlQueryFormBookmark()
386
389
$bookmark_list = PMA_listBookmarks(isset($GLOBALS['db']) ? $GLOBALS['db'] : '', $GLOBALS['cfg']['Bookmark'] );
387
if ( ! $bookmark_list || count( $bookmark_list ) < 1 ) {
390
if (! $bookmark_list || count($bookmark_list) < 1) {
391
394
echo '<fieldset id="bookmarkoptions">';
393
396
echo $GLOBALS['strBookmarkQuery'] . '</legend>' . "\n";
394
397
echo '<div class="formelement">';
395
398
echo '<select name="id_bookmark">' . "\n";
396
399
echo '<option value=""></option>' . "\n";
397
foreach ( $bookmark_list as $key => $value ) {
398
echo '<option value="' . htmlspecialchars( $key ) . '">'
399
.htmlspecialchars( $value ) . '</option>' . "\n";
400
foreach ($bookmark_list as $key => $value) {
401
echo '<option value="' . htmlspecialchars($key) . '">'
402
.htmlspecialchars($value) . '</option>' . "\n";
401
404
// is required for correct display with styles/line height
402
405
echo '</select> ' . "\n";
403
406
echo '</div>' . "\n";
404
407
echo '<div class="formelement">' . "\n";
405
408
echo $GLOBALS['strVar'];
406
if ( $GLOBALS['cfg']['ReplaceHelpImg'] ) {
409
if ($GLOBALS['cfg']['ReplaceHelpImg']) {
407
410
echo ' <a href="./Documentation.html#faqbookmark"'
408
411
.' target="documentation">'
409
412
.'<img class="icon" src="' . $GLOBALS['pmaThemeImage'] . 'b_help.png"'
514
517
&& $GLOBALS['allow_recoding'] ) {
515
518
echo $GLOBALS['strCharsetOfFile'] . "\n"
516
519
. '<select name="charset_of_file" size="1">' . "\n";
517
foreach( $GLOBALS['cfg']['AvailableCharsets'] as $temp_charset ) {
520
foreach ($GLOBALS['cfg']['AvailableCharsets'] as $temp_charset) {
518
521
echo '<option value="' . $temp_charset . '"';
519
if ( $temp_charset == $GLOBALS['charset'] ) {
522
if ($temp_charset == $GLOBALS['charset']) {
520
523
echo ' selected="selected"';
522
525
echo '>' . $temp_charset . '</option>' . "\n";
524
527
echo '</select>' . "\n";
525
} elseif ( PMA_MYSQL_INT_VERSION >= 40100 ) {
528
} elseif (PMA_MYSQL_INT_VERSION >= 40100) {
526
529
echo $GLOBALS['strCharsetOfFile'] . "\n";
527
echo PMA_generateCharsetDropdownBox( PMA_CSDROPDOWN_CHARSET,
528
'charset_of_file', NULL, 'utf8', FALSE );
530
echo PMA_generateCharsetDropdownBox(PMA_CSDROPDOWN_CHARSET,
531
'charset_of_file', null, 'utf8', FALSE);
529
532
} // end if (recoding)
530
533
echo '<input type="submit" name="SQL" value="' . $GLOBALS['strGo']
532
535
echo '<div class="clearfloat"></div>' . "\n";
533
536
echo '</fieldset>';
535
foreach( $errors as $error => $message ) {
538
foreach ( $errors as $error => $message ) {
536
539
echo '<div>' . $error . '</div>';
537
540
echo '<div>' . $message . '</div>';