Changeset 4931

Show
Ignore:
Timestamp:
02/04/06 18:19:20 (2 years ago)
Author:
GamerZ
Message:

Updated database-manager.php

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • wp-dbmanager/trunk/database-manager.php

    r4876 r4931  
    4949### Format Bytes Into KB/MB 
    5050function format_size($rawSize) { 
    51       if ($rawSize / 1048576 > 1) 
     51      if($rawSize / 1073741824 > 1)  
     52            return round($rawSize/1048576, 1) . ' GB'; 
     53      else if ($rawSize / 1048576 > 1) 
    5254            return round($rawSize/1048576, 1) . ' MB'; 
    5355      else if ($rawSize / 1024 > 1) 
     
    5557      else 
    5658            return round($rawSize, 1) . ' bytes'; 
     59} 
     60 
     61 
     62### Get File Extension 
     63function file_ext($file_name) { 
     64      return substr(strrchr($file_name, '.'), 1); 
    5765} 
    5866 
     
    8492      $database_file = trim($_POST['database_file']); 
    8593      $optimize = $_POST['optimize']; 
     94      $emptydrop = $_POST['emptydrop']; 
    8695      $delete = $_POST['delete']; 
    8796      $nice_file_date = date('l, jS F Y @ H:i', substr($database_file, 0, 10)); 
     
    152161                  if(!empty($database_file)) { 
    153162                        $file_path = $backup['path'].'/'.$database_file; 
    154                         $nice_file_name = date('jS_F_Y', substr($database_file, 0, 10)).'-'.substr($database_file, 13); 
     163                        //$nice_file_name = date('jS_F_Y', substr($database_file, 0, 10)).'-'.substr($database_file, 13); 
    155164                        header("Pragma: public"); 
    156165                        header("Expires: 0"); 
     
    159168                        header("Content-Type: application/octet-stream"); 
    160169                        header("Content-Type: application/download"); 
    161                         header("Content-Disposition: attachment; filename=".basename($nice_file_name).";"); 
     170                        header("Content-Disposition: attachment; filename=".basename($database_file).";"); 
    162171                        header("Content-Transfer-Encoding: binary"); 
    163172                        header("Content-Length: ".filesize($file_path)); 
     
    168177                  break; 
    169178            case 'Optimize': 
    170                   foreach($optimize as $key => $value) { 
    171                         if($value == 'yes') { 
    172                               $tables_string .=  ', '.$key; 
    173                         } 
     179                  if(!empty($optimize)) { 
     180                        foreach($optimize as $key => $value) { 
     181                              if($value == 'yes') { 
     182                                    $tables_string .=  ', '.$key; 
     183                              } 
     184                        } 
     185                  } else { 
     186                        $text = '<font color="red">No Tables Selected</font>'; 
    174187                  } 
    175188                  $selected_tables = substr($tables_string, 2); 
     
    177190                        $optimize2 = $wpdb->query("OPTIMIZE TABLE $selected_tables"); 
    178191                        if(!$optimize2) { 
    179                               $text = "<font color=\"red\">Table(s) '$selected_tables' Failed To Be Optimized</font>"; 
     192                              $text = "<font color=\"red\">Table(s) '$selected_tables' NOT Optimized</font>"; 
    180193                        } else { 
    181                               $text = "<font color=\"green\">Table(s) '$selected_tables' Optimized Successfully</font>"; 
    182                         } 
    183                   } else { 
    184                         $text = '<font color="red">No Tables Selected</font>'; 
     194                              $text = "<font color=\"green\">Table(s) '$selected_tables' Optimized</font>"; 
     195                        } 
    185196                  } 
    186197                  break; 
     
    201212                        if($sql_queries) { 
    202213                              foreach($sql_queries as $sql_query) {                  
    203                                     if (preg_match("/^\\s*(insert|update|replace|delete|create) /i",$sql_query)) { 
     214                                    if (preg_match("/^\\s*(insert|update|replace|delete|create|alter) /i",$sql_query)) { 
    204215                                          $run_query = $wpdb->query($sql_query); 
    205216                                          if(!$run_query) { 
     
    223234                  } 
    224235                  break; 
     236            case 'Empty/Drop': 
     237                  $empty_tables = array(); 
     238                  if(!empty($emptydrop)) { 
     239                        foreach($emptydrop as $key => $value) { 
     240                              if($value == 'empty') { 
     241                                    $empty_tables[] = $key; 
     242                              } elseif($value == 'drop') { 
     243                                    $drop_tables .=  ', '.$key; 
     244                              } 
     245                        } 
     246                  } else { 
     247                        $text = '<font color="red">No Tables Selected</font>'; 
     248                  } 
     249                  $drop_tables = substr($drop_tables, 2); 
     250                  if(!empty($empty_tables)) { 
     251                        foreach($empty_tables as $empty_table) { 
     252                              $empty_query = $wpdb->query("TRUNCATE $empty_table"); 
     253                              $text .= "<font color=\"green\">Table '$empty_table' Emptied</font><br />"; 
     254                        } 
     255                  } 
     256                  if(!empty($drop_tables)) { 
     257                        $drop_query = $wpdb->query("DROP TABLE $drop_tables"); 
     258                        $text = "<font color=\"green\">Table(s) '$drop_tables' Dropped</font>"; 
     259                  } 
     260                  break; 
    225261      } 
    226262} 
     
    241277                  <li><a href="database-manager.php?mode=restore"><?php _e('Restore/Download DB'); ?></a></li>  
    242278                  <li><a href="database-manager.php?mode=delete"><?php _e('Delete Backup DB'); ?></a></li> 
    243                   <li class="last"><a href="database-manager.php?mode=run"><?php _e('Run SQL Query'); ?></a></li> 
     279                  <li><a href="database-manager.php?mode=run"><?php _e('Run SQL Query'); ?></a></li> 
     280                  <li class="last"><a href="database-manager.php?mode=empty"><?php _e('Empty/Drop Tables'); ?></a></li> 
    244281            </ul> 
     282            <?php if(!empty($text)) { echo '<!-- Last Action --><div id="message" class="updated fade"><p>'.$text.'</p></div>'; } ?> 
    245283            <!-- Backup Database --> 
    246284            <div class="wrap"> 
    247285                  <h2>Backup Database</h2> 
    248                   <form action="<?=$_SERVER['PHP_SELF']?>" method="post"> 
     286                  <form action="<?php echo $_SERVER['PHP_SELF']; ?>?mode=backup" method="post"> 
    249287                  <table width="100%" cellspacing="3" cellpadding="3" border="0"> 
    250288                        <tr style='background-color: #eee'> 
    251289                              <th align="left" scope="row">Database Name:</th> 
    252                               <td><?=DB_NAME?></td> 
     290                              <td><?php echo DB_NAME; ?></td> 
    253291                        </tr> 
    254292                        <tr style='background-color: none'> 
    255293                              <th align="left" scope="row">Database Backup To:</th> 
    256                               <td><?=$backup['path']?></td> 
     294                              <td><?php echo $backup['path']; ?></td> 
    257295                        </tr> 
    258296                        <tr style='background-color: #eee'> 
    259297                              <th align="left" scope="row">Database Backup Date:</th> 
    260                               <td><?=date('jS F Y', $backup['date'])?></td> 
     298                              <td><?php echo date('jS F Y', $backup['date']); ?></td> 
    261299                        </tr> 
    262300                        <tr style='background-color: none'> 
    263301                              <th align="left" scope="row">Database Backup File Name:</th> 
    264                               <td><?=$backup['filename']?> / <?=date('jS_F_Y', substr($backup['filename'], 0, 10)).'-'.substr($backup['filename'], 13);?></td> 
     302                              <td><?php echo $backup['filename']; ?></td> 
    265303                        </tr> 
    266304                        <tr style='background-color: #eee'> 
     
    270308                        <tr style='background-color: none'> 
    271309                              <th align="left" scope="row">MYSQL Dump Location</th> 
    272                               <td><?=$backup['mysqldumppath']?></td> 
     310                              <td><?php echo $backup['mysqldumppath']; ?></td> 
    273311                        </tr> 
    274312                        <tr style='background-color: #eee'> 
     
    296334                  <li><a href="database-manager.php?mode=restore"><?php _e('Restore/Download DB'); ?></a></li>  
    297335                  <li><a href="database-manager.php?mode=delete"><?php _e('Delete Backup DB'); ?></a></li> 
    298                   <li class="last"><a href="database-manager.php?mode=run"><?php _e('Run SQL Query'); ?></a></li> 
     336                  <li><a href="database-manager.php?mode=run"><?php _e('Run SQL Query'); ?></a></li> 
     337                  <li class="last"><a href="database-manager.php?mode=empty"><?php _e('Empty/Drop Tables'); ?></a></li> 
    299338            </ul> 
     339            <?php if(!empty($text)) { echo '<!-- Last Action --><div id="message" class="updated fade"><p>'.$text.'</p></div>'; } ?> 
    300340            <!-- Optimize Database --> 
    301341            <div class="wrap"> 
    302342                  <h2>Optimize Database</h2> 
    303                   <form action="<?=$_SERVER['PHP_SELF']?>" method="post"> 
     343                  <form action="<?php echo $_SERVER['PHP_SELF']; ?>?mode=optimize" method="post"> 
    304344                        <table width="100%" cellspacing="3" cellpadding="3" border="0"> 
    305345                              <tr> 
     
    343383                  <li><a href="database-manager.php?mode=restore" class="current"><?php _e('Restore/Download DB'); ?></a></li>  
    344384                  <li><a href="database-manager.php?mode=delete"><?php _e('Delete Backup DB'); ?></a></li> 
    345                   <li class="last"><a href="database-manager.php?mode=run"><?php _e('Run SQL Query'); ?></a></li> 
     385                  <li><a href="database-manager.php?mode=run"><?php _e('Run SQL Query'); ?></a></li> 
     386                  <li class="last"><a href="database-manager.php?mode=empty"><?php _e('Empty/Drop Tables'); ?></a></li> 
    346387            </ul> 
     388            <?php if(!empty($text)) { echo '<!-- Last Action --><div id="message" class="updated fade"><p>'.$text.'</p></div>'; } ?> 
    347389            <!-- Restore/Download Database --> 
    348390            <div class="wrap"> 
    349391                  <h2>Restore/Download Database</h2> 
    350                   <form action="<?=$_SERVER['PHP_SELF']?>" method="post"> 
     392                  <form action="<?php echo $_SERVER['PHP_SELF']; ?>?mode=restore" method="post"> 
    351393                        <table width="100%" cellspacing="3" cellpadding="3" border="0"> 
    352394                              <tr> 
     
    365407                                                $database_files = array(); 
    366408                                                while (false !== ($file = readdir($handle))) {  
    367                                                       if ($file != '.' && $file != '..') { 
     409                                                      if ($file != '.' && $file != '..' && (file_ext($file) == 'sql' || file_ext($file) == 'gz')) { 
    368410                                                            $database_files[] = $file; 
    369411                                                      }  
     
    396438                              </tr> 
    397439                              <tr> 
    398                                     <th align="left" colspan="3"><?=$no?> Backup File(s)</th> 
    399                                     <th align="left"><?=format_size($totalsize)?></th> 
     440                                    <th align="left" colspan="3"><?php echo $no; ?> Backup File(s)</th> 
     441                                    <th align="left"><?php echo format_size($totalsize); ?></th> 
    400442                                    <td>&nbsp;</td> 
    401443                              </tr> 
     
    419461                  <li><a href="database-manager.php?mode=restore"><?php _e('Restore/Download DB'); ?></a></li>  
    420462                  <li><a href="database-manager.php?mode=delete" class="current"><?php _e('Delete Backup DB'); ?></a></li> 
    421                   <li class="last"><a href="database-manager.php?mode=run"><?php _e('Run SQL Query'); ?></a></li> 
     463                  <li><a href="database-manager.php?mode=run"><?php _e('Run SQL Query'); ?></a></li> 
     464                  <li class="last"><a href="database-manager.php?mode=empty"><?php _e('Empty/Drop Tables'); ?></a></li> 
    422465            </ul> 
     466            <?php if(!empty($text)) { echo '<!-- Last Action --><div id="message" class="updated fade"><p>'.$text.'</p></div>'; } ?> 
    423467            <!-- Delete Database Backup Files --> 
    424468            <div class="wrap"> 
    425469                  <h2>Delete Database Backup Files</h2> 
    426                   <form action="<?=$_SERVER['PHP_SELF']?>" method="post"> 
     470                  <form action="<?php echo $_SERVER['PHP_SELF']; ?>?mode=delete" method="post"> 
    427471                        <table width="100%" cellspacing="3" cellpadding="3" border="0"> 
    428472                              <tr> 
     
    441485                                                $database_files = array(); 
    442486                                                while (false !== ($file = readdir($handle))) {  
    443                                                       if ($file != '.' && $file != '..') {  
     487                                                      if ($file != '.' && $file != '..'  && (file_ext($file) == 'sql' || file_ext($file) == 'gz')) {  
    444488                                                            $database_files[] = $file; 
    445489                                                      }  
     
    472516                              </tr> 
    473517                              <tr> 
    474                                     <th align="left" colspan="3"><?=$no?> Backup File(s)</th> 
    475                                     <th align="left"><?=format_size($totalsize)?></th> 
     518                                    <th align="left" colspan="3"><?php echo $no; ?> Backup File(s)</th> 
     519                                    <th align="left"><?php echo format_size($totalsize); ?></th> 
    476520                                    <td>&nbsp;</td> 
    477521                              </tr> 
     
    495539                  <li><a href="database-manager.php?mode=restore"><?php _e('Restore/Download DB'); ?></a></li>  
    496540                  <li><a href="database-manager.php?mode=delete"><?php _e('Delete Backup DB'); ?></a></li> 
    497                   <li class="last"><a href="database-manager.php?mode=run" class="current"><?php _e('Run SQL Query'); ?></a></li> 
     541                  <li><a href="database-manager.php?mode=run" class="current"><?php _e('Run SQL Query'); ?></a></li> 
     542                  <li class="last"><a href="database-manager.php?mode=empty"><?php _e('Empty/Drop Tables'); ?></a></li> 
    498543            </ul> 
     544            <?php if(!empty($text)) { echo '<!-- Last Action --><div id="message" class="updated fade"><p>'.$text.'</p></div>'; } ?> 
    499545            <!-- Run SQL Query --> 
    500546            <div class="wrap"> 
    501547                  <h2>Run SQL Query</h2> 
    502                   <form action="<?=$_SERVER['PHP_SELF']?>" method="post"> 
    503                         <p><b>Seperate Multiple Queries With A New Line</b><br /><font color="green">Use Only INSERT, UPDATE, REPLACE, DELETE and CREATE statements.</font></p> 
     548                  <form action="<?php echo $_SERVER['PHP_SELF']; ?>?mode=run" method="post"> 
     549                        <p><b>Seperate Multiple Queries With A New Line</b><br /><font color="green">Use Only INSERT, UPDATE, REPLACE, DELETE, CREATE and ALTER statements.</font></p> 
    504550                        <p align="center"><textarea cols="150" rows="30" name="sql_query"></textarea></p> 
    505551                        <p align="center"><input type="submit" name="do" Value="Run" class="button">&nbsp;&nbsp;<input type="submit" name="cancel" Value="Cancel" class="button"></p> 
    506                         <p>1. CREATE statement will return an error, which is perfectly normal due to the database class. To confirm that your table has been created check the Manage Database page.<br />2. UPDATE statement may return an error sometimes due to the newly updated value being the same as the previous value.</font></p> 
     552                        <p>1. CREATE statement will return an error, which is perfectly normal due to the database class. To confirm that your table has been created check the Manage Database page.<br />2. UPDATE statement may return an error sometimes due to the newly updated value being the same as the previous value.<br />3. ALTER statement will return an error because there is no value returned.</font></p> 
     553                  </form> 
     554            </div> 
     555<?php 
     556            break; 
     557      // Empty/Drop Tables 
     558      case 'empty': 
     559            $title = __('Empty/Drop Tables'); 
     560            require("./admin-header.php"); 
     561            $tables = $wpdb->get_results("SHOW TABLES"); 
     562?>          <!-- Drop/Empty Tables --> 
     563            <ul id="submenu">  
     564                  <li><a href="database-manager.php"><?php _e('Manage Database'); ?></a></li>  
     565                  <li><a href="database-manager.php?mode=backup"><?php _e('Backup DB'); ?></a></li> 
     566                  <li><a href="database-manager.php?mode=optimize"><?php _e('Optimize DB'); ?></a></li> 
     567                  <li><a href="database-manager.php?mode=restore"><?php _e('Restore/Download DB'); ?></a></li>  
     568                  <li><a href="database-manager.php?mode=delete"><?php _e('Delete Backup DB'); ?></a></li> 
     569                  <li><a href="database-manager.php?mode=run"><?php _e('Run SQL Query'); ?></a></li> 
     570                  <li class="last"><a href="database-manager.php?mode=empty" class="current"><?php _e('Empty/Drop Tables'); ?></a></li> 
     571            </ul> 
     572            <?php if(!empty($text)) { echo '<!-- Last Action --><div id="message" class="updated fade"><p>'.$text.'</p></div>'; } ?> 
     573            <!-- Empty/Drop Tables --> 
     574            <div class="wrap"> 
     575                  <h2>Empty/Drop Tables</h2> 
     576                  <form action="<?php echo $_SERVER['PHP_SELF']; ?>?mode=empty" method="post"> 
     577                        <table width="100%" cellspacing="3" cellpadding="3" border="0"> 
     578                              <tr> 
     579                              <th align="left" scope="col">Tables</th> 
     580                              <th align="left" scope="col">Empty</th> 
     581                              <th align="left" scope="col">Drop</th> 
     582                        </tr> 
     583                                    <?php 
     584                                          foreach($tables as $dbtable) { 
     585                                                if($no%2 == 0) { 
     586                                                      $style = 'style=\'background-color: #eee\''; 
     587                                                } else { 
     588                                                      $style = 'style=\'background-color: none\''; 
     589                                                } 
     590                                                $no++; 
     591                                                $table_name = '$dbtable->Tables_in_'.DB_NAME; 
     592                                                eval("\$table_name = \"$table_name\";"); 
     593                                                echo "<tr $style><th align=\"left\" scope=\"row\">$table_name</th>\n"; 
     594                                                echo "<td><input type=\"radio\" name=\"emptydrop[$table_name]\" value=\"empty\">&nbsp;Empty</td>"; 
     595                                                echo "<td><input type=\"radio\" name=\"emptydrop[$table_name]\" value=\"drop\">&nbsp;Drop</td></tr>"; 
     596                                          } 
     597                                    ?> 
     598                              <tr> 
     599                                    <td colspan="3">1. DROPPING a table means deleting the table. This action is not REVERSIBLE.<br />2. EMPTYING a table means all the rows in the table will be deleted. This action is not REVERSIBLE.</td> 
     600                              </tr> 
     601                              <tr> 
     602                                    <td colspan="3" align="center"><input type="submit" name="do" value="Empty/Drop" class="button" onclick="return confirm('You Are About To Empty Or Drop The Selected Databases.\nThis Action Is Not Reversible.\n\n Choose \'Cancel\' to stop, \'OK\' to delete.')">&nbsp;&nbsp;<input type="submit" name="cancel" Value="Cancel" class="button"></td> 
     603                              </tr> 
     604                        </table> 
    507605                  </form> 
    508606            </div> 
     
    522620                  <li><a href="database-manager.php?mode=restore"><?php _e('Restore/Download DB'); ?></a></li>  
    523621                  <li><a href="database-manager.php?mode=delete"><?php _e('Delete Backup DB'); ?></a></li> 
    524                   <li class="last"><a href="database-manager.php?mode=run"><?php _e('Run SQL Query'); ?></a></li> 
     622                  <li><a href="database-manager.php?mode=run"><?php _e('Run SQL Query'); ?></a></li> 
     623                  <li class="last"><a href="database-manager.php?mode=empty" class="current"><?php _e('Empty/Drop Tables'); ?></a></li> 
    525624            </ul> 
    526625            <?php if(!empty($text)) { echo '<!-- Last Action --><div id="message" class="updated fade"><p>'.$text.'</p></div>'; } ?> 
  • wp-dbmanager/trunk/readme-upgrade.txt

    r4819 r4931  
    1 -> Upgrade Instructions For Version 2.00 To Version 2.01 
     1-> Upgrade Instructions For Version 2.0x To Version 2.02 
    22------------------------------------------------------------------ 
    33// Open wp-admin folder 
  • wp-dbmanager/trunk/readme.txt

    r4876 r4931  
    1313// Version 2.02 (01-03-2006) 
    1414- NEW: Improved On 'manage_database' Capabilities 
     15- NEW: Added GigaBytes To File Size 
     16- NEW: Added ALTER Statement To Allowed Queries 
     17- NEW: Able To Empty/Drop Tables 
    1518- FIXED: PHP Short Tags 
     19- FIXED: Redirect Back To The Same Page Instead Of Manage Database Page After Submitting Form 
    1620 
    1721// Version 2.01 (01-02-2006)