<?php
  ///////////////////////////////////////////////////
  //2010 (C)
  //Карпухин Павел
  ///////////////////////////////////////////////////

  $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 = $TEXT['dboptim'];

require_once "../config_a.php";
require_once "../utils/functions.php";
require_once "../utils/top_adm.php";

if($result2['administrator'] == 0) {puterror($result2['skin'],$TEXT['error-loginform2']); require_once "../utils/bottom_adm.php"; exit();}

if(empty($_GET['tbl'])) {$_GET['tbl'] = "no_table";}
  if(strlen($_GET['tbl'])>30) {puterror($result2['skin'],$TEXT['error-rep-tbl']); require_once "../utils/bottom_adm.php"; exit();}
  $_GET['tbl'] = rep($_GET['tbl']);
   $tbl = $_GET['tbl'];

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

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

?>
<table align="center" 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 align="center" class="table" border="1" cellpadding="0" cellspacing="0" width="100%">
<?php
$dis_keys = mysqli_query($dbcnx,"ALTER TABLE DISABLE KEYS");
  $query = "OPTIMIZE TABLE $opt_tbl ";
     $result = mysqli_query($dbcnx,$query);
      if(!$result) {puterror($result2['skin'],$TEXT['error-optimize']); require_once "../utils/bottom_adm.php"; exit();}
?>
          <thead>
           <tr class='tableheadercat'>
             <td width="40%"><?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>
           </thead>
           <tbody id="tab">
<?php
       while($result_optimize = mysqli_fetch_array($result,MYSQLI_ASSOC))
       {
      $result_optimize1 = $result_optimize['Table'];
      $result_optimize2 = $result_optimize['Op'];
      $result_optimize3 = $result_optimize['Msg_type'];
      $result_optimize4 = $result_optimize['Msg_text'];
      ?>
           <tr>
              <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']."&nbsp;&rArr;&nbsp;&laquo;".$result_optimize1."&raquo;";
          $who = $result2['familiya']." ".$result2['name'];
          //*************************************
          $query21 = "INSERT INTO tbl_logs ( `log_id` , `data` , `ip` , `who` , `doing` , `what` ) VALUES ( NULL , NOW() , '$ip' , '$who' , '$doing' , '$what')";
           if(!mysqli_query($dbcnx,$query21)) {puterror($result2['skin'],$TEXT['error-log']); require_once "../utils/bottom_adm.php"; exit();}
          }
$en_keys = mysqli_query($dbcnx,"ALTER TABLE ENABLE KEYS");
?>
</tbody>
</table>
</fieldset>
</td></tr>
</table>
<?php
  require_once "../utils/bottom_adm.php";
?>