PageRenderTime 53ms CodeModel.GetById 28ms RepoModel.GetById 0ms app.codeStats 0ms

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

https://bitbucket.org/zachisit/zachis.it-m
PHP | 118 lines | 87 code | 9 blank | 22 comment | 13 complexity | ed0c0af95f61057b26dec63a0e8405fc MD5 | raw file
  1. <?php
  2. /*
  3. +----------------------------------------------------------------+
  4. | |
  5. | WordPress 2.8 Plugin: WP-DBManager 2.63 |
  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. check_admin_referer('wp-dbmanager_empty');
  39. $empty_tables = array();
  40. if(!empty($emptydrop)) {
  41. foreach($emptydrop as $key => $value) {
  42. if($value == 'empty') {
  43. $empty_tables[] = $key;
  44. } elseif($value == 'drop') {
  45. $drop_tables .= ', '.$key;
  46. }
  47. }
  48. } else {
  49. $text = '<font color="red">'.__('No Tables Selected.', 'wp-dbmanager').'</font>';
  50. }
  51. $drop_tables = substr($drop_tables, 2);
  52. if(!empty($empty_tables)) {
  53. foreach($empty_tables as $empty_table) {
  54. $empty_query = $wpdb->query("TRUNCATE $empty_table");
  55. $text .= '<font color="green">'.sprintf(__('Table \'%s\' Emptied', 'wp-dbmanager'), $empty_table).'</font><br />';
  56. }
  57. }
  58. if(!empty($drop_tables)) {
  59. $drop_query = $wpdb->query("DROP TABLE $drop_tables");
  60. $text = '<font color="green">'.sprintf(__('Table(s) \'%s\' Dropped', 'wp-dbmanager'), $drop_tables).'</font>';
  61. }
  62. break;
  63. }
  64. }
  65. ### Show Tables
  66. $tables = $wpdb->get_col("SHOW TABLES");
  67. ?>
  68. <?php if(!empty($text)) { echo '<!-- Last Action --><div id="message" class="updated fade"><p>'.$text.'</p></div>'; } ?>
  69. <!-- Empty/Drop Tables -->
  70. <form method="post" action="<?php echo admin_url('admin.php?page='.plugin_basename(__FILE__)); ?>">
  71. <?php wp_nonce_field('wp-dbmanager_empty'); ?>
  72. <div class="wrap">
  73. <div id="icon-wp-dbmanager" class="icon32"><br /></div>
  74. <h2><?php _e('Empty/Drop Tables', 'wp-dbmanager'); ?></h2>
  75. <br style="clear" />
  76. <table class="widefat">
  77. <thead>
  78. <tr>
  79. <th><?php _e('Tables', 'wp-dbmanager'); ?></th>
  80. <th><?php _e('Empty', 'wp-dbmanager'); ?> <sup><?php _e('1', 'wp-dbmanager'); ?></sup></th>
  81. <th><?php _e('Drop', 'wp-dbmanager'); ?> <sup><?php _e('2', 'wp-dbmanager'); ?></sup></th>
  82. </tr>
  83. </thead>
  84. <?php
  85. foreach($tables as $table_name) {
  86. if($no%2 == 0) {
  87. $style = '';
  88. } else {
  89. $style = ' class="alternate"';
  90. }
  91. $no++;
  92. echo "<tr $style><th align=\"left\" scope=\"row\">$table_name</th>\n";
  93. 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>';
  94. 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>';
  95. }
  96. ?>
  97. <tr>
  98. <td colspan="3">
  99. <?php _e('1. EMPTYING a table means all the rows in the table will be deleted. This action is not REVERSIBLE.', 'wp-dbmanager'); ?>
  100. <br />
  101. <?php _e('2. DROPPING a table means deleting the table. This action is not REVERSIBLE.', 'wp-dbmanager'); ?>
  102. </td>
  103. </tr>
  104. <tr>
  105. <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>
  106. </tr>
  107. </table>
  108. </div>
  109. </form>