2 /* vim: set expandtab sw=4 ts=4 sts=4: */
4 * handles miscellaneous db operations:
10 * - viewing PDF schemas
18 require_once './libraries/common.inc.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)) {
42 * @todo activate this with the correct version of MySQL
43 * when they fix the problem when the db contains a VIEW
44 * (problem exists in 5.1.20)
45 * also, in 6.0.0 when the db contains a Falcon table,
46 * renaming it results in a unusable db!
48 //if (PMA_MYSQL_INT_VERSION >= 50107) {
49 // $local_query = 'RENAME DATABASE ' . PMA_backquote($db) . ' TO ' . PMA_backquote($newname) . ';';
50 // $sql_query = $local_query;
51 // PMA_DBI_query($local_query);
54 $local_query = 'CREATE DATABASE ' . PMA_backquote($newname);
55 if (isset($db_collation)) {
56 $local_query .= ' DEFAULT' . PMA_generateCharsetQueryPart($db_collation);
59 $sql_query = $local_query;
60 PMA_DBI_query($local_query);
61 // rebuild the database list because PMA_Table::moveCopy
62 // checks in this list if the target db exists
63 $GLOBALS['PMA_List_Database']->build();
66 if (isset($GLOBALS['add_constraints'])) {
67 $GLOBALS['sql_constraints_query_full_db'] = '';
70 $tables_full = PMA_DBI_get_tables_full($db);
72 foreach ($tables_full as $each_table => $tmp) {
73 // to be able to rename a db containing views, we
74 // first collect in $views all the views we find and we
75 // will handle them after the tables
77 * @todo support a view of a view
79 if (PMA_Table
::isView($db, $each_table)) {
80 $views[] = $each_table;
87 // value of $what for this table only
90 if (!isset($tables_full[$each_table]['Engine'])) {
91 $tables_full[$each_table]['Engine'] = $tables_full[$each_table]['Type'];
93 // do not copy the data from a Merge table
94 // note: on the calling FORM, 'data' means 'structure and data'
95 if ($tables_full[$each_table]['Engine'] == 'MRG_MyISAM') {
96 if ($this_what == 'data') {
97 $this_what = 'structure';
99 if ($this_what == 'dataonly') {
100 $this_what = 'nocopy';
104 if ($this_what != 'nocopy') {
105 PMA_Table
::moveCopy($db, $each_table, $newname, $each_table,
106 isset($this_what) ?
$this_what : 'data', $move, 'db_copy');
107 if (isset($GLOBALS['add_constraints'])) {
108 $GLOBALS['sql_constraints_query_full_db'] .= $GLOBALS['sql_constraints_query'];
109 unset($GLOBALS['sql_constraints_query']);
113 $sql_query = $back . $sql_query;
118 foreach ($views as $view) {
119 PMA_Table
::moveCopy($db, $view, $newname, $view,
120 'structure', $move, 'db_copy');
122 unset($view, $views);
124 // now that all tables exist, create all the accumulated constraints
125 if (isset($GLOBALS['add_constraints'])) {
127 * @todo this works with mysqli but not with mysql, because
128 * mysql extension does not accept more than one statement; maybe
129 * interface with the sql import plugin that handles statement delimiter
131 PMA_DBI_query($GLOBALS['sql_constraints_query_full_db']);
133 // and prepare to display them
134 $GLOBALS['sql_query'] .= "\n" . $GLOBALS['sql_constraints_query_full_db'];
135 unset($GLOBALS['sql_constraints_query_full_db']);
137 // see the previous todo
138 // } // end else MySQL < 50107
140 // Duplicate the bookmarks for this db (done once for each db)
141 if ($db != $newname) {
142 $get_fields = array('user', 'label', 'query');
143 $where_fields = array('dbase' => $db);
144 $new_fields = array('dbase' => $newname);
145 PMA_Table
::duplicateInfo('bookmarkwork', 'bookmark', $get_fields,
146 $where_fields, $new_fields);
150 // cleanup pmadb stuff for this db
151 require_once './libraries/relation_cleanup.lib.php';
152 PMA_relationsCleanupDatabase($db);
154 if (PMA_MYSQL_INT_VERSION
< 50107) {
155 $local_query = 'DROP DATABASE ' . PMA_backquote($db) . ';';
156 $sql_query .= "\n" . $local_query;
157 PMA_DBI_query($local_query);
159 $message = sprintf($strRenameDatabaseOK, htmlspecialchars($db),
160 htmlspecialchars($newname));
162 $message = sprintf($strCopyDatabaseOK, htmlspecialchars($db),
163 htmlspecialchars($newname));
167 /* Change database to be used */
171 if (isset($switch_to_new) && $switch_to_new == 'true') {
172 PMA_setCookie('pma_switch_to_new', 'true');
175 PMA_setCookie('pma_switch_to_new', '');
181 * Settings for relations stuff
184 require_once './libraries/relation.lib.php';
185 $cfgRelation = PMA_getRelationsParam();
188 * Check if comments were updated
189 * (must be done before displaying the menu tabs)
191 if ($cfgRelation['commwork'] && isset($db_comment) && $db_comment == 'true') {
192 PMA_SetComment($db, '', '(db_comment)', $comment);
196 * Prepares the tables list if the user where not redirected to this script
197 * because there is no table in the database ($is_info is true)
199 if (empty($is_info)) {
200 require './libraries/db_common.inc.php';
201 $url_query .= '&goto=db_operations.php';
203 // Gets the database structure
204 $sub_part = '_structure';
205 require './libraries/db_info.inc.php';
209 if (PMA_MYSQL_INT_VERSION
>= 40101) {
210 $db_collation = PMA_getDbCollation($db);
212 if (PMA_MYSQL_INT_VERSION
< 50002
213 ||
(PMA_MYSQL_INT_VERSION
>= 50002 && $db != 'information_schema')) {
214 $is_information_schema = false;
216 $is_information_schema = true;
219 if (!$is_information_schema) {
221 require './libraries/display_create_table.lib.php';
223 if ($cfgRelation['commwork']) {
228 <form method
="post" action
="db_operations.php">
229 <?php
echo PMA_generate_common_hidden_inputs($db); ?
>
230 <input type
="hidden" name
="db_comment" value
="true" />
234 if ($cfg['PropertiesIconic']) {
235 echo '<img class="icon" src="' . $pmaThemeImage . 'b_comment.png"'
236 .' alt="" border="0" width="16" height="16" hspace="2" align="middle" />';
239 $comment = PMA_getComments($db);
242 <input type
="text" name
="comment" class="textfield" size
="30"
244 echo (isset($comment) && is_array($comment)
245 ? htmlspecialchars(implode(' ', $comment))
247 <input type
="submit" value
="<?php echo $strGo; ?>" />
256 <form method
="post" action
="db_operations.php"
257 onsubmit
="return emptyFormElements(this, 'newname')">
258 <input type
="hidden" name
="what" value
="data" />
259 <input type
="hidden" name
="db_rename" value
="true" />
260 <?php
echo PMA_generate_common_hidden_inputs($db); ?
>
264 if ($cfg['PropertiesIconic']) {
265 echo '<img class="icon" src="' . $pmaThemeImage . 'b_edit.png"'
266 .' alt="" width="16" height="16" />';
268 echo $strDBRename . ':';
271 <input type
="text" name
="newname" size
="30" class="textfield" value
="" />
273 echo '(' . $strCommand . ': ';
275 * @todo (see explanations above in a previous todo)
277 //if (PMA_MYSQL_INT_VERSION >= 50107) {
278 // echo 'RENAME DATABASE';
280 echo 'INSERT INTO ... SELECT';
283 <input type
="submit" value
="<?php echo $strGo; ?>" />
292 <form method
="post" action
="db_operations.php"
293 onsubmit
="return emptyFormElements(this, 'newname')">
295 if (isset($db_collation)) {
296 echo '<input type="hidden" name="db_collation" value="' . $db_collation
299 echo '<input type="hidden" name="db_copy" value="true" />' . "\n";
300 echo PMA_generate_common_hidden_inputs($db);
305 if ($cfg['PropertiesIconic']) {
306 echo '<img class="icon" src="' . $pmaThemeImage . 'b_edit.png"'
307 .' alt="" width="16" height="16" />';
309 echo $strDBCopy . ':';
310 if (PMA_MYSQL_INT_VERSION
>= 50000) {
311 $drop_clause = 'DROP TABLE / DROP VIEW';
313 $drop_clause = 'DROP TABLE';
317 <input type
="text" name
="newname" size
="30" class="textfield" value
="" /><br
/>
318 <input type
="radio" name
="what" value
="structure"
319 id
="radio_copy_structure" style
="vertical-align: middle" />
320 <label
for="radio_copy_structure"><?php
echo $strStrucOnly; ?
></label
><br
/>
321 <input type
="radio" name
="what" value
="data" id
="radio_copy_data"
322 checked
="checked" style
="vertical-align: middle" />
323 <label
for="radio_copy_data"><?php
echo $strStrucData; ?
></label
><br
/>
324 <input type
="radio" name
="what" value
="dataonly"
325 id
="radio_copy_dataonly" style
="vertical-align: middle" />
326 <label
for="radio_copy_dataonly"><?php
echo $strDataOnly; ?
></label
><br
/>
328 <input type
="checkbox" name
="create_database_before_copying" value
="1"
329 id
="checkbox_create_database_before_copying"
330 style
="vertical-align: middle" checked
="checked" />
331 <label
for="checkbox_create_database_before_copying">
332 <?php
echo $strCreateDatabaseBeforeCopying; ?
></label
><br
/>
333 <input type
="checkbox" name
="drop_if_exists" value
="true"
334 id
="checkbox_drop" style
="vertical-align: middle" />
335 <label
for="checkbox_drop"><?php
echo sprintf($strAddClause, $drop_clause); ?
></label
><br
/>
336 <input type
="checkbox" name
="sql_auto_increment" value
="1"
337 id
="checkbox_auto_increment" style
="vertical-align: middle" />
338 <label
for="checkbox_auto_increment">
339 <?php
echo $strAddAutoIncrement; ?
></label
><br
/>
340 <input type
="checkbox" name
="add_constraints" value
="1"
341 id
="checkbox_constraints" style
="vertical-align: middle" />
342 <label
for="checkbox_constraints">
343 <?php
echo $strAddConstraints; ?
></label
><br
/>
347 if (isset($_COOKIE) && isset($_COOKIE['pma_switch_to_new'])
348 && $_COOKIE['pma_switch_to_new'] == 'true') {
349 $pma_switch_to_new = 'true';
352 <input type
="checkbox" name
="switch_to_new" value
="true"
354 <?php
echo ((isset($pma_switch_to_new) && $pma_switch_to_new == 'true') ?
' checked="checked"' : ''); ?
>
355 style
="vertical-align: middle" />
356 <label
for="checkbox_switch"><?php
echo $strSwitchToDatabase; ?
></label
>
358 <fieldset
class="tblFooters">
359 <input type
="submit" name
="submit_copy" value
="<?php echo $strGo; ?>" />
365 * Change database charset
367 if (PMA_MYSQL_INT_VERSION
>= 40101) {
368 // MySQL supports setting default charsets / collations for databases since
370 echo '<form method="post" action="./db_operations.php">' . "\n"
371 . PMA_generate_common_hidden_inputs($db, $table)
372 . '<fieldset>' . "\n"
374 if ($cfg['PropertiesIconic']) {
375 echo '<img class="icon" src="' . $pmaThemeImage . 's_asci.png"'
376 .' alt="" width="16" height="16" />';
378 echo ' <label for="select_db_collation">' . $strCollation . ':</label>' . "\n"
379 . ' </legend>' . "\n"
380 . PMA_generateCharsetDropdownBox(PMA_CSDROPDOWN_COLLATION
,
381 'db_collation', 'select_db_collation', $db_collation, false, 3)
382 . ' <input type="submit" name="submitcollation"'
383 . ' value="' . $strGo . '" style="vertical-align: middle" />' . "\n"
384 . '</fieldset>' . "\n"
389 && !$cfgRelation['allworks'] && $cfg['PmaNoRelation_DisableWarning'] == false) {
390 /* Show error if user has configured something, notice elsewhere */
391 if (!empty($cfg['Servers'][$server]['pmadb'])) {
392 echo '<div class="error"><h1>' . $strError . '</h1>';
394 echo '<div class="notice">';
396 printf($strRelationNotWorking, '<a href="' . $cfg['PmaAbsoluteUri'] . 'chk_rel.php?' . $url_query . '">', '</a>');
399 } // end if (!$is_information_schema)
402 // not sure about leaving the PDF dialog for information_schema
403 if ($num_tables > 0 && strlen($table)) {
404 $takeaway = $url_query . '&table=' . urlencode($table);
409 if ($cfgRelation['pdfwork'] && $num_tables > 0) { ?
>
410 <!-- Work on PDF Pages
-->
413 // We only show this if we find something in the new pdf_pages table
417 FROM ' . PMA_backquote($GLOBALS['cfgRelation']['db']) . '.' . PMA_backquote($cfgRelation['pdf_pages']) . '
418 WHERE db_name = \'' . PMA_sqlAddslashes($db) . '\'';
419 $test_rs = PMA_query_as_cu($test_query, null, PMA_DBI_QUERY_STORE
);
421 if ($test_rs && PMA_DBI_num_rows($test_rs) > 0) { ?
>
423 <form method
="post" action
="pdf_schema.php">
427 echo PMA_generate_common_hidden_inputs($db);
428 if ($cfg['PropertiesIconic']) {
429 echo '<img class="icon" src="' . $pmaThemeImage . 'b_view.png"'
430 .' alt="" width="16" height="16" />';
435 <label
for="pdf_page_number_opt"><?php
echo $strPageNumber; ?
></label
>
436 <select name
="pdf_page_number" id
="pdf_page_number_opt">
438 while ($pages = @PMA_DBI_fetch_assoc
($test_rs)) {
439 echo ' <option value="' . $pages['page_nr'] . '">'
440 . $pages['page_nr'] . ': ' . $pages['page_descr'] . '</option>' . "\n";
442 PMA_DBI_free_result($test_rs);
447 <input type
="checkbox" name
="show_grid" id
="show_grid_opt" />
448 <label
for="show_grid_opt"><?php
echo $strShowGrid; ?
></label
><br
/>
449 <input type
="checkbox" name
="show_color" id
="show_color_opt"
451 <label
for="show_color_opt"><?php
echo $strShowColor; ?
></label
><br
/>
452 <input type
="checkbox" name
="show_table_dimension" id
="show_table_dim_opt" />
453 <label
for="show_table_dim_opt"><?php
echo $strShowTableDimension; ?
>
455 <input type
="checkbox" name
="all_tab_same_wide" id
="all_tab_same_wide" />
456 <label
for="all_tab_same_wide"><?php
echo $strAllTableSameWidth; ?
>
458 <input type
="checkbox" name
="with_doc" id
="with_doc" checked
="checked" />
459 <label
for="with_doc"><?php
echo $strDataDict; ?
></label
><br
/>
461 <label
for="orientation_opt"><?php
echo $strShowDatadictAs; ?
></label
>
462 <select name
="orientation" id
="orientation_opt">
463 <option value
="L"><?php
echo $strLandscape;?
></option
>
464 <option value
="P"><?php
echo $strPortrait;?
></option
>
467 <label
for="paper_opt"><?php
echo $strPaperSize; ?
></label
>
468 <select name
="paper" id
="paper_opt">
470 foreach ($cfg['PDFPageSizes'] AS $key => $val) {
471 echo '<option value="' . $val . '"';
472 if ($val == $cfg['PDFDefaultPageSize']) {
473 echo ' selected="selected"';
475 echo ' >' . $val . '</option>' . "\n";
480 <fieldset
class="tblFooters">
481 <input type
="submit" value
="<?php echo $strGo; ?>" />
490 echo '<a href="pdf_pages.php?' . $takeaway . '">';
491 if ($cfg['PropertiesIconic']) {
492 echo '<img class="icon" src="' . $pmaThemeImage . 'b_edit.png"'
493 .' alt="" width="16" height="16" />';
495 echo $strEditPDFPages . '</a>';
503 * Displays the footer
505 require_once './libraries/footer.inc.php';