home *** CD-ROM | disk | FTP | other *** search
/ Cricao de Sites - 650 Layouts Prontos / WebMasters.iso / Plugins / wp-dbmanager / dbmanager / database-empty.php < prev    next >
PHP Script  |  2008-02-19  |  4KB  |  110 lines

  1. <?php
  2. /*
  3. +----------------------------------------------------------------+
  4. |                                                                                            |
  5. |    WordPress 2.1 Plugin: WP-DBManager 2.20                                |
  6. |    Copyright (c) 2007 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/dbmanager/database-empty.php                |
  15. |                                                                                            |
  16. +----------------------------------------------------------------+
  17. */
  18.  
  19.  
  20. ### Check Whether User Can Manage Database
  21. if(!current_user_can('manage_database')) {
  22.     die('Access Denied');
  23. }
  24.  
  25.  
  26. ### Variables Variables Variables
  27. $base_name = plugin_basename('dbmanager/database-manager.php');
  28. $base_page = 'admin.php?page='.$base_name;
  29. $backup = array();
  30. $backup_options = get_option('dbmanager_options');
  31. $backup['date'] = current_time('timestamp');
  32. $backup['mysqldumppath'] = $backup_options['mysqldumppath'];
  33. $backup['mysqlpath'] = $backup_options['mysqlpath'];
  34. $backup['path'] = $backup_options['path'];
  35.  
  36.  
  37. ### Form Processing 
  38. if($_POST['do']) {
  39.     // Lets Prepare The Variables
  40.     $emptydrop = $_POST['emptydrop'];
  41.  
  42.     // Decide What To Do
  43.     switch($_POST['do']) {
  44.         case __('Empty/Drop', 'wp-dbmanager'):
  45.             $empty_tables = array();
  46.             if(!empty($emptydrop)) {
  47.                 foreach($emptydrop as $key => $value) {
  48.                     if($value == 'empty') {
  49.                         $empty_tables[] = $key;
  50.                     } elseif($value == 'drop') {
  51.                         $drop_tables .=  ', '.$key;
  52.                     }
  53.                 }
  54.             } else {
  55.                 $text = '<font color="red">'.__('No Tables Selected.', 'wp-dbmanager').'</font>';
  56.             }
  57.             $drop_tables = substr($drop_tables, 2);
  58.             if(!empty($empty_tables)) {
  59.                 foreach($empty_tables as $empty_table) {
  60.                     $empty_query = $wpdb->query("TRUNCATE $empty_table");
  61.                     $text .= '<font color="green">'.sprintf(__('Table \'%s\' Emptied', 'wp-dbmanager'), $empty_table).'</font><br />';
  62.                 }
  63.             }
  64.             if(!empty($drop_tables)) {
  65.                 $drop_query = $wpdb->query("DROP TABLE $drop_tables");
  66.                 $text = '<font color="green">'.sprintf(__('Table(s) \'%s\' Dropped', 'wp-dbmanager'), $drop_tables).'</font>';
  67.             }
  68.             break;
  69.     }
  70. }
  71.  
  72.  
  73. ### Show Tables
  74. $tables = $wpdb->get_col("SHOW TABLES");
  75. ?>
  76. <?php if(!empty($text)) { echo '<!-- Last Action --><div id="message" class="updated fade"><p>'.$text.'</p></div>'; } ?>
  77. <!-- Empty/Drop Tables -->
  78. <div class="wrap">
  79.     <h2><?php _e('Empty/Drop Tables', 'wp-dbmanager'); ?></h2>
  80.     <form action="<?php echo $_SERVER['REQUEST_URI']; ?>" method="post">
  81.         <table width="100%" cellspacing="3" cellpadding="3" border="0">
  82.             <tr class="thead">
  83.             <th align="left"><?php _e('Tables', 'wp-dbmanager'); ?></th>
  84.             <th align="left"><?php _e('Empty', 'wp-dbmanager'); ?></th>
  85.             <th align="left"><?php _e('Drop', 'wp-dbmanager'); ?></th>
  86.         </tr>
  87.                 <?php
  88.                     foreach($tables as $table_name) {
  89.                         if($no%2 == 0) {
  90.                             $style = 'style=\'background: none;\'';                            
  91.                         } else {
  92.                             $style = 'style=\'background-color: #eee;\'';
  93.                         }
  94.                         $no++;
  95.                         echo "<tr $style><th align=\"left\" scope=\"row\">$table_name</th>\n";
  96.                         echo "<td><input type=\"radio\" name=\"emptydrop[$table_name]\" value=\"empty\" /> ".__('Empty', 'wp-dbmanager').'</td>';
  97.                         echo "<td><input type=\"radio\" name=\"emptydrop[$table_name]\" value=\"drop\" /> ".__('Drop', 'wp-dbmanager').'</td></tr>';
  98.                     }
  99.                 ?>
  100.             <tr>
  101.                 <td colspan="3">
  102.                     <?php _e('1. DROPPING a table means deleting the table. This action is not REVERSIBLE.', 'wp-dbmanager'); ?><br />
  103.                     <?php _e('2. EMPTYING a table means all the rows in the table will be deleted. This action is not REVERSIBLE.', 'wp-dbmanager'); ?></td>
  104.             </tr>
  105.             <tr>
  106.                 <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'); ?>')" />  <input type="button" name="cancel" value="<?php _e('Cancel', 'wp-dbmanager'); ?>" class="button" onclick="javascript:history.go(-1)" /></td>
  107.             </tr>
  108.         </table>
  109.     </form>
  110. </div>