home *** CD-ROM | disk | FTP | other *** search
/ Internet Magazine 2003 May / INTERNET103.ISO / pc / software / windows / building / php_nuke / html / admin / modules / optimize.php < prev    next >
Encoding:
PHP Script  |  2002-09-16  |  3.5 KB  |  84 lines

  1. <?php
  2.  
  3. /************************************************************************/
  4. /* PHP-NUKE: Web Portal System                                          */
  5. /* ===========================                                          */
  6. /*                                                                      */
  7. /* Optimize your database                                               */
  8. /*                                                                      */
  9. /* Copyright (c) 2001 by Xavier JULIE (webmaster@securite-internet.org  */
  10. /* http://www.securite-internet.org                                     */
  11. /*                                    */
  12. /* This program is free software. You can redistribute it and/or modify */
  13. /* it under the terms of the GNU General Public License as published by */
  14. /* the Free Software Foundation; either version 2 of the License.       */
  15. /************************************************************************/
  16.  
  17. if (!eregi("admin.php", $PHP_SELF)) { die ("Access Denied"); }
  18. $result = sql_query("select name, radminsuper from ".$prefix."_authors where aid='$aid'", $dbi);
  19. list($name, $radminsuper) = sql_fetch_row($result, $dbi);
  20.  
  21. include("header.php");
  22. GraphicAdmin();
  23. title(""._DBOPTIMIZATION."");
  24. OpenTable();
  25.  
  26. if ($radminsuper==1) {   
  27.         
  28.     echo "<center><font class=\"title\">"._OPTIMIZINGDB." $dbname</font></center><br><br>"
  29.     ."<table border=1 align=\"center\"><tr><td><div align=center>"._TABLE."</div></td><td><div align=center>"._SIZE."</div></td><td><div align=center>"._STATUS."</div></td><td><div align=center>"._SPACESAVED."</div></td></tr>";
  30.     $db_clean = $dbname;
  31.     $tot_data = 0;
  32.     $tot_idx = 0;
  33.     $tot_all = 0;
  34.     $local_query = 'SHOW TABLE STATUS FROM '.$dbname;
  35.     $result = @sql_query($local_query, $dbi);
  36.     if (@sql_num_rows($result, $dbi)) {
  37.     while ($row = sql_fetch_array($result, $dbi)) {
  38.             $tot_data = $row['Data_length'];
  39.             $tot_idx  = $row['Index_length'];
  40.             $total = $tot_data + $tot_idx;
  41.             $total = $total / 1024 ;
  42.             $total = round ($total,3);
  43.             $gain= $row['Data_free'];
  44.             $gain = $gain / 1024 ;
  45.             $total_gain += $gain;
  46.             $gain = round ($gain,3);   
  47.             $local_query = 'OPTIMIZE TABLE '.$row[0];
  48.         $resultat  = sql_query($local_query, $dbi);
  49.                if ($gain == 0) {
  50.                echo "<tr><td>"."$row[0]"."</td>"."<td>"."$total"." Kb"."</td>"."<td>"._ALREADYOPTIMIZED."</td><td>0 Kb</td></tr>";
  51.                } else {
  52.                   echo "<tr><td><b>"."$row[0]"."</b></td>"."<td><b>"."$total"." Kb"."</b></td>"."<td><b>"._OPTIMIZED."</b></td><td><b>"."$gain"." Kb</b></td></tr>";
  53.                }        
  54.     } 
  55.     }
  56.     echo "</table>";
  57.     echo "</center>";
  58.     CloseTable();
  59.     echo "<br>";
  60.     OpenTable();
  61.     $total_gain = round ($total_gain,3);
  62.     echo "<center><b>"._OPTIMIZATIONRESULTS."</b><br><br>"
  63.     .""._TOTALSPACESAVED." "."$total_gain"." Kb<br>";
  64.     
  65.     $sql_query = "CREATE TABLE IF NOT EXISTS ".$prefix."_optimize_gain(gain decimal(10,3))";  
  66.     $result = @sql_query($sql_query, $dbi);
  67.        
  68.     $sql_query = "INSERT INTO ".$prefix."_optimize_gain (gain) VALUES ('$total_gain')";
  69.     $result = @sql_query($sql_query, $dbi);
  70.        
  71.     $sql_query = "SELECT * FROM ".$prefix."_optimize_gain";
  72.     $result = sql_query ($sql_query, $dbi);
  73.     while ($row = sql_fetch_row($result, $dbi)) {
  74.     $histo += $row[0];
  75.     $cpt += 1;
  76.     }
  77.  
  78.     echo ""._YOUHAVERUNSCRIPT." $cpt "._TIMES."<br>"
  79.     ."$histo "._KBSAVED."</center>";
  80.     CloseTable();
  81.     include("footer.php");     
  82. }
  83.  
  84. ?>