<!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/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 d-flex justify-content-between">
					<form name="form2" action="tags_main.php">
						<input type="text" name="tag" value="<?php echo $tag;?>" placeholder="请输入标签" class="admin-input-lg">
						<button type="submit" class="btn btn-success btn-sm">搜索</button>
					</form>
					<form name="form1" action="tags_main.php?action=fetch" method="post">
						<input type="text" name="startaid" placeholder="请输入标签id开始" class="admin-input-sm mr-2">
						<input type="text" name="endaid" placeholder="请输入标签id结束" class="admin-input-sm">
						<button type="submit" class="btn btn-success btn-sm">获取标签</button>
						<a href="makehtml_taglist.php" class="btn btn-success btn-sm">更新标签</a>
					</form>
				</div>
			</div>
			<div class="card shadow-sm">
				<div class="card-header">标签管理</div>
				<div class="card-body">
					<form name="form3" action="tags_main.php?action=delete" method="post">
						<div class="table-responsive">
							<table class="table table-borderless table-hover">
								<thead>
									<tr>
										<td scope="col">选择</td>
										<td scope="col">id</td>
										<td scope="col">标签</td>
										<td scope="col">缩略图</td>
										<td scope="col">SEO标题</td>
										<td scope="col">关键词</td>
										<td scope="col">描述</td>
										<td scope="col"><a href="tags_main.php?tag=<?php echo $tag;?>&orderby=count&orderway=<?php echo $neworderway;?>">点击</a></td>
										<td scope="col"><a href="tags_main.php?tag=<?php echo $tag;?>&orderby=total&orderway=<?php echo $neworderway;?>">文档数</a></td>
										<td scope="col"><a href="tags_main.php?tag=<?php echo $tag;?>&orderby=addtime&orderway=<?php echo $neworderway;?>">添加时间</a></td>
										<td scope="col">更新时间</td>
										<td scope="col">操作</td>
									</tr>
								</thead>
								<tbody>
									{dede:datalist}
									<?php
									$fields['addtime'] = GetDateMk($fields['addtime']);
									$fields['uptime'] = GetDateMk($fields['uptime']);
									$fields['tag'] = dede_htmlspecialchars($fields['tag']);
									?>
									<tr>
										<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:sfield.tag/}</a></td>
										<td>
											<input value="<?php echo $fields['litpic'];?>" type="text" name="litpic{dede:field.id/}" id="litpic{dede:field.id/}" class="admin-input-sm">
											<button type="button" class="btn btn-success btn-sm" onclick="SelectImage('form3.litpic{dede:field.id/}');">选择</button>
										</td>
										<td><input type="text" value="<?php echo $fields['title'];?>" name="title<?php echo $fields['id'];?>" id="title<?php echo $fields['id'];?>" class="admin-input-sm"></td>
										<td><input type="text" value="<?php echo $fields['keywords'];?>" name="keywords<?php echo $fields['id'];?>" id="keywords<?php echo $fields['id'];?>" class="admin-input-sm"></td>
										<td><textarea name="description<?php echo $fields['id'];?>" id="description<?php echo $fields['id'];?>" class="admin-textarea-sm"><?php echo $fields['description'];?></textarea></td>

										<td><input type="text" value="<?php echo $fields['count'];?>" id="count<?php echo $fields['id'];?>" class="admin-input-xs"></td>
										<td><?php echo $fields['total'];?></td>
										<td><?php echo $fields['addtime'];?></td>
										<td><?php echo $fields['uptime'];?></td>
										<td>
											<a href="javascript:UpdateOne(<?php echo $fields['id'];?>);" class="btn btn-light btn-sm"><i class="fa fa-check" title="保存"></i></a>
											<a href="makehtml_taglist.php?tagid=<?php echo $fields['id'];?>" class="btn btn-light btn-sm"><i class="fa fa-repeat" title="更新"></i></a>
											<a href="javascript:DeleteOne(<?php echo $fields['id'];?>);" class="btn btn-danger btn-sm"><i class="fa fa-trash" title="删除"></i></a>
										</td>
									</tr>
									{/dede:datalist}
									<tr>
										<td colspan="8">
											<a href="javascript:selAll();" class="btn btn-success btn-sm">全选</a>
											<a href="javascript:noSelAll();" class="btn btn-success btn-sm">取消</a>
											<button type="button" onclick="document.form3.submit();" class="btn btn-danger btn-sm">删除</button>
										</td>
									</tr>
								</tbody>
							</table>
						</div>
					</form>
					{dede:pagelist listsize='6'/}
				</div>
			</div>
		</div>
		<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) {
				let count = document.getElementById('count' + tid).value;
				let litpic = document.getElementById('litpic' + tid).value;
				let title = document.getElementById('title' + tid).value;
				let keywords = document.getElementById('keywords' + tid).value;
				let description = document.getElementById('description' + tid).value;
				$.post("tags_main.php?action=update", {
					count: count,
					litpic: litpic,
					title: title,
					keywords: keywords,
					description: description,
					tid: tid,
				}, function(data) {
					if (data == "success") {
						location.reload();
					} else {
						ShowMsg(data);
					}
				});
			}
			function DeleteOne(tid) {
				location = "tags_main.php?action=delete&ids=" + tid;
			}
		</script>
	</body>
</html>