-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathconfirmation.php
476 lines (419 loc) · 14.1 KB
/
confirmation.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
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
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
<?php
include("server.php");
if (!isset($_SESSION['username'])) {
$_SESSION['msg'] = "You must log in first";
header('location: signin.php');
}
if(!isset($_SESSION['checkout']))
{
$_SESSION['msg'] = "You must add items to your cart first";
header('location: pantry.php');
}
if(!isset($_SESSION['proceed']))
{
$_SESSION['msg'] = "You must fill in your shipping information first";
header('location: shipping.php');
}
if(!isset($_SESSION['confirm']))
{
$_SESSION['msg'] = "You must fill in your payment information first";
header('location: payment.php');
}
$weight = 0;
$price = 0;
$tax = 0;
$orderTot = 0;
if(isset($_SESSION["weight"]) && isset($_SESSION["price"]) && isset($_SESSION["tax"]) && isset($_SESSION["orderTot"]))
{
$weight = $_SESSION["weight"];
$price = $_SESSION["price"];
$tax = $_SESSION["tax"];
$orderTot = $_SESSION["orderTot"];
}
$username = $_SESSION['username']['username'];
$userQuery = "SELECT * FROM customer WHERE username='$username';";
$userResults = mysqli_query($db, $userQuery);
if(mysqli_num_rows($userResults) == 1) {
$user = mysqli_fetch_assoc($userResults);
$customerID = $user['user_id'];
}
$query = "SELECT * FROM customer_profile WHERE username='$username';";
// echo $query;
$results = mysqli_query($db, $query);
if(mysqli_num_rows($results) == 1) {
$profile = mysqli_fetch_assoc($results);
// $customerID = $profile['customer_id'];
$firstName = $profile['first_name'];
$lastName = $profile['last_name'];
$address = $profile['address'];
$city = $profile['city'];
$state = $profile['state'];
$zipcode = $profile['zipcode'];
$card_type = $profile['card_type'];
$card_number = $profile['card_number'];
$cvc = $profile['cvc'];
$expiration_date = $profile['expiration_date'];
} else if(mysqli_num_rows($results) == 0) {
$profile = mysqli_fetch_assoc($results);
$firstName = "-";
$lastName = "-";
$address = "-";
$city = "-";
$state = "-";
$zipcode = "-";
$card_type = "-";
$card_number = "-";
$cvc = "-";
$expiration_date = "-";
}
$substring = substr($card_number, -4);
// echo $customerID;
if(!empty($_GET["action"]))
{
switch($_GET["action"])
{
case "complete":
$_SESSION["complete"] = "true";
if(isset($_SESSION["cart"]))
{
foreach ($_SESSION["cart"] as $product)
{
$item_id = $product["item_id"];
$quantity = $product["quantity"];
$inventory = $product["inventory"];
if($quantity <= $inventory)
{
$updatedQuan = $inventory - $quantity;
$inventoryQuery = "UPDATE item SET inventory = '$updatedQuan' WHERE item_id = $item_id";
mysqli_query($db,$inventoryQuery);
}
}
header('location: complete.php');
//Destroys cart session
unset($_SESSION["cart"]);
}
break;
case "pantry":
unset($_SESSION["checkout"]);
unset($_SESSION["proceed"]);
header('location: pantry.php');
break;
case "shipping":
unset($_SESSION["checkout"]);
header('location: shipping.php');
break;
case "payment":
unset($_SESSION["checkout"]);
unset($_SESSION["proceed"]);
unset($_SESSION["confirm"]);
header('location: pantry.php');
break;
case "home":
unset($_SESSION["complete"]);
unset($_SESSION["checkout"]);
unset($_SESSION["proceed"]);
unset($_SESSION["confirm"]);
header('location: home.php');
break;
case "about":
unset($_SESSION["complete"]);
unset($_SESSION["checkout"]);
unset($_SESSION["proceed"]);
unset($_SESSION["confirm"]);
header('location: home.php#about');
break;
case "team":
unset($_SESSION["complete"]);
unset($_SESSION["checkout"]);
unset($_SESSION["proceed"]);
unset($_SESSION["confirm"]);
header('location: home.php#about');
break;
case "contact":
unset($_SESSION["complete"]);
unset($_SESSION["checkout"]);
unset($_SESSION["proceed"]);
unset($_SESSION["confirm"]);
header('location: home.php#contact');
break;
}
}
?>
<!DOCTYPE html>
<html>
<head>
<!-- Site Properties -->
<title>Something Simple</title>
<script src="https://code.jquery.com/jquery-3.3.1.min.js" integrity="sha256-FgpCb/KJQlLNfOu91ta32o/NMZxltwRo8QtmkMRdAu8=" crossorigin="anonymous"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/semantic-ui/2.3.3/semantic.min.js"></script>
<link rel="stylesheet" type="text/css" href="https://cdnjs.cloudflare.com/ajax/libs/semantic-ui/2.3.3/semantic.css">
<link href="https://fonts.googleapis.com/css?family=Pacifico" rel="stylesheet">
<style type="text/css">
body {
min-height: 700px;
padding: 0.5em 0em;
background: #F5EAD1 url('images/web-graphics/leaf-watermark.png');
background-size: 600px;
background-repeat: no-repeat;
background-position: left bottom;
left: -2em;
bottom: -2em;
}
#confirmation .container {
margin-bottom: 2em;
}
#confirmation .container .raised {
padding: 2em 2em 3em 2em;
}
#confirmation .container .header span {
font-family: 'Pacifico', cursive;
}
#confirmation .container .header i {
padding: 0 0.5em;
}
#confirmation .container .right .button {
margin: 0 1em !important;
}
#confirmation .navbar .container .right h3 {
margin: 0 1em !important;
}
#confirmation .container .row h1 {
font-size: 5em;
margin-bottom: 0.5em;
font-family: 'Pacifico', cursive;
}
#confirmation .container .field {
margin-bottom: 1em;
}
#confirmation .container .grid .row {
padding: 0.5em 0;
}
</style>
<script src="https://cdnjs.cloudflare.com/ajax/libs/semantic-ui/2.3.3/semantic.js"></script>
</head>
<body>
<div class="pusher">
<!-- MASTER HEAD -->
<section id="confirmation">
<!-- NAV BAR -->
<div class="navbar">
<div class="ui container">
<div class="ui large secondary menu">
<div class="header item">
<span>something simple.</span>
<i class="leaf icon"></i>
</div>
<a class="item" href="confirmation.php?action=home">Home</a>
<a href="confirmation.php?action=about" class="item">About</a>
<a href="confirmation.php?action=team" class="item">Team</a>
<a href="confirmation.php?action=contact" class="item">Contact</a>
<div class="right item">
<h3>Welcome, <?php echo $_SESSION['username']['username']; ?>!</h3>
<a class="ui primary button" href="profile.php">Profile</a>
<a class="ui negative button" href="pantry.php?action=logout">Log Out</a>
</div>
</div>
</div>
</div>
<div class="ui container">
<div class="row">
<h1>Confirmation</h1>
</div>
<div class="row">
<div class="ui four small steps">
<a href="confirmation.php?action=pantry" class="completed link step">
<i class="cart icon"></i>
<div class="content">
<div class="title">Pantry</div>
<div class="description">Choose items to order</div>
</div>
</a>
<a href="confirmation.php?action=shipping" class="completed link step">
<i class="truck icon"></i>
<div class="content">
<div class="title">Shipping</div>
<div class="description">Choose your shipping options</div>
</div>
</a>
<a href="confirmation.php?action=payment" class="completed link step">
<i class="payment icon"></i>
<div class="content">
<div class="title">Billing</div>
<div class="description">Enter billing information</div>
</div>
</a>
<div class="active step">
<i class="info icon"></i>
<div class="content">
<div class="title">Confirm Order</div>
</div>
</div>
</div>
</div>
</div>
<!-- SHOPPING INFO -->
<div class="container">
<div class="ui raised segment container">
<div class="ui grid">
<div class="ui eight wide column">
<div class="ui container">
<!-- SHOPPING CART -->
<h1>Shopping Cart</h1>
<div class="ui grid">
<?php
if(isset($_SESSION["cart"])) {
foreach ($_SESSION["cart"] as $product) {
$name = $product["item_name"];
$item_id = $product["item_id"];
$quantity = $product["quantity"];
$item_price = $product["item_price"];
$item_weight = $product["item_weight"];
$item_total_weight = $item_weight * $quantity;
$suffix = "lbs";
if ($item_total_weight == 1) {
$suffix = "lb";
}
echo "<!-- ITEMS -->
<div class='row'>
<div class='ten wide column'>
<span><strong>$name</strong></span>
</div>
<div class='three wide column right floated right aligned'>
<span>$quantity</span>
</div>
<div class='three wide column right floated right aligned'>
<span>$item_total_weight"." "."$suffix</span>
</div>
</div>";
$username = $_SESSION['username']['username'];
$order = "INSERT INTO orders(order_id, customer_id, username, item_id, quantity) VALUES (NULL, $customerID, '$username', $item_id, $quantity);";
mysqli_query($db, $order);
// echo $order;
}
}
?>
</div>
</div>
</div>
<div class="ui eight wide column">
<!-- ORDER SUMMARY -->
<h1>Order Summary</h1>
<div class="ui grid">
<!-- WEIGHT -->
<div class="row">
<div class="ten wide column">
<span>Weight</span>
</div>
<div class="six wide column right floated right aligned">
<span><?php echo $weight." lbs"; ?></span>
</div>
</div>
<!-- TOTAL BEFORE TAX -->
<div class="row">
<div class="ten wide column">
<span>Total before tax</span>
</div>
<div class="six wide column right floated right aligned">
<span><?php echo "$ ".number_format($price, 2); ?></span>
</div>
</div>
<!-- ESTIMATED TAX -->
<div class="row">
<div class="ten wide column">
<span>Estimated tax</span>
</div>
<div class="six wide column right floated right aligned">
<span><?php echo "$ ".number_format($tax, 2); ?></span>
</div>
</div>
<!-- ORDER TOTAL -->
<div class="row">
<div class="ten wide column">
<span><h3>Order Total:</h3></span>
</div>
<div class="six wide column right floated right aligned">
<span><h3><?php echo "$ ".number_format($orderTot, 2); ?></h3></span>
</div>
</div>
</div>
</div>
</div>
</div>
<!-- PAYMENT AND SHIPPING INFO -->
<div class="ui raised segment container">
<div class="ui grid">
<div class="ui eight wide column">
<div class="ui container">
<!-- SHIPPING INFO -->
<h1>Shipping Info</h1>
<div class="ui grid">
<!-- SHIPPING TO -->
<div class="row">
<div class="sixteen wide column">
<h3><strong>Shipping to:</strong></h3>
</div>
</div>
<div class="row">
<div class="sixteen wide column">
<p>
<?php echo $firstName . " " . $lastName?> <br>
<?php echo $address ?> <br>
<?php echo $city . ', ' . $state ?> <br>
<?php echo $zipcode ?>
</p>
</div>
</div>
</div>
</div>
</div>
<div class="ui eight wide column">
<!-- PAYMENT INFO -->
<h1>Payment Info</h1>
<div class="ui grid">
<!-- SHIPPING TO -->
<div class="row">
<div class="sixteen wide column">
<h3><strong>Billing to:</strong></h3>
</div>
</div>
<div class="row">
<div class="sixteen wide column">
<p>
<?php echo $firstName . " " . $lastName ?> <br>
<?php echo $card_type . " ending in " . $substring ?> <br>
<?php echo "Expiring on " . $expiration_date ?>
</p>
</div>
</div>
</div>
</div>
</div>
</div>
<!-- BUTTONS -->
<div class="ui center aligned container">
<a href="confirmation.php?action=complete&item_id=$item_id">
<button class="ui big green button">Submit order</button>
</a>
</div>
<div class="ui center aligned container">
<form method="post" action="home.php">
<input type="hidden" name="cancel" value="yes"></input>
<button class="ui small gray button" type="submit">Cancel order</button>
</form>
</div>
</div>
</section>
</div>
<script>
$(document)
.ready(function() {
$('.ui.dropdown')
.dropdown({
on: 'click'
})
;
})
;
</script>
</body>
</html>