| 1 |
<?php |
| 2 |
/* |
| 3 |
+----------------------------------------------------------------+ |
| 4 |
| | |
| 5 |
| WordPress 2.8 Plugin: WP-DBManager 2.50 | |
| 6 |
| Copyright (c) 2009 Lester "GaMerZ" Chan | |
| 7 |
| | |
| 8 |
| File Written By: | |
| 9 |
| - Lester "GaMerZ" Chan | |
| 10 |
| - http://lesterchan.net | |
| 11 |
| | |
| 12 |
| File Information: | |
| 13 |
| - Database Empty | |
| 14 |
| - wp-content/plugins/wp-dbmanager/database-empty.php | |
| 15 |
| | |
| 16 |
+----------------------------------------------------------------+ |
| 17 |
*/ |
| 18 |
|
| 19 |
|
| 20 |
### Check Whether User Can Manage Database |
| 21 |
if(!current_user_can('manage_database')) { |
| 22 |
die('Access Denied'); |
| 23 |
} |
| 24 |
|
| 25 |
|
| 26 |
### Variables Variables Variables |
| 27 |
$base_name = plugin_basename('wp-dbmanager/database-manager.php'); |
| 28 |
$base_page = 'admin.php?page='.$base_name; |
| 29 |
$backup = array(); |
| 30 |
$backup_options = get_option('dbmanager_options'); |
| 31 |
$backup['date'] = current_time('timestamp'); |
| 32 |
$backup['mysqldumppath'] = $backup_options['mysqldumppath']; |
| 33 |
$backup['mysqlpath'] = $backup_options['mysqlpath']; |
| 34 |
$backup['path'] = $backup_options['path']; |
| 35 |
|
| 36 |
|
| 37 |
### Form Processing |
| 38 |
if($_POST['do']) { |
| 39 |
// Lets Prepare The Variables |
| 40 |
$emptydrop = $_POST['emptydrop']; |
| 41 |
|
| 42 |
// Decide What To Do |
| 43 |
switch($_POST['do']) { |
| 44 |
case __('Empty/Drop', 'wp-dbmanager'): |
| 45 |
$empty_tables = array(); |
| 46 |
if(!empty($emptydrop)) { |
| 47 |
foreach($emptydrop as $key => $value) { |
| 48 |
if($value == 'empty') { |
| 49 |
$empty_tables[] = $key; |
| 50 |
} elseif($value == 'drop') { |
| 51 |
$drop_tables .= ', '.$key; |
| 52 |
} |
| 53 |
} |
| 54 |
} else { |
| 55 |
$text = '<font color="red">'.__('No Tables Selected.', 'wp-dbmanager').'</font>'; |
| 56 |
} |
| 57 |
$drop_tables = substr($drop_tables, 2); |
| 58 |
if(!empty($empty_tables)) { |
| 59 |
foreach($empty_tables as $empty_table) { |
| 60 |
$empty_query = $wpdb->query("TRUNCATE $empty_table"); |
| 61 |
$text .= '<font color="green">'.sprintf(__('Table \'%s\' Emptied', 'wp-dbmanager'), $empty_table).'</font><br />'; |
| 62 |
} |
| 63 |
} |
| 64 |
if(!empty($drop_tables)) { |
| 65 |
$drop_query = $wpdb->query("DROP TABLE $drop_tables"); |
| 66 |
$text = '<font color="green">'.sprintf(__('Table(s) \'%s\' Dropped', 'wp-dbmanager'), $drop_tables).'</font>'; |
| 67 |
} |
| 68 |
break; |
| 69 |
} |
| 70 |
} |
| 71 |
|
| 72 |
|
| 73 |
### Show Tables |
| 74 |
$tables = $wpdb->get_col("SHOW TABLES"); |
| 75 |
?> |
| 76 |
<?php if(!empty($text)) { echo '<!-- Last Action --><div id="message" class="updated fade"><p>'.$text.'</p></div>'; } ?> |
| 77 |
<!-- Empty/Drop Tables --> |
| 78 |
<form method="post" action="<?php echo $_SERVER['PHP_SELF']; ?>?page=<?php echo plugin_basename(__FILE__); ?>"> |
| 79 |
<div class="wrap"> |
| 80 |
<div id="icon-wp-dbmanager" class="icon32"><br /></div> |
| 81 |
<h2><?php _e('Empty/Drop Tables', 'wp-dbmanager'); ?></h2> |
| 82 |
<br style="clear" /> |
| 83 |
<table class="widefat"> |
| 84 |
<thead> |
| 85 |
<tr> |
| 86 |
<th><?php _e('Tables', 'wp-dbmanager'); ?></th> |
| 87 |
<th><?php _e('Empty', 'wp-dbmanager'); ?> <sup><?php _e('1', 'wp-dbmanager'); ?></sup></th> |
| 88 |
<th><?php _e('Drop', 'wp-dbmanager'); ?> <sup><?php _e('2', 'wp-dbmanager'); ?></sup></th> |
| 89 |
</tr> |
| 90 |
</thead> |
| 91 |
<?php |
| 92 |
foreach($tables as $table_name) { |
| 93 |
if($no%2 == 0) { |
| 94 |
$style = ''; |
| 95 |
} else { |
| 96 |
$style = ' class="alternate"'; |
| 97 |
} |
| 98 |
$no++; |
| 99 |
echo "<tr $style><th align=\"left\" scope=\"row\">$table_name</th>\n"; |
| 100 |
echo "<td><input type=\"radio\" id=\"$table_name-empty\" name=\"emptydrop[$table_name]\" value=\"empty\" /> <label for=\"$table_name-empty\">".__('Empty', 'wp-dbmanager').'</label></td>'; |
| 101 |
echo "<td><input type=\"radio\" id=\"$table_name-drop\" name=\"emptydrop[$table_name]\" value=\"drop\" /> <label for=\"$table_name-drop\">".__('Drop', 'wp-dbmanager').'</label></td></tr>'; |
| 102 |
} |
| 103 |
?> |
| 104 |
<tr> |
| 105 |
<td colspan="3"> |
| 106 |
<?php _e('1. EMPTYING a table means all the rows in the table will be deleted. This action is not REVERSIBLE.', 'wp-dbmanager'); ?> |
| 107 |
<br /> |
| 108 |
<?php _e('2. DROPPING a table means deleting the table. This action is not REVERSIBLE.', 'wp-dbmanager'); ?> |
| 109 |
</td> |
| 110 |
</tr> |
| 111 |
<tr> |
| 112 |
<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'); ?>')" /> <input type="button" name="cancel" value="<?php _e('Cancel', 'wp-dbmanager'); ?>" class="button" onclick="javascript:history.go(-1)" /></td> |
| 113 |
</tr> |
| 114 |
</table> |
| 115 |
</div> |
| 116 |
</form> |