<?php

include("../includes/site_config.php");
include('../session_handler.inc');/*
if ($Sess_UserType != "A") {
        exit;
}*/

$message = "";

if (isset($_POST["optimize"])) {
    $query = "SHOW TABLE STATUS";
//    echo $query;
    $result=mysql_query($query, $link);
    $table_list = "";
    while ($cur_table = mysql_fetch_object($result)) {
        $table_list .= $cur_table->Name.", ";
//        echo $cur_table->Name;
    }

    if (!empty($table_list)) {
//    echo $table_list."!!!!";
        $table_list = substr($table_list, 0, -2);
//    echo $table_list;
        $query = "OPTIMIZE TABLE ".$table_list;
        mysql_query($query, $link);
//        echo $query;
        $message = DB_OPTIMIZE_SUCCESS;
    }
}

# retrieve the template
$area = 'member';

?>
<?php include("include/header.php"); ?>
<table width="<?php print("$CONST_TABLE_WIDTH"); ?>" align="<?php print("$CONST_TABLE_ALIGN"); ?>" border="0" cellspacing="<?php print("$CONST_TABLE_CELLSPACING"); ?>" cellpadding="<?php print("$CONST_TABLE_CELLPADDING"); ?>">
  <tr>
    <td align="right">
      <?php 	  //require_once("$CONST_INCLUDE_ROOT/user_status.inc.php");	  require_once("../user_status.inc.php");	  ?>
    </td>
  </tr>
  <tr>
    <td class="pageheader"><?php echo DB_OPTIMIZE_SECTION_NAME ?></td>
  </tr>
  <tr>
    <td><?php echo DB_OPTIMIZE_TEXT?></td>
  </tr>
  <tr>
    <td>
        <table width="100%"  border="0" cellpadding="<?php print("$CONST_SUBTABLE_CELLPADDING"); ?>" cellspacing="<?php print("$CONST_SUBTABLE_CELLSPACING"); ?>">
        <form action="<?php echo $CONST_LINK_ROOT?>admin/admin_db_optimize.php?<?php echo $sess_id ?>" method="post" name="frmEmails">
        <input type="hidden" name="optimize" value="yes">
        <?
        if (!empty($message)) {
            echo '<tr><td colspan="2" class="tdhead">'.$message.'</td></tr>';
        }
        ?>
          <tr align="center">
            <td colspan="2" class="tdfoot"> <input name="Submit" type="submit" class="button" value="<?php echo DB_OPTIMIZE_BUTTON?>">
            </td>
          </tr>
        </form>
      </table></td>
  </tr>
</table>
<?php include("include/footer.php"); ?>