WP-DBManager - Version 1.00

Version Description

Download this release

Release Info

Developer GamerZ
Plugin Icon WP-DBManager
Version 1.00
Comparing to
See all releases

Version 1.00

Files changed (2) hide show
  1. database-manager.php +617 -0
  2. readme.txt +39 -0
database-manager.php ADDED
@@ -0,0 +1,617 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /*
3
+ * Database Manager For WordPress
4
+ * - wp-admin/database-manager.php
5
+ *
6
+ * Copyright � 2004-2005 Lester "GaMerZ" Chan
7
+ */
8
+
9
+
10
+ ### Require Admin Header
11
+ require_once('./admin.php');
12
+
13
+
14
+ ### Variables Variables Variables
15
+ $title = __('Manage Database');
16
+ $this_file = $parent_file = 'database-manager.php';
17
+ $mode = trim($_GET['mode']);
18
+ $backup = array();
19
+ $backup['date'] = time();
20
+ $backup['mysqldumppath'] = 'mysqldump';
21
+ $backup['mysqlpath'] = 'mysql';
22
+ $backup['path'] = ABSPATH.'wp-backup-db/';
23
+
24
+
25
+ ### Cancel
26
+ if(isset($_POST['cancel'])) {
27
+ Header('Location: database-manager.php');
28
+ exit();
29
+ }
30
+
31
+
32
+ ### Format Bytes Into KB/MB
33
+ function format_size($rawSize) {
34
+ if ($rawSize / 1048576 > 1)
35
+ return round($rawSize/1048576, 1) . ' MB';
36
+ else if ($rawSize / 1024 > 1)
37
+ return round($rawSize/1024, 1) . ' KB';
38
+ else
39
+ return round($rawSize, 1) . ' bytes';
40
+ }
41
+
42
+
43
+ ### Check Folder Whether There Is Any File Inside
44
+ function is_emtpy_folder($folder){
45
+ if(is_dir($folder) ){
46
+ $handle = opendir($folder);
47
+ while( (gettype( $name = readdir($handle)) != 'boolean')){
48
+ $name_array[] = $name;
49
+ }
50
+ foreach($name_array as $temp)
51
+ $folder_content .= $temp;
52
+
53
+ if($folder_content == '...')
54
+ return true;
55
+ else
56
+ return false;
57
+ closedir($handle);
58
+ }
59
+ else
60
+ return true; // folder doesnt exist
61
+ }
62
+
63
+
64
+ ### Form Processing
65
+ if($_POST['do']) {
66
+ // Lets Prepare The Variables
67
+ $database_file = trim($_POST['database_file']);
68
+ $optimize = $_POST['optimize'];
69
+ $delete = $_POST['delete'];
70
+ $nice_file_date = date('l, jS F Y @ H:i', substr($database_file, 0, 10));
71
+
72
+ // Decide What To Do
73
+ switch($_POST['do']) {
74
+ case 'Backup':
75
+ $gzip = intval($_POST['gzip']);
76
+ if($gzip == 1) {
77
+ $backup['filename'] = $backup['date'].'_-_'.DB_NAME.'.sql.gz';
78
+ $backup['filepath'] = $backup['path'].'/'.$backup['filename'];
79
+ $backup['command'] = $backup['mysqldumppath'].' -h'.DB_HOST.' -u'.DB_USER.' -p'.DB_PASSWORD.' --add-drop-table '.DB_NAME.' | gzip > '.$backup['filepath'];
80
+ } else {
81
+ $backup['filename'] = $backup['date'].'_-_'.DB_NAME.'.sql';
82
+ $backup['filepath'] = $backup['path'].'/'.$backup['filename'];
83
+ $backup['command'] = $backup['mysqldumppath'].' -h'.DB_HOST.' -u'.DB_USER.' -p'.DB_PASSWORD.' --add-drop-table '.DB_NAME.' > '.$backup['filepath'];
84
+ }
85
+ passthru($backup['command'], $error);
86
+ if(!is_writable($backup['path'])) {
87
+ $text = "<font color=\"red\">Database Failed To Backup On '".date('l, jS F Y @ H:i')."'. Backup Folder Not Writable</font>";
88
+ } elseif(filesize($backup['filepath']) == 0) {
89
+ unlink($backup['filepath']);
90
+ $text = "<font color=\"red\">Database Failed To Backup On '".date('l, jS F Y @ H:i')."'. Backup File Size Is 0KB</font>";
91
+ } elseif(!is_file($backup['filepath'])) {
92
+ $text = "<font color=\"red\">Database Failed To Backup On '".date('l, jS F Y @ H:i')."'. Invalid Backup File Path</font>";
93
+ } elseif($error) {
94
+ $text = "<font color=\"red\">Database Failed To Backup On '".date('l, jS F Y @ H:i')."'</font>";
95
+ } else {
96
+ $text = "<font color=\"green\">Database Backed Up Successfully On '".date('l, jS F Y @ H:i')."'</font>";
97
+ }
98
+ break;
99
+ case 'Restore':
100
+ if(!empty($database_file)) {
101
+ if(stristr($database_file, '.gz')) {
102
+ $backup['command'] = 'gunzip < '.$backup['path'].'/'.$database_file.' | '.$backup['mysqlpath'].' -h'.DB_HOST.' -u'.DB_USER.' -p'.DB_PASSWORD.' '.DB_NAME;
103
+ } else {
104
+ $backup['command'] = $backup['mysqlpath'].' -h'.DB_HOST.' -u'.DB_USER.' -p'.DB_PASSWORD.' '.DB_NAME.' < '.$backup['path'].'/'.$database_file;
105
+ }
106
+ passthru($backup['command'], $error);
107
+ if($error) {
108
+ $text = "<font color=\"red\">Database On '$nice_file_date' Failed To Restore</font>";
109
+ } else {
110
+ $text = "<font color=\"green\">Database On '$nice_file_date' Restored Successfully</font>";
111
+ }
112
+ } else {
113
+ $text = '<font color="red">No Backup Database File Selected</font>';
114
+ }
115
+ break;
116
+ case 'Delete':
117
+ if(!empty($delete)) {
118
+ foreach($delete as $dbbackup) {
119
+ $nice_file_date = date('l, jS F Y @ H:i', substr($dbbackup, 0, 10));
120
+ if(is_file($backup['path'].'/'.$dbbackup)) {
121
+ if(!unlink($backup['path'].'/'.$dbbackup)) {
122
+ $text .= "<font color=\"red\">Unable To Delete Database Backup File On '$nice_file_date'</font><br />";
123
+ } else {
124
+ $text .= "<font color=\"green\">Database Backup File On '$nice_file_date' Deleted Successfully</font><br />";
125
+ }
126
+ } else {
127
+ $text = "<font color=\"red\">Invalid Database Backup File On '$nice_file_date'</font>";
128
+ }
129
+ }
130
+ } else {
131
+ $text = '<font color="red">No Backup Database File Selected</font>';
132
+ }
133
+ break;
134
+ case 'Download':
135
+ if(!empty($database_file)) {
136
+ $file_path = $backup['path'].'/'.$database_file;
137
+ $nice_file_name = date('jS_F_Y', substr($database_file, 0, 10)).'-'.substr($database_file, 13);
138
+ header("Pragma: public");
139
+ header("Expires: 0");
140
+ header("Cache-Control: must-revalidate, post-check=0, pre-check=0");
141
+ header("Content-Type: application/force-download");
142
+ header("Content-Type: application/octet-stream");
143
+ header("Content-Type: application/download");
144
+ header("Content-Disposition: attachment; filename=".basename($nice_file_name).";");
145
+ header("Content-Transfer-Encoding: binary");
146
+ header("Content-Length: ".filesize($file_path));
147
+ @readfile($file_path);
148
+ } else {
149
+ $text = '<font color="red">No Backup Database File Selected</font>';
150
+ }
151
+ break;
152
+ case 'Optimize':
153
+ foreach($optimize as $key => $value) {
154
+ if($value == 'yes') {
155
+ $tables_string .= ', '.$key;
156
+ }
157
+ }
158
+ $selected_tables = substr($tables_string, 2);
159
+ if(!empty($selected_tables)) {
160
+ $optimize2 = $wpdb->query("OPTIMIZE TABLE $selected_tables");
161
+ if(!$optimize2) {
162
+ $text = "<font color=\"red\">Table(s) '$selected_tables' Failed To Be Optimized</font>";
163
+ } else {
164
+ $text = "<font color=\"green\">Table(s) '$selected_tables' Optimized Successfully</font>";
165
+ }
166
+ } else {
167
+ $text = '<font color="red">No Tables Selected</font>';
168
+ }
169
+ break;
170
+ case 'Run':
171
+ $sql_queries2 = trim($_POST['sql_query']);
172
+ $totalquerycount = 0;
173
+ $successquery = 0;
174
+ if($sql_queries2) {
175
+ $sql_queries = array();
176
+ $sql_queries2 = explode("\n", $sql_queries2);
177
+ foreach($sql_queries2 as $sql_query2) {
178
+ $sql_query2 = trim(stripslashes($sql_query2));
179
+ $sql_query2 = preg_replace("/[\r\n]+/", '', $sql_query2);
180
+ if(!empty($sql_query2)) {
181
+ $sql_queries[] = $sql_query2;
182
+ }
183
+ }
184
+ if($sql_queries) {
185
+ foreach($sql_queries as $sql_query) {
186
+ if (preg_match("/^\\s*(insert|update|replace|delete|create) /i",$sql_query)) {
187
+ $run_query = $wpdb->query($sql_query);
188
+ if(!$run_query) {
189
+ $text .= "<font color=\"red\">$sql_query</font><br />";
190
+ } else {
191
+ $successquery++;
192
+ $text .= "<font color=\"green\">$sql_query</font><br />";
193
+ }
194
+ $totalquerycount++;
195
+ } elseif (preg_match("/^\\s*(select|drop|show|grant) /i",$sql_query)) {
196
+ $text .= "<font color=\"red\">$sql_query</font><br />";
197
+ $totalquerycount++;
198
+ }
199
+ }
200
+ $text .= "<font color=\"blue\">$successquery/$totalquerycount Query(s) Executed Successfully</font>";
201
+ } else {
202
+ $text = "<font color=\"red\">Empty Query</font>";
203
+ }
204
+ } else {
205
+ $text = "<font color=\"red\">Empty Query</font>";
206
+ }
207
+ break;
208
+ }
209
+ }
210
+
211
+
212
+ ### Switch $mode
213
+ switch($mode) {
214
+ // Backup Database
215
+ case 'backup':
216
+ $title = 'Backup Database';
217
+ $standalone = 0;
218
+ require("./admin-header.php");
219
+ if ($user_level < 9) {
220
+ die('<p>Insufficient Level</p>');
221
+ }
222
+ $backup['filename'] = $backup['date'].'_-_'.DB_NAME.'.sql';
223
+ ?>
224
+ <ul id="adminmenu2">
225
+ <li><a href="database-manager.php">Manage Database</a></li>
226
+ <li><a href="database-manager.php?mode=backup" class="current">Backup DB</a></li>
227
+ <li><a href="database-manager.php?mode=optimize">Optimize DB</a></li>
228
+ <li><a href="database-manager.php?mode=restore">Restore/Download DB</a></li>
229
+ <li><a href="database-manager.php?mode=delete">Delete Backup DB</a></li>
230
+ <li class="last"><a href="database-manager.php?mode=run">Run SQL Query</a></li>
231
+ </ul>
232
+ <!-- Backup Database -->
233
+ <div class="wrap">
234
+ <h2>Backup Database</h2>
235
+ <form action="<?=$_SERVER['PHP_SELF']?>" method="post">
236
+ <table width="100%" cellspacing="3" cellpadding="3" border="0">
237
+ <tr style='background-color: #eee'>
238
+ <th align="left" scope="row">Database Name:</th>
239
+ <td><?=DB_NAME?></td>
240
+ </tr>
241
+ <tr style='background-color: none'>
242
+ <th align="left" scope="row">Database Backup To:</th>
243
+ <td><?=$backup['path']?></td>
244
+ </tr>
245
+ <tr style='background-color: #eee'>
246
+ <th align="left" scope="row">Database Backup Date:</th>
247
+ <td><?=date('jS F Y', $backup['date'])?></td>
248
+ </tr>
249
+ <tr style='background-color: none'>
250
+ <th align="left" scope="row">Database Backup File Name:</th>
251
+ <td><?=$backup['filename']?> / <?=date('jS_F_Y', substr($backup['filename'], 0, 10)).'-'.substr($backup['filename'], 13);?></td>
252
+ </tr>
253
+ <tr style='background-color: #eee'>
254
+ <th align="left" scope="row">Database Backup Type:</th>
255
+ <td>Full (Structure and Data)</td>
256
+ </tr>
257
+ <tr style='background-color: none'>
258
+ <th align="left" scope="row">MYSQL Dump Location</th>
259
+ <td><?=$backup['mysqldumppath']?></td>
260
+ </tr>
261
+ <tr style='background-color: #eee'>
262
+ <th align="left" scope="row">GZIP Database Backup File?</th>
263
+ <td><input type="radio" name="gzip" value="1">Yes&nbsp;&nbsp;<input type="radio" name="gzip" value="0" CHECKED>No</td>
264
+ </tr>
265
+ <tr>
266
+ <td colspan="2" align="center"><input type="submit" name="do" value="Backup" class="button">&nbsp;&nbsp;<input type="submit" name="cancel" Value="Cancel" class="button"></td>
267
+ </tr>
268
+ </table>
269
+ </form>
270
+ </div>
271
+ <?php
272
+ break;
273
+ // Optimize Database
274
+ case 'optimize':
275
+ $title = 'Optimize Database';
276
+ $standalone = 0;
277
+ require("./admin-header.php");
278
+ if ($user_level < 9) {
279
+ die('<p>Insufficient Level</p>');
280
+ }
281
+ $tables = $wpdb->get_results("SHOW TABLES");
282
+ ?>
283
+ <ul id="adminmenu2">
284
+ <li><a href="database-manager.php">Manage Database</a></li>
285
+ <li><a href="database-manager.php?mode=backup">Backup DB</a></li>
286
+ <li><a href="database-manager.php?mode=optimize" class="current">Optimize DB</a></li>
287
+ <li><a href="database-manager.php?mode=restore">Restore/Download DB</a></li>
288
+ <li><a href="database-manager.php?mode=delete">Delete Backup DB</a></li>
289
+ <li class="last"><a href="database-manager.php?mode=run">Run SQL Query</a></li>
290
+ </ul>
291
+ <!-- Optimize Database -->
292
+ <div class="wrap">
293
+ <h2>Optimize Database</h2>
294
+ <form action="<?=$_SERVER['PHP_SELF']?>" method="post">
295
+ <table width="100%" cellspacing="3" cellpadding="3" border="0">
296
+ <tr>
297
+ <th align="left" scope="col">Tables</th>
298
+ <th align="left" scope="col">Options</th>
299
+ </tr>
300
+ <?php
301
+ foreach($tables as $dbtable) {
302
+ if($no%2 == 0) {
303
+ $style = 'style=\'background-color: #eee\'';
304
+ } else {
305
+ $style = 'style=\'background-color: none\'';
306
+ }
307
+ $no++;
308
+ $table_name = '$dbtable->Tables_in_'.DB_NAME;
309
+ eval("\$table_name = \"$table_name\";");
310
+ echo "<tr $style><th align=\"left\" scope=\"row\">$table_name</th>\n";
311
+ echo "<td><input type=\"radio\" name=\"optimize[$table_name]\" value=\"no\">No&nbsp;&nbsp;<input type=\"radio\" name=\"optimize[$table_name]\" value=\"yes\" CHECKED>Yes</td></tr>";
312
+ }
313
+ ?>
314
+ <tr>
315
+ <td colspan="2" align="center">Database should be optimize once every month.</td>
316
+ </tr>
317
+ <tr>
318
+ <td colspan="2" align="center"><input type="submit" name="do" value="Optimize" class="button">&nbsp;&nbsp;<input type="submit" name="cancel" Value="Cancel" class="button"></td>
319
+ </tr>
320
+ </table>
321
+ </form>
322
+ </div>
323
+ <?php
324
+ break;
325
+ // Restore Database
326
+ case 'restore':
327
+ $title = 'Restore/Download Database';
328
+ $standalone = 0;
329
+ require("./admin-header.php");
330
+ if ($user_level < 9) {
331
+ die('<p>Insufficient Level</p>');
332
+ }
333
+ ?>
334
+ <ul id="adminmenu2">
335
+ <li><a href="database-manager.php">Manage Database</a></li>
336
+ <li><a href="database-manager.php?mode=backup">Backup DB</a></li>
337
+ <li><a href="database-manager.php?mode=optimize">Optimize DB</a></li>
338
+ <li><a href="database-manager.php?mode=restore" class="current">Restore/Download DB</a></li>
339
+ <li><a href="database-manager.php?mode=delete">Delete Backup DB</a></li>
340
+ <li class="last"><a href="database-manager.php?mode=run">Run SQL Query</a></li>
341
+ </ul>
342
+ <!-- Restore/Download Database -->
343
+ <div class="wrap">
344
+ <h2>Restore/Download Database</h2>
345
+ <form action="<?=$_SERVER['PHP_SELF']?>" method="post">
346
+ <table width="100%" cellspacing="3" cellpadding="3" border="0">
347
+ <tr>
348
+ <th align="left" scope="row" colspan="5">Choose A Backup Date To Restore Or Download</th>
349
+ </tr>
350
+ <tr>
351
+ <th align="left" scope="col">No.</th>
352
+ <th align="left" scope="col">Database File</th>
353
+ <th align="left" scope="col">Date/Time</th>
354
+ <th align="left" scope="col">Size</th>
355
+ <th align="left" scope="col">Select</th>
356
+ </tr>
357
+ <?php
358
+ if(!is_emtpy_folder($backup['path'])) {
359
+ if ($handle = opendir($backup['path'])) {
360
+ $database_files = array();
361
+ while (false !== ($file = readdir($handle))) {
362
+ if ($file != '.' && $file != '..') {
363
+ $database_files[] = $file;
364
+ }
365
+ }
366
+ closedir($handle);
367
+ for($i = (sizeof($database_files)-1); $i > -1; $i--) {
368
+ if($no%2 == 0) {
369
+ $style = 'style=\'background-color: #eee\'';
370
+ } else {
371
+ $style = 'style=\'background-color: none\'';
372
+ }
373
+ $no++;
374
+ $database_text = substr($database_files[$i], 13);
375
+ $date_text = date('l, jS F Y @ H:i', substr($database_files[$i], 0, 10));
376
+ $size_text = filesize($backup['path'].'/'.$database_files[$i]);
377
+ echo "<tr $style>\n<td>$no</td>";
378
+ echo "<td>$database_text</td>";
379
+ echo "<td>$date_text</td>";
380
+ echo '<td>'.format_size($size_text).'</td>';
381
+ echo "<td><input type=\"radio\" name=\"database_file\" value=\"$database_files[$i]\" /></td>\n</tr>\n";
382
+ $totalsize += $size_text;
383
+ }
384
+ } else {
385
+ echo '<tr><td align="center" colspan="5">There Are No Database Backup Files Available</td></tr>';
386
+ }
387
+ } else {
388
+ echo '<tr><td align="center" colspan="5">There Are No Database Backup Files Available</td></tr>';
389
+ }
390
+ ?>
391
+ </tr>
392
+ <tr>
393
+ <th align="left" colspan="3"><?=$no?> Backup File(s)</th>
394
+ <th align="left"><?=format_size($totalsize)?></th>
395
+ <td>&nbsp;</td>
396
+ </tr>
397
+ <tr>
398
+ <td colspan="5" align="center"><input type="submit" name="do" value="Download" class="button">&nbsp;&nbsp;<input type="submit" class="button" name="do" value="Restore" onclick="return confirm('You Are About To Restore A Database.\nThis Action Is Not Reversible.\nAny Data Inserted After The Backup Date Will Be Gone.\n\n Choose \'Cancel\' to stop, \'OK\' to restore.')" class="button">&nbsp;&nbsp;<input type="submit" name="cancel" Value="Cancel" class="button"></td>
399
+ </tr>
400
+ </table>
401
+ </form>
402
+ </div>
403
+ <?php
404
+ break;
405
+ // Delete Database Backup Files
406
+ case 'delete':
407
+ $title = 'Delete Backup Database';
408
+ $standalone = 0;
409
+ require("./admin-header.php");
410
+ if ($user_level < 9) {
411
+ die('<p>Insufficient Level</p>');
412
+ }
413
+ ?>
414
+ <ul id="adminmenu2">
415
+ <li><a href="database-manager.php">Manage Database</a></li>
416
+ <li><a href="database-manager.php?mode=backup">Backup DB</a></li>
417
+ <li><a href="database-manager.php?mode=optimize">Optimize DB</a></li>
418
+ <li><a href="database-manager.php?mode=restore">Restore/Download DB</a></li>
419
+ <li><a href="database-manager.php?mode=delete" class="current">Delete Backup DB</a></li>
420
+ <li class="last"><a href="database-manager.php?mode=run">Run SQL Query</a></li>
421
+ </ul>
422
+ <!-- Delete Database Backup Files -->
423
+ <div class="wrap">
424
+ <h2>Delete Database Backup Files</h2>
425
+ <form action="<?=$_SERVER['PHP_SELF']?>" method="post">
426
+ <table width="100%" cellspacing="3" cellpadding="3" border="0">
427
+ <tr>
428
+ <th align="left" scope="row" colspan="5">Choose Database Backup Files To Delete</th>
429
+ </tr>
430
+ <tr>
431
+ <th align="left" scope="col">No.</th>
432
+ <th align="left" scope="col">Database File</th>
433
+ <th align="left" scope="col">Date/Time</th>
434
+ <th align="left" scope="col">Size</th>
435
+ <th align="left" scope="col">Select</th>
436
+ </tr>
437
+ <?php
438
+ if(!is_emtpy_folder($backup['path'])) {
439
+ if ($handle = opendir($backup['path'])) {
440
+ $database_files = array();
441
+ while (false !== ($file = readdir($handle))) {
442
+ if ($file != '.' && $file != '..') {
443
+ $database_files[] = $file;
444
+ }
445
+ }
446
+ closedir($handle);
447
+ for($i = (sizeof($database_files)-1); $i > -1; $i--) {
448
+ if($no%2 == 0) {
449
+ $style = 'style=\'background-color: #eee\'';
450
+ } else {
451
+ $style = 'style=\'background-color: none\'';
452
+ }
453
+ $no++;
454
+ $database_text = substr($database_files[$i], 13);
455
+ $date_text = date('l, jS F Y @ H:i', substr($database_files[$i], 0, 10));
456
+ $size_text = filesize($backup['path'].'/'.$database_files[$i]);
457
+ echo "<tr $style>\n<td>$no</td>";
458
+ echo "<td>$database_text</td>";
459
+ echo "<td>$date_text</td>";
460
+ echo '<td>'.format_size($size_text).'</td>';
461
+ echo "<td><input type=\"checkbox\" name=\"delete[]\" value=\"$database_files[$i]\" /></td>\n</tr>\n";
462
+ $totalsize += $size_text;
463
+ }
464
+ } else {
465
+ echo '<tr><td align="center" colspan="5">There Are No Database Backup Files Available</td></tr>';
466
+ }
467
+ } else {
468
+ echo '<tr><td align="center" colspan="5">There Are No Database Backup Files Available</td></tr>';
469
+ }
470
+ ?>
471
+ </tr>
472
+ <tr>
473
+ <th align="left" colspan="3"><?=$no?> Backup File(s)</th>
474
+ <th align="left"><?=format_size($totalsize)?></th>
475
+ <td>&nbsp;</td>
476
+ </tr>
477
+ <tr>
478
+ <td colspan="5" align="center"><input type="submit" class="button" name="do" value="Delete" onclick="return confirm('You Are About To Delete The Selected Database Backup Files.\nThis Action Is Not Reversible.\n\n Choose \'Cancel\' to stop, \'OK\' to delete.')">&nbsp;&nbsp;<input type="submit" name="cancel" Value="Cancel" class="button"></td>
479
+ </tr>
480
+ </table>
481
+ </form>
482
+ </div>
483
+ <?php
484
+ break;
485
+ // Run SQL Query
486
+ case 'run':
487
+ $title = 'Run SQL Query';
488
+ $standalone = 0;
489
+ require("./admin-header.php");
490
+ if ($user_level < 9) {
491
+ die('<p>Insufficient Level</p>');
492
+ }
493
+ ?>
494
+ <ul id="adminmenu2">
495
+ <li><a href="database-manager.php">Manage Database</a></li>
496
+ <li><a href="database-manager.php?mode=backup">Backup DB</a></li>
497
+ <li><a href="database-manager.php?mode=optimize">Optimize DB</a></li>
498
+ <li><a href="database-manager.php?mode=restore">Restore/Download DB</a></li>
499
+ <li><a href="database-manager.php?mode=delete">Delete Backup DB</a></li>
500
+ <li class="last"><a href="database-manager.php?mode=run" class="current">Run SQL Query</a></li>
501
+ </ul>
502
+ <!-- Run SQL Query -->
503
+ <div class="wrap">
504
+ <h2>Run SQL Query</h2>
505
+ <form action="<?=$_SERVER['PHP_SELF']?>" method="post">
506
+ <p><b>Seperate Multiple Queries With A New Line</b><br /><font color="green">Use Only INSERT, UPDATE, REPLACE, DELETE and CREATE statements.</font></p>
507
+ <p align="center"><textarea cols="150" rows="30" name="sql_query"></textarea></p>
508
+ <p align="center"><input type="submit" name="do" Value="Run" class="button">&nbsp;&nbsp;<input type="submit" name="cancel" Value="Cancel" class="button"></p>
509
+ <p>1. CREATE statement will return an error, which is perfectly normal due to the database class. To confirm that your table has been created check the Manage Database page.<br />2. UPDATE statement may return an error sometimes due to the newly updated value being the same as the previous value.</font></p>
510
+ </form>
511
+ </div>
512
+ <?php
513
+ break;
514
+ // Database Information
515
+ default:
516
+ $title = 'Manage Database';
517
+ $standalone = 0;
518
+ require("./admin-header.php");
519
+ if ($user_level < 9) {
520
+ die('<p>Insufficient Level</p>');
521
+ }
522
+ // Get MYSQL Version
523
+ $sqlversion = $wpdb->get_var("SELECT VERSION() AS version");
524
+ ?>
525
+ <ul id="adminmenu2">
526
+ <li><a href="database-manager.php" class="current">Manage Database</a></li>
527
+ <li><a href="database-manager.php?mode=backup">Backup DB</a></li>
528
+ <li><a href="database-manager.php?mode=optimize">Optimize DB</a></li>
529
+ <li><a href="database-manager.php?mode=restore">Restore/Download DB</a></li>
530
+ <li><a href="database-manager.php?mode=delete">Delete Backup DB</a></li>
531
+ <li class="last"><a href="database-manager.php?mode=run">Run SQL Query</a></li>
532
+ </ul>
533
+ <?php
534
+ if(!empty($text)) { echo '<!-- Last Action --><div class="wrap"><h2>Last Action</h2>'.$text.' </div>'; }
535
+ ?>
536
+
537
+ <!-- Database Information -->
538
+ <div class="wrap">
539
+ <h2>Database Information</h2>
540
+ <table width="100%" cellspacing="3" cellpadding="3" border="0">
541
+ <tr>
542
+ <th align="left" scope="col">Setting</th>
543
+ <th align="left" scope="col">Value</th>
544
+ </tr>
545
+ <tr>
546
+ <td>Database Host</td>
547
+ <td><?=DB_HOST?></td>
548
+ </tr>
549
+ <tr>
550
+ <td>Database Name</td>
551
+ <td><?=DB_NAME?></td>
552
+ </tr>
553
+ <tr>
554
+ <td>Database User</td>
555
+ <td><?=DB_USER?></td>
556
+ </tr>
557
+ <tr>
558
+ <td>Database Type</td>
559
+ <td>MYSQL</td>
560
+ </tr>
561
+ <tr>
562
+ <td>Database Version</td>
563
+ <td>v<?=$sqlversion?></td>
564
+ </tr>
565
+ </table>
566
+ </div>
567
+ <div class="wrap">
568
+ <h2>Tables Information</h2>
569
+ <table width="100%" cellspacing="3" cellpadding="3" border="0">
570
+ <tr>
571
+ <th align="left" scope="col">No.</th>
572
+ <th align="left" scope="col">Tables</th>
573
+ <th align="left" scope="col">Records</th>
574
+ <th align="left" scope="col">Data Usage</th>
575
+ <th align="left" scope="col">Index Usage</th>
576
+ <th align="left" scope="col">Overhead</th>
577
+ </tr>
578
+ <?php
579
+ // If MYSQL Version More Than 3.23, Get More Info
580
+ if($sqlversion >= '3.23') {
581
+ $tablesstatus = $wpdb->get_results("SHOW TABLE STATUS");
582
+ foreach($tablesstatus as $tablestatus) {
583
+ if($no%2 == 0) {
584
+ $style = 'style=\'background-color: #eee\'';
585
+ } else {
586
+ $style = 'style=\'background-color: none\'';
587
+ }
588
+ $no++;
589
+ echo "<tr $style>\n<td>$no</td>\n";
590
+ echo "<td>$tablestatus->Name</td>\n";
591
+ echo "<td>".number_format($tablestatus->Rows)."</td>\n";
592
+ echo "<td>".format_size($tablestatus->Data_length)."</td>\n";
593
+ echo "<td>".format_size($tablestatus->Index_length)."</td>\n";
594
+ echo "<td>".format_size($tablestatus->Data_free)."</td>\n";
595
+ $row_usage += $tablestatus->Rows;
596
+ $data_usage += $tablestatus->Data_length;
597
+ $index_usage += $tablestatus->Index_length;
598
+ $overhead_usage += $tablestatus->Data_free;
599
+ }
600
+ echo "<tr><th align=\"left\" scope=\"row\">Total:</th>\n";
601
+ echo "<th align=\"left\" scope=\"row\">$no Tables</th>\n";
602
+ echo "<th align=\"left\" scope=\"row\">".number_format($row_usage)."</th>\n";
603
+ echo "<th align=\"left\" scope=\"row\">".format_size($data_usage)."</th>\n";
604
+ echo "<th align=\"left\" scope=\"row\">".format_size($index_usage)."</th>";
605
+ echo "<th align=\"left\" scope=\"row\">".format_size($overhead_usage)."</th></tr>";
606
+ } else {
607
+ echo '<tr><td colspan="6" align="center"><b>Could Not Show Table Status Due To Your MYSQL Version Is Lower Than 3.23.</b></td></tr>';
608
+ }
609
+ ?>
610
+ </table>
611
+ </div>
612
+ <?php
613
+ } // End switch($mode)
614
+
615
+ ### Require Admin Footer
616
+ require_once 'admin-footer.php';
617
+ ?>
readme.txt ADDED
@@ -0,0 +1,39 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ -> Database Manager For WordPress
2
+ --------------------------------------------------
3
+ Author -> Lester 'GaMerZ' Chan
4
+ Email -> lesterch@singnet.com.sg
5
+ Website -> http://www.lesterchan.net/
6
+ Demo -> N/A
7
+ Updated -> 13th May 2005
8
+ --------------------------------------------------
9
+ Notes -> Minium level required to add/edit/delete polls is 9
10
+ --------------------------------------------------
11
+
12
+ -> Installation Instructions
13
+ --------------------------------------------------
14
+ // Create a folder called 'wp-backup-db' under your root Wordpress folder
15
+
16
+
17
+ // CHMOD wp-backup-db to 777
18
+
19
+
20
+ // Open wp-admin folder
21
+
22
+ Put:
23
+ ------------------------------------------------------------------
24
+ database-manager.php
25
+ ------------------------------------------------------------------
26
+
27
+
28
+ // Open wp-admin/menu.php
29
+
30
+ Find:
31
+ ------------------------------------------------------------------
32
+ $menu[25] = array(__('Presentation'), 8, 'themes.php');
33
+ ------------------------------------------------------------------
34
+ Add Above It:
35
+ ------------------------------------------------------------------
36
+ $menu[24] = array(__('Database'), 9, 'database-manager.php');
37
+ ------------------------------------------------------------------
38
+
39
+ // Login to Wordpress Administration Panel and click the option 'Database' at the top