<?php
  ///////////////////////////////////////////////////
  //Оптимизация таблиц базы данных
  ///////////////////////////////////////////////////

  $lang = substr($_SERVER["HTTP_ACCEPT_LANGUAGE"], 0,2);
  if (is_file ("../lang/".$lang."/".$lang.".php")) include "../lang/".$lang."/".$lang.".php";
     else include "../lang/ru/ru.php";

  $title=$titlepage = $TEXT['optim-title'];
  $helppage=$TEXT['optim-help'];

  require_once "../config.php";
  require_once "../util/top_layer1.php";

  if($result2['administrator'] == 0) puterror2($TEXT['error-loginform2']);

  if(empty($_GET['tbl'])) $_GET['tbl'] = "no_table";
  if(strlen($_GET['tbl'])>30) puterror($TEXT['error-rep-tbl']);
  $_GET['tbl'] = rep($_GET['tbl']);
   $tbl = $_GET['tbl'];
   $i="";

    $tbls = mysql_query("SHOW TABLES FROM $dbname");
     while($all = mysql_fetch_array($tbls))
      {
      $i .=$all['0'].", ";
      }
     $all_tbls=substr($i, 0,-2);

     if($tbl !== "no_table") $opt_tbl = "`".$tbl."`";
    else $opt_tbl = $all_tbls;

?>
<table class="table" border="0" cellpadding="0" cellspacing="0" width="80%">
<tr><td>
<fieldset>
<legend align="left" title="<?php echo $TEXT['optim-tit2']; ?>"><?php echo $TEXT['optim_text']; ?></legend>
<table class="table" border="1" cellpadding="0" cellspacing="0" width="100%">
<?php
$dis_keys = mysql_query("ALTER TABLE DISABLE KEYS");
  $query = "OPTIMIZE TABLE $opt_tbl ";
     $result = mysql_query($query);
      if(!$result) puterror2($TEXT['error-optimize']);
?>
           <tr class="tableheadercat">
             <td><?php echo $TEXT['analiz-tab']; ?></td>
             <td><?php echo $TEXT['analiz-op']; ?></td>
             <td><?php echo $TEXT['analiz-msg-type']; ?></td>
             <td><?php echo $TEXT['analiz-msg-text']; ?></td>
           </tr>
<?php
       while($result_optimize = mysql_fetch_array($result))
              {
      $result_optimize1 = $result_optimize['Table'];
      $result_optimize2 = $result_optimize['Op'];
      $result_optimize3 = $result_optimize['Msg_type'];
      $result_optimize4 = $result_optimize['Msg_text'];
      ?>
           <tr class="tabledata" onmouseover="this.style.backgroundColor='#cccccc';" onmouseout="this.style.backgroundColor='#ffffff';">
              <td><?php echo $result_optimize1; ?></td>
              <td><?php echo $result_optimize2; ?></td>
              <td><?php echo $result_optimize3; ?></td>
              <td><?php echo $result_optimize4; ?></td>
           </tr>
      <?php
           //}
          //*************************************
          //Информация для лога
          $ip = $_SERVER['REMOTE_ADDR'];
          $doing = $TEXT['log-opt1'];
          $what = $TEXT['log-opt2'].$result_optimize1;
          $who = $result2['fullname'];
          //*************************************
          $query21 = "INSERT INTO tbl_logs ( `log_id` , `data` , `ip` , `who` , `doing` , `what` ) VALUES ( NULL , NOW() , '$ip' , '$who' , '$doing' , '$what')";
           if(!mysql_query($query21)) puterror2($TEXT['error-log']);
             }
   $en_keys = mysql_query("ALTER TABLE ENABLE KEYS");
?>
</table>
<table border="0" width="100%">
<tr align="right"><td class="catname"><a href=index.php title="<?php echo $TEXT['global-title6']; ?>"><?php echo $TEXT['btn_back']; ?></a></tr></td>
</table>
</fieldset>
</td></tr>
</table>
<?php
  require_once "../util/bottom.php";
?>
