lylme_spage/admin/tag.php

159 lines
6.0 KiB
PHP
Raw Permalink Normal View History

2022-03-12 15:38:17 +08:00
<?php
$title = '导航菜单管理';
2022-03-05 02:40:02 +08:00
include './head.php';
2023-12-17 23:44:51 +08:00
$tagsrows = $DB->num_rows($site->getTags());
2022-03-05 02:40:02 +08:00
?>
<main class="lyear-layout-content">
<div class="container-fluid">
<div class="row">
<div class="col-lg-12">
<div class="card">
<div class="card-body">
<?php
2022-03-12 15:38:17 +08:00
$set = isset($_GET['set']) ? $_GET['set'] : null;
if ($set == 'add') {
echo '<h4>新增导航菜单链接</h4>
2022-03-05 02:40:02 +08:00
<div class="panel-body">
<form action="./tag.php?set=add_submit" method="POST">
<div class="form-group">
<label>*名称:</label><br>
<input type="text" class="form-control" name="name" value="" required>
</div>
<div class="form-group">
<label>*链接地址:</label><br>
<input type="text" class="form-control" name="link" value="" required>
</div>
<div class="form-group">
<label>*打开方式:</label><br>
<select class="form-control" name="target">
<option value="0">0. 当前窗口打开</option>
<option selected="selected" value="1">1. 新窗口打开</option>
</select></div>
<div class="form-group">
2023-12-17 23:44:51 +08:00
<label>排序权重: (*必填) </label><br>
<input type="text" class="form-control" name="sort" value="10" required>
<small class="help-block">(*必填) 数字越小越靠前</small>
</div>
<div class="form-group">
2022-03-05 02:40:02 +08:00
<input type="submit" class="btn btn-primary btn-block" value="添加"></form>
</div>
<br/><a href="./tag.php"><<返回</a>
</div></div>';
2022-03-12 15:38:17 +08:00
} elseif ($set == 'edit') {
$id = $_GET['id'];
$row2 = $DB->query("select * from lylme_tags where tag_id='$id' limit 1");
$row = $DB->fetch($row2);
echo '<h4>修改导航菜单链接</h4>
2022-03-05 02:40:02 +08:00
<div class="panel-body">
2022-03-12 15:38:17 +08:00
<form action="./tag.php?set=edit_submit&id=' . $id . '" method="POST">
2022-03-05 02:40:02 +08:00
<div class="form-group">
<label>*名称:</label><br>
2022-03-12 15:38:17 +08:00
<input type="text" class="form-control" name="name" value="' . $row['tag_name'] . '" required>
2022-03-05 02:40:02 +08:00
</div>
<div class="form-group">
<label>*链接地址:</label><br>
2022-03-12 15:38:17 +08:00
<input type="text" class="form-control" name="link" value="' . $row['tag_link'] . '" required>
2022-03-05 02:40:02 +08:00
</div>
<div class="form-group">
<label>*打开方式:</label><br>
<select class="form-control" name="target">
<option value="0">0. 当前窗口打开</option>
<option ';
2022-03-12 15:38:17 +08:00
if ($row['tag_target'] == 1) {
echo 'selected="selected"';
}
echo 'value="1">1. 新窗口打开</option>
2022-03-05 02:40:02 +08:00
</select></div>
<div class="form-group">
2023-12-17 23:44:51 +08:00
<label>排序权重: (*必填) </label><br>
<input type="text" class="form-control" name="sort" value="' . $row['sort'] . '" required>
<small class="help-block">(*必填) 数字越小越靠前</small>
</div>
<div class="form-group">
2022-03-05 02:40:02 +08:00
<input type="submit" class="btn btn-primary btn-block" value="修改"></form>
</div>
<br/><a href="./tag.php"><<返回</a>
</div></div>';
2022-03-12 15:38:17 +08:00
} elseif ($set == 'add_submit') {
$name = $_POST['name'];
$link = $_POST['link'];
2023-12-17 23:44:51 +08:00
$sort = $_POST['sort'] ?: 10;
2022-03-12 15:38:17 +08:00
if ($_POST['target'] == true) {
$target = 1;
} else {
$target = 0;
}
2023-12-17 23:44:51 +08:00
if ($name == null or $link == null) {
2022-03-12 15:38:17 +08:00
echo '<script>alert("保存错误,请确保带星号的都不为空!");history.go(-1);</script>';
} else {
2023-12-17 23:44:51 +08:00
$sql = "INSERT INTO `lylme_tags` (`tag_id`, `tag_name`, `tag_link`, `tag_target`,`sort`) VALUES (NULL, '" . $name . "', '" . $link . "', '" . $target . "','" . $sort . "');";
2022-03-12 15:38:17 +08:00
if ($DB->query($sql)) {
2022-03-12 16:52:26 +08:00
echo '<script>alert("添加导航菜单 ' . $name . ' 成功!");window.location.href="./tag.php";</script>';
2023-12-17 23:44:51 +08:00
} else {
echo '<script>alert("添加导航菜单失败");history.go(-1);</script>';
}
2022-03-12 15:38:17 +08:00
}
} elseif ($set == 'edit_submit') {
$id = $_GET['id'];
2023-12-17 23:44:51 +08:00
$sort = $_POST['sort'] ?: 10;
2022-03-12 15:38:17 +08:00
$rows2 = $DB->query("select * from lylme_tags where tag_id='$id' limit 1");
$rows = $DB->fetch($rows2);
2023-12-17 23:44:51 +08:00
if (!$rows) {
echo '<script>alert("当前记录不存在!");history.go(-1);</script>';
}
2022-03-12 15:38:17 +08:00
$name = $_POST['name'];
$link = $_POST['link'];
if ($_POST['target'] == true) {
$target = 1;
} else {
$target = 0;
}
2023-12-17 23:44:51 +08:00
if ($name == null or $link == null) {
2022-03-12 15:38:17 +08:00
echo '<script>alert("保存错误,请确保带星号的都不为空!");history.go(-1);</script>';
} else {
2023-12-17 23:44:51 +08:00
$sql = "UPDATE `lylme_tags` SET `tag_name` = '" . $name . "', `tag_link` = '" . $link . "', `tag_target` = '" . $target . "', `sort` = '" . $sort . "' WHERE `lylme_tags`.`tag_id` = " . $id . ";";
if ($DB->query($sql)) {
echo '<script>alert("修改导航菜单 ' . $name . ' 成功!");window.location.href="./tag.php";</script>';
} else {
echo '<script>alert("修改导航菜单失败!");history.go(-1);</script>';
}
2022-03-12 15:38:17 +08:00
}
} elseif ($set == 'delete') {
$id = $_GET['id'];
$sql = "DELETE FROM lylme_tags WHERE tag_id='$id'";
2023-12-17 23:44:51 +08:00
if ($DB->query($sql)) {
echo '<script>alert("删除成功!");window.location.href="./tag.php";</script>';
} else {
echo '<script>alert("删除失败!");history.go(-1);</script>';
}
2022-03-05 02:40:02 +08:00
} else {
2022-03-12 15:38:17 +08:00
echo '<div class="alert alert-info">系统共有 <b>' . $tagsrows . '</b> 个导航菜单<br/><a href="./tag.php?set=add" class="btn btn-primary">新增导航菜单</a></div>';
2023-12-17 23:44:51 +08:00
?>
2022-03-05 02:40:02 +08:00
<div class="table-responsive">
<table class="table table-striped">
2023-12-17 23:44:51 +08:00
<thead><tr><th>排序权重</th><th>名称</th><th>链接</th><th>操作</th></tr></thead>
2022-03-05 02:40:02 +08:00
<tbody>
<?php
2023-12-17 23:44:51 +08:00
$rs = $site->getTags();
2022-03-12 15:38:17 +08:00
while ($res = $DB->fetch($rs)) {
2023-12-17 23:44:51 +08:00
echo '<tr><td>' . $res['sort'] . '</td><td>' . $res['tag_name'] . '</td><td>' . $res['tag_link'] . '</td><td><a href="./tag.php?set=edit&id=' . $res['tag_id'] . '" class="btn btn-info btn-xs">编辑</a>&nbsp;<a href="./tag.php?set=delete&id=' . $res['tag_id'] . '" class="btn btn-xs btn-danger" onclick="return confirm(\'确定删除 ' . $res['tag_name'] . ' \');">删除</a></td></tr>';
2022-03-12 15:38:17 +08:00
}
2023-12-17 23:44:51 +08:00
?>
2022-03-05 02:40:02 +08:00
</tbody>
</table>
</div>
</div>
</div>
</div>
</div>
</div>
</main>
2022-03-12 15:38:17 +08:00
<?php
2022-03-05 02:40:02 +08:00
}
include './footer.php';
?>