3 // vim: expandtab sw=4 ts=4 sts=4:
6 * handles miscellaneous db operations:
12 * - viewing PDF schemas
18 require_once './libraries/common.lib.php';
19 require_once './libraries/Table.class.php';
20 require_once './libraries/mysql_charsets.lib.php';
23 * Rename/move or copy database
26 ((isset($db_rename) && $db_rename == 'true') ||
27 (isset($db_copy) && $db_copy == 'true'))) {
29 if (isset($db_rename) && $db_rename == 'true') {
35 if (!isset($newname) ||
!strlen($newname)) {
36 $message = $strDatabaseEmpty;
38 $sql_query = ''; // in case target db exists
40 (isset($create_database_before_copying) && $create_database_before_copying)) {
41 $local_query = 'CREATE DATABASE ' . PMA_backquote($newname);
42 if (isset($db_collation)) {
43 $local_query .= ' DEFAULT' . PMA_generateCharsetQueryPart($db_collation);
46 $sql_query = $local_query;
47 PMA_DBI_query($local_query);
50 if (isset($GLOBALS['add_constraints'])) {
51 $GLOBALS['sql_constraints_query_full_db'] = '';
54 $tables_full = PMA_DBI_get_tables_full($db);
55 foreach ($tables_full as $table => $tmp) {
59 // value of $what for this table only
62 if (!isset($tables_full[$table]['Engine'])) {
63 $tables_full[$table]['Engine'] = $tables_full[$table]['Type'];
65 // do not copy the data from a Merge table
66 // note: on the calling FORM, 'data' means 'structure and data'
67 if ($tables_full[$table]['Engine'] == 'MRG_MyISAM') {
68 if ($this_what == 'data') {
69 $this_what = 'structure';
71 if ($this_what == 'dataonly') {
72 $this_what = 'nocopy';
76 if ($this_what != 'nocopy') {
77 PMA_Table
::moveCopy($db, $table, $newname, $table,
78 isset($this_what) ?
$this_what : 'data', $move, 'db_copy');
79 if (isset($GLOBALS['add_constraints'])) {
80 $GLOBALS['sql_constraints_query_full_db'] .= $GLOBALS['sql_constraints_query'];
81 unset($GLOBALS['sql_constraints_query']);
85 $sql_query = $back . $sql_query;
89 // now that all tables exist, create all the accumulated constraints
90 if (isset($GLOBALS['add_constraints'])) {
91 // FIXME: this works with mysqli but not with mysql,
92 // because mysql extension does not accept more than one
93 // statement; maybe interface with the sql import plugin
94 // that handles statement delimiter
95 PMA_DBI_query($GLOBALS['sql_constraints_query_full_db']);
97 // and prepare to display them
98 $GLOBALS['sql_query'] .= "\n" . $GLOBALS['sql_constraints_query_full_db'];
99 unset($GLOBALS['sql_constraints_query_full_db']);
102 // Duplicate the bookmarks for this db (done once for each db)
103 if ($db != $newname) {
104 $get_fields = array('user', 'label', 'query');
105 $where_fields = array('dbase' => $db);
106 $new_fields = array('dbase' => $newname);
107 PMA_Table
::duplicateInfo('bookmarkwork', 'bookmark', $get_fields,
108 $where_fields, $new_fields);
112 // cleanup pmadb stuff for this db
113 require_once './libraries/relation_cleanup.lib.php';
114 PMA_relationsCleanupDatabase($db);
116 $local_query = 'DROP DATABASE ' . PMA_backquote($db) . ';';
117 $sql_query .= "\n" . $local_query;
118 PMA_DBI_query($local_query);
119 $message = sprintf($strRenameDatabaseOK, htmlspecialchars($db),
120 htmlspecialchars($newname));
122 $message = sprintf($strCopyDatabaseOK, htmlspecialchars($db),
123 htmlspecialchars($newname));
127 /* Change database to be used */
131 if (isset($switch_to_new) && $switch_to_new == 'true') {
132 PMA_setCookie('pma_switch_to_new', 'true');
135 PMA_setCookie('pma_switch_to_new', '');
141 * Settings for relations stuff
144 require_once './libraries/relation.lib.php';
145 $cfgRelation = PMA_getRelationsParam();
148 * Check if comments were updated
149 * (must be done before displaying the menu tabs)
151 if ($cfgRelation['commwork'] && isset($db_comment) && $db_comment == 'true') {
152 PMA_SetComment($db, '', '(db_comment)', $comment);
156 * Prepares the tables list if the user where not redirected to this script
157 * because there is no table in the database ($is_info is true)
159 if (empty($is_info)) {
160 require './libraries/db_details_common.inc.php';
161 $url_query .= '&goto=db_operations.php';
163 // Gets the database structure
164 $sub_part = '_structure';
165 require './libraries/db_details_db_info.inc.php';
169 if (PMA_MYSQL_INT_VERSION
>= 40101) {
170 $db_collation = PMA_getDbCollation($db);
172 if (PMA_MYSQL_INT_VERSION
< 50002
173 ||
(PMA_MYSQL_INT_VERSION
>= 50002 && $db != 'information_schema')) {
174 $is_information_schema = false;
176 $is_information_schema = true;
179 if (!$is_information_schema) {
181 require './libraries/display_create_table.lib.php';
183 if ($cfgRelation['commwork']) {
188 <form method
="post" action
="db_operations.php">
189 <?php
echo PMA_generate_common_hidden_inputs($db); ?
>
190 <input type
="hidden" name
="db_comment" value
="true" />
194 if ($cfg['PropertiesIconic']) {
195 echo '<img class="icon" src="' . $pmaThemeImage . 'b_comment.png"'
196 .' alt="" border="0" width="16" height="16" hspace="2" align="middle" />';
199 $comment = PMA_getComments($db);
202 <input type
="text" name
="comment" class="textfield" size
="30"
204 echo (isset($comment) && is_array($comment)
205 ? htmlspecialchars(implode(' ', $comment))
207 <input type
="submit" value
="<?php echo $strGo; ?>" />
216 <form method
="post" action
="db_operations.php"
217 onsubmit
="return emptyFormElements(this, 'newname')">
218 <input type
="hidden" name
="what" value
="data" />
219 <input type
="hidden" name
="db_rename" value
="true" />
220 <?php
echo PMA_generate_common_hidden_inputs($db); ?
>
224 if ($cfg['PropertiesIconic']) {
225 echo '<img class="icon" src="' . $pmaThemeImage . 'b_edit.png"'
226 .' alt="" width="16" height="16" />';
228 echo $strDBRename . ':';
231 <input type
="text" name
="newname" size
="30" class="textfield" value
="" />
232 <input type
="submit" value
="<?php echo $strGo; ?>" />
241 <form method
="post" action
="db_operations.php"
242 onsubmit
="return emptyFormElements(this, 'newname')">
244 if (isset($db_collation)) {
245 echo '<input type="hidden" name="db_collation" value="' . $db_collation
248 echo '<input type="hidden" name="db_copy" value="true" />' . "\n";
249 echo PMA_generate_common_hidden_inputs($db);
254 if ($cfg['PropertiesIconic']) {
255 echo '<img class="icon" src="' . $pmaThemeImage . 'b_edit.png"'
256 .' alt="" width="16" height="16" />';
258 echo $strDBCopy . ':';
259 if (PMA_MYSQL_INT_VERSION
>= 50000) {
260 $drop_clause = 'DROP TABLE / DROP VIEW';
262 $drop_clause = 'DROP TABLE';
266 <input type
="text" name
="newname" size
="30" class="textfield" value
="" /><br
/>
267 <input type
="radio" name
="what" value
="structure"
268 id
="radio_copy_structure" style
="vertical-align: middle" />
269 <label
for="radio_copy_structure"><?php
echo $strStrucOnly; ?
></label
><br
/>
270 <input type
="radio" name
="what" value
="data" id
="radio_copy_data"
271 checked
="checked" style
="vertical-align: middle" />
272 <label
for="radio_copy_data"><?php
echo $strStrucData; ?
></label
><br
/>
273 <input type
="radio" name
="what" value
="dataonly"
274 id
="radio_copy_dataonly" style
="vertical-align: middle" />
275 <label
for="radio_copy_dataonly"><?php
echo $strDataOnly; ?
></label
><br
/>
277 <input type
="checkbox" name
="create_database_before_copying" value
="1"
278 id
="checkbox_create_database_before_copying"
279 style
="vertical-align: middle" checked
="checked" />
280 <label
for="checkbox_create_database_before_copying">
281 <?php
echo $strCreateDatabaseBeforeCopying; ?
></label
><br
/>
282 <input type
="checkbox" name
="drop_if_exists" value
="true"
283 id
="checkbox_drop" style
="vertical-align: middle" />
284 <label
for="checkbox_drop"><?php
echo sprintf($strAddClause, $drop_clause); ?
></label
><br
/>
285 <input type
="checkbox" name
="sql_auto_increment" value
="1"
286 id
="checkbox_auto_increment" style
="vertical-align: middle" />
287 <label
for="checkbox_auto_increment">
288 <?php
echo $strAddAutoIncrement; ?
></label
><br
/>
289 <input type
="checkbox" name
="add_constraints" value
="1"
290 id
="checkbox_constraints" style
="vertical-align: middle" />
291 <label
for="checkbox_constraints">
292 <?php
echo $strAddConstraints; ?
></label
><br
/>
296 if (isset($_COOKIE) && isset($_COOKIE['pma_switch_to_new'])
297 && $_COOKIE['pma_switch_to_new'] == 'true') {
298 $pma_switch_to_new = 'true';
301 <input type
="checkbox" name
="switch_to_new" value
="true"
303 <?php
echo ((isset($pma_switch_to_new) && $pma_switch_to_new == 'true') ?
' checked="checked"' : ''); ?
>
304 style
="vertical-align: middle" />
305 <label
for="checkbox_switch"><?php
echo $strSwitchToDatabase; ?
></label
>
307 <fieldset
class="tblFooters">
308 <input type
="submit" name
="submit_copy" value
="<?php echo $strGo; ?>" />
314 * Change database charset
316 if (PMA_MYSQL_INT_VERSION
>= 40101) {
317 // MySQL supports setting default charsets / collations for databases since
319 echo '<form method="post" action="./db_operations.php">' . "\n"
320 . PMA_generate_common_hidden_inputs($db, isset($table) ?
$table : '')
321 . '<fieldset>' . "\n"
323 if ($cfg['PropertiesIconic']) {
324 echo '<img class="icon" src="' . $pmaThemeImage . 's_asci.png"'
325 .' alt="" width="16" height="16" />';
327 echo ' <label for="select_db_collation">' . $strCollation . ':</label>' . "\n"
328 . ' </legend>' . "\n"
329 . PMA_generateCharsetDropdownBox(PMA_CSDROPDOWN_COLLATION
,
330 'db_collation', 'select_db_collation', $db_collation, false, 3)
331 . ' <input type="submit" name="submitcollation"'
332 . ' value="' . $strGo . '" style="vertical-align: middle" />' . "\n"
333 . '</fieldset>' . "\n"
338 && !$cfgRelation['allworks'] && $cfg['PmaNoRelation_DisableWarning'] == false) {
339 echo '<div class="error"><h1>' . $strError . '</h1>'
340 . sprintf($strRelationNotWorking,
341 '<a href="' . $cfg['PmaAbsoluteUri'] . 'chk_rel.php?' . $url_query . '">',
345 } // end if (!$is_information_schema)
348 // not sure about leaving the PDF dialog for information_schema
349 if ($num_tables > 0 && isset($table)) {
350 $takeaway = $url_query . '&table=' . urlencode($table);
355 if ($cfgRelation['pdfwork'] && $num_tables > 0) { ?
>
356 <!-- Work on PDF Pages
-->
359 // We only show this if we find something in the new pdf_pages table
363 FROM ' . PMA_backquote($GLOBALS['cfgRelation']['db']) . '.' . PMA_backquote($cfgRelation['pdf_pages']) . '
364 WHERE db_name = \'' . PMA_sqlAddslashes($db) . '\'';
365 $test_rs = PMA_query_as_cu($test_query, null, PMA_DBI_QUERY_STORE
);
367 if ($test_rs && PMA_DBI_num_rows($test_rs) > 0) { ?
>
369 <form method
="post" action
="pdf_schema.php">
373 echo PMA_generate_common_hidden_inputs($db);
374 if ($cfg['PropertiesIconic']) {
375 echo '<img class="icon" src="' . $pmaThemeImage . 'b_view.png"'
376 .' alt="" width="16" height="16" />';
381 <label
for="pdf_page_number_opt"><?php
echo $strPageNumber; ?
></label
>
382 <select name
="pdf_page_number" id
="pdf_page_number_opt">
384 while ($pages = @PMA_DBI_fetch_assoc
($test_rs)) {
385 echo ' <option value="' . $pages['page_nr'] . '">'
386 . $pages['page_nr'] . ': ' . $pages['page_descr'] . '</option>' . "\n";
388 PMA_DBI_free_result($test_rs);
393 <input type
="checkbox" name
="show_grid" id
="show_grid_opt" />
394 <label
for="show_grid_opt"><?php
echo $strShowGrid; ?
></label
><br
/>
395 <input type
="checkbox" name
="show_color" id
="show_color_opt"
397 <label
for="show_color_opt"><?php
echo $strShowColor; ?
></label
><br
/>
398 <input type
="checkbox" name
="show_table_dimension" id
="show_table_dim_opt" />
399 <label
for="show_table_dim_opt"><?php
echo $strShowTableDimension; ?
>
401 <input type
="checkbox" name
="all_tab_same_wide" id
="all_tab_same_wide" />
402 <label
for="all_tab_same_wide"><?php
echo $strAllTableSameWidth; ?
>
404 <input type
="checkbox" name
="with_doc" id
="with_doc" checked
="checked" />
405 <label
for="with_doc"><?php
echo $strDataDict; ?
></label
><br
/>
407 <label
for="orientation_opt"><?php
echo $strShowDatadictAs; ?
></label
>
408 <select name
="orientation" id
="orientation_opt">
409 <option value
="L"><?php
echo $strLandscape;?
></option
>
410 <option value
="P"><?php
echo $strPortrait;?
></option
>
413 <label
for="paper_opt"><?php
echo $strPaperSize; ?
></label
>
414 <select name
="paper" id
="paper_opt">
416 foreach ($cfg['PDFPageSizes'] AS $key => $val) {
417 echo '<option value="' . $val . '"';
418 if ($val == $cfg['PDFDefaultPageSize']) {
419 echo ' selected="selected"';
421 echo ' >' . $val . '</option>' . "\n";
426 <fieldset
class="tblFooters">
427 <input type
="submit" value
="<?php echo $strGo; ?>" />
436 echo '<a href="pdf_pages.php?' . $takeaway . '">';
437 if ($cfg['PropertiesIconic']) {
438 echo '<img class="icon" src="' . $pmaThemeImage . 'b_edit.png"'
439 .' alt="" width="16" height="16" />';
441 echo $strEditPDFPages . '</a>';
449 && $cfgRelation['relwork'] && $cfgRelation['commwork']
450 && isset($cfg['docSQLDir']) && !empty($cfg['docSQLDir'])) {
452 * import docSQL files
455 .'<li><a href="db_details_importdocsql.php?' . $takeaway . '">' . "\n";
456 if ($cfg['PropertiesIconic']) {
457 echo '<img class="icon" src="' . $pmaThemeImage . 'b_docsql.png"'
458 .' alt="" width="16" height="16" />';
460 echo $strImportDocSQL . '</a></li>' . "\n"
465 * Displays the footer
467 require_once './libraries/footer.inc.php';