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