forked from ego008/youbbs-for-sae
-
Notifications
You must be signed in to change notification settings - Fork 0
/
admin-node.php
89 lines (75 loc) · 2.73 KB
/
admin-node.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
<?php
define('IN_SAESPOT', 1);
define('ROOT' , pathinfo(__FILE__, PATHINFO_DIRNAME));
include(ROOT . '/config.php');
include(ROOT . '/common.php');
if (!$cur_user || $cur_user['flag']<99) exit('error: 403 Access Denied');
$nid = intval($_GET['nid']);
if($nid){
$query = "SELECT * FROM `yunbbs_categories` WHERE `id`='$nid'";
$c_obj = $DBS->fetch_one_array($query);
if(!$c_obj){
header('location: /admin-node#edit');
exit;
}
}
$tip1 = '';
$tip2 = '';
if($_SERVER['REQUEST_METHOD'] == 'POST'){
$action = $_POST['action'];
$DBM = new DB_MySQL;
$DBM->connect($servername_m, $dbport, $dbusername, $dbpassword, $dbname);
if($action=='find'){
$n_id = trim($_POST['findid']);
if($n_id){
header('location: /admin-node-'.$n_id);
}else{
header('location: /admin-node#edit');
}
exit;
}else if($action=='add'){
$n_name = trim($_POST['name']);
$n_about = trim($_POST['about']);
if($n_name){
$check_obj = $DBS->fetch_one_array("SELECT * FROM `yunbbs_categories` WHERE `name`='".$n_name."'");
if($check_obj){
$tip1 = $n_name.' 分类名已存在,请修改为不同的分类名';
}else{
if($DBM->query("INSERT INTO `yunbbs_categories` (`id`,`name`,`about`) VALUES (null,'$n_name','$n_about')")){
//更新缓存
$MMC->delete('newest_nodes');
$MMC->delete('bot_nodes');
$MMC->delete('site_infos');
$tip1 = '已成功添加';
}else{
$tip1 = '数据库更新失败,修改尚未保存,请稍后再试';
}
}
}else{
$tip1 = '分类名不能留空';
}
}else if($action=='edit'){
$n_name = trim($_POST['name']);
$n_about = trim($_POST['about']);
if($n_name){
if($DBM->unbuffered_query("UPDATE `yunbbs_categories` SET `name`='$n_name',`about`='$n_about' WHERE `id`='$nid'")){
//更新缓存
$MMC->delete('newest_nodes');
$MMC->delete('bot_nodes');
$MMC->delete('n-'.$nid);
$c_obj['name'] = $n_name;
$c_obj['about'] = $n_about;
$tip2 = '已成功保存';
}else{
$tip2 = '数据库更新失败,修改尚未保存,请稍后再试';
}
}else{
$tip2 = '分类名不能留空';
}
}
}
// 页面变量
$title = '分类管理';
$pagefile = ROOT . '/templates/default/'.$tpl.'admin-node.php';
include(ROOT . '/templates/default/'.$tpl.'layout.php');
?>