Add wrapper to show config errors even with no error reporting (RFE #1447173).
[phpmyadmin/crack.git] / db_operations.php
blob213e376740acf6e742bcee6757bceb5b74f0be58
1 <?php
2 /* $Id$ */
3 // vim: expandtab sw=4 ts=4 sts=4:
5 /**
6 * handles miscellaneous db operations:
7 * - move/rename
8 * - copy
9 * - changing collation
10 * - changing comment
11 * - adding tables
12 * - viewing PDF schemas
15 /**
16 * requirements
18 require_once './libraries/common.lib.php';
19 require_once './libraries/Table.class.php';
20 require_once './libraries/mysql_charsets.lib.php';
22 /**
23 * Rename/move or copy database
25 if (isset($db) &&
26 ((isset($db_rename) && $db_rename == 'true') ||
27 (isset($db_copy) && $db_copy == 'true'))) {
29 if (isset($db_rename) && $db_rename == 'true') {
30 $move = true;
31 } else {
32 $move = false;
35 if (!isset($newname) || !strlen($newname)) {
36 $message = $strDatabaseEmpty;
37 } else {
38 if ($move ||
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);
44 $local_query .= ';';
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) {
51 $back = $sql_query;
52 $sql_query = '';
54 // value of $what for this table only
55 $this_what = $what;
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;
78 unset($table);
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);
89 if ($move) {
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));
99 } else {
100 $message = sprintf($strCopyDatabaseOK, htmlspecialchars($db),
101 htmlspecialchars($newname));
103 $reload = true;
105 /* Change database to be used */
106 if ($move) {
107 $db = $newname;
108 } else {
109 if (isset($switch_to_new) && $switch_to_new == 'true') {
110 PMA_setCookie('pma_switch_to_new', 'true');
111 $db = $newname;
112 } else {
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 .= '&amp;goto=db_operations.php';
141 // Gets the database structure
142 $sub_part = '_structure';
143 require './libraries/db_details_db_info.inc.php';
144 echo "\n";
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;
153 } else {
154 $is_information_schema = true;
157 if (!$is_information_schema) {
159 require './libraries/display_create_table.lib.php';
161 if ($cfgRelation['commwork']) {
163 * database comment
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" />
169 <fieldset>
170 <legend>
171 <?php
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" />';
176 echo $strDBComment;
177 $comment = PMA_getComments($db);
179 </legend>
180 <input type="text" name="comment" class="textfield" size="30"
181 value="<?php
182 echo (isset($comment) && is_array($comment)
183 ? htmlspecialchars(implode(' ', $comment))
184 : ''); ?>" />
185 <input type="submit" value="<?php echo $strGo; ?>" />
186 </fieldset>
187 </form>
188 <?php
191 * rename database
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); ?>
199 <fieldset>
200 <legend>
201 <?php
202 if ($cfg['PropertiesIconic']) {
203 echo '<img class="icon" src="' . $pmaThemeImage . 'b_edit.png"'
204 .' alt="" width="16" height="16" />';
206 echo $strDBRename . ':';
208 </legend>
209 <input type="text" name="newname" size="30" class="textfield" value="" />
210 <input type="submit" value="<?php echo $strGo; ?>" />
211 </fieldset>
212 </form>
214 <?php
216 * Copy database
219 <form method="post" action="db_operations.php"
220 onsubmit="return emptyFormElements(this, 'newname')">
221 <?php
222 if (isset($db_collation)) {
223 echo '<input type="hidden" name="db_collation" value="' . $db_collation
224 .'" />' . "\n";
226 echo '<input type="hidden" name="db_copy" value="true" />' . "\n";
227 echo PMA_generate_common_hidden_inputs($db);
229 <fieldset>
230 <legend>
231 <?php
232 if ($cfg['PropertiesIconic']) {
233 echo '<img class="icon" src="' . $pmaThemeImage . 'b_edit.png"'
234 .' alt="" width="16" height="16" />';
236 echo $strDBCopy . ':';
238 </legend>
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 />
266 <?php
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"
273 id="checkbox_switch"
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>
277 </fieldset>
278 <fieldset class="tblFooters">
279 <input type="submit" name="submit_copy" value="<?php echo $strGo; ?>" />
280 </fieldset>
281 </form>
283 <?php
285 * Change database charset
287 if (PMA_MYSQL_INT_VERSION >= 40101) {
288 // MySQL supports setting default charsets / collations for databases since
289 // version 4.1.1.
290 echo '<form method="post" action="./db_operations.php">' . "\n"
291 . PMA_generate_common_hidden_inputs($db, $table)
292 . '<fieldset>' . "\n"
293 . ' <legend>';
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"
305 . '</form>' . "\n";
308 if ($num_tables > 0
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 . '">',
313 '</a>')
314 . '</div>';
315 } // end if
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 . '&amp;table=' . urlencode($table);
324 if ($cfgRelation['pdfwork'] && $num_tables > 0) { ?>
325 <!-- Work on PDF Pages -->
327 <?php
328 // We only show this if we find something in the new pdf_pages table
330 $test_query = '
331 SELECT *
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) { ?>
337 <!-- PDF schema -->
338 <form method="post" action="pdf_schema.php">
339 <fieldset>
340 <legend>
341 <?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" />';
347 echo $strDisplayPDF;
349 </legend>
350 <label for="pdf_page_number_opt"><?php echo $strPageNumber; ?></label>
351 <select name="pdf_page_number" id="pdf_page_number_opt">
352 <?php
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";
356 } // end while
357 PMA_DBI_free_result($test_rs);
358 unset($test_rs);
360 </select><br />
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"
365 checked="checked" />
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; ?>
369 </label><br />
370 <input type="checkbox" name="all_tab_same_wide" id="all_tab_same_wide" />
371 <label for="all_tab_same_wide"><?php echo $strAllTableSameWidth; ?>
372 </label><br />
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>
380 </select><br />
382 <label for="paper_opt"><?php echo $strPaperSize; ?></label>
383 <select name="paper" id="paper_opt">
384 <?php
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";
393 </select>
394 </fieldset>
395 <fieldset class="tblFooters">
396 <input type="submit" value="<?php echo $strGo; ?>" />
397 </fieldset>
398 </form>
399 <?php
400 } // end if
402 <ul>
403 <li>
404 <?php
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>';
412 </li>
413 </ul>
414 <?php
415 } // end if
417 if ($num_tables > 0
418 && $cfgRelation['relwork'] && $cfgRelation['commwork']
419 && isset($cfg['docSQLDir']) && !empty($cfg['docSQLDir'])) {
421 * import docSQL files
423 echo '<ul>' . "\n"
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"
430 .'</ul>';
434 * Displays the footer
436 require_once './libraries/footer.inc.php';