-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathOrder.php
More file actions
401 lines (320 loc) · 16.3 KB
/
Order.php
File metadata and controls
401 lines (320 loc) · 16.3 KB
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
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
<!DOCTYPE HTML>
<!--
Alpha by HTML5 UP
html5up.net | @ajlkn
Free for personal and commercial use under the CCA 3.0 license (html5up.net/license)
-->
<html>
<head>
<title>Order Now!</title>
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1, user-scalable=no" />
<link rel="stylesheet" href="assets/css/main.css" />
</head>
<style>
/* Style the tab */
.tab {
overflow: hidden;
border: 1px solid #ccc;
background-color: #f1f1f1;
}
/* Style the buttons that are used to open the tab content */
.tab button {
background-color: inherit;
float: left;
border: none;
outline: none;
cursor: pointer;
padding: 14px 16px;
transition: 0.3s;
color: black;
}
/* Change background color of buttons on hover */
.tab button:hover {
box-shadow: 0 12px 16px 0 rgba(0,0,0,0.24), 0 17px 50px 0 rgba(0,0,0,0.19);
}
/* Create an active/current tablink class */
.tab button.active {
background-color: #EFCA46;
}
/* Style the tab content */
.tabcontent {
display: none;
padding: 0;
border: 1px solid #ccc;
border-top: none;
}
.us {
background-color: lightgray;
color: white;
margin: 10px;
padding: 30px;
height: 250px;
vertical-align: middle;
}
</style>
<script>
function displayFunction(name) {
var x = document.getElementById(name);
if (x.style.display === "none") { // if element hidden
x.style.display = "block"; // unhide it
} else {
x.style.display = "none";
}
}
function displayLocationFunction() {
if(document.getElementById("pickup").checked) {
document.getElementById("pickup-method").style.display = "block"; // unhide it
} else {
document.getElementById("pickup-method").style.display = "none"; //hide
}
}
/*
function displayFunction(name) {
var x = document.getElementById(name);
if (x.checked) {
document.getElementById(name.concat("-topping")).style.display = "block"; // unhide it
} else {
document.getElementById(name.concat("-topping")).style.display = "none"; //hide
}
}
*/
</script>
<body class="is-preload">
<div id="page-wrapper">
<?php
session_start();
if(!isset($_SESSION['logged_in'])) {
header("Location:SignUp.php");
}
?>
<?php include("LoggedInHeader.php"); ?>
<?php
try {
include("library.php");
$query = "SELECT * FROM Location";
global $db;
$statement = $db->prepare($query);
$statement->execute();
$locations = $statement->fetchAll();
} catch (Exception $e) {
$error_message = $e->getMessage();
echo "<p>Error message: $error_message </p>";
}
?>
<!-- Header -->
<?php include("library.php"); $stmt = $db->prepare("SELECT * FROM Users WHERE uemail = ?");
$stmt->execute([$_SESSION['email']]);
$user = $stmt->fetch();?> <!-- Includes database login information-->
<!-- |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||-->
<?php
function makeSafe($value)
{
$value = htmlspecialchars($value);
return $value;
}
function retrieveEids($job) {
$username = 'ram8ny';
$password = 'Spring2021!!';
$dbname = 'ram8ny';
$host = "usersrv01.cs.virginia.edu";
$dsn = "mysql:host=$host;dbname=$dbname";
$db = new PDO($dsn, $username, $password);
$sql = "SELECT eid FROM Employee WHERE job = :job";
$statement = $db->prepare($sql);
$statement->bindParam(":job", $job);
$statement->execute();
$eids = $statement->fetchAll();
return $eids;
}
function incrementExp($eid) {
$username = 'ram8ny';
$password = 'Spring2021!!';
$dbname = 'ram8ny';
$host = "usersrv01.cs.virginia.edu";
$dsn = "mysql:host=$host;dbname=$dbname";
$db = new PDO($dsn, $username, $password);
$sql = "UPDATE Cashier SET exp = exp + 1 WHERE eid = :eid";
}
include_once("./library.php"); // To connect to the database
if ($_SERVER["REQUEST_METHOD"] == "POST") {
$address = $pizza_size = $cheese = $topping = $quantity = "";
$email = $_SESSION['email'];
$deliver = 1;
$points = 10 + $user['upoints'];
$newstmt = $db->prepare("UPDATE Users SET upoints = ? WHERE uemail = ?");
$newstmt->execute([$points,$email]);
if($user['upoints'] >= 100){
$points = 10;
$newstmt = $db->prepare("UPDATE Users SET upoints = ? WHERE uemail = ?");
$newstmt->execute([$points,$email]);
}
$location = makeSafe($_POST["location"]); // either delivery or pickup
if(strcmp($location, "pickup") == 0) { // if equal
$address = $_POST["pickup-method"];
$deliver = 0;
}
$pizza_size = $_POST["pizza-size"];
if(isset($_POST['cheese'])) {
$cheese = $_POST["pizza-cheese"]; // light, regular, or extra
} else {
$cheese = "none";
}
$topping = $_POST['topping'];
$quantity = $_POST['quantity'];
$cost = 10; // <------------------------------------------------------------------------ change later
$order_status = 0; // change later
$eids = [];
if($deliver) {
// Select random driver
$eids = retrieveEids("driver");
} else {
// Select cashier
$eids = retrieveEids("cashier");
}
$eid_index = array_rand($eids); // change later
$eid = $eids[$eid_index]['eid'];
if(!$deliver) {
incrementExp($eid);
}
$con = new mysqli($host, $username, $password, $dbname);
// Check connection
if (mysqli_connect_errno()) {
echo "Failed to connect to MySQL: " . mysqli_connect_error();
}
// Form the SQL query (a SELECT query)
$sql="SELECT tid FROM Topping WHERE tname = '$topping'";
// $sql= $db->prepare("SELECT tid FROM Topping WHERE tname = '$topping'");
$result = mysqli_query($con,$sql);
// $result = $sql->execute();
$tid = 0; // Topping ID value: tid
while($row = mysqli_fetch_array($result)) {
$tid = $row["tid"];
}
$sql="SELECT sid FROM Size WHERE sname = '$pizza_size'";
//$sql= $db->prepare("SELECT sid FROM Size WHERE sname = '$pizza_size'");
$result = mysqli_query($con,$sql);
//$result = $sql->execute();
$sid = 0; // Topping ID value: tid
while($row = mysqli_fetch_array($result)) {
$sid = $row["sid"];
}
/*
$sql="INSERT INTO Order (uemail, tid, sid, eid, cheese, quantity, deliver, cost, orderStatus)
VALUES
('$email','$tid', '$sid', '$eid', '$cheese', '$quantity', '$deliver', '$cost', '$order_status')";
*/
$sql=$db->prepare("INSERT INTO Orders (uemail, tid, sid, eid, cheese, quantity, deliver, cost, orderStatus)
VALUES
('$email','$tid', '$sid', '$eid', '$cheese', '$quantity', '$deliver', '$cost', '$order_status')");
$sql->execute();
// echo "'$email','$tid', '$sid', '$eid', '$cheese', '$quantity', '$deliver', '$cost', '$order_status'";
//if (!mysqli_query($con,$sql)) {
// die('Error: ' . mysqli_error($con));
// }
// echo "1 record added"; // Output to user
mysqli_close($con);
}
?>
<!-- |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||-->
<div style="padding:5%;">
<h2 style="text-align: center;">Order Form</h2>
<hr>
<form method="post" style="padding:2%;border: 2px solid;border-radius:25px;">
<h2>Location:</h2>
<div class="pizza-cheese">
<input type="radio" id="delivery" name="location" value="delivery" onclick="displayLocationFunction()" checked>
<label for="delivery">Delivery</label>
<input type="radio" id="pickup" name="location" value="pickup" onclick="displayLocationFunction()">
<label for="pickup">Pickup</label>
<select class="pickup-method" name="pickup-method" id="pickup-method" style="display:none;">
<?php $i=0 ?>
<?php foreach( $locations as $location ): ?>
<?php if($i == 0) : ?>
<option value="<?php echo $location['lid']?>" id='lid-[insert lid]' checked><?php echo $location['laddrstr'] . ', ' . $location['laddrcity'] . ', ' . $location['laddrstate'] . ', ' . $location['laddrzip']?></option>
<?php else : ?>
<option value="<?php echo $location['lid']?>" id='lid-[insert lid]'><?php echo $location['laddrstr'] . ', ' . $location['laddrcity'] . ', ' . $location['laddrstate'] . ', ' . $location['laddrzip']?></option>
<?php endif; ?>
<?php $i=$i+1; ?>
<?php endforeach;?>
</select>
</div>
<!-- placeholder values-->
<!--
<input type="radio" id="address1" name="location" value="address1" checked>
<label for="address1">26 Smoky Hollow Drive, Pomona, CA 91768</label>
<input type="radio" id="address2" name="location" value="address2">
<label for="address2">274 Plumb Branch Ave., Duluth, GA 30096</label>
<input type="radio" id="address3" name="location" value="address3">
<label for="address3">21 Bald Hill St., Rossville, GA 30741</label>
-->
<hr>
<h2>Pizza Size:</h2>
<input type="radio" id="small" name="pizza-size" value="small" checked>
<label for="small">Small</label>
<input type="radio" id="medium" name="pizza-size" value="medium">
<label for="medium">Medium</label>
<input type="radio" id="large" name="pizza-size" value="large">
<label for="large">Large</label>
<hr>
<h2>Cheese:</h2>
<div class="pizza-cheese">
<input type="checkbox" id="cheese" name="cheese" onclick="displayFunction('pizza-cheese')">
<label for="cheese">Cheese</label>
<select class="pizza-cheese" name="pizza-cheese" id="pizza-cheese" style="display:none;">
<option value="light">Light</option>
<option value="regular">Regular</option>
<option value="extra">Extra</option>
</select>
</div>
<hr>
<h2>Topppings:</h2>
<p>Please select one topping</p>
<div class="pizza-topping">
<input type="radio" id="pepperoni" value="pepperoni" name="topping" checked>
<label for="pepperoni">Pepperoni</label>
<input type="radio" id="chicken" value="chicken" name="topping">
<label for="chicken">Chicken</label>
<input type="radio" id="ham" value="ham" name="topping">
<label for="ham">Ham</label>
<input type="radio" id="beef" value="beef" name="topping">
<label for="beef">Beef</label>
<input type="radio" id="cheddar-cheese" value="cheddar cheese" name="topping">
<label for="cheddar-cheese">Cheddar Cheese</label>
<input type="radio" id="pineapple" value="pineapple" name="topping">
<label for="pineapple">Pineapple</label>
<input type="radio" id="onions" value="onions" name="topping">
<label for="onions">Onions</label>
<input type="radio" id="spinach" value="spinach" name="topping">
<label for="spinach">Spinach</label>
<select class="quantity" name="quantity" id="quantity">
<option value="light">Light</option>
<option value="regular">Regular</option>
<option value="extra">Extra</option>
</select>
</div>
<hr>
<p>Use points: <?php echo $user['upoints']; ?></p> <!-- Use function to fetch sign in user points-->
Your points are automatically applied and will be deducted after submitting your order.
<?php $currentPrice = 10;
if ($user['upoints'] >=100){
$currentPrice -= 10;
}
?>
<p>You pay: $<?php echo $currentPrice; ?>.00</p> <!-- Use button function to subtract from price and take away all points from user-->
<input type="submit" value="Order" class="btn btn-secondary" onclick= "alert('Your order went through! Check your order status for further updates.')">
</form>
</div>
<!-- Footer -->
<?php include("footer.php"); ?>
</div>
<!-- Scripts -->
<script src="assets/js/jquery.min.js"></script>
<script src="assets/js/jquery.dropotron.min.js"></script>
<script src="assets/js/jquery.scrollex.min.js"></script>
<script src="assets/js/browser.min.js"></script>
<script src="assets/js/breakpoints.min.js"></script>
<script src="assets/js/util.js"></script>
<script src="assets/js/main.js"></script>
</body>
</html>