-
Notifications
You must be signed in to change notification settings - Fork 0
/
management-user.php
171 lines (112 loc) · 3.42 KB
/
management-user.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
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
<?php
require 'common.php';
$action=isset($_GET['action'])?$_GET['action']:'';
$cookie=isset($_COOKIE['identity'])?$_COOKIE['identity']:'';
function reload($cookie){
if($cookie == 1){
echo '<script>location.href="both-management.php";</script>';
}
if($cookie == 2){
echo '<script>location.href="user-management.php";</script>';
}
if($cookie == ''){
echo '<script>alert("非法操作!");history.go(-1);</script>';
}
}
//添加管理员
if($action=="addAdmin"){
$account = _POST('account');
$password = md5(_POST('password'));
$identity = 2;
$realname = _POST('realname');
connect_mydb();
select_mydb();
$sql="insert into
user (account,password,identity,realname)
VALUES ('$account','$password','$identity','$realname');";
query($sql);
mysqli_close($mydb);
reload($cookie);
}
//添加用户
else if($action == "addUser"){
$account = _POST('account');
$password = md5(_POST('password'));
$identity = 3;
$realname = _POST('realname');
connect_mydb();
select_mydb();
$sql="insert into
user (account,password,identity,realname)
VALUES ('$account','$password','$identity','$realname');";
query($sql);
var_dump($realname);
mysqli_close($mydb);
reload($cookie);
}
//删除用户和管理员
else if($action == "deleteUser"){
$id=_POST('id');
connect_mydb();
select_mydb();
$sql="delete from
user
WHERE id='$id'";
query($sql);
mysqli_close($mydb);
reload($cookie);
}
//修改用户和管理员
else if($action == "modifyUser"){
$id=_POST('id');
$account = _POST('account');
$password = md5(_POST('password'));
$realname = _POST('realname');
connect_mydb();
select_mydb();
$sql="update user
set account='$account',password='$password' , realname='$realname'
WHERE id='$id';";
query($sql);
mysqli_close($mydb);
reload($cookie);
}
//查询管理员
else if($action == "getAdmin"){
connect_mydb();
select_mydb();
$sql="select * from
user
WHERE IDENTITY =2;";
$result=fetch_all($sql);
$result=json_encode($result);
mysqli_close($mydb);
echo $result;
}
//查询用户
else if($action == "getUser"){
connect_mydb();
select_mydb();
$sql="select * from
user
WHERE IDENTITY =3;";
$result=fetch_all($sql);
$result=json_encode($result);
mysqli_close($mydb);
echo $result;
}
//用户自己修改个人信息
else if($action == "modifySelf"){
$account=_POST('cookie');
$password = md5(_POST('password'));
$realname = _POST('realname');
connect_mydb();
select_mydb();
$sql="update user
set password='$password' , realname='$realname'
WHERE account='$account';";
query($sql);
mysqli_close($mydb);
echo '<script>location.href="me.php";</script>';
}
?>