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;
39 (isset($create_database_before_copying) && $create_database_before_copying)) {
40 $local_query = 'CREATE DATABASE ' . PMA_backquote($newname);
41 if (isset($db_collation)) {
42 $local_query .= ' DEFAULT' . PMA_generateCharsetQueryPart($db_collation);
45 $sql_query = $local_query;
46 PMA_DBI_query($local_query);
49 $tables_full = PMA_DBI_get_tables_full($db);
50 foreach ($tables_full as $table => $tmp) {
54 // value of $what for this table only
57 if (!isset($tables_full[$table]['Engine'])) {
58 $tables_full[$table]['Engine'] = $tables_full[$table]['Type'];
60 // do not copy the data from a Merge table
61 // note: on the calling FORM, 'data' means 'structure and data'
62 if ($tables_full[$table]['Engine'] == 'MRG_MyISAM') {
63 if ($this_what == 'data') {
64 $this_what = 'structure';
66 if ($this_what == 'dataonly') {
67 $this_what = 'nocopy';
71 if ($this_what != 'nocopy') {
72 PMA_Table
::moveCopy($db, $table, $newname, $table,
73 isset($this_what) ?
$this_what : 'data', $move);
76 $sql_query = $back . $sql_query;
80 // Duplicate the bookmarks for this db (done once for each db)
81 if ($db != $newname) {
82 $get_fields = array('user', 'label', 'query');
83 $where_fields = array('dbase' => $db);
84 $new_fields = array('dbase' => $newname);
85 PMA_Table
::duplicateInfo('bookmarkwork', 'bookmark', $get_fields,
86 $where_fields, $new_fields);
90 // cleanup pmadb stuff for this db
91 require_once './libraries/relation_cleanup.lib.php';
92 PMA_relationsCleanupDatabase($db);
94 $local_query = 'DROP DATABASE ' . PMA_backquote($db) . ';';
95 $sql_query .= "\n" . $local_query;
96 PMA_DBI_query($local_query);
97 $message = sprintf($strRenameDatabaseOK, htmlspecialchars($db),
98 htmlspecialchars($newname));
100 $message = sprintf($strCopyDatabaseOK, htmlspecialchars($db),
101 htmlspecialchars($newname));
105 /* Change database to be used */
109 if (isset($switch_to_new) && $switch_to_new == 'true') {
110 PMA_setCookie('pma_switch_to_new', 'true');
113 PMA_setCookie('pma_switch_to_new', '');
119 * Settings for relations stuff
122 require_once './libraries/relation.lib.php';
123 $cfgRelation = PMA_getRelationsParam();
126 * Check if comments were updated
127 * (must be done before displaying the menu tabs)
129 if ($cfgRelation['commwork'] && isset($db_comment) && $db_comment == 'true') {
130 PMA_SetComment($db, '', '(db_comment)', $comment);
134 * Prepares the tables list if the user where not redirected to this script
135 * because there is no table in the database ($is_info is true)
137 if (empty($is_info)) {
138 require './libraries/db_details_common.inc.php';
139 $url_query .= '&goto=db_operations.php';
141 // Gets the database structure
142 $sub_part = '_structure';
143 require './libraries/db_details_db_info.inc.php';
147 if (PMA_MYSQL_INT_VERSION
>= 40101) {
148 $db_collation = PMA_getDbCollation($db);
150 if (PMA_MYSQL_INT_VERSION
< 50002
151 ||
(PMA_MYSQL_INT_VERSION
>= 50002 && $db != 'information_schema')) {
152 $is_information_schema = false;
154 $is_information_schema = true;
157 if (!$is_information_schema) {
159 require './libraries/display_create_table.lib.php';
161 if ($cfgRelation['commwork']) {
166 <form method
="post" action
="db_operations.php">
167 <?php
echo PMA_generate_common_hidden_inputs($db); ?
>
168 <input type
="hidden" name
="db_comment" value
="true" />
172 if ($cfg['PropertiesIconic']) {
173 echo '<img class="icon" src="' . $pmaThemeImage . 'b_comment.png"'
174 .' alt="" border="0" width="16" height="16" hspace="2" align="middle" />';
177 $comment = PMA_getComments($db);
180 <input type
="text" name
="comment" class="textfield" size
="30"
182 echo (isset($comment) && is_array($comment)
183 ? htmlspecialchars(implode(' ', $comment))
185 <input type
="submit" value
="<?php echo $strGo; ?>" />
194 <form method
="post" action
="db_operations.php"
195 onsubmit
="return emptyFormElements(this, 'newname')">
196 <input type
="hidden" name
="what" value
="data" />
197 <input type
="hidden" name
="db_rename" value
="true" />
198 <?php
echo PMA_generate_common_hidden_inputs($db); ?
>
202 if ($cfg['PropertiesIconic']) {
203 echo '<img class="icon" src="' . $pmaThemeImage . 'b_edit.png"'
204 .' alt="" width="16" height="16" />';
206 echo $strDBRename . ':';
209 <input type
="text" name
="newname" size
="30" class="textfield" value
="" />
210 <input type
="submit" value
="<?php echo $strGo; ?>" />
219 <form method
="post" action
="db_operations.php"
220 onsubmit
="return emptyFormElements(this, 'newname')">
222 if (isset($db_collation)) {
223 echo '<input type="hidden" name="db_collation" value="' . $db_collation
226 echo '<input type="hidden" name="db_copy" value="true" />' . "\n";
227 echo PMA_generate_common_hidden_inputs($db);
232 if ($cfg['PropertiesIconic']) {
233 echo '<img class="icon" src="' . $pmaThemeImage . 'b_edit.png"'
234 .' alt="" width="16" height="16" />';
236 echo $strDBCopy . ':';
239 <input type
="text" name
="newname" size
="30" class="textfield" value
="" /><br
/>
240 <input type
="radio" name
="what" value
="structure"
241 id
="radio_copy_structure" style
="vertical-align: middle" />
242 <label
for="radio_copy_structure"><?php
echo $strStrucOnly; ?
></label
><br
/>
243 <input type
="radio" name
="what" value
="data" id
="radio_copy_data"
244 checked
="checked" style
="vertical-align: middle" />
245 <label
for="radio_copy_data"><?php
echo $strStrucData; ?
></label
><br
/>
246 <input type
="radio" name
="what" value
="dataonly"
247 id
="radio_copy_dataonly" style
="vertical-align: middle" />
248 <label
for="radio_copy_dataonly"><?php
echo $strDataOnly; ?
></label
><br
/>
250 <input type
="checkbox" name
="create_database_before_copying" value
="1"
251 id
="checkbox_create_database_before_copying"
252 style
="vertical-align: middle" checked
="checked" />
253 <label
for="checkbox_create_database_before_copying">
254 <?php
echo $strCreateDatabaseBeforeCopying; ?
></label
><br
/>
255 <input type
="checkbox" name
="drop_if_exists" value
="true"
256 id
="checkbox_drop" style
="vertical-align: middle" />
257 <label
for="checkbox_drop"><?php
echo $strStrucDrop; ?
></label
><br
/>
258 <input type
="checkbox" name
="sql_auto_increment" value
="1"
259 id
="checkbox_auto_increment" style
="vertical-align: middle" />
260 <label
for="checkbox_auto_increment">
261 <?php
echo $strAddAutoIncrement; ?
></label
><br
/>
262 <input type
="checkbox" name
="constraints" value
="1"
263 id
="checkbox_constraints" style
="vertical-align: middle" />
264 <label
for="checkbox_constraints">
265 <?php
echo $strAddConstraints; ?
></label
><br
/>
267 if (isset($_COOKIE) && isset($_COOKIE['pma_switch_to_new'])
268 && $_COOKIE['pma_switch_to_new'] == 'true') {
269 $pma_switch_to_new = 'true';
272 <input type
="checkbox" name
="switch_to_new" value
="true"
274 <?php
echo ((isset($pma_switch_to_new) && $pma_switch_to_new == 'true') ?
' checked="checked"' : ''); ?
>
275 style
="vertical-align: middle" />
276 <label
for="checkbox_switch"><?php
echo $strSwitchToDatabase; ?
></label
>
278 <fieldset
class="tblFooters">
279 <input type
="submit" name
="submit_copy" value
="<?php echo $strGo; ?>" />
285 * Change database charset
287 if (PMA_MYSQL_INT_VERSION
>= 40101) {
288 // MySQL supports setting default charsets / collations for databases since
290 echo '<form method="post" action="./db_operations.php">' . "\n"
291 . PMA_generate_common_hidden_inputs($db, $table)
292 . '<fieldset>' . "\n"
294 if ($cfg['PropertiesIconic']) {
295 echo '<img class="icon" src="' . $pmaThemeImage . 's_asci.png"'
296 .' alt="" width="16" height="16" />';
298 echo ' <label for="select_db_collation">' . $strCollation . ':</label>' . "\n"
299 . ' </legend>' . "\n"
300 . PMA_generateCharsetDropdownBox(PMA_CSDROPDOWN_COLLATION
,
301 'db_collation', 'select_db_collation', $db_collation, false, 3)
302 . ' <input type="submit" name="submitcollation"'
303 . ' value="' . $strGo . '" style="vertical-align: middle" />' . "\n"
304 . '</fieldset>' . "\n"
309 && !$cfgRelation['allworks'] && $cfg['PmaNoRelation_DisableWarning'] == false) {
310 echo '<div class="error"><h1>' . $strError . '</h1>'
311 . sprintf($strRelationNotWorking,
312 '<a href="' . $cfg['PmaAbsoluteUri'] . 'chk_rel.php?' . $url_query . '">',
316 } // end if (!$is_information_schema)
319 // not sure about leaving the PDF dialog for information_schema
320 if ($num_tables > 0) {
321 $takeaway = $url_query . '&table=' . urlencode($table);
324 if ($cfgRelation['pdfwork'] && $num_tables > 0) { ?
>
325 <!-- Work on PDF Pages
-->
328 // We only show this if we find something in the new pdf_pages table
332 FROM ' . PMA_backquote($GLOBALS['cfgRelation']['db']) . '.' . PMA_backquote($cfgRelation['pdf_pages']) . '
333 WHERE db_name = \'' . PMA_sqlAddslashes($db) . '\'';
334 $test_rs = PMA_query_as_cu($test_query, null, PMA_DBI_QUERY_STORE
);
336 if ($test_rs && PMA_DBI_num_rows($test_rs) > 0) { ?
>
338 <form method
="post" action
="pdf_schema.php">
342 echo PMA_generate_common_hidden_inputs($db);
343 if ($cfg['PropertiesIconic']) {
344 echo '<img class="icon" src="' . $pmaThemeImage . 'b_view.png"'
345 .' alt="" width="16" height="16" />';
350 <label
for="pdf_page_number_opt"><?php
echo $strPageNumber; ?
></label
>
351 <select name
="pdf_page_number" id
="pdf_page_number_opt">
353 while ($pages = @PMA_DBI_fetch_assoc
($test_rs)) {
354 echo ' <option value="' . $pages['page_nr'] . '">'
355 . $pages['page_nr'] . ': ' . $pages['page_descr'] . '</option>' . "\n";
357 PMA_DBI_free_result($test_rs);
362 <input type
="checkbox" name
="show_grid" id
="show_grid_opt" />
363 <label
for="show_grid_opt"><?php
echo $strShowGrid; ?
></label
><br
/>
364 <input type
="checkbox" name
="show_color" id
="show_color_opt"
366 <label
for="show_color_opt"><?php
echo $strShowColor; ?
></label
><br
/>
367 <input type
="checkbox" name
="show_table_dimension" id
="show_table_dim_opt" />
368 <label
for="show_table_dim_opt"><?php
echo $strShowTableDimension; ?
>
370 <input type
="checkbox" name
="all_tab_same_wide" id
="all_tab_same_wide" />
371 <label
for="all_tab_same_wide"><?php
echo $strAllTableSameWidth; ?
>
373 <input type
="checkbox" name
="with_doc" id
="with_doc" checked
="checked" />
374 <label
for="with_doc"><?php
echo $strDataDict; ?
></label
><br
/>
376 <label
for="orientation_opt"><?php
echo $strShowDatadictAs; ?
></label
>
377 <select name
="orientation" id
="orientation_opt">
378 <option value
="L"><?php
echo $strLandscape;?
></option
>
379 <option value
="P"><?php
echo $strPortrait;?
></option
>
382 <label
for="paper_opt"><?php
echo $strPaperSize; ?
></label
>
383 <select name
="paper" id
="paper_opt">
385 foreach ($cfg['PDFPageSizes'] AS $key => $val) {
386 echo '<option value="' . $val . '"';
387 if ($val == $cfg['PDFDefaultPageSize']) {
388 echo ' selected="selected"';
390 echo ' >' . $val . '</option>' . "\n";
395 <fieldset
class="tblFooters">
396 <input type
="submit" value
="<?php echo $strGo; ?>" />
405 echo '<a href="pdf_pages.php?' . $takeaway . '">';
406 if ($cfg['PropertiesIconic']) {
407 echo '<img class="icon" src="' . $pmaThemeImage . 'b_edit.png"'
408 .' alt="" width="16" height="16" />';
410 echo $strEditPDFPages . '</a>';
418 && $cfgRelation['relwork'] && $cfgRelation['commwork']
419 && isset($cfg['docSQLDir']) && !empty($cfg['docSQLDir'])) {
421 * import docSQL files
424 .'<li><a href="db_details_importdocsql.php?' . $takeaway . '">' . "\n";
425 if ($cfg['PropertiesIconic']) {
426 echo '<img class="icon" src="' . $pmaThemeImage . 'b_docsql.png"'
427 .' alt="" width="16" height="16" />';
429 echo $strImportDocSQL . '</a></li>' . "\n"
434 * Displays the footer
436 require_once './libraries/footer.inc.php';