home *** CD-ROM | disk | FTP | other *** search
/ Cricao de Sites - 650 Layouts Prontos / WebMasters.iso / Plugins / wp-dbmanager / dbmanager / database-optimize.php < prev    next >
PHP Script  |  2008-02-19  |  3KB  |  94 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 Optimize                                                                |
  14. |    - wp-content/plugins/dbmanager/database-optimize.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.  
  30. ### Form Processing 
  31. if($_POST['do']) {
  32.     // Lets Prepare The Variables
  33.     $optimize = $_POST['optimize'];
  34.  
  35.     // Decide What To Do
  36.     switch($_POST['do']) {
  37.         case 'Optimize':
  38.             if(!empty($optimize)) {
  39.                 foreach($optimize as $key => $value) {
  40.                     if($value == 'yes') {
  41.                         $tables_string .=  ', '.$key;
  42.                     }
  43.                 }
  44.             } else {
  45.                 $text = '<font color="red">'.__('No Tables Selected', 'wp-dbmanager').'</font>';
  46.             }
  47.             $selected_tables = substr($tables_string, 2);
  48.             if(!empty($selected_tables)) {
  49.                 $optimize2 = $wpdb->query("OPTIMIZE TABLE $selected_tables");
  50.                 if(!$optimize2) {
  51.                     $text = '<font color="red">'.sprintf(__('Table(s) \'%s\' NOT Optimized', 'wp-dbmanager'), $selected_tables).'</font>';
  52.                 } else {
  53.                     $text = '<font color="green">'.sprintf(__('Table(s) \'%s\' Optimized', 'wp-dbmanager'), $selected_tables).'</font>';
  54.                 }
  55.             }
  56.             break;
  57.     }
  58. }
  59.  
  60.  
  61. ### Show Tables
  62. $tables = $wpdb->get_col("SHOW TABLES");
  63. ?>
  64. <?php if(!empty($text)) { echo '<!-- Last Action --><div id="message" class="updated fade"><p>'.$text.'</p></div>'; } ?>
  65. <!-- Optimize Database -->
  66. <div class="wrap">
  67.     <h2><?php _e('Optimize Database', 'wp-dbmanager'); ?></h2>
  68.     <form action="<?php echo $_SERVER['REQUEST_URI']; ?>" method="post">
  69.         <table width="100%" cellspacing="3" cellpadding="3" border="0">
  70.             <tr class="thead">
  71.                 <th align="left"><?php _e('Tables', 'wp-dbmanager'); ?></th>
  72.                 <th align="left"><?php _e('Options', 'wp-dbmanager'); ?></th>
  73.             </tr>
  74.                 <?php
  75.                     foreach($tables as $table_name) {
  76.                         if($no%2 == 0) {
  77.                             $style = 'style=\'background: none\'';                            
  78.                         } else {
  79.                             $style = 'style=\'background-color: #eee;\'';
  80.                         }
  81.                         $no++;
  82.                         echo "<tr $style><th align=\"left\" scope=\"row\">$table_name</th>\n";
  83.                         echo "<td><input type=\"radio\" name=\"optimize[$table_name]\" value=\"no\" />".__('No', 'wp-dbmanager')."   <input type=\"radio\" name=\"optimize[$table_name]\" value=\"yes\" checked=\"checked\" />".__('Yes', 'wp-dbmanager').'</td></tr>';
  84.                     }
  85.                 ?>
  86.             <tr>
  87.                 <td colspan="2" align="center"><?php _e('Database should be optimize once every month.', 'wp-dbmanager'); ?></td>
  88.             </tr>
  89.             <tr>
  90.                 <td colspan="2" align="center"><input type="submit" name="do" value="<?php _e('Optimize', 'wp-dbmanager'); ?>" class="button" />  <input type="button" name="cancel" value="<?php _e('Cancel', 'wp-dbmanager'); ?>" class="button" onclick="javascript:history.go(-1)" /></td>
  91.             </tr>
  92.         </table>
  93.     </form>
  94. </div>