<!DOCTYPE html>
<html>
	<head>
		<meta charset="utf-8">
		<meta name="viewport" content="width=device-width,initial-scale=1,shrink-to-fit=no">
		<title>安装DedeV<?php echo $cfg_version_detail;?></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/style.js"></script>
	</head>
	<body>
		<div class="install-head shadow-sm mb-3">
			<div class="container">
				<div class="row align-items-center">
					<div class="col-5">
						<a href="/" target="_blank" class="logo"><img src="/static/web/img/logo.png" title="DedeBIZ"></a>
					</div>
					<div class="col-7">
						<div class="text-right">
							<a href="https://www.dedebiz.com/service" target="_blank"><i class="fa fa-handshake-o"></i> 技术服务</a>
							<a href="https://www.dedebiz.com/help" target="_blank" class="ml-3"><i class="fa fa-question-circle"></i> 帮助中心</a>
						</div>
					</div>
				</div>
			</div>
		</div>
		<div class="container">
			<div class="install-box">
				<?php if (count($arrMsg) > 0) {foreach($arrMsg as $msg){?>
				<div class="alert alert-warning"><?php echo $msg ?></div>
				<?php }}?>
				<div class="alert alert-warning">请先阅读<a href="https://www.dedebiz.com/license?from=install" target="_blank">《站点授权协议》</a></div>
				<div class="card shadow-sm mb-3">
					<div class="card-header">
						<h1 class="text-center">安装DedeV<?php echo $cfg_version_detail;?></h1>
					</div>
					<div class="card-body">
						<form action="/install/index.php" method="post" name="form1">
							<input type="hidden" name="step" value="2">
							<input type="hidden" name="cookieencode" value="<?php echo $rnd_cookieEncode;?>">
							<input type="hidden" name="adminmail" value="admin@dedebiz.com">
							<div class="form-group">
								<label for="dbtype" class="form-label">数据库类型</label>
								<select id="dbtype" name="dbtype" class="form-control form-select">
									<option value="mysql" selected>MySQL</option>
									<?php if (extension_loaded("sqlite3")) {;?><option value="sqlite">SQLite</option><?php }?>
								</select>
								<div class="form-text">数据库类型一般为MySQL，则SQLite用于开发调试</div>
							</div>
							<div class="form-group server">
								<label for="dbhost" class="form-label">数据库地址</label>
								<input type="text" name="dbhost" id="dbhost" class="form-control" placeholder="localhost">
							</div>
							<div class="form-group server">
								<label for="dbuser" class="form-label">数据库账号</label>
								<input type="text" name="dbuser" id="dbuser" class="form-control" placeholder="root">
							</div>
							<div class="form-group server">
								<label for="dbpwd" class="form-label">数据库密码</label>
								<input type="text" name="dbpwd" id="dbpwd" class="form-control" placeholder="请输入数据库密码">
							</div>
							<div class="form-group">
								<label for="dbprefix" class="form-label">数据表前缀</label>
								<input type="text" name="dbprefix" id="dbprefix" class="form-control" placeholder="biz_">
								<div class="form-text text-danger">注意DedeV<?php echo $cfg_version_detail;?>数据表前缀默认为biz_</div>
							</div>
							<div class="form-group">
								<label for="dbname" class="form-label">数据库名称</label>
								<div class="input-group">
									<input id="dbname" name="dbname" type="text" class="form-control" placeholder="DedeBIZ">
									<div class="input-group-append"><button type="button" id="btnCheckConnect" class="btn btn-success">检查</button></div>
								</div>
							</div>
							<div id="alertConnect"></div>
							<div class="form-group">
								<label for="baseurl" class="form-label">网站地址</label>
								<input type="text" name="baseurl" id="baseurl" class="form-control" placeholder="<?php echo $baseurl;?>">
							</div>
							<div class="form-group">
								<label for="webname" class="form-label">网站名称</label>
								<input type="text" name="webname" id="webname" class="form-control" placeholder="我的网站">
							</div>
							<div class="form-group">
								<label for="adminuser" class="form-label">管理员账号</label>
								<input type="text" name="adminuser" id="adminuser" class="form-control" placeholder="admin" onkeyup="this.value=this.value.replace(/[^0-9a-zA-Z_@!\.-]/g,'');">
								<div class="form-text">请使用数字0-9小写a-z大写A-Z符号_@!.-</div>
							</div>
							<div class="form-group">
								<label for="adminpwd" class="form-label">管理员密码</label>
								<input type="text" name="adminpwd" id="adminpwd" class="form-control" placeholder="admin" onkeyup="this.value=this.value.replace(/[^0-9a-zA-Z_@!\.-]/g,'');">
								<div class="form-text">请使用数字0-9小写a-z大写A-Z符号_@!.-</div>
							</div>
							<div class="text-right"><button type="submit" class="btn btn-success">安装</button></div>
						</form>
					</div>
				</div>
			</div>
		</div>
		<script>
			$("#btnCheckConnect").click(function() {
				let dbhost = $('#dbhost').val();
				let dbuser = $('#dbuser').val();
				let dbpwd = $('#dbpwd').val();
				if (!dbhost) dbhost = "localhost";
				if (!dbuser) dbuser = "root";
				$.get('index.php?step=10&dbhost=' + dbhost + '&dbuser=' + dbuser + '&dbpwd=' + dbpwd,function(rs) {
					console.log(rs);
					let result = JSON.parse(rs);
					if (result.code === 200) {
						ShowAlert("#alertConnect", result.data, "success", 3000);
					} else {
						ShowAlert("#alertConnect", result.data, "danger", 3000);
					}
				})
			});
			$("#dbtype").change(function() {
				if ($(this).val() === 'sqlite') {
					$(".form-group.server").hide()
				} else {
					$(".form-group.server").show()
				}
			});
		</script>
	</body>
</html>