| 1 |
<?php |
| 2 |
/* |
| 3 |
+----------------------------------------------------------------+ |
| 4 |
| | |
| 5 |
| WordPress 2.0 Plugin: WP-DBManager 2.04 | |
| 6 |
| Copyright (c) 2005 Lester "GaMerZ" Chan | |
| 7 |
| | |
| 8 |
| File Written By: | |
| 9 |
| - Lester "GaMerZ" Chan | |
| 10 |
| - http://www.lesterchan.net | |
| 11 |
| | |
| 12 |
| File Information: | |
| 13 |
| - Database Empty | |
| 14 |
| - wp-content/plugins/dbmanager/database-empty.php | |
| 15 |
| | |
| 16 |
+----------------------------------------------------------------+ |
| 17 |
*/ |
| 18 |
|
| 19 |
|
| 20 |
### Require Database Config |
| 21 |
require('database-config.php'); |
| 22 |
|
| 23 |
|
| 24 |
### Form Processing |
| 25 |
if($_POST['do']) { |
| 26 |
// Lets Prepare The Variables |
| 27 |
$emptydrop = $_POST['emptydrop']; |
| 28 |
|
| 29 |
// Decide What To Do |
| 30 |
switch($_POST['do']) { |
| 31 |
case 'Empty/Drop': |
| 32 |
$empty_tables = array(); |
| 33 |
if(!empty($emptydrop)) { |
| 34 |
foreach($emptydrop as $key => $value) { |
| 35 |
if($value == 'empty') { |
| 36 |
$empty_tables[] = $key; |
| 37 |
} elseif($value == 'drop') { |
| 38 |
$drop_tables .= ', '.$key; |
| 39 |
} |
| 40 |
} |
| 41 |
} else { |
| 42 |
$text = '<font color="red">No Tables Selected</font>'; |
| 43 |
} |
| 44 |
$drop_tables = substr($drop_tables, 2); |
| 45 |
if(!empty($empty_tables)) { |
| 46 |
foreach($empty_tables as $empty_table) { |
| 47 |
$empty_query = $wpdb->query("TRUNCATE $empty_table"); |
| 48 |
$text .= "<font color=\"green\">Table '$empty_table' Emptied</font><br />"; |
| 49 |
} |
| 50 |
} |
| 51 |
if(!empty($drop_tables)) { |
| 52 |
$drop_query = $wpdb->query("DROP TABLE $drop_tables"); |
| 53 |
$text = "<font color=\"green\">Table(s) '$drop_tables' Dropped</font>"; |
| 54 |
} |
| 55 |
break; |
| 56 |
} |
| 57 |
} |
| 58 |
|
| 59 |
|
| 60 |
### Show Tables |
| 61 |
$tables = $wpdb->get_results("SHOW TABLES"); |
| 62 |
?> |
| 63 |
<?php if(!empty($text)) { echo '<!-- Last Action --><div id="message" class="updated fade"><p>'.$text.'</p></div>'; } ?> |
| 64 |
<!-- Empty/Drop Tables --> |
| 65 |
<div class="wrap"> |
| 66 |
<h2>Empty/Drop Tables</h2> |
| 67 |
<form action="<?php echo $_SERVER['REQUEST_URI']; ?>" method="post"> |
| 68 |
<table width="100%" cellspacing="3" cellpadding="3" border="0"> |
| 69 |
<tr> |
| 70 |
<th align="left" scope="col">Tables</th> |
| 71 |
<th align="left" scope="col">Empty</th> |
| 72 |
<th align="left" scope="col">Drop</th> |
| 73 |
</tr> |
| 74 |
<?php |
| 75 |
foreach($tables as $dbtable) { |
| 76 |
if($no%2 == 0) { |
| 77 |
$style = 'style=\'background-color: #eee\''; |
| 78 |
} else { |
| 79 |
$style = 'style=\'background-color: none\''; |
| 80 |
} |
| 81 |
$no++; |
| 82 |
$table_name = '$dbtable->Tables_in_'.DB_NAME; |
| 83 |
eval("\$table_name = \"$table_name\";"); |
| 84 |
echo "<tr $style><th align=\"left\" scope=\"row\">$table_name</th>\n"; |
| 85 |
echo "<td><input type=\"radio\" name=\"emptydrop[$table_name]\" value=\"empty\" /> Empty</td>"; |
| 86 |
echo "<td><input type=\"radio\" name=\"emptydrop[$table_name]\" value=\"drop\" /> Drop</td></tr>"; |
| 87 |
} |
| 88 |
?> |
| 89 |
<tr> |
| 90 |
<td colspan="3">1. DROPPING a table means deleting the table. This action is not REVERSIBLE.<br />2. EMPTYING a table means all the rows in the table will be deleted. This action is not REVERSIBLE.</td> |
| 91 |
</tr> |
| 92 |
<tr> |
| 93 |
<td colspan="3" align="center"><input type="submit" name="do" value="Empty/Drop" class="button" onclick="return confirm('You Are About To Empty Or Drop The Selected Databases.\nThis Action Is Not Reversible.\n\n Choose \'Cancel\' to stop, \'OK\' to delete.')" /> <input type="button" name="cancel" Value="<?php _e('Cancel'); ?>" class="button" onclick="javascript:history.go(-1)" /></td> |
| 94 |
</tr> |
| 95 |
</table> |
| 96 |
</form> |
| 97 |
</div> |