<?php
require ('authentication_manager.php');
?>
<?php

/* 删除数据表、建立删除索引 */
/* 162100源码 - 162100.com */


if (POWER != 5) {
  err('该命令必须以基本管理员身份登陆！请重登陆');
}

if (!isset($sql['db_err'])) {
  db_conn();
}
if ($sql['db_err'] != '') {
  err($sql['db_err']);
}
@ require ('inc/function/deldir.php');

if (!isset($sql['db_err'])) {
  db_conn();
}
if ($sql['db_err'] != '') {
  err($sql['db_err']);
}

if ($_GET['act'] == 'del_beifen') {
  if (empty($_GET['beifen']) || !file_exists($_GET['beifen'])) {
    err('<script> alert("备份源参数出错！"); </script>');
  }
  deldir($_GET['beifen']);
  if ($_GET['m'] == 1) {
    $tname = basename($_GET['beifen'], '.sql');
    err('<script>
  var allCheckBox = parent.document.getElementsByName("beifen_'.$tname.'");
  if (allCheckBox != null && allCheckBox.length > 0) {
    for (var i = 0; i < allCheckBox.length; i++) {
      if (allCheckBox[i] != null) {
        allCheckBox[i].innerHTML = "";
        allCheckBox[i].style.display = "none";
      }
    }
  }
  </script>');
  } else {
    alert('备份已删除！', '?get=sql');
  }
} else {

  $_GET['table'] = trim(trim($_GET['table']), '`');

  if ($_GET['act'] == 'empty') {
    $out .= '数据库表格['.$_GET['table'].']清空'.(@mysql_query('DELETE FROM '.$sql['pref'].''.$sql['data']['承载成员档案的表名'].' WHERE username<>"'.$web['manager'].'"', $db) ? '成功' : '失败').'！';
  } elseif ($_GET['act'] == 'index') {
    if ($_GET['table'] == $sql['data']['承载主题文章的表名']) {
      $eval_index .='@mysql_query(\'ALTER TABLE `'.$sql['pref'].''.$_GET['table'].'` ADD INDEX `area_id` (area_id)\') &&
	                 @mysql_query(\'ALTER TABLE `'.$sql['pref'].''.$_GET['table'].'` ADD INDEX `topdate` (topdate)\') &&
					 @mysql_query(\'ALTER TABLE `'.$sql['pref'].''.$_GET['table'].'` ADD INDEX `author_ip` (author_ip)\') &&
					 @mysql_query(\'ALTER TABLE `'.$sql['pref'].''.$_GET['table'].'` ADD INDEX `title_mark` (title_mark(5))\')';
    } elseif ($_GET['table'] == $sql['data']['承载关键词的表名']) {
      $eval_index .='@mysql_query(\'ALTER TABLE `'.$sql['pref'].''.$_GET['table'].'` ADD FULLTEXT INDEX `title` (title)\')';
    } elseif ($_GET['table'] == $sql['data']['承载成员档案的表名']) {
      $eval_index .='@mysql_query(\'ALTER TABLE `'.$sql['pref'].''.$_GET['table'].'` ADD UNIQUE `username_check_reg` (username,check_reg)\') &&
	                 @mysql_query(\'ALTER TABLE `'.$sql['pref'].''.$_GET['table'].'` ADD UNIQUE `email_check_reg` (email,check_reg)\')';
    } elseif ($_GET['table'] == $sql['data']['承载回复评论的表名']) {
      $eval_index .='@mysql_query(\'ALTER TABLE `'.$sql['pref'].''.$_GET['table'].'` ADD INDEX `r_id` (r_id)\') &&
	                 @mysql_query(\'ALTER TABLE `'.$sql['pref'].''.$_GET['table'].'` ADD INDEX `author_ip` (author_ip)\')';
    } elseif ($_GET['table'] == $sql['data']['承载财务数据的表名']) {
      $eval_index .='@mysql_query(\'ALTER TABLE `'.$sql['pref'].''.$_GET['table'].'` ADD INDEX `username` (username)\')';
    } elseif ($_GET['table'] == $sql['data']['承载在线统计的表名']) {
      $eval_index .='@mysql_query(\'ALTER TABLE `'.$sql['pref'].''.$_GET['table'].'` ADD UNIQUE `username` (username)\')';
    } elseif ($_GET['table'] == $sql['data']['承载版区分类的表名']) {
      $eval_index .='@mysql_query(\'ALTER TABLE `'.$sql['pref'].''.$_GET['table'].'` ADD UNIQUE `area_id` (area_id)\')';
    } elseif ($_GET['table'] == $sql['data']['承载上传数据的表名']) {
      $eval_index .='@mysql_query(\'ALTER TABLE `'.$sql['pref'].''.$_GET['table'].'` ADD UNIQUE `title` (title)\')';
    }
    $out .= '数据库表格['.$_GET['table'].']建立索引'.(eval('return '.$eval_index.';') ? '成功' : '失败（索引已存在）').'！';

  } elseif ($_GET['act'] == 'index_del') {
    if ($_GET['table'] == $sql['data']['承载主题文章的表名']) {
      $eval_index .='@mysql_query(\'ALTER TABLE `'.$sql['pref'].''.$_GET['table'].'` DROP INDEX `area_id`\') &&
	                 @mysql_query(\'ALTER TABLE `'.$sql['pref'].''.$_GET['table'].'` DROP INDEX `topdate`\') &&
					 @mysql_query(\'ALTER TABLE `'.$sql['pref'].''.$_GET['table'].'` DROP INDEX `author_ip`\') &&
					 @mysql_query(\'ALTER TABLE `'.$sql['pref'].''.$_GET['table'].'` DROP INDEX `title_mark`\')';

    } elseif ($_GET['table'] == $sql['data']['承载关键词的表名']) {
      $eval_index .='@mysql_query(\'ALTER TABLE `'.$sql['pref'].''.$_GET['table'].'` DROP INDEX `title`\')';
    } elseif ($_GET['table'] == $sql['data']['承载成员档案的表名']) {
      $eval_index .='@mysql_query(\'ALTER TABLE `'.$sql['pref'].''.$_GET['table'].'` DROP INDEX `username_check_reg`\') &&
	                 @mysql_query(\'ALTER TABLE `'.$sql['pref'].''.$_GET['table'].'` DROP INDEX `email_check_reg`\')';
    } elseif ($_GET['table'] == $sql['data']['承载回复评论的表名']) {
      $eval_index .='@mysql_query(\'ALTER TABLE `'.$sql['pref'].''.$_GET['table'].'` DROP INDEX `r_id`\') &&
	                 @mysql_query(\'ALTER TABLE `'.$sql['pref'].''.$_GET['table'].'` DROP INDEX `author_ip`\')';
    } elseif ($_GET['table'] == $sql['data']['承载财务数据的表名']) {
      $eval_index .='@mysql_query(\'ALTER TABLE `'.$sql['pref'].''.$_GET['table'].'` DROP INDEX `username`\')';
    } elseif ($_GET['table'] == $sql['data']['承载在线统计的表名']) {
      $eval_index .='@mysql_query(\'ALTER TABLE `'.$sql['pref'].''.$_GET['table'].'` DROP INDEX `username`\')';
    } elseif ($_GET['table'] == $sql['data']['承载版区分类的表名']) {
      $eval_index .='@mysql_query(\'ALTER TABLE `'.$sql['pref'].''.$_GET['table'].'` DROP INDEX `area_id`\')';
    } elseif ($_GET['table'] == $sql['data']['承载上传数据的表名']) {
      $eval_index .='@mysql_query(\'ALTER TABLE `'.$sql['pref'].''.$_GET['table'].'` DROP INDEX `title`\')';
    }
    $out .= '数据库表格['.$_GET['table'].']删除索引'.(eval('return '.$eval_index.';') ? '成功' : '失败（索引不存在）').'！';

  } elseif ($_GET['act'] == 'del') {
    $out .= '数据库表格['.$_GET['table'].']删除'.(@mysql_query('DROP TABLE IF EXISTS `'.$sql['pref'].''.$_GET['table'].'`') ? '成功' : '失败').'！';
  } else {
    err('参数错误！');
  }
}
@mysql_close();

err($out.'<a href="?get=sql">进入数据库参数管理</a>');


?>



