<!DOCTYPE html>
<html>
	<head>
		<meta charset="utf-8">
		<meta http-equiv="X-UA-Compatible" content="IE=Edge,chrome=1">
		<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/admin.main.js"></script>
	</head>
	<body>
		<table align="center" class="table maintable my-3">
			<tr bgcolor="#f8fafb">
				<td width="460">
					<form name="form2" action="tags_main.php">
						<input type="text" name="tag" value="<?php echo $tag;?>" placeholder="请输入标签" class="admin-input-lg">
						<button type="submit" name="sb" class="btn btn-success btn-sm">搜索</button>
					</form>
				</td>
				<td>
					<form name="form1" action="tags_main.php?action=fetch" method="post">
						<input type="text" name="startaid" placeholder="请输入标签id开始" class="admin-input-sm mr-3">
						<input type="text" name="endaid" placeholder="请输入标签id结束" class="admin-input-sm">
						<button name="submit" type="submit" class="btn btn-success btn-sm">获取标签</button>
						<a href="makehtml_taglist.php" name="sb" class="btn btn-success btn-sm">更新标签</a>
					</form>
				</td>
			</tr>
		</table>
		<form name="form3" action="tags_main.php?action=delete" method="post">
			<table align="center" class="table maintable mb-3">
				<tr>
					<td colspan="8" bgcolor="#f8fafb">标签管理</td>
				</tr>
				<tr align="center" bgcolor="#f8f9fa">
					<td width="6%">选择</td>
					<td width="6%">id</td>
					<td width="20%">标签</td>
					<td width="10%"><a href="tags_main.php?tag=<?php echo $tag;?>&orderby=count&orderway=<?php echo $neworderway;?>">点击</a></td>
					<td width="10%"><a href="tags_main.php?tag=<?php echo $tag;?>&orderby=total&orderway=<?php echo $neworderway;?>">文档数</a></td>
					<td width="10%"><a href="tags_main.php?tag=<?php echo $tag;?>&orderby=addtime&orderway=<?php echo $neworderway;?>">添加时间</a></td>
					<td width="10%">更新时间</td>
					<td>操作</td>
				</tr>
				{dede:datalist empty='<tr><td colspan="8" align="center">暂无标签</td></tr>'}
				<?php
				$fields['addtime'] = GetDateMk($fields['addtime']);
				$fields['uptime'] = GetDateMk($fields['uptime']);
				$fields['tag'] = dede_htmlspecialchars($fields['tag']);
				?>
				<tr align="center">
					<td><input type="checkbox" name="ids[]" value="<?php echo $fields['id'];?>"></td>
					<td>{dede:field.id/}</td>
					<td><a href="<?php echo $cfg_phpurl;?>/tags.php?/<?php echo $fields['id'];?>/" target="_blank">{dede:field.tag/}</a></td>
					<td><input type="text" value="<?php echo $fields['count'];?>" id="count<?php echo $fields['id'];?>" size='5'></td>
					<td><?php echo $fields['total'];?></td>
					<td><?php echo $fields['addtime'];?></td>
					<td><?php echo $fields['uptime'];?></td>
					<td>
						<a href='javascript:UpdateKwDes(<?php echo $fields['id'];?>,"<?php echo $fields['tag'];?>");' class="btn btn-light btn-sm"><i class="fa fa-cog"></i> 设置</a>
						<a href="javascript:UpdateOne(<?php echo $fields['id'];?>);" class="btn btn-light btn-sm"><i class="fa fa-refresh"></i> 刷新</a>
						<a href="makehtml_taglist.php?tagid=<?php echo $fields['id'];?>" class="btn btn-light btn-sm"><i class="fa fa-repeat"></i> 更新</a>
						<a href="javascript:DeleteOne(<?php echo $fields['id'];?>);" class="btn btn-danger btn-sm"><i class="fa fa-trash"></i> 删除</a>
					</td>
				</tr>
				{/dede:datalist}
				<tr>
					<td colspan="8">
						<button type="button" name="select" onclick="selAll();" class="btn btn-success btn-sm">全选</button>
						<button type="button" name="select" onclick="noSelAll();" class="btn btn-success btn-sm">取消</button>
						<button type="button" onclick="document.form3.submit();" class="btn btn-danger btn-sm">删除</button>
					</td>
				</tr>
				<tr>
					<td colspan="8" bgcolor="#f8fafb" align="center">{dede:pagelist/}</td>
				</tr>
			</table>
		</form>
		<script>
			function selAll() {
				var a = document.getElementsByTagName("input");
				for (var i = 0; i < a.length; i++){
					if (a[i].type == "checkbox") a[i].checked = true;
				}
			}
			function noSelAll() {
				var a = document.getElementsByTagName("input");
				for (var i = 0; i < a.length; i++){
					if (a[i].type == "checkbox") a[i].checked = false;
				}
			}
			function UpdateOne(tid) {
				location = "tags_main.php?action=update&count=" + document.getElementById('count' + tid).value + "&tid=" + tid;
			}
			function DeleteOne(tid) {
				location = "tags_main.php?action=delete&ids=" + tid;
			}
			function UpdateKwDes(tid, tag) {
				$.get("tags_main.php?action=get_one&tid=" + tid, function(data) {
					let rs = JSON.parse(data);
					let title = rs.title ? rs.title : "";
					let keywords = rs.keywords ? rs.keywords : "";
					let description = rs.description ? rs.description : "";
					ShowMsg(`<div class="form-group row">
						<label for="iptTitle" class="col-sm-3 col-form-label">标签</label>
						<div class="col-sm-9"><input type="text" name="title" class="form-control" disabled value="${tag}"></div>
					</div>
					<div class="form-group row">
						<label for="iptKw" class="col-sm-3 col-form-label">标题</label>
						<div class="col-sm-9"><input type="text" name="title" id="iptTitle" class="form-control" placeholder="例如：DedeBIZ管理系统" value="${title}"></div>
					</div>
					<div class="form-group row">
						<label for="iptKw" class="col-sm-3 col-form-label">关键词</label>
						<div class="col-sm-9"><input type="text" name="kw" id="iptKw" class="form-control" placeholder="例如：dedebiz" value="${keywords}"></div>
					</div>
					<div class="form-group row">
						<label for="iptDes" class="col-sm-3 col-form-label">描述</label>
						<div class="col-sm-9"><textarea name="des" id="iptDes" class="form-control" placeholder="例如：DedeBIZ系统基于PHP7版本开发，具有很强的可扩展性，并且采用GPLv2协议完全开放源代码。">${description}</textarea></div>
					</div>`, {
						footer: `<button type="button" class="btn btn-success btn-sm" onclick="UpdateKwDesDo(${tid}, '~modalID~')">保存</button>`,
					});
				})
			}
			function UpdateKwDesDo(tid, mdlID) {
				let title = $("#iptTitle").val();
				let kw = $("#iptKw").val();
				let des = $("#iptDes").val();
				$.post("tags_main.php?action=set_one", {
					tid: tid,
					title: title,
					kw: kw,
					des: des,
				}, function(data) {
					let rs = JSON.parse(data);
					if (rs.code === 200) {
						location.reload();
					}

				});
			}
		</script>
	</body>
</html>