-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathroot.php
243 lines (229 loc) · 7.46 KB
/
root.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
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
<?php
include("dbconnect.php");
$mysqli -> query('set names utf8');
session_start();
if(!isset($_SESSION['user']))
{
echo "<script>alert('您已登出!');</script>";
echo "<script>history.go(-1)</script>";
exit();
}
?>
<!DOCTYPE html>
<html lang = "en">
<head>
<meta charset = "utf-8">
<title>為食而行-管理者介面</title>
<style type = "text/css">
header
{
position: relative;
width: 100%;
}
.set
{
background-color: black;
opacity: 0.6;
width: 100%;
height: 50px;
position: absolute;
z-index: 1;
}
.title
{
font-family: DFKai-sb;
font-size: 60px;
color: white;
position: absolute;
left: 5%;
margin-top: 50px;
z-index: 1;
}
.img
{
position: relative;
width: 100%;
-webkit-filter: brightness(.5);
}
.option
{
font-weight: bold;
font-size: 15px;
border: 5px lightskyblue solid;
display: inline-block;
padding: 2px;
background-color: lightskyblue;
}
ul
{
font-family: DFKai-sb;
list-style: none;
color: white;
position: absolute;
z-index: 1;
}
ul li
{
display: inline;
}
a
{
color: white;
text-decoration: none;
}
</style>
<script type="text/javascript">
function addRecipe()
{
document.getElementById('addRecipe').style.display = "inline";
document.getElementById('deleteRecipe').style.display = "none";
document.getElementById('deleteUser').style.display = "none";
}
function deleteRecipe()
{
document.getElementById('deleteRecipe').style.display = "inline";
document.getElementById('addRecipe').style.display = "none";
document.getElementById('deleteUser').style.display = "none";
}
function deleteUser()
{
document.getElementById('deleteUser').style.display = "inline";
document.getElementById('addRecipe').style.display = "none";
document.getElementById('deleteRecipe').style.display = "none";
}
</script>
</head>
<body>
<header>
<span class="set"></span>
</header>
<h1 class = "title">為食而行-管理者介面</h1>
<ul style = "right: 15%">
<a href = "user.php">
<li class = "option">首頁</li>
</a>
<a href = "loginOut.php">
<li class = "option">離開</li>
</a>
<a href = "#">
<li class = "option" onclick="addRecipe()">新增食譜</li>
</a>
<a href = "#">
<li class = "option" onclick="deleteRecipe()">刪除食譜</li>
</a>
<a href = "#">
<li class = "option" onclick="deleteUser()">刪除使用者帳號</li>
</a>
</ul>
<img class = "img" src = "封面1.png" alt="">
<div style="display: none" id = "addRecipe">
<form action = "#" method = "post">新增食譜
<p>食譜名: <input type = text maxlength="19" name = "Name" required></p>
<p>食譜類型:
<select name="Type">
<option value="主菜">主菜</option>
<option value="早餐">早餐</option>
<option value="前菜">前菜</option>
<option value="甜點">甜點</option>
</select>
</p>
<p>每100公克之熱量:<input type = text maxlength="5" name = "Cal" required></p>
<p>作法:<br><textarea maxlength="500" name = "Step" rows="25" cols="60" required></textarea></p>
<p><input type = "submit" value = "新增"></p>
</form>
</div>
<div style="display: none" id = "deleteRecipe">
<form action = "#" method = "post">刪除食譜
<p>食譜名: <input type = text maxlength="19" name = "deleteName" required></p>
<p><input type = "submit" value = "刪除"></p>
</form>
</div>
<div style="display: none" id = "deleteUser">
<form action = "#" method = "post">刪除使用者帳號
<p>使用者帳號: <input type = text maxlength="10" name = "deleteUser" required></p>
<p><input type = "submit" value = "刪除"></p>
</form>
</div>
</body>
<?php
if(isset($_POST['Name']) && isset($_POST['Type']) && isset($_POST['Cal']) && isset($_POST['Step']))
{
include("dbconnect.php");
$mysqli -> query('set names utf8');
$name = $_POST['Name'];
$type = $_POST['Type'];
$cal = $_POST['Cal'];
$step = $_POST['Step'];
$repeatCheck = "select 菜名 from 食譜 where (菜名 = '$name')";
$get = $mysqli -> query($repeatCheck);
$rows = $get -> num_rows;
if($rows)
{
echo "<script>alert('已有此道菜!');</script>";
echo "<script>history.go(-1)</script>";
}
else
{
$Demand = $mysqli -> prepare("INSERT INTO 食譜類型(菜名,食譜類型) VALUES (?,?)");
$Demand -> bind_param('ss',$name,$type); //ss為字串型態
if($Demand -> execute())
{
$Demand -> close();
}
$Demand = $mysqli -> prepare("INSERT INTO 食譜(菜名,熱量,作法) VALUES (?,?,?)");
$Demand -> bind_param('sds',$name,$cal,$step); //ss為字串型態
if($Demand -> execute())
{
echo "<script>alert('新增成功!');</script>";
echo "<script>history.go(-1)</script>";
$Demand -> close();
}
}
$mysqli -> close();
}?>
<?php
include("dbconnect.php");
$mysqli -> query('set names utf8');
if(isset($_POST['deleteName']))
{
$deleteName = $_POST['deleteName'];
$Check = "select 菜名 from 食譜類型 where (菜名 = '$deleteName')";
$get = $mysqli -> query($Check);
$rows = $get -> num_rows;
if(!$rows)
{
echo "<script>alert('無此道菜!');</script>";
echo "<script>history.go(-1)</script>";
}
else
{
$deleteDemand = "delete from 食譜類型 where 菜名 = '$deleteName'";
$delete = $mysqli -> query($deleteDemand);
echo "<script>alert('刪除成功!');</script>";
echo "<script>history.go(-1)</script>";
}
}
?>
<?php
include("dbconnect.php");
$mysqli -> query('set names utf8');
if(isset($_POST['deleteUser']))
{
$deleteUser = $_POST['deleteUser'];
$Check = "select 帳號 from 帳密 where (帳號 = '$deleteUser')";
$get = $mysqli -> query($Check);
$rows = $get -> num_rows;
if(!$rows)
{
echo "<script>alert('無此帳號!');</script>";
echo "<script>history.go(-1)</script>";
}
else
{
$deleteDemand = "delete from 帳密 where 帳號 = '$deleteUser'";
$delete = $mysqli -> query($deleteDemand);
echo "<script>alert('刪除成功!');</script>";
echo "<script>history.go(-1)</script>";
}
}
?>