<!DOCTYPE html>
<html>
	<head>
		<meta charset="utf-8">
		<meta name="viewport" content="width=device-width,initial-scale=1,shrink-to-fit=no">
		<title>数据备份</title>
		<link rel="stylesheet" href="/static/web/css/font-awesome.min.css">
		<link rel="stylesheet" href="/static/web/css/bootstrap.min.css">
		<link rel="stylesheet" href="/static/web/css/admin.css">
		<script src="/static/web/js/jquery.min.js"></script>
		<script src="/static/web/js/bootstrap.min.js"></script>
		<script src="/static/web/js/webajax.js"></script>
		<script src="/static/web/js/admin.main.js"></script>
	</head>
	<body>
		<div class="container-fluid">
			<ol class="breadcrumb">
				<li class="breadcrumb-item"><a href="index_body.php">后台面板</a></li>
				<li class="breadcrumb-item active">数据备份</li>
			</ol>
			<div class="card shadow-sm mb-3">
				<div class="card-body">
					<a href="sys_data_revert.php" class="btn btn-success btn-sm">数据还原</a>
					<a href="sys_sql_query.php" class="btn btn-success btn-sm">SQL命令工具</a>
				</div>
			</div>
			<div class="card shadow-sm">
				<div class="card-header">数据备份</div>
				<div class="card-body">
					<form name="form1" action="sys_data_done.php?dopost=bak" method="post" target="stafrm" onSubmit="checkSubmit();">
						<input type="hidden" name="tablearr">
						<div class="table-responsive">
							<table class="table table-borderless">
								<thead>
									<tr>
										<td colspan="8">系统默认表</td>
									</tr>
									<tr>
										<td scope="col">选择</td>
										<td scope="col">表名</td>
										<td scope="col">记录数</td>
										<td scope="col">操作</td>
										<td scope="col">选择</td>
										<td scope="col">表名</td>
										<td scope="col">记录数</td>
										<td scope="col">操作</td>
									</tr>
								</thead>
								<tbody>
									<?php  
									for ($i=0; isset($dedeSysTables[$i]); $i++)
									{ 
										$t = $dedeSysTables[$i];
										echo "<tr>";
									?>
									<td><input type="checkbox" name="tables" value="<?php echo $t;?>" checked></td>
									<td><?php echo $t;?></td>
									<td><?php echo TjCount($t,$dsql);?></td>
									<td>
										<a href="javascript:LoadUrl('dopost=opimize&tablename=<?php echo $t;?>');" class="btn btn-light btn-sm">优化</a>
										<a href="javascript:LoadUrl('dopost=repair&tablename=<?php echo $t;?>');" class="btn btn-light btn-sm">修复</a>
										<a href="javascript:LoadUrl('dopost=viewinfo&tablename=<?php echo $t;?>');" class="btn btn-light btn-sm">结构</a>
									</td>
									<?php
									$i++;
									if (isset($dedeSysTables[$i])) {
										$t = $dedeSysTables[$i];
									?>
									<td><input type="checkbox" name="tables" value="<?php echo $t;?>" checked></td>
									<td><?php echo $t;?></td>
									<td><?php echo TjCount($t,$dsql);?></td>
									<td>
										<a href="javascript:LoadUrl('dopost=opimize&tablename=<?php echo $t;?>');" class="btn btn-light btn-sm">优化</a>
										<a href="javascript:LoadUrl('dopost=repair&tablename=<?php echo $t;?>');" class="btn btn-light btn-sm">修复</a>
										<a href="javascript:LoadUrl('dopost=viewinfo&tablename=<?php echo $t;?>');" class="btn btn-light btn-sm">结构</a>
									</td>
									<?php
									} else {
										echo "<td></td><td></td><td></td><td></td>";
									}
									echo "</tr>";
									}
									?>
								</tbody>
								<thead>
									<tr>
										<td colspan="8">其他数据表</td>
									</tr>
									<tr>
										<td scope="col">选择</td>
										<td scope="col">表名</td>
										<td scope="col">记录数</td>
										<td scope="col">操作</td>
										<td scope="col">选择</td>
										<td scope="col">表名</td>
										<td scope="col">记录数</td>
										<td scope="col">操作</td>
									</tr>
								</thead>
								<tbody>
									<?php  
									for ($i=0; isset($otherTables[$i]); $i++)
									{ 
										$t = $otherTables[$i];
										echo "<tr>";
									?>
									<td><input type="checkbox" name="tables" value="<?php echo $t;?>"></td>
									<td><?php echo $t;?></td>
									<td><?php echo TjCount($t,$dsql);?></td>
									<td>
										<a href="javascript:LoadUrl('dopost=opimize&tablename=<?php echo $t;?>');" class="btn btn-light btn-sm">优化</a>
										<a href="javascript:LoadUrl('dopost=repair&tablename=<?php echo $t;?>');" class="btn btn-light btn-sm">修复</a>
										<a href="javascript:LoadUrl('dopost=viewinfo&tablename=<?php echo $t;?>');" class="btn btn-light btn-sm">结构</a>
									</td>
									<?php
									$i++;
									if (isset($otherTables[$i])) {
										$t = $otherTables[$i];
									?>
									<td><input type="checkbox" name="tables" value="<?php echo $t;?>"></td>
									<td><?php echo $t;?></td>
									<td><?php echo TjCount($t,$dsql);?></td>
									<td>
										<a href="javascript:LoadUrl('dopost=opimize&tablename=<?php echo $t;?>');" class="btn btn-light btn-sm">优化</a>
										<a href="javascript:LoadUrl('dopost=repair&tablename=<?php echo $t;?>');" class="btn btn-light btn-sm">修复</a>
										<a href="javascript:LoadUrl('dopost=viewinfo&tablename=<?php echo $t;?>');" class="btn btn-light btn-sm">结构</a>
									</td>
									<?php
									} else {
										echo "<td></td><td></td><td></td><td></td>";
									}
									echo "</tr>";
									}
									?>
									<tr>
										<td colspan="8">
											<label>分卷大小：<input name="fsize" type="text" id="fsize" value="2048" class="admin-input-sm"> K</label>
											<label><input type="checkbox" name="isstruct" id="isstruct" value="1" checked> 备份结构</label>
											<?php if (@function_exists('gzcompress') && false) {?>
											<label><input type="checkbox" name="iszip" id="iszip" value="1" checked> 完成后压缩成ZIP</label>
											<?php }?>
											<a href="javascript:SelAll();" class="btn btn-success btn-sm">全选</a>
											<a href="javascript:ReSel();" class="btn btn-success btn-sm">反选</a>
											<a href="javascript:NoneSel();" class="btn btn-success btn-sm">取消</a>
											<button type="submit" class="btn btn-success btn-sm">备份</button>
										</td>
									</tr>
									<tr>
										<td colspan="8">
											<div class="admin-win-iframe"><iframe name="stafrm" frameborder="0" id="stafrm" width="100%" height="100%"></iframe></div>
										</td>
									</tr>
								</tbody>
							</table>
						</div>
					</form>
				</div>
			</div>
		</div>
		<script>
			var posLeft = 200;
			var posTop = 150;
			function LoadUrl(surl) {
				fetch("sys_data.php?" + surl).then(resp => {
					if (resp.ok) {
						return resp.text()
					}
					throw new Error('x');
				}).then((d) => {
					ShowMsg(d, {
						size: "modal-lg"
					});
				}).catch((error) => {
					ShowMsg("操作失败");
				});
			}
			//获得选中文件的数据表
			function getCheckboxItem() {
				var myform = document.form1;
				var allSel = '';
				if (myform.tables.value) return myform.tables.value;
				for (i = 0; i < myform.tables.length; i++) {
					if (myform.tables[i].checked) {
						if (allSel == "")
							allSel = myform.tables[i].value;
						else
							allSel = allSel + "," + myform.tables[i].value;
					}
				}
				return allSel;
			}
			//反选
			function ReSel() {
				var myform = document.form1;
				for (i = 0; i < myform.tables.length; i++) {
					if (myform.tables[i].checked) myform.tables[i].checked = false;
					else myform.tables[i].checked = true;
				}
			}
			//全选
			function SelAll() {
				var myform = document.form1;
				for (i = 0; i < myform.tables.length; i++) {
					myform.tables[i].checked = true;
				}
			}
			//取消
			function NoneSel() {
				var myform = document.form1;
				for (i = 0; i < myform.tables.length; i++) {
					myform.tables[i].checked = false;
				}
			}
			function checkSubmit() {
				var myform = document.form1;
				myform.tablearr.value = getCheckboxItem();
				return true;
			}
		</script>
	</body>
</html>