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'])) {
92 * @todo this works with mysqli but not with mysql, because
93 * mysql extension does not accept more than one statement; maybe
94 * interface with the sql import plugin that handles statement delimiter
96 PMA_DBI_query($GLOBALS['sql_constraints_query_full_db']);
98 // and prepare to display them
99 $GLOBALS['sql_query'] .= "\n" . $GLOBALS['sql_constraints_query_full_db'];
100 unset($GLOBALS['sql_constraints_query_full_db']);
103 // Duplicate the bookmarks for this db (done once for each db)
104 if ($db != $newname) {
105 $get_fields = array('user', 'label', 'query');
106 $where_fields = array('dbase' => $db);
107 $new_fields = array('dbase' => $newname);
108 PMA_Table
::duplicateInfo('bookmarkwork', 'bookmark', $get_fields,
109 $where_fields, $new_fields);
113 // cleanup pmadb stuff for this db
114 require_once './libraries/relation_cleanup.lib.php';
115 PMA_relationsCleanupDatabase($db);
117 $local_query = 'DROP DATABASE ' . PMA_backquote($db) . ';';
118 $sql_query .= "\n" . $local_query;
119 PMA_DBI_query($local_query);
120 $message = sprintf($strRenameDatabaseOK, htmlspecialchars($db),
121 htmlspecialchars($newname));
123 $message = sprintf($strCopyDatabaseOK, htmlspecialchars($db),
124 htmlspecialchars($newname));
128 /* Change database to be used */
132 if (isset($switch_to_new) && $switch_to_new == 'true') {
133 PMA_setCookie('pma_switch_to_new', 'true');
136 PMA_setCookie('pma_switch_to_new', '');
142 * Settings for relations stuff
145 require_once './libraries/relation.lib.php';
146 $cfgRelation = PMA_getRelationsParam();
149 * Check if comments were updated
150 * (must be done before displaying the menu tabs)
152 if ($cfgRelation['commwork'] && isset($db_comment) && $db_comment == 'true') {
153 PMA_SetComment($db, '', '(db_comment)', $comment);
157 * Prepares the tables list if the user where not redirected to this script
158 * because there is no table in the database ($is_info is true)
160 if (empty($is_info)) {
161 require './libraries/db_details_common.inc.php';
162 $url_query .= '&goto=db_operations.php';
164 // Gets the database structure
165 $sub_part = '_structure';
166 require './libraries/db_details_db_info.inc.php';
170 if (PMA_MYSQL_INT_VERSION
>= 40101) {
171 $db_collation = PMA_getDbCollation($db);
173 if (PMA_MYSQL_INT_VERSION
< 50002
174 ||
(PMA_MYSQL_INT_VERSION
>= 50002 && $db != 'information_schema')) {
175 $is_information_schema = false;
177 $is_information_schema = true;
180 if (!$is_information_schema) {
182 require './libraries/display_create_table.lib.php';
184 if ($cfgRelation['commwork']) {
189 <form method
="post" action
="db_operations.php">
190 <?php
echo PMA_generate_common_hidden_inputs($db); ?
>
191 <input type
="hidden" name
="db_comment" value
="true" />
195 if ($cfg['PropertiesIconic']) {
196 echo '<img class="icon" src="' . $pmaThemeImage . 'b_comment.png"'
197 .' alt="" border="0" width="16" height="16" hspace="2" align="middle" />';
200 $comment = PMA_getComments($db);
203 <input type
="text" name
="comment" class="textfield" size
="30"
205 echo (isset($comment) && is_array($comment)
206 ? htmlspecialchars(implode(' ', $comment))
208 <input type
="submit" value
="<?php echo $strGo; ?>" />
217 <form method
="post" action
="db_operations.php"
218 onsubmit
="return emptyFormElements(this, 'newname')">
219 <input type
="hidden" name
="what" value
="data" />
220 <input type
="hidden" name
="db_rename" value
="true" />
221 <?php
echo PMA_generate_common_hidden_inputs($db); ?
>
225 if ($cfg['PropertiesIconic']) {
226 echo '<img class="icon" src="' . $pmaThemeImage . 'b_edit.png"'
227 .' alt="" width="16" height="16" />';
229 echo $strDBRename . ':';
232 <input type
="text" name
="newname" size
="30" class="textfield" value
="" />
233 <input type
="submit" value
="<?php echo $strGo; ?>" />
242 <form method
="post" action
="db_operations.php"
243 onsubmit
="return emptyFormElements(this, 'newname')">
245 if (isset($db_collation)) {
246 echo '<input type="hidden" name="db_collation" value="' . $db_collation
249 echo '<input type="hidden" name="db_copy" value="true" />' . "\n";
250 echo PMA_generate_common_hidden_inputs($db);
255 if ($cfg['PropertiesIconic']) {
256 echo '<img class="icon" src="' . $pmaThemeImage . 'b_edit.png"'
257 .' alt="" width="16" height="16" />';
259 echo $strDBCopy . ':';
260 if (PMA_MYSQL_INT_VERSION
>= 50000) {
261 $drop_clause = 'DROP TABLE / DROP VIEW';
263 $drop_clause = 'DROP TABLE';
267 <input type
="text" name
="newname" size
="30" class="textfield" value
="" /><br
/>
268 <input type
="radio" name
="what" value
="structure"
269 id
="radio_copy_structure" style
="vertical-align: middle" />
270 <label
for="radio_copy_structure"><?php
echo $strStrucOnly; ?
></label
><br
/>
271 <input type
="radio" name
="what" value
="data" id
="radio_copy_data"
272 checked
="checked" style
="vertical-align: middle" />
273 <label
for="radio_copy_data"><?php
echo $strStrucData; ?
></label
><br
/>
274 <input type
="radio" name
="what" value
="dataonly"
275 id
="radio_copy_dataonly" style
="vertical-align: middle" />
276 <label
for="radio_copy_dataonly"><?php
echo $strDataOnly; ?
></label
><br
/>
278 <input type
="checkbox" name
="create_database_before_copying" value
="1"
279 id
="checkbox_create_database_before_copying"
280 style
="vertical-align: middle" checked
="checked" />
281 <label
for="checkbox_create_database_before_copying">
282 <?php
echo $strCreateDatabaseBeforeCopying; ?
></label
><br
/>
283 <input type
="checkbox" name
="drop_if_exists" value
="true"
284 id
="checkbox_drop" style
="vertical-align: middle" />
285 <label
for="checkbox_drop"><?php
echo sprintf($strAddClause, $drop_clause); ?
></label
><br
/>
286 <input type
="checkbox" name
="sql_auto_increment" value
="1"
287 id
="checkbox_auto_increment" style
="vertical-align: middle" />
288 <label
for="checkbox_auto_increment">
289 <?php
echo $strAddAutoIncrement; ?
></label
><br
/>
290 <input type
="checkbox" name
="add_constraints" value
="1"
291 id
="checkbox_constraints" style
="vertical-align: middle" />
292 <label
for="checkbox_constraints">
293 <?php
echo $strAddConstraints; ?
></label
><br
/>
297 if (isset($_COOKIE) && isset($_COOKIE['pma_switch_to_new'])
298 && $_COOKIE['pma_switch_to_new'] == 'true') {
299 $pma_switch_to_new = 'true';
302 <input type
="checkbox" name
="switch_to_new" value
="true"
304 <?php
echo ((isset($pma_switch_to_new) && $pma_switch_to_new == 'true') ?
' checked="checked"' : ''); ?
>
305 style
="vertical-align: middle" />
306 <label
for="checkbox_switch"><?php
echo $strSwitchToDatabase; ?
></label
>
308 <fieldset
class="tblFooters">
309 <input type
="submit" name
="submit_copy" value
="<?php echo $strGo; ?>" />
315 * Change database charset
317 if (PMA_MYSQL_INT_VERSION
>= 40101) {
318 // MySQL supports setting default charsets / collations for databases since
320 echo '<form method="post" action="./db_operations.php">' . "\n"
321 . PMA_generate_common_hidden_inputs($db, isset($table) ?
$table : '')
322 . '<fieldset>' . "\n"
324 if ($cfg['PropertiesIconic']) {
325 echo '<img class="icon" src="' . $pmaThemeImage . 's_asci.png"'
326 .' alt="" width="16" height="16" />';
328 echo ' <label for="select_db_collation">' . $strCollation . ':</label>' . "\n"
329 . ' </legend>' . "\n"
330 . PMA_generateCharsetDropdownBox(PMA_CSDROPDOWN_COLLATION
,
331 'db_collation', 'select_db_collation', $db_collation, false, 3)
332 . ' <input type="submit" name="submitcollation"'
333 . ' value="' . $strGo . '" style="vertical-align: middle" />' . "\n"
334 . '</fieldset>' . "\n"
339 && !$cfgRelation['allworks'] && $cfg['PmaNoRelation_DisableWarning'] == false) {
340 echo '<div class="error"><h1>' . $strError . '</h1>'
341 . sprintf($strRelationNotWorking,
342 '<a href="' . $cfg['PmaAbsoluteUri'] . 'chk_rel.php?' . $url_query . '">',
346 } // end if (!$is_information_schema)
349 // not sure about leaving the PDF dialog for information_schema
350 if ($num_tables > 0 && isset($table)) {
351 $takeaway = $url_query . '&table=' . urlencode($table);
356 if ($cfgRelation['pdfwork'] && $num_tables > 0) { ?
>
357 <!-- Work on PDF Pages
-->
360 // We only show this if we find something in the new pdf_pages table
364 FROM ' . PMA_backquote($GLOBALS['cfgRelation']['db']) . '.' . PMA_backquote($cfgRelation['pdf_pages']) . '
365 WHERE db_name = \'' . PMA_sqlAddslashes($db) . '\'';
366 $test_rs = PMA_query_as_cu($test_query, null, PMA_DBI_QUERY_STORE
);
368 if ($test_rs && PMA_DBI_num_rows($test_rs) > 0) { ?
>
370 <form method
="post" action
="pdf_schema.php">
374 echo PMA_generate_common_hidden_inputs($db);
375 if ($cfg['PropertiesIconic']) {
376 echo '<img class="icon" src="' . $pmaThemeImage . 'b_view.png"'
377 .' alt="" width="16" height="16" />';
382 <label
for="pdf_page_number_opt"><?php
echo $strPageNumber; ?
></label
>
383 <select name
="pdf_page_number" id
="pdf_page_number_opt">
385 while ($pages = @PMA_DBI_fetch_assoc
($test_rs)) {
386 echo ' <option value="' . $pages['page_nr'] . '">'
387 . $pages['page_nr'] . ': ' . $pages['page_descr'] . '</option>' . "\n";
389 PMA_DBI_free_result($test_rs);
394 <input type
="checkbox" name
="show_grid" id
="show_grid_opt" />
395 <label
for="show_grid_opt"><?php
echo $strShowGrid; ?
></label
><br
/>
396 <input type
="checkbox" name
="show_color" id
="show_color_opt"
398 <label
for="show_color_opt"><?php
echo $strShowColor; ?
></label
><br
/>
399 <input type
="checkbox" name
="show_table_dimension" id
="show_table_dim_opt" />
400 <label
for="show_table_dim_opt"><?php
echo $strShowTableDimension; ?
>
402 <input type
="checkbox" name
="all_tab_same_wide" id
="all_tab_same_wide" />
403 <label
for="all_tab_same_wide"><?php
echo $strAllTableSameWidth; ?
>
405 <input type
="checkbox" name
="with_doc" id
="with_doc" checked
="checked" />
406 <label
for="with_doc"><?php
echo $strDataDict; ?
></label
><br
/>
408 <label
for="orientation_opt"><?php
echo $strShowDatadictAs; ?
></label
>
409 <select name
="orientation" id
="orientation_opt">
410 <option value
="L"><?php
echo $strLandscape;?
></option
>
411 <option value
="P"><?php
echo $strPortrait;?
></option
>
414 <label
for="paper_opt"><?php
echo $strPaperSize; ?
></label
>
415 <select name
="paper" id
="paper_opt">
417 foreach ($cfg['PDFPageSizes'] AS $key => $val) {
418 echo '<option value="' . $val . '"';
419 if ($val == $cfg['PDFDefaultPageSize']) {
420 echo ' selected="selected"';
422 echo ' >' . $val . '</option>' . "\n";
427 <fieldset
class="tblFooters">
428 <input type
="submit" value
="<?php echo $strGo; ?>" />
437 echo '<a href="pdf_pages.php?' . $takeaway . '">';
438 if ($cfg['PropertiesIconic']) {
439 echo '<img class="icon" src="' . $pmaThemeImage . 'b_edit.png"'
440 .' alt="" width="16" height="16" />';
442 echo $strEditPDFPages . '</a>';
450 && $cfgRelation['relwork'] && $cfgRelation['commwork']
451 && isset($cfg['docSQLDir']) && !empty($cfg['docSQLDir'])) {
453 * import docSQL files
456 .'<li><a href="db_details_importdocsql.php?' . $takeaway . '">' . "\n";
457 if ($cfg['PropertiesIconic']) {
458 echo '<img class="icon" src="' . $pmaThemeImage . 'b_docsql.png"'
459 .' alt="" width="16" height="16" />';
461 echo $strImportDocSQL . '</a></li>' . "\n"
466 * Displays the footer
468 require_once './libraries/footer.inc.php';