root/wp-dbmanager/trunk/database-empty.php

Revision 52756, 4.4 kB (checked in by GamerZ, 3 days ago)

2.31

Line 
1 <?php
2 /*
3 +----------------------------------------------------------------+
4 |                                                                                            |
5 |    WordPress 2.5 Plugin: WP-DBManager 2.31                                |
6 |    Copyright (c) 2008 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 action="<?php echo $_SERVER['REQUEST_URI']; ?>" method="post">
79     <div class="wrap">
80         <h2><?php _e('Empty/Drop Tables', 'wp-dbmanager'); ?></h2>   
81         <br style="clear" />
82         <table class="widefat">
83             <thead>
84                 <tr>
85                     <th><?php _e('Tables', 'wp-dbmanager'); ?></th>
86                     <th><?php _e('Empty', 'wp-dbmanager'); ?> <sup><?php _e('1', 'wp-dbmanager'); ?></sup></th>
87                     <th><?php _e('Drop', 'wp-dbmanager'); ?> <sup><?php _e('2', 'wp-dbmanager'); ?></sup></th>
88                 </tr>
89             </thead>
90                 <?php
91                     foreach($tables as $table_name) {
92                         if($no%2 == 0) {
93                             $style = '';                           
94                         } else {
95                             $style = ' class="alternate"';
96                         }
97                         $no++;
98                         echo "<tr $style><th align=\"left\" scope=\"row\">$table_name</th>\n";
99                         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>';
100                         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>';
101                     }
102                 ?>
103             <tr>
104                 <td colspan="3">
105                     <?php _e('1. EMPTYING a table means all the rows in the table will be deleted. This action is not REVERSIBLE.', 'wp-dbmanager'); ?>
106                     <br />
107                     <?php _e('2. DROPPING a table means deleting the table. This action is not REVERSIBLE.', 'wp-dbmanager'); ?>               
108                 </td>
109             </tr>
110             <tr>
111                 <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>
112             </tr>
113         </table>
114     </div>
115 </form>
Note: See TracBrowser for help on using the browser.