forked from phpmyadmin/phpmyadmin
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdb_operations.php
415 lines (372 loc) · 18.1 KB
/
db_operations.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
<?php
/* $Id$ */
// vim: expandtab sw=4 ts=4 sts=4:
require_once('./libraries/grab_globals.lib.php');
require_once('./libraries/common.lib.php');
require_once('./libraries/mysql_charsets.lib.php');
/**
* Rename database or Copy database
*/
if (isset($db) &&
((isset($db_rename) && $db_rename == 'true') ||
(isset($db_copy) && $db_copy == 'true'))) {
require_once('./libraries/tbl_move_copy.php');
if (isset($db_rename) && $db_rename == 'true') {
$move = TRUE;
} else {
$move = FALSE;
}
if (!isset($newname) || empty($newname)) {
$message = $strDatabaseEmpty;
} else {
if ($move ||
(isset($create_database_before_copying) && $create_database_before_copying)) {
$local_query = 'CREATE DATABASE ' . PMA_backquote($newname);
if (isset($db_collation)) {
$local_query .= ' DEFAULT' . PMA_generateCharsetQueryPart($db_collation);
}
$local_query .= ';';
$sql_query = $local_query;
PMA_DBI_query($local_query);
}
$tables_full = PMA_DBI_get_tables_full($db);
foreach ($tables_full as $table => $tmp) {
$back = $sql_query;
$sql_query = '';
// value of $what for this table only
$this_what = $what;
if (!isset($tables_full[$table]['Engine'])) {
$tables_full[$table]['Engine'] = $tables_full[$table]['Type'];
}
// do not copy the data from a Merge table
// note: on the calling FORM, 'data' means 'structure and data'
if ($tables_full[$table]['Engine'] == 'MRG_MyISAM') {
if ($this_what == 'data') {
$this_what = 'structure';
}
if ($this_what == 'dataonly') {
$this_what = 'nocopy';
}
}
if ($this_what != 'nocopy') {
PMA_table_move_copy($db, $table, $newname, $table, isset($this_what) ? $this_what : 'data', $move);
}
$sql_query = $back . $sql_query;
}
unset($table);
// Duplicate the bookmarks for this db (done once for each db)
if ($db != $newname) {
$get_fields = array('user','label','query');
$where_fields = array('dbase' => $db);
$new_fields = array('dbase' => $newname);
PMA_duplicate_table_info('bookmarkwork', 'bookmark', $get_fields, $where_fields, $new_fields);
}
if ($move) {
// cleanup pmadb stuff for this db
require_once('./libraries/relation_cleanup.lib.php');
PMA_relationsCleanupDatabase($db);
$local_query = 'DROP DATABASE ' . PMA_backquote($db) . ';';
$sql_query .= "\n" . $local_query;
PMA_DBI_query($local_query);
$message = sprintf($strRenameDatabaseOK, htmlspecialchars($db), htmlspecialchars($newname));
} else {
$message = sprintf($strCopyDatabaseOK, htmlspecialchars($db), htmlspecialchars($newname));
}
$reload = TRUE;
/* Change database to be used */
if ($move) {
$db = $newname;
} else {
$pma_uri_parts = parse_url($cfg['PmaAbsoluteUri']);
if (isset($switch_to_new) && $switch_to_new == 'true') {
setcookie('pma_switch_to_new', 'true', 0, $GLOBALS['cookie_path'], '' , $GLOBALS['is_https']);
$db = $newname;
} else {
setcookie('pma_switch_to_new', '', 0, $GLOBALS['cookie_path'], '' , $GLOBALS['is_https']);
}
}
}
}
/**
* Settings for relations stuff
*/
require_once('./libraries/relation.lib.php');
$cfgRelation = PMA_getRelationsParam();
/**
* Check if comments were updated
* (must be done before displaying the menu tabs)
*/
if ($cfgRelation['commwork'] && isset($db_comment) && $db_comment == 'true') {
PMA_SetComment($db, '', '(db_comment)', $comment);
}
/**
* Prepares the tables list if the user where not redirected to this script
* because there is no table in the database ($is_info is TRUE)
*/
if (empty($is_info)) {
require('./db_details_common.php');
$url_query .= '&goto=db_operations.php';
// Gets the database structure
$sub_part = '_structure';
require('./db_details_db_info.php');
echo "\n";
}
if (PMA_MYSQL_INT_VERSION >= 40101) {
$db_collation = PMA_getDbCollation($db);
}
if (PMA_MYSQL_INT_VERSION < 50002 || (PMA_MYSQL_INT_VERSION >= 50002 && $db != 'information_schema')) {
$is_information_schema = FALSE;
} else {
$is_information_schema = TRUE;
}
if (!$is_information_schema) {
require('./libraries/display_create_table.lib.php');
echo '<table border="0" cellpadding="2" cellspacing="0">';
if ($cfgRelation['commwork']) {
?>
<!-- Alter/Enter db-comment -->
<tr><td colspan="3"><img src="<?php echo $GLOBALS['pmaThemeImage'] . 'spacer.png'; ?>" width="1" height="1" border="0" alt="" /></td></tr>
<tr>
<td colspan="3" class="tblHeaders"><?php
if ($cfg['PropertiesIconic']) {
echo '<img src="' . $pmaThemeImage . 'b_comment.png" border="0" width="16" height="16" hspace="2" align="middle" />';
}
echo $strDBComment;
$comment = PMA_getComments($db);
?></td></tr>
<form method="post" action="db_operations.php">
<tr bgcolor="<?php echo $cfg['BgcolorOne']; ?>">
<td colspan="2" nowrap="nowrap">
<input type="hidden" name="db_comment" value="true" />
<?php echo PMA_generate_common_hidden_inputs($db); ?>
<input type="text" name="comment" class="textfield" size="30" value="<?php echo (isset($comment) && is_array($comment) ? htmlspecialchars(implode(' ', $comment)) : ''); ?>" /></td><td align="right">
<input type="submit" value="<?php echo $strGo; ?>" />
</td></tr>
</form>
<?php
}
?>
<!-- Rename database -->
<tr><td colspan="3"><img src="<?php echo $GLOBALS['pmaThemeImage'] . 'spacer.png'; ?>" width="1" height="1" border="0" alt="" /></td></tr>
<tr><td colspan="3" class="tblHeaders"><?php
if ($cfg['PropertiesIconic']) {
echo '<img src="' . $pmaThemeImage . 'b_edit.png" border="0" width="16" height="16" hspace="2" align="middle" />';
}
echo $strDBRename.': ';
?></td></tr>
<form method="post" action="db_operations.php"
onsubmit="return emptyFormElements(this, 'newname')">
<tr bgcolor="<?php echo $cfg['BgcolorOne']; ?>"><td colspan="2"><?php
echo '<input type="hidden" name="what" value="data" />';
echo '<input type="hidden" name="db_rename" value="true" />'
. PMA_generate_common_hidden_inputs($db);
?><input type="text" name="newname" size="30" class="textfield" value="" /></td>
<td align="right"><input type="submit" value="<?php echo $strGo; ?>" /></td>
</form></tr>
<!-- Copy database -->
<tr><td colspan="3"><img src="<?php echo $GLOBALS['pmaThemeImage'] . 'spacer.png'; ?>" width="1" height="1" border="0" alt="" /></td></tr>
<tr><td colspan="3" class="tblHeaders"><?php
if ($cfg['PropertiesIconic']) {
echo '<img src="' . $pmaThemeImage . 'b_edit.png" border="0" width="16" height="16" hspace="2" align="middle" />';
}
echo $strDBCopy.': ';
?></td></tr>
<form method="post" action="db_operations.php"
onsubmit="return emptyFormElements(this, 'newname')">
<tr bgcolor="<?php echo $cfg['BgcolorOne']; ?>"><td colspan="3">
<?php
if (isset($db_collation)) {
echo '<input type="hidden" name="db_collation" value="' . $db_collation .'" />' . "\n";
}
echo '<input type="hidden" name="db_copy" value="true" />' . "\n"
. PMA_generate_common_hidden_inputs($db);
?><input type="text" name="newname" size="30" class="textfield" value="" /></td>
</tr><tr>
<td nowrap="nowrap" bgcolor="<?php echo $cfg['BgcolorOne']; ?>" colspan="2">
<input type="radio" name="what" value="structure" id="radio_copy_structure" style="vertical-align: middle" /><label for="radio_copy_structure"><?php echo $strStrucOnly; ?></label> <br />
<input type="radio" name="what" value="data" id="radio_copy_data" checked="checked" style="vertical-align: middle" /><label for="radio_copy_data"><?php echo $strStrucData; ?></label> <br />
<input type="radio" name="what" value="dataonly" id="radio_copy_dataonly" style="vertical-align: middle" /><label for="radio_copy_dataonly"><?php echo $strDataOnly; ?></label> <br />
<input type="checkbox" name="create_database_before_copying" value="1" id="checkbox_create_database_before_copying" style="vertical-align: middle" checked="checked" /><label for="checkbox_create_database_before_copying"><?php echo $strCreateDatabaseBeforeCopying; ?></label><br />
<input type="checkbox" name="drop_if_exists" value="true" id="checkbox_drop" style="vertical-align: middle" /><label for="checkbox_drop"><?php echo $strStrucDrop; ?></label> <br />
<input type="checkbox" name="sql_auto_increment" value="1" id="checkbox_auto_increment" style="vertical-align: middle" /><label for="checkbox_auto_increment"><?php echo $strAddAutoIncrement; ?></label><br />
<input type="checkbox" name="constraints" value="1" id="checkbox_constraints" style="vertical-align: middle" /><label for="checkbox_constraints"><?php echo $strAddConstraints; ?></label><br />
<?php
if (isset($_COOKIE) && isset($_COOKIE['pma_switch_to_new']) && $_COOKIE['pma_switch_to_new'] == 'true') {
$pma_switch_to_new = 'true';
}
?>
<input type="checkbox" name="switch_to_new" value="true" id="checkbox_switch"<?php echo ((isset($pma_switch_to_new) && $pma_switch_to_new == 'true') ? ' checked="checked"' : ''); ?> style="vertical-align: middle" /><label for="checkbox_switch"><?php echo $strSwitchToDatabase; ?></label>
</td>
<td align="<?php echo $cell_align_right; ?>" valign="bottom" bgcolor="<?php echo $cfg['BgcolorOne']; ?>">
<input type="submit" name="submit_copy" value="<?php echo $strGo; ?>" />
</td>
</tr>
</form>
<?php
if (PMA_MYSQL_INT_VERSION >= 40101) {
// MySQL supports setting default charsets / collations for databases since
// version 4.1.1.
echo ' <!-- Change database charset -->' . "\n"
. ' <tr><td colspan="3"><img src="' . $GLOBALS['pmaThemeImage'] . 'spacer.png' . '" width="1" height="1" border="0" alt="" /></td></tr>' . "\n"
. ' <tr><td colspan="3" class="tblHeaders">';
if ($cfg['PropertiesIconic']) {
echo '<img src="' . $pmaThemeImage . 's_asci.png" border="0" width="16" height="16" hspace="2" align="middle" />';
}
echo ' <label for="select_db_collation">' . $strCollation . '</label>: ' . "\n"
. ' </td></tr>' . "\n"
. ' <form method="post" action="./db_operations.php">' . "\n"
. ' <tr bgcolor="' . $cfg['BgcolorOne'] . '"><td colspan="2" nowrap="nowrap">'
. PMA_generate_common_hidden_inputs($db, $table, 3)
. PMA_generateCharsetDropdownBox(PMA_CSDROPDOWN_COLLATION, 'db_collation', 'select_db_collation', $db_collation, FALSE, 3)
. ' </td><td align="right">'
. ' <input type="submit" name="submitcollation" value="' . $strGo . '" style="vertical-align: middle" />' . "\n"
. ' </td></tr>' . "\n"
. ' </form>' . "\n"
. ' ' . "\n\n";
}
if ($num_tables > 0
&& !$cfgRelation['allworks'] && $cfg['PmaNoRelation_DisableWarning'] == FALSE) {
echo '<tr><td colspan="3"><img src="' . $GLOBALS['pmaThemeImage'] . 'spacer.png' . '" width="1" height="1" border="0" alt="" /></td></tr>'
. '<tr><th colspan="3" class="tblHeadError"><div class="errorhead">' . $strError . '</div></th></tr>'
. '<tr><td colspan="3" class="tblError">'
. sprintf(wordwrap($strRelationNotWorking,65,'<br />'), '<a href="' . $cfg['PmaAbsoluteUri'] . 'chk_rel.php?' . $url_query . '">', '</a>')
. '</td></tr>';
} // end if
?>
</table>
<?php
} // end if (!$is_information_schema)
// not sure about leaving the PDF dialog for information_schema
?>
<form method="post" action="pdf_schema.php">
<?php
if ($num_tables > 0) {
$takeaway = $url_query . '&table=' . urlencode($table);
}
if (($cfgRelation['pdfwork'] && $num_tables > 0) ||
($num_tables > 0
&& $cfgRelation['relwork'] && $cfgRelation['commwork']
&& isset($cfg['docSQLDir']) && !empty($cfg['docSQLDir'])
)) { ?>
<hr /><table border="0" cellpadding="2" cellspacing="0">
<?php
}
if ($cfgRelation['pdfwork'] && $num_tables > 0) { ?>
<!-- Work on PDF Pages -->
<tr>
<td colspan="3" class="tblHeaders">
<?php
if ($cfg['PropertiesIconic']) {
echo '<img src="' . $pmaThemeImage . 'b_pdfdoc.png" border="0" width="16" height="16" hspace="2" align="middle" />';
} ?>PDF</td>
</tr>
<tr bgcolor="<?php echo $cfg['BgcolorOne']; ?>">
<td colspan="3">
<?php
echo '<a href="pdf_pages.php?' . $takeaway . '">';
if ($cfg['PropertiesIconic']) {
echo '<img src="' . $pmaThemeImage . 'b_edit.png" border="0" width="16" height="16" hspace="2" align="middle" />';
}
echo ''. $strEditPDFPages . '</a>';
?>
</td>
</tr>
<!-- PDF schema -->
<?php
// We only show this if we find something in the new pdf_pages table
$test_query = 'SELECT * FROM ' . PMA_backquote($cfgRelation['pdf_pages'])
. ' WHERE db_name = \'' . PMA_sqlAddslashes($db) . '\'';
$test_rs = PMA_query_as_cu($test_query, NULL, PMA_DBI_QUERY_STORE);
if ($test_rs && PMA_DBI_num_rows($test_rs) > 0) { ?>
<tr bgcolor="<?php echo $cfg['BgcolorTwo']; ?>">
<td colspan="3">
<?php
echo PMA_generate_common_hidden_inputs($db);
if ($cfg['PropertiesIconic']) {
echo '<img src="' . $pmaThemeImage . 'b_view.png" border="0" width="16" height="16" hspace="2" align="middle" />';
}
echo $strDisplayPDF; ?>:
</td>
</tr>
<tr bgcolor="<?php echo $cfg['BgcolorTwo']; ?>">
<td width="20"> </td>
<td colspan="2">
<label for="pdf_page_number_opt"><?php echo $strPageNumber; ?></label>
<select name="pdf_page_number" id="pdf_page_number_opt">
<?php
while ($pages = @PMA_DBI_fetch_assoc($test_rs)) {
echo ' <option value="' . $pages['page_nr'] . '">' . $pages['page_nr'] . ': ' . $pages['page_descr'] . '</option>' . "\n";
} // end while
PMA_DBI_free_result($test_rs);
unset($test_rs);
?>
</select><br />
<input type="checkbox" name="show_grid" id="show_grid_opt" /><label for="show_grid_opt"><?php echo $strShowGrid; ?></label><br />
<input type="checkbox" name="show_color" id="show_color_opt" checked="checked" /><label for="show_color_opt"><?php echo $strShowColor; ?></label><br />
<input type="checkbox" name="show_table_dimension" id="show_table_dim_opt" /><label for="show_table_dim_opt"><?php echo $strShowTableDimension; ?></label><br />
<input type="checkbox" name="all_tab_same_wide" id="all_tab_same_wide" /><label for="all_tab_same_wide"><?php echo $strAllTableSameWidth; ?></label><br />
<input type="checkbox" name="with_doc" id="with_doc" checked="checked" /><label for="with_doc"><?php echo $strDataDict; ?></label><br />
<label for="orientation_opt"><?php echo $strShowDatadictAs; ?></label>
<select name="orientation" id="orientation_opt">
<option value="L"><?php echo $strLandscape;?></option>
<option value="P"><?php echo $strPortrait;?></option>
</select><br />
<label for="paper_opt"><?php echo $strPaperSize; ?></label>
<select name="paper" id="paper_opt">
<?php
foreach ($cfg['PDFPageSizes'] AS $key => $val) {
echo '<option value="' . $val . '"';
if ($val == $cfg['PDFDefaultPageSize']) {
echo ' selected="selected"';
}
echo ' >' . $val . '</option>' . "\n";
}
?>
</select>
</td>
</tr>
<tr bgcolor="<?php echo $cfg['BgcolorTwo']; ?>">
<td width="20"> </td>
<td colspan="3" align="right"> <input type="submit" value="<?php echo $strGo; ?>" /></td>
</tr>
<tr>
<td colspan="3"><img src="<?php echo $GLOBALS['pmaThemeImage'] . 'spacer.png'; ?>" width="1" height="1" border="0" alt="" /></td>
</tr>
<?php
} // end if
} // end if
if ($num_tables > 0
&& $cfgRelation['relwork'] && $cfgRelation['commwork']
&& isset($cfg['docSQLDir']) && !empty($cfg['docSQLDir'])
) {
?>
<!-- import docSQL files -->
<tr bgcolor="<?php echo $cfg['BgcolorOne']; ?>">
<td colspan="3">
<?php
echo '<a href="db_details_importdocsql.php?' . $takeaway . '">';
if ($cfg['PropertiesIconic']) {
echo '<img src="' . $pmaThemeImage . 'b_docsql.png" border="0" width="16" height="16" hspace="2" align="middle" />';
}
echo $strImportDocSQL . '</a>';
?>
</td>
</tr>
<?php
}
echo "\n";
if (($cfgRelation['pdfwork'] && $num_tables > 0) ||
($num_tables > 0
&& $cfgRelation['relwork'] && $cfgRelation['commwork']
&& isset($cfg['docSQLDir']) && !empty($cfg['docSQLDir'])
)) { ?>
</table>
</form>
<?php
}
/**
* Displays the footer
*/
echo "\n";
require_once('./footer.inc.php');
?>