<?php
require("../../class/connect.php");
include("../../class/config.php");
include("../../class/db_sql.php");
include("../../class/functions.php");
include("class/functions.php");
$link=db_connect();
$empire=new mysqlquery();
//验证用户
$logininid=getcvar('loginuserid');
$loginin=getcvar('loginusername');
$loginrnd=getcvar('loginrnd');
$loginlevel=getcvar('loginlevel');
is_login($logininid,$loginin,$loginrnd);
//验证权限
CheckLevel($logininid,$loginin,$classid,"dbdata");
$bakpath=$public_r['bakdbpath'];
$mydbname=$_GET['mydbname'];
if(empty($mydbname))
{
	printerror("NotChangeBakTable","history.go(-1)");
}
//选择数据库
$udb=$empire->query("use ".$mydbname);
//查询
$and="";
$keyboard=RepPostVar($_GET['keyboard']);
$sear=$_GET['sear'];
if(empty($sear))
{
	$keyboard=$dbtbpre;
}
if($keyboard)
{
	$and=" LIKE '%$keyboard%'";
}
$sql=$empire->query("SHOW TABLE STATUS".$and);
//存放目录
$mypath=$mydbname."_".date("YmdHis");
//风格
$loginadminstyleid=(int)getcvar('loginadminstyleid');
?>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
<title>选择数据表</title>
<link href="../adminstyle/<?=$loginadminstyleid?>/adminstyle.css" rel="stylesheet" type="text/css">
<script language="JavaScript">

function CheckAll(form)
  {
  for (var i=0;i<form.elements.length;i++)
    {
    var e = form.elements[i];
    if(e.name=='bakstru')
		{
		continue;
	    }
	if (e.name != 'chkall')
       e.checked = form.chkall.checked;
    }
  }
function check()
{var ok;
ok=confirm("确认要执行此操作?");
return ok;
}
</script>
</head>

<body>
<table width="100%" border="0" align="center" cellpadding="3" cellspacing="1">
<form name="searchtb" method="GET" action="ChangeTable.php">
<input name="sear" type="hidden" id="sear" value="1">
<input name="mydbname" type="hidden" value="<?=$mydbname?>">
  <tr> 
    <td width="58%">位置：备份数据 -&gt; <a href="ChangeDb.php">选择数据库</a> -&gt; <a href="ChangeTable.php?mydbname=<?=$mydbname?>">选择备份表</a></td>
      <td width="42%"><div align="center">查询: 
          <input name="keyboard" type="text" id="keyboard" value="<?=$keyboard?>">
          <input type="submit" name="Submit3" value="显示数据表">
        </div></td>
  </tr>
  <tr> 
    <td height="25" colspan="2"><div align="center">
          备份步骤：选择数据库 -&gt; <font color="#FF0000">选择要备份的表</font> -&gt; 开始备份 -&gt; 
          完成</div></td>
  </tr>
</form>
</table>
<form action="phome.php" method="post" name="form1" target="_blank" onsubmit="return check();">
  <table width="100%" border="0" align="center" cellpadding="3" cellspacing="1" class="tableborder">
    <tr class="header"> 
      <td height="25">备份参数设置： 
        <input name="phome" type="hidden" id="phome" value="DoEbak">
        <input name="mydbname" type="hidden" id="mydbname" value="<?=$mydbname?>">
        </td>
    </tr>
    <tr> 
      <td height="25" bgcolor="#FFFFFF"> 
        <table width="100%" border="0" align="center" cellpadding="3" cellspacing="1">
          <tr> 
            <td width="23%">每组文件大小：</td>
            <td width="77%" height="23"> <input name="filesize" type="text" id="filesize" value="300" size="6">
              KB (1 MB = 1024 KB)</td>
          </tr>
          <tr> 
            <td>备份数据库结构：</td>
            <td height="23"><input name="bakstru" type="checkbox" id="bakstru" value="1" checked>
              (没特殊情况，请选择)</td>
          </tr>
		  <tr> 
            <td>&nbsp;</td>
            <td height="23"><input name="bakstrufour" type="checkbox" id="bakstrufour" value="1">
              导出为Mysql 4.0或3.*格式<font color="#666666">(如果您打算从4.1以上版本导入4.0及以下版本请选择)</font></td>
          </tr>
          <tr>
            <td>存放目录：</td>
            <td height="23">admin/ebak/<?=$bakpath?>/
              <input name="mypath" type="text" id="mypath" value="<?=$mypath?>">
              (为空的话，将由系统自己生成，目录不存在的话，系统自己会建立)</td>
          </tr>
          <tr> 
            <td valign="top">备份说明：<br>
              (系统会生成一个readme.txt) </td>
            <td height="23"><textarea name="readme" cols="80" rows="8" id="readme"></textarea></td>
          </tr>
		  <tr>
            <td valign="top">去除自增值的字段列表：<br>
              (格式：<strong><font color="#FF0000">表名.字段名</font></strong><br>
              多个请用&quot;,&quot;格开)</td>
            <td height="23"><textarea name="autofield" cols="80" rows="5" id="autofield"></textarea></td>
          </tr>
        </table>
      </td>
    </tr>
    <tr class="header"> 
      <td height="25">选择要备份的表：</td>
    </tr>
    <tr>
      <td height="25" bgcolor="#FFFFFF"><table width="100%" border="0" align="center" cellpadding="3" cellspacing="1">
          <tr bgcolor="#DBEAF5"> 
            <td width="5%" height="23"> 
              <div align="center">选择</div></td>
            <td width="33%" height="23" bgcolor="#DBEAF5"> 
              <div align="center">表名(点击查看字段)</div></td>
            <td width="18%" height="23" bgcolor="#DBEAF5"> 
              <div align="center">类型</div></td>
            <td width="17%" height="23"> 
              <div align="center">记录数</div></td>
            <td width="14%" height="23"> 
              <div align="center">大小</div></td>
            <td width="13%" height="23"> 
              <div align="center">碎片</div></td>
          </tr>
		  <?
		  $totaldatasize=0;//总数据大小
		  $tablenum=0;//总表数
		  $datasize=0;//数据大小
		  $rownum=0;//总记录数
		  while($r=$empire->fetch($sql))
		  {
		  $rownum+=$r[Rows];
		  $tablenum++;
		  $datasize=$r[Data_length]+$r[Index_length];
		  $totaldatasize+=$r[Data_length]+$r[Index_length]+$r[Data_free];
		  ?>
          <tr id=tb<?=$r[Name]?>> 
            <td height="23">
<div align="center">
                <input name="tablename[]" type="checkbox" id="tablename[]" value="<?=$r[Name]?>" onclick="if(this.checked){tb<?=$r[Name]?>.style.backgroundColor='#F1F7FC';}else{tb<?=$r[Name]?>.style.backgroundColor='#ffffff';}" checked>
              </div></td>
            <td height="23">
<div align="center"><a href="#ebak" onclick="window.open('ListField.php?mydbname=<?=$mydbname?>&mytbname=<?=$r[Name]?>','','width=660,height=500,scrollbars=yes');" title="点击查看表字段列表"><?=$r[Name]?></a></div></td>
            <td height="23">
<div align="center"><?=$r[Type]?></div></td>
            <td height="23">
<div align="center"><?=$r[Rows]?></div></td>
            <td height="23">
<div align="center"><?=Ebak_ChangeSize($datasize)?></div></td>
            <td height="23">
<div align="center"><?=Ebak_ChangeSize($r[Data_free])?></div></td>
          </tr>
		  <?
		  }
		  db_close();
		  $empire=null;
		  ?>
          <tr bgcolor="#DBEAF5"> 
            <td height="23"> 
              <div align="center"><input type=checkbox name=chkall value=on onclick=CheckAll(this.form) checked></div></td>
            <td height="23"> 
              <div align="center"> 
                <?=$tablenum?>
              </div></td>
            <td height="23"> 
              <div align="center">---</div></td>
            <td height="23"> 
              <div align="center"><?=$rownum?></div></td>
            <td height="23" colspan="2"> 
              <div align="center"><?=Ebak_ChangeSize($totaldatasize)?></div></td>
          </tr>
        </table></td>
    </tr>
    <tr class="header"> 
      <td height="25">
<div align="center">
          <input type="submit" name="Submit" value="开始备份" onclick="document.form1.phome.value='DoEbak';">
          &nbsp;&nbsp; &nbsp;&nbsp; 
          <input type="submit" name="Submit2" value="修复数据表" onclick="document.form1.phome.value='DoRep';">
          &nbsp;&nbsp; &nbsp;&nbsp; 
          <input type="submit" name="Submit22" value="优化数据表" onclick="document.form1.phome.value='DoOpi';">
        &nbsp;&nbsp; &nbsp;&nbsp; 
          <input type="submit" name="Submit22" value="删除数据表" onclick="document.form1.phome.value='DoDrop';">
		&nbsp;&nbsp; &nbsp;&nbsp; 
          <input type="submit" name="Submit22" value="清空数据表" onclick="document.form1.phome.value='EmptyTable';">
		</div></td>
    </tr>
  </table>
</form>
</body>
</html>
