forked from hzequn/PHP_hotel
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathadd_admin.php
205 lines (199 loc) · 6.81 KB
/
add_admin.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
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
<?php
date_default_timezone_set('PRC');
$ndate=date("Y-m-d");
include_once 'conn.php';
$addnew=$_POST["addnew"];
?>
<script src="js/jquery-2.1.3.min.js" type="text/javascript" charset="utf-8"></script>
<script src="js/sweetalert.min.js" type="text/javascript" charset="utf-8"></script>
<?php
$username=$_POST['username'];
//MD5加盐加密
$salt="skjddq237:&*^$df234GJSN";
$pwd1=$_POST['pwd1'];
$pwd1=$pwd1+$salt;
$pwd1=md5($pwd1);
$pwd2=$_POST['pwd2'];
$pwd2=$pwd2+$salt;
$pwd2=md5($pwd2);
$cx=$_POST['cx'];
if($username!="" && $pwd1!="" && $pwd2!="")
{
$sql="select * from allusers where username='$username' and pwd='$pwd1'";
$query=mysql_query($sql);
$rowscount=mysql_num_rows($query);
if($rowscount > 0)
{
echo
"<script>
$(function(){
swal('失败','已存在管理员账号','error')
});
</script>";
}
else
{
$ndate =date("Y-m-d");
$sql="insert into allusers(username,pwd,cx) values('$username','$pwd1','$cx')";
mysql_query($sql);
echo
"<script>
$(function(){
swal('成功','添加管理员','success')
});
</script>";
}
$_SESSION['cx']=="超级管理员";
}
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<link rel="stylesheet" href="css/bootstrap.min.css" />
<link rel="stylesheet" href="css/jquery.mCustomScrollbar.min.css" />
<link rel="stylesheet" href="css/custom.css" />
<link rel="stylesheet" href="css/demo_add.css" />
<link rel="stylesheet" href="css/font-awesome.min.css" />
<link rel="stylesheet" href="css/style.css" />
<meta http-equiv="Content-Type" content="text/html; charset=gb2312" />
<title>添加新管理员</title>
</head>
<script>
function check(){
if(document.getElementById("username").value==""){
swal({
title: "失败!",
text: "请输入账号!",
icon: "error",
showConfirmButton: true
})
document.getElementById("username").focus();
return false;
}
if(document.getElementById("pwd1").value==""){
swal({
title: "失败!",
text: "请输入密码!",
icon: "error",
showConfirmButton: true
})
document.getElementById("pwd1").focus();
return false;
}
if(document.getElementById("pwd2").value==""){
swal({
title: "失败!",
text: "请输入确认密码!",
icon: "error",
showConfirmButton: true
})
document.getElementById("pwd2").focus();
return false;
}
if(document.getElementById("pwd2").value != document.getElementById("pwd1").value){
swal({
title: "失败!",
text: "两次密码不一致!",
icon: "error",
showConfirmButton: true
})
document.getElementById("pwd1").value="";
document.getElementById("pwd2").value="";
document.getElementById("pwd1").focus();
return false;
}
}
</script>
<body>
<!--添加管理员-->
<div class="add_admin">
<div class="clearfix admin_con_top">
<h2 class="fl">添加新管理员</h2>
<p class="fr">当前日期: <?php echo $ndate; ?></p>
</div>
<form id="form1" name="form1" method="post" action="">
<ul>
<li>
<span class="user">账号:</span>
<input type="text" name="username" id="username" value='' placeholder="用户名" class="admin_name" autocomplete="off"/>*
<input type='text' style='display:none'> <!-- 针对firefox -->
<input type="hidden" name="addnew" value="1" />
</li>
<li>
<span class="password">密码:</span>
<input type="password" name="pwd1" class="pass admin_password1" id=" pwd1" value='' placeholder="密码" autocomplete="new-password" readonly onFocus="this.removeAttribute('readonly');" onBlur="this.setAttribute('readonly',true);"/>*
<input type='text' style='display:none'> <!-- 针对firefox -->
</li>
<li>
<span class="password">确认密码:</span>
<input type="password" name="pwd2" class="pass admin_password2" id="pwd2" value='' placeholder="确认密码" autocomplete="new-password" readonly onFocus="this.removeAttribute('readonly');" onBlur="this.setAttribute('readonly',true);"/>*
<input type='text' style='display:none'> <!-- 针对firefox -->
</li>
<li>
<span class="password">系统权限</span>
<select name='cx' id='cx'>*
<option value="普通管理员">普通管理员</option>
<option value="超级管理员">超级管理员</option>
</select>
</li>
</ul>
<div class="bottom_box">
<input type="submit" name="Submit" value="添加" onClick="return check();" >
<input type="reset" name="Submit2" value="重置"/>
</div>
</form>
<div class="clearfix admin_con_top">
<div class="clearfix admin_con_top">
<h2 class="fl">已有管理员列表</h2>
<?php
$sql="select * from allusers where 1=1";
$query=mysql_query($sql);
$rowscount=mysql_num_rows($query);
?>
<p class="fr">共<span><?php echo $rowscount;?></span>条记录</p>
</div>
</div>
<div class="admin_list">
<table class="table table-striped">
<tr>
<th>编号</th>
<th>账号</th>
<th>密码</th>
<th>系统权限</th>
<th>添加时间</th>
<th>操作</th>
</tr>
<?php
$sql="select * from allusers order by id desc";
$query=mysql_query($sql);
$rowscount=mysql_num_rows($query);
for($i=0;$i<$rowscount;$i++)
{
?>
<tr>
<td><?php echo $i+1;?></td>
<td><?php echo mysql_result($query,$i,"username");?></td>
<td><?php echo mysql_result($query,$i,"pwd");?></td>
<td><?php echo mysql_result($query,$i,"cx");?></td>
<td><?php echo date('Y-m-d',strtotime(mysql_result($query,$i,"addtime")));?></td>
<td>
<a href="del.php?id=<?php echo mysql_result($query,$i,"id");?>&tablename=allusers"
onClick="return confirm('真的要删除?')">
<i class="fa fa-trash b_r b_red material-icons"></i>
<span class="text_red">删除<span>
</a>
</td>
</tr>
<?php
}
?>
</table>
</div>
</div>
<!--添加管理员end-->
<script src="js/bootstrap.min.js" type="text/javascript" charset="utf-8"></script>
<script src="js/CustomScrollbar.min.js" type="text/javascript" charset="utf-8"></script>
<script src="js/custom.js" type="text/javascript" charset="utf-8"></script>
<script src="js/index.js" type="text/javascript" charset="utf-8"></script>
</body>
</html>