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);
56 foreach ($tables_full as $table => $tmp) {
57 // to be able to rename a db containing views, we
58 // first collect in $views all the views we find and we
59 // will handle them after the tables
61 * @todo support a view of a view
63 if (PMA_Table
::isView($db, $table)) {
71 // value of $what for this table only
74 if (!isset($tables_full[$table]['Engine'])) {
75 $tables_full[$table]['Engine'] = $tables_full[$table]['Type'];
77 // do not copy the data from a Merge table
78 // note: on the calling FORM, 'data' means 'structure and data'
79 if ($tables_full[$table]['Engine'] == 'MRG_MyISAM') {
80 if ($this_what == 'data') {
81 $this_what = 'structure';
83 if ($this_what == 'dataonly') {
84 $this_what = 'nocopy';
88 if ($this_what != 'nocopy') {
89 PMA_Table
::moveCopy($db, $table, $newname, $table,
90 isset($this_what) ?
$this_what : 'data', $move, 'db_copy');
91 if (isset($GLOBALS['add_constraints'])) {
92 $GLOBALS['sql_constraints_query_full_db'] .= $GLOBALS['sql_constraints_query'];
93 unset($GLOBALS['sql_constraints_query']);
97 $sql_query = $back . $sql_query;
102 foreach ($views as $view) {
103 PMA_Table
::moveCopy($db, $view, $newname, $view,
104 'structure', $move, 'db_copy');
106 unset($view, $views);
108 // now that all tables exist, create all the accumulated constraints
109 if (isset($GLOBALS['add_constraints'])) {
111 * @todo this works with mysqli but not with mysql, because
112 * mysql extension does not accept more than one statement; maybe
113 * interface with the sql import plugin that handles statement delimiter
115 PMA_DBI_query($GLOBALS['sql_constraints_query_full_db']);
117 // and prepare to display them
118 $GLOBALS['sql_query'] .= "\n" . $GLOBALS['sql_constraints_query_full_db'];
119 unset($GLOBALS['sql_constraints_query_full_db']);
122 // Duplicate the bookmarks for this db (done once for each db)
123 if ($db != $newname) {
124 $get_fields = array('user', 'label', 'query');
125 $where_fields = array('dbase' => $db);
126 $new_fields = array('dbase' => $newname);
127 PMA_Table
::duplicateInfo('bookmarkwork', 'bookmark', $get_fields,
128 $where_fields, $new_fields);
132 // cleanup pmadb stuff for this db
133 require_once './libraries/relation_cleanup.lib.php';
134 PMA_relationsCleanupDatabase($db);
136 $local_query = 'DROP DATABASE ' . PMA_backquote($db) . ';';
137 $sql_query .= "\n" . $local_query;
138 PMA_DBI_query($local_query);
139 $message = sprintf($strRenameDatabaseOK, htmlspecialchars($db),
140 htmlspecialchars($newname));
142 $message = sprintf($strCopyDatabaseOK, htmlspecialchars($db),
143 htmlspecialchars($newname));
147 /* Change database to be used */
151 if (isset($switch_to_new) && $switch_to_new == 'true') {
152 PMA_setCookie('pma_switch_to_new', 'true');
155 PMA_setCookie('pma_switch_to_new', '');
161 * Settings for relations stuff
164 require_once './libraries/relation.lib.php';
165 $cfgRelation = PMA_getRelationsParam();
168 * Check if comments were updated
169 * (must be done before displaying the menu tabs)
171 if ($cfgRelation['commwork'] && isset($db_comment) && $db_comment == 'true') {
172 PMA_SetComment($db, '', '(db_comment)', $comment);
176 * Prepares the tables list if the user where not redirected to this script
177 * because there is no table in the database ($is_info is true)
179 if (empty($is_info)) {
180 require './libraries/db_details_common.inc.php';
181 $url_query .= '&goto=db_operations.php';
183 // Gets the database structure
184 $sub_part = '_structure';
185 require './libraries/db_details_db_info.inc.php';
189 if (PMA_MYSQL_INT_VERSION
>= 40101) {
190 $db_collation = PMA_getDbCollation($db);
192 if (PMA_MYSQL_INT_VERSION
< 50002
193 ||
(PMA_MYSQL_INT_VERSION
>= 50002 && $db != 'information_schema')) {
194 $is_information_schema = false;
196 $is_information_schema = true;
199 if (!$is_information_schema) {
201 require './libraries/display_create_table.lib.php';
203 if ($cfgRelation['commwork']) {
208 <form method
="post" action
="db_operations.php">
209 <?php
echo PMA_generate_common_hidden_inputs($db); ?
>
210 <input type
="hidden" name
="db_comment" value
="true" />
214 if ($cfg['PropertiesIconic']) {
215 echo '<img class="icon" src="' . $pmaThemeImage . 'b_comment.png"'
216 .' alt="" border="0" width="16" height="16" hspace="2" align="middle" />';
219 $comment = PMA_getComments($db);
222 <input type
="text" name
="comment" class="textfield" size
="30"
224 echo (isset($comment) && is_array($comment)
225 ? htmlspecialchars(implode(' ', $comment))
227 <input type
="submit" value
="<?php echo $strGo; ?>" />
236 <form method
="post" action
="db_operations.php"
237 onsubmit
="return emptyFormElements(this, 'newname')">
238 <input type
="hidden" name
="what" value
="data" />
239 <input type
="hidden" name
="db_rename" value
="true" />
240 <?php
echo PMA_generate_common_hidden_inputs($db); ?
>
244 if ($cfg['PropertiesIconic']) {
245 echo '<img class="icon" src="' . $pmaThemeImage . 'b_edit.png"'
246 .' alt="" width="16" height="16" />';
248 echo $strDBRename . ':';
251 <input type
="text" name
="newname" size
="30" class="textfield" value
="" />
252 <input type
="submit" value
="<?php echo $strGo; ?>" />
261 <form method
="post" action
="db_operations.php"
262 onsubmit
="return emptyFormElements(this, 'newname')">
264 if (isset($db_collation)) {
265 echo '<input type="hidden" name="db_collation" value="' . $db_collation
268 echo '<input type="hidden" name="db_copy" value="true" />' . "\n";
269 echo PMA_generate_common_hidden_inputs($db);
274 if ($cfg['PropertiesIconic']) {
275 echo '<img class="icon" src="' . $pmaThemeImage . 'b_edit.png"'
276 .' alt="" width="16" height="16" />';
278 echo $strDBCopy . ':';
279 if (PMA_MYSQL_INT_VERSION
>= 50000) {
280 $drop_clause = 'DROP TABLE / DROP VIEW';
282 $drop_clause = 'DROP TABLE';
286 <input type
="text" name
="newname" size
="30" class="textfield" value
="" /><br
/>
287 <input type
="radio" name
="what" value
="structure"
288 id
="radio_copy_structure" style
="vertical-align: middle" />
289 <label
for="radio_copy_structure"><?php
echo $strStrucOnly; ?
></label
><br
/>
290 <input type
="radio" name
="what" value
="data" id
="radio_copy_data"
291 checked
="checked" style
="vertical-align: middle" />
292 <label
for="radio_copy_data"><?php
echo $strStrucData; ?
></label
><br
/>
293 <input type
="radio" name
="what" value
="dataonly"
294 id
="radio_copy_dataonly" style
="vertical-align: middle" />
295 <label
for="radio_copy_dataonly"><?php
echo $strDataOnly; ?
></label
><br
/>
297 <input type
="checkbox" name
="create_database_before_copying" value
="1"
298 id
="checkbox_create_database_before_copying"
299 style
="vertical-align: middle" checked
="checked" />
300 <label
for="checkbox_create_database_before_copying">
301 <?php
echo $strCreateDatabaseBeforeCopying; ?
></label
><br
/>
302 <input type
="checkbox" name
="drop_if_exists" value
="true"
303 id
="checkbox_drop" style
="vertical-align: middle" />
304 <label
for="checkbox_drop"><?php
echo sprintf($strAddClause, $drop_clause); ?
></label
><br
/>
305 <input type
="checkbox" name
="sql_auto_increment" value
="1"
306 id
="checkbox_auto_increment" style
="vertical-align: middle" />
307 <label
for="checkbox_auto_increment">
308 <?php
echo $strAddAutoIncrement; ?
></label
><br
/>
309 <input type
="checkbox" name
="add_constraints" value
="1"
310 id
="checkbox_constraints" style
="vertical-align: middle" />
311 <label
for="checkbox_constraints">
312 <?php
echo $strAddConstraints; ?
></label
><br
/>
316 if (isset($_COOKIE) && isset($_COOKIE['pma_switch_to_new'])
317 && $_COOKIE['pma_switch_to_new'] == 'true') {
318 $pma_switch_to_new = 'true';
321 <input type
="checkbox" name
="switch_to_new" value
="true"
323 <?php
echo ((isset($pma_switch_to_new) && $pma_switch_to_new == 'true') ?
' checked="checked"' : ''); ?
>
324 style
="vertical-align: middle" />
325 <label
for="checkbox_switch"><?php
echo $strSwitchToDatabase; ?
></label
>
327 <fieldset
class="tblFooters">
328 <input type
="submit" name
="submit_copy" value
="<?php echo $strGo; ?>" />
334 * Change database charset
336 if (PMA_MYSQL_INT_VERSION
>= 40101) {
337 // MySQL supports setting default charsets / collations for databases since
339 echo '<form method="post" action="./db_operations.php">' . "\n"
340 . PMA_generate_common_hidden_inputs($db, isset($table) ?
$table : '')
341 . '<fieldset>' . "\n"
343 if ($cfg['PropertiesIconic']) {
344 echo '<img class="icon" src="' . $pmaThemeImage . 's_asci.png"'
345 .' alt="" width="16" height="16" />';
347 echo ' <label for="select_db_collation">' . $strCollation . ':</label>' . "\n"
348 . ' </legend>' . "\n"
349 . PMA_generateCharsetDropdownBox(PMA_CSDROPDOWN_COLLATION
,
350 'db_collation', 'select_db_collation', $db_collation, false, 3)
351 . ' <input type="submit" name="submitcollation"'
352 . ' value="' . $strGo . '" style="vertical-align: middle" />' . "\n"
353 . '</fieldset>' . "\n"
358 && !$cfgRelation['allworks'] && $cfg['PmaNoRelation_DisableWarning'] == false) {
359 echo '<div class="error"><h1>' . $strError . '</h1>'
360 . sprintf($strRelationNotWorking,
361 '<a href="' . $cfg['PmaAbsoluteUri'] . 'chk_rel.php?' . $url_query . '">',
365 } // end if (!$is_information_schema)
368 // not sure about leaving the PDF dialog for information_schema
369 if ($num_tables > 0 && isset($table)) {
370 $takeaway = $url_query . '&table=' . urlencode($table);
375 if ($cfgRelation['pdfwork'] && $num_tables > 0) { ?
>
376 <!-- Work on PDF Pages
-->
379 // We only show this if we find something in the new pdf_pages table
383 FROM ' . PMA_backquote($GLOBALS['cfgRelation']['db']) . '.' . PMA_backquote($cfgRelation['pdf_pages']) . '
384 WHERE db_name = \'' . PMA_sqlAddslashes($db) . '\'';
385 $test_rs = PMA_query_as_cu($test_query, null, PMA_DBI_QUERY_STORE
);
387 if ($test_rs && PMA_DBI_num_rows($test_rs) > 0) { ?
>
389 <form method
="post" action
="pdf_schema.php">
393 echo PMA_generate_common_hidden_inputs($db);
394 if ($cfg['PropertiesIconic']) {
395 echo '<img class="icon" src="' . $pmaThemeImage . 'b_view.png"'
396 .' alt="" width="16" height="16" />';
401 <label
for="pdf_page_number_opt"><?php
echo $strPageNumber; ?
></label
>
402 <select name
="pdf_page_number" id
="pdf_page_number_opt">
404 while ($pages = @PMA_DBI_fetch_assoc
($test_rs)) {
405 echo ' <option value="' . $pages['page_nr'] . '">'
406 . $pages['page_nr'] . ': ' . $pages['page_descr'] . '</option>' . "\n";
408 PMA_DBI_free_result($test_rs);
413 <input type
="checkbox" name
="show_grid" id
="show_grid_opt" />
414 <label
for="show_grid_opt"><?php
echo $strShowGrid; ?
></label
><br
/>
415 <input type
="checkbox" name
="show_color" id
="show_color_opt"
417 <label
for="show_color_opt"><?php
echo $strShowColor; ?
></label
><br
/>
418 <input type
="checkbox" name
="show_table_dimension" id
="show_table_dim_opt" />
419 <label
for="show_table_dim_opt"><?php
echo $strShowTableDimension; ?
>
421 <input type
="checkbox" name
="all_tab_same_wide" id
="all_tab_same_wide" />
422 <label
for="all_tab_same_wide"><?php
echo $strAllTableSameWidth; ?
>
424 <input type
="checkbox" name
="with_doc" id
="with_doc" checked
="checked" />
425 <label
for="with_doc"><?php
echo $strDataDict; ?
></label
><br
/>
427 <label
for="orientation_opt"><?php
echo $strShowDatadictAs; ?
></label
>
428 <select name
="orientation" id
="orientation_opt">
429 <option value
="L"><?php
echo $strLandscape;?
></option
>
430 <option value
="P"><?php
echo $strPortrait;?
></option
>
433 <label
for="paper_opt"><?php
echo $strPaperSize; ?
></label
>
434 <select name
="paper" id
="paper_opt">
436 foreach ($cfg['PDFPageSizes'] AS $key => $val) {
437 echo '<option value="' . $val . '"';
438 if ($val == $cfg['PDFDefaultPageSize']) {
439 echo ' selected="selected"';
441 echo ' >' . $val . '</option>' . "\n";
446 <fieldset
class="tblFooters">
447 <input type
="submit" value
="<?php echo $strGo; ?>" />
456 echo '<a href="pdf_pages.php?' . $takeaway . '">';
457 if ($cfg['PropertiesIconic']) {
458 echo '<img class="icon" src="' . $pmaThemeImage . 'b_edit.png"'
459 .' alt="" width="16" height="16" />';
461 echo $strEditPDFPages . '</a>';
469 && $cfgRelation['relwork'] && $cfgRelation['commwork']
470 && isset($cfg['docSQLDir']) && !empty($cfg['docSQLDir'])) {
472 * import docSQL files
475 .'<li><a href="db_details_importdocsql.php?' . $takeaway . '">' . "\n";
476 if ($cfg['PropertiesIconic']) {
477 echo '<img class="icon" src="' . $pmaThemeImage . 'b_docsql.png"'
478 .' alt="" width="16" height="16" />';
480 echo $strImportDocSQL . '</a></li>' . "\n"
485 * Displays the footer
487 require_once './libraries/footer.inc.php';