home *** CD-ROM | disk | FTP | other *** search
/ PC World 2005 April / PCWorld_2005-04_cd.bin / akce / web / unitednuke / unitednuke.exe / html / admin / modules / optimize.php < prev    next >
PHP Script  |  2004-01-10  |  4KB  |  87 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", $_SERVER['PHP_SELF'])) { die ("Access Denied"); }
  18. global $prefix, $db;
  19. $aid = substr(trim($aid), 0,25);
  20. $row = $db->sql_fetchrow($db->sql_query("SELECT name, radminsuper FROM ".$prefix."_authors WHERE aid='$aid'"));
  21. $name = $row['name'];
  22. $radminsuper = $row['radminsuper'];
  23.  
  24. include("header.php");
  25. GraphicAdmin();
  26. title(""._DBOPTIMIZATION."");
  27. OpenTable();
  28.  
  29. if ($radminsuper==1) {
  30.         
  31.     echo "<center><font class=\"title\">"._OPTIMIZINGDB." $dbname</font></center><br><br>"
  32.     ."<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>";
  33.     $db_clean = $dbname;
  34.     $tot_data = 0;
  35.     $tot_idx = 0;
  36.     $tot_all = 0;
  37.     $local_query = 'SHOW TABLE STATUS FROM '.$dbname;
  38.     $result = @sql_query($local_query, $dbi);
  39.     if (@sql_num_rows($result, $dbi)) {
  40.     while ($row = sql_fetch_array($result, $dbi)) {
  41.             $tot_data = $row['Data_length'];
  42.             $tot_idx  = $row['Index_length'];
  43.             $total = $tot_data + $tot_idx;
  44.             $total = $total / 1024 ;
  45.             $total = round ($total,3);
  46.             $gain= $row['Data_free'];
  47.             $gain = $gain / 1024 ;
  48.             $total_gain += $gain;
  49.             $gain = round ($gain,3);   
  50.             $local_query = 'OPTIMIZE TABLE '.$row[0];
  51.         $resultat  = sql_query($local_query, $dbi);
  52.                if ($gain == 0) {
  53.                echo "<tr><td>"."$row[0]"."</td>"."<td>"."$total"." Kb"."</td>"."<td>"._ALREADYOPTIMIZED."</td><td>0 Kb</td></tr>";
  54.                } else {
  55.                   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>";
  56.                }        
  57.     } 
  58.     }
  59.     echo "</table>";
  60.     echo "</center>";
  61.     CloseTable();
  62.     echo "<br>";
  63.     OpenTable();
  64.     $total_gain = round ($total_gain,3);
  65.     echo "<center><b>"._OPTIMIZATIONRESULTS."</b><br><br>"
  66.     .""._TOTALSPACESAVED." "."$total_gain"." Kb<br>";
  67.     
  68.     $sql_query = "CREATE TABLE IF NOT EXISTS ".$prefix."_optimize_gain(gain decimal(10,3))";  
  69.     $result = @sql_query($sql_query, $dbi);
  70.        
  71.     $sql_query = "INSERT INTO ".$prefix."_optimize_gain (gain) VALUES ('$total_gain')";
  72.     $result = @sql_query($sql_query, $dbi);
  73.        
  74.     $sql_query = "SELECT * FROM ".$prefix."_optimize_gain";
  75.     $result = sql_query ($sql_query, $dbi);
  76.     while ($row = sql_fetch_row($result, $dbi)) {
  77.     $histo += $row[0];
  78.     $cpt += 1;
  79.     }
  80.  
  81.     echo ""._YOUHAVERUNSCRIPT." $cpt "._TIMES."<br>"
  82.     ."$histo "._KBSAVED."</center>";
  83.     CloseTable();
  84.     include("footer.php");     
  85. }
  86.  
  87. ?>