mirror of
https://github.com/LyLme/lylme_spage.git
synced 2024-11-17 22:38:03 +08:00
添加分组排序功能
This commit is contained in:
parent
6f322de182
commit
8b9848f6c5
108
admin/group.php
108
admin/group.php
@ -1,5 +1,5 @@
|
||||
<?php
|
||||
$title='链接管理';
|
||||
$title='分组管理';
|
||||
include './head.php';
|
||||
?>
|
||||
<main class="lyear-layout-content">
|
||||
@ -64,20 +64,21 @@ elseif($set=='add_submit')
|
||||
{
|
||||
$name=$_POST['group_name'];
|
||||
$icon=$_POST['group_icon'];
|
||||
$group_order = $groupsrows+1;
|
||||
if($name==NULL){
|
||||
echo '<script>alert("保存错误,请确保带星号的都不为空!");history.go(-1);</script>';
|
||||
} else {
|
||||
|
||||
$sql="INSERT INTO `lylme_groups` (`group_id`, `group_name`, `group_icon`) VALUES (NULL, '".$name."', '".$icon."')";
|
||||
$sql="INSERT INTO `lylme_groups` (`group_id`, `group_name`, `group_icon`,`group_order`) VALUES (NULL, '".$name."', '".$icon."', '".$group_order."')";
|
||||
|
||||
if(mysqli_query($con,$sql)){
|
||||
echo '<script>alert("添加分组 '.$name.' 成功!");window.location.href="/admin/group.php";</script>';
|
||||
exit();
|
||||
}else
|
||||
echo '<script>alert("添加分组失败);history.go(-1);</script>';
|
||||
echo '<script>alert("添加分组失败");history.go(-1);</script>';
|
||||
exit();
|
||||
}
|
||||
echo '<script>alert("添加分组失败,名称重复);history.go(-1);</script>';
|
||||
echo '<script>alert("添加分组失败,名称重复");history.go(-1);</script>';
|
||||
}
|
||||
elseif($set=='edit_submit')
|
||||
{
|
||||
@ -100,7 +101,6 @@ else
|
||||
echo '<script>alert("'.$sql.'修改分组失败");history.go(-1);</script>';
|
||||
}
|
||||
}
|
||||
|
||||
elseif($set=='delete')
|
||||
{
|
||||
$id=$_GET['id'];
|
||||
@ -109,8 +109,50 @@ $delsql2='DELETE FROM `lylme_groups` WHERE group_id='.$id;
|
||||
if(mysqli_query($con,$delsql1) && mysqli_query($con,$delsql2))
|
||||
echo '<script>alert("删除成功!");window.location.href="/admin/group.php";</script>';
|
||||
else
|
||||
echo '<script>alert("删除失败!\n);history.go(-1);</script>';
|
||||
echo '<script>alert("删除失败!");history.go(-1);</script>';
|
||||
}
|
||||
|
||||
|
||||
elseif($set=='up')
|
||||
{
|
||||
$id=$_GET['id'];
|
||||
$order=$_GET['order']-1;
|
||||
$arrid=$_GET['arrid'];
|
||||
if($order <= 0){
|
||||
echo '<script>window.location.href="/admin/group.php";</script>';
|
||||
exit();
|
||||
}
|
||||
|
||||
// while($orderrow > 1){
|
||||
// $order=$order-1;
|
||||
// $sql3 = 'SELECT * FROM `lylme_groups` WHERE `group_order` ='.$order;
|
||||
// $orderrow=mysqli_num_rows(mysqli_query($con,$sql3));
|
||||
// }
|
||||
|
||||
$sql1 = 'UPDATE `lylme_groups` SET `group_order` = '.$order.' WHERE `group_id` = '.$id;
|
||||
$sql2 = 'UPDATE `lylme_groups` SET `group_order` = '.$_GET['order'].' WHERE `group_id` = '.$arrid;
|
||||
if(mysqli_query($con,$sql1))
|
||||
|
||||
echo '<script>window.location.href="/admin/group.php?orderid='.$id.'";</script>';
|
||||
else
|
||||
echo '<script>alert("上移失败!");history.go(-1);</script>';
|
||||
}
|
||||
|
||||
elseif($set=='down')
|
||||
{
|
||||
$id=$_GET['id'];
|
||||
$order=$_GET['order']+1;
|
||||
$arrid=$_GET['arrid'];
|
||||
$sql1 = 'UPDATE `lylme_groups` SET `group_order` = '.$order.' WHERE `group_id` = '.$id;
|
||||
$sql2 = 'UPDATE `lylme_groups` SET `group_order` = '.$order.' WHERE `group_id` = '.$arr[$arrid+1];
|
||||
|
||||
if(mysqli_query($con,$sql1))
|
||||
echo '<script>window.location.href="/admin/group.php?orderid='.$id.'";</script>';
|
||||
else
|
||||
echo '<script>alert("下移失败!");history.go(-1);</script>';
|
||||
}
|
||||
|
||||
|
||||
else
|
||||
{
|
||||
|
||||
@ -120,35 +162,53 @@ $cons='系统共有 <b>'.$groupsrows.'</b> 个分组<br/><a href="./group.php?se
|
||||
echo '<div class="alert alert-info">';
|
||||
echo $cons;
|
||||
echo '</div>';
|
||||
// echo $css;
|
||||
|
||||
?>
|
||||
<div class="table-responsive">
|
||||
<table class="table table-striped">
|
||||
<thead><tr><th>ID</th><th>名称</th><th>操作</th></tr></thead>
|
||||
<thead><tr><th>排序权重</th><th>名称</th><th>排序</th><th>操作</th></tr></thead>
|
||||
<tbody>
|
||||
<?php
|
||||
$pagesize=30;
|
||||
$pages=intval($groupsrows/$pagesize);
|
||||
if ($groupsrows%$pagesize)
|
||||
{
|
||||
$pages++;
|
||||
}
|
||||
if (isset($_GET['page'])){
|
||||
$page=intval($_GET['page']);
|
||||
}
|
||||
else{
|
||||
$page=1;
|
||||
}
|
||||
$offset=$pagesize*($page - 1);
|
||||
// $pagesize=30;
|
||||
// $pages=intval($groupsrows/$pagesize);
|
||||
// if ($groupsrows%$pagesize)
|
||||
// {
|
||||
// $pages++;
|
||||
// }
|
||||
// if (isset($_GET['page'])){
|
||||
// $page=intval($_GET['page']);
|
||||
// }
|
||||
// else{
|
||||
// $page=1;
|
||||
// }
|
||||
// $offset=$pagesize*($page - 1);
|
||||
|
||||
$rs=mysqli_query($con,"SELECT * FROM lylme_groups WHERE{$sql} order by group_id asc");
|
||||
while($res = mysqli_fetch_array($rs))
|
||||
{
|
||||
echo '<tr><td><b>'.$res['group_id'].'</b></td><td>'.$res['group_name'].'</td><td><a href="./group.php?set=edit&id='.$res['group_id'].'" class="btn btn-info btn-xs">编辑</a> <a href="./group.php?set=delete&id='.$res['group_id'].'" class="btn btn-xs btn-danger" onclick="return confirm(\'你确实要删除分组 '.$res['group_name'].' 吗?\n\n注意:该操作组会同时删除分组下的链接\');">删除</a></td></tr>';
|
||||
$rs=mysqli_query($con,"SELECT * FROM lylme_groups WHERE{$sql} order by group_order asc");
|
||||
$orderid=isset($_GET['orderid'])?$_GET['orderid']:null;
|
||||
if($orderid != NULL){echo '<style>#ordertd-'.$orderid.' {background: #d9edf7; !important}</style>';}
|
||||
$arr=array();
|
||||
$arrid = 0;
|
||||
while($res = mysqli_fetch_array($rs)){
|
||||
array_push($arr,$res['group_id']);
|
||||
|
||||
echo '<tr id="ordertd-'.$res['group_id'].'"><td><b>'.$res['group_order'].'</b></td><td>'.$res['group_name'].'</td><td>';
|
||||
if($arr[0] != $res['group_id']){
|
||||
echo '<a href="./group.php?set=up&id='.$res['group_id'].'&order='.$res['group_order'].'&arrid='.$arr[$arrid-1].'" class="btn btn-primary btn-xs">上移</a> ';}
|
||||
if($arr[$groupsrows-1] != $res['group_id']){
|
||||
echo '<a href="./group.php?set=down&id='.$res['group_id'].'&order='.$res['group_order'].'&arrid='.$arr[$arrid].'" class="btn btn-cyan btn-xs">下移</a>';}
|
||||
|
||||
echo '</td><td> <a href="./group.php?set=edit&id='.$res['group_id'].'" class="btn btn-info btn-xs">编辑</a> <a href="./group.php?set=delete&id='.$res['group_id'].'" class="btn btn-xs btn-danger" onclick="return confirm(\'你确实要删除分组 '.$res['group_name'].' 吗?\n\n注意:该操作组会同时删除分组下的链接\');">删除</a> </td></tr>';
|
||||
$arrid = $arrid+1;
|
||||
}
|
||||
|
||||
|
||||
|
||||
?>
|
||||
|
||||
</tbody>
|
||||
</table>
|
||||
<p><b>注:</b>权重越小越靠前, 权重相同时按分组ID排序</p>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
Loading…
Reference in New Issue
Block a user