-
Notifications
You must be signed in to change notification settings - Fork 26
/
database-repair.php
82 lines (76 loc) · 2.88 KB
/
database-repair.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
<?php
### Check Whether User Can Manage Database
if ( ! current_user_can( 'install_plugins' ) ) {
die( 'Access Denied' );
}
### Variables Variables Variables
$base_name = plugin_basename('wp-dbmanager/database-manager.php');
$base_page = 'admin.php?page='.$base_name;
### Form Processing
if(!empty($_POST['do'])) {
// Lets Prepare The Variables
$repair = $_POST['repair'];
$text = '';
// Decide What To Do
switch($_POST['do']) {
case __('Repair', 'wp-dbmanager'):
check_admin_referer('wp-dbmanager_repair');
if(!empty($repair)) {
$tables_string = '';
foreach($repair as $key => $value) {
if($value == 'yes') {
$tables_string .= '`, `'.$key;
}
}
} else {
$text = '<p style="color: red;">'.__('No Tables Selected', 'wp-dbmanager').'</p>';
}
$selected_tables = substr($tables_string, 2);
$selected_tables .= '`';
if(!empty($selected_tables)) {
$repair2 = $wpdb->query("REPAIR TABLE $selected_tables");
if(!$repair2) {
$text = '<p style="color: red;">'.sprintf(__('Table(s) \'%s\' NOT Repaired', 'wp-dbmanager'), str_replace('`', '', $selected_tables)).'</p>';
} else {
$text = '<p style="color: green;">'.sprintf(__('Table(s) \'%s\' Repaired', 'wp-dbmanager'), str_replace('`', '', $selected_tables)).'</p>';
}
}
break;
}
}
### Show Tables
$tables = $wpdb->get_col("SHOW TABLES");
?>
<?php if(!empty($text)) { echo '<!-- Last Action --><div id="message" class="updated fade"><p>'.$text.'</p></div>'; } ?>
<!-- Repair Database -->
<form method="post" action="<?php echo admin_url('admin.php?page='.plugin_basename(__FILE__)); ?>">
<?php wp_nonce_field('wp-dbmanager_repair'); ?>
<div class="wrap">
<h2><?php _e('Repair Database', 'wp-dbmanager'); ?></h2>
<br style="clear" />
<table class="widefat">
<thead>
<tr>
<th><?php _e('Tables', 'wp-dbmanager'); ?></th>
<th><?php _e('Options', 'wp-dbmanager'); ?></th>
</tr>
</thead>
<?php
$no = 0;
foreach($tables as $table_name) {
if($no%2 == 0) {
$style = '';
} else {
$style = ' class="alternate"';
}
$no++;
echo "<tr $style><th align=\"left\" scope=\"row\">$table_name</th>\n";
echo "<td><input type=\"radio\" id=\"$table_name-no\" name=\"repair[$table_name]\" value=\"no\" /> <label for=\"$table_name-no\">".__('No', 'wp-dbmanager')."</label> <input type=\"radio\" id=\"$table_name-yes\" name=\"repair[$table_name]\" value=\"yes\" checked=\"checked\" /> <label for=\"$table_name-yes\">".__('Yes', 'wp-dbmanager').'</label></td></tr>';
}
?>
<tr>
<td colspan="2" align="center"><input type="submit" name="do" value="<?php _e('Repair', 'wp-dbmanager'); ?>" class="button" /> <input type="button" name="cancel" value="<?php _e('Cancel', 'wp-dbmanager'); ?>" class="button" onclick="javascript:history.go(-1)" /></td>
</tr>
</table>
</div>
</form>