PluginProbe
WP-DBManager / 2.80.9
WP-DBManager v2.80.9
4.0.0 trunk 1.00 2.00 2.01 2.02 2.03 2.04 2.05 2.10 2.11 2.20 2.30 2.31 2.40 2.50 2.65 2.70 2.71 2.72 2.73 2.74 2.75 2.76 2.78 All 40 releases
wp-dbmanager / database-empty.php

database-empty.php in WP-DBManager 2.80.9, at database-empty.php

102 lines 3.9 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 ### Check Whether User Can Manage Database
3 if ( ! current_user_can( 'install_plugins' ) ) {
4 die( 'Access Denied' );
5 }
6
7
8 ### Variables Variables Variables
9 $base_name = plugin_basename('wp-dbmanager/database-manager.php');
10 $base_page = 'admin.php?page='.$base_name;
11 $backup = array();
12 $backup_options = get_option('dbmanager_options');
13 $backup['date'] = current_time('timestamp');
14 $backup['mysqldumppath'] = $backup_options['mysqldumppath'];
15 $backup['mysqlpath'] = $backup_options['mysqlpath'];
16 $backup['path'] = $backup_options['path'];
17
18
19 ### Form Processing
20 if(!empty($_POST['do'])) {
21 // Lets Prepare The Variables
22 $emptydrop = (!empty($_POST['emptydrop']) ? $_POST['emptydrop'] : array());
23 $text = '';
24
25 // Decide What To Do
26 switch($_POST['do']) {
27 case __('Empty/Drop', 'wp-dbmanager'):
28 check_admin_referer('wp-dbmanager_empty');
29 $empty_tables = array();
30 $drop_tables = '';
31 if(!empty($emptydrop)) {
32 foreach($emptydrop as $key => $value) {
33 if($value == 'empty') {
34 $empty_tables[] = $key;
35 } elseif($value == 'drop') {
36 $drop_tables .= ', '.$key;
37 }
38 }
39 } else {
40 $text = '<p style="color: red;">'.__('No Tables Selected.', 'wp-dbmanager').'</p>';
41 }
42 $drop_tables = substr($drop_tables, 2);
43 if(!empty($empty_tables)) {
44 foreach($empty_tables as $empty_table) {
45 $empty_query = $wpdb->query("TRUNCATE $empty_table");
46 $text .= '<p style="color: green;">'.sprintf(__('Table \'%s\' Emptied', 'wp-dbmanager'), $empty_table).'</p>';
47 }
48 }
49 if(!empty($drop_tables)) {
50 $drop_query = $wpdb->query("DROP TABLE $drop_tables");
51 $text = '<p style="color: green;">'.sprintf(__('Table(s) \'%s\' Dropped', 'wp-dbmanager'), $drop_tables).'</p>';
52 }
53 break;
54 }
55 }
56
57
58 ### Show Tables
59 $tables = $wpdb->get_col("SHOW TABLES");
60 ?>
61 <?php if(!empty($text)) { echo '<!-- Last Action --><div id="message" class="updated fade"><p>'.$text.'</p></div>'; } ?>
62 <!-- Empty/Drop Tables -->
63 <form method="post" action="<?php echo admin_url('admin.php?page='.plugin_basename(__FILE__)); ?>">
64 <?php wp_nonce_field('wp-dbmanager_empty'); ?>
65 <div class="wrap">
66 <h2><?php _e('Empty/Drop Tables', 'wp-dbmanager'); ?></h2>
67 <br style="clear" />
68 <table class="widefat">
69 <thead>
70 <tr>
71 <th><?php _e('Tables', 'wp-dbmanager'); ?></th>
72 <th><?php _e('Empty', 'wp-dbmanager'); ?> <sup><?php _e('1', 'wp-dbmanager'); ?></sup></th>
73 <th><?php _e('Drop', 'wp-dbmanager'); ?> <sup><?php _e('2', 'wp-dbmanager'); ?></sup></th>
74 </tr>
75 </thead>
76 <?php
77 $no = 0;
78 foreach($tables as $table_name) {
79 if($no%2 == 0) {
80 $style = '';
81 } else {
82 $style = ' class="alternate"';
83 }
84 $no++;
85 echo "<tr $style><th align=\"left\" scope=\"row\">$table_name</th>\n";
86 echo "<td><input type=\"radio\" id=\"$table_name-empty\" name=\"emptydrop[$table_name]\" value=\"empty\" />&nbsp;<label for=\"$table_name-empty\">".__('Empty', 'wp-dbmanager').'</label></td>';
87 echo "<td><input type=\"radio\" id=\"$table_name-drop\" name=\"emptydrop[$table_name]\" value=\"drop\" />&nbsp;<label for=\"$table_name-drop\">".__('Drop', 'wp-dbmanager').'</label></td></tr>';
88 }
89 ?>
90 <tr>
91 <td colspan="3">
92 <?php _e('1. EMPTYING a table means all the rows in the table will be deleted. This action is not REVERSIBLE.', 'wp-dbmanager'); ?>
93 <br />
94 <?php _e('2. DROPPING a table means deleting the table. This action is not REVERSIBLE.', 'wp-dbmanager'); ?>
95 </td>
96 </tr>
97 <tr>
98 <td colspan="3" align="center"><input type="submit" name="do" value="<?php _e('Empty/Drop', 'wp-dbmanager'); ?>" class="button" onclick="return confirm('<?php _e('You Are About To Empty Or Drop The Selected Databases.\nThis Action Is Not Reversible.\n\n Choose [Cancel] to stop, [Ok] to delete.', 'wp-dbmanager'); ?>')" />&nbsp;&nbsp;<input type="button" name="cancel" value="<?php _e('Cancel', 'wp-dbmanager'); ?>" class="button" onclick="javascript:history.go(-1)" /></td>
99 </tr>
100 </table>
101 </div>
102 </form>