PageRenderTime 48ms CodeModel.GetById 20ms RepoModel.GetById 0ms app.codeStats 0ms

/wp-content/plugins/wp-dbmanager/database-empty.php

https://bitbucket.org/openfarmtech/weblog-content
PHP | 116 lines | 85 code | 9 blank | 22 comment | 13 complexity | c855ad493e9388f014b1b3ebe288dfce MD5 | raw file
Possible License(s): GPL-2.0, AGPL-1.0, LGPL-2.0, LGPL-3.0, BSD-3-Clause, GPL-3.0, LGPL-2.1, AGPL-3.0, CC-BY-SA-3.0
  1. <?php
  2. /*
  3. +----------------------------------------------------------------+
  4. | |
  5. | WordPress 2.8 Plugin: WP-DBManager 2.50 |
  6. | Copyright (c) 2009 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. ### Check Whether User Can Manage Database
  19. if(!current_user_can('manage_database')) {
  20. die('Access Denied');
  21. }
  22. ### Variables Variables Variables
  23. $base_name = plugin_basename('wp-dbmanager/database-manager.php');
  24. $base_page = 'admin.php?page='.$base_name;
  25. $backup = array();
  26. $backup_options = get_option('dbmanager_options');
  27. $backup['date'] = current_time('timestamp');
  28. $backup['mysqldumppath'] = $backup_options['mysqldumppath'];
  29. $backup['mysqlpath'] = $backup_options['mysqlpath'];
  30. $backup['path'] = $backup_options['path'];
  31. ### Form Processing
  32. if($_POST['do']) {
  33. // Lets Prepare The Variables
  34. $emptydrop = $_POST['emptydrop'];
  35. // Decide What To Do
  36. switch($_POST['do']) {
  37. case __('Empty/Drop', 'wp-dbmanager'):
  38. $empty_tables = array();
  39. if(!empty($emptydrop)) {
  40. foreach($emptydrop as $key => $value) {
  41. if($value == 'empty') {
  42. $empty_tables[] = $key;
  43. } elseif($value == 'drop') {
  44. $drop_tables .= ', '.$key;
  45. }
  46. }
  47. } else {
  48. $text = '<font color="red">'.__('No Tables Selected.', 'wp-dbmanager').'</font>';
  49. }
  50. $drop_tables = substr($drop_tables, 2);
  51. if(!empty($empty_tables)) {
  52. foreach($empty_tables as $empty_table) {
  53. $empty_query = $wpdb->query("TRUNCATE $empty_table");
  54. $text .= '<font color="green">'.sprintf(__('Table \'%s\' Emptied', 'wp-dbmanager'), $empty_table).'</font><br />';
  55. }
  56. }
  57. if(!empty($drop_tables)) {
  58. $drop_query = $wpdb->query("DROP TABLE $drop_tables");
  59. $text = '<font color="green">'.sprintf(__('Table(s) \'%s\' Dropped', 'wp-dbmanager'), $drop_tables).'</font>';
  60. }
  61. break;
  62. }
  63. }
  64. ### Show Tables
  65. $tables = $wpdb->get_col("SHOW TABLES");
  66. ?>
  67. <?php if(!empty($text)) { echo '<!-- Last Action --><div id="message" class="updated fade"><p>'.$text.'</p></div>'; } ?>
  68. <!-- Empty/Drop Tables -->
  69. <form method="post" action="<?php echo $_SERVER['PHP_SELF']; ?>?page=<?php echo plugin_basename(__FILE__); ?>">
  70. <div class="wrap">
  71. <div id="icon-wp-dbmanager" class="icon32"><br /></div>
  72. <h2><?php _e('Empty/Drop Tables', 'wp-dbmanager'); ?></h2>
  73. <br style="clear" />
  74. <table class="widefat">
  75. <thead>
  76. <tr>
  77. <th><?php _e('Tables', 'wp-dbmanager'); ?></th>
  78. <th><?php _e('Empty', 'wp-dbmanager'); ?> <sup><?php _e('1', 'wp-dbmanager'); ?></sup></th>
  79. <th><?php _e('Drop', 'wp-dbmanager'); ?> <sup><?php _e('2', 'wp-dbmanager'); ?></sup></th>
  80. </tr>
  81. </thead>
  82. <?php
  83. foreach($tables as $table_name) {
  84. if($no%2 == 0) {
  85. $style = '';
  86. } else {
  87. $style = ' class="alternate"';
  88. }
  89. $no++;
  90. echo "<tr $style><th align=\"left\" scope=\"row\">$table_name</th>\n";
  91. 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>';
  92. 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>';
  93. }
  94. ?>
  95. <tr>
  96. <td colspan="3">
  97. <?php _e('1. EMPTYING a table means all the rows in the table will be deleted. This action is not REVERSIBLE.', 'wp-dbmanager'); ?>
  98. <br />
  99. <?php _e('2. DROPPING a table means deleting the table. This action is not REVERSIBLE.', 'wp-dbmanager'); ?>
  100. </td>
  101. </tr>
  102. <tr>
  103. <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>
  104. </tr>
  105. </table>
  106. </div>
  107. </form>