<!DOCTYPE html>
<html>
	<head>
		<meta charset="utf-8">
		<meta http-equiv="X-UA-Compatible" content="IE=Edge,chrome=1">
		<title>SQL命令工具</title>
		<link rel="stylesheet" href="../static/web/font/css/font-awesome.min.css">
		<link rel="stylesheet" href="../static/web/css/bootstrap.min.css">
		<link rel="stylesheet" href="../static/web/css/admin.css">
		<link rel="stylesheet" href="css/codemirror.css">
		<script src="js/codemirror.js"></script>
		<script src="js/mode/sql/sql.js"></script>
	</head>
	<body>
		<table align="center" class="table maintable my-3">
			<tr>
				<td bgcolor="#f5f5f5" colspan="2">SQL命令工具</td>
			</tr>
			<form action="sys_sql_query.php" method="post" name="infoform" target="stafrm">
				<input type="hidden" name="dopost" value="viewinfo">
				<input type="hidden" name="_csrf_token" value="<?php echo $GLOBALS['csrf_token'];?>">
				<tr>
					<td width="370">
						<select name="tablename" id="tablename" class="admin-input-lg">
							<?php
							if ($cfg_dbtype=="sqlite") {
								$query = "SELECT name FROM sqlite_master WHERE type='table' ORDER BY name;";
							} else {
								$query = "SHOW TABLES FROM {$GLOBALS['cfg_dbname']} ";
								}
								$dsql->SetQuery($query);
								$dsql->Execute('t');
								while($row = $dsql->GetArray('t',MYSQL_BOTH))
								{
									$dsql->SetQuery("Select count(*) From ".$row[0]);
									$dsql->Execute('n');
									$row2 = $dsql->GetArray('n',MYSQL_BOTH);
									$dd = $row2[0];
									echo "<option value='".$row[0]."'>".$row[0]."(".$dd.")</option>";
								}
							?>
						</select>
					</td>
					<td>
						<button type="Submit" name="Submit1" class="btn btn-success btn-sm" onclick="this.form.dopost.value='opimize';">优化选中表</button>
						<button type="Submit" name="Submit2" class="btn btn-success btn-sm" onclick="this.form.dopost.value='repair';">修复选中表</button>
						<button type="Submit" name="Submit3" class="btn btn-success btn-sm" onclick="this.form.dopost.value='viewinfo';">查看表结构</button>
						<button type="Submit" name="Submit5" class="btn btn-success btn-sm" onclick="this.form.dopost.value='opimizeAll';">优化全部表</button>
						<button type="Submit" name="Submit6" class="btn btn-success btn-sm" onclick="this.form.dopost.value='repairAll';">修复全部表</button>
					</td>
				</tr>
				<tr>
					<td>返回信息：</td>
					<td><iframe name="stafrm" frameborder="0" id="stafrm" width="100%" height="100%"></iframe></td>
				</tr>
			</form>
			<form action="sys_sql_query.php" method="post" name="form1" target="stafrm">
				<input type="hidden" name="dopost" value="query">
				<input type="hidden" name="_csrf_token" value="<?php echo $GLOBALS['csrf_token'];?>">
				<tr>
					<td colspan="2">
						<span>运行SQL命令行：</span>
						<label><input type="radio" name="querytype" value="0"> 单行命令</label>
						<label><input type="radio" name="querytype" value="2" checked> 多行命令</label>
					</td>
				</tr>
				<tr>
					<td colspan="2" class="p-0"><textarea name="sqlquery" id="sqlquery"></textarea></td>
				</tr>
				<tr>
					<td bgcolor="#f5f5f5" colspan="2" align="center"><button type="submit" class="btn btn-success btn-sm">运行</button></td>
				</tr>
			</form>
		</table>
		<script>
			var editor = CodeMirror.fromTextArea(document.getElementById('sqlquery'), {
				lineNumbers: true,
				lineWrapping: true,
				mode: 'text/x-mysql'
			});
		</script>
	</body>
</html>