sorry, wrong version checked in
[phpmyadmin/arisferyanto.git] / db_operations.php
blobcb18a83f0070c0506df207b2d734ee8fa7250cc5
1 <?php
2 /* $Id$ */
3 // vim: expandtab sw=4 ts=4 sts=4:
5 require_once('./libraries/common.lib.php');
6 require_once('./libraries/mysql_charsets.lib.php');
7 /**
8 * Rename database or Copy database
9 */
10 if (isset($db) &&
11 ((isset($db_rename) && $db_rename == 'true') ||
12 (isset($db_copy) && $db_copy == 'true'))) {
14 require_once('./libraries/tbl_move_copy.php');
16 if (isset($db_rename) && $db_rename == 'true') {
17 $move = TRUE;
18 } else {
19 $move = FALSE;
22 if (!isset($newname) || empty($newname)) {
23 $message = $strDatabaseEmpty;
24 } else {
25 if ($move ||
26 (isset($create_database_before_copying) && $create_database_before_copying)) {
27 $local_query = 'CREATE DATABASE ' . PMA_backquote($newname);
28 if (isset($db_collation)) {
29 $local_query .= ' DEFAULT' . PMA_generateCharsetQueryPart($db_collation);
31 $local_query .= ';';
32 $sql_query = $local_query;
33 PMA_DBI_query($local_query);
36 $tables_full = PMA_DBI_get_tables_full($db);
37 foreach ($tables_full as $table => $tmp) {
38 $back = $sql_query;
39 $sql_query = '';
41 // value of $what for this table only
42 $this_what = $what;
44 if (!isset($tables_full[$table]['Engine'])) {
45 $tables_full[$table]['Engine'] = $tables_full[$table]['Type'];
47 // do not copy the data from a Merge table
48 // note: on the calling FORM, 'data' means 'structure and data'
49 if ($tables_full[$table]['Engine'] == 'MRG_MyISAM') {
50 if ($this_what == 'data') {
51 $this_what = 'structure';
53 if ($this_what == 'dataonly') {
54 $this_what = 'nocopy';
58 if ($this_what != 'nocopy') {
59 PMA_table_move_copy($db, $table, $newname, $table, isset($this_what) ? $this_what : 'data', $move);
62 $sql_query = $back . $sql_query;
64 unset($table);
66 // Duplicate the bookmarks for this db (done once for each db)
67 if ($db != $newname) {
68 $get_fields = array('user','label','query');
69 $where_fields = array('dbase' => $db);
70 $new_fields = array('dbase' => $newname);
71 PMA_duplicate_table_info('bookmarkwork', 'bookmark', $get_fields, $where_fields, $new_fields);
74 if ($move) {
75 // cleanup pmadb stuff for this db
76 require_once('./libraries/relation_cleanup.lib.php');
77 PMA_relationsCleanupDatabase($db);
79 $local_query = 'DROP DATABASE ' . PMA_backquote($db) . ';';
80 $sql_query .= "\n" . $local_query;
81 PMA_DBI_query($local_query);
82 $message = sprintf($strRenameDatabaseOK, htmlspecialchars($db), htmlspecialchars($newname));
83 } else {
84 $message = sprintf($strCopyDatabaseOK, htmlspecialchars($db), htmlspecialchars($newname));
86 $reload = TRUE;
88 /* Change database to be used */
89 if ($move) {
90 $db = $newname;
91 } else {
92 $pma_uri_parts = parse_url($cfg['PmaAbsoluteUri']);
93 if (isset($switch_to_new) && $switch_to_new == 'true') {
94 setcookie('pma_switch_to_new', 'true', 0, $GLOBALS['cookie_path'], '' , $GLOBALS['is_https']);
95 $db = $newname;
96 } else {
97 setcookie('pma_switch_to_new', '', 0, $GLOBALS['cookie_path'], '' , $GLOBALS['is_https']);
103 * Settings for relations stuff
106 require_once('./libraries/relation.lib.php');
107 $cfgRelation = PMA_getRelationsParam();
110 * Check if comments were updated
111 * (must be done before displaying the menu tabs)
113 if ($cfgRelation['commwork'] && isset($db_comment) && $db_comment == 'true') {
114 PMA_SetComment($db, '', '(db_comment)', $comment);
118 * Prepares the tables list if the user where not redirected to this script
119 * because there is no table in the database ($is_info is TRUE)
121 if (empty($is_info)) {
122 require('./db_details_common.php');
123 $url_query .= '&amp;goto=db_operations.php';
125 // Gets the database structure
126 $sub_part = '_structure';
127 require('./db_details_db_info.php');
128 echo "\n";
131 if (PMA_MYSQL_INT_VERSION >= 40101) {
132 $db_collation = PMA_getDbCollation($db);
134 if (PMA_MYSQL_INT_VERSION < 50002 || (PMA_MYSQL_INT_VERSION >= 50002 && $db != 'information_schema')) {
135 $is_information_schema = FALSE;
136 } else {
137 $is_information_schema = TRUE;
140 if (!$is_information_schema) {
142 require('./libraries/display_create_table.lib.php');
144 echo '<table border="0" cellpadding="2" cellspacing="0">';
145 if ($cfgRelation['commwork']) {
147 <!-- Alter/Enter db-comment -->
148 <tr><td colspan="3"><img src="<?php echo $GLOBALS['pmaThemeImage'] . 'spacer.png'; ?>" width="1" height="1" border="0" alt="" /></td></tr>
150 <tr>
151 <td colspan="3" class="tblHeaders"><?php
152 if ($cfg['PropertiesIconic']) {
153 echo '<img src="' . $pmaThemeImage . 'b_comment.png" border="0" width="16" height="16" hspace="2" align="middle" />';
155 echo $strDBComment;
156 $comment = PMA_getComments($db);
157 ?></td></tr>
158 <form method="post" action="db_operations.php">
159 <tr bgcolor="<?php echo $cfg['BgcolorOne']; ?>">
160 <td colspan="2" nowrap="nowrap">
161 <input type="hidden" name="db_comment" value="true" />
162 <?php echo PMA_generate_common_hidden_inputs($db); ?>
163 <input type="text" name="comment" class="textfield" size="30" value="<?php echo (isset($comment) && is_array($comment) ? htmlspecialchars(implode(' ', $comment)) : ''); ?>" /></td><td align="right">
164 <input type="submit" value="<?php echo $strGo; ?>" />
165 </td></tr>
166 </form>
167 <?php
170 <!-- Rename database -->
171 <tr><td colspan="3"><img src="<?php echo $GLOBALS['pmaThemeImage'] . 'spacer.png'; ?>" width="1" height="1" border="0" alt="" /></td></tr>
172 <tr><td colspan="3" class="tblHeaders"><?php
173 if ($cfg['PropertiesIconic']) {
174 echo '<img src="' . $pmaThemeImage . 'b_edit.png" border="0" width="16" height="16" hspace="2" align="middle" />';
176 echo $strDBRename.':&nbsp;';
177 ?></td></tr>
178 <form method="post" action="db_operations.php"
179 onsubmit="return emptyFormElements(this, 'newname')">
180 <tr bgcolor="<?php echo $cfg['BgcolorOne']; ?>"><td colspan="2"><?php
181 echo '<input type="hidden" name="what" value="data" />';
182 echo '<input type="hidden" name="db_rename" value="true" />'
183 . PMA_generate_common_hidden_inputs($db);
184 ?><input type="text" name="newname" size="30" class="textfield" value="" /></td>
185 <td align="right"><input type="submit" value="<?php echo $strGo; ?>" /></td>
186 </form></tr>
188 <!-- Copy database -->
189 <tr><td colspan="3"><img src="<?php echo $GLOBALS['pmaThemeImage'] . 'spacer.png'; ?>" width="1" height="1" border="0" alt="" /></td></tr>
190 <tr><td colspan="3" class="tblHeaders"><?php
191 if ($cfg['PropertiesIconic']) {
192 echo '<img src="' . $pmaThemeImage . 'b_edit.png" border="0" width="16" height="16" hspace="2" align="middle" />';
194 echo $strDBCopy.':&nbsp;';
195 ?></td></tr>
196 <form method="post" action="db_operations.php"
197 onsubmit="return emptyFormElements(this, 'newname')">
198 <tr bgcolor="<?php echo $cfg['BgcolorOne']; ?>"><td colspan="3">
199 <?php
200 if (isset($db_collation)) {
201 echo '<input type="hidden" name="db_collation" value="' . $db_collation .'" />' . "\n";
203 echo '<input type="hidden" name="db_copy" value="true" />' . "\n"
204 . PMA_generate_common_hidden_inputs($db);
205 ?><input type="text" name="newname" size="30" class="textfield" value="" /></td>
206 </tr><tr>
207 <td nowrap="nowrap" bgcolor="<?php echo $cfg['BgcolorOne']; ?>" colspan="2">
208 <input type="radio" name="what" value="structure" id="radio_copy_structure" style="vertical-align: middle" /><label for="radio_copy_structure"><?php echo $strStrucOnly; ?></label>&nbsp;&nbsp;<br />
209 <input type="radio" name="what" value="data" id="radio_copy_data" checked="checked" style="vertical-align: middle" /><label for="radio_copy_data"><?php echo $strStrucData; ?></label>&nbsp;&nbsp;<br />
210 <input type="radio" name="what" value="dataonly" id="radio_copy_dataonly" style="vertical-align: middle" /><label for="radio_copy_dataonly"><?php echo $strDataOnly; ?></label>&nbsp;&nbsp;<br />
213 <input type="checkbox" name="create_database_before_copying" value="1" id="checkbox_create_database_before_copying" style="vertical-align: middle" checked="checked" /><label for="checkbox_create_database_before_copying"><?php echo $strCreateDatabaseBeforeCopying; ?></label><br />
214 <input type="checkbox" name="drop_if_exists" value="true" id="checkbox_drop" style="vertical-align: middle" /><label for="checkbox_drop"><?php echo $strStrucDrop; ?></label>&nbsp;&nbsp;<br />
215 <input type="checkbox" name="sql_auto_increment" value="1" id="checkbox_auto_increment" style="vertical-align: middle" /><label for="checkbox_auto_increment"><?php echo $strAddAutoIncrement; ?></label><br />
216 <input type="checkbox" name="constraints" value="1" id="checkbox_constraints" style="vertical-align: middle" /><label for="checkbox_constraints"><?php echo $strAddConstraints; ?></label><br />
217 <?php
218 if (isset($_COOKIE) && isset($_COOKIE['pma_switch_to_new']) && $_COOKIE['pma_switch_to_new'] == 'true') {
219 $pma_switch_to_new = 'true';
222 <input type="checkbox" name="switch_to_new" value="true" id="checkbox_switch"<?php echo ((isset($pma_switch_to_new) && $pma_switch_to_new == 'true') ? ' checked="checked"' : ''); ?> style="vertical-align: middle" /><label for="checkbox_switch"><?php echo $strSwitchToDatabase; ?></label>&nbsp;&nbsp;
223 </td>
224 <td align="<?php echo $cell_align_right; ?>" valign="bottom" bgcolor="<?php echo $cfg['BgcolorOne']; ?>">
225 <input type="submit" name="submit_copy" value="<?php echo $strGo; ?>" />
226 </td>
227 </tr>
228 </form>
230 <?php
232 if (PMA_MYSQL_INT_VERSION >= 40101) {
233 // MySQL supports setting default charsets / collations for databases since
234 // version 4.1.1.
235 echo ' <!-- Change database charset -->' . "\n"
236 . ' <tr><td colspan="3"><img src="' . $GLOBALS['pmaThemeImage'] . 'spacer.png' . '" width="1" height="1" border="0" alt="" /></td></tr>' . "\n"
237 . ' <tr><td colspan="3" class="tblHeaders">';
238 if ($cfg['PropertiesIconic']) {
239 echo '<img src="' . $pmaThemeImage . 's_asci.png" border="0" width="16" height="16" hspace="2" align="middle" />';
241 echo ' <label for="select_db_collation">' . $strCollation . '</label>:&nbsp;' . "\n"
242 . ' </td></tr>' . "\n"
243 . ' <form method="post" action="./db_operations.php">' . "\n"
244 . ' <tr bgcolor="' . $cfg['BgcolorOne'] . '"><td colspan="2" nowrap="nowrap">'
245 . PMA_generate_common_hidden_inputs($db, $table, 3)
246 . PMA_generateCharsetDropdownBox(PMA_CSDROPDOWN_COLLATION, 'db_collation', 'select_db_collation', $db_collation, FALSE, 3)
247 . ' </td><td align="right">'
248 . ' <input type="submit" name="submitcollation" value="' . $strGo . '" style="vertical-align: middle" />' . "\n"
249 . ' </td></tr>' . "\n"
250 . ' </form>' . "\n"
251 . ' ' . "\n\n";
254 echo '</table>';
256 if ( $num_tables > 0
257 && !$cfgRelation['allworks'] && $cfg['PmaNoRelation_DisableWarning'] == FALSE) {
258 echo '<div class="error"><h1>' . $strError . '</h1>'
259 . sprintf( $strRelationNotWorking, '<a href="' . $cfg['PmaAbsoluteUri'] . 'chk_rel.php?' . $url_query . '">', '</a>')
260 . '</div>';
261 } // end if
262 } // end if (!$is_information_schema)
263 // not sure about leaving the PDF dialog for information_schema
266 <form method="post" action="pdf_schema.php">
267 <?php
269 if ($num_tables > 0) {
270 $takeaway = $url_query . '&amp;table=' . urlencode($table);
273 if (($cfgRelation['pdfwork'] && $num_tables > 0) ||
274 ($num_tables > 0
275 && $cfgRelation['relwork'] && $cfgRelation['commwork']
276 && isset($cfg['docSQLDir']) && !empty($cfg['docSQLDir'])
277 )) { ?>
278 <hr /><table border="0" cellpadding="2" cellspacing="0">
279 <?php
282 if ($cfgRelation['pdfwork'] && $num_tables > 0) { ?>
283 <!-- Work on PDF Pages -->
284 <tr>
285 <td colspan="3" class="tblHeaders">
286 <?php
287 if ($cfg['PropertiesIconic']) {
288 echo '<img src="' . $pmaThemeImage . 'b_pdfdoc.png" border="0" width="16" height="16" hspace="2" align="middle" />';
289 } ?>PDF</td>
290 </tr>
292 <tr bgcolor="<?php echo $cfg['BgcolorOne']; ?>">
293 <td colspan="3">
294 <?php
295 echo '<a href="pdf_pages.php?' . $takeaway . '">';
296 if ($cfg['PropertiesIconic']) {
297 echo '<img src="' . $pmaThemeImage . 'b_edit.png" border="0" width="16" height="16" hspace="2" align="middle" />';
299 echo ''. $strEditPDFPages . '</a>';
301 </td>
302 </tr>
304 <!-- PDF schema -->
305 <?php
306 // We only show this if we find something in the new pdf_pages table
308 $test_query = 'SELECT * FROM ' . PMA_backquote($cfgRelation['pdf_pages'])
309 . ' WHERE db_name = \'' . PMA_sqlAddslashes($db) . '\'';
310 $test_rs = PMA_query_as_cu($test_query, NULL, PMA_DBI_QUERY_STORE);
312 if ($test_rs && PMA_DBI_num_rows($test_rs) > 0) { ?>
313 <tr bgcolor="<?php echo $cfg['BgcolorTwo']; ?>">
314 <td colspan="3">
315 <?php
316 echo PMA_generate_common_hidden_inputs($db);
317 if ($cfg['PropertiesIconic']) {
318 echo '<img src="' . $pmaThemeImage . 'b_view.png" border="0" width="16" height="16" hspace="2" align="middle" />';
320 echo $strDisplayPDF; ?>:&nbsp;
321 </td>
322 </tr>
324 <tr bgcolor="<?php echo $cfg['BgcolorTwo']; ?>">
325 <td width="20">&nbsp;</td>
326 <td colspan="2">
327 <label for="pdf_page_number_opt"><?php echo $strPageNumber; ?></label>
328 <select name="pdf_page_number" id="pdf_page_number_opt">
329 <?php
330 while ($pages = @PMA_DBI_fetch_assoc($test_rs)) {
331 echo ' <option value="' . $pages['page_nr'] . '">' . $pages['page_nr'] . ': ' . $pages['page_descr'] . '</option>' . "\n";
332 } // end while
333 PMA_DBI_free_result($test_rs);
334 unset($test_rs);
336 </select><br />
338 <input type="checkbox" name="show_grid" id="show_grid_opt" /><label for="show_grid_opt"><?php echo $strShowGrid; ?></label><br />
339 <input type="checkbox" name="show_color" id="show_color_opt" checked="checked" /><label for="show_color_opt"><?php echo $strShowColor; ?></label><br />
340 <input type="checkbox" name="show_table_dimension" id="show_table_dim_opt" /><label for="show_table_dim_opt"><?php echo $strShowTableDimension; ?></label><br />
341 <input type="checkbox" name="all_tab_same_wide" id="all_tab_same_wide" /><label for="all_tab_same_wide"><?php echo $strAllTableSameWidth; ?></label><br />
342 <input type="checkbox" name="with_doc" id="with_doc" checked="checked" /><label for="with_doc"><?php echo $strDataDict; ?></label><br />
344 <label for="orientation_opt"><?php echo $strShowDatadictAs; ?></label>
345 <select name="orientation" id="orientation_opt">
346 <option value="L"><?php echo $strLandscape;?></option>
347 <option value="P"><?php echo $strPortrait;?></option>
348 </select><br />
350 <label for="paper_opt"><?php echo $strPaperSize; ?></label>
351 <select name="paper" id="paper_opt">
352 <?php
353 foreach ($cfg['PDFPageSizes'] AS $key => $val) {
354 echo '<option value="' . $val . '"';
355 if ($val == $cfg['PDFDefaultPageSize']) {
356 echo ' selected="selected"';
358 echo ' >' . $val . '</option>' . "\n";
361 </select>
362 </td>
363 </tr>
365 <tr bgcolor="<?php echo $cfg['BgcolorTwo']; ?>">
366 <td width="20">&nbsp;</td>
367 <td colspan="3" align="right">&nbsp;&nbsp;<input type="submit" value="<?php echo $strGo; ?>" /></td>
368 </tr>
369 <tr>
370 <td colspan="3"><img src="<?php echo $GLOBALS['pmaThemeImage'] . 'spacer.png'; ?>" width="1" height="1" border="0" alt="" /></td>
371 </tr>
372 <?php
373 } // end if
374 } // end if
376 if ($num_tables > 0
377 && $cfgRelation['relwork'] && $cfgRelation['commwork']
378 && isset($cfg['docSQLDir']) && !empty($cfg['docSQLDir'])
381 <!-- import docSQL files -->
382 <tr bgcolor="<?php echo $cfg['BgcolorOne']; ?>">
383 <td colspan="3">
384 <?php
385 echo '<a href="db_details_importdocsql.php?' . $takeaway . '">';
386 if ($cfg['PropertiesIconic']) {
387 echo '<img src="' . $pmaThemeImage . 'b_docsql.png" border="0" width="16" height="16" hspace="2" align="middle" />';
389 echo $strImportDocSQL . '</a>';
391 </td>
392 </tr>
393 <?php
395 echo "\n";
396 if (($cfgRelation['pdfwork'] && $num_tables > 0) ||
397 ($num_tables > 0
398 && $cfgRelation['relwork'] && $cfgRelation['commwork']
399 && isset($cfg['docSQLDir']) && !empty($cfg['docSQLDir'])
400 )) { ?>
401 </table>
402 </form>
403 <?php
407 * Displays the footer
409 echo "\n";
410 require_once('./footer.inc.php');